dolibarr  16.0.5
card.php
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 require '../../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/salaries/class/paymentsalary.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
34 if (isModEnabled('banque')) require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
35 
36 // Load translation files required by the page
37 $langs->loadLangs(array('bills', 'banks', 'companies', 'salaries'));
38 
39 // Security check
40 $id = GETPOST("id", 'int');
41 $action = GETPOST('action', 'aZ09');
42 $confirm = GETPOST('confirm');
43 if ($user->socid) $socid = $user->socid;
44 
45 $object = new PaymentSalary($db);
46 if ($id > 0) {
47  $result = $object->fetch($id);
48  if (!$result) dol_print_error($db, 'Failed to get payment id '.$id);
49 }
50 restrictedArea($user, 'salaries', $object->fk_salary, 'salary', ''); // $object is payment of salary
51 
52 
53 /*
54  * Actions
55  */
56 
57 // Delete payment
58 if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->salaries->delete) {
59  $db->begin();
60 
61  $result = $object->delete($user);
62  if ($result > 0) {
63  $db->commit();
64  header("Location: ".DOL_URL_ROOT."/salaries/payments.php");
65  exit;
66  } else {
67  setEventMessages($object->error, $object->errors, 'errors');
68  $db->rollback();
69  }
70 }
71 
72 
73 /*
74  * View
75  */
76 
77 llxHeader();
78 
79 $salary = new Salary($db);
80 
81 $form = new Form($db);
82 
83 $h = 0;
84 
85 $head = array();
86 
87 $head[$h][0] = DOL_URL_ROOT.'/salaries/payment_salary/card.php?id='.$id;
88 $head[$h][1] = $langs->trans("SalaryPayment");
89 $hselected = $h;
90 $h++;
91 
92 /*
93 $head[$h][0] = DOL_URL_ROOT.'/compta/payment_sc/info.php?id='.$id;
94 $head[$h][1] = $langs->trans("Info");
95 $h++;
96 */
97 
98 
99 print dol_get_fiche_head($head, $hselected, $langs->trans("SalaryPayment"), -1, 'payment');
100 
101 /*
102  * Deletion confirmation of payment
103  */
104 if ($action == 'delete') {
105  print $form->formconfirm('card.php?id='.$object->id, $langs->trans("DeleteSalary"), $langs->trans("ConfirmDeleteSalaryPayment"), 'confirm_delete', '', 0, 2);
106 }
107 
108 /*
109  * Validation confirmation of payment
110  */
111 /*
112 if ($action == 'valide')
113 {
114  $facid = GETPOST('facid', 'int');
115  print $form->formconfirm('card.php?id='.$object->id.'&amp;facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2);
116 
117 }
118 */
119 
120 
121 $linkback = '<a href="'.DOL_URL_ROOT.'/salaries/payments.php">'.$langs->trans("BackToList").'</a>';
122 
123 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'id', '');
124 
125 
126 print '<div class="fichecenter">';
127 print '<div class="underbanner clearboth"></div>';
128 
129 print '<table class="border centpercent">';
130 
131 // Ref
132 /*print '<tr><td class="titlefield">'.$langs->trans('Ref').'</td>';
133 print '<td colspan="3">';
134 print $form->showrefnav($object,'id','',1,'rowid','id');
135 print '</td></tr>';*/
136 
137 // Date
138 print '<tr><td>'.$langs->trans('Date').'</td><td colspan="3">'.dol_print_date($object->datep, 'day').'</td></tr>';
139 
140 // Mode
141 print '<tr><td>'.$langs->trans('Mode').'</td><td colspan="3">';
142 print $langs->trans("PaymentType".$object->type_code);
143 print '</td></tr>';
144 
145 // Numero
146 print '<tr><td>'.$langs->trans('Numero').'</td><td colspan="3">'.$object->num_payment.'</td></tr>';
147 
148 // Montant
149 print '<tr><td>'.$langs->trans('Amount').'</td><td colspan="3">'.price($object->amount, 0, $outputlangs, 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 salaries payed
178  */
179 
180 $disable_delete = 0;
181 $sql = 'SELECT f.rowid as scid, f.label, f.paye, f.amount as sc_amount, ps.amount';
182 $sql .= ' FROM '.MAIN_DB_PREFIX.'payment_salary as ps,'.MAIN_DB_PREFIX.'salary as f';
183 $sql .= ' WHERE ps.fk_salary = f.rowid';
184 $sql .= ' AND f.entity = '.$conf->entity;
185 $sql .= ' AND ps.rowid = '.((int) $object->id);
186 
187 dol_syslog("payment_salary/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>';
195 
196  print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
197  print '<table class="noborder centpercent">';
198  print '<tr class="liste_titre">';
199  print '<td>'.$langs->trans('Salary').'</td>';
200  print '<td>'.$langs->trans('Label').'</td>';
201  print '<td class="right">'.$langs->trans('ExpectedToPay').'</td>';
202  print '<td class="center">'.$langs->trans('Status').'</td>';
203  print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>';
204  print "</tr>\n";
205 
206  if ($num > 0) {
207  while ($i < $num) {
208  $objp = $db->fetch_object($resql);
209 
210  print '<tr class="oddeven">';
211  // Ref
212  print '<td>';
213  $salary->fetch($objp->scid);
214  print $salary->getNomUrl(1);
215  print "</td>\n";
216  // Label
217  print '<td>'.$objp->label.'</td>';
218  // Expected to pay
219  print '<td class="right">'.price($objp->sc_amount).'</td>';
220  // Status
221  print '<td class="center">'.$salary->getLibStatut(4, $objp->amount).'</td>';
222  // Amount payed
223  print '<td class="right">'.price($objp->amount).'</td>';
224  print "</tr>\n";
225  if ($objp->paye == 1) {
226  // If at least one invoice is paid, disable delete
227  $disable_delete = 1;
228  }
229  $total = $total + $objp->amount;
230  $i++;
231  }
232  }
233 
234  print "</table>\n";
235  print "</div>";
236 
237  $db->free($resql);
238 } else {
239  dol_print_error($db);
240 }
241 
242 
243 
244 /*
245  * Button actions
246  */
247 
248 print '<div class="tabsAction">';
249 
250 if ($action == '') {
251  if ($user->rights->salaries->delete) {
252  if (!$disable_delete) {
253  print '<a class="butActionDelete" href="card.php?id='.GETPOST('id', 'int').'&action=delete&token='.newToken().'">'.$langs->trans('Delete').'</a>';
254  } else {
255  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("CantRemovePaymentSalaryPaid")).'">'.$langs->trans('Delete').'</a>';
256  }
257  }
258 }
259 
260 print '</div>';
261 
262 // End of page
263 llxFooter();
264 $db->close();
restrictedArea
restrictedArea($user, $features, $objectid=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:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
PaymentSalary
Class to manage payments of salaries.
Definition: paymentsalary.class.php:34
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:484
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:4844
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
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:2046
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:2514
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
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:1822
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:105
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:1779
Salary
Class to manage salary payments.
Definition: salary.class.php:33
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->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->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
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:5541
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59