dolibarr 21.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 * Copyright (C) 2018-2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.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 <https://www.gnu.org/licenses/>.
19 */
20
27// Load Dolibarr environment
28require '../../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/compta/localtax/class/localtax.class.php';
30require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/vat.lib.php';
32
42// Load translation files required by the page
43$langs->loadLangs(array('compta', 'banks', 'bills'));
44
45$id = GETPOSTINT("id");
46$action = GETPOST("action", "aZ09");
47$cancel = GETPOST('cancel', 'aZ09');
48
49$refund = GETPOSTINT("refund");
50if (empty($refund)) {
51 $refund = 0;
52}
53
54$lttype = GETPOSTINT('localTaxType');
55
56// Security check
57$socid = GETPOSTINT('socid');
58if ($user->socid) {
59 $socid = $user->socid;
60}
61// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
62$hookmanager->initHooks(array('localtaxvatcard', 'globalcard'));
63
64$result = restrictedArea($user, 'tax', '', '', 'charges');
65
66$object = new Localtax($db);
67
68$permissiontoadd = $user->hasRight('tax', 'charges', 'creer');
69$permissiontodelete = $user->hasRight('tax', 'charges', 'supprimer');
70
71
76if ($cancel && !$id) {
77 header("Location: list.php?localTaxType=".$lttype);
78 exit;
79}
80
81if ($action == 'add' && !$cancel && $permissiontoadd) {
82 $db->begin();
83
84 $datev = dol_mktime(12, 0, 0, GETPOSTINT("datevmonth"), GETPOSTINT("datevday"), GETPOSTINT("datevyear"));
85 $datep = dol_mktime(12, 0, 0, GETPOSTINT("datepmonth"), GETPOSTINT("datepday"), GETPOSTINT("datepyear"));
86
87 $object->accountid = GETPOSTINT("accountid");
88 $object->paymenttype = GETPOST("paiementtype");
89 $object->datev = $datev;
90 $object->datep = $datep;
91 $object->amount = price2num(GETPOST("amount"));
92 $object->label = GETPOST("label");
93 $object->ltt = $lttype;
94
95 $ret = $object->addPayment($user);
96 if ($ret > 0) {
97 $db->commit();
98 header("Location: list.php?localTaxType=".$lttype);
99 exit;
100 } else {
101 $db->rollback();
102 setEventMessages($object->error, $object->errors, 'errors');
103 $action = "create";
104 }
105}
106
107//delete payment of localtax
108if ($action == 'delete' && $permissiontodelete) {
109 $result = $object->fetch($id);
110
111 if ($object->rappro == 0) {
112 $db->begin();
113
114 $ret = $object->delete($user);
115 if ($ret > 0) {
116 if ($object->fk_bank) {
117 $accountline = new AccountLine($db);
118 $result = $accountline->fetch($object->fk_bank);
119 if ($result > 0) {
120 $result = $accountline->delete($user); // $result may be 0 if not found (when bank entry was deleted manually and fk_bank point to nothing)
121 }
122 } else {
123 $accountline = null;
124 }
125
126 if ($result >= 0) {
127 $db->commit();
128 header("Location: ".DOL_URL_ROOT.'/compta/localtax/list.php?localTaxType='.$object->ltt);
129 exit;
130 } else {
131 $object->error = $accountline !== null ? $accountline->error : "No account line / no bank identified found";
132 $db->rollback();
133 setEventMessages($object->error, $object->errors, 'errors');
134 }
135 } else {
136 $db->rollback();
137 setEventMessages($object->error, $object->errors, 'errors');
138 }
139 } else {
140 $mesg = 'Error try do delete a line linked to a conciliated bank transaction';
141 setEventMessages($mesg, null, 'errors');
142 }
143}
144
145
146/*
147 * View
148 */
149
150$form = new Form($db);
151
152if ($id) {
153 $result = $object->fetch($id);
154 if ($result <= 0) {
155 dol_print_error($db);
156 exit;
157 }
158}
159
160$title = $langs->trans("LT".$object->ltt)." - ".$langs->trans("Card");
161$help_url = '';
162llxHeader('', $title, $help_url);
163
164if ($action == 'create') {
165 $datev = dol_mktime(12, 0, 0, GETPOSTINT("datevmonth"), GETPOSTINT("datevday"), GETPOSTINT("datevyear"));
166 $datep = dol_mktime(12, 0, 0, GETPOSTINT("datepmonth"), GETPOSTINT("datepday"), GETPOSTINT("datepyear"));
167
168 print load_fiche_titre($langs->transcountry($lttype == 2 ? "newLT2Payment" : "newLT1Payment", $mysoc->country_code));
169
170 print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" name="formlocaltax" method="post">'."\n";
171 print '<input type="hidden" name="token" value="'.newToken().'">';
172 print '<input type="hidden" name="localTaxType" value="'.$lttype.'">';
173 print '<input type="hidden" name="action" value="add">';
174
175 print dol_get_fiche_head();
176
177 print '<table class="border centpercent">';
178
179 // Date of payment
180 print "<tr>";
181 print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("DatePayment").'</td><td>';
182 print $form->selectDate($datep, "datep", 0, 0, 0, 'add', 1, 1);
183 print '</td></tr>';
184
185 // End date of period
186 print '<tr><td class="fieldrequired">'.$form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo")).'</td><td>';
187 print $form->selectDate($datev, "datev", 0, 0, 0, 'add', 1, 1);
188 print '</td></tr>';
189
190 // Label
191 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>';
192
193 // Amount
194 print '<tr><td class="fieldrequired">'.$langs->trans("Amount").'</td><td><input name="amount" size="10" value="'.GETPOST("amount").'"></td></tr>';
195
196 if (isModEnabled("bank")) {
197 // Type payment
198 print '<tr><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td>';
199 print $form->select_types_paiements(GETPOST("paiementtype"), "paiementtype", '', 0, 1, 0, 0, 1, 'maxwidth500 widthcentpercentminusx', 1);
200 print "</td>\n";
201 print "</tr>";
202
203 // Bank account
204 print '<tr><td class="fieldrequired" id="label_fk_account">'.$langs->trans("BankAccount").'</td><td>';
205 print img_picto('', 'bank_account', 'class="pictofixedwidth"');
206 $form->select_comptes(GETPOSTINT("accountid"), "accountid", 0, "courant=1", 2, '', 0, 'maxwidth500 widthcentpercentminusx'); // Affiche liste des comptes courant
207 print '</td></tr>';
208
209 // Number
210 print '<tr><td>'.$langs->trans('Numero');
211 print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
212 print '<td><input name="num_payment" type="text" value="'.GETPOST("num_payment").'"></td></tr>'."\n";
213 }
214
215 // Other attributes
216 $parameters = array();
217 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
218 print $hookmanager->resPrint;
219
220 print '</table>';
221
222 print dol_get_fiche_end();
223
224 print $form->buttonsSaveCancel();
225
226 print '</form>';
227}
228
229
230// View mode
231if ($id) {
232 $h = 0;
233 $head = array();
234 $head[$h][0] = DOL_URL_ROOT.'/compta/localtax/card.php?id='.$object->id;
235 $head[$h][1] = $langs->trans('Card');
236 $head[$h][2] = 'card';
237 $h++;
238
239 print dol_get_fiche_head($head, 'card', $langs->transcountry("LT".$object->ltt, $mysoc->country_code), -1, 'payment');
240
241 $linkback = '<a href="'.DOL_URL_ROOT.'/compta/localtax/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
242
243 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', '');
244
245 print '<div class="fichecenter">';
246 print '<div class="underbanner clearboth"></div>';
247
248 print '<table class="border centpercent">';
249
250 print "<tr>";
251 print '<td class="titlefield">'.$langs->trans("Ref").'</td><td>';
252 print $object->ref;
253 print '</td></tr>';
254
255 print "<tr>";
256 print '<td>'.$langs->trans("DatePayment").'</td><td>';
257 print dol_print_date($object->datep, 'day');
258 print '</td></tr>';
259
260 print '<tr><td>'.$form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo")).'</td><td>';
261 print dol_print_date($object->datev, 'day');
262 print '</td></tr>';
263
264 print '<tr><td>'.$langs->trans("Amount").'</td><td>'.price($object->amount).'</td></tr>';
265
266 if (isModEnabled("bank")) {
267 if ($object->fk_account > 0) {
268 $bankline = new AccountLine($db);
269 $bankline->fetch($object->fk_bank);
270
271 print '<tr>';
272 print '<td>'.$langs->trans('BankTransactionLine').'</td>';
273 print '<td>';
274 print $bankline->getNomUrl(1, 0, 'showall');
275 print '</td>';
276 print '</tr>';
277 }
278 }
279
280 // Other attributes
281 $parameters = array();
282 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
283 print $hookmanager->resPrint;
284
285 print '</table>';
286
287 print '</div>';
288
289 print dol_get_fiche_end();
290
291
292 /*
293 * Action bar
294 */
295 print "<div class=\"tabsAction\">\n";
296 if ($object->rappro == 0) {
297 print '<a class="butActionDelete" href="card.php?id='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans("Delete").'</a>';
298 } else {
299 print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("LinkedToAConcialitedTransaction").'">'.$langs->trans("Delete").'</a>';
300 }
301 print "</div>";
302}
303
304// End of page
305llxFooter();
306$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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:71
Class to manage bank transaction lines.
Class to manage generation of HTML components Only common components must be here.
Class to manage local tax.
llxFooter()
Footer empty.
Definition document.php:107
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...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.