31require
'../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formexpensereport.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
36require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
37require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
39require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
40require_once DOL_DOCUMENT_ROOT.
'/core/lib/expensereport.lib.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
42require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
43require_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
44require_once DOL_DOCUMENT_ROOT.
'/core/modules/expensereport/modules_expensereport.php';
45require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
46require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/paymentexpensereport.class.php';
47require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
48require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
49if (isModEnabled(
'accounting')) {
50 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
65$langs->loadLangs(array(
"trips",
"bills",
"mails"));
67$action =
GETPOST(
'action',
'aZ09');
68$cancel =
GETPOST(
'cancel',
'alpha');
69$confirm =
GETPOST(
'confirm',
'alpha');
70$backtopage =
GETPOST(
'backtopage',
'alpha');
77$vatrate =
GETPOST(
'vatrate',
'alpha');
79$comments =
GETPOST(
'comments',
'restricthtml');
84$childids = $user->getAllChildIds(1);
87 if (empty($date_start)) {
91 if (empty($date_end)) {
98$rootfordata = DOL_DATA_ROOT;
99$rootforuser = DOL_DATA_ROOT;
101if (isModEnabled(
'multicompany') && !empty(
$conf->entity) &&
$conf->entity > 1) {
102 $rootfordata .=
'/'.$conf->entity;
104$conf->expensereport->dir_output = $rootfordata.
'/expensereport';
107$urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
108$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
121$extrafields->fetch_name_optionals_label(
$object->table_element);
124include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
127$hookmanager->initHooks(array(
'expensereportcard',
'globalcard'));
129$permissionnote = $user->hasRight(
'expensereport',
'creer');
130$permissiondellink = $user->hasRight(
'expensereport',
'creer');
131$permissiontoadd = $user->hasRight(
'expensereport',
'creer');
135$projectRequired = isModEnabled(
'project') &&
getDolGlobalString(
'EXPENSEREPORT_PROJECT_IS_REQUIRED');
141 if ($user->hasRight(
'expensereport',
'readall')) {
144 if ($user->hasRight(
'expensereport',
'lire') && in_array(
$object->fk_user_author, $childids)) {
153if ($user->hasRight(
'expensereport',
'supprimer')) {
162 $socid = $user->socid;
166$permissiontoadd = $user->hasRight(
'expensereport',
'creer');
178$parameters = array(
'socid' => $socid);
179$reshook = $hookmanager->executeHooks(
'doActions', $parameters,
$object, $action);
184if (empty($reshook)) {
185 $backurlforlist = DOL_URL_ROOT.
'/expensereport/list.php';
187 if (empty($backtopage) || ($cancel && empty($id))) {
188 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
189 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
190 $backtopage = $backurlforlist;
192 $backtopage = DOL_URL_ROOT.
'/expensereport/card.php?id='.((!empty($id) &&
$id > 0) ? $id :
'__ID__');
198 if (!empty($backtopageforcancel)) {
199 header(
"Location: ".$backtopageforcancel);
201 } elseif (!empty($backtopage)) {
202 header(
"Location: ".$backtopage);
216 $fk_c_type_fees = -1;
219 include DOL_DOCUMENT_ROOT.
'/core/actions_linkedfiles.inc.php';
221 if (!empty(
GETPOST(
'sendit',
'alpha'))) {
222 if ($action ==
'updateline') {
223 $action =
'editline';
229 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
231 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
233 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
236 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontoadd) {
237 if (1 == 0 && !
GETPOST(
'clone_content',
'alpha') && !
GETPOST(
'clone_receivers',
'alpha')) {
246 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
257 if ($action ==
'confirm_delete' &&
GETPOST(
"confirm",
'alpha') ==
"yes" && $id > 0 && $candelete) {
260 $result =
$object->delete($user);
262 header(
"Location: index.php");
269 if ($action ==
'add' && $permissiontoadd) {
272 $object->date_debut = $date_start;
276 if (!(
$object->fk_user_author > 0)) {
277 $object->fk_user_author = $user->id;
281 if ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'expensereport',
'creer'))
282 || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'expensereport',
'creer') && !$user->hasRight(
'expensereport',
'writeall_advance'))) {
287 if (!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') || !$user->hasRight(
'expensereport',
'writeall_advance')) {
288 if (!in_array(
$object->fk_user_author, $childids)) {
295 $fuser =
new User($db);
296 $fuser->fetch(
$object->fk_user_author);
305 $ret = $extrafields->setOptionalsFromPost(
null,
$object);
314 if ($overlappingExpenseReportID > 0) {
316 setEventMessages($langs->trans(
"ErrorDoubleDeclaration").
' <a href="'.$_SERVER[
'PHP_SELF'].
'?id='.$overlappingExpenseReportID.
'">'. $langs->trans(
'ShowTrip').
'</a>',
null,
'errors');
331 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
341 if (($action ==
'update' || $action ==
'updateFromRefuse') && $permissiontoadd) {
345 $object->date_debut = $date_start;
355 $object->fk_user_modif = $user->id;
357 $result =
$object->update($user);
359 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
GETPOSTINT(
'id'));
366 if ($action ==
'update_extras' && $permissiontoadd) {
370 $ret = $extrafields->setOptionalsFromPost(
null,
$object,
GETPOST(
'attribute',
'restricthtml'));
377 $result =
$object->insertExtraFields(
'EXPENSEREPORT_MODIFY');
385 $action =
'edit_extras';
389 if ($action ==
"confirm_validate" &&
GETPOST(
"confirm",
'alpha') ==
"yes" && $id > 0 && $permissiontoadd) {
395 $result =
$object->setValidate($user);
400 $outputlangs = $langs;
403 $newlang =
GETPOST(
'lang_id',
'aZ09');
406 $user =
new User($db);
407 $user->fetch(
$object->fk_user_author);
408 $newlang = $user->lang;
410 if (!empty($newlang)) {
412 $outputlangs->setDefaultLang($newlang);
417 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
424 if (!$error && $result > 0 &&
$object->fk_user_validator > 0) {
425 $langs->load(
"mails");
428 $destinataire =
new User($db);
429 $destinataire->fetch(
$object->fk_user_validator);
430 $emailTo = $destinataire->email;
433 $expediteur =
new User($db);
434 $expediteur->fetch(
$object->fk_user_author);
437 if ($emailTo && $emailFrom) {
448 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportWaitingForApproval");
451 $link = $urlwithroot.
'/expensereport/card.php?id='.
$object->id;
452 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
453 $message = $langs->transnoentities(
"ExpenseReportWaitingForApprovalMessage", $expediteur->getFullName($langs),
get_date_range(
$object->date_debut,
$object->date_fin,
'', $langs), $link);
468 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
470 if (empty($mailfile->error)) {
472 $result = $mailfile->sendfile();
474 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
477 $langs->load(
"other");
478 if (!empty($mailfile->error) || !empty($mailfile->errors)) {
481 if (!empty($mailfile->error)) {
482 $mesg .=
'<br>' . $mailfile->error;
484 if (!empty($mailfile->errors) && is_array($mailfile->errors)) {
485 $mesg .=
'<br>' . implode(
'<br>', $mailfile->errors);
489 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
497 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
504 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
511 if ($action ==
"confirm_save_from_refuse" &&
GETPOST(
"confirm",
'alpha') ==
"yes" && $id > 0 && $permissiontoadd) {
514 $result =
$object->set_save_from_refuse($user);
519 $outputlangs = $langs;
522 $newlang =
GETPOST(
'lang_id',
'aZ09');
525 $user =
new User($db);
526 $user->fetch(
$object->fk_user_author);
527 $newlang = $user->lang;
529 if (!empty($newlang)) {
531 $outputlangs->setDefaultLang($newlang);
536 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
544 $destinataire =
new User($db);
545 $destinataire->fetch(
$object->fk_user_validator);
546 $emailTo = $destinataire->email;
549 $expediteur =
new User($db);
550 $expediteur->fetch(
$object->fk_user_author);
553 if ($emailFrom && $emailTo) {
564 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportWaitingForReApproval");
567 $link = $urlwithroot.
'/expensereport/card.php?id='.
$object->id;
568 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
570 $message .=
'<br>'.$langs->transnoentities(
"ExpenseReportWaitingForReApprovalMessage2", $link);
589 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
591 if (empty($mailfile->error)) {
593 $result = $mailfile->sendfile();
595 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
597 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
600 $langs->load(
"other");
601 if ($mailfile->error) {
603 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
604 $mesg .=
'<br>'.$mailfile->error;
607 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
615 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
624 if ($action ==
"confirm_approve" &&
GETPOST(
"confirm",
'alpha') ==
"yes" && $id > 0 && $user->hasRight(
'expensereport',
'approve')) {
628 $result =
$object->setApproved($user);
633 $outputlangs = $langs;
636 $newlang =
GETPOST(
'lang_id',
'aZ09');
639 $user =
new User($db);
640 $user->fetch(
$object->fk_user_author);
641 $newlang = $user->lang;
643 if (!empty($newlang)) {
645 $outputlangs->setDefaultLang($newlang);
650 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
658 $destinataire =
new User($db);
659 $destinataire->fetch(
$object->fk_user_author);
660 $emailTo = $destinataire->email;
664 if (empty($emailTo)) {
669 $expediteur =
new User($db);
670 $expediteur->fetch(
$object->fk_user_approve > 0 ?
$object->fk_user_approve :
$object->fk_user_validator);
673 if ($emailFrom && $emailTo) {
684 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportApproved");
687 $link = $urlwithroot.
'/expensereport/card.php?id='.
$object->id;
688 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
689 $message = $langs->transnoentities(
"ExpenseReportApprovedMessage",
$object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $link);
706 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, $emailCC,
'', 0, -1);
708 if (empty($mailfile->error)) {
710 $result = $mailfile->sendfile();
712 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
714 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
717 $langs->load(
"other");
718 if ($mailfile->error) {
720 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
721 $mesg .=
'<br>'.$mailfile->error;
724 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
732 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
741 if ($action ==
"confirm_refuse" &&
GETPOST(
'confirm',
'alpha') ==
"yes" && $id > 0 && $user->hasRight(
'expensereport',
'approve')) {
745 $detailRefuse =
GETPOST(
'detail_refuse',
'alpha');
746 $result =
$object->setDeny($user, $detailRefuse);
751 $outputlangs = $langs;
754 $newlang =
GETPOST(
'lang_id',
'aZ09');
757 $user =
new User($db);
758 $user->fetch(
$object->fk_user_author);
759 $newlang = $user->lang;
761 if (!empty($newlang)) {
763 $outputlangs->setDefaultLang($newlang);
768 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
776 $destinataire =
new User($db);
777 $destinataire->fetch(
$object->fk_user_author);
778 $emailTo = $destinataire->email;
781 $expediteur =
new User($db);
782 $expediteur->fetch(
$object->fk_user_refuse);
785 if ($emailFrom && $emailTo) {
796 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportRefused");
799 $link = $urlwithroot.
'/expensereport/card.php?id='.
$object->id;
800 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
801 $message = $langs->transnoentities(
"ExpenseReportRefusedMessage",
$object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $detailRefuse, $link);
819 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
821 if (empty($mailfile->error)) {
823 $result = $mailfile->sendfile();
825 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
827 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
830 $langs->load(
"other");
831 if ($mailfile->error) {
833 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
834 $mesg .=
'<br>'.$mailfile->error;
837 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
845 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
855 if ($action ==
"confirm_cancel" &&
GETPOST(
'confirm',
'alpha') ==
"yes" && $id > 0 && $user->hasRight(
'expensereport',
'creer')) {
856 if (!
GETPOST(
'detail_cancel',
'alpha')) {
857 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Comment")),
null,
'errors');
862 if ($user->id ==
$object->fk_user_valid || $user->id ==
$object->fk_user_author) {
863 $detailCancel =
GETPOST(
'detail_cancel',
'alpha');
864 $result =
$object->set_cancel($user, $detailCancel);
869 $outputlangs = $langs;
872 $newlang =
GETPOST(
'lang_id',
'aZ09');
875 $user =
new User($db);
876 $user->fetch(
$object->fk_user_author);
877 $newlang = $user->lang;
879 if (!empty($newlang)) {
881 $outputlangs->setDefaultLang($newlang);
886 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
894 $destinataire =
new User($db);
895 $destinataire->fetch(
$object->fk_user_author);
896 $emailTo = $destinataire->email;
899 $expediteur =
new User($db);
900 $expediteur->fetch(
$object->fk_user_cancel);
903 if ($emailFrom && $emailTo) {
914 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportCanceled");
917 $link = $urlwithroot.
'/expensereport/card.php?id='.
$object->id;
918 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
919 $message = $langs->transnoentities(
"ExpenseReportCanceledMessage",
$object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $detailCancel, $link);
937 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
939 if (empty($mailfile->error)) {
941 $result = $mailfile->sendfile();
943 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
945 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
948 $langs->load(
"other");
949 if ($mailfile->error) {
951 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
952 $mesg .=
'<br>'.$mailfile->error;
955 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
963 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
976 if ($action ==
"confirm_setdraft" &&
GETPOST(
'confirm',
'alpha') ==
"yes" && $id > 0 && $user->hasRight(
'expensereport',
'creer')) {
979 if ($user->id ==
$object->fk_user_author || $user->id ==
$object->fk_user_valid || in_array(
$object->fk_user_author, $childids)) {
980 $result =
$object->setStatut(0);
985 $outputlangs = $langs;
988 $newlang =
GETPOST(
'lang_id',
'aZ09');
991 $user =
new User($db);
992 $user->fetch(
$object->fk_user_author);
993 $newlang = $user->lang;
995 if (!empty($newlang)) {
997 $outputlangs->setDefaultLang($newlang);
1002 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1007 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
1017 if ($action ==
'set_unpaid' && $id > 0 && $user->hasRight(
'expensereport',
'to_paid')) {
1021 $result =
$object->setUnpaid($user);
1026 $outputlangs = $langs;
1029 $newlang =
GETPOST(
'lang_id',
'aZ09');
1032 $user =
new User($db);
1033 $user->fetch(
$object->fk_user_author);
1034 $newlang = $user->lang;
1036 if (!empty($newlang)) {
1038 $outputlangs->setDefaultLang($newlang);
1043 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1048 if ($action ==
'set_paid' && $id > 0 && $user->hasRight(
'expensereport',
'to_paid')) {
1052 $result =
$object->setPaid($id, $user);
1057 $outputlangs = $langs;
1060 $newlang =
GETPOST(
'lang_id',
'aZ09');
1063 $user =
new User($db);
1064 $user->fetch(
$object->fk_user_author);
1065 $newlang = $user->lang;
1067 if (!empty($newlang)) {
1069 $outputlangs->setDefaultLang($newlang);
1074 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1082 $destinataire =
new User($db);
1083 $destinataire->fetch(
$object->fk_user_author);
1084 $emailTo = $destinataire->email;
1087 $expediteur =
new User($db);
1088 $expediteur->fetch($user->id);
1091 if ($emailFrom && $emailTo) {
1092 $filename = array();
1094 $mimetype = array();
1102 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportPaid");
1105 $link = $urlwithroot.
'/expensereport/card.php?id='.
$object->id;
1106 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
1107 $message = $langs->transnoentities(
"ExpenseReportPaidMessage",
$object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $link);
1110 $object->setDocModel($user,
"");
1111 $resultPDF = expensereport_pdf_create($db,
$object,
'',
"", $langs);
1114 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
1116 if (empty($mailfile->error)) {
1118 $result = $mailfile->sendfile();
1120 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
1122 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
1125 $langs->load(
"other");
1126 if ($mailfile->error) {
1128 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
1129 $mesg .=
'<br>'.$mailfile->error;
1132 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
1140 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
1149 if ($action ==
"addline" && $user->hasRight(
'expensereport',
'creer')) {
1152 if (GETPOSTISSET(
'attachfile')) {
1153 $arrayoffiles =
GETPOST(
'attachfile',
'array');
1154 if (is_array($arrayoffiles) && !empty($arrayoffiles[0])) {
1155 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1156 $entityprefix = (
$conf->entity !=
'1') ?
$conf->entity.
'/' :
'';
1157 $relativepath =
'expensereport/'.$object->ref.
'/'.$arrayoffiles[0];
1159 $ecmfiles->fetch(0,
'', $relativepath);
1160 $fk_ecm_files = $ecmfiles->id;
1165 if (empty($vatrate)) {
1168 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $vatrate));
1172 if (empty($value_unit)) {
1173 $value_unit =
price2num((
float) $value_unit_ht + ((
float) $value_unit_ht * (
float) $tmpvat / 100),
'MU');
1176 $fk_c_exp_tax_cat =
GETPOSTINT(
'fk_c_exp_tax_cat');
1183 if (!($fk_c_type_fees > 0)) {
1185 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1189 if ((
float) $tmpvat < 0 || $tmpvat ===
'') {
1191 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"VAT")),
null,
'errors');
1196 if (empty($date) || $date ==
"--") {
1198 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1199 } elseif ($date < $object->date_debut || $date > (
$object->date_fin + (24 * 3600 - 1))) {
1205 $langs->load(
"errors");
1206 $type = $error > 0 ?
'errors' :
'warnings';
1207 setEventMessages($langs->trans(
"WarningDateOfLineMustBeInExpenseReportRange"),
null, $type);
1211 if ($value_unit == 0) {
1213 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"PriceUTTC")),
null,
'errors');
1217 if ($projectRequired && $fk_project <= 0) {
1219 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Project")),
null,
'errors');
1223 if ($fileRequired && $fk_ecm_files == 0) {
1225 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"File")),
null,
'errors');
1232 $result =
$object->addline($qty, $value_unit, $fk_c_type_fees, $vatrate, $date, $comments, $fk_project, $fk_c_exp_tax_cat, $type, $fk_ecm_files);
1238 $outputlangs = $langs;
1239 $newlang =
GETPOST(
'lang_id',
'alpha');
1241 $user =
new User($db);
1242 $user->fetch(
$object->fk_user_author);
1243 $newlang = $user->lang;
1245 if (!empty($newlang)) {
1247 $outputlangs->setDefaultLang($newlang);
1250 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1254 unset($value_unit_ht);
1258 unset($fk_c_type_fees);
1269 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
GETPOSTINT(
'id'));
1276 if ($action ==
'confirm_delete_line' &&
GETPOST(
"confirm",
'alpha') ==
"yes" && $user->hasRight(
'expensereport',
'creer')) {
1282 $total_ht = $object_ligne->total_ht;
1283 $total_tva = $object_ligne->total_tva;
1290 $outputlangs = $langs;
1293 $newlang =
GETPOST(
'lang_id',
'aZ09');
1296 $user =
new User($db);
1297 $user->fetch(
$object->fk_user_author);
1298 $newlang = $user->lang;
1300 if (!empty($newlang)) {
1302 $outputlangs->setDefaultLang($newlang);
1307 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1311 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
GETPOSTINT(
'id'));
1318 if ($action ==
"updateline" && $permissiontoadd) {
1324 if (GETPOSTISSET(
'attachfile')) {
1325 $arrayoffiles =
GETPOST(
'attachfile',
'array');
1326 if (is_array($arrayoffiles) && !empty($arrayoffiles[0])) {
1327 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1328 $relativepath =
'expensereport/'.$object->ref.
'/'.$arrayoffiles[0];
1330 $ecmfiles->fetch(0,
'', $relativepath);
1331 $fk_ecm_files = $ecmfiles->id;
1336 $type_fees_id =
GETPOSTINT(
'fk_c_type_fees');
1337 $fk_c_exp_tax_cat =
GETPOSTINT(
'fk_c_exp_tax_cat');
1338 $projet_id = $fk_project;
1339 $comments =
GETPOST(
'comments',
'restricthtml');
1341 $vatrate =
GETPOST(
'vatrate',
'alpha');
1344 if (empty($vatrate)) {
1347 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $vatrate));
1351 if (empty($value_unit)) {
1352 $value_unit =
price2num((
float) $value_unit_ht + ((
float) $value_unit_ht * (
float) $tmpvat / 100),
'MU');
1357 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1360 if ((
float) $tmpvat < 0 || $tmpvat ==
'') {
1362 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Vat")),
null,
'errors');
1366 if ($date < $object->date_debut || $date > (
$object->date_fin + (24 * 3600 - 1))) {
1371 $langs->load(
"errors");
1372 $type = $error > 0 ?
'errors' :
'warnings';
1373 setEventMessages($langs->trans(
"WarningDateOfLineMustBeInExpenseReportRange"),
null, $type);
1377 if ($projectRequired && $projet_id <= 0) {
1379 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Project")),
null,
'errors');
1384 $result =
$object->updateline($rowid, $type_fees_id, $projet_id, $vatrate, $comments, $qty, $value_unit, $date, $id, $fk_c_exp_tax_cat, $fk_ecm_files);
1389 $outputlangs = $langs;
1392 $newlang =
GETPOST(
'lang_id',
'aZ09');
1395 $tmpuser =
new User($db);
1396 $tmpuser->fetch(
$object->fk_user_author);
1397 $newlang = $tmpuser->lang;
1399 if (!empty($newlang)) {
1401 $outputlangs->setDefaultLang($newlang);
1406 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1410 unset($value_unit_ht);
1414 unset($fk_c_type_fees);
1427 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
1430 $triggersendname =
'EXPENSEREPORT_SENTBYMAIL';
1431 $autocopy =
'MAIN_MAIL_AUTOCOPY_EXPENSEREPORT_TO';
1432 $trackid =
'exp'.$object->id;
1433 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
1436 $upload_dir =
$conf->expensereport->dir_output;
1437 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1445$title = $langs->trans(
"ExpenseReport").
" - ".$langs->trans(
"Card");
1446$help_url =
"EN:Module_Expense_Reports|FR:Module_Notes_de_frais";
1450$form =
new Form($db);
1453$projecttmp =
new Project($db);
1455$bankaccountstatic =
new Account($db);
1456$ecmfilesstatic =
new EcmFiles($db);
1460if ($action ==
'create') {
1463 print
'<form action="'.$_SERVER[
'PHP_SELF'].
'" method="post" name="create">';
1464 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1465 print
'<input type="hidden" name="action" value="add">';
1466 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
1470 print
'<table class="border centpercent">';
1475 print
'<td class="titlefieldcreate fieldrequired">'.$langs->trans(
"DateStart").
'</td>';
1477 print $form->selectDate($date_start ? $date_start : -1,
'date_debut', 0, 0, 0,
'', 1, 1);
1483 print
'<td class="fieldrequired">'.$langs->trans(
"DateEnd").
'</td>';
1485 print $form->selectDate($date_end ? $date_end : -1,
'date_fin', 0, 0, 0,
'', 1, 1);
1491 print
'<td class="fieldrequired">'.$langs->trans(
"User").
'</td>';
1493 $defaultselectuser = $user->id;
1495 $defaultselectuser =
GETPOSTINT(
'fk_user_author');
1497 $include_users =
'hierarchyme';
1498 if (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'expensereport',
'writeall_advance')) {
1499 $include_users = array();
1501 $s = $form->select_dolusers($defaultselectuser,
"fk_user_author", 0,
"", 0, $include_users,
'',
'0,'.
$conf->entity);
1508 print
'<td>'.$langs->trans(
"VALIDATOR").
'</td>';
1511 $include_users =
$object->fetch_users_approver_expensereport();
1512 if (empty($include_users)) {
1513 print
img_warning().
' '.$langs->trans(
"NobodyHasPermissionToValidateExpenseReport");
1515 $defaultselectuser = (empty($user->fk_user_expense_validator) ? $user->fk_user : $user->fk_user_expense_validator);
1520 $defaultselectuser =
GETPOSTINT(
'fk_user_validator');
1522 $s = $form->select_dolusers($defaultselectuser,
"fk_user_validator", 1,
"", ((empty($defaultselectuser) || !
getDolGlobalString(
'EXPENSEREPORT_DEFAULT_VALIDATOR_UNCHANGEABLE')) ? 0 : 1), $include_users);
1523 print $form->textwithpicto($s, $langs->trans(
"AnyOtherInThisListCanValidate"));
1531 print
'<td>'.$langs->trans(
"ModePaiement").
'</td>';
1533 $form->select_types_paiements(
'',
'fk_c_paiement');
1539 $note_public = GETPOSTISSET(
'note_public') ?
GETPOST(
'note_public',
'restricthtml') :
'';
1542 print
'<td class="tdtop">'.$langs->trans(
'NotePublic').
'</td>';
1545 $doleditor =
new DolEditor(
'note_public', $note_public,
'', 80,
'dolibarr_notes',
'In',
false,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3,
'90%');
1546 print $doleditor->Create(1);
1550 $note_private = GETPOSTISSET(
'note_private') ?
GETPOST(
'note_private',
'restricthtml') :
'';
1552 if (empty($user->socid)) {
1554 print
'<td class="tdtop">'.$langs->trans(
'NotePrivate').
'</td>';
1557 $doleditor =
new DolEditor(
'note_private', $note_private,
'', 80,
'dolibarr_notes',
'In',
false,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3,
'90%');
1558 print $doleditor->Create(1);
1563 $parameters = array(
'colspan' =>
' colspan="3"',
'cols' => 3);
1564 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters,
$object, $action);
1565 print $hookmanager->resPrint;
1566 if (empty($reshook)) {
1567 print
$object->showOptionals($extrafields,
'create', $parameters);
1575 print $form->buttonsSaveCancel(
"AddTrip");
1578} elseif ($id > 0 || $ref) {
1579 $result =
$object->fetch($id, $ref);
1582 if (!in_array(
$object->fk_user_author, $childids)) {
1583 if (!$user->hasRight(
'expensereport',
'readall') && !$user->hasRight(
'expensereport',
'lire_tous')
1584 && (!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') || !$user->hasRight(
'expensereport',
'writeall_advance'))) {
1587 print
'<div class="tabBar">';
1588 print $langs->trans(
'NotUserRightToView');
1602 print
"<form name='update' action=\"".$_SERVER[
'PHP_SELF'].
"\" method=\"post\">\n";
1603 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1604 print
'<input type="hidden" name="id" value="'.$id.
'">';
1605 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
1610 print
'<input type="hidden" name="action" value="updateFromRefuse">';
1612 print
'<input type="hidden" name="action" value="update">';
1615 $linkback =
'<a href="'.DOL_URL_ROOT.
'/expensereport/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
1617 print
'<table class="border centpercent">';
1620 print
'<td>'.$langs->trans(
"User").
'</td>';
1622 $userfee =
new User($db);
1623 if (
$object->fk_user_author > 0) {
1624 $userfee->fetch(
$object->fk_user_author);
1625 print $userfee->getNomUrl(-1);
1630 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Ref").
'</td><td>';
1631 print $form->showrefnav(
$object,
'ref', $linkback, 1,
'ref',
'ref',
'');
1635 print
'<td>'.$langs->trans(
"DateStart").
'</td>';
1637 print $form->selectDate(
$object->date_debut,
'date_debut');
1641 print
'<td>'.$langs->trans(
"DateEnd").
'</td>';
1643 print $form->selectDate(
$object->date_fin,
'date_fin');
1649 print
'<td>'.$langs->trans(
"ModePaiement").
'</td>';
1651 $form->select_types_paiements(
$object->fk_c_paiement,
'fk_c_paiement');
1658 print
'<td>'.$langs->trans(
"VALIDATOR").
'</td>';
1660 $include_users =
$object->fetch_users_approver_expensereport();
1661 $s = $form->select_dolusers(
$object->fk_user_validator,
"fk_user_validator", 1,
"", 0, $include_users);
1662 print $form->textwithpicto($s, $langs->trans(
"AnyOtherInThisListCanValidate"));
1667 print
'<td>'.$langs->trans(
"VALIDOR").
'</td>';
1669 $userfee =
new User($db);
1670 $userfee->fetch(
$object->fk_user_valid);
1671 print $userfee->getNomUrl(-1);
1677 print
'<td>'.$langs->trans(
"AUTHORPAIEMENT").
'</td>';
1679 $userfee =
new User($db);
1680 $userfee->fetch($user->id);
1681 print $userfee->getNomUrl(-1);
1693 print $form->buttonsSaveCancel(
"Modify");
1697 $taxlessUnitPriceDisabled =
getDolGlobalString(
'EXPENSEREPORT_FORCE_LINE_AMOUNTS_INCLUDING_TAXES_ONLY') ?
' disabled' :
'';
1704 if ($action ==
'clone') {
1706 $criteriaforfilter =
'hierarchyme';
1707 if ($user->hasRight(
'expensereport',
'readall')) {
1708 $criteriaforfilter =
'';
1710 $formquestion = array(
1712 0 => array(
'type' =>
'other',
'name' =>
'fk_user_author',
'label' => $langs->trans(
"SelectTargetUser"),
'value' => $form->select_dolusers((
GETPOSTINT(
'fk_user_author') > 0 ?
GETPOSTINT(
'fk_user_author') : $user->id),
'fk_user_author', 0, null, 0, $criteriaforfilter,
'',
'0', 0, 0,
'', 0,
'',
'maxwidth150'))
1715 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneExpenseReport',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1);
1718 if ($action ==
'save') {
1719 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"SaveTrip"), $langs->trans(
"ConfirmSaveTrip"),
"confirm_validate",
"",
"", 1);
1722 if ($action ==
'save_from_refuse') {
1723 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"SaveTrip"), $langs->trans(
"ConfirmSaveTrip"),
"confirm_save_from_refuse",
"",
"", 1);
1726 if ($action ==
'delete') {
1727 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"DeleteTrip"), $langs->trans(
"ConfirmDeleteTrip"),
"confirm_delete",
"",
"", 1);
1730 if ($action ==
'validate') {
1731 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"ValideTrip"), $langs->trans(
"ConfirmValideTrip"),
"confirm_approve",
"",
"", 1);
1734 if ($action ==
'paid') {
1735 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"PaidTrip"), $langs->trans(
"ConfirmPaidTrip"),
"confirm_paid",
"",
"", 1);
1738 if ($action ==
'cancel') {
1739 $array_input = array(
'text' => $langs->trans(
"ConfirmCancelTrip"), 0 => array(
'type' =>
"text",
'label' =>
'<strong>'.$langs->trans(
"Comment").
'</strong>',
'name' =>
"detail_cancel",
'value' =>
""));
1740 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"Cancel"),
"",
"confirm_cancel", $array_input,
"", 1);
1743 if ($action ==
'setdraft') {
1744 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"BrouillonnerTrip"), $langs->trans(
"ConfirmBrouillonnerTrip"),
"confirm_setdraft",
"",
"", 1);
1747 if ($action ==
'refuse') {
1748 $array_input = array(
'text' => $langs->trans(
"ConfirmRefuseTrip"), 0 => array(
'type' =>
"text",
'label' => $langs->trans(
"Comment"),
'name' =>
"detail_refuse",
'value' =>
""));
1749 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"Deny"),
'',
"confirm_refuse", $array_input,
"yes", 1);
1752 if ($action ==
'delete_line') {
1753 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".
$id.
"&rowid=".
GETPOSTINT(
'rowid'), $langs->trans(
"DeleteLine"), $langs->trans(
"ConfirmDeleteLine"),
"confirm_delete_line",
'',
'yes', 1);
1757 $parameters = array(
'formConfirm' => $formconfirm);
1758 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters,
$object, $action);
1759 if (empty($reshook)) {
1760 $formconfirm .= $hookmanager->resPrint;
1761 } elseif ($reshook > 0) {
1762 $formconfirm = $hookmanager->resPrint;
1769 $linkback =
'<a href="'.DOL_URL_ROOT.
'/expensereport/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
1771 $morehtmlref =
'<div class="refidno">';
1772 $morehtmlref .=
'</div>';
1774 dol_banner_tab(
$object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
1776 print
'<div class="fichecenter">';
1777 print
'<div class="fichehalfleft">';
1778 print
'<div class="underbanner clearboth"></div>';
1780 print
'<table class="border tableforfield centpercent">';
1784 print
'<td class="titlefield">'.$langs->trans(
"User").
'</td>';
1786 if (
$object->fk_user_author > 0) {
1787 $userauthor =
new User($db);
1788 $result = $userauthor->fetch(
$object->fk_user_author);
1791 } elseif ($result > 0) {
1792 print $userauthor->getNomUrl(-1);
1799 print
'<td class="titlefield">'.$langs->trans(
"Period").
'</td>';
1806 print
'<td>'.$langs->trans(
"ModePaiement").
'</td>';
1807 print
'<td>'.$object->fk_c_paiement.
'</td>';
1813 print
'<td>'.$langs->trans(
"DATE_SAVE").
'</td>';
1814 print
'<td>'.dol_print_date(
$object->date_valid,
'dayhour',
'tzuser');
1816 print
' '.img_warning($langs->trans(
"Late").
' - '.$langs->trans(
"ToApprove"));
1819 print
' '.img_warning($langs->trans(
"Late").
' - '.$langs->trans(
"ToPay"));
1827 print
'<td>'.$langs->trans(
"VALIDATOR").
'</td>';
1829 if (
$object->fk_user_validator > 0) {
1830 $userfee =
new User($db);
1831 $result = $userfee->fetch(
$object->fk_user_validator);
1833 print $userfee->getNomUrl(-1);
1835 if (empty($userfee->email) || !
isValidEmail($userfee->email)) {
1836 $langs->load(
"errors");
1837 print
img_warning($langs->trans(
"ErrorBadEMail", $userfee->email));
1843 print
'<td>'.$langs->trans(
"CANCEL_USER").
'</span></td>';
1845 if (
$object->fk_user_cancel > 0) {
1846 $userfee =
new User($db);
1847 $result = $userfee->fetch(
$object->fk_user_cancel);
1849 print $userfee->getNomUrl(-1);
1855 print
'<td>'.$langs->trans(
"MOTIF_CANCEL").
'</td>';
1856 print
'<td>'.$object->detail_cancel.
'</td></tr>';
1859 print
'<td>'.$langs->trans(
"DATE_CANCEL").
'</td>';
1860 print
'<td>'.dol_print_date(
$object->date_cancel,
'dayhour',
'tzuser').
'</td></tr>';
1864 print
'<td>'.$langs->trans(
"ApprovedBy").
'</td>';
1866 if (
$object->fk_user_approve > 0) {
1867 $userapp =
new User($db);
1868 $result = $userapp->fetch(
$object->fk_user_approve);
1870 print $userapp->getNomUrl(-1);
1876 print
'<td>'.$langs->trans(
"DateApprove").
'</td>';
1877 print
'<td>'.dol_print_date(
$object->date_approve,
'dayhour',
'tzuser').
'</td></tr>';
1883 print
'<td>'.$langs->trans(
"REFUSEUR").
'</td>';
1885 $userfee =
new User($db);
1886 $result = $userfee->fetch(
$object->fk_user_refuse);
1888 print $userfee->getNomUrl(-1);
1893 print
'<td>'.$langs->trans(
"DATE_REFUS").
'</td>';
1894 print
'<td>'.dol_print_date(
$object->date_refuse,
'dayhour',
'tzuser');
1896 print
' - '.$object->detail_refuse;
1920 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
1925 print
'<div class="fichehalfright">';
1926 print
'<div class="underbanner clearboth"></div>';
1928 print
'<table class="border tableforfield centpercent">';
1932 print
'<td class="titlefieldmiddle">'.$langs->trans(
"AmountHT").
'</td>';
1933 print
'<td class="nowrap amountcard">'.price(
$object->total_ht, 1,
'', 1, - 1, - 1,
$conf->currency).
'</td>';
1950 print
'<td>'.$langs->trans(
"AmountVAT").
'</td>';
1951 print
'<td class="nowrap amountcard">'.price(
$object->total_tva, 1,
'', 1, -1, -1,
$conf->currency).
'</td>';
1955 if ($mysoc->localtax1_assuj ==
"1" ||
$object->total_localtax1 != 0) {
1956 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td>';
1957 print
'<td class="valuefield">'.price(
$object->total_localtax1, 1,
'', 1, -1, -1,
$conf->currency).
'</td></tr>';
1959 if ($mysoc->localtax2_assuj ==
"1" ||
$object->total_localtax2 != 0) {
1960 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td>';
1961 print
'<td class="valuefield">'.price(
$object->total_localtax2, 1,
'', 1, -1, -1,
$conf->currency).
'</td></tr>';
1965 print
'<td>'.$langs->trans(
"AmountTTC").
'</td>';
1966 print
'<td class="nowrap amountcard">'.price(
$object->total_ttc, 1,
'', 1, -1, -1,
$conf->currency).
'</td>';
1972 if (isModEnabled(
"bank")) {
1977 print
'<table class="noborder paymenttable centpercent">';
1979 print
'<tr class="liste_titre">';
1980 print
'<td class="liste_titre">'.$langs->trans(
'Payments').
'</td>';
1981 print
'<td class="liste_titre">'.$langs->trans(
'Date').
'</td>';
1982 print
'<td class="liste_titre">'.$langs->trans(
'Type').
'</td>';
1983 if (isModEnabled(
"bank")) {
1984 print
'<td class="liste_titre right">'.$langs->trans(
'BankAccount').
'</td>';
1986 print
'<td class="liste_titre right">'.$langs->trans(
'Amount').
'</td>';
1987 print
'<td class="liste_titre" width="18"> </td>';
1991 $sql =
"SELECT p.rowid, p.num_payment, p.datep as dp, p.amount, p.fk_bank,";
1992 $sql .=
"c.code as payment_code, c.libelle as payment_type,";
1993 $sql .=
"ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal";
1994 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as e, ".MAIN_DB_PREFIX.
"payment_expensereport as p";
1995 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON p.fk_typepayment = c.id";
1996 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
1997 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
1998 $sql .=
" WHERE e.rowid = ".((int) $id);
1999 $sql .=
" AND p.fk_expensereport = e.rowid";
2000 $sql .=
' AND e.entity IN ('.getEntity(
'expensereport').
')';
2001 $sql .=
" ORDER BY dp";
2003 $resql = $db->query($sql);
2005 $num = $db->num_rows($resql);
2009 $objp = $db->fetch_object($resql);
2011 $paymentexpensereportstatic->id = $objp->rowid;
2012 $paymentexpensereportstatic->datep = $db->jdate($objp->dp);
2013 $paymentexpensereportstatic->ref = $objp->rowid;
2014 $paymentexpensereportstatic->num_payment = $objp->num_payment;
2015 $paymentexpensereportstatic->type_code = $objp->payment_code;
2016 $paymentexpensereportstatic->type_label = $objp->payment_type;
2018 print
'<tr class="oddeven">';
2020 print $paymentexpensereportstatic->getNomUrl(1);
2022 print
'<td>'.dol_print_date($db->jdate($objp->dp),
'day').
"</td>\n";
2023 $labeltype = $langs->trans(
"PaymentType".$objp->payment_code) !=
"PaymentType".$objp->payment_code ? $langs->trans(
"PaymentType".$objp->payment_code) : $objp->payment_type;
2024 print
"<td>".$labeltype.
' '.$objp->num_payment.
"</td>\n";
2026 if (isModEnabled(
"bank")) {
2027 $bankaccountstatic->id = $objp->baid;
2028 $bankaccountstatic->ref = $objp->baref;
2029 $bankaccountstatic->label = $objp->baref;
2030 $bankaccountstatic->number = $objp->banumber;
2032 if (isModEnabled(
'accounting')) {
2033 $bankaccountstatic->account_number = $objp->account_number;
2036 $accountingjournal->fetch($objp->fk_accountancy_journal);
2037 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
2040 print
'<td class="right">';
2041 if ($bankaccountstatic->id) {
2042 print $bankaccountstatic->getNomUrl(1,
'transactions');
2046 print
'<td class="right">'.price($objp->amount).
"</td>";
2049 $totalpaid += $objp->amount;
2055 $resteapayeraffiche = $remaintopay;
2057 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
2060 $cssforamountpaymentcomplete =
'amountpaymentneutral';
2061 $resteapayeraffiche = 0;
2062 } elseif (
$object->paid == 0) {
2063 $cssforamountpaymentcomplete =
'amountpaymentneutral';
2065 print
'<tr><td colspan="'.$nbcols.
'" class="right">'.$langs->trans(
"AlreadyPaid").
':</td><td class="right">'.
price($totalpaid).
'</td><td></td></tr>';
2066 print
'<tr><td colspan="'.$nbcols.
'" class="right">'.$langs->trans(
"AmountExpected").
':</td><td class="right">'.
price(
$object->total_ttc).
'</td><td></td></tr>';
2068 print
'<tr><td colspan="'.$nbcols.
'" class="right">'.$langs->trans(
"RemainderToPay").
':</td>';
2069 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td><td></td></tr>';
2080 print
'<div class="clearboth"></div><br><br>';
2082 print
'<div style="clear: both;"></div>';
2084 $actiontouse =
'updateline';
2086 $actiontouse =
'addline';
2089 print
'<form name="expensereport" action="'.$_SERVER[
"PHP_SELF"].
'" enctype="multipart/form-data" method="post" >';
2090 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2091 print
'<input type="hidden" name="action" value="'.$actiontouse.
'">';
2092 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
2093 print
'<input type="hidden" name="fk_expensereport" value="'.$object->id.
'" />';
2094 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
2095 print
'<input type="hidden" name="page_y" value="">';
2097 print
'<div class="div-table-responsive-no-min">';
2098 print
'<table id="tablelines" class="noborder centpercent">';
2104 print
'<tr class="liste_titre headerexpensereportdet">';
2105 print
'<td class="center linecollinenb">'.$langs->trans(
'LineNb').
'</td>';
2107 print
'<td class="center linecoldate">'.$langs->trans(
'Date').
'</td>';
2108 if (isModEnabled(
'project')) {
2109 print
'<td class="minwidth100imp linecolproject">'.$langs->trans(
'Project').
'</td>';
2111 print
'<td class="center linecoltype">'.$langs->trans(
'Type').
'</td>';
2113 print
'<td class="center linecolcarcategory">'.$langs->trans(
'CarCategory').
'</td>';
2115 print
'<td class="linecoldescription">'.$langs->trans(
'Description').
'</td>';
2116 print
'<td class="right linecolvat">'.$langs->trans(
'VAT').
'</td>';
2117 print
'<td class="right linecolpriceuht">'.$langs->trans(
'PriceUHT').
'</td>';
2118 print
'<td class="right linecolpriceuttc">'.$langs->trans(
'PriceUTTC').
'</td>';
2119 print
'<td class="right linecolqty">'.$langs->trans(
'Qty').
'</td>';
2120 if ($action !=
'editline') {
2121 print
'<td class="right linecolamountht">'.$langs->trans(
'AmountHT').
'</td>';
2122 print
'<td class="right linecolamountttc">'.$langs->trans(
'AmountTTC').
'</td>';
2134 print
'<td class="right"></td>';
2138 foreach (
$object->lines as &$line) {
2141 if ($action !=
'editline' || $line->id !=
GETPOSTINT(
'rowid')) {
2142 print
'<tr class="oddeven linetr" data-id="'.$line->id.
'">';
2145 print
'<td class="center linecollinenb">';
2150 print
'<td class="center linecoldate">'.dol_print_date($db->jdate($line->date),
'day').
'</td>';
2153 if (isModEnabled(
'project')) {
2154 print
'<td class="lineproject">';
2155 if ($line->fk_project > 0) {
2156 $projecttmp->id = $line->fk_project;
2157 $projecttmp->ref = $line->projet_ref;
2158 $projecttmp->title = $line->projet_title;
2159 print $projecttmp->getNomUrl(1);
2165 if (isModEnabled(
'accounting')) {
2166 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
2168 $resaccountingaccount = $accountingaccount->fetch(0, $line->type_fees_accountancy_code, 1);
2170 $titlealt .= $langs->trans(
"AccountancyCode").
': ';
2171 if ($resaccountingaccount > 0) {
2172 $titlealt .= $accountingaccount->account_number;
2174 $titlealt .= $langs->trans(
"NotFound");
2180 print
'<td class="center linecoltype" title="'.dol_escape_htmltag($titlealt).
'">';
2181 $labeltype = ($langs->trans(($line->type_fees_code)) == $line->type_fees_code ? $line->type_fees_libelle : $langs->trans($line->type_fees_code));
2187 print
'<td class="fk_c_exp_tax_cat linecoltaxcat">';
2188 $exp_tax_cat_label =
dol_getIdFromCode($db, $line->fk_c_exp_tax_cat,
'c_exp_tax_cat',
'rowid',
'label');
2189 print $langs->trans($exp_tax_cat_label);
2194 print
'<td class="left linecolcomment">'.dol_nl2br($line->comments).
'</td>';
2197 $senderissupplier = 0;
2198 $tooltiponprice =
'';
2199 $tooltiponpriceend =
'';
2201 $tooltiponprice = $langs->transcountry(
"TotalHT", $mysoc->country_code).
'='.
price($line->total_ht);
2202 $tooltiponprice .=
'<br>'.$langs->transcountry(
"TotalVAT", ($senderissupplier ?
$object->thirdparty->country_code : $mysoc->country_code)).
'='.
price($line->total_tva);
2203 if (is_object(
$object->thirdparty)) {
2204 if ($senderissupplier) {
2205 $seller =
$object->thirdparty;
2212 if ($mysoc->useLocalTax(1)) {
2213 if (($seller->country_code == $buyer->country_code) || $line->total_localtax1 || $seller->useLocalTax(1)) {
2214 $tooltiponprice .=
'<br>'.$langs->transcountry(
"TotalLT1", $seller->country_code).
'='.
price($line->total_localtax1);
2216 $tooltiponprice .=
'<br>'.$langs->transcountry(
"TotalLT1", $seller->country_code).
'=<span class="opacitymedium">'.$langs->trans($senderissupplier ?
"NotUsedForThisVendor" :
"NotUsedForThisCustomer").
'</span>';
2219 if ($mysoc->useLocalTax(2)) {
2220 if ((isset($seller->country_code) && isset($buyer->thirdparty->country_code) && $seller->country_code == $buyer->thirdparty->country_code) || $line->total_localtax2 || $seller->useLocalTax(2)) {
2221 $tooltiponprice .=
'<br>'.$langs->transcountry(
"TotalLT2", $seller->country_code).
'='.
price($line->total_localtax2);
2223 $tooltiponprice .=
'<br>'.$langs->transcountry(
"TotalLT2", $seller->country_code).
'=<span class="opacitymedium">'.$langs->trans($senderissupplier ?
"NotUsedForThisVendor" :
"NotUsedForThisCustomer").
'</span>';
2227 $tooltiponprice .=
'<br>'.$langs->transcountry(
"TotalTTC", $mysoc->country_code).
'='.
price($line->total_ttc);
2229 $tooltiponprice =
'<span class="classfortooltip" title="'.dol_escape_htmltag($tooltiponprice).
'">';
2230 $tooltiponpriceend =
'</span>';
2233 print
'<td class="right linecolvatrate">';
2234 print $tooltiponprice;
2235 print
vatrate($line->vatrate.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
''), true);
2236 print $tooltiponpriceend;
2240 print
'<td class="right linecolunitht">';
2241 if (!empty($line->value_unit_ht)) {
2242 print
price($line->value_unit_ht);
2244 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $line->vatrate));
2245 $pricenettoshow =
price2num((
float) $line->value_unit / (1 + (
float) $tmpvat / 100),
'MU');
2246 print
price($pricenettoshow);
2250 print
'<td class="right linecolunitttc">'.price($line->value_unit).
'</td>';
2252 print
'<td class="right linecolqty">'.dol_escape_htmltag($line->qty).
'</td>';
2254 if ($action !=
'editline') {
2255 print
'<td class="right linecoltotalht">'.price($line->total_ht).
'</td>';
2256 print
'<td class="right linecoltotalttc">'.price($line->total_ttc).
'</td>';
2260 print
'<td class="center linecolpreview">';
2261 if ($line->fk_ecm_files > 0) {
2262 $modulepart =
'expensereport';
2263 $maxheightmini = 32;
2265 $result = $ecmfilesstatic->fetch($line->fk_ecm_files);
2267 $relativepath = preg_replace(
'/expensereport\//',
'', $ecmfilesstatic->filepath);
2268 $fileinfo = pathinfo($ecmfilesstatic->filepath.
'/'.$ecmfilesstatic->filename);
2271 if (!
dol_is_file(
$conf->expensereport->dir_output.
'/'.$relativepath.
'/'.$minifile)) {
2275 $urlforhref =
getAdvancedPreviewUrl($modulepart, $relativepath.
'/'.$fileinfo[
'filename'].
'.'.strtolower($fileinfo[
'extension']), 1,
'&entity='.(empty(
$object->entity) ?
$conf->entity :
$object->entity));
2276 if (empty($urlforhref)) {
2277 $urlforhref = DOL_URL_ROOT.
'/viewimage.php?modulepart='.$modulepart.
'&entity='.(empty(
$object->entity) ?
$conf->entity :
$object->entity).
'&file='.urlencode($relativepath.$fileinfo[
'filename'].
'.'.strtolower($fileinfo[
'extension']));
2278 print
'<a href="'.$urlforhref.
'" class="aphoto" target="_blank" rel="noopener noreferrer">';
2280 print
'<a href="'.$urlforhref[
'url'].
'" class="'.$urlforhref[
'css'].
'" target="'.$urlforhref[
'target'].
'" mime="'.$urlforhref[
'mime'].
'">';
2282 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="">';
2285 if (preg_match(
'/\.pdf$/i', $ecmfilesstatic->filename)) {
2286 $filepdf =
$conf->expensereport->dir_output.
'/'.$relativepath.
'/'.$ecmfilesstatic->filename;
2287 $fileimage =
$conf->expensereport->dir_output.
'/'.$relativepath.
'/'.$ecmfilesstatic->filename.
'_preview.png';
2288 $relativepathimage = $relativepath.
'/'.$ecmfilesstatic->filename.
'_preview.png';
2290 $pdfexists = file_exists($filepdf);
2293 if (!file_exists($fileimage) || (filemtime($fileimage) < filemtime($filepdf))) {
2295 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2304 if ($pdfexists && !$error) {
2305 $heightforphotref = 70;
2306 if (!empty(
$conf->dol_optimize_smallscreen)) {
2307 $heightforphotref = 60;
2309 $urlforhref =
getAdvancedPreviewUrl($modulepart, $relativepath.
'/'.$fileinfo[
'filename'].
'.'.strtolower($fileinfo[
'extension']), 1,
'&entity='.(empty(
$object->entity) ?
$conf->entity :
$object->entity));
2310 print
'<a href="'.$urlforhref[
'url'].
'" class="'.$urlforhref[
'css'].
'" target="'.$urlforhref[
'target'].
'" mime="'.$urlforhref[
'mime'].
'">';
2312 if (file_exists($fileimage)) {
2313 print
'<img height="'.$heightforphotref.
'" class="photo photowithmargin photowithborder" src="'.DOL_URL_ROOT.
'/viewimage.php?modulepart=apercu'.$modulepart.
'&file='.urlencode($relativepathimage).
'">';
2316 print
img_mime($ecmfilesstatic->filename);
2326 print
'<td class="nowrap right linecolwarning">';
2327 print !empty($line->rule_warning_message) ?
img_warning(html_entity_decode($line->rule_warning_message)) :
' ';
2332 print
'<td class="nowrap right linecolaction">';
2334 print
'<a class="editfielda reposition paddingrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=editline&token='.
newToken().
'&rowid='.$line->rowid.
'">';
2336 print
'</a> ';
2337 print
'<a class="paddingrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=delete_line&token='.
newToken().
'&rowid='.$line->rowid.
'">';
2347 if ($action ==
'editline' && $line->id ==
GETPOSTINT(
'rowid')) {
2350 if (isModEnabled(
'project')) {
2357 print
'<!-- line of expense report -->'.
"\n";
2358 print
'<tr class="tredited">';
2360 print
'<td class="center">';
2364 print
'<td colspan="'.($colspan - 1).
'" class="liste_titre"> ';
2365 print
'<a href="" class="commonlink auploadnewfilenow reposition">'.$langs->trans(
"UploadANewFileNow");
2366 print
img_picto($langs->trans(
"UploadANewFileNow"),
'chevron-down',
'', 0, 0, 0,
'',
'marginleftonly');
2369 print
' - <a href="" class="commonlink aattachtodoc reposition">'.$langs->trans(
"AttachTheNewLineToTheDocument");
2370 print
img_picto($langs->trans(
"AttachTheNewLineToTheDocument"),
'chevron-down',
'', 0, 0, 0,
'',
'marginleftonly');
2374 print
'<!-- Code to open/close section to submit or link files in edit mode -->'.
"\n";
2375 print
'<script type="text/javascript">'.
"\n";
2376 print
'$(document).ready(function() {
2377 $( ".auploadnewfilenow" ).click(function() {
2378 jQuery(".truploadnewfilenow").toggle();
2379 jQuery(".trattachnewfilenow").hide();
2382 $( ".aattachtodoc" ).click(function() {
2383 jQuery(".trattachnewfilenow").toggle();
2384 jQuery(".truploadnewfilenow").hide();
2387 if (is_array(
GETPOST(
'attachfile',
'array')) && count(
GETPOST(
'attachfile',
'array'))) {
2388 print
'jQuery(".trattachnewfilenow").toggle();'.
"\n";
2391 jQuery("form[name=\"expensereport\"]").submit(function() {
2392 if (jQuery(".truploadnewfilenow").is(":hidden")) {
2393 jQuery("input[name=\"sendit\"]").val("");
2400 print
'</script>'.
"\n";
2403 $filenamelinked =
'';
2404 if ($line->fk_ecm_files > 0) {
2405 $result = $ecmfilesstatic->fetch($line->fk_ecm_files);
2407 $filenamelinked = $ecmfilesstatic->filename;
2411 $tredited =
'tredited';
2412 include DOL_DOCUMENT_ROOT.
'/expensereport/tpl/expensereport_addfile.tpl.php';
2413 include DOL_DOCUMENT_ROOT.
'/expensereport/tpl/expensereport_linktofile.tpl.php';
2415 print
'<tr class="oddeven tredited">';
2420 print
'<td class="center">';
2421 print $form->selectDate($line->date,
'date');
2425 if (isModEnabled(
'project')) {
2426 print
'<td class="nowraponall">';
2427 print $formproject->select_projects(-1, $line->fk_project,
'fk_project', 0, 0, $projectRequired ? 0 : 1, 1, 0, 0, 0,
'', 1, 0,
'maxwidth300');
2432 print
'<td class="center">';
2433 print $formexpensereport->selectTypeExpenseReport($line->fk_c_type_fees,
'fk_c_type_fees');
2437 print
'<td class="fk_c_exp_tax_cat">';
2438 $params = array(
'fk_expense' =>
$object->id,
'fk_expense_det' => $line->id,
'date' => $line->date);
2439 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);
2445 print
'<textarea name="comments" class="flat_ndf centpercent">'.dol_escape_htmltag($line->comments, 0, 1).
'</textarea>';
2449 $selectedvat =
price2num($line->vatrate).(!empty($line->vat_src_code) ?
' ('.$line->vat_src_code.
')' :
'');
2450 print
'<td class="right">';
2451 print $form->load_tva(
'vatrate', (GETPOSTISSET(
"vatrate") ?
GETPOST(
"vatrate") : $selectedvat), $mysoc,
'', 0, 0,
'', false, 1, 2);
2455 print
'<td class="right">';
2456 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.
' />';
2460 print
'<td class="right">';
2461 print
'<input type="text" min="0" class="right maxwidth50" id="value_unit" name="value_unit" value="'.dol_escape_htmltag(
price2num($line->value_unit)).
'" />';
2465 print
'<td class="right">';
2466 print
'<input type="text" min="0" class="input_qty right maxwidth50" name="qty" value="'.dol_escape_htmltag($line->qty).
'" />';
2473 print
'<td class="center">';
2477 print
'<td class="center">';
2481 print
'<input type="hidden" name="rowid" value="'.$line->rowid.
'">';
2482 print $form->buttonsSaveCancel(
'Save',
'Cancel', array(), 0,
'small');
2498 if (isModEnabled(
'project')) {
2501 if ($action !=
'editline') {
2505 $nbFiles = $nbLinks = 0;
2506 $arrayoffiles = array();
2508 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2509 require_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
2510 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
2513 $nbFiles = count($arrayoffiles);
2518 print
'<tr class="liste_titre">';
2519 print
'<td colspan="'.$colspan.
'" class="liste_titre expensereportautoload">';
2520 print
'<a href="" class="commonlink auploadnewfilenow reposition">'.$langs->trans(
"UploadANewFileNow");
2521 print
img_picto($langs->trans(
"UploadANewFileNow"),
'chevron-down',
'', 0, 0, 0,
'',
'marginleftonly');
2524 print
' - <a href="" class="commonlink aattachtodoc reposition">'.$langs->trans(
"AttachTheNewLineToTheDocument");
2525 print
img_picto($langs->trans(
"AttachTheNewLineToTheDocument"),
'chevron-down',
'', 0, 0, 0,
'',
'marginleftonly');
2529 print
'<!-- Code to open/close section to submit or link files in the form to add new line -->'.
"\n";
2530 print
'<script type="text/javascript">'.
"\n";
2531 print
'$(document).ready(function() {
2532 $( ".auploadnewfilenow" ).click(function() {
2533 console.log("We click on toggle of auploadnewfilenow");
2534 jQuery(".truploadnewfilenow").toggle();
2535 jQuery(".trattachnewfilenow").hide();
2536 if (jQuery(".truploadnewfilenow").is(":hidden")) {
2537 jQuery("input[name=\"sendit\"]").prop("name", "senditdisabled");
2539 jQuery("input[name=\"senditdisabled\"]").prop("name", "sendit");
2541 // TODO Switch css fa-chevron-dow and add fa-chevron-up
2544 $( ".aattachtodoc" ).click(function() {
2545 console.log("We click on toggle of aattachtodoc");
2546 jQuery(".trattachnewfilenow").toggle();
2547 jQuery(".truploadnewfilenow").hide();
2548 // TODO Switch css fa-chevron-dow and add fa-chevron-up
2551 if (is_array(
GETPOST(
'attachfile',
'array')) && count(
GETPOST(
'attachfile',
'array')) && $action !=
'updateline') {
2552 print
'jQuery(".trattachnewfilenow").show();'.
"\n";
2555 jQuery("form[name=\"expensereport\"]").submit(function() {
2556 if (jQuery(".truploadnewfilenow").is(":hidden")) {
2557 /* 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. */
2558 jQuery("input[name=\"sendit\"]").val("");
2559 jQuery("input[name=\"sendit\"]").prop("name", "senditdisabled");
2561 jQuery("input[name=\"senditdisabled\"]").prop("name", "sendit");
2568 print
'</script>'.
"\n";
2572 include DOL_DOCUMENT_ROOT.
'/expensereport/tpl/expensereport_linktofile.tpl.php';
2573 include DOL_DOCUMENT_ROOT.
'/expensereport/tpl/expensereport_addfile.tpl.php';
2575 print
'<tr class="liste_titre expensereportcreate">';
2577 print
'<td class="center expensereportcreatedate">'.$langs->trans(
'Date').
'</td>';
2578 if (isModEnabled(
'project')) {
2579 print
'<td class="minwidth100imp">'.$form->textwithpicto($langs->trans(
'Project'), $langs->trans(
"ClosedProjectsAreHidden")).
'</td>';
2581 print
'<td class="center expensereportcreatetype">'.$langs->trans(
'Type').
'</td>';
2583 print
'<td>'.$langs->trans(
'CarCategory').
'</td>';
2585 print
'<td class="expensereportcreatedescription">'.$langs->trans(
'Description').
'</td>';
2586 print
'<td class="right expensereportcreatevat">'.$langs->trans(
'VAT').
'</td>';
2587 print
'<td class="right expensereportcreatepriceuth">'.$langs->trans(
'PriceUHT').
'</td>';
2588 print
'<td class="right expensereportcreatepricettc">'.$langs->trans(
'PriceUTTC').
'</td>';
2589 print
'<td class="right expensereportcreateqty">'.$langs->trans(
'Qty').
'</td>';
2596 print
'<tr class="oddeven nohover">';
2602 print
'<td class="center inputdate">';
2603 print $form->selectDate(!empty($date) ? $date : -1,
'date', 0, 0, 0,
'', 1, 1);
2607 if (isModEnabled(
'project')) {
2608 print
'<td class="inputproject">';
2609 $formproject->select_projects(-1, !empty($fk_project) ? $fk_project : 0,
'fk_project', 0, 0, $projectRequired ? 0 : 1, -1, 0, 0, 0,
'', 0, 0,
'maxwidth300');
2614 print
'<td class="center inputtype">';
2615 print $formexpensereport->selectTypeExpenseReport(!empty($fk_c_type_fees) ? $fk_c_type_fees :
"",
'fk_c_type_fees', 1);
2619 print
'<td class="fk_c_exp_tax_cat">';
2620 $params = array(
'fk_expense' =>
$object->id);
2621 print $form->selectExpenseCategories(
'',
'fk_c_exp_tax_cat', 1, array(),
'fk_c_type_fees', $userauthor->default_c_exp_tax_cat, $params, 0);
2626 print
'<td class="inputcomment">';
2627 print
'<textarea class="flat_ndf centpercent" name="comments" rows="'.ROWS_2.
'">'.
dol_escape_htmltag(!empty($comments) ? $comments :
"", 0, 1).
'</textarea>';
2631 print
'<td class="right inputvat">';
2635 $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS =
'none';
2637 print $form->load_tva(
'vatrate', (!empty($vatrate) ? $vatrate : $defaultvat), null, null, 0, 0,
'', false, 1);
2641 print
'<td class="right inputpricenet">';
2642 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 :
"")).
'"'.$taxlessUnitPriceDisabled.
' />';
2646 print
'<td class="right inputtax">';
2647 print
'<input type="text" class="right maxwidth50" id="value_unit" name="value_unit" value="'.dol_escape_htmltag((!empty($value_unit) ? $value_unit :
"")).
'">';
2651 print
'<td class="right inputqty">';
2652 print
'<input type="text" min="0" class=" input_qty right maxwidth50" name="qty" value="'.dol_escape_htmltag(!empty($qty) ? $qty : 1).
'">';
2658 if ($action !=
'editline') {
2659 print
'<td class="right"></td>';
2660 print
'<td class="right"></td>';
2664 print
'<td class="center inputbuttons">';
2665 print $form->buttonsSaveCancel(
"Add",
'',
'', 1,
'reposition');
2676 /* JQuery for product free or predefined select */
2677 jQuery(document).ready(function() {
2678 jQuery("#value_unit_ht").keyup(function(event) {
2679 console.log(event.which); // discard event tag and arrows
2680 if (event.which != 9 && (event.which < 37 ||event.which > 40) && jQuery("#value_unit_ht").val() != "") {
2681 jQuery("#value_unit").val("");
2684 jQuery("#value_unit").keyup(function(event) {
2685 console.log(event.which); // discard event tag and arrows
2686 if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#value_unit").val() != "") {
2687 jQuery("#value_unit_ht").val("");
2695 /* unit price coef calculation */
2696 jQuery(".input_qty, #fk_c_type_fees, #select_fk_c_exp_tax_cat, #vatrate ").change(function(event) {
2697 console.log("We change a parameter");
2699 let type_fee = jQuery("#fk_c_type_fees").find(":selected").val();
2700 let tax_cat = jQuery("#select_fk_c_exp_tax_cat").find(":selected").val();
2701 let tva = jQuery("#vatrate").find(":selected").val();
2702 let qty = jQuery(".input_qty").val();
2704 let path = "'.DOL_URL_ROOT.
'/expensereport/ajax/ajaxik.php";
2705 path += "?fk_c_exp_tax_cat="+tax_cat;
2706 path += "&fk_expense="+'.((int)
$object->id).
';
2707 path += "&vatrate="+tva;
2708 path += "&qty="+qty;
2710 if (type_fee == 4) { // frais_kilométriques
2711 if (tax_cat == "" || parseInt(tax_cat) <= 0){
2719 success: function(response) {
2720 if (response.response_status == "success"){';
2724 jQuery("#value_unit").val(parseFloat(response.data) * (100 + parseFloat(tva)) / 100);
2725 jQuery("#value_unit").trigger("change");
2729 jQuery("#value_unit_ht").val(response.data);
2730 jQuery("#value_unit_ht").trigger("change");
2731 jQuery("#value_unit").val("");
2736 } else if(response.response_status == "error" && response.errorMessage != undefined && response.errorMessage.length > 0 ) {
2737 console.log("We get an error result");
2738 $.jnotify(response.errorMessage, "error", {timeout: 0, type: "error"},{ remove: function (){} } );
2744 /*console.log(event.which); // discard event tag and arrows
2745 if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#value_unit").val() != "") {
2746 jQuery("#value_unit_ht").val("");
2766 print
'Record not found';
2777print
'<div class="tabsAction">';
2779if ($action !=
'create' && $action !=
'edit' && $action !=
'editline') {
2784 if (empty($user->socid)) {
2787 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>';
2799 if (in_array(
$object->fk_user_author, $childids) || $user->hasRight(
'expensereport',
'writeall_advance')) {
2801 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>';
2804 if (count(
$object->lines) > 0) {
2805 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>';
2816 if ($user->id ==
$object->fk_user_author || $user->id ==
$object->fk_user_valid) {
2818 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>';
2823 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>';
2828 if ($user->id ==
$object->fk_user_author || $user->id ==
$object->fk_user_valid) {
2830 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>';
2840 if (in_array(
$object->fk_user_author, $childids)) {
2842 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>';
2850 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=validate&token='.
newToken().
'&id='.
$object->id.
'">'.$langs->trans(
'Approve').
'</a></div>';
2852 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=refuse&token='.
newToken().
'&id='.
$object->id.
'">'.$langs->trans(
'Deny').
'</a></div>';
2855 if ($user->id ==
$object->fk_user_author || $user->id ==
$object->fk_user_valid) {
2857 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=cancel&id='.
$object->id.
'">'.$langs->trans(
"Cancel").
'</a></div>';
2866 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=refuse&token='.
newToken().
'&id='.
$object->id.
'">'.$langs->trans(
'Deny').
'</a></div>';
2872 if ($remaintopay == 0) {
2873 print
'<div class="inline-block divButAction"><span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPayment').
'</span></div>';
2875 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>';
2883 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>";
2889 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>';
2895 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>';
2900 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>';
2904 if ($user->hasRight(
'expensereport',
'creer')) {
2905 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>';
2911 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>';
2914 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>';
2917 $parameters = array();
2918 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters,
$object, $action);
2925if (
GETPOST(
'modelselected',
'alpha')) {
2926 $action =
'presend';
2929if ($action !=
'presend') {
2934 print
'<div class="fichecenter"><div class="fichehalfleft">';
2935 print
'<a name="builddoc"></a>';
2937 if ($user->hasRight(
'expensereport',
'creer') && $action !=
'create' && $action !=
'edit') {
2940 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".
$object->id;
2941 $genallowed = $user->hasRight(
'expensereport',
'creer');
2942 $delallowed = $user->hasRight(
'expensereport',
'creer');
2944 print $formfile->showdocuments(
'expensereport', $filename, $filedir, $urlsource, $genallowed, $delallowed);
2945 $somethingshown = $formfile->numoffiles;
2961 print
'</div><div class="fichehalfright">';
2963 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
2965 $somethingshown = $formactions->showactions(
$object,
'expensereport',
null);
2967 print
'</div></div>';
2971$modelmail =
'expensereport_send';
2972$defaulttopic =
'SendExpenseReportRef';
2973$diroutput =
$conf->expensereport->dir_output;
2974$trackid =
'exp'.$object->id;
2976include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
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($utf8_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_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
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($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formatted for view output Used into pdf and HTML pages.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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 '.
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_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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
newToken()
Return the value of token currently saved into session with name 'newtoken'.
getImageFileNameForSize($file, $extName, $extImgTarget='')
Return the filename of file to get the thumbs.
get_date_range($date_start, $date_end, $format='', $outputlangs=null, $withparenthesis=1)
Format output for start and end date.
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.
dol_clone($object, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify 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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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.