dolibarr  13.0.2
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", "alpha");
36 $refund = GETPOST("refund", "int");
37 if (empty($refund)) $refund = 0;
38 
39 $lttype = GETPOST('localTaxType', 'int');
40 
41 // Security check
42 $socid = GETPOST('socid', 'int');
43 if ($user->socid) $socid = $user->socid;
44 $result = restrictedArea($user, 'tax', '', '', 'charges');
45 
46 $object = new Localtax($db);
47 
48 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
49 $hookmanager->initHooks(array('localtaxvatcard', 'globalcard'));
50 
51 
56 if ($_POST["cancel"] == $langs->trans("Cancel") && !$id)
57 {
58  header("Location: list.php?localTaxType=".$lttype);
59  exit;
60 }
61 
62 if ($action == 'add' && $_POST["cancel"] <> $langs->trans("Cancel"))
63 {
64  $db->begin();
65 
66  $datev = dol_mktime(12, 0, 0, $_POST["datevmonth"], $_POST["datevday"], $_POST["datevyear"]);
67  $datep = dol_mktime(12, 0, 0, $_POST["datepmonth"], $_POST["datepday"], $_POST["datepyear"]);
68 
69  $object->accountid = GETPOST("accountid");
70  $object->paymenttype = GETPOST("paiementtype");
71  $object->datev = $datev;
72  $object->datep = $datep;
73  $object->amount = price2num(GETPOST("amount"));
74  $object->label = GETPOST("label");
75  $object->ltt = $lttype;
76 
77  $ret = $object->addPayment($user);
78  if ($ret > 0)
79  {
80  $db->commit();
81  header("Location: list.php?localTaxType=".$lttype);
82  exit;
83  } else {
84  $db->rollback();
85  setEventMessages($object->error, $object->errors, 'errors');
86  $_GET["action"] = "create";
87  }
88 }
89 
90 //delete payment of localtax
91 if ($action == 'delete')
92 {
93  $result = $object->fetch($id);
94 
95  if ($object->rappro == 0)
96  {
97  $db->begin();
98 
99  $ret = $object->delete($user);
100  if ($ret > 0)
101  {
102  if ($object->fk_bank)
103  {
104  $accountline = new AccountLine($db);
105  $result = $accountline->fetch($object->fk_bank);
106  if ($result > 0) $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  if ($result >= 0)
110  {
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 {
136  $result = $object->fetch($id);
137  if ($result <= 0)
138  {
139  dol_print_error($db);
140  exit;
141  }
142 }
143 
144 $form = new Form($db);
145 
146 $title = $langs->trans("LT".$object->ltt)." - ".$langs->trans("Card");
147 $help_url = '';
148 llxHeader("", $title, $helpurl);
149 
150 if ($action == 'create')
151 {
152  print load_fiche_titre($langs->transcountry($lttype == 2 ? "newLT2Payment" : "newLT1Payment", $mysoc->country_code));
153 
154  print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" name="formlocaltax" method="post">'."\n";
155  print '<input type="hidden" name="token" value="'.newToken().'">';
156  print '<input type="hidden" name="localTaxType" value="'.$lttype.'">';
157  print '<input type="hidden" name="action" value="add">';
158 
160 
161  print '<table class="border centpercent">';
162 
163  print "<tr>";
164  print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("DatePayment").'</td><td>';
165  print $form->selectDate($datep, "datep", '', '', '', 'add', 1, 1);
166  print '</td></tr>';
167 
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="'.($_POST["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 (!empty($conf->banque->enabled))
179  {
180  print '<tr><td class="fieldrequired">'.$langs->trans("Account").'</td><td>';
181  $form->select_comptes($_POST["accountid"], "accountid", 0, "courant=1", 2); // Affiche liste des comptes courant
182  print '</td></tr>';
183 
184  print '<tr><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td>';
185  $form->select_types_paiements(GETPOST("paiementtype"), "paiementtype");
186  print "</td>\n";
187  print "</tr>";
188 
189  // Number
190  print '<tr><td>'.$langs->trans('Numero');
191  print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
192  print '<td><input name="num_payment" type="text" value="'.GETPOST("num_payment").'"></td></tr>'."\n";
193  }
194  // Other attributes
195  $parameters = array();
196  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
197  print $hookmanager->resPrint;
198 
199  print '</table>';
200 
202 
203  print '<div class="center">';
204  print '<input type="submit" class="button button-save" value="'.$langs->trans("Save").'">';
205  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
206  print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
207  print '</div>';
208 
209  print '</form>';
210 }
211 
212 
213 // View mode
214 if ($id)
215 {
216  $h = 0;
217  $head[$h][0] = DOL_URL_ROOT.'/compta/localtax/card.php?id='.$object->id;
218  $head[$h][1] = $langs->trans('Card');
219  $head[$h][2] = 'card';
220  $h++;
221 
222  print dol_get_fiche_head($head, 'card', $langs->transcountry("LT".$object->ltt, $mysoc->country_code), -1, 'payment');
223 
224  $linkback = '<a href="'.DOL_URL_ROOT.'/compta/localtax/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
225 
226  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', '');
227 
228  print '<div class="fichecenter">';
229  print '<div class="underbanner clearboth"></div>';
230 
231  print '<table class="border centpercent">';
232 
233  print "<tr>";
234  print '<td class="titlefield">'.$langs->trans("Ref").'</td><td>';
235  print $object->ref;
236  print '</td></tr>';
237 
238  print "<tr>";
239  print '<td>'.$langs->trans("DatePayment").'</td><td>';
240  print dol_print_date($object->datep, 'day');
241  print '</td></tr>';
242 
243  print '<tr><td>'.$form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo")).'</td><td>';
244  print dol_print_date($object->datev, 'day');
245  print '</td></tr>';
246 
247  print '<tr><td>'.$langs->trans("Amount").'</td><td>'.price($object->amount).'</td></tr>';
248 
249  if (!empty($conf->banque->enabled))
250  {
251  if ($object->fk_account > 0)
252  {
253  $bankline = new AccountLine($db);
254  $bankline->fetch($object->fk_bank);
255 
256  print '<tr>';
257  print '<td>'.$langs->trans('BankTransactionLine').'</td>';
258  print '<td>';
259  print $bankline->getNomUrl(1, 0, 'showall');
260  print '</td>';
261  print '</tr>';
262  }
263  }
264 
265  // Other attributes
266  $parameters = array();
267  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
268  print $hookmanager->resPrint;
269 
270  print '</table>';
271 
272  print '</div>';
273 
275 
276 
277  /*
278  * Action buttons
279  */
280  print "<div class=\"tabsAction\">\n";
281  if ($object->rappro == 0)
282  {
283  print '<a class="butActionDelete" href="card.php?id='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans("Delete").'</a>';
284  } else {
285  print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("LinkedToAConcialitedTransaction").'">'.$langs->trans("Delete").'</a>';
286  }
287  print "</div>";
288 }
289 
290 // End of page
291 llxFooter();
292 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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...
Class to manage bank transaction lines.
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...
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Class to manage local tax.
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.
llxFooter()
Empty footer.
Definition: wrapper.php:59