dolibarr  16.0.5
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 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", "aZ09");
36 $cancel = GETPOST('cancel', 'aZ09');
37 
38 $refund = GETPOST("refund", "int");
39 if (empty($refund)) {
40  $refund = 0;
41 }
42 
43 $lttype = GETPOST('localTaxType', 'int');
44 
45 // Security check
46 $socid = GETPOST('socid', 'int');
47 if ($user->socid) {
48  $socid = $user->socid;
49 }
50 $result = restrictedArea($user, 'tax', '', '', 'charges');
51 
52 $object = new Localtax($db);
53 
54 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
55 $hookmanager->initHooks(array('localtaxvatcard', 'globalcard'));
56 
57 
62 if ($cancel && !$id) {
63  header("Location: list.php?localTaxType=".$lttype);
64  exit;
65 }
66 
67 if ($action == 'add' && !$cancel) {
68  $db->begin();
69 
70  $datev = dol_mktime(12, 0, 0, GETPOST("datevmonth"), GETPOST("datevday"), GETPOST("datevyear"));
71  $datep = dol_mktime(12, 0, 0, GETPOST("datepmonth"), GETPOST("datepday"), GETPOST("datepyear"));
72 
73  $object->accountid = GETPOST("accountid", 'int');
74  $object->paymenttype = GETPOST("paiementtype");
75  $object->datev = $datev;
76  $object->datep = $datep;
77  $object->amount = price2num(GETPOST("amount"));
78  $object->label = GETPOST("label");
79  $object->ltt = $lttype;
80 
81  $ret = $object->addPayment($user);
82  if ($ret > 0) {
83  $db->commit();
84  header("Location: list.php?localTaxType=".$lttype);
85  exit;
86  } else {
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  $result = $object->fetch($id);
96 
97  if ($object->rappro == 0) {
98  $db->begin();
99 
100  $ret = $object->delete($user);
101  if ($ret > 0) {
102  if ($object->fk_bank) {
103  $accountline = new AccountLine($db);
104  $result = $accountline->fetch($object->fk_bank);
105  if ($result > 0) {
106  $result = $accountline->delete($user); // $result may be 0 if not found (when bank entry was deleted manually and fk_bank point to nothing)
107  }
108  }
109 
110  if ($result >= 0) {
111  $db->commit();
112  header("Location: ".DOL_URL_ROOT.'/compta/localtax/list.php?localTaxType='.$object->ltt);
113  exit;
114  } else {
115  $object->error = $accountline->error;
116  $db->rollback();
117  setEventMessages($object->error, $object->errors, 'errors');
118  }
119  } else {
120  $db->rollback();
121  setEventMessages($object->error, $object->errors, 'errors');
122  }
123  } else {
124  $mesg = 'Error try do delete a line linked to a conciliated bank transaction';
125  setEventMessages($mesg, null, 'errors');
126  }
127 }
128 
129 
130 /*
131  * View
132  */
133 
134 if ($id) {
135  $result = $object->fetch($id);
136  if ($result <= 0) {
137  dol_print_error($db);
138  exit;
139  }
140 }
141 
142 $form = new Form($db);
143 
144 $title = $langs->trans("LT".$object->ltt)." - ".$langs->trans("Card");
145 $help_url = '';
146 llxHeader('', $title, $helpurl);
147 
148 if ($action == 'create') {
149  print load_fiche_titre($langs->transcountry($lttype == 2 ? "newLT2Payment" : "newLT1Payment", $mysoc->country_code));
150 
151  print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" name="formlocaltax" method="post">'."\n";
152  print '<input type="hidden" name="token" value="'.newToken().'">';
153  print '<input type="hidden" name="localTaxType" value="'.$lttype.'">';
154  print '<input type="hidden" name="action" value="add">';
155 
156  print dol_get_fiche_head();
157 
158  print '<table class="border centpercent">';
159 
160  // Date of payment
161  print "<tr>";
162  print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("DatePayment").'</td><td>';
163  print $form->selectDate($datep, "datep", '', '', '', 'add', 1, 1);
164  print '</td></tr>';
165 
166  // End date of period
167  print '<tr><td class="fieldrequired">'.$form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo")).'</td><td>';
168  print $form->selectDate($datev, "datev", '', '', '', 'add', 1, 1);
169  print '</td></tr>';
170 
171  // Label
172  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>';
173 
174  // Amount
175  print '<tr><td class="fieldrequired">'.$langs->trans("Amount").'</td><td><input name="amount" size="10" value="'.GETPOST("amount").'"></td></tr>';
176 
177  if (isModEnabled('banque')) {
178  // Type payment
179  print '<tr><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td>';
180  $form->select_types_paiements(GETPOST("paiementtype"), "paiementtype", '', 0, 1, 0, 0, 1, 'maxwidth500 widthcentpercentminusx');
181  print "</td>\n";
182  print "</tr>";
183 
184  // Bank account
185  print '<tr><td class="fieldrequired" id="label_fk_account">'.$langs->trans("Account").'</td><td>';
186  print img_picto('', 'bank_account', 'pictofixedwidth');
187  $form->select_comptes(GETPOST("accountid", "int"), "accountid", 0, "courant=1", 2, '', 0, 'maxwidth500 widthcentpercentminusx'); // Affiche liste des comptes courant
188  print '</td></tr>';
189 
190  // Number
191  print '<tr><td>'.$langs->trans('Numero');
192  print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
193  print '<td><input name="num_payment" type="text" value="'.GETPOST("num_payment").'"></td></tr>'."\n";
194  }
195 
196  // Other attributes
197  $parameters = array();
198  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
199  print $hookmanager->resPrint;
200 
201  print '</table>';
202 
203  print dol_get_fiche_end();
204 
205  print $form->buttonsSaveCancel();
206 
207  print '</form>';
208 }
209 
210 
211 // View mode
212 if ($id) {
213  $h = 0;
214  $head[$h][0] = DOL_URL_ROOT.'/compta/localtax/card.php?id='.$object->id;
215  $head[$h][1] = $langs->trans('Card');
216  $head[$h][2] = 'card';
217  $h++;
218 
219  print dol_get_fiche_head($head, 'card', $langs->transcountry("LT".$object->ltt, $mysoc->country_code), -1, 'payment');
220 
221  $linkback = '<a href="'.DOL_URL_ROOT.'/compta/localtax/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
222 
223  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', '');
224 
225  print '<div class="fichecenter">';
226  print '<div class="underbanner clearboth"></div>';
227 
228  print '<table class="border centpercent">';
229 
230  print "<tr>";
231  print '<td class="titlefield">'.$langs->trans("Ref").'</td><td>';
232  print $object->ref;
233  print '</td></tr>';
234 
235  print "<tr>";
236  print '<td>'.$langs->trans("DatePayment").'</td><td>';
237  print dol_print_date($object->datep, 'day');
238  print '</td></tr>';
239 
240  print '<tr><td>'.$form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo")).'</td><td>';
241  print dol_print_date($object->datev, 'day');
242  print '</td></tr>';
243 
244  print '<tr><td>'.$langs->trans("Amount").'</td><td>'.price($object->amount).'</td></tr>';
245 
246  if (isModEnabled('banque')) {
247  if ($object->fk_account > 0) {
248  $bankline = new AccountLine($db);
249  $bankline->fetch($object->fk_bank);
250 
251  print '<tr>';
252  print '<td>'.$langs->trans('BankTransactionLine').'</td>';
253  print '<td>';
254  print $bankline->getNomUrl(1, 0, 'showall');
255  print '</td>';
256  print '</tr>';
257  }
258  }
259 
260  // Other attributes
261  $parameters = array();
262  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
263  print $hookmanager->resPrint;
264 
265  print '</table>';
266 
267  print '</div>';
268 
269  print dol_get_fiche_end();
270 
271 
272  /*
273  * Action bar
274  */
275  print "<div class=\"tabsAction\">\n";
276  if ($object->rappro == 0) {
277  print '<a class="butActionDelete" href="card.php?id='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans("Delete").'</a>';
278  } else {
279  print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("LinkedToAConcialitedTransaction").'">'.$langs->trans("Delete").'</a>';
280  }
281  print "</div>";
282 }
283 
284 // End of page
285 llxFooter();
286 $db->close();
restrictedArea
restrictedArea($user, $features, $objectid=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:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
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:484
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:4844
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
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:2046
$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:116
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5661
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:2514
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:3880
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:1822
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:105
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:386
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
$parameters
$parameters
Actions.
Definition: card.php:78
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:5541
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
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:2757
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
Localtax
Class to manage local tax.
Definition: localtax.class.php:29