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