dolibarr  9.0.0
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  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
26 require '../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/compta/localtax/class/localtax.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/vat.lib.php';
30 
31 // Load translation files required by the page
32 $langs->loadLangs(array('compta', 'banks', 'bills'));
33 
34 $id=GETPOST("id",'int');
35 $action=GETPOST("action","alpha");
36 $refund=GETPOST("refund","int");
37 if (empty($refund)) $refund=0;
38 
39 $lttype=GETPOST('localTaxType', 'int');
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 Localtax($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('localtaxvatcard','globalcard'));
50 
51 
56 if ($_POST["cancel"] == $langs->trans("Cancel") && ! $id)
57 {
58  header("Location: list.php?localTaxType=".$lttype);
59  exit;
60 }
61 
62 if ($action == 'add' && $_POST["cancel"] <> $langs->trans("Cancel"))
63 {
64 
65  $db->begin();
66 
67  $datev=dol_mktime(12,0,0, $_POST["datevmonth"], $_POST["datevday"], $_POST["datevyear"]);
68  $datep=dol_mktime(12,0,0, $_POST["datepmonth"], $_POST["datepday"], $_POST["datepyear"]);
69 
70  $object->accountid=GETPOST("accountid");
71  $object->paymenttype=GETPOST("paiementtype");
72  $object->datev=$datev;
73  $object->datep=$datep;
74  $object->amount=price2num(GETPOST("amount"));
75  $object->label=GETPOST("label");
76  $object->ltt=$lttype;
77 
78  $ret=$object->addPayment($user);
79  if ($ret > 0)
80  {
81  $db->commit();
82  header("Location: list.php?localTaxType=".$lttype);
83  exit;
84  }
85  else
86  {
87  $db->rollback();
88  setEventMessages($object->error, $object->errors, 'errors');
89  $_GET["action"]="create";
90  }
91 }
92 
93 //delete payment of localtax
94 if ($action == 'delete')
95 {
96  $result=$object->fetch($id);
97 
98  if ($object->rappro == 0)
99  {
100  $db->begin();
101 
102  $ret=$object->delete($user);
103  if ($ret > 0)
104  {
105  if ($object->fk_bank)
106  {
107  $accountline=new AccountLine($db);
108  $result=$accountline->fetch($object->fk_bank);
109  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)
110  }
111 
112  if ($result >= 0)
113  {
114  $db->commit();
115  header("Location: ".DOL_URL_ROOT.'/compta/localtax/list.php?localTaxType='.$object->ltt);
116  exit;
117  }
118  else
119  {
120  $object->error=$accountline->error;
121  $db->rollback();
122  setEventMessages($object->error, $object->errors, 'errors');
123  }
124  }
125  else
126  {
127  $db->rollback();
128  setEventMessages($object->error, $object->errors, 'errors');
129  }
130  }
131  else
132  {
133  $mesg='Error try do delete a line linked to a conciliated bank transaction';
134  setEventMessages($mesg, null, 'errors');
135  }
136 }
137 
138 
139 /*
140  * View
141  */
142 
143 if ($id)
144 {
145  $result = $object->fetch($id);
146  if ($result <= 0)
147  {
148  dol_print_error($db);
149  exit;
150  }
151 }
152 
153 $form = new Form($db);
154 
155 $title=$langs->trans("LT".$object->ltt) . " - " . $langs->trans("Card");
156 $help_url='';
157 llxHeader("",$title,$helpurl);
158 
159 
160 
161 if ($action == 'create')
162 {
163  print load_fiche_titre($langs->transcountry($lttype==2?"newLT2Payment":"newLT1Payment",$mysoc->country_code));
164 
165  print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" name="formlocaltax" method="post">'."\n";
166  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
167  print '<input type="hidden" name="localTaxType" value="'.$lttype.'">';
168  print '<input type="hidden" name="action" value="add">';
169 
170  dol_fiche_head();
171 
172  print '<table class="border" width="100%">';
173 
174  print "<tr>";
175  print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("DatePayment").'</td><td>';
176  print $form->selectDate($datep, "datep", '', '', '', 'add', 1, 1);
177  print '</td></tr>';
178 
179  print '<tr><td class="fieldrequired">'.$form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo")).'</td><td>';
180  print $form->selectDate($datev, "datev", '', '', '', 'add', 1, 1);
181  print '</td></tr>';
182 
183  // Label
184  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>';
185 
186  // Amount
187  print '<tr><td class="fieldrequired">'.$langs->trans("Amount").'</td><td><input name="amount" size="10" value="'.GETPOST("amount").'"></td></tr>';
188 
189  if (! empty($conf->banque->enabled))
190  {
191  print '<tr><td class="fieldrequired">'.$langs->trans("Account").'</td><td>';
192  $form->select_comptes($_POST["accountid"],"accountid",0,"courant=1",1); // Affiche liste des comptes courant
193  print '</td></tr>';
194 
195  print '<tr><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td>';
196  $form->select_types_paiements(GETPOST("paiementtype"), "paiementtype");
197  print "</td>\n";
198  print "</tr>";
199 
200  // Number
201  print '<tr><td>'.$langs->trans('Numero');
202  print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
203  print '<td><input name="num_payment" type="text" value="'.GETPOST("num_payment").'"></td></tr>'."\n";
204  }
205  // Other attributes
206  $parameters=array();
207  $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
208  print $hookmanager->resPrint;
209 
210  print '</table>';
211 
212  dol_fiche_end();
213 
214  print '<div class="center">';
215  print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
216  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
217  print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
218  print '</div>';
219 
220  print '</form>';
221 }
222 
223 
224 // View mode
225 if ($id)
226 {
227  $h = 0;
228  $head[$h][0] = DOL_URL_ROOT.'/compta/localtax/card.php?id='.$object->id;
229  $head[$h][1] = $langs->trans('Card');
230  $head[$h][2] = 'card';
231  $h++;
232 
233  dol_fiche_head($head, 'card', $langs->transcountry("LT".$object->ltt, $mysoc->country_code), -1, 'payment');
234 
235  $linkback = '<a href="'.DOL_URL_ROOT.'/compta/localtax/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
236 
237  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', '');
238 
239  print '<div class="fichecenter">';
240  print '<div class="underbanner clearboth"></div>';
241 
242  print '<table class="border" width="100%">';
243 
244  print "<tr>";
245  print '<td class="titlefield">'.$langs->trans("Ref").'</td><td>';
246  print $object->ref;
247  print '</td></tr>';
248 
249  print "<tr>";
250  print '<td>'.$langs->trans("DatePayment").'</td><td>';
251  print dol_print_date($object->datep,'day');
252  print '</td></tr>';
253 
254  print '<tr><td>'.$form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo")).'</td><td>';
255  print dol_print_date($object->datev,'day');
256  print '</td></tr>';
257 
258  print '<tr><td>'.$langs->trans("Amount").'</td><td>'.price($object->amount).'</td></tr>';
259 
260  if (! empty($conf->banque->enabled))
261  {
262  if ($object->fk_account > 0)
263  {
264  $bankline=new AccountLine($db);
265  $bankline->fetch($object->fk_bank);
266 
267  print '<tr>';
268  print '<td>'.$langs->trans('BankTransactionLine').'</td>';
269  print '<td>';
270  print $bankline->getNomUrl(1,0,'showall');
271  print '</td>';
272  print '</tr>';
273  }
274  }
275 
276  // Other attributes
277  $parameters=array();
278  $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
279  print $hookmanager->resPrint;
280 
281  print '</table>';
282 
283  print '</div>';
284 
285  dol_fiche_end();
286 
287 
288  /*
289  * Action buttons
290  */
291  print "<div class=\"tabsAction\">\n";
292  if ($object->rappro == 0)
293  {
294  print '<a class="butActionDelete" href="card.php?id='.$object->id.'&action=delete">'.$langs->trans("Delete").'</a>';
295  }
296  else
297  {
298  print '<a class="butActionRefused" href="#" title="'.$langs->trans("LinkedToAConcialitedTransaction").'">'.$langs->trans("Delete").'</a>';
299  }
300  print "</div>";
301 }
302 
303 // End of page
304 llxFooter();
305 $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.
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_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...
Class to manage generation of HTML components Only common components must be here.
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).
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 local tax.
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