dolibarr  17.0.4
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 // 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 $object = new PaymentSalary($db);
47 if ($id > 0) {
48  $result = $object->fetch($id);
49  if (!$result) dol_print_error($db, 'Failed to get payment id '.$id);
50 }
51 restrictedArea($user, 'salaries', $object->fk_salary, 'salary', ''); // $object is payment of salary
52 
53 
54 /*
55  * Actions
56  */
57 
58 // Delete payment
59 if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->salaries->delete) {
60  $db->begin();
61 
62  $result = $object->delete($user);
63  if ($result > 0) {
64  $db->commit();
65  header("Location: ".DOL_URL_ROOT."/salaries/payments.php");
66  exit;
67  } else {
68  setEventMessages($object->error, $object->errors, 'errors');
69  $db->rollback();
70  }
71 }
72 
73 
74 /*
75  * View
76  */
77 
78 llxHeader();
79 
80 $salary = new Salary($db);
81 
82 $form = new Form($db);
83 
84 $h = 0;
85 
86 $head = array();
87 
88 $head[$h][0] = DOL_URL_ROOT.'/salaries/payment_salary/card.php?id='.$id;
89 $head[$h][1] = $langs->trans("SalaryPayment");
90 $hselected = $h;
91 $h++;
92 
93 /*
94 $head[$h][0] = DOL_URL_ROOT.'/compta/payment_sc/info.php?id='.$id;
95 $head[$h][1] = $langs->trans("Info");
96 $h++;
97 */
98 
99 
100 print dol_get_fiche_head($head, $hselected, $langs->trans("SalaryPayment"), -1, 'payment');
101 
102 /*
103  * Deletion confirmation of payment
104  */
105 if ($action == 'delete') {
106  print $form->formconfirm('card.php?id='.$object->id, $langs->trans("DeleteSalary"), $langs->trans("ConfirmDeleteSalaryPayment"), 'confirm_delete', '', 0, 2);
107 }
108 
109 /*
110  * Validation confirmation of payment
111  */
112 /*
113 if ($action == 'valide')
114 {
115  $facid = GETPOST('facid', 'int');
116  print $form->formconfirm('card.php?id='.$object->id.'&amp;facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2);
117 
118 }
119 */
120 
121 
122 $linkback = '<a href="'.DOL_URL_ROOT.'/salaries/payments.php">'.$langs->trans("BackToList").'</a>';
123 
124 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'id', '');
125 
126 
127 print '<div class="fichecenter">';
128 print '<div class="underbanner clearboth"></div>';
129 
130 print '<table class="border centpercent">';
131 
132 // Ref
133 /*print '<tr><td class="titlefield">'.$langs->trans('Ref').'</td>';
134 print '<td colspan="3">';
135 print $form->showrefnav($object,'id','',1,'rowid','id');
136 print '</td></tr>';*/
137 
138 // Date
139 print '<tr><td>'.$langs->trans('Date').'</td><td colspan="3">'.dol_print_date($object->datep, 'day').'</td></tr>';
140 
141 // Mode
142 print '<tr><td>'.$langs->trans('Mode').'</td><td colspan="3">';
143 print $langs->trans("PaymentType".$object->type_code);
144 print '</td></tr>';
145 
146 // Numero
147 print '<tr><td>'.$langs->trans('Numero').'</td><td colspan="3">'.$object->num_payment.'</td></tr>';
148 
149 // Montant
150 print '<tr><td>'.$langs->trans('Amount').'</td><td colspan="3">'.price($object->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
151 
152 // Note
153 print '<tr><td>'.$langs->trans('Note').'</td><td colspan="3">'.nl2br($object->note).'</td></tr>';
154 
155 // Bank account
156 if (isModEnabled("banque")) {
157  if ($object->bank_account) {
158  $bankline = new AccountLine($db);
159  $bankline->fetch($object->bank_line);
160 
161  print '<tr>';
162  print '<td>'.$langs->trans('BankTransactionLine').'</td>';
163  print '<td colspan="3">';
164  print $bankline->getNomUrl(1, 0, 'showall');
165  print '</td>';
166  print '</tr>';
167  }
168 }
169 
170 print '</table>';
171 
172 print '</div>';
173 
174 print dol_get_fiche_end();
175 
176 
177 /*
178  * List of salaries payed
179  */
180 
181 $disable_delete = 0;
182 $sql = 'SELECT f.rowid as scid, f.label, f.paye, f.amount as sc_amount, ps.amount';
183 $sql .= ' FROM '.MAIN_DB_PREFIX.'payment_salary as ps,'.MAIN_DB_PREFIX.'salary as f';
184 $sql .= ' WHERE ps.fk_salary = f.rowid';
185 $sql .= ' AND f.entity = '.$conf->entity;
186 $sql .= ' AND ps.rowid = '.((int) $object->id);
187 
188 dol_syslog("payment_salary/card.php", LOG_DEBUG);
189 $resql = $db->query($sql);
190 if ($resql) {
191  $num = $db->num_rows($resql);
192 
193  $i = 0;
194  $total = 0;
195  print '<br>';
196 
197  print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
198  print '<table class="noborder centpercent">';
199  print '<tr class="liste_titre">';
200  print '<td>'.$langs->trans('Salary').'</td>';
201  print '<td>'.$langs->trans('Label').'</td>';
202  print '<td class="right">'.$langs->trans('ExpectedToPay').'</td>';
203  print '<td class="center">'.$langs->trans('Status').'</td>';
204  print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>';
205  print "</tr>\n";
206 
207  if ($num > 0) {
208  while ($i < $num) {
209  $objp = $db->fetch_object($resql);
210 
211  print '<tr class="oddeven">';
212  // Ref
213  print '<td>';
214  $salary->fetch($objp->scid);
215  print $salary->getNomUrl(1);
216  print "</td>\n";
217  // Label
218  print '<td>'.$objp->label.'</td>';
219  // Expected to pay
220  print '<td class="right">'.price($objp->sc_amount).'</td>';
221  // Status
222  print '<td class="center">'.$salary->getLibStatut(4, $objp->amount).'</td>';
223  // Amount payed
224  print '<td class="right">'.price($objp->amount).'</td>';
225  print "</tr>\n";
226  if ($objp->paye == 1) {
227  // If at least one invoice is paid, disable delete
228  $disable_delete = 1;
229  }
230  $total = $total + $objp->amount;
231  $i++;
232  }
233  }
234 
235  print "</table>\n";
236  print "</div>";
237 
238  $db->free($resql);
239 } else {
240  dol_print_error($db);
241 }
242 
243 
244 
245 /*
246  * Button actions
247  */
248 
249 print '<div class="tabsAction">';
250 
251 if ($action == '') {
252  if ($user->rights->salaries->delete) {
253  if (!$disable_delete) {
254  print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 1);
255  } else {
256  print dolGetButtonAction($langs->trans("CantRemovePaymentSalaryPaid"), $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 0);
257  }
258  }
259 }
260 
261 print '</div>';
262 
263 // End of page
264 llxFooter();
265 $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') &&!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)) $resql
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_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_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
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_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
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.