dolibarr  19.0.0-dev
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 = GETPOST("id", 'int');
42 $action = GETPOST('action', 'aZ09');
43 $confirm = GETPOST('confirm');
44 if ($user->socid) $socid = $user->socid;
45 
46 $salary = new Salary($db);
47 
48 $object = new PaymentSalary($db);
49 if ($id > 0) {
50  $result = $object->fetch($id);
51  if (!$result) dol_print_error($db, 'Failed to get payment id '.$id);
52 }
53 restrictedArea($user, 'salaries', $object->fk_salary, 'salary', ''); // $object is payment of salary
54 
55 
56 /*
57  * Actions
58  */
59 
60 // Delete payment
61 if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('salaries', 'delete')) {
62  $db->begin();
63 
64  $result = $object->delete($user);
65  if ($result > 0) {
66  $db->commit();
67  header("Location: ".DOL_URL_ROOT."/salaries/payments.php");
68  exit;
69  } else {
70  setEventMessages($object->error, $object->errors, 'errors');
71  $db->rollback();
72  }
73 }
74 
75 if ($action == 'setdatep' && GETPOST('datepday') && $user->hasRight('salaries', 'write')) {
76  $datepaye = dol_mktime(GETPOST('datephour', 'int'), GETPOST('datepmin', 'int'), GETPOST('datepsec', 'int'), GETPOST('datepmonth', 'int'), GETPOST('datepday', 'int'), GETPOST('datepyear', 'int'), 'tzuserrel');
77  $res = $object->updatePaymentDate($datepaye);
78  if ($res === 0) {
79  setEventMessages($langs->trans('PaymentDateUpdateSucceeded'), null, 'mesgs');
80  } else {
81  setEventMessages($langs->trans('PaymentDateUpdateFailed'), null, 'errors');
82  }
83 }
84 
85 
86 /*
87  * View
88  */
89 
90 $form = new Form($db);
91 
92 llxHeader('', $langs->trans("SalaryPayment"));
93 
94 $h = 0;
95 
96 $head = array();
97 
98 $head[$h][0] = DOL_URL_ROOT.'/salaries/payment_salary/card.php?id='.$id;
99 $head[$h][1] = $langs->trans("SalaryPayment");
100 $hselected = $h;
101 $h++;
102 
103 /*
104 $head[$h][0] = DOL_URL_ROOT.'/compta/payment_sc/info.php?id='.$id;
105 $head[$h][1] = $langs->trans("Info");
106 $h++;
107 */
108 
109 
110 print dol_get_fiche_head($head, $hselected, $langs->trans("SalaryPayment"), -1, 'payment');
111 
112 /*
113  * Deletion confirmation of payment
114  */
115 if ($action == 'delete') {
116  print $form->formconfirm('card.php?id='.$object->id, $langs->trans("DeleteSalary"), $langs->trans("ConfirmDeleteSalaryPayment"), 'confirm_delete', '', 0, 2);
117 }
118 
119 /*
120  * Validation confirmation of payment
121  */
122 /*
123 if ($action == 'valide')
124 {
125  $facid = GETPOST('facid', 'int');
126  print $form->formconfirm('card.php?id='.$object->id.'&amp;facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2);
127 
128 }
129 */
130 
131 
132 $linkback = '<a href="'.DOL_URL_ROOT.'/salaries/payments.php">'.$langs->trans("BackToList").'</a>';
133 
134 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'id', '');
135 
136 
137 print '<div class="fichecenter">';
138 print '<div class="underbanner clearboth"></div>';
139 
140 print '<table class="border centpercent tableforfield">';
141 
142 // Ref
143 /*print '<tr><td class="titlefield">'.$langs->trans('Ref').'</td>';
144 print '<td colspan="3">';
145 print $form->showrefnav($object,'id','',1,'rowid','id');
146 print '</td></tr>';*/
147 
148 // Date
149 print '<tr><td>';
150 print $form->editfieldkey("Date", 'datep', $object->datep, $object, 1, 'datehourpicker');
151 print '</td><td>';
152 print $form->editfieldval("Date", 'datep', $object->datep, $object, 1, 'datehourpicker', '', null, null, '', 0, '', 'id', 'tzuserrel', array('addnowlink'=>1));
153 print "</td>";
154 print '</tr>';
155 
156 // Mode
157 print '<tr><td>'.$langs->trans('Mode').'</td><td>';
158 print $langs->trans("PaymentType".$object->type_code);
159 print '</td></tr>';
160 
161 // Numero
162 print '<tr><td>'.$langs->trans('Numero').'</td><td>'.dol_escape_htmltag($object->num_payment).'</td></tr>';
163 
164 // Montant
165 print '<tr><td>'.$langs->trans('Amount').'</td><td>'.price($object->amount, 0, $langs, 1, -1, -1, $conf->currency).'</td></tr>';
166 
167 // Note
168 print '<tr><td>'.$langs->trans('Note').'</td><td class="valeur sensiblehtmlcontent">'.dol_string_onlythesehtmltags(dol_htmlcleanlastbr($object->note_private)).'</td></tr>';
169 
170 // Bank account
171 if (isModEnabled("banque")) {
172  if ($object->bank_account) {
173  $bankline = new AccountLine($db);
174  $bankline->fetch($object->bank_line);
175 
176  print '<tr>';
177  print '<td>'.$langs->trans('BankTransactionLine').'</td>';
178  print '<td>';
179  print $bankline->getNomUrl(1, 0, 'showall');
180  print '</td>';
181  print '</tr>';
182  }
183 }
184 
185 print '</table>';
186 
187 print '</div>';
188 
189 print dol_get_fiche_end();
190 
191 
192 /*
193  * List of salaries payed
194  */
195 
196 $disable_delete = 0;
197 $sql = 'SELECT f.rowid as scid, f.label, f.paye, f.amount as sc_amount, ps.amount';
198 $sql .= ' FROM '.MAIN_DB_PREFIX.'payment_salary as ps,'.MAIN_DB_PREFIX.'salary as f';
199 $sql .= ' WHERE ps.fk_salary = f.rowid';
200 $sql .= ' AND f.entity = '.$conf->entity;
201 $sql .= ' AND ps.rowid = '.((int) $object->id);
202 
203 dol_syslog("payment_salary/card.php", LOG_DEBUG);
204 $resql = $db->query($sql);
205 if ($resql) {
206  $num = $db->num_rows($resql);
207 
208  $i = 0;
209  $total = 0;
210  print '<br>';
211 
212  print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
213  print '<table class="noborder centpercent">';
214  print '<tr class="liste_titre">';
215  print '<td>'.$langs->trans('Salary').'</td>';
216  print '<td>'.$langs->trans('Label').'</td>';
217  print '<td class="right">'.$langs->trans('ExpectedToPay').'</td>';
218  print '<td class="center">'.$langs->trans('Status').'</td>';
219  print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>';
220  print "</tr>\n";
221 
222  if ($num > 0) {
223  while ($i < $num) {
224  $objp = $db->fetch_object($resql);
225 
226  print '<tr class="oddeven">';
227  // Ref
228  print '<td>';
229  $salary->fetch($objp->scid);
230  print $salary->getNomUrl(1);
231  print "</td>\n";
232  // Label
233  print '<td>'.$objp->label.'</td>';
234  // Expected to pay
235  print '<td class="right">'.price($objp->sc_amount).'</td>';
236  // Status
237  print '<td class="center">'.$salary->getLibStatut(4, $objp->amount).'</td>';
238  // Amount payed
239  print '<td class="right">'.price($objp->amount).'</td>';
240  print "</tr>\n";
241  if ($objp->paye == 1) {
242  // If at least one invoice is paid, disable delete
243  $disable_delete = 1;
244  }
245  $total = $total + $objp->amount;
246  $i++;
247  }
248  }
249 
250  print "</table>\n";
251  print "</div>";
252 
253  $db->free($resql);
254 } else {
255  dol_print_error($db);
256 }
257 
258 
259 
260 /*
261  * Button actions
262  */
263 
264 print '<div class="tabsAction">';
265 
266 if ($action == '') {
267  if ($user->rights->salaries->delete) {
268  if (!$disable_delete) {
269  print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 1);
270  } else {
271  print dolGetButtonAction($langs->trans("CantRemovePaymentSalaryPaid"), $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 0);
272  }
273  }
274 }
275 
276 print '</div>';
277 
278 // End of page
279 llxFooter();
280 $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 salaries.
Class to manage salary payments.
if(isModEnabled('facture') && $user->hasRight('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') && $user->hasRight('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:746
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_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.
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.
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.