dolibarr  20.0.0-beta
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.'/salaries/class/salary.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/salaries/class/paymentsalary.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 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
36 
37 // Load translation files required by the page
38 $langs->loadLangs(array('bills', 'banks', 'companies', 'salaries'));
39 
40 // Security check
41 $id = GETPOSTINT("id");
42 $action = GETPOST('action', 'aZ09');
43 $confirm = GETPOST('confirm');
44 if ($user->socid) {
45  $socid = $user->socid;
46 }
47 
48 $salary = new Salary($db);
49 
50 $object = new PaymentSalary($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 restrictedArea($user, 'salaries', $object->fk_salary, 'salary', ''); // $object is payment of salary
58 
59 
60 /*
61  * Actions
62  */
63 
64 // Delete payment
65 if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('salaries', 'delete')) {
66  $db->begin();
67 
68  $result = $object->delete($user);
69  if ($result > 0) {
70  $db->commit();
71  header("Location: ".DOL_URL_ROOT."/salaries/payments.php");
72  exit;
73  } else {
74  setEventMessages($object->error, $object->errors, 'errors');
75  $db->rollback();
76  }
77 }
78 
79 if ($action == 'setdatep' && GETPOST('datepday') && $user->hasRight('salaries', 'write')) {
80  $datepaye = dol_mktime(GETPOSTINT('datephour'), GETPOSTINT('datepmin'), GETPOSTINT('datepsec'), GETPOSTINT('datepmonth'), GETPOSTINT('datepday'), GETPOSTINT('datepyear'), 'tzuserrel');
81  $res = $object->updatePaymentDate($datepaye);
82  if ($res === 0) {
83  setEventMessages($langs->trans('PaymentDateUpdateSucceeded'), null, 'mesgs');
84  } else {
85  setEventMessages($langs->trans('PaymentDateUpdateFailed'), null, 'errors');
86  }
87 }
88 
89 
90 /*
91  * View
92  */
93 
94 $form = new Form($db);
95 
96 llxHeader('', $langs->trans("SalaryPayment"));
97 
98 $h = 0;
99 
100 $head = array();
101 
102 $head[$h][0] = DOL_URL_ROOT.'/salaries/payment_salary/card.php?id='.$id;
103 $head[$h][1] = $langs->trans("SalaryPayment");
104 $hselected = $h;
105 $h++;
106 
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("SalaryPayment"), -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("DeleteSalary"), $langs->trans("ConfirmDeleteSalaryPayment"), 'confirm_delete', '', 0, 2);
121 }
122 
123 /*
124  * Validation confirmation of payment
125  */
126 /*
127 if ($action == 'valide')
128 {
129  $facid = GETPOST('facid', 'int');
130  print $form->formconfirm('card.php?id='.$object->id.'&amp;facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2);
131 
132 }
133 */
134 
135 
136 $linkback = '<a href="'.DOL_URL_ROOT.'/salaries/payments.php">'.$langs->trans("BackToList").'</a>';
137 
138 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'id', '');
139 
140 
141 print '<div class="fichecenter">';
142 print '<div class="underbanner clearboth"></div>';
143 
144 print '<table class="border centpercent tableforfield">';
145 
146 // Ref
147 /*print '<tr><td class="titlefield">'.$langs->trans('Ref').'</td>';
148 print '<td colspan="3">';
149 print $form->showrefnav($object,'id','',1,'rowid','id');
150 print '</td></tr>';*/
151 
152 // Date
153 print '<tr><td>';
154 print $form->editfieldkey("Date", 'datep', $object->datep, $object, 1, 'datehourpicker');
155 print '</td><td>';
156 print $form->editfieldval("Date", 'datep', $object->datep, $object, 1, 'datehourpicker', '', null, null, '', 0, '', 'id', 'tzuserrel', array('addnowlink'=>1));
157 print "</td>";
158 print '</tr>';
159 
160 // Mode
161 print '<tr><td>'.$langs->trans('Mode').'</td><td>';
162 print $langs->trans("PaymentType".$object->type_code);
163 print '</td></tr>';
164 
165 // Numero
166 print '<tr><td>'.$langs->trans('Numero').'</td><td>'.dol_escape_htmltag($object->num_payment).'</td></tr>';
167 
168 // Montant
169 print '<tr><td>'.$langs->trans('Amount').'</td><td>'.price($object->amount, 0, $langs, 1, -1, -1, $conf->currency).'</td></tr>';
170 
171 // Note
172 print '<tr><td>'.$langs->trans('Note').'</td><td class="valeur sensiblehtmlcontent">'.dol_string_onlythesehtmltags(dol_htmlcleanlastbr($object->note_private)).'</td></tr>';
173 
174 // Bank account
175 if (isModEnabled("bank")) {
176  if ($object->bank_account) {
177  $bankline = new AccountLine($db);
178  $bankline->fetch($object->bank_line);
179 
180  print '<tr>';
181  print '<td>'.$langs->trans('BankTransactionLine').'</td>';
182  print '<td>';
183  print $bankline->getNomUrl(1, 0, 'showall');
184  print '</td>';
185  print '</tr>';
186  }
187 }
188 
189 print '</table>';
190 
191 print '</div>';
192 
193 print dol_get_fiche_end();
194 
195 
196 /*
197  * List of salaries paid
198  */
199 
200 $disable_delete = 0;
201 $sql = 'SELECT f.rowid as scid, f.label, f.paye, f.amount as sc_amount, ps.amount';
202 $sql .= ' FROM '.MAIN_DB_PREFIX.'payment_salary as ps,'.MAIN_DB_PREFIX.'salary as f';
203 $sql .= ' WHERE ps.fk_salary = f.rowid';
204 $sql .= ' AND f.entity = '.$conf->entity;
205 $sql .= ' AND ps.rowid = '.((int) $object->id);
206 
207 dol_syslog("payment_salary/card.php", LOG_DEBUG);
208 $resql = $db->query($sql);
209 if ($resql) {
210  $num = $db->num_rows($resql);
211 
212  $i = 0;
213  $total = 0;
214  print '<br>';
215 
216  print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
217  print '<table class="noborder centpercent">';
218  print '<tr class="liste_titre">';
219  print '<td>'.$langs->trans('Salary').'</td>';
220  print '<td>'.$langs->trans('Label').'</td>';
221  print '<td class="right">'.$langs->trans('ExpectedToPay').'</td>';
222  print '<td class="center">'.$langs->trans('Status').'</td>';
223  print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>';
224  print "</tr>\n";
225 
226  if ($num > 0) {
227  while ($i < $num) {
228  $objp = $db->fetch_object($resql);
229 
230  print '<tr class="oddeven">';
231  // Ref
232  print '<td>';
233  $salary->fetch($objp->scid);
234  print $salary->getNomUrl(1);
235  print "</td>\n";
236  // Label
237  print '<td>'.$objp->label.'</td>';
238  // Expected to pay
239  print '<td class="right">'.price($objp->sc_amount).'</td>';
240  // Status
241  print '<td class="center">'.$salary->getLibStatut(4, $objp->amount).'</td>';
242  // Amount paid
243  print '<td class="right">'.price($objp->amount).'</td>';
244  print "</tr>\n";
245  if ($objp->paye == 1) {
246  // If at least one invoice is paid, disable delete
247  $disable_delete = 1;
248  }
249  $total = $total + $objp->amount;
250  $i++;
251  }
252  }
253 
254  print "</table>\n";
255  print "</div>";
256 
257  $db->free($resql);
258 } else {
259  dol_print_error($db);
260 }
261 
262 
263 
264 /*
265  * Button actions
266  */
267 
268 print '<div class="tabsAction">';
269 
270 if ($action == '') {
271  if ($user->hasRight('salaries', 'delete')) {
272  if (!$disable_delete) {
273  print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 1);
274  } else {
275  print dolGetButtonAction($langs->trans("CantRemovePaymentSalaryPaid"), $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 0);
276  }
277  }
278 }
279 
280 print '</div>';
281 
282 // End of page
283 llxFooter();
284 $db->close();
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
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.
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
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_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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_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.
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.
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_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
isModEnabled($module)
Is Dolibarr module enabled.
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.