dolibarr  7.0.0-beta
card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2011-2014 Juanjo Menent <jmenent@2byte.es>
3  * Copyright (C) 2015 Marcos GarcĂ­a <marcosgdf@gmail.com>
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.'/compta/localtax/class/localtax.class.php';
27 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
28 
29 $langs->load("compta");
30 $langs->load("banks");
31 $langs->load("bills");
32 
33 $id=GETPOST("id",'int');
34 $action=GETPOST("action","alpha");
35 $refund=GETPOST("refund","int");
36 if (empty($refund)) $refund=0;
37 
38 $lttype=GETPOST('localTaxType', 'int');
39 
40 // Security check
41 $socid = isset($_GET["socid"])?$_GET["socid"]:'';
42 if ($user->societe_id) $socid=$user->societe_id;
43 $result = restrictedArea($user, 'tax', '', '', 'charges');
44 
45 $localtax = new Localtax($db);
46 
47 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
48 $hookmanager->initHooks(array('localtaxvatcard','globalcard'));
49 
50 
55 //add payment of localtax
56 if($_POST["cancel"] == $langs->trans("Cancel")){
57  header("Location: reglement.php?localTaxType=".$lttype);
58  exit;
59 }
60 
61 if ($action == 'add' && $_POST["cancel"] <> $langs->trans("Cancel"))
62 {
63 
64  $db->begin();
65 
66  $datev=dol_mktime(12,0,0, $_POST["datevmonth"], $_POST["datevday"], $_POST["datevyear"]);
67  $datep=dol_mktime(12,0,0, $_POST["datepmonth"], $_POST["datepday"], $_POST["datepyear"]);
68 
69  $localtax->accountid=GETPOST("accountid");
70  $localtax->paymenttype=GETPOST("paiementtype");
71  $localtax->datev=$datev;
72  $localtax->datep=$datep;
73  $localtax->amount=price2num(GETPOST("amount"));
74  $localtax->label=GETPOST("label");
75  $localtax->ltt=$lttype;
76 
77  $ret=$localtax->addPayment($user);
78  if ($ret > 0)
79  {
80  $db->commit();
81  header("Location: reglement.php?localTaxType=".$lttype);
82  exit;
83  }
84  else
85  {
86  $db->rollback();
87  setEventMessages($localtax->error, $localtax->errors, 'errors');
88  $_GET["action"]="create";
89  }
90 }
91 
92 //delete payment of localtax
93 if ($action == 'delete')
94 {
95  $result=$localtax->fetch($id);
96 
97  if ($localtax->rappro == 0)
98  {
99  $db->begin();
100 
101  $ret=$localtax->delete($user);
102  if ($ret > 0)
103  {
104  if ($localtax->fk_bank)
105  {
106  $accountline=new AccountLine($db);
107  $result=$accountline->fetch($localtax->fk_bank);
108  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)
109  }
110 
111  if ($result >= 0)
112  {
113  $db->commit();
114  header("Location: ".DOL_URL_ROOT.'/compta/localtax/reglement.php?localTaxType='.$localtax->ltt);
115  exit;
116  }
117  else
118  {
119  $localtax->error=$accountline->error;
120  $db->rollback();
121  setEventMessages($localtax->error, $localtax->errors, 'errors');
122  }
123  }
124  else
125  {
126  $db->rollback();
127  setEventMessages($localtax->error, $localtax->errors, 'errors');
128  }
129  }
130  else
131  {
132  $mesg='Error try do delete a line linked to a conciliated bank transaction';
133  setEventMessages($mesg, null, 'errors');
134  }
135 }
136 
137 
138 /*
139 * View
140 */
141 
142 llxHeader();
143 
144 $form = new Form($db);
145 
146 if ($id)
147 {
148  $vatpayment = new Localtax($db);
149  $result = $vatpayment->fetch($id);
150  if ($result <= 0)
151  {
152  dol_print_error($db);
153  exit;
154  }
155 }
156 
157 
158 if ($action == 'create')
159 {
160  print load_fiche_titre($langs->transcountry($lttype==2?"newLT2Payment":"newLT1Payment",$mysoc->country_code));
161 
162  print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" name="formlocaltax" method="post">'."\n";
163  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
164  print '<input type="hidden" name="localTaxType" value="'.$lttype.'">';
165  print '<input type="hidden" name="action" value="add">';
166 
167  dol_fiche_head();
168 
169  print '<table class="border" width="100%">';
170 
171  print "<tr>";
172  print '<td class="fieldrequired">'.$langs->trans("DatePayment").'</td><td>';
173  print $form->select_date($datep,"datep",'','','','add',1,1);
174  print '</td></tr>';
175 
176  print '<tr><td class="fieldrequired">'.$langs->trans("DateValue").'</td><td>';
177  print $form->select_date($datev,"datev",'','','','add',1,1);
178  print '</td></tr>';
179 
180  // Label
181  print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td><input name="label" class="minwidth200" value="'.($_POST["label"]?GETPOST("label",'',2):$langs->transcountry(($lttype==2?"LT2Payment":"LT1Payment"),$mysoc->country_code)).'"></td></tr>';
182 
183  // Amount
184  print '<tr><td class="fieldrequired">'.$langs->trans("Amount").'</td><td><input name="amount" size="10" value="'.GETPOST("amount").'"></td></tr>';
185 
186  if (! empty($conf->banque->enabled))
187  {
188  print '<tr><td class="fieldrequired">'.$langs->trans("Account").'</td><td>';
189  $form->select_comptes($_POST["accountid"],"accountid",0,"courant=1",1); // Affiche liste des comptes courant
190  print '</td></tr>';
191 
192  print '<tr><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td>';
193  $form->select_types_paiements(GETPOST("paiementtype"), "paiementtype");
194  print "</td>\n";
195  print "</tr>";
196 
197  // Number
198  print '<tr><td>'.$langs->trans('Numero');
199  print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
200  print '<td><input name="num_payment" type="text" value="'.GETPOST("num_payment").'"></td></tr>'."\n";
201  }
202  // Other attributes
203  $parameters=array();
204  $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
205  print $hookmanager->resPrint;
206 
207  print '</table>';
208 
209  dol_fiche_end();
210 
211  print '<div class="center">';
212  print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
213  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
214  print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
215  print '</div>';
216 
217  print '</form>';
218 }
219 
220 
221 /* ************************************************************************** */
222 /* */
223 /* Barre d'action */
224 /* */
225 /* ************************************************************************** */
226 
227 if ($id)
228 {
229  $h = 0;
230  $head[$h][0] = DOL_URL_ROOT.'/compta/localtax/card.php?id='.$vatpayment->id;
231  $head[$h][1] = $langs->trans('Card');
232  $head[$h][2] = 'card';
233  $h++;
234 
235  dol_fiche_head($head, 'card', $langs->trans("VATPayment"), 0, 'payment');
236 
237 
238  print '<table class="border" width="100%">';
239 
240  print "<tr>";
241  print '<td width="25%">'.$langs->trans("Ref").'</td><td>';
242  print $vatpayment->ref;
243  print '</td></tr>';
244 
245  print "<tr>";
246  print '<td>'.$langs->trans("DatePayment").'</td><td>';
247  print dol_print_date($vatpayment->datep,'day');
248  print '</td></tr>';
249 
250  print '<tr><td>'.$langs->trans("DateValue").'</td><td>';
251  print dol_print_date($vatpayment->datev,'day');
252  print '</td></tr>';
253 
254  print '<tr><td>'.$langs->trans("Amount").'</td><td>'.price($vatpayment->amount).'</td></tr>';
255 
256  if (! empty($conf->banque->enabled))
257  {
258  if ($vatpayment->fk_account > 0)
259  {
260  $bankline=new AccountLine($db);
261  $bankline->fetch($vatpayment->fk_bank);
262 
263  print '<tr>';
264  print '<td>'.$langs->trans('BankTransactionLine').'</td>';
265  print '<td>';
266  print $bankline->getNomUrl(1,0,'showall');
267  print '</td>';
268  print '</tr>';
269  }
270  }
271 
272  // Other attributes
273  $parameters=array();
274  $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$vatpayment,$action); // Note that $action and $object may have been modified by hook
275  print $hookmanager->resPrint;
276 
277  print '</table>';
278 
279  dol_fiche_end();
280 
281 
282  /*
283  * Boutons d'actions
284  */
285  print "<div class=\"tabsAction\">\n";
286  if ($vatpayment->rappro == 0)
287  print '<a class="butActionDelete" href="card.php?id='.$vatpayment->id.'&action=delete">'.$langs->trans("Delete").'</a>';
288  else
289  print '<a class="butActionRefused" href="#" title="'.$langs->trans("LinkedToAConcialitedTransaction").'">'.$langs->trans("Delete").'</a>';
290  print "</div>";
291 }
292 
293 llxFooter();
294 $db->close();
295 
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.
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
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.
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
Class to manage local tax.
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