28 require
'../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
30 require_once DOL_DOCUMENT_ROOT.
'/salaries/class/paymentsalary.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/lib/salaries.lib.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
34 if (!empty($conf->projet->enabled))
36 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
37 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
41 $langs->loadLangs(array(
"compta",
"banks",
"bills",
"users",
"salaries",
"hrm"));
42 if (!empty($conf->projet->enabled)) $langs->load(
"projects");
45 $action =
GETPOST(
'action',
'aZ09');
46 $cancel =
GETPOST(
'cancel',
'aZ09');
47 $accountid =
GETPOST(
'accountid',
'int') > 0 ?
GETPOST(
'accountid',
'int') : 0;
48 $projectid = (
GETPOST(
'projectid',
'int') ?
GETPOST(
'projectid',
'int') :
GETPOST(
'fk_project',
'int'));
56 $socid =
GETPOST(
"socid",
"int");
57 if ($user->socid) $socid = $user->socid;
64 $extrafields->fetch_name_optionals_label($object->table_element);
67 $hookmanager->initHooks(array(
'salarycard',
'globalcard'));
76 header(
"Location: list.php");
81 if ($action ==
'classin' && $user->rights->banque->modifier)
84 $object->setProject($projectid);
87 if ($action ==
'add' && empty($cancel))
91 if (empty($datev)) $datev = $datep;
95 $object->accountid =
GETPOST(
"accountid",
'int') > 0 ?
GETPOST(
"accountid",
"int") : 0;
96 $object->fk_user =
GETPOST(
"fk_user",
'int') > 0 ?
GETPOST(
"fk_user",
"int") : 0;
97 $object->datev = $datev;
98 $object->datep = $datep;
100 $object->label =
GETPOST(
"label",
'alphanohtml');
101 $object->datesp = $datesp;
102 $object->dateep = $dateep;
103 $object->note =
GETPOST(
"note",
'restricthtml');
104 $object->type_payment = ($type_payment > 0 ? $type_payment : 0);
105 $object->num_payment =
GETPOST(
"num_payment",
'alphanohtml');
106 $object->fk_user_author = $user->id;
107 $object->fk_project = $projectid;
110 $fuser =
new User($db);
111 $fuser->fetch(
GETPOST(
"fk_user",
"int"));
112 $object->salary = $fuser->salary;
115 $ret = $extrafields->setOptionalsFromPost(null, $object);
116 if ($ret < 0) $error++;
118 if (empty($datep) || empty($datev) || empty($datesp) || empty($dateep))
120 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")), null,
'errors');
123 if (empty($object->fk_user) || $object->fk_user < 0)
125 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Employee")), null,
'errors');
128 if (empty($type_payment) || $type_payment < 0)
130 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"PaymentMode")), null,
'errors');
133 if (empty($object->amount))
135 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Amount")), null,
'errors');
138 if (!empty($conf->banque->enabled) && !$object->accountid > 0)
140 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BankAccount")), null,
'errors');
148 $ret = $object->create($user);
153 if (
GETPOST(
'saveandnew',
'alpha')) {
155 header(
"Location: card.php?action=create&fk_project=".urlencode($projectid).
"&accountid=".urlencode($accountid).
'&paymenttype='.urlencode(
GETPOST(
'paymenttype',
'az09')).
'&datepday='.
GETPOST(
"datepday",
'int').
'&datepmonth='.
GETPOST(
"datepmonth",
'int').
'&datepyear='.
GETPOST(
"datepyear",
'int'));
158 header(
"Location: list.php");
171 if ($action ==
'delete')
173 $result = $object->fetch($id);
175 if ($object->rappro == 0)
179 $ret = $object->delete($user);
182 if ($object->fk_bank)
185 $result = $accountline->fetch($object->fk_bank);
186 if ($result > 0) $result = $accountline->delete($user);
192 header(
"Location: ".DOL_URL_ROOT.
'/salaries/list.php');
195 $object->error = $accountline->error;
204 setEventMessages(
'Error try do delete a line linked to a conciliated bank transaction', null,
'errors');
213 llxHeader(
"", $langs->trans(
"SalaryPayment"));
215 $form =
new Form($db);
216 if (!empty($conf->projet->enabled)) $formproject =
new FormProjets($db);
221 $result = $object->fetch($id);
230 if ($action ==
'create')
232 $year_current = strftime(
"%Y",
dol_now());
233 $pastmonth = strftime(
"%m",
dol_now()) - 1;
234 $pastmonthyear = $year_current;
241 $datespmonth =
GETPOST(
'datespmonth',
'int');
242 $datespday =
GETPOST(
'datespday',
'int');
243 $datespyear =
GETPOST(
'datespyear',
'int');
244 $dateepmonth =
GETPOST(
'dateepmonth',
'int');
245 $dateepday =
GETPOST(
'dateepday',
'int');
246 $dateepyear =
GETPOST(
'dateepyear',
'int');
247 $datesp =
dol_mktime(0, 0, 0, $datespmonth, $datespday, $datespyear);
248 $dateep =
dol_mktime(23, 59, 59, $dateepmonth, $dateepday, $dateepyear);
250 if (empty($datesp) || empty($dateep))
255 print '<form name="salary" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
256 print '<input type="hidden" name="token" value="'.newToken().
'">';
257 print '<input type="hidden" name="action" value="add">';
263 print '<table class="border centpercent">';
267 print $form->editfieldkey(
'DatePayment',
'datep',
'', $object, 0,
'string',
'', 1).
'</td><td>';
268 print $form->selectDate((empty($datep) ?
'' : $datep),
"datep", 0, 0, 0,
'add', 1, 1);
273 print $form->editfieldkey(
'DateValue',
'datev',
'', $object, 0).
'</td><td>';
274 print $form->selectDate((empty($datev) ?-1 : $datev),
"datev",
'',
'',
'',
'add', 1, 1);
279 print $form->editfieldkey(
'Employee',
'fk_user',
'', $object, 0,
'string',
'', 1).
'</td><td>';
281 print $form->select_dolusers(
GETPOST(
'fk_user',
'int'),
'fk_user', 1,
'', 0,
'',
'', 0, 0, 0,
'AND employee=1', 0,
'',
'maxwidth300', $noactive);
286 print $form->editfieldkey(
'Label',
'label',
'', $object, 0,
'string',
'', 1).
'</td><td>';
287 print '<input name="label" id="label" class="minwidth300" value="'.(GETPOST(
"label") ?
GETPOST(
"label") : $langs->trans(
"SalaryPayment")).
'">';
292 print $form->editfieldkey(
'DateStartPeriod',
'datesp',
'', $object, 0,
'string',
'', 1).
'</td><td>';
293 print $form->selectDate($datesp,
"datesp",
'',
'',
'',
'add');
298 print $form->editfieldkey(
'DateEndPeriod',
'dateep',
'', $object, 0,
'string',
'', 1).
'</td><td>';
299 print $form->selectDate($dateep,
"dateep",
'',
'',
'',
'add');
304 print $form->editfieldkey(
'Amount',
'amount',
'', $object, 0,
'string',
'', 1).
'</td><td>';
305 print '<input name="amount" id="amount" class="minwidth100" value="'.GETPOST(
"amount").
'">';
309 if (!empty($conf->banque->enabled))
312 print $form->editfieldkey(
'BankAccount',
'selectaccountid',
'', $object, 0,
'string',
'', 1).
'</td><td>';
313 $form->select_comptes($accountid,
"accountid", 0,
'', 1);
319 print $form->editfieldkey(
'PaymentMode',
'selectpaymenttype',
'', $object, 0,
'string',
'', 1).
'</td><td>';
320 $form->select_types_paiements(
GETPOST(
"paymenttype",
'aZ09'),
"paymenttype",
'', 2);
324 if (!empty($conf->banque->enabled))
327 print '<tr><td><label for="num_payment">'.$langs->trans(
'Numero');
328 print ' <em>('.$langs->trans(
"ChequeOrTransferNumber").
')</em>';
329 print '</label></td>';
330 print '<td><input name="num_payment" id="num_payment" type="text" value="'.GETPOST(
"num_payment").
'"></td></tr>'.
"\n";
334 if (!empty($conf->projet->enabled))
338 print '<tr><td>'.$langs->trans(
"Project").
'</td><td>';
339 $formproject->select_projects(-1, $projectid,
'fk_project', 0, 0, 1, 1);
344 $parameters = array();
345 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
346 print $hookmanager->resPrint;
349 print $object->showOptionals($extrafields,
'edit');
356 print '<div class="center">';
357 print '<input type="submit" class="button button-save" name="save" value="'.$langs->trans(
"Save").
'">';
358 print ' ';
359 print '<input type="submit" class="button" name="saveandnew" value="'.$langs->trans(
"SaveAndNew").
'">';
360 print ' ';
361 print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
376 $head = salaries_prepare_head($object);
380 $linkback =
'<a href="'.DOL_URL_ROOT.
'/salaries/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
382 $morehtmlref =
'<div class="refidno">';
385 $userstatic =
new User($db);
386 $userstatic->fetch($object->fk_user);
387 $morehtmlref .= $langs->trans(
'Employee').
' : '.$userstatic->getNomUrl(1);
390 if (!empty($conf->projet->enabled))
392 $morehtmlref .=
'<br>'.$langs->trans(
'Project').
' ';
393 if ($user->rights->salaries->write)
395 if ($action !=
'classify') {
396 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> : ';
398 if ($action ==
'classify') {
400 $morehtmlref .=
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'">';
401 $morehtmlref .=
'<input type="hidden" name="action" value="classin">';
402 $morehtmlref .=
'<input type="hidden" name="token" value="'.newToken().
'">';
403 $morehtmlref .= $formproject->select_projects(0, $object->fk_project,
'projectid', $maxlength, 0, 1, 0, 1, 0, 0,
'', 1);
404 $morehtmlref .=
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
405 $morehtmlref .=
'</form>';
407 $morehtmlref .= $form->form_project(
$_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->socid, $object->fk_project,
'none', 0, 0, 0, 1);
410 if (!empty($object->fk_project)) {
412 $proj->fetch($object->fk_project);
413 $morehtmlref .=
'<a href="'.DOL_URL_ROOT.
'/projet/card.php?id='.$object->fk_project.
'" title="'.$langs->trans(
'ShowProject').
'">';
414 $morehtmlref .= $proj->ref;
415 $morehtmlref .=
'</a>';
421 $morehtmlref .=
'</div>';
423 dol_banner_tab($object,
'id', $linkback, 1,
'rowid',
'ref', $morehtmlref,
'', 0,
'',
'');
425 print '<div class="fichecenter">';
426 print '<div class="underbanner clearboth"></div>';
428 print '<table class="border centpercent">';
431 print '<tr><td class="titlefield">'.$langs->trans(
"Label").
'</td><td>'.$object->label.
'</td></tr>';
434 print '<td>'.$langs->trans(
"DateStartPeriod").
'</td><td>';
438 print '<tr><td>'.$langs->trans(
"DateEndPeriod").
'</td><td>';
443 print '<td>'.$langs->trans(
"DatePayment").
'</td><td>';
447 print '<tr><td>'.$langs->trans(
"DateValue").
'</td><td>';
451 print '<tr><td>'.$langs->trans(
"Amount").
'</td><td>'.
price($object->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).
'</td></tr>';
453 if (!empty($conf->banque->enabled))
455 if ($object->fk_account > 0)
458 $bankline->fetch($object->fk_bank);
461 print '<td>'.$langs->trans(
'BankTransactionLine').
'</td>';
463 print $bankline->getNomUrl(1, 0,
'showall');
470 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
481 print '<div class="tabsAction">'.
"\n";
482 if ($object->rappro == 0)
484 if (!empty($user->rights->salaries->delete))
486 print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=delete&token='.
newToken().
'">'.$langs->trans(
"Delete").
'</a></div>';
488 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.(dol_escape_htmltag($langs->trans(
"NotAllowed"))).
'">'.$langs->trans(
"Delete").
'</a></div>';
491 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans(
"LinkedToAConciliatedTransaction").
'">'.$langs->trans(
"Delete").
'</a></div>';
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
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...
Class to manage salary payments.
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Class to manage bank transaction lines.
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...
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage projects.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_getIdFromCode($db, $key, $tablename, $fieldkey= 'code', $fieldid= 'id', $entityfilter=0)
Return an id or code from a code or id.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
print
Draft customers invoices.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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.