dolibarr  17.0.3
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 <https://www.gnu.org/licenses/>.
18  */
19 
26 // Load Dolibarr environment
27 require '../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/compta/localtax/class/localtax.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 // Load translation files required by the page
33 $langs->loadLangs(array('compta', 'banks', 'bills'));
34 
35 $id = GETPOST("id", 'int');
36 $action = GETPOST("action", "aZ09");
37 $cancel = GETPOST('cancel', 'aZ09');
38 
39 $refund = GETPOST("refund", "int");
40 if (empty($refund)) {
41  $refund = 0;
42 }
43 
44 $lttype = GETPOST('localTaxType', 'int');
45 
46 // Security check
47 $socid = GETPOST('socid', 'int');
48 if ($user->socid) {
49  $socid = $user->socid;
50 }
51 $result = restrictedArea($user, 'tax', '', '', 'charges');
52 
53 $object = new Localtax($db);
54 
55 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
56 $hookmanager->initHooks(array('localtaxvatcard', 'globalcard'));
57 
58 
63 if ($cancel && !$id) {
64  header("Location: list.php?localTaxType=".$lttype);
65  exit;
66 }
67 
68 if ($action == 'add' && !$cancel) {
69  $db->begin();
70 
71  $datev = dol_mktime(12, 0, 0, GETPOST("datevmonth"), GETPOST("datevday"), GETPOST("datevyear"));
72  $datep = dol_mktime(12, 0, 0, GETPOST("datepmonth"), GETPOST("datepday"), GETPOST("datepyear"));
73 
74  $object->accountid = GETPOST("accountid", 'int');
75  $object->paymenttype = GETPOST("paiementtype");
76  $object->datev = $datev;
77  $object->datep = $datep;
78  $object->amount = price2num(GETPOST("amount"));
79  $object->label = GETPOST("label");
80  $object->ltt = $lttype;
81 
82  $ret = $object->addPayment($user);
83  if ($ret > 0) {
84  $db->commit();
85  header("Location: list.php?localTaxType=".$lttype);
86  exit;
87  } else {
88  $db->rollback();
89  setEventMessages($object->error, $object->errors, 'errors');
90  $_GET["action"] = "create";
91  }
92 }
93 
94 //delete payment of localtax
95 if ($action == 'delete') {
96  $result = $object->fetch($id);
97 
98  if ($object->rappro == 0) {
99  $db->begin();
100 
101  $ret = $object->delete($user);
102  if ($ret > 0) {
103  if ($object->fk_bank) {
104  $accountline = new AccountLine($db);
105  $result = $accountline->fetch($object->fk_bank);
106  if ($result > 0) {
107  $result = $accountline->delete($user); // $result may be 0 if not found (when bank entry was deleted manually and fk_bank point to nothing)
108  }
109  }
110 
111  if ($result >= 0) {
112  $db->commit();
113  header("Location: ".DOL_URL_ROOT.'/compta/localtax/list.php?localTaxType='.$object->ltt);
114  exit;
115  } else {
116  $object->error = $accountline->error;
117  $db->rollback();
118  setEventMessages($object->error, $object->errors, 'errors');
119  }
120  } else {
121  $db->rollback();
122  setEventMessages($object->error, $object->errors, 'errors');
123  }
124  } else {
125  $mesg = 'Error try do delete a line linked to a conciliated bank transaction';
126  setEventMessages($mesg, null, 'errors');
127  }
128 }
129 
130 
131 /*
132  * View
133  */
134 
135 if ($id) {
136  $result = $object->fetch($id);
137  if ($result <= 0) {
138  dol_print_error($db);
139  exit;
140  }
141 }
142 
143 $form = new Form($db);
144 
145 $title = $langs->trans("LT".$object->ltt)." - ".$langs->trans("Card");
146 $help_url = '';
147 llxHeader('', $title, $helpurl);
148 
149 if ($action == 'create') {
150  print load_fiche_titre($langs->transcountry($lttype == 2 ? "newLT2Payment" : "newLT1Payment", $mysoc->country_code));
151 
152  print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" name="formlocaltax" method="post">'."\n";
153  print '<input type="hidden" name="token" value="'.newToken().'">';
154  print '<input type="hidden" name="localTaxType" value="'.$lttype.'">';
155  print '<input type="hidden" name="action" value="add">';
156 
157  print dol_get_fiche_head();
158 
159  print '<table class="border centpercent">';
160 
161  // Date of payment
162  print "<tr>";
163  print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("DatePayment").'</td><td>';
164  print $form->selectDate($datep, "datep", '', '', '', 'add', 1, 1);
165  print '</td></tr>';
166 
167  // End date of period
168  print '<tr><td class="fieldrequired">'.$form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo")).'</td><td>';
169  print $form->selectDate($datev, "datev", '', '', '', 'add', 1, 1);
170  print '</td></tr>';
171 
172  // Label
173  print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td><input name="label" class="minwidth200" value="'.(GETPOSTISSET("label") ? GETPOST("label", '', 2) : $langs->transcountry(($lttype == 2 ? "LT2Payment" : "LT1Payment"), $mysoc->country_code)).'"></td></tr>';
174 
175  // Amount
176  print '<tr><td class="fieldrequired">'.$langs->trans("Amount").'</td><td><input name="amount" size="10" value="'.GETPOST("amount").'"></td></tr>';
177 
178  if (isModEnabled("banque")) {
179  // Type payment
180  print '<tr><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td>';
181  print $form->select_types_paiements(GETPOST("paiementtype"), "paiementtype", '', 0, 1, 0, 0, 1, 'maxwidth500 widthcentpercentminusx', 1);
182  print "</td>\n";
183  print "</tr>";
184 
185  // Bank account
186  print '<tr><td class="fieldrequired" id="label_fk_account">'.$langs->trans("Account").'</td><td>';
187  print img_picto('', 'bank_account', 'pictofixedwidth');
188  $form->select_comptes(GETPOST("accountid", "int"), "accountid", 0, "courant=1", 2, '', 0, 'maxwidth500 widthcentpercentminusx'); // Affiche liste des comptes courant
189  print '</td></tr>';
190 
191  // Number
192  print '<tr><td>'.$langs->trans('Numero');
193  print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
194  print '<td><input name="num_payment" type="text" value="'.GETPOST("num_payment").'"></td></tr>'."\n";
195  }
196 
197  // Other attributes
198  $parameters = array();
199  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
200  print $hookmanager->resPrint;
201 
202  print '</table>';
203 
204  print dol_get_fiche_end();
205 
206  print $form->buttonsSaveCancel();
207 
208  print '</form>';
209 }
210 
211 
212 // View mode
213 if ($id) {
214  $h = 0;
215  $head[$h][0] = DOL_URL_ROOT.'/compta/localtax/card.php?id='.$object->id;
216  $head[$h][1] = $langs->trans('Card');
217  $head[$h][2] = 'card';
218  $h++;
219 
220  print dol_get_fiche_head($head, 'card', $langs->transcountry("LT".$object->ltt, $mysoc->country_code), -1, 'payment');
221 
222  $linkback = '<a href="'.DOL_URL_ROOT.'/compta/localtax/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
223 
224  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', '');
225 
226  print '<div class="fichecenter">';
227  print '<div class="underbanner clearboth"></div>';
228 
229  print '<table class="border centpercent">';
230 
231  print "<tr>";
232  print '<td class="titlefield">'.$langs->trans("Ref").'</td><td>';
233  print $object->ref;
234  print '</td></tr>';
235 
236  print "<tr>";
237  print '<td>'.$langs->trans("DatePayment").'</td><td>';
238  print dol_print_date($object->datep, 'day');
239  print '</td></tr>';
240 
241  print '<tr><td>'.$form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo")).'</td><td>';
242  print dol_print_date($object->datev, 'day');
243  print '</td></tr>';
244 
245  print '<tr><td>'.$langs->trans("Amount").'</td><td>'.price($object->amount).'</td></tr>';
246 
247  if (isModEnabled("banque")) {
248  if ($object->fk_account > 0) {
249  $bankline = new AccountLine($db);
250  $bankline->fetch($object->fk_bank);
251 
252  print '<tr>';
253  print '<td>'.$langs->trans('BankTransactionLine').'</td>';
254  print '<td>';
255  print $bankline->getNomUrl(1, 0, 'showall');
256  print '</td>';
257  print '</tr>';
258  }
259  }
260 
261  // Other attributes
262  $parameters = array();
263  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
264  print $hookmanager->resPrint;
265 
266  print '</table>';
267 
268  print '</div>';
269 
270  print dol_get_fiche_end();
271 
272 
273  /*
274  * Action bar
275  */
276  print "<div class=\"tabsAction\">\n";
277  if ($object->rappro == 0) {
278  print '<a class="butActionDelete" href="card.php?id='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans("Delete").'</a>';
279  } else {
280  print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("LinkedToAConcialitedTransaction").'">'.$langs->trans("Delete").'</a>';
281  }
282  print "</div>";
283 }
284 
285 // End of page
286 llxFooter();
287 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:70
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5360
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:520
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4993
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
dol_banner_tab
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.
Definition: functions.lib.php:2082
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:118
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5823
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2550
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:4024
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1858
restrictedArea
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
Definition: security.lib.php:346
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:11295
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2054
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:137
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:421
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:53
$parameters
$parameters
Actions.
Definition: card.php:79
AccountLine
Class to manage bank transaction lines.
Definition: account.class.php:1779
price
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.
Definition: functions.lib.php:5697
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8466
dol_mktime
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Definition: functions.lib.php:2863
Localtax
Class to manage local tax.
Definition: localtax.class.php:29