dolibarr 19.0.3
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 * Copyright (C) 2024 Alexandre SPANGARO <alexandre@inovea-conseil.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
30// Load Dolibarr environment
31require '../../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
33require_once DOL_DOCUMENT_ROOT.'/salaries/class/paymentsalary.class.php';
34require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
35require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
36require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
37
38// Load translation files required by the page
39$langs->loadLangs(array('bills', 'banks', 'companies', 'salaries'));
40
41// Security check
42$id = GETPOST("id", 'int');
43$action = GETPOST('action', 'aZ09');
44$confirm = GETPOST('confirm');
45if ($user->socid) {
46 $socid = $user->socid;
47}
48
49$salary = new Salary($db);
50
51$object = new PaymentSalary($db);
52if ($id > 0) {
53 $result = $object->fetch($id);
54 if (!$result) {
55 dol_print_error($db, 'Failed to get payment id '.$id);
56 }
57}
58restrictedArea($user, 'salaries', $object->fk_salary, 'salary', ''); // $object is payment of salary
59
60
61/*
62 * Actions
63 */
64
65// Delete payment
66if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('salaries', 'delete')) {
67 $db->begin();
68
69 $result = $object->delete($user);
70 if ($result > 0) {
71 $db->commit();
72 header("Location: ".DOL_URL_ROOT."/salaries/payments.php");
73 exit;
74 } else {
75 setEventMessages($object->error, $object->errors, 'errors');
76 $db->rollback();
77 }
78}
79
80if ($action == 'setdatep' && GETPOST('datepday') && $user->hasRight('salaries', 'write')) {
81 $datepaye = dol_mktime(GETPOST('datephour', 'int'), GETPOST('datepmin', 'int'), GETPOST('datepsec', 'int'), GETPOST('datepmonth', 'int'), GETPOST('datepday', 'int'), GETPOST('datepyear', 'int'), 'tzuserrel');
82 $res = $object->updatePaymentDate($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$form = new Form($db);
96
97llxHeader('', $langs->trans("SalaryPayment"));
98
99$h = 0;
100
101$head = array();
102
103$head[$h][0] = DOL_URL_ROOT.'/salaries/payment_salary/card.php?id='.$id;
104$head[$h][1] = $langs->trans("SalaryPayment");
105$hselected = $h;
106$h++;
107
108/*
109$head[$h][0] = DOL_URL_ROOT.'/compta/payment_sc/info.php?id='.$id;
110$head[$h][1] = $langs->trans("Info");
111$h++;
112*/
113
114
115print dol_get_fiche_head($head, $hselected, $langs->trans("SalaryPayment"), -1, 'payment');
116
117/*
118 * Deletion confirmation of payment
119 */
120if ($action == 'delete') {
121 print $form->formconfirm('card.php?id='.$object->id, $langs->trans("DeleteSalary"), $langs->trans("ConfirmDeleteSalaryPayment"), 'confirm_delete', '', 0, 2);
122}
123
124/*
125 * Validation confirmation of payment
126 */
127/*
128if ($action == 'valide')
129{
130 $facid = GETPOST('facid', 'int');
131 print $form->formconfirm('card.php?id='.$object->id.'&amp;facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2);
132
133}
134*/
135
136
137$linkback = '<a href="'.DOL_URL_ROOT.'/salaries/payments.php">'.$langs->trans("BackToList").'</a>';
138
139dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'id', '');
140
141
142print '<div class="fichecenter">';
143print '<div class="underbanner clearboth"></div>';
144
145print '<table class="border centpercent tableforfield">';
146
147// Ref
148/*print '<tr><td class="titlefield">'.$langs->trans('Ref').'</td>';
149print '<td colspan="3">';
150print $form->showrefnav($object,'id','',1,'rowid','id');
151print '</td></tr>';*/
152
153// Date
154print '<tr><td>';
155print $form->editfieldkey("Date", 'datep', $object->datepaye, $object, 1, 'datehourpicker');
156print '</td><td>';
157print $form->editfieldval("Date", 'datep', $object->datepaye, $object, 1, 'datehourpicker', '', null, null, '', 0, '', 'id', 'tzuserrel', array('addnowlink'=>1));
158print "</td>";
159print '</tr>';
160
161// Mode
162print '<tr><td>'.$langs->trans('Mode').'</td><td>';
163print $langs->trans("PaymentType".$object->type_code);
164print '</td></tr>';
165
166// Numero
167print '<tr><td>'.$langs->trans('Numero').'</td><td>'.dol_escape_htmltag($object->num_payment).'</td></tr>';
168
169// Montant
170print '<tr><td>'.$langs->trans('Amount').'</td><td>'.price($object->amount, 0, $langs, 1, -1, -1, $conf->currency).'</td></tr>';
171
172// Note
173print '<tr><td>'.$langs->trans('Note').'</td><td class="valeur sensiblehtmlcontent">'.dol_string_onlythesehtmltags(dol_htmlcleanlastbr($object->note_private)).'</td></tr>';
174
175// Bank account
176if (isModEnabled("banque")) {
177 if ($object->bank_account) {
178 $bankline = new AccountLine($db);
179 $bankline->fetch($object->bank_line);
180
181 print '<tr>';
182 print '<td>'.$langs->trans('BankTransactionLine').'</td>';
183 print '<td>';
184 print $bankline->getNomUrl(1, 0, 'showall');
185 print '</td>';
186 print '</tr>';
187 }
188}
189
190print '</table>';
191
192print '</div>';
193
194print dol_get_fiche_end();
195
196
197/*
198 * List of salaries payed
199 */
200
201$disable_delete = 0;
202$sql = 'SELECT f.rowid as scid, f.label, f.paye, f.amount as sc_amount, ps.amount';
203$sql .= ' FROM '.MAIN_DB_PREFIX.'payment_salary as ps,'.MAIN_DB_PREFIX.'salary as f';
204$sql .= ' WHERE ps.fk_salary = f.rowid';
205$sql .= ' AND f.entity = '.$conf->entity;
206$sql .= ' AND ps.rowid = '.((int) $object->id);
207
208dol_syslog("payment_salary/card.php", LOG_DEBUG);
209$resql = $db->query($sql);
210if ($resql) {
211 $num = $db->num_rows($resql);
212
213 $i = 0;
214 $total = 0;
215 print '<br>';
216
217 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
218 print '<table class="noborder centpercent">';
219 print '<tr class="liste_titre">';
220 print '<td>'.$langs->trans('Salary').'</td>';
221 print '<td>'.$langs->trans('Label').'</td>';
222 print '<td class="right">'.$langs->trans('ExpectedToPay').'</td>';
223 print '<td class="center">'.$langs->trans('Status').'</td>';
224 print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>';
225 print "</tr>\n";
226
227 if ($num > 0) {
228 while ($i < $num) {
229 $objp = $db->fetch_object($resql);
230
231 print '<tr class="oddeven">';
232 // Ref
233 print '<td>';
234 $salary->fetch($objp->scid);
235 print $salary->getNomUrl(1);
236 print "</td>\n";
237 // Label
238 print '<td>'.$objp->label.'</td>';
239 // Expected to pay
240 print '<td class="right">'.price($objp->sc_amount).'</td>';
241 // Status
242 print '<td class="center">'.$salary->getLibStatut(4, $objp->amount).'</td>';
243 // Amount payed
244 print '<td class="right">'.price($objp->amount).'</td>';
245 print "</tr>\n";
246 if ($objp->paye == 1) {
247 // If at least one invoice is paid, disable delete
248 $disable_delete = 1;
249 }
250 $total = $total + $objp->amount;
251 $i++;
252 }
253 }
254
255 print "</table>\n";
256 print "</div>";
257
258 $db->free($resql);
259} else {
260 dol_print_error($db);
261}
262
263
264
265/*
266 * Button actions
267 */
268
269print '<div class="tabsAction">';
270
271if ($action == '') {
272 if ($user->hasRight('salaries', 'delete')) {
273 if (!$disable_delete) {
274 print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 1);
275 } else {
276 print dolGetButtonAction($langs->trans("CantRemovePaymentSalaryPaid"), $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 0);
277 }
278 }
279}
280
281print '</div>';
282
283// End of page
284llxFooter();
285$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:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to manage bank transaction lines.
Class to manage generation of HTML components Only common components must be here.
Class to manage payments of salaries.
Class to manage salary payments.
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_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...
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
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.
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_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles=1, $removeclassattribute=1, $cleanalsojavascript=0, $allowiframe=0, $allowed_tags=array(), $allowlink=0)
Clean a string to keep only desirable HTML tags.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
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.