dolibarr 25.0.0-alpha
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-2026 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
6 * Copyright (C) 2026 Jose Martinez <jose.martinez@pichinov.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Load Dolibarr environment
29require '../../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.'/compta/localtax/class/localtax.class.php';
31require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/vat.lib.php';
33
43// Load translation files required by the page
44$langs->loadLangs(array('compta', 'banks', 'bills'));
45
46$id = GETPOSTINT("id");
47$action = GETPOST("action", "aZ09");
48$cancel = GETPOST('cancel', 'alpha');
49
50$refund = GETPOSTINT("refund");
51if (empty($refund)) {
52 $refund = 0;
53}
54
55$lttype = GETPOSTINT('localTaxType');
56
57// Security check
58$socid = GETPOSTINT('socid');
59if ($user->socid) {
60 $socid = $user->socid;
61}
62// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
63$hookmanager->initHooks(array('localtaxvatcard', 'globalcard'));
64
65$result = restrictedArea($user, 'tax', '', '', 'charges');
66
67$object = new Localtax($db);
68
69$permissiontoadd = $user->hasRight('tax', 'charges', 'creer');
70$permissiontodelete = $user->hasRight('tax', 'charges', 'supprimer');
71
72
77if ($cancel && !$id) {
78 header("Location: list.php?localTaxType=".$lttype);
79 exit;
80}
81
82if ($action == 'add' && !$cancel && $permissiontoadd) {
83 $db->begin();
84
85 $datev = dol_mktime(12, 0, 0, GETPOSTINT("datevmonth"), GETPOSTINT("datevday"), GETPOSTINT("datevyear"));
86 $datep = dol_mktime(12, 0, 0, GETPOSTINT("datepmonth"), GETPOSTINT("datepday"), GETPOSTINT("datepyear"));
87
88 $object->accountid = GETPOSTINT("accountid");
89 $object->paymenttype = GETPOST("paiementtype");
90 $object->datev = $datev;
91 $object->datep = $datep;
92 $object->amount = price2num(GETPOST("amount"));
93 $object->label = GETPOST("label");
94 $object->ltt = $lttype;
95
96 $ret = $object->addPayment($user);
97 if ($ret > 0) {
98 $db->commit();
99 header("Location: list.php?localTaxType=".$lttype);
100 exit;
101 } else {
102 $db->rollback();
103 setEventMessages($object->error, $object->errors, 'errors');
104 $action = "create";
105 }
106}
107
108//delete payment of localtax
109if ($action == 'delete' && $permissiontodelete) {
110 $result = $object->fetch($id);
111
112 if ($object->rappro == 0) {
113 $db->begin();
114
115 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
116 $ret = $object->delete($user);
117 if ($ret > 0) {
118 if ($object->fk_bank) {
119 $accountline = new AccountLine($db);
120 $result = $accountline->fetch($object->fk_bank);
121 if ($result > 0) {
122 $result = $accountline->delete($user); // $result may be 0 if not found (when bank entry was deleted manually and fk_bank point to nothing)
123 }
124 } else {
125 $accountline = null;
126 }
127
128 if ($result >= 0) {
129 $db->commit();
130 header("Location: ".DOL_URL_ROOT.'/compta/localtax/list.php?localTaxType='.$object->ltt);
131 exit;
132 } else {
133 $object->error = $accountline !== null ? $accountline->error : "No account line / no bank identified found";
134 $db->rollback();
135 setEventMessages($object->error, $object->errors, 'errors');
136 }
137 } else {
138 $db->rollback();
139 setEventMessages($object->error, $object->errors, 'errors');
140 }
141 } else {
142 $mesg = 'Error try do delete a line linked to a conciliated bank transaction';
143 setEventMessages($mesg, null, 'errors');
144 }
145}
146
147
148/*
149 * View
150 */
151
152$form = new Form($db);
153
154if ($id) {
155 $result = $object->fetch($id);
156 if ($result <= 0) {
158 }
159}
160
161$title = $langs->trans("LT".$object->ltt)." - ".$langs->trans("Card");
162$help_url = '';
163llxHeader('', $title, $help_url);
164
165if ($action == 'create') {
166 $datev = dol_mktime(12, 0, 0, GETPOSTINT("datevmonth"), GETPOSTINT("datevday"), GETPOSTINT("datevyear"));
167 $datep = dol_mktime(12, 0, 0, GETPOSTINT("datepmonth"), GETPOSTINT("datepday"), GETPOSTINT("datepyear"));
168
169 print load_fiche_titre($langs->transcountry($lttype == 2 ? "newLT2Payment" : "newLT1Payment", $mysoc->country_code));
170
171 print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" name="formlocaltax" method="post">'."\n";
172 print '<input type="hidden" name="token" value="'.newToken().'">';
173 print '<input type="hidden" name="localTaxType" value="'.$lttype.'">';
174 print '<input type="hidden" name="action" value="add">';
175
176 print dol_get_fiche_head();
177
178 print '<table class="border centpercent">';
179
180 // Date of payment
181 print "<tr>";
182 print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("DatePayment").'</td><td>';
183 print $form->selectDate($datep, "datep", 0, 0, 0, 'add', 1, 1);
184 print '</td></tr>';
185
186 // End date of period
187 print '<tr><td class="fieldrequired">'.$form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo")).'</td><td>';
188 print $form->selectDate($datev, "datev", 0, 0, 0, 'add', 1, 1);
189 print '</td></tr>';
190
191 // Label
192 print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td><input name="label" class="minwidth200" value="'.(GETPOSTISSET("label") ? GETPOST("label", 'alphanohtml', 2) : $langs->transcountry(($lttype == 2 ? "LT2Payment" : "LT1Payment"), $mysoc->country_code)).'"></td></tr>';
193
194 // Amount
195 print '<tr><td class="fieldrequired">'.$langs->trans("Amount").'</td><td><input name="amount" size="10" value="'.GETPOST("amount").'"></td></tr>';
196
197 if (isModEnabled("bank")) {
198 // Type payment
199 print '<tr><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td>';
200 print $form->select_types_paiements(GETPOST("paiementtype"), "paiementtype", '', 0, 1, 0, 0, 1, 'maxwidth500 widthcentpercentminusx', 1);
201 print "</td>\n";
202 print "</tr>";
203
204 // Bank account
205 print '<tr><td class="fieldrequired" id="label_fk_account">'.$langs->trans("BankAccount").'</td><td>';
206 print img_picto('', 'bank_account', 'class="pictofixedwidth"');
207 $form->select_comptes(GETPOSTINT("accountid"), "accountid", 0, "(courant:=:1)", 2, '', 0, 'maxwidth500 widthcentpercentminusx'); // Affiche liste des comptes courant
208 print '</td></tr>';
209
210 // Number
211 print '<tr><td>'.$langs->trans('Numero');
212 print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
213 print '<td><input name="num_payment" type="text" value="'.GETPOST("num_payment").'"></td></tr>'."\n";
214 }
215
216 // Other attributes
217 $parameters = array();
218 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
219 print $hookmanager->resPrint;
220
221 print '</table>';
222
223 print dol_get_fiche_end();
224
225 print $form->buttonsSaveCancel();
226
227 print '</form>';
228}
229
230
231// View mode
232if ($id) {
233 $h = 0;
234 $head = array();
235 $head[$h][0] = DOL_URL_ROOT.'/compta/localtax/card.php?id='.$object->id;
236 $head[$h][1] = $langs->trans('Card');
237 $head[$h][2] = 'card';
238 $h++;
239
240 print dol_get_fiche_head($head, 'card', $langs->transcountry("LT".$object->ltt, $mysoc->country_code), -1, 'payment');
241
242 $linkback = '<a href="'.DOL_URL_ROOT.'/compta/localtax/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
243
244 dol_banner_tab($object, 'id', $linkback);
245
246 print '<div class="fichecenter">';
247 print '<div class="underbanner clearboth"></div>';
248
249 print '<table class="border centpercent">';
250
251 print "<tr>";
252 print '<td class="titlefield">'.$langs->trans("Ref").'</td><td>';
253 print $object->ref;
254 print '</td></tr>';
255
256 print "<tr>";
257 print '<td>'.$langs->trans("DatePayment").'</td><td>';
258 print dol_print_date($object->datep, 'day');
259 print '</td></tr>';
260
261 print '<tr><td>'.$form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo")).'</td><td>';
262 print dol_print_date($object->datev, 'day');
263 print '</td></tr>';
264
265 print '<tr><td>'.$langs->trans("Amount").'</td><td>'.price($object->amount).'</td></tr>';
266
267 if (isModEnabled("bank")) {
268 if ($object->fk_account > 0) {
269 $bankline = new AccountLine($db);
270 $bankline->fetch($object->fk_bank);
271
272 print '<tr>';
273 print '<td>'.$langs->trans('BankTransactionLine').'</td>';
274 print '<td>';
275 print $bankline->getNomUrl(1, 0, 'showall');
276 print '</td>';
277 print '</tr>';
278 }
279 }
280
281 // Other attributes
282 $parameters = array();
283 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
284 print $hookmanager->resPrint;
285
286 print '</table>';
287
288 print '</div>';
289
290 print dol_get_fiche_end();
291
292
293 /*
294 * Action bar
295 */
296 print "<div class=\"tabsAction\">\n";
297 if ($object->rappro == 0) {
298 print dolGetButtonAction($langs->trans("Delete"), $langs->trans("Delete"), 'delete', 'card.php?id='.$object->id.'&action=delete&token='.newToken(), '', true, array('attr' => array('class' => 'reposition')))."\n";
299 } else {
300 print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("LinkedToAConcialitedTransaction").'">'.$langs->trans("Delete").'</a>';
301 }
302 print "</div>";
303}
304
305// End of page
306llxFooter();
307$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage bank transaction lines.
Class to manage generation of HTML components Only common components must be here.
Class to manage local tax.
global $mysoc
recordNotFound($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Displays an error page when a record is not found.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:540
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:738
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.