dolibarr 21.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-2024 Frédéric France <frederic.france@free.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
27require '../../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.'/compta/localtax/class/localtax.class.php';
29require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
30require_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 = GETPOSTINT("id");
36$action = GETPOST("action", "aZ09");
37$cancel = GETPOST('cancel', 'aZ09');
38
39$refund = GETPOSTINT("refund");
40if (empty($refund)) {
41 $refund = 0;
42}
43
44$lttype = GETPOSTINT('localTaxType');
45
46// Security check
47$socid = GETPOSTINT('socid');
48if ($user->socid) {
49 $socid = $user->socid;
50}
51// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
52$hookmanager->initHooks(array('localtaxvatcard', 'globalcard'));
53
54$result = restrictedArea($user, 'tax', '', '', 'charges');
55
56$object = new Localtax($db);
57
58$permissiontoadd = $user->hasRight('tax', 'charges', 'creer');
59$permissiontodelete = $user->hasRight('tax', 'charges', 'supprimer');
60
61
66if ($cancel && !$id) {
67 header("Location: list.php?localTaxType=".$lttype);
68 exit;
69}
70
71if ($action == 'add' && !$cancel && $permissiontoadd) {
72 $db->begin();
73
74 $datev = dol_mktime(12, 0, 0, GETPOST("datevmonth"), GETPOST("datevday"), GETPOST("datevyear"));
75 $datep = dol_mktime(12, 0, 0, GETPOST("datepmonth"), GETPOST("datepday"), GETPOST("datepyear"));
76
77 $object->accountid = GETPOSTINT("accountid");
78 $object->paymenttype = GETPOST("paiementtype");
79 $object->datev = $datev;
80 $object->datep = $datep;
81 $object->amount = price2num(GETPOST("amount"));
82 $object->label = GETPOST("label");
83 $object->ltt = $lttype;
84
85 $ret = $object->addPayment($user);
86 if ($ret > 0) {
87 $db->commit();
88 header("Location: list.php?localTaxType=".$lttype);
89 exit;
90 } else {
91 $db->rollback();
92 setEventMessages($object->error, $object->errors, 'errors');
93 $action = "create";
94 }
95}
96
97//delete payment of localtax
98if ($action == 'delete' && $permissiontodelete) {
99 $result = $object->fetch($id);
100
101 if ($object->rappro == 0) {
102 $db->begin();
103
104 $ret = $object->delete($user);
105 if ($ret > 0) {
106 if ($object->fk_bank) {
107 $accountline = new AccountLine($db);
108 $result = $accountline->fetch($object->fk_bank);
109 if ($result > 0) {
110 $result = $accountline->delete($user); // $result may be 0 if not found (when bank entry was deleted manually and fk_bank point to nothing)
111 }
112 }
113
114 if ($result >= 0) {
115 $db->commit();
116 header("Location: ".DOL_URL_ROOT.'/compta/localtax/list.php?localTaxType='.$object->ltt);
117 exit;
118 } else {
119 $object->error = $accountline->error;
120 $db->rollback();
121 setEventMessages($object->error, $object->errors, 'errors');
122 }
123 } else {
124 $db->rollback();
125 setEventMessages($object->error, $object->errors, 'errors');
126 }
127 } else {
128 $mesg = 'Error try do delete a line linked to a conciliated bank transaction';
129 setEventMessages($mesg, null, 'errors');
130 }
131}
132
133
134/*
135 * View
136 */
137
138$form = new Form($db);
139
140if ($id) {
141 $result = $object->fetch($id);
142 if ($result <= 0) {
143 dol_print_error($db);
144 exit;
145 }
146}
147
148$title = $langs->trans("LT".$object->ltt)." - ".$langs->trans("Card");
149$help_url = '';
150llxHeader('', $title, $help_url);
151
152if ($action == 'create') {
153 $datev = dol_mktime(12, 0, 0, GETPOST("datevmonth"), GETPOST("datevday"), GETPOST("datevyear"));
154 $datep = dol_mktime(12, 0, 0, GETPOST("datepmonth"), GETPOST("datepday"), GETPOST("datepyear"));
155
156 print load_fiche_titre($langs->transcountry($lttype == 2 ? "newLT2Payment" : "newLT1Payment", $mysoc->country_code));
157
158 print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" name="formlocaltax" method="post">'."\n";
159 print '<input type="hidden" name="token" value="'.newToken().'">';
160 print '<input type="hidden" name="localTaxType" value="'.$lttype.'">';
161 print '<input type="hidden" name="action" value="add">';
162
163 print dol_get_fiche_head();
164
165 print '<table class="border centpercent">';
166
167 // Date of payment
168 print "<tr>";
169 print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("DatePayment").'</td><td>';
170 print $form->selectDate($datep, "datep", 0, 0, 0, 'add', 1, 1);
171 print '</td></tr>';
172
173 // End date of period
174 print '<tr><td class="fieldrequired">'.$form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo")).'</td><td>';
175 print $form->selectDate($datev, "datev", 0, 0, 0, 'add', 1, 1);
176 print '</td></tr>';
177
178 // Label
179 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>';
180
181 // Amount
182 print '<tr><td class="fieldrequired">'.$langs->trans("Amount").'</td><td><input name="amount" size="10" value="'.GETPOST("amount").'"></td></tr>';
183
184 if (isModEnabled("bank")) {
185 // Type payment
186 print '<tr><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td>';
187 print $form->select_types_paiements(GETPOST("paiementtype"), "paiementtype", '', 0, 1, 0, 0, 1, 'maxwidth500 widthcentpercentminusx', 1);
188 print "</td>\n";
189 print "</tr>";
190
191 // Bank account
192 print '<tr><td class="fieldrequired" id="label_fk_account">'.$langs->trans("BankAccount").'</td><td>';
193 print img_picto('', 'bank_account', 'class="pictofixedwidth"');
194 $form->select_comptes(GETPOSTINT("accountid"), "accountid", 0, "courant=1", 2, '', 0, 'maxwidth500 widthcentpercentminusx'); // Affiche liste des comptes courant
195 print '</td></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
203 // Other attributes
204 $parameters = array();
205 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
206 print $hookmanager->resPrint;
207
208 print '</table>';
209
210 print dol_get_fiche_end();
211
212 print $form->buttonsSaveCancel();
213
214 print '</form>';
215}
216
217
218// View mode
219if ($id) {
220 $h = 0;
221 $head = array();
222 $head[$h][0] = DOL_URL_ROOT.'/compta/localtax/card.php?id='.$object->id;
223 $head[$h][1] = $langs->trans('Card');
224 $head[$h][2] = 'card';
225 $h++;
226
227 print dol_get_fiche_head($head, 'card', $langs->transcountry("LT".$object->ltt, $mysoc->country_code), -1, 'payment');
228
229 $linkback = '<a href="'.DOL_URL_ROOT.'/compta/localtax/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
230
231 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', '');
232
233 print '<div class="fichecenter">';
234 print '<div class="underbanner clearboth"></div>';
235
236 print '<table class="border centpercent">';
237
238 print "<tr>";
239 print '<td class="titlefield">'.$langs->trans("Ref").'</td><td>';
240 print $object->ref;
241 print '</td></tr>';
242
243 print "<tr>";
244 print '<td>'.$langs->trans("DatePayment").'</td><td>';
245 print dol_print_date($object->datep, 'day');
246 print '</td></tr>';
247
248 print '<tr><td>'.$form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo")).'</td><td>';
249 print dol_print_date($object->datev, 'day');
250 print '</td></tr>';
251
252 print '<tr><td>'.$langs->trans("Amount").'</td><td>'.price($object->amount).'</td></tr>';
253
254 if (isModEnabled("bank")) {
255 if ($object->fk_account > 0) {
256 $bankline = new AccountLine($db);
257 $bankline->fetch($object->fk_bank);
258
259 print '<tr>';
260 print '<td>'.$langs->trans('BankTransactionLine').'</td>';
261 print '<td>';
262 print $bankline->getNomUrl(1, 0, 'showall');
263 print '</td>';
264 print '</tr>';
265 }
266 }
267
268 // Other attributes
269 $parameters = array();
270 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
271 print $hookmanager->resPrint;
272
273 print '</table>';
274
275 print '</div>';
276
277 print dol_get_fiche_end();
278
279
280 /*
281 * Action bar
282 */
283 print "<div class=\"tabsAction\">\n";
284 if ($object->rappro == 0) {
285 print '<a class="butActionDelete" href="card.php?id='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans("Delete").'</a>';
286 } else {
287 print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("LinkedToAConcialitedTransaction").'">'.$langs->trans("Delete").'</a>';
288 }
289 print "</div>";
290}
291
292// End of page
293llxFooter();
294$db->close();
$id
Definition account.php:39
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
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:70
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.