dolibarr  16.0.5
card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
5  * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
6  * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
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 
29 require '../../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/paymentvat.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
34 if (isModEnabled('banque')) {
35  require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
36 }
37 
38 // Load translation files required by the page
39 $langs->loadLangs(array('bills', 'banks', 'companies'));
40 
41 // Security check
42 $id = GETPOST("id", 'int');
43 $action = GETPOST('action', 'aZ09');
44 $confirm = GETPOST('confirm');
45 if ($user->socid) {
46  $socid = $user->socid;
47 }
48 // TODO ajouter regle pour restreindre acces paiement
49 //$result = restrictedArea($user, 'facture', $id,'');
50 
51 $object = new PaymentVAT($db);
52 if ($id > 0) {
53  $result = $object->fetch($id);
54  if (!$result) {
55  dol_print_error($db, 'Failed to get payment id '.$id);
56  }
57 }
58 
59 
60 /*
61  * Actions
62  */
63 
64 // Delete payment
65 if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->tax->charges->supprimer) {
66  $db->begin();
67 
68  $result = $object->delete($user);
69  if ($result > 0) {
70  $db->commit();
71  header("Location: ".DOL_URL_ROOT."/compta/tva/payments.php?mode=tvaonly");
72  exit;
73  } else {
74  setEventMessages($object->error, $object->errors, 'errors');
75  $db->rollback();
76  }
77 }
78 
79 // Validate social contribution
80 /*
81 if ($action == 'confirm_valide' && $confirm == 'yes' && $user->rights->tax->charges->creer)
82 {
83  $db->begin();
84 
85  $result=$object->valide();
86 
87  if ($result > 0)
88  {
89  $db->commit();
90 
91  $factures=array(); // TODO Get all id of invoices linked to this payment
92  foreach($factures as $id)
93  {
94  $fac = new Facture($db);
95  $fac->fetch($id);
96 
97  $outputlangs = $langs;
98  if (! empty($_REQUEST['lang_id']))
99  {
100  $outputlangs = new Translate("",$conf);
101  $outputlangs->setDefaultLang($_REQUEST['lang_id']);
102  }
103  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
104  $fac->generateDocument($fac->modelpdf, $outputlangs);
105  }
106  }
107 
108  header('Location: card.php?id='.$object->id);
109  exit;
110  }
111  else
112  {
113  setEventMessages($object->error, $object->errors, 'errors');
114  $db->rollback();
115  }
116 }
117 */
118 
119 
120 /*
121  * View
122  */
123 
124 llxHeader();
125 
126 $tva = new TVA($db);
127 
128 $form = new Form($db);
129 
130 $h = 0;
131 
132 $head[$h][0] = DOL_URL_ROOT.'/compta/payment_vat/card.php?id='.$id;
133 $head[$h][1] = $langs->trans("VATPayment");
134 $hselected = $h;
135 $h++;
136 
137 /*$head[$h][0] = DOL_URL_ROOT.'/compta/payment_sc/info.php?id='.$id;
138 $head[$h][1] = $langs->trans("Info");
139 $h++;
140 */
141 
142 
143 print dol_get_fiche_head($head, $hselected, $langs->trans("VATPayment"), -1, 'payment');
144 
145 /*
146  * Deletion confirmation of payment
147  */
148 if ($action == 'delete') {
149  print $form->formconfirm('card.php?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete', '', 0, 2);
150 }
151 
152 /*
153  * Validation confirmation of payment
154  */
155 /*
156 if ($action == 'valide')
157 {
158  $facid = $_GET['facid'];
159  print $form->formconfirm('card.php?id='.$object->id.'&amp;facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2);
160 
161 }
162 */
163 
164 
165 $linkback = '<a href="'.DOL_URL_ROOT.'/compta/tva/payments.php">'.$langs->trans("BackToList").'</a>';
166 
167 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'id', '');
168 
169 
170 print '<div class="fichecenter">';
171 print '<div class="underbanner clearboth"></div>';
172 
173 print '<table class="border centpercent">';
174 
175 // Ref
176 /*print '<tr><td class="titlefield">'.$langs->trans('Ref').'</td>';
177 print '<td colspan="3">';
178 print $form->showrefnav($object,'id','',1,'rowid','id');
179 print '</td></tr>';*/
180 
181 // Date
182 print '<tr><td>'.$langs->trans('Date').'</td><td colspan="3">'.dol_print_date($object->datep, 'day').'</td></tr>';
183 
184 // Mode
185 print '<tr><td>'.$langs->trans('Mode').'</td><td colspan="3">'.$langs->trans("PaymentType".$object->type_code).'</td></tr>';
186 
187 // Numero
188 print '<tr><td>'.$langs->trans('Numero').'</td><td colspan="3">'.$object->num_paiement.'</td></tr>';
189 
190 // Montant
191 print '<tr><td>'.$langs->trans('Amount').'</td><td colspan="3">'.price($object->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
192 
193 // Note
194 print '<tr><td>'.$langs->trans('Note').'</td><td colspan="3">'.nl2br($object->note).'</td></tr>';
195 
196 // Bank account
197 if (isModEnabled('banque')) {
198  if ($object->bank_account) {
199  $bankline = new AccountLine($db);
200  $bankline->fetch($object->bank_line);
201 
202  print '<tr>';
203  print '<td>'.$langs->trans('BankTransactionLine').'</td>';
204  print '<td colspan="3">';
205  print $bankline->getNomUrl(1, 0, 'showall');
206  print '</td>';
207  print '</tr>';
208  }
209 }
210 
211 print '</table>';
212 
213 print '</div>';
214 
215 print dol_get_fiche_end();
216 
217 
218 /*
219  * List of social contributions payed
220  */
221 
222 $disable_delete = 0;
223 $sql = 'SELECT f.rowid as scid, f.label as label, f.paye, f.amount as tva_amount, pf.amount';
224 //$sql .= ', pc.libelle as sc_type';
225 $sql .= ' FROM '.MAIN_DB_PREFIX.'payment_vat as pf,'.MAIN_DB_PREFIX.'tva as f';
226 //$sql .= ', '.MAIN_DB_PREFIX.'c_chargesociales as pc';
227 $sql .= ' WHERE pf.fk_tva = f.rowid';
228 //$sql .= ' AND f.fk_type = pc.id';
229 $sql .= ' AND f.entity = '.$conf->entity;
230 $sql .= ' AND pf.rowid = '.((int) $object->id);
231 
232 dol_syslog("compta/payment_vat/card.php", LOG_DEBUG);
233 $resql = $db->query($sql);
234 if ($resql) {
235  $num = $db->num_rows($resql);
236 
237  $i = 0;
238  $total = 0;
239  print '<br><table class="noborder centpercent">';
240  print '<tr class="liste_titre">';
241  print '<td>'.$langs->trans('VATDeclaration').'</td>';
242  //print '<td>'.$langs->trans('Type').'</td>';
243  print '<td>'.$langs->trans('Label').'</td>';
244  print '<td class="right">'.$langs->trans('ExpectedToPay').'</td>';
245  print '<td class="center">'.$langs->trans('Status').'</td>';
246  print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>';
247  print "</tr>\n";
248 
249  if ($num > 0) {
250  while ($i < $num) {
251  $objp = $db->fetch_object($resql);
252 
253  print '<tr class="oddeven">';
254  // Ref
255  print '<td>';
256  $tva->fetch($objp->scid);
257  print $tva->getNomUrl(1);
258  print "</td>\n";
259  // Type
260  /* print '<td>';
261  print $tva->type_label;4
262  print "</td>\n";*/
263  // Label
264  print '<td>'.$objp->label.'</td>';
265  // Expected to pay
266  print '<td class="right"><span class="amount">'.price($objp->tva_amount).'</span></td>';
267  // Status
268  print '<td class="center">'.$tva->getLibStatut(4, $objp->amount).'</td>';
269  // Amount payed
270  print '<td class="right"><span class="amount">'.price($objp->amount).'</span></td>';
271  print "</tr>\n";
272  if ($objp->paye == 1) { // If at least one invoice is paid, disable delete
273  $disable_delete = 1;
274  }
275  $total = $total + $objp->amount;
276  $i++;
277  }
278  }
279 
280 
281  print "</table>\n";
282  $db->free($resql);
283 } else {
284  dol_print_error($db);
285 }
286 
287 
288 
289 /*
290  * Boutons Actions
291  */
292 print '<div class="tabsAction">';
293 
294 /*
295 if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
296 {
297  if ($user->socid == 0 && $object->statut == 0 && $_GET['action'] == '')
298  {
299  if ($user->rights->facture->paiement)
300  {
301  print '<a class="butAction" href="card.php?id='.GETPOST('id', 'int').'&amp;facid='.$objp->facid.'&amp;action=valide">'.$langs->trans('Valid').'</a>';
302  }
303  }
304 }
305 */
306 
307 if ($action == '') {
308  if ($user->rights->tax->charges->supprimer) {
309  if (!$disable_delete) {
310  print '<a class="butActionDelete" href="card.php?id='.GETPOST('id', 'int').'&action=delete&token='.newToken().'">'.$langs->trans('Delete').'</a>';
311  } else {
312  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("CantRemovePaymentVATPaid")).'">'.$langs->trans('Delete').'</a>';
313  }
314  }
315 }
316 
317 print '</div>';
318 
319 // End of page
320 llxFooter();
321 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
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
PaymentVAT
Class to manage payments of social contributions.
Definition: paymentvat.class.php:33
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
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
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
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
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
AccountLine
Class to manage bank transaction lines.
Definition: account.class.php:1779
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
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
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