dolibarr  18.0.0-alpha
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) 2022 Alexandre Spangaro <aspangaro@open-dsi.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/sociales/class/chargesociales.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/paymentsocialcontribution.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', 'aZ09');
46 if ($user->socid) {
47  $socid = $user->socid;
48 }
49 
50 $object = new PaymentSocialContribution($db);
51 if ($id > 0) {
52  $result = $object->fetch($id);
53  if (!$result) {
54  dol_print_error($db, 'Failed to get payment id '.$id);
55  }
56 }
57 
58 $result = restrictedArea($user, 'payment_sc', $id, '');
59 
60 
61 /*
62  * Actions
63  */
64 
65 // Delete payment
66 if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('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/sociales/payments.php");
73  exit;
74  } else {
75  setEventMessages($object->error, $object->errors, 'errors');
76  $db->rollback();
77  }
78 }
79 
80 /*if ($action == 'setdatep' && GETPOST('datepday') && $user->hasRight('tax', 'charges', 'creer')) {
81  $datepaye = dol_mktime(GETPOST('datephour', 'int'), GETPOST('datepmin', 'int'), GETPOST('datepsec', 'int'), GETPOST('datepmonth', 'int'), GETPOST('datepday', 'int'), GETPOST('datepyear', 'int'));
82  $res = $object->update_date($datepaye);
83  if ($res === 0) {
84  setEventMessages($langs->trans('PaymentDateUpdateSucceeded'), null, 'mesgs');
85  } else {
86  setEventMessages($langs->trans('PaymentDateUpdateFailed'), null, 'errors');
87  }
88 }*/
89 
90 
91 /*
92  * View
93  */
94 
95 llxHeader();
96 
97 $socialcontrib = new ChargeSociales($db);
98 
99 $form = new Form($db);
100 
101 $h = 0;
102 
103 $head[$h][0] = DOL_URL_ROOT.'/compta/payment_sc/card.php?id='.$id;
104 $head[$h][1] = $langs->trans("PaymentSocialContribution");
105 $hselected = $h;
106 $h++;
107 
108 /*$head[$h][0] = DOL_URL_ROOT.'/compta/payment_sc/info.php?id='.$id;
109 $head[$h][1] = $langs->trans("Info");
110 $h++;
111 */
112 
113 
114 print dol_get_fiche_head($head, $hselected, $langs->trans("PaymentSocialContribution"), -1, 'payment');
115 
116 /*
117  * Deletion confirmation of payment
118  */
119 if ($action == 'delete') {
120  print $form->formconfirm('card.php?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete', '', 0, 2);
121 }
122 
123 $linkback = '<a href="'.DOL_URL_ROOT.'/compta/sociales/payments.php">'.$langs->trans("BackToList").'</a>';
124 
125 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'id', '');
126 
127 
128 print '<div class="fichecenter">';
129 print '<div class="underbanner clearboth"></div>';
130 
131 print '<table class="border centpercent">';
132 
133 // Ref
134 /*print '<tr><td class="titlefield">'.$langs->trans('Ref').'</td>';
135 print '<td colspan="3">';
136 print $form->showrefnav($object,'id','',1,'rowid','id');
137 print '</td></tr>';*/
138 
139 // Date
140 print '<tr><td>'.$langs->trans('Date').'</td><td colspan="3">'.dol_print_date($object->datep, 'day').'</td></tr>';
141 
142 // Mode
143 print '<tr><td>'.$langs->trans('Mode').'</td><td colspan="3">'.$langs->trans("PaymentType".$object->type_code).'</td></tr>';
144 
145 // Numero
146 print '<tr><td>'.$langs->trans('Numero').'</td><td colspan="3">'.$object->num_payment.'</td></tr>';
147 
148 // Amount
149 print '<tr><td>'.$langs->trans('Amount').'</td><td colspan="3">'.price($object->amount, 0, $langs, 1, -1, -1, $conf->currency).'</td></tr>';
150 
151 // Note
152 print '<tr><td>'.$langs->trans('Note').'</td><td colspan="3">'.nl2br($object->note).'</td></tr>';
153 
154 // Bank account
155 if (isModEnabled("banque")) {
156  if ($object->bank_account) {
157  $bankline = new AccountLine($db);
158  $bankline->fetch($object->bank_line);
159 
160  print '<tr>';
161  print '<td>'.$langs->trans('BankTransactionLine').'</td>';
162  print '<td colspan="3">';
163  print $bankline->getNomUrl(1, 0, 'showall');
164  print '</td>';
165  print '</tr>';
166  }
167 }
168 
169 print '</table>';
170 
171 print '</div>';
172 
173 print dol_get_fiche_end();
174 
175 
176 /*
177  * List of social contributions paid
178  */
179 
180 $disable_delete = 0;
181 $sql = 'SELECT f.rowid as scid, f.libelle as label, f.paye, f.amount as sc_amount, pf.amount, pc.libelle as sc_type';
182 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementcharge as pf,'.MAIN_DB_PREFIX.'chargesociales as f, '.MAIN_DB_PREFIX.'c_chargesociales as pc';
183 $sql .= ' WHERE pf.fk_charge = f.rowid AND f.fk_type = pc.id';
184 $sql .= ' AND f.entity = '.$conf->entity;
185 $sql .= ' AND pf.rowid = '.((int) $object->id);
186 
187 dol_syslog("compta/payment_sc/card.php", LOG_DEBUG);
188 $resql = $db->query($sql);
189 if ($resql) {
190  $num = $db->num_rows($resql);
191 
192  $i = 0;
193  $total = 0;
194  print '<br><table class="noborder centpercent">';
195  print '<tr class="liste_titre">';
196  print '<td>'.$langs->trans('SocialContribution').'</td>';
197  print '<td>'.$langs->trans('Type').'</td>';
198  print '<td>'.$langs->trans('Label').'</td>';
199  print '<td class="right">'.$langs->trans('ExpectedToPay').'</td>';
200  print '<td class="center">'.$langs->trans('Status').'</td>';
201  print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>';
202  print "</tr>\n";
203 
204  if ($num > 0) {
205  while ($i < $num) {
206  $objp = $db->fetch_object($resql);
207 
208  print '<tr class="oddeven">';
209  // Ref
210  print '<td>';
211  $socialcontrib->fetch($objp->scid);
212  print $socialcontrib->getNomUrl(1);
213  print "</td>\n";
214  // Type
215  print '<td>';
216  print $socialcontrib->type_label;
217  /*print $socialcontrib->type;*/
218  print "</td>\n";
219  // Label
220  print '<td>'.$objp->label.'</td>';
221  // Expected to pay
222  print '<td class="right"><span class="amount">'.price($objp->sc_amount).'</span></td>';
223  // Status
224  print '<td class="center">'.$socialcontrib->getLibStatut(4, $objp->amount).'</td>';
225  // Amount paid
226  print '<td class="right"><span class="amount">'.price($objp->amount).'</span></td>';
227  print "</tr>\n";
228  if ($objp->paye == 1) { // If at least one invoice is paid, disable delete
229  $disable_delete = 1;
230  }
231  $total = $total + $objp->amount;
232  $i++;
233  }
234  }
235 
236 
237  print "</table>\n";
238  $db->free($resql);
239 } else {
240  dol_print_error($db);
241 }
242 
243 
244 
245 /*
246  * Actions Buttons
247  */
248 print '<div class="tabsAction">';
249 
250 /*
251 if (!empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
252 {
253  if ($user->socid == 0 && $object->statut == 0 && $_GET['action'] == '')
254  {
255  if ($user->rights->facture->paiement)
256  {
257  print '<a class="butAction" href="card.php?id='.GETPOST('id', 'int').'&amp;facid='.$objp->facid.'&amp;action=valide">'.$langs->trans('Valid').'</a>';
258  }
259  }
260 }
261 */
262 
263 if ($action == '') {
264  if ($user->rights->tax->charges->supprimer) {
265  if (!$disable_delete) {
266  print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 1);
267  } else {
268  print dolGetButtonAction($langs->trans("CantRemovePaymentWithOneInvoicePaid"), $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 0);
269  }
270  }
271 }
272 
273 print '</div>';
274 
275 // End of page
276 llxFooter();
277 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:70
ChargeSociales
Classe permettant la gestion des paiements des charges La tva collectee n'est calculee que sur les fa...
Definition: chargesociales.class.php:34
$sql
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)) $sql
Social contributions to pay.
Definition: index.php:745
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:530
PaymentSocialContribution
Class to manage payments of social contributions.
Definition: paymentsocialcontribution.class.php:33
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:4994
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
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:2097
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:2566
llxHeader
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
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1639
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:1873
restrictedArea
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.
Definition: security.lib.php:341
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:11317
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2069
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:147
dolGetButtonAction
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
Definition: functions.lib.php:10880
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:1863
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:5708
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8509