30require
'../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formexpensereport.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
36require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
37require_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
39require_once DOL_DOCUMENT_ROOT.
'/core/lib/expensereport.lib.php';
40require_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
42require_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
43require_once DOL_DOCUMENT_ROOT.
'/core/modules/expensereport/modules_expensereport.php';
44require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
45require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/paymentexpensereport.class.php';
46require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
47require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
48if (isModEnabled(
'accounting')) {
49 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
53$langs->loadLangs(array(
"trips",
"bills",
"mails"));
55$action =
GETPOST(
'action',
'aZ09');
56$cancel =
GETPOST(
'cancel',
'alpha');
57$confirm =
GETPOST(
'confirm',
'alpha');
58$backtopage =
GETPOST(
'backtopage',
'alpha');
64$fk_project =
GETPOST(
'fk_project',
'int');
65$vatrate =
GETPOST(
'vatrate',
'alpha');
67$comments =
GETPOST(
'comments',
'restricthtml');
68$fk_c_type_fees =
GETPOST(
'fk_c_type_fees',
'int');
71$childids = $user->getAllChildIds(1);
74 if (empty($date_start)) {
78 if (empty($date_end)) {
85$rootfordata = DOL_DATA_ROOT;
86$rootforuser = DOL_DATA_ROOT;
88if (isModEnabled(
'multicompany') && !empty($conf->entity) && $conf->entity > 1) {
89 $rootfordata .=
'/'.$conf->entity;
91$conf->expensereport->dir_output = $rootfordata.
'/expensereport';
94$urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
95$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
108$extrafields->fetch_name_optionals_label($object->table_element);
111include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
114$hookmanager->initHooks(array(
'expensereportcard',
'globalcard'));
116$permissionnote = $user->rights->expensereport->creer;
117$permissiondellink = $user->rights->expensereport->creer;
118$permissiontoadd = $user->rights->expensereport->creer;
122$projectRequired = isModEnabled(
'project') &&
getDolGlobalString(
'EXPENSEREPORT_PROJECT_IS_REQUIRED');
125if ($object->id > 0) {
128 if ($user->hasRight(
'expensereport',
'readall')) {
131 if ($user->hasRight(
'expensereport',
'lire') && in_array($object->fk_user_author, $childids)) {
140if ($user->hasRight(
'expensereport',
'supprimer')) {
143if ($object->statut ==
ExpenseReport::STATUS_DRAFT && $user->hasRight(
'expensereport',
'write') && in_array($object->fk_user_author, $childids)) {
149 $socid = $user->socid;
151$result =
restrictedArea($user,
'expensereport', $object->id,
'expensereport');
153$permissiontoadd = $user->rights->expensereport->creer;
163$parameters = array(
'socid' => $socid);
164$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
169if (empty($reshook)) {
170 $backurlforlist = DOL_URL_ROOT.
'/expensereport/list.php';
172 if (empty($backtopage) || ($cancel && empty($id))) {
173 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
174 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
175 $backtopage = $backurlforlist;
177 $backtopage = DOL_URL_ROOT.
'/expensereport/card.php?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
183 if (!empty($backtopageforcancel)) {
184 header(
"Location: ".$backtopageforcancel);
186 } elseif (!empty($backtopage)) {
187 header(
"Location: ".$backtopage);
201 $fk_c_type_fees = -1;
204 include DOL_DOCUMENT_ROOT.
'/core/actions_linkedfiles.inc.php';
206 if (!empty(
GETPOST(
'sendit',
'alpha'))) {
207 if ($action ==
'updateline') {
208 $action =
'editline';
214 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
216 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
218 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
221 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $user->hasRight(
'expensereport',
'creer')) {
222 if (1 == 0 && !
GETPOST(
'clone_content',
'alpha') && !
GETPOST(
'clone_receivers',
'alpha')) {
225 if ($object->id > 0) {
227 $orig = clone $object;
229 $result = $object->createFromClone($user,
GETPOST(
'fk_user_author',
'int'));
231 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
242 if ($action ==
'confirm_delete' &&
GETPOST(
"confirm",
'alpha') ==
"yes" && $id > 0 && $candelete) {
244 $result = $object->fetch($id);
245 $result = $object->delete($user);
247 header(
"Location: index.php");
254 if ($action ==
'add' && $user->hasRight(
'expensereport',
'creer')) {
259 $object->date_debut = $date_start;
260 $object->date_fin = $date_end;
262 $object->fk_user_author =
GETPOST(
'fk_user_author',
'int');
263 if (!($object->fk_user_author > 0)) {
264 $object->fk_user_author = $user->id;
268 if ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'expensereport',
'creer'))
269 || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'expensereport',
'creer') && !$user->hasRight(
'expensereport',
'writeall_advance'))) {
274 if (!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') || !$user->hasRight(
'expensereport',
'writeall_advance')) {
275 if (!in_array($object->fk_user_author, $childids)) {
282 $fuser =
new User($db);
283 $fuser->fetch($object->fk_user_author);
286 $object->fk_c_paiement =
GETPOST(
'fk_c_paiement',
'int');
287 $object->fk_user_validator =
GETPOST(
'fk_user_validator',
'int');
288 $object->note_public =
GETPOST(
'note_public',
'restricthtml');
289 $object->note_private =
GETPOST(
'note_private',
'restricthtml');
292 $ret = $extrafields->setOptionalsFromPost(
null, $object);
299 $overlappingExpenseReportID = $object->periode_existe($fuser, $object->date_debut, $object->date_fin);
301 if ($overlappingExpenseReportID > 0) {
303 setEventMessages($langs->trans(
"ErrorDoubleDeclaration").
' <a href="'.$_SERVER[
'PHP_SELF'].
'?id='.$overlappingExpenseReportID.
'">'. $langs->trans(
'ShowTrip').
'</a>',
null,
'errors');
311 $id = $object->create($user);
318 Header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
328 if (($action ==
'update' || $action ==
'updateFromRefuse') && $user->hasRight(
'expensereport',
'creer')) {
332 $object->date_debut = $date_start;
333 $object->date_fin = $date_end;
335 if ($object->status < 3) {
336 $object->fk_user_validator =
GETPOST(
'fk_user_validator',
'int');
339 $object->fk_c_paiement =
GETPOST(
'fk_c_paiement',
'int');
340 $object->note_public =
GETPOST(
'note_public',
'restricthtml');
341 $object->note_private =
GETPOST(
'note_private',
'restricthtml');
342 $object->fk_user_modif = $user->id;
344 $result = $object->update($user);
346 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
GETPOST(
'id',
'int'));
353 if ($action ==
'update_extras') {
354 $object->oldcopy =
dol_clone($object, 2);
357 $ret = $extrafields->setOptionalsFromPost(
null, $object,
GETPOST(
'attribute',
'restricthtml'));
364 $result = $object->insertExtraFields(
'EXPENSEREPORT_MODIFY');
372 $action =
'edit_extras';
376 if ($action ==
"confirm_validate" &&
GETPOST(
"confirm",
'alpha') ==
"yes" && $id > 0 && $user->hasRight(
'expensereport',
'creer')) {
384 $result = $object->setValidate($user);
389 $outputlangs = $langs;
392 $newlang =
GETPOST(
'lang_id',
'aZ09');
395 $newlang = $object->thirdparty->default_lang;
397 if (!empty($newlang)) {
399 $outputlangs->setDefaultLang($newlang);
401 $model = $object->model_pdf;
402 $ret = $object->fetch($id);
404 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
411 if (!$error && $result > 0 && $object->fk_user_validator > 0) {
412 $langs->load(
"mails");
415 $destinataire =
new User($db);
416 $destinataire->fetch($object->fk_user_validator);
417 $emailTo = $destinataire->email;
420 $expediteur =
new User($db);
421 $expediteur->fetch($object->fk_user_author);
422 $emailFrom = $conf->global->MAIN_MAIL_EMAIL_FROM;
424 if ($emailTo && $emailFrom) {
430 $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
432 $societeName = $conf->global->MAIN_APPLICATION_TITLE;
435 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportWaitingForApproval");
438 $link = $urlwithroot.
'/expensereport/card.php?id='.$object->id;
439 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
440 $message = $langs->transnoentities(
"ExpenseReportWaitingForApprovalMessage", $expediteur->getFullName($langs),
get_date_range($object->date_debut, $object->date_fin,
'', $langs), $link);
455 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
459 $result = $mailfile->sendfile();
461 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
464 $langs->load(
"other");
465 if (!empty($mailfile->error) || !empty($mailfile->errors)) {
468 if (!empty($mailfile->error)) {
469 $mesg .=
'<br>' . $mailfile->error;
471 if (!empty($mailfile->errors) && is_array($mailfile->errors)) {
472 $mesg .=
'<br>' . implode(
'<br>', $mailfile->errors);
476 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
484 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
491 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
498 if ($action ==
"confirm_save_from_refuse" &&
GETPOST(
"confirm",
'alpha') ==
"yes" && $id > 0 && $user->hasRight(
'expensereport',
'creer')) {
501 $result = $object->set_save_from_refuse($user);
506 $outputlangs = $langs;
509 $newlang =
GETPOST(
'lang_id',
'aZ09');
512 $newlang = $object->thirdparty->default_lang;
514 if (!empty($newlang)) {
516 $outputlangs->setDefaultLang($newlang);
518 $model = $object->model_pdf;
519 $ret = $object->fetch($id);
521 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
529 $destinataire =
new User($db);
530 $destinataire->fetch($object->fk_user_validator);
531 $emailTo = $destinataire->email;
534 $expediteur =
new User($db);
535 $expediteur->fetch($object->fk_user_author);
536 $emailFrom = $conf->global->MAIN_MAIL_EMAIL_FROM;
538 if ($emailFrom && $emailTo) {
544 $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
546 $societeName = $conf->global->MAIN_APPLICATION_TITLE;
549 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportWaitingForReApproval");
552 $link = $urlwithroot.
'/expensereport/card.php?id='.$object->id;
553 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
554 $message = $langs->transnoentities(
"ExpenseReportWaitingForReApprovalMessage",
dol_print_date($object->date_refuse,
'day'), $object->detail_refuse, $expediteur->getFullName($langs),
get_date_range($object->date_debut, $object->date_fin,
'', $langs), $link);
573 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
577 $result = $mailfile->sendfile();
579 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
581 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
584 $langs->load(
"other");
585 if ($mailfile->error) {
587 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
588 $mesg .=
'<br>'.$mailfile->error;
591 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
599 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
608 if ($action ==
"confirm_approve" &&
GETPOST(
"confirm",
'alpha') ==
"yes" && $id > 0 && $user->hasRight(
'expensereport',
'approve')) {
612 $result = $object->setApproved($user);
617 $outputlangs = $langs;
620 $newlang =
GETPOST(
'lang_id',
'aZ09');
623 $newlang = $object->thirdparty->default_lang;
625 if (!empty($newlang)) {
627 $outputlangs->setDefaultLang($newlang);
629 $model = $object->model_pdf;
630 $ret = $object->fetch($id);
632 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
640 $destinataire =
new User($db);
641 $destinataire->fetch($object->fk_user_author);
642 $emailTo = $destinataire->email;
646 if (empty($emailTo)) {
651 $expediteur =
new User($db);
652 $expediteur->fetch($object->fk_user_approve > 0 ? $object->fk_user_approve : $object->fk_user_validator);
655 if ($emailFrom && $emailTo) {
666 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportApproved");
669 $link = $urlwithroot.
'/expensereport/card.php?id='.$object->id;
670 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
671 $message = $langs->transnoentities(
"ExpenseReportApprovedMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $link);
688 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
692 $result = $mailfile->sendfile();
694 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
696 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
699 $langs->load(
"other");
700 if ($mailfile->error) {
702 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
703 $mesg .=
'<br>'.$mailfile->error;
706 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
714 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
723 if ($action ==
"confirm_refuse" &&
GETPOST(
'confirm',
'alpha') ==
"yes" && $id > 0 && $user->hasRight(
'expensereport',
'approve')) {
727 $detailRefuse =
GETPOST(
'detail_refuse',
'alpha');
728 $result = $object->setDeny($user, $detailRefuse);
733 $outputlangs = $langs;
736 $newlang =
GETPOST(
'lang_id',
'aZ09');
739 $newlang = $object->thirdparty->default_lang;
741 if (!empty($newlang)) {
743 $outputlangs->setDefaultLang($newlang);
745 $model = $object->model_pdf;
746 $ret = $object->fetch($id);
748 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
756 $destinataire =
new User($db);
757 $destinataire->fetch($object->fk_user_author);
758 $emailTo = $destinataire->email;
761 $expediteur =
new User($db);
762 $expediteur->fetch($object->fk_user_refuse);
763 $emailFrom = $conf->global->MAIN_MAIL_EMAIL_FROM;
765 if ($emailFrom && $emailTo) {
771 $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
773 $societeName = $conf->global->MAIN_APPLICATION_TITLE;
776 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportRefused");
779 $link = $urlwithroot.
'/expensereport/card.php?id='.$object->id;
780 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
781 $message = $langs->transnoentities(
"ExpenseReportRefusedMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $detailRefuse, $link);
799 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
803 $result = $mailfile->sendfile();
805 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
807 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
810 $langs->load(
"other");
811 if ($mailfile->error) {
813 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
814 $mesg .=
'<br>'.$mailfile->error;
817 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
825 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
835 if ($action ==
"confirm_cancel" &&
GETPOST(
'confirm',
'alpha') ==
"yes" && $id > 0 && $user->hasRight(
'expensereport',
'creer')) {
836 if (!
GETPOST(
'detail_cancel',
'alpha')) {
837 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Comment")),
null,
'errors');
842 if ($user->id == $object->fk_user_valid || $user->id == $object->fk_user_author) {
843 $detailCancel =
GETPOST(
'detail_cancel',
'alpha');
844 $result = $object->set_cancel($user, $detailCancel);
849 $outputlangs = $langs;
852 $newlang =
GETPOST(
'lang_id',
'aZ09');
855 $newlang = $object->thirdparty->default_lang;
857 if (!empty($newlang)) {
859 $outputlangs->setDefaultLang($newlang);
861 $model = $object->model_pdf;
862 $ret = $object->fetch($id);
864 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
872 $destinataire =
new User($db);
873 $destinataire->fetch($object->fk_user_author);
874 $emailTo = $destinataire->email;
877 $expediteur =
new User($db);
878 $expediteur->fetch($object->fk_user_cancel);
879 $emailFrom = $conf->global->MAIN_MAIL_EMAIL_FROM;
881 if ($emailFrom && $emailTo) {
887 $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
889 $societeName = $conf->global->MAIN_APPLICATION_TITLE;
892 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportCanceled");
895 $link = $urlwithroot.
'/expensereport/card.php?id='.$object->id;
896 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
897 $message = $langs->transnoentities(
"ExpenseReportCanceledMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $detailCancel, $link);
915 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
919 $result = $mailfile->sendfile();
921 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
923 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
926 $langs->load(
"other");
927 if ($mailfile->error) {
929 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
930 $mesg .=
'<br>'.$mailfile->error;
933 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
941 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
954 if ($action ==
"confirm_setdraft" &&
GETPOST(
'confirm',
'alpha') ==
"yes" && $id > 0 && $user->hasRight(
'expensereport',
'creer')) {
957 if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) {
958 $result = $object->setStatut(0);
963 $outputlangs = $langs;
966 $newlang =
GETPOST(
'lang_id',
'aZ09');
969 $newlang = $object->thirdparty->default_lang;
971 if (!empty($newlang)) {
973 $outputlangs->setDefaultLang($newlang);
975 $model = $object->model_pdf;
976 $ret = $object->fetch($id);
978 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
983 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
993 if ($action ==
'set_unpaid' && $id > 0 && $user->hasRight(
'expensereport',
'to_paid')) {
997 $result = $object->setUnpaid($user);
1002 $outputlangs = $langs;
1005 $newlang =
GETPOST(
'lang_id',
'aZ09');
1008 $newlang = $object->thirdparty->default_lang;
1010 if (!empty($newlang)) {
1011 $outputlangs =
new Translate(
"", $conf);
1012 $outputlangs->setDefaultLang($newlang);
1014 $model = $object->model_pdf;
1015 $ret = $object->fetch($id);
1017 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1022 if ($action ==
'set_paid' && $id > 0 && $user->hasRight(
'expensereport',
'to_paid')) {
1024 $object->fetch($id);
1026 $result = $object->setPaid($id, $user);
1031 $outputlangs = $langs;
1034 $newlang =
GETPOST(
'lang_id',
'aZ09');
1037 $newlang = $object->thirdparty->default_lang;
1039 if (!empty($newlang)) {
1040 $outputlangs =
new Translate(
"", $conf);
1041 $outputlangs->setDefaultLang($newlang);
1043 $model = $object->model_pdf;
1044 $ret = $object->fetch($id);
1046 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1054 $destinataire =
new User($db);
1055 $destinataire->fetch($object->fk_user_author);
1056 $emailTo = $destinataire->email;
1059 $expediteur =
new User($db);
1060 $expediteur->fetch($user->id);
1061 $emailFrom = $conf->global->MAIN_MAIL_EMAIL_FROM;
1063 if ($emailFrom && $emailTo) {
1064 $filename = array();
1066 $mimetype = array();
1069 $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
1071 $societeName = $conf->global->MAIN_APPLICATION_TITLE;
1074 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportPaid");
1077 $link = $urlwithroot.
'/expensereport/card.php?id='.$object->id;
1078 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
1079 $message = $langs->transnoentities(
"ExpenseReportPaidMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $link);
1082 $object->setDocModel($user,
"");
1083 $resultPDF = expensereport_pdf_create($db, $object,
'',
"", $langs);
1086 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
1090 $result = $mailfile->sendfile();
1092 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
1094 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
1097 $langs->load(
"other");
1098 if ($mailfile->error) {
1100 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
1101 $mesg .=
'<br>'.$mailfile->error;
1104 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
1112 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
1121 if ($action ==
"addline" && $user->hasRight(
'expensereport',
'creer')) {
1126 if (GETPOSTISSET(
'attachfile')) {
1127 $arrayoffiles =
GETPOST(
'attachfile',
'array');
1128 if (is_array($arrayoffiles) && !empty($arrayoffiles[0])) {
1129 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1130 $entityprefix = ($conf->entity !=
'1') ? $conf->entity.
'/' :
'';
1131 $relativepath =
'expensereport/'.$object->ref.
'/'.$arrayoffiles[0];
1133 $ecmfiles->fetch(0,
'', $relativepath);
1134 $fk_ecm_files = $ecmfiles->id;
1139 if (empty($vatrate)) {
1142 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $vatrate));
1146 if (empty($value_unit)) {
1147 $value_unit =
price2num($value_unit_ht + ($value_unit_ht * $tmpvat / 100),
'MU');
1150 $fk_c_exp_tax_cat =
GETPOST(
'fk_c_exp_tax_cat',
'int');
1157 if (!($fk_c_type_fees > 0)) {
1159 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1163 if ((
float) $tmpvat < 0 || $tmpvat ===
'') {
1165 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"VAT")),
null,
'errors');
1170 if (empty($date) || $date ==
"--") {
1172 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1173 } elseif ($date < $object->date_debut || $date > ($object->date_fin + (24 * 3600 - 1))) {
1175 $langs->load(
"errors");
1176 setEventMessages($langs->trans(
"WarningDateOfLineMustBeInExpenseReportRange"),
null,
'warnings');
1180 if ($value_unit == 0) {
1182 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"PriceUTTC")),
null,
'errors');
1186 if ($projectRequired && $fk_project <= 0) {
1188 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Project")),
null,
'errors');
1192 if ($fileRequired && $fk_ecm_files == 0) {
1194 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"File")),
null,
'errors');
1201 $result = $object->addline($qty, $value_unit, $fk_c_type_fees, $vatrate, $date, $comments, $fk_project, $fk_c_exp_tax_cat, $type, $fk_ecm_files);
1203 $ret = $object->fetch($object->id);
1207 $outputlangs = $langs;
1208 $newlang =
GETPOST(
'lang_id',
'alpha');
1210 $user =
new User($db);
1211 $user->fetch($object->fk_user_author);
1212 $newlang = $user->lang;
1214 if (!empty($newlang)) {
1215 $outputlangs =
new Translate(
"", $conf);
1216 $outputlangs->setDefaultLang($newlang);
1219 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1223 unset($value_unit_ht);
1227 unset($fk_c_type_fees);
1238 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
GETPOST(
'id',
'int'));
1245 if ($action ==
'confirm_delete_line' &&
GETPOST(
"confirm",
'alpha') ==
"yes" && $user->hasRight(
'expensereport',
'creer')) {
1247 $object->fetch($id);
1250 $object_ligne->fetch(
GETPOST(
"rowid",
'int'));
1251 $total_ht = $object_ligne->total_ht;
1252 $total_tva = $object_ligne->total_tva;
1254 $result = $object->deleteline(
GETPOST(
"rowid",
'int'), $user);
1259 $outputlangs = $langs;
1262 $newlang =
GETPOST(
'lang_id',
'aZ09');
1265 $newlang = $object->thirdparty->default_lang;
1267 if (!empty($newlang)) {
1268 $outputlangs =
new Translate(
"", $conf);
1269 $outputlangs->setDefaultLang($newlang);
1271 $model = $object->model_pdf;
1272 $ret = $object->fetch($id);
1274 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1278 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
GETPOST(
'id',
'int'));
1285 if ($action ==
"updateline" && $user->hasRight(
'expensereport',
'creer')) {
1287 $object->fetch($id);
1291 if (GETPOSTISSET(
'attachfile')) {
1292 $arrayoffiles =
GETPOST(
'attachfile',
'array');
1293 if (is_array($arrayoffiles) && !empty($arrayoffiles[0])) {
1294 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1295 $relativepath =
'expensereport/'.$object->ref.
'/'.$arrayoffiles[0];
1297 $ecmfiles->fetch(0,
'', $relativepath);
1298 $fk_ecm_files = $ecmfiles->id;
1302 $rowid =
GETPOST(
'rowid',
'int');
1303 $type_fees_id =
GETPOST(
'fk_c_type_fees',
'int');
1304 $fk_c_exp_tax_cat =
GETPOST(
'fk_c_exp_tax_cat',
'int');
1305 $projet_id = $fk_project;
1306 $comments =
GETPOST(
'comments',
'restricthtml');
1308 $vatrate =
GETPOST(
'vatrate',
'alpha');
1311 if (empty($vatrate)) {
1314 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $vatrate));
1318 if (empty($value_unit)) {
1319 $value_unit =
price2num($value_unit_ht + ($value_unit_ht * $tmpvat / 100),
'MU');
1322 if (!
GETPOST(
'fk_c_type_fees',
'int') > 0) {
1324 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1327 if ((
float) $tmpvat < 0 || $tmpvat ==
'') {
1329 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Vat")),
null,
'errors');
1333 if ($date < $object->date_debut || $date > ($object->date_fin + (24 * 3600 - 1))) {
1334 $langs->load(
"errors");
1335 setEventMessages($langs->trans(
"WarningDateOfLineMustBeInExpenseReportRange"),
null,
'warnings');
1339 if ($projectRequired && $projet_id <= 0) {
1341 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Project")),
null,
'errors');
1346 $result = $object->updateline($rowid, $type_fees_id, $projet_id, $vatrate, $comments, $qty, $value_unit, $date, $id, $fk_c_exp_tax_cat, $fk_ecm_files);
1351 $outputlangs = $langs;
1354 $newlang =
GETPOST(
'lang_id',
'aZ09');
1357 $newlang = $object->thirdparty->default_lang;
1359 if (!empty($newlang)) {
1360 $outputlangs =
new Translate(
"", $conf);
1361 $outputlangs->setDefaultLang($newlang);
1363 $model = $object->model_pdf;
1364 $ret = $object->fetch($id);
1366 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1370 unset($value_unit_ht);
1374 unset($fk_c_type_fees);
1388 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
1391 $triggersendname =
'EXPENSEREPORT_SENTBYMAIL';
1392 $autocopy =
'MAIN_MAIL_AUTOCOPY_EXPENSEREPORT_TO';
1393 $trackid =
'exp'.$object->id;
1394 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
1397 $upload_dir = $conf->expensereport->dir_output;
1398 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1406$title = $langs->trans(
"ExpenseReport").
" - ".$langs->trans(
"Card");
1407$help_url =
"EN:Module_Expense_Reports|FR:Module_Notes_de_frais";
1411$form =
new Form($db);
1414$projecttmp =
new Project($db);
1416$bankaccountstatic =
new Account($db);
1417$ecmfilesstatic =
new EcmFiles($db);
1421if ($action ==
'create') {
1424 print
'<form action="'.$_SERVER[
'PHP_SELF'].
'" method="post" name="create">';
1425 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1426 print
'<input type="hidden" name="action" value="add">';
1427 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
1431 print
'<table class="border centpercent">';
1436 print
'<td class="titlefieldcreate fieldrequired">'.$langs->trans(
"DateStart").
'</td>';
1438 print $form->selectDate($date_start ? $date_start : -1,
'date_debut', 0, 0, 0,
'', 1, 1);
1444 print
'<td class="fieldrequired">'.$langs->trans(
"DateEnd").
'</td>';
1446 print $form->selectDate($date_end ? $date_end : -1,
'date_fin', 0, 0, 0,
'', 1, 1);
1452 print
'<td class="fieldrequired">'.$langs->trans(
"User").
'</td>';
1454 $defaultselectuser = $user->id;
1455 if (
GETPOST(
'fk_user_author',
'int') > 0) {
1456 $defaultselectuser =
GETPOST(
'fk_user_author',
'int');
1458 $include_users =
'hierarchyme';
1459 if (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'expensereport',
'writeall_advance')) {
1460 $include_users = array();
1462 $s = $form->select_dolusers($defaultselectuser,
"fk_user_author", 0,
"", 0, $include_users,
'',
'0,'.$conf->entity);
1469 print
'<td>'.$langs->trans(
"VALIDATOR").
'</td>';
1472 $include_users = $object->fetch_users_approver_expensereport();
1473 if (empty($include_users)) {
1474 print
img_warning().
' '.$langs->trans(
"NobodyHasPermissionToValidateExpenseReport");
1476 $defaultselectuser = (empty($user->fk_user_expense_validator) ? $user->fk_user : $user->fk_user_expense_validator);
1478 $defaultselectuser = $conf->global->EXPENSEREPORT_DEFAULT_VALIDATOR;
1480 if (
GETPOST(
'fk_user_validator',
'int') > 0) {
1481 $defaultselectuser =
GETPOST(
'fk_user_validator',
'int');
1483 $s = $form->select_dolusers($defaultselectuser,
"fk_user_validator", 1,
"", ((empty($defaultselectuser) || !
getDolGlobalString(
'EXPENSEREPORT_DEFAULT_VALIDATOR_UNCHANGEABLE')) ? 0 : 1), $include_users);
1484 print $form->textwithpicto($s, $langs->trans(
"AnyOtherInThisListCanValidate"));
1492 print
'<td>'.$langs->trans(
"ModePaiement").
'</td>';
1494 $form->select_types_paiements(
'',
'fk_c_paiement');
1500 $note_public = GETPOSTISSET(
'note_public') ?
GETPOST(
'note_public',
'restricthtml') :
'';
1503 print
'<td class="tdtop">'.$langs->trans(
'NotePublic').
'</td>';
1506 $doleditor =
new DolEditor(
'note_public', $note_public,
'', 80,
'dolibarr_notes',
'In', 0,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3,
'90%');
1507 print $doleditor->Create(1);
1511 $note_private = GETPOSTISSET(
'note_private') ?
GETPOST(
'note_private',
'restricthtml') :
'';
1513 if (empty($user->socid)) {
1515 print
'<td class="tdtop">'.$langs->trans(
'NotePrivate').
'</td>';
1518 $doleditor =
new DolEditor(
'note_private', $note_private,
'', 80,
'dolibarr_notes',
'In', 0,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3,
'90%');
1519 print $doleditor->Create(1);
1524 $parameters = array(
'colspan' =>
' colspan="3"',
'cols' => 3);
1525 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
1526 print $hookmanager->resPrint;
1527 if (empty($reshook)) {
1528 print $object->showOptionals($extrafields,
'create', $parameters);
1536 print $form->buttonsSaveCancel(
"AddTrip");
1539} elseif ($id > 0 || $ref) {
1540 $result = $object->fetch($id, $ref);
1543 if (!in_array($object->fk_user_author, $user->getAllChildIds(1))) {
1544 if (!$user->hasRight(
'expensereport',
'readall') && !$user->hasRight(
'expensereport',
'lire_tous')
1545 && (!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') || !$user->hasRight(
'expensereport',
'writeall_advance'))) {
1548 print
'<div class="tabBar">';
1549 print $langs->trans(
'NotUserRightToView');
1562 if ($action ==
'edit' && ($object->status < 3 || $object->status == 99)) {
1563 print
"<form name='update' action=\"".$_SERVER[
'PHP_SELF'].
"\" method=\"post\">\n";
1564 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1565 print
'<input type="hidden" name="id" value="'.$id.
'">';
1566 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
1570 if ($object->status == 99) {
1571 print
'<input type="hidden" name="action" value="updateFromRefuse">';
1573 print
'<input type="hidden" name="action" value="update">';
1576 $linkback =
'<a href="'.DOL_URL_ROOT.
'/expensereport/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
1578 print
'<table class="border centpercent">';
1581 print
'<td>'.$langs->trans(
"User").
'</td>';
1583 $userfee =
new User($db);
1584 if ($object->fk_user_author > 0) {
1585 $userfee->fetch($object->fk_user_author);
1586 print $userfee->getNomUrl(-1);
1591 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Ref").
'</td><td>';
1592 print $form->showrefnav($object,
'ref', $linkback, 1,
'ref',
'ref',
'');
1596 print
'<td>'.$langs->trans(
"DateStart").
'</td>';
1598 print $form->selectDate($object->date_debut,
'date_debut');
1602 print
'<td>'.$langs->trans(
"DateEnd").
'</td>';
1604 print $form->selectDate($object->date_fin,
'date_fin');
1610 print
'<td>'.$langs->trans(
"ModePaiement").
'</td>';
1612 $form->select_types_paiements($object->fk_c_paiement,
'fk_c_paiement');
1617 if ($object->status < 3) {
1619 print
'<td>'.$langs->trans(
"VALIDATOR").
'</td>';
1621 $include_users = $object->fetch_users_approver_expensereport();
1622 $s = $form->select_dolusers($object->fk_user_validator,
"fk_user_validator", 1,
"", 0, $include_users);
1623 print $form->textwithpicto($s, $langs->trans(
"AnyOtherInThisListCanValidate"));
1628 print
'<td>'.$langs->trans(
"VALIDOR").
'</td>';
1630 $userfee =
new User($db);
1631 $userfee->fetch($object->fk_user_valid);
1632 print $userfee->getNomUrl(-1);
1636 if ($object->status == 6) {
1638 print
'<td>'.$langs->trans(
"AUTHORPAIEMENT").
'</td>';
1640 $userfee =
new User($db);
1641 $userfee->fetch($user->id);
1642 print $userfee->getNomUrl(-1);
1654 print $form->buttonsSaveCancel(
"Modify");
1658 $taxlessUnitPriceDisabled =
getDolGlobalString(
'EXPENSEREPORT_FORCE_LINE_AMOUNTS_INCLUDING_TAXES_ONLY') ?
' disabled' :
'';
1665 if ($action ==
'clone') {
1667 $criteriaforfilter =
'hierarchyme';
1668 if ($user->hasRight(
'expensereport',
'readall')) {
1669 $criteriaforfilter =
'';
1671 $formquestion = array(
1673 array(
'type' =>
'other',
'name' =>
'fk_user_author',
'label' => $langs->trans(
"SelectTargetUser"),
'value' => $form->select_dolusers((
GETPOST(
'fk_user_author',
'int') > 0 ?
GETPOST(
'fk_user_author',
'int') : $user->id),
'fk_user_author', 0, null, 0, $criteriaforfilter,
'',
'0', 0, 0,
'', 0,
'',
'maxwidth150'))
1676 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneExpenseReport', $object->ref),
'confirm_clone', $formquestion,
'yes', 1);
1679 if ($action ==
'save') {
1680 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"SaveTrip"), $langs->trans(
"ConfirmSaveTrip"),
"confirm_validate",
"",
"", 1);
1683 if ($action ==
'save_from_refuse') {
1684 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"SaveTrip"), $langs->trans(
"ConfirmSaveTrip"),
"confirm_save_from_refuse",
"",
"", 1);
1687 if ($action ==
'delete') {
1688 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"DeleteTrip"), $langs->trans(
"ConfirmDeleteTrip"),
"confirm_delete",
"",
"", 1);
1691 if ($action ==
'validate') {
1692 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"ValideTrip"), $langs->trans(
"ConfirmValideTrip"),
"confirm_approve",
"",
"", 1);
1695 if ($action ==
'paid') {
1696 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"PaidTrip"), $langs->trans(
"ConfirmPaidTrip"),
"confirm_paid",
"",
"", 1);
1699 if ($action ==
'cancel') {
1700 $array_input = array(
'text'=>$langs->trans(
"ConfirmCancelTrip"), array(
'type'=>
"text",
'label'=>
'<strong>'.$langs->trans(
"Comment").
'</strong>',
'name'=>
"detail_cancel",
'value'=>
""));
1701 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"Cancel"),
"",
"confirm_cancel", $array_input,
"", 1);
1704 if ($action ==
'setdraft') {
1705 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"BrouillonnerTrip"), $langs->trans(
"ConfirmBrouillonnerTrip"),
"confirm_setdraft",
"",
"", 1);
1708 if ($action ==
'refuse') {
1709 $array_input = array(
'text'=>$langs->trans(
"ConfirmRefuseTrip"), array(
'type'=>
"text",
'label'=>$langs->trans(
"Comment"),
'name'=>
"detail_refuse",
'value'=>
""));
1710 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"Deny"),
'',
"confirm_refuse", $array_input,
"yes", 1);
1713 if ($action ==
'delete_line') {
1714 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id.
"&rowid=".
GETPOST(
'rowid',
'int'), $langs->trans(
"DeleteLine"), $langs->trans(
"ConfirmDeleteLine"),
"confirm_delete_line",
'',
'yes', 1);
1721 $linkback =
'<a href="'.DOL_URL_ROOT.
'/expensereport/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
1723 $morehtmlref =
'<div class="refidno">';
1724 $morehtmlref .=
'</div>';
1726 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
1728 print
'<div class="fichecenter">';
1729 print
'<div class="fichehalfleft">';
1730 print
'<div class="underbanner clearboth"></div>';
1732 print
'<table class="border tableforfield centpercent">';
1736 print
'<td class="titlefield">'.$langs->trans(
"User").
'</td>';
1738 if ($object->fk_user_author > 0) {
1739 $userauthor =
new User($db);
1740 $result = $userauthor->fetch($object->fk_user_author);
1743 } elseif ($result > 0) {
1744 print $userauthor->getNomUrl(-1);
1751 print
'<td class="titlefield">'.$langs->trans(
"Period").
'</td>';
1753 print
get_date_range($object->date_debut, $object->date_fin,
'day', $langs, 0);
1758 print
'<td>'.$langs->trans(
"ModePaiement").
'</td>';
1759 print
'<td>'.$object->fk_c_paiement.
'</td>';
1765 print
'<td>'.$langs->trans(
"DATE_SAVE").
'</td>';
1766 print
'<td>'.dol_print_date($object->date_valid,
'dayhour',
'tzuser');
1767 if ($object->status == 2 && $object->hasDelay(
'toapprove')) {
1768 print
' '.img_warning($langs->trans(
"Late").
' - '.$langs->trans(
"ToApprove"));
1770 if ($object->status == 5 && $object->hasDelay(
'topay')) {
1771 print
' '.img_warning($langs->trans(
"Late").
' - '.$langs->trans(
"ToPay"));
1779 print
'<td>'.$langs->trans(
"VALIDATOR").
'</td>';
1781 if ($object->fk_user_validator > 0) {
1782 $userfee =
new User($db);
1783 $result = $userfee->fetch($object->fk_user_validator);
1785 print $userfee->getNomUrl(-1);
1787 if (empty($userfee->email) || !
isValidEmail($userfee->email)) {
1788 $langs->load(
"errors");
1789 print
img_warning($langs->trans(
"ErrorBadEMail", $userfee->email));
1795 print
'<td>'.$langs->trans(
"CANCEL_USER").
'</span></td>';
1797 if ($object->fk_user_cancel > 0) {
1798 $userfee =
new User($db);
1799 $result = $userfee->fetch($object->fk_user_cancel);
1801 print $userfee->getNomUrl(-1);
1807 print
'<td>'.$langs->trans(
"MOTIF_CANCEL").
'</td>';
1808 print
'<td>'.$object->detail_cancel.
'</td></tr>';
1811 print
'<td>'.$langs->trans(
"DATE_CANCEL").
'</td>';
1812 print
'<td>'.dol_print_date($object->date_cancel,
'dayhour',
'tzuser').
'</td></tr>';
1816 print
'<td>'.$langs->trans(
"ApprovedBy").
'</td>';
1818 if ($object->fk_user_approve > 0) {
1819 $userapp =
new User($db);
1820 $result = $userapp->fetch($object->fk_user_approve);
1822 print $userapp->getNomUrl(-1);
1828 print
'<td>'.$langs->trans(
"DateApprove").
'</td>';
1829 print
'<td>'.dol_print_date($object->date_approve,
'dayhour',
'tzuser').
'</td></tr>';
1833 if ($object->status == 99 || !empty($object->detail_refuse)) {
1835 print
'<td>'.$langs->trans(
"REFUSEUR").
'</td>';
1837 $userfee =
new User($db);
1838 $result = $userfee->fetch($object->fk_user_refuse);
1840 print $userfee->getNomUrl(-1);
1845 print
'<td>'.$langs->trans(
"DATE_REFUS").
'</td>';
1846 print
'<td>'.dol_print_date($object->date_refuse,
'dayhour',
'tzuser');
1847 if ($object->detail_refuse) {
1848 print
' - '.$object->detail_refuse;
1854 if ($object->status == $object::STATUS_CLOSED) {
1872 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
1877 print
'<div class="fichehalfright">';
1878 print
'<div class="underbanner clearboth"></div>';
1880 print
'<table class="border tableforfield centpercent">';
1884 print
'<td class="titlefieldmiddle">'.$langs->trans(
"AmountHT").
'</td>';
1885 print
'<td class="nowrap amountcard">'.price($object->total_ht, 1,
'', 1, - 1, - 1, $conf->currency).
'</td>';
1904 print
'<td>'.$langs->trans(
"AmountVAT").
'</td>';
1905 print
'<td class="nowrap amountcard">'.price($object->total_tva, 1,
'', 1, -1, -1, $conf->currency).
'</td>';
1909 if ($mysoc->localtax1_assuj ==
"1" || $object->total_localtax1 != 0) {
1910 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td>';
1911 print
'<td class="valuefield">'.price($object->total_localtax1, 1,
'', 1, -1, -1, $conf->currency).
'</td></tr>';
1913 if ($mysoc->localtax2_assuj ==
"1" || $object->total_localtax2 != 0) {
1914 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td>';
1915 print
'<td class="valuefield">'.price($object->total_localtax2, 1,
'', 1, -1, -1, $conf->currency).
'</td></tr>';
1919 print
'<td>'.$langs->trans(
"AmountTTC").
'</td>';
1920 print
'<td class="nowrap amountcard">'.price($object->total_ttc, 1,
'', 1, -1, -1, $conf->currency).
'</td>';
1926 if (isModEnabled(
"banque")) {
1931 print
'<table class="noborder paymenttable centpercent">';
1933 print
'<tr class="liste_titre">';
1934 print
'<td class="liste_titre">'.$langs->trans(
'Payments').
'</td>';
1935 print
'<td class="liste_titre">'.$langs->trans(
'Date').
'</td>';
1936 print
'<td class="liste_titre">'.$langs->trans(
'Type').
'</td>';
1937 if (isModEnabled(
"banque")) {
1938 print
'<td class="liste_titre right">'.$langs->trans(
'BankAccount').
'</td>';
1940 print
'<td class="liste_titre right">'.$langs->trans(
'Amount').
'</td>';
1941 print
'<td class="liste_titre" width="18"> </td>';
1945 $sql =
"SELECT p.rowid, p.num_payment, p.datep as dp, p.amount, p.fk_bank,";
1946 $sql .=
"c.code as payment_code, c.libelle as payment_type,";
1947 $sql .=
"ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal";
1948 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as e, ".MAIN_DB_PREFIX.
"payment_expensereport as p";
1949 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON p.fk_typepayment = c.id";
1950 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
1951 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
1952 $sql .=
" WHERE e.rowid = ".((int) $id);
1953 $sql .=
" AND p.fk_expensereport = e.rowid";
1954 $sql .=
' AND e.entity IN ('.getEntity(
'expensereport').
')';
1955 $sql .=
" ORDER BY dp";
1957 $resql = $db->query($sql);
1959 $num = $db->num_rows($resql);
1963 $objp = $db->fetch_object($resql);
1965 $paymentexpensereportstatic->id = $objp->rowid;
1966 $paymentexpensereportstatic->datep = $db->jdate($objp->dp);
1967 $paymentexpensereportstatic->ref = $objp->rowid;
1968 $paymentexpensereportstatic->num_payment = $objp->num_payment;
1969 $paymentexpensereportstatic->type_code = $objp->payment_code;
1970 $paymentexpensereportstatic->type_label = $objp->payment_type;
1972 print
'<tr class="oddseven">';
1974 print $paymentexpensereportstatic->getNomUrl(1);
1976 print
'<td>'.dol_print_date($db->jdate($objp->dp),
'day').
"</td>\n";
1977 $labeltype = $langs->trans(
"PaymentType".$objp->payment_code) !=
"PaymentType".$objp->payment_code ? $langs->trans(
"PaymentType".$objp->payment_code) : $objp->payment_type;
1978 print
"<td>".$labeltype.
' '.$objp->num_payment.
"</td>\n";
1980 if (isModEnabled(
"banque")) {
1981 $bankaccountstatic->id = $objp->baid;
1982 $bankaccountstatic->ref = $objp->baref;
1983 $bankaccountstatic->label = $objp->baref;
1984 $bankaccountstatic->number = $objp->banumber;
1986 if (isModEnabled(
'accounting')) {
1987 $bankaccountstatic->account_number = $objp->account_number;
1990 $accountingjournal->fetch($objp->fk_accountancy_journal);
1991 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
1994 print
'<td class="right">';
1995 if ($bankaccountstatic->id) {
1996 print $bankaccountstatic->getNomUrl(1,
'transactions');
2000 print
'<td class="right">'.price($objp->amount).
"</td>";
2003 $totalpaid += $objp->amount;
2006 if (!is_null($totalpaid)) {
2010 $remaintopay =
price2num($object->total_ttc - $totalpaid);
2011 $resteapayeraffiche = $remaintopay;
2013 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
2016 $cssforamountpaymentcomplete =
'amountpaymentneutral';
2017 $resteapayeraffiche = 0;
2018 } elseif ($object->paid == 0) {
2019 $cssforamountpaymentcomplete =
'amountpaymentneutral';
2021 print
'<tr><td colspan="'.$nbcols.
'" class="right">'.$langs->trans(
"AlreadyPaid").
':</td><td class="right">'.
price($totalpaid).
'</td><td></td></tr>';
2022 print
'<tr><td colspan="'.$nbcols.
'" class="right">'.$langs->trans(
"AmountExpected").
':</td><td class="right">'.
price($object->total_ttc).
'</td><td></td></tr>';
2024 print
'<tr><td colspan="'.$nbcols.
'" class="right">'.$langs->trans(
"RemainderToPay").
':</td>';
2025 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td><td></td></tr>';
2036 print
'<div class="clearboth"></div><br>';
2038 print
'<div style="clear: both;"></div>';
2040 $actiontouse =
'updateline';
2041 if (($object->status == 0 || $object->status == 99) && $action !=
'editline') {
2042 $actiontouse =
'addline';
2045 print
'<form name="expensereport" action="'.$_SERVER[
"PHP_SELF"].
'" enctype="multipart/form-data" method="post" >';
2046 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2047 print
'<input type="hidden" name="action" value="'.$actiontouse.
'">';
2048 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
2049 print
'<input type="hidden" name="fk_expensereport" value="'.$object->id.
'" />';
2050 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
2051 print
'<input type="hidden" name="page_y" value="">';
2053 print
'<div class="div-table-responsive-no-min">';
2054 print
'<table id="tablelines" class="noborder centpercent">';
2056 if (!empty($object->lines)) {
2060 print
'<tr class="liste_titre headerexpensereportdet">';
2061 print
'<td class="center linecollinenb">'.$langs->trans(
'LineNb').
'</td>';
2063 print
'<td class="center linecoldate">'.$langs->trans(
'Date').
'</td>';
2064 if (isModEnabled(
'project')) {
2065 print
'<td class="minwidth100imp linecolproject">'.$langs->trans(
'Project').
'</td>';
2067 print
'<td class="center linecoltype">'.$langs->trans(
'Type').
'</td>';
2069 print
'<td class="center linecolcarcategory">'.$langs->trans(
'CarCategory').
'</td>';
2071 print
'<td class="linecoldescription">'.$langs->trans(
'Description').
'</td>';
2072 print
'<td class="right linecolvat">'.$langs->trans(
'VAT').
'</td>';
2073 print
'<td class="right linecolpriceuht">'.$langs->trans(
'PriceUHT').
'</td>';
2074 print
'<td class="right linecolpriceuttc">'.$langs->trans(
'PriceUTTC').
'</td>';
2075 print
'<td class="right linecolqty">'.$langs->trans(
'Qty').
'</td>';
2076 if ($action !=
'editline') {
2077 print
'<td class="right linecolamountht">'.$langs->trans(
'AmountHT').
'</td>';
2078 print
'<td class="right linecolamountttc">'.$langs->trans(
'AmountTTC').
'</td>';
2089 if (($object->status < 2 || $object->status == 99) && $user->hasRight(
'expensereport',
'creer')) {
2090 print
'<td class="right"></td>';
2094 foreach ($object->lines as &$line) {
2097 if ($action !=
'editline' || $line->id !=
GETPOST(
'rowid',
'int')) {
2098 print
'<tr class="oddeven linetr" data-id="'.$line->id.
'">';
2101 print
'<td class="center linecollinenb">';
2106 print
'<td class="center linecoldate">'.dol_print_date($db->jdate($line->date),
'day').
'</td>';
2109 if (isModEnabled(
'project')) {
2110 print
'<td class="lineproject">';
2111 if ($line->fk_project > 0) {
2112 $projecttmp->id = $line->fk_project;
2113 $projecttmp->ref = $line->projet_ref;
2114 $projecttmp->title = $line->projet_title;
2115 print $projecttmp->getNomUrl(1);
2121 if (isModEnabled(
'accounting')) {
2122 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
2124 $resaccountingaccount = $accountingaccount->fetch(0, $line->type_fees_accountancy_code, 1);
2126 $titlealt .= $langs->trans(
"AccountancyCode").
': ';
2127 if ($resaccountingaccount > 0) {
2128 $titlealt .= $accountingaccount->account_number;
2130 $titlealt .= $langs->trans(
"NotFound");
2136 print
'<td class="center linecoltype" title="'.dol_escape_htmltag($titlealt).
'">';
2137 $labeltype = ($langs->trans(($line->type_fees_code)) == $line->type_fees_code ? $line->type_fees_libelle : $langs->trans($line->type_fees_code));
2143 print
'<td class="fk_c_exp_tax_cat linecoltaxcat">';
2144 $exp_tax_cat_label =
dol_getIdFromCode($db, $line->fk_c_exp_tax_cat,
'c_exp_tax_cat',
'rowid',
'label');
2145 print $langs->trans($exp_tax_cat_label);
2150 print
'<td class="left linecolcomment">'.dol_nl2br($line->comments).
'</td>';
2153 print
'<td class="right linecolvatrate">'.vatrate($line->vatrate.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
''), true).
'</td>';
2156 print
'<td class="right linecolunitht">';
2157 if (!empty($line->value_unit_ht)) {
2158 print
price($line->value_unit_ht);
2160 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $line->vatrate));
2161 $pricenettoshow =
price2num($line->value_unit / (1 + $tmpvat / 100),
'MU');
2162 print
price($pricenettoshow);
2166 print
'<td class="right linecolunitttc">'.price($line->value_unit).
'</td>';
2168 print
'<td class="right linecolqty">'.dol_escape_htmltag($line->qty).
'</td>';
2170 if ($action !=
'editline') {
2171 print
'<td class="right linecoltotalht">'.price($line->total_ht).
'</td>';
2172 print
'<td class="right linecoltotalttc">'.price($line->total_ttc).
'</td>';
2176 print
'<td class="center linecolpreview">';
2177 if ($line->fk_ecm_files > 0) {
2178 $modulepart =
'expensereport';
2179 $maxheightmini = 32;
2181 $result = $ecmfilesstatic->fetch($line->fk_ecm_files);
2183 $relativepath = preg_replace(
'/expensereport\//',
'', $ecmfilesstatic->filepath);
2184 $fileinfo = pathinfo($ecmfilesstatic->filepath.
'/'.$ecmfilesstatic->filename);
2187 if (!
dol_is_file($conf->expensereport->dir_output.
'/'.$relativepath.
'/'.$minifile)) {
2191 $urlforhref =
getAdvancedPreviewUrl($modulepart, $relativepath.
'/'.$fileinfo[
'filename'].
'.'.strtolower($fileinfo[
'extension']), 1,
'&entity='.(empty($object->entity) ? $conf->entity : $object->entity));
2192 if (empty($urlforhref)) {
2193 $urlforhref = DOL_URL_ROOT.
'/viewimage.php?modulepart='.$modulepart.
'&entity='.(empty($object->entity) ? $conf->entity : $object->entity).
'&file='.urlencode($relativepath.$fileinfo[
'filename'].
'.'.strtolower($fileinfo[
'extension']));
2194 print
'<a href="'.$urlforhref.
'" class="aphoto" target="_blank" rel="noopener noreferrer">';
2196 print
'<a href="'.$urlforhref[
'url'].
'" class="'.$urlforhref[
'css'].
'" target="'.$urlforhref[
'target'].
'" mime="'.$urlforhref[
'mime'].
'">';
2198 print
'<img class="photo" height="'.$maxheightmini.
'" src="'.DOL_URL_ROOT.
'/viewimage.php?modulepart='.$modulepart.
'&entity='.(empty($object->entity) ? $conf->entity : $object->entity).
'&file='.urlencode($relativepath.
'/'.$minifile).
'" title="">';
2201 $modulepart =
'expensereport';
2203 if (preg_match(
'/\.pdf$/i', $ecmfilesstatic->filename)) {
2204 $filepdf = $conf->expensereport->dir_output.
'/'.$relativepath.
'/'.$ecmfilesstatic->filename;
2205 $fileimage = $conf->expensereport->dir_output.
'/'.$relativepath.
'/'.$ecmfilesstatic->filename.
'_preview.png';
2206 $relativepathimage = $relativepath.
'/'.$ecmfilesstatic->filename.
'_preview.png';
2208 $pdfexists = file_exists($filepdf);
2211 if (!file_exists($fileimage) || (filemtime($fileimage) < filemtime($filepdf))) {
2213 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2222 if ($pdfexists && !$error) {
2223 $heightforphotref = 70;
2224 if (!empty($conf->dol_optimize_smallscreen)) {
2225 $heightforphotref = 60;
2228 if (file_exists($fileimage)) {
2230 $urlforhref =
getAdvancedPreviewUrl($modulepart, $relativepath.
'/'.$fileinfo[
'filename'].
'.'.strtolower($fileinfo[
'extension']), 1,
'&entity='.(empty($object->entity) ? $conf->entity : $object->entity));
2231 print
'<a href="'.$urlforhref[
'url'].
'" class="'.$urlforhref[
'css'].
'" target="'.$urlforhref[
'target'].
'" mime="'.$urlforhref[
'mime'].
'">';
2232 print
'<img height="'.$heightforphotref.
'" class="photo photowithmargin photowithborder" src="'.DOL_URL_ROOT.
'/viewimage.php?modulepart=apercu'.$modulepart.
'&file='.urlencode($relativepathimage).
'">';
2238 if (!$thumbshown && $fileinfo[
'extension'] ==
'pdf' && !empty($filepdf) && !empty($relativepath) && !empty($fileinfo[
'filename'])) {
2240 $imgpreview = $formFile->showPreview([], $modulepart, $relativepath.
'/'.$fileinfo[
'filename'].
'.'.strtolower($fileinfo[
'extension']), 0);
2242 } elseif (!$thumbshown) {
2243 print
img_mime($ecmfilesstatic->filename);
2250 print
'<td class="nowrap right linecolwarning">';
2251 print !empty($line->rule_warning_message) ?
img_warning(html_entity_decode($line->rule_warning_message)) :
' ';
2256 print
'<td class="nowrap right linecolaction">';
2258 print
'<a class="editfielda reposition paddingrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=editline&token='.newToken().
'&rowid='.$line->rowid.
'">';
2260 print
'</a> ';
2261 print
'<a class="paddingrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delete_line&token='.newToken().
'&rowid='.$line->rowid.
'">';
2271 if ($action ==
'editline' && $line->id ==
GETPOST(
'rowid',
'int')) {
2274 if (isModEnabled(
'project')) {
2281 print
'<!-- line of expense report -->'.
"\n";
2282 print
'<tr class="tredited">';
2284 print
'<td class="center">';
2288 print
'<td colspan="'.($colspan - 1).
'" class="liste_titre"> ';
2289 print
'<a href="" class="commonlink auploadnewfilenow reposition">'.$langs->trans(
"UploadANewFileNow");
2290 print
img_picto($langs->trans(
"UploadANewFileNow"),
'chevron-down',
'',
false, 0, 0,
'',
'marginleftonly');
2293 print
' - <a href="" class="commonlink aattachtodoc reposition">'.$langs->trans(
"AttachTheNewLineToTheDocument");
2294 print
img_picto($langs->trans(
"AttachTheNewLineToTheDocument"),
'chevron-down',
'',
false, 0, 0,
'',
'marginleftonly');
2298 print
'<!-- Code to open/close section to submit or link files in edit mode -->'.
"\n";
2299 print
'<script type="text/javascript">'.
"\n";
2300 print
'$(document).ready(function() {
2301 $( ".auploadnewfilenow" ).click(function() {
2302 jQuery(".truploadnewfilenow").toggle();
2303 jQuery(".trattachnewfilenow").hide();
2306 $( ".aattachtodoc" ).click(function() {
2307 jQuery(".trattachnewfilenow").toggle();
2308 jQuery(".truploadnewfilenow").hide();
2311 if (is_array(
GETPOST(
'attachfile',
'array')) && count(
GETPOST(
'attachfile',
'array'))) {
2312 print
'jQuery(".trattachnewfilenow").toggle();'.
"\n";
2315 jQuery("form[name=\"expensereport\"]").submit(function() {
2316 if (jQuery(".truploadnewfilenow").is(":hidden")) {
2317 jQuery("input[name=\"sendit\"]").val("");
2324 print
'</script>'.
"\n";
2327 $filenamelinked =
'';
2328 if ($line->fk_ecm_files > 0) {
2329 $result = $ecmfilesstatic->fetch($line->fk_ecm_files);
2331 $filenamelinked = $ecmfilesstatic->filename;
2335 $tredited =
'tredited';
2336 include DOL_DOCUMENT_ROOT.
'/expensereport/tpl/expensereport_addfile.tpl.php';
2337 include DOL_DOCUMENT_ROOT.
'/expensereport/tpl/expensereport_linktofile.tpl.php';
2339 print
'<tr class="oddeven tredited">';
2344 print
'<td class="center">';
2345 print $form->selectDate($line->date,
'date');
2349 if (isModEnabled(
'project')) {
2351 $formproject->select_projects(-1, $line->fk_project,
'fk_project', 0, 0, $projectRequired ? 0 : 1, 1, 0, 0, 0,
'', 0, 0,
'maxwidth300');
2356 print
'<td class="center">';
2357 print $formexpensereport->selectTypeExpenseReport($line->fk_c_type_fees,
'fk_c_type_fees');
2361 print
'<td class="fk_c_exp_tax_cat">';
2362 $params = array(
'fk_expense' => $object->id,
'fk_expense_det' => $line->id,
'date' => $line->date);
2363 print $form->selectExpenseCategories($line->fk_c_exp_tax_cat,
'fk_c_exp_tax_cat', 1, array(),
'fk_c_type_fees', $userauthor->default_c_exp_tax_cat, $params);
2369 print
'<textarea name="comments" class="flat_ndf centpercent">'.dol_escape_htmltag($line->comments, 0, 1).
'</textarea>';
2373 $selectedvat =
price2num($line->vatrate).(!empty($line->vat_src_code) ?
' ('.$line->vat_src_code.
')' :
'');
2374 print
'<td class="right">';
2375 print $form->load_tva(
'vatrate', (GETPOSTISSET(
"vatrate") ?
GETPOST(
"vatrate") : $selectedvat), $mysoc,
'', 0, 0,
'', false, 1);
2379 print
'<td class="right">';
2380 print
'<input type="text" min="0" class="right maxwidth50" id="value_unit_ht" name="value_unit_ht" value="'.dol_escape_htmltag(
price2num((!empty($line->value_unit_ht) ? $line->value_unit_ht :
""))).
'"'.$taxlessUnitPriceDisabled.
' />';
2384 print
'<td class="right">';
2385 print
'<input type="text" min="0" class="right maxwidth50" id="value_unit" name="value_unit" value="'.dol_escape_htmltag(
price2num($line->value_unit)).
'" />';
2389 print
'<td class="right">';
2390 print
'<input type="text" min="0" class="input_qty right maxwidth50" name="qty" value="'.dol_escape_htmltag($line->qty).
'" />';
2397 print
'<td class="center">';
2401 print
'<td class="center">';
2405 print
'<input type="hidden" name="rowid" value="'.$line->rowid.
'">';
2406 print $form->buttonsSaveCancel(
'Save',
'Cancel', array(), 0,
'small');
2422 if (isModEnabled(
'project')) {
2425 if ($action !=
'editline') {
2429 $nbFiles = $nbLinks = 0;
2430 $arrayoffiles = array();
2432 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2433 require_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
2434 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
2437 $nbFiles = count($arrayoffiles);
2438 $nbLinks =
Link::count($db, $object->element, $object->id);
2442 print
'<tr class="liste_titre">';
2443 print
'<td colspan="'.$colspan.
'" class="liste_titre expensereportautoload">';
2444 print
'<a href="" class="commonlink auploadnewfilenow reposition">'.$langs->trans(
"UploadANewFileNow");
2445 print
img_picto($langs->trans(
"UploadANewFileNow"),
'chevron-down',
'',
false, 0, 0,
'',
'marginleftonly');
2448 print
' - <a href="" class="commonlink aattachtodoc reposition">'.$langs->trans(
"AttachTheNewLineToTheDocument");
2449 print
img_picto($langs->trans(
"AttachTheNewLineToTheDocument"),
'chevron-down',
'',
false, 0, 0,
'',
'marginleftonly');
2453 print
'<!-- Code to open/close section to submit or link files in the form to add new line -->'.
"\n";
2454 print
'<script type="text/javascript">'.
"\n";
2455 print
'$(document).ready(function() {
2456 $( ".auploadnewfilenow" ).click(function() {
2457 console.log("We click on toggle of auploadnewfilenow");
2458 jQuery(".truploadnewfilenow").toggle();
2459 jQuery(".trattachnewfilenow").hide();
2460 if (jQuery(".truploadnewfilenow").is(":hidden")) {
2461 jQuery("input[name=\"sendit\"]").prop("name", "senditdisabled");
2463 jQuery("input[name=\"senditdisabled\"]").prop("name", "sendit");
2465 // TODO Switch css fa-chevron-dow and add fa-chevron-up
2468 $( ".aattachtodoc" ).click(function() {
2469 console.log("We click on toggle of aattachtodoc");
2470 jQuery(".trattachnewfilenow").toggle();
2471 jQuery(".truploadnewfilenow").hide();
2472 // TODO Switch css fa-chevron-dow and add fa-chevron-up
2475 if (is_array(
GETPOST(
'attachfile',
'array')) && count(
GETPOST(
'attachfile',
'array')) && $action !=
'updateline') {
2476 print
'jQuery(".trattachnewfilenow").show();'.
"\n";
2479 jQuery("form[name=\"expensereport\"]").submit(function() {
2480 if (jQuery(".truploadnewfilenow").is(":hidden")) {
2481 /* When section to send file is not expanded, we disable the button sendit that submit form to add a new file, so button to submit line will work. */
2482 jQuery("input[name=\"sendit\"]").val("");
2483 jQuery("input[name=\"sendit\"]").prop("name", "senditdisabled");
2485 jQuery("input[name=\"senditdisabled\"]").prop("name", "sendit");
2492 print
'</script>'.
"\n";
2496 include DOL_DOCUMENT_ROOT.
'/expensereport/tpl/expensereport_linktofile.tpl.php';
2497 include DOL_DOCUMENT_ROOT.
'/expensereport/tpl/expensereport_addfile.tpl.php';
2499 print
'<tr class="liste_titre expensereportcreate">';
2501 print
'<td class="center expensereportcreatedate">'.$langs->trans(
'Date').
'</td>';
2502 if (isModEnabled(
'project')) {
2503 print
'<td class="minwidth100imp">'.$form->textwithpicto($langs->trans(
'Project'), $langs->trans(
"ClosedProjectsAreHidden")).
'</td>';
2505 print
'<td class="center expensereportcreatetype">'.$langs->trans(
'Type').
'</td>';
2507 print
'<td>'.$langs->trans(
'CarCategory').
'</td>';
2509 print
'<td class="expensereportcreatedescription">'.$langs->trans(
'Description').
'</td>';
2510 print
'<td class="right expensereportcreatevat">'.$langs->trans(
'VAT').
'</td>';
2511 print
'<td class="right expensereportcreatepriceuth">'.$langs->trans(
'PriceUHT').
'</td>';
2512 print
'<td class="right expensereportcreatepricettc">'.$langs->trans(
'PriceUTTC').
'</td>';
2513 print
'<td class="right expensereportcreateqty">'.$langs->trans(
'Qty').
'</td>';
2520 print
'<tr class="oddeven nohover">';
2526 print
'<td class="center inputdate">';
2527 print $form->selectDate(!empty($date) ? $date : -1,
'date', 0, 0, 0,
'', 1, 1);
2531 if (isModEnabled(
'project')) {
2532 print
'<td class="inputproject">';
2533 $formproject->select_projects(-1, !empty($fk_project) ? $fk_project : 0,
'fk_project', 0, 0, $projectRequired ? 0 : 1, -1, 0, 0, 0,
'', 0, 0,
'maxwidth300');
2538 print
'<td class="center inputtype">';
2539 print $formexpensereport->selectTypeExpenseReport(!empty($fk_c_type_fees) ? $fk_c_type_fees :
"",
'fk_c_type_fees', 1);
2543 print
'<td class="fk_c_exp_tax_cat">';
2544 $params = array(
'fk_expense' => $object->id);
2545 print $form->selectExpenseCategories(
'',
'fk_c_exp_tax_cat', 1, array(),
'fk_c_type_fees', $userauthor->default_c_exp_tax_cat, $params, 0);
2550 print
'<td class="inputcomment">';
2551 print
'<textarea class="flat_ndf centpercent" name="comments" rows="'.ROWS_2.
'">'.
dol_escape_htmltag(!empty($comments) ? $comments :
"", 0, 1).
'</textarea>';
2555 print
'<td class="right inputvat">';
2559 $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS =
'none';
2561 print $form->load_tva(
'vatrate', (!empty($vatrate) ? $vatrate : $defaultvat), $mysoc,
'', 0, 0,
'', false, 1);
2565 print
'<td class="right inputpricenet">';
2566 print
'<input type="text" class="right maxwidth50" id="value_unit_ht" name="value_unit_ht" value="'.dol_escape_htmltag((!empty($value_unit_ht) ? $value_unit_ht : 0)).
'"'.$taxlessUnitPriceDisabled.
' />';
2570 print
'<td class="right inputtax">';
2571 print
'<input type="text" class="right maxwidth50" id="value_unit" name="value_unit" value="'.dol_escape_htmltag((!empty($value_unit) ? $value_unit : 0)).
'">';
2575 print
'<td class="right inputqty">';
2576 print
'<input type="text" min="0" class=" input_qty right maxwidth50" name="qty" value="'.dol_escape_htmltag(!empty($qty) ? $qty : 1).
'">';
2582 if ($action !=
'editline') {
2583 print
'<td class="right"></td>';
2584 print
'<td class="right"></td>';
2587 print
'<td class="center inputbuttons">';
2588 print $form->buttonsSaveCancel(
"Add",
'',
'', 1,
'reposition');
2599 /* JQuery for product free or predefined select */
2600 jQuery(document).ready(function() {
2601 jQuery("#value_unit_ht").keyup(function(event) {
2602 console.log(event.which); // discard event tag and arrows
2603 if (event.which != 9 && (event.which < 37 ||event.which > 40) && jQuery("#value_unit_ht").val() != "") {
2604 jQuery("#value_unit").val("");
2607 jQuery("#value_unit").keyup(function(event) {
2608 console.log(event.which); // discard event tag and arrows
2609 if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#value_unit").val() != "") {
2610 jQuery("#value_unit_ht").val("");
2618 /* unit price coef calculation */
2619 jQuery(".input_qty, #fk_c_type_fees, #select_fk_c_exp_tax_cat, #vatrate ").change(function(event) {
2620 console.log("We change a parameter");
2622 let type_fee = jQuery("#fk_c_type_fees").find(":selected").val();
2623 let tax_cat = jQuery("#select_fk_c_exp_tax_cat").find(":selected").val();
2624 let tva = jQuery("#vatrate").find(":selected").val();
2625 let qty = jQuery(".input_qty").val();
2627 let path = "'.dol_buildpath(
"/expensereport/ajax/ajaxik.php", 1).
'";
2628 path += "?fk_c_exp_tax_cat="+tax_cat;
2629 path += "&fk_expense="+'.((int) $object->id).
';
2630 path += "&vatrate="+tva;
2631 path += "&qty="+qty;
2633 if (type_fee == 4) { // frais_kilométriques
2634 if (tax_cat == "" || parseInt(tax_cat) <= 0){
2642 success: function(response) {
2643 if (response.response_status == "success"){';
2647 jQuery("#value_unit").val(parseFloat(response.data) * (100 + parseFloat(tva)) / 100);
2648 jQuery("#value_unit").trigger("change");
2652 jQuery("#value_unit_ht").val(response.data);
2653 jQuery("#value_unit_ht").trigger("change");
2654 jQuery("#value_unit").val("");
2659 } else if(response.response_status == "error" && response.errorMessage != undefined && response.errorMessage.length > 0 ) {
2660 console.log("We get an error result");
2661 $.jnotify(response.errorMessage, "error", {timeout: 0, type: "error"},{ remove: function (){} } );
2667 /*console.log(event.which); // discard event tag and arrows
2668 if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#value_unit").val() != "") {
2669 jQuery("#value_unit_ht").val("");
2689 print
'Record not found';
2700print
'<div class="tabsAction">';
2702if ($action !=
'create' && $action !=
'edit' && $action !=
'editline') {
2704 $object->fetch($id, $ref);
2707 if (empty($user->socid)) {
2710 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans(
'SendMail').
'</a></div>';
2722 if (in_array($object->fk_user_author, $user->getAllChildIds(1)) || $user->hasRight(
'expensereport',
'writeall_advance')) {
2724 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=edit&token='.newToken().
'&id='.$object->id.
'">'.$langs->trans(
'Modify').
'</a></div>';
2727 if (count($object->lines) > 0) {
2728 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=save&token='.newToken().
'&id='.$object->id.
'">'.$langs->trans(
'ValidateAndSubmit').
'</a></div>';
2739 if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) {
2741 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=edit&token='.newToken().
'&id='.$object->id.
'">'.$langs->trans(
'Modify').
'</a></div>';
2746 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=save_from_refuse&token='.newToken().
'&id='.$object->id.
'">'.$langs->trans(
'ValidateAndSubmit').
'</a></div>';
2751 if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) {
2753 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=setdraft&token='.newToken().
'&id='.$object->id.
'">'.$langs->trans(
'SetToDraft').
'</a></div>';
2763 if (in_array($object->fk_user_author, $user->getAllChildIds(1))) {
2765 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=setdraft&token='.newToken().
'&id='.$object->id.
'">'.$langs->trans(
'SetToDraft').
'</a></div>';
2773 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=validate&id='.$object->id.
'">'.$langs->trans(
'Approve').
'</a></div>';
2775 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=refuse&id='.$object->id.
'">'.$langs->trans(
'Deny').
'</a></div>';
2778 if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) {
2780 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=cancel&id='.$object->id.
'">'.$langs->trans(
"Cancel").
'</a></div>';
2789 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=refuse&id='.$object->id.
'">'.$langs->trans(
'Deny').
'</a></div>';
2795 if ($remaintopay == 0) {
2796 print
'<div class="inline-block divButAction"><span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPayment').
'</span></div>';
2798 print
'<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.
'/expensereport/payment/payment.php?id='.$object->id.
'&action=create">'.$langs->trans(
'DoPayment').
'</a></div>';
2805 if ($object->paid == 0) {
2806 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=set_paid&token='.newToken().
'">'.$langs->trans(
"ClassifyPaid").
"</a></div>";
2810 if ($user->hasRight(
'expensereport',
'creer') && ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) && $object->status ==
ExpenseReport::STATUS_APPROVED) {
2812 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=cancel&token='.newToken().
'&id='.$object->id.
'">'.$langs->trans(
"Cancel").
'</a></div>';
2816 if (($user->hasRight(
'expensereport',
'approve') || $user->hasRight(
'expensereport',
'to_paid')) && $object->status ==
ExpenseReport::STATUS_CLOSED) {
2818 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=cancel&token='.newToken().
'&id='.$object->id.
'">'.$langs->trans(
"Cancel").
'</a></div>';
2823 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=set_unpaid&token='.newToken().
'&id='.$object->id.
'">'.$langs->trans(
'ClassifyUnPaid').
'</a></div>';
2827 if ($user->hasRight(
'expensereport',
'creer')) {
2828 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=clone&token='.newToken().
'">'.$langs->trans(
"ToClone").
'</a></div>';
2834 print
'<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER[
"PHP_SELF"].
'?action=delete&token='.newToken().
'&id='.$object->id.
'">'.$langs->trans(
'Delete').
'</a></div>';
2837 print
'<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER[
"PHP_SELF"].
'?action=delete&token='.newToken().
'&id='.$object->id.
'">'.$langs->trans(
'Delete').
'</a></div>';
2840 $parameters = array();
2841 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
2848if (
GETPOST(
'modelselected',
'alpha')) {
2849 $action =
'presend';
2852if ($action !=
'presend') {
2857 print
'<div class="fichecenter"><div class="fichehalfleft">';
2858 print
'<a name="builddoc"></a>';
2860 if ($user->hasRight(
'expensereport',
'creer') && $action !=
'create' && $action !=
'edit') {
2863 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".$object->id;
2864 $genallowed = $user->rights->expensereport->creer;
2865 $delallowed = $user->rights->expensereport->creer;
2867 print $formfile->showdocuments(
'expensereport', $filename, $filedir, $urlsource, $genallowed, $delallowed);
2868 $somethingshown = $formfile->numoffiles;
2880 print
'</div><div class="fichehalfright">';
2882 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
2884 $somethingshown =
$formactions->showactions($object,
'expensereport',
null);
2886 print
'</div></div>';
2890$modelmail =
'expensereport_send';
2891$defaulttopic =
'SendExpenseReportRef';
2892$diroutput = $conf->expensereport->dir_output;
2893$trackid =
'exp'.$object->id;
2895include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action=='set') elseif( $action=='specimen') elseif($action=='setmodel') elseif( $action=='del') elseif($action=='setdoc') $formactions
View.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage bank accounts.
Class to manage accounting accounts.
Class to manage accounting journals.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Class to manage a WYSIWYG editor.
Class to manage ECM files.
Class to manage Trips and Expenses.
const STATUS_DRAFT
Draft status.
const STATUS_APPROVED
Classified approved.
const STATUS_CANCELED
Classified canceled.
const STATUS_CLOSED
Classified paid.
const STATUS_REFUSED
Classified refused.
const STATUS_VALIDATED
Validated (need to be paid)
Class of expense report details lines.
static count($dbs, $objecttype, $objectid)
Return nb of links.
Class to manage payments of expense report.
Class to manage projects.
Class to manage translations.
Class to manage Dolibarr users.
expensereport_prepare_head($object)
Prepare array with list of tabs.
dol_convert_file($fileinput, $ext='png', $fileoutput='', $page='')
Convert an image file or a PDF into another image format.
dol_is_file($pathoffile)
Return if path is a file.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
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_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
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.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
get_date_range($date_start, $date_end, $format='', $outputlangs='', $withparenthesis=1)
Format output for start and end date.
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_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
img_mime($file, $titlealt='', $morecss='')
Show MIME img of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
getImageFileNameForSize($file, $extName, $extImgTarget='')
Return the filename of file to get the thumbs.
getAdvancedPreviewUrl($modulepart, $relativepath, $alldata=0, $param='')
Return URL we can use for advanced preview links.
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_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
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...
image_format_supported($file, $acceptsvg=0)
Return if a filename is file name of a supported image format.
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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.