32require
'../main.inc.php';
44require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formexpensereport.class.php';
45require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
46require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
47require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
48require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
49require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
50require_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
51require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
52require_once DOL_DOCUMENT_ROOT.
'/core/lib/expensereport.lib.php';
53require_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
54require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
55require_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
56require_once DOL_DOCUMENT_ROOT.
'/core/modules/expensereport/modules_expensereport.php';
57require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
58require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/paymentexpensereport.class.php';
59require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
61 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);
91 if (empty($date_end)) {
98$rootfordata = DOL_DATA_ROOT;
99$rootforuser = DOL_DATA_ROOT;
102 $rootfordata .=
'/'.$conf->entity;
104$conf->expensereport->dir_output = $rootfordata.
'/expensereport';
108$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
120$extrafields->fetch_name_optionals_label(
$object->table_element);
123include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
126$hookmanager->initHooks(array(
'expensereportcard',
'globalcard'));
128$permissionnote = $user->hasRight(
'expensereport',
'creer');
129$permissiondellink = $user->hasRight(
'expensereport',
'creer');
130$permissiontoadd = $user->hasRight(
'expensereport',
'creer');
131$permissiontoeditextra = $permissiontoadd;
132if (
GETPOST(
'attribute',
'aZ09') && isset($extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')])) {
134 $permissiontoeditextra =
dol_eval((
string) $extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')]);
145 if ($user->hasRight(
'expensereport',
'readall')) {
148 if ($user->hasRight(
'expensereport',
'lire') && in_array(
$object->fk_user_author, $childids)) {
157if ($user->hasRight(
'expensereport',
'supprimer')) {
166 $socid = $user->socid;
170$permissiontoadd = $user->hasRight(
'expensereport',
'creer');
183$parameters = array(
'socid' => $socid);
184$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
186 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
189if (empty($reshook)) {
190 $backurlforlist = DOL_URL_ROOT.
'/expensereport/list.php';
192 if (empty($backtopage) || ($cancel && empty($id))) {
193 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
194 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
195 $backtopage = $backurlforlist;
197 $backtopage = DOL_URL_ROOT.
'/expensereport/card.php?id='.((!empty($id) &&
$id > 0) ? $id :
'__ID__');
203 if (!empty($backtopageforcancel)) {
204 header(
"Location: ".$backtopageforcancel);
206 } elseif (!empty($backtopage)) {
207 header(
"Location: ".$backtopage);
221 $fk_c_type_fees = -1;
224 include DOL_DOCUMENT_ROOT.
'/core/actions_linkedfiles.inc.php';
226 if (!empty(
GETPOST(
'sendit',
'alpha'))) {
227 if ($action ==
'updateline') {
228 $action =
'editline';
234 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
236 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
238 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
241 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontoadd) {
243 setEventMessages($langs->trans(
"NoCloneOptionsSpecified"),
null,
'errors');
251 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
262 if ($action ==
'confirm_delete' &&
GETPOST(
"confirm",
'alpha') ==
"yes" && $id > 0 && $candelete) {
266 $result =
$object->delete($user);
268 header(
"Location: index.php");
275 if ($action ==
'add' && $permissiontoadd) {
282 if (!(
$object->fk_user_author > 0)) {
283 $object->fk_user_author = $user->id;
287 if ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'expensereport',
'creer'))
288 || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'expensereport',
'creer') && !$user->hasRight(
'expensereport',
'writeall_advance'))) {
290 setEventMessages($langs->trans(
"NotEnoughPermissions"),
null,
'errors');
293 if (!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') || !$user->hasRight(
'expensereport',
'writeall_advance')) {
294 if (!in_array(
$object->fk_user_author, $childids)) {
296 setEventMessages($langs->trans(
"UserNotInHierachy"),
null,
'errors');
301 $fuser =
new User($db);
302 $fuser->fetch(
$object->fk_user_author);
311 $ret = $extrafields->setOptionalsFromPost(
null, $object);
320 if ($overlappingExpenseReportID > 0) {
322 setEventMessages($langs->trans(
"ErrorDoubleDeclaration").
' <a href="'.$_SERVER[
'PHP_SELF'].
'?id='.$overlappingExpenseReportID.
'">'. $langs->trans(
'ShowTrip').
'</a>',
null,
'errors');
337 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
347 if (($action ==
'update' || $action ==
'updateFromRefuse') && $permissiontoadd) {
361 $object->fk_user_modif = $user->id;
363 $result =
$object->update($user);
365 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
GETPOSTINT(
'id'));
372 if ($action ==
'update_extras' && $permissiontoeditextra) {
375 $attribute_name =
GETPOST(
'attribute',
'aZ09');
378 $ret = $extrafields->setOptionalsFromPost(
null, $object, $attribute_name);
384 $result =
$object->updateExtraField($attribute_name,
'EXPENSEREPORT_MODIFY');
392 $action =
'edit_extras';
396 if ($action ==
"confirm_validate" &&
GETPOST(
"confirm",
'alpha') ==
"yes" && $id > 0 && $permissiontoadd) {
402 $result =
$object->setValidate($user);
407 $outputlangs = $langs;
410 $newlang =
GETPOST(
'lang_id',
'aZ09');
413 $tmpuser =
new User($db);
414 $tmpuser->fetch(
$object->fk_user_author);
415 $newlang = $tmpuser->lang;
417 if (!empty($newlang)) {
419 $outputlangs->setDefaultLang($newlang);
424 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
431 if (!$error && $result > 0 &&
$object->fk_user_validator > 0) {
432 $langs->load(
"mails");
435 $destinataire =
new User($db);
436 $destinataire->fetch(
$object->fk_user_validator);
437 $emailTo = $destinataire->email;
440 $expediteur =
new User($db);
441 $expediteur->fetch(
$object->fk_user_author);
444 if ($emailTo && $emailFrom) {
455 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportWaitingForApproval");
458 $link = $urlwithroot.
'/expensereport/card.php?id='.
$object->id;
459 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
460 $summary =
$object->getSummary();
462 if ($summary !==
'') {
463 $message .= $langs->transnoentities(
"Summary").
': '.
dol_escape_htmltag($summary).
'<br>';
465 $message .= $langs->transnoentities(
"ExpenseReportWaitingForApprovalMessage", $expediteur->getFullName($langs),
get_date_range(
$object->date_debut,
$object->date_fin,
'', $langs), $link);
480 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
482 if (empty($mailfile->error)) {
484 $result = $mailfile->sendfile();
486 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
487 setEventMessages($mesg,
null,
'mesgs');
489 $langs->load(
"other");
490 if (!empty($mailfile->error) || !empty($mailfile->errors)) {
493 if (!empty($mailfile->error)) {
494 $mesg .=
'<br>' . $mailfile->error;
496 if (!empty($mailfile->errors) && is_array($mailfile->errors)) {
497 $mesg .=
'<br>' . implode(
'<br>', $mailfile->errors);
499 setEventMessages($mesg,
null,
'errors');
501 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
505 setEventMessages($mailfile->error, $mailfile->errors,
'errors');
509 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
516 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
523 if ($action ==
"confirm_save_from_refuse" &&
GETPOST(
"confirm",
'alpha') ==
"yes" && $id > 0 && $permissiontoadd) {
526 $result =
$object->set_save_from_refuse($user);
531 $outputlangs = $langs;
534 $newlang =
GETPOST(
'lang_id',
'aZ09');
537 $tmpuser =
new User($db);
538 $tmpuser->fetch(
$object->fk_user_author);
539 $newlang = $tmpuser->lang;
541 if (!empty($newlang)) {
543 $outputlangs->setDefaultLang($newlang);
548 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
556 $destinataire =
new User($db);
557 $destinataire->fetch(
$object->fk_user_validator);
558 $emailTo = $destinataire->email;
561 $expediteur =
new User($db);
562 $expediteur->fetch(
$object->fk_user_author);
565 if ($emailFrom && $emailTo) {
576 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportWaitingForReApproval");
579 $link = $urlwithroot.
'/expensereport/card.php?id='.
$object->id;
580 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
582 $message .=
'<br>'.$langs->transnoentities(
"ExpenseReportWaitingForReApprovalMessage2", $link);
601 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
603 if (empty($mailfile->error)) {
605 $result = $mailfile->sendfile();
607 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
608 setEventMessages($mesg,
null,
'mesgs');
609 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
612 $langs->load(
"other");
613 if ($mailfile->error) {
615 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
616 $mesg .=
'<br>'.$mailfile->error;
617 setEventMessages($mesg,
null,
'errors');
619 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
623 setEventMessages($mailfile->error, $mailfile->errors,
'errors');
627 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
636 if ($action ==
"confirm_approve" &&
GETPOST(
"confirm",
'alpha') ==
"yes" && $id > 0 && $user->hasRight(
'expensereport',
'approve')) {
640 $result =
$object->setApproved($user);
645 $outputlangs = $langs;
648 $newlang =
GETPOST(
'lang_id',
'aZ09');
651 $tmpuser =
new User($db);
652 $tmpuser->fetch(
$object->fk_user_author);
653 $newlang = $tmpuser->lang;
655 if (!empty($newlang)) {
657 $outputlangs->setDefaultLang($newlang);
662 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
670 $destinataire =
new User($db);
671 $destinataire->fetch(
$object->fk_user_author);
672 $emailTo = $destinataire->email;
676 if (empty($emailTo)) {
681 $expediteur =
new User($db);
682 $expediteur->fetch(
$object->fk_user_approve > 0 ?
$object->fk_user_approve :
$object->fk_user_validator);
685 if ($emailFrom && $emailTo) {
696 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportApproved");
699 $link = $urlwithroot.
'/expensereport/card.php?id='.
$object->id;
700 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
701 $message = $langs->transnoentities(
"ExpenseReportApprovedMessage",
$object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $link);
718 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, $emailCC,
'', 0, -1);
720 if (empty($mailfile->error)) {
722 $result = $mailfile->sendfile();
724 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
725 setEventMessages($mesg,
null,
'mesgs');
726 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
729 $langs->load(
"other");
730 if ($mailfile->error) {
732 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
733 $mesg .=
'<br>'.$mailfile->error;
734 setEventMessages($mesg,
null,
'errors');
736 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
740 setEventMessages($mailfile->error, $mailfile->errors,
'errors');
744 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
748 setEventMessages($langs->trans(
"FailedtoSetToApprove"),
null,
'warnings');
753 if ($action ==
"confirm_refuse" &&
GETPOST(
'confirm',
'alpha') ==
"yes" && $id > 0 && $user->hasRight(
'expensereport',
'approve')) {
757 $detailRefuse =
GETPOST(
'detail_refuse',
'alpha');
758 $result =
$object->setDeny($user, $detailRefuse);
763 $outputlangs = $langs;
766 $newlang =
GETPOST(
'lang_id',
'aZ09');
769 $tmpuser =
new User($db);
770 $tmpuser->fetch(
$object->fk_user_author);
771 $newlang = $tmpuser->lang;
773 if (!empty($newlang)) {
775 $outputlangs->setDefaultLang($newlang);
780 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
788 $destinataire =
new User($db);
789 $destinataire->fetch(
$object->fk_user_author);
790 $emailTo = $destinataire->email;
793 $expediteur =
new User($db);
794 $expediteur->fetch(
$object->fk_user_refuse);
797 if ($emailFrom && $emailTo) {
808 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportRefused");
811 $link = $urlwithroot.
'/expensereport/card.php?id='.
$object->id;
812 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
813 $message = $langs->transnoentities(
"ExpenseReportRefusedMessage",
$object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $detailRefuse, $link);
831 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
833 if (empty($mailfile->error)) {
835 $result = $mailfile->sendfile();
837 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
838 setEventMessages($mesg,
null,
'mesgs');
839 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
842 $langs->load(
"other");
843 if ($mailfile->error) {
845 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
846 $mesg .=
'<br>'.$mailfile->error;
847 setEventMessages($mesg,
null,
'errors');
849 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
853 setEventMessages($mailfile->error, $mailfile->errors,
'errors');
857 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
861 setEventMessages($langs->trans(
"FailedtoSetToDeny"),
null,
'warnings');
867 if ($action ==
"confirm_cancel" &&
GETPOST(
'confirm',
'alpha') ==
"yes" && $id > 0 && $user->hasRight(
'expensereport',
'creer')) {
868 if (!
GETPOST(
'detail_cancel',
'alpha')) {
869 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Comment")),
null,
'errors');
874 if ($user->id ==
$object->fk_user_valid || $user->id ==
$object->fk_user_author) {
875 $detailCancel =
GETPOST(
'detail_cancel',
'alpha');
876 $result =
$object->set_cancel($user, $detailCancel);
881 $outputlangs = $langs;
884 $newlang =
GETPOST(
'lang_id',
'aZ09');
887 $tmpuser =
new User($db);
888 $tmpuser->fetch(
$object->fk_user_author);
889 $newlang = $tmpuser->lang;
891 if (!empty($newlang)) {
893 $outputlangs->setDefaultLang($newlang);
898 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
906 $destinataire =
new User($db);
907 $destinataire->fetch(
$object->fk_user_author);
908 $emailTo = $destinataire->email;
911 $expediteur =
new User($db);
912 $expediteur->fetch(
$object->fk_user_cancel);
915 if ($emailFrom && $emailTo) {
926 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportCanceled");
929 $link = $urlwithroot.
'/expensereport/card.php?id='.
$object->id;
930 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
931 $message = $langs->transnoentities(
"ExpenseReportCanceledMessage",
$object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $detailCancel, $link);
949 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
951 if (empty($mailfile->error)) {
953 $result = $mailfile->sendfile();
955 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
956 setEventMessages($mesg,
null,
'mesgs');
957 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
960 $langs->load(
"other");
961 if ($mailfile->error) {
963 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
964 $mesg .=
'<br>'.$mailfile->error;
965 setEventMessages($mesg,
null,
'errors');
967 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
971 setEventMessages($mailfile->error, $mailfile->errors,
'errors');
975 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
979 setEventMessages($langs->trans(
"FailedToSetToCancel"),
null,
'warnings');
988 if ($action ==
"confirm_setdraft" &&
GETPOST(
'confirm',
'alpha') ==
"yes" && $id > 0 && $user->hasRight(
'expensereport',
'creer')) {
991 if ($user->id ==
$object->fk_user_author || $user->id ==
$object->fk_user_valid || in_array(
$object->fk_user_author, $childids)) {
997 $outputlangs = $langs;
1000 $newlang =
GETPOST(
'lang_id',
'aZ09');
1003 $tmpuser =
new User($db);
1004 $tmpuser->fetch(
$object->fk_user_author);
1005 $newlang = $tmpuser->lang;
1007 if (!empty($newlang)) {
1009 $outputlangs->setDefaultLang($newlang);
1014 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1019 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
1025 setEventMessages(
"NOT_AUTHOR",
null,
'errors');
1029 if ($action ==
'set_unpaid' && $id > 0 && $user->hasRight(
'expensereport',
'to_paid')) {
1033 $result =
$object->setUnpaid($user);
1038 $outputlangs = $langs;
1041 $newlang =
GETPOST(
'lang_id',
'aZ09');
1044 $tmpuser =
new User($db);
1045 $tmpuser->fetch(
$object->fk_user_author);
1046 $newlang = $tmpuser->lang;
1048 if (!empty($newlang)) {
1050 $outputlangs->setDefaultLang($newlang);
1055 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1058 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
1064 if ($action ==
'set_paid' && $id > 0 && $user->hasRight(
'expensereport',
'to_paid')) {
1068 $result =
$object->setPaid($id, $user);
1073 $outputlangs = $langs;
1076 $newlang =
GETPOST(
'lang_id',
'aZ09');
1079 $tmpuser =
new User($db);
1080 $tmpuser->fetch(
$object->fk_user_author);
1081 $newlang = $tmpuser->lang;
1083 if (!empty($newlang)) {
1085 $outputlangs->setDefaultLang($newlang);
1090 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1101 $destinataire =
new User($db);
1102 $destinataire->fetch(
$object->fk_user_author);
1103 $emailTo = $destinataire->email;
1106 $expediteur =
new User($db);
1107 $expediteur->fetch($user->id);
1110 if ($emailFrom && $emailTo) {
1111 $filename = array();
1113 $mimetype = array();
1121 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportPaid");
1124 $link = $urlwithroot.
'/expensereport/card.php?id='.
$object->id;
1125 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
1126 $message = $langs->transnoentities(
"ExpenseReportPaidMessage",
$object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $link);
1129 $object->setDocModel($user,
"");
1130 $resultPDF = expensereport_pdf_create($db, $object,
'',
"", $langs);
1133 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
1135 if (empty($mailfile->error)) {
1137 $result = $mailfile->sendfile();
1139 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
1140 setEventMessages($mesg,
null,
'mesgs');
1142 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
1145 $langs->load(
"other");
1146 if ($mailfile->error) {
1148 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
1149 $mesg .=
'<br>'.$mailfile->error;
1150 setEventMessages($mesg,
null,
'errors');
1152 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
1156 setEventMessages($mailfile->error, $mailfile->errors,
'errors');
1159 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
1163 setEventMessages($langs->trans(
"FailedToSetPaid"),
null,
'warnings');
1169 if ($action ==
"addline" && $user->hasRight(
'expensereport',
'creer')) {
1173 $arrayoffiles =
GETPOST(
'attachfile',
'array');
1174 if (is_array($arrayoffiles) && !empty($arrayoffiles[0])) {
1175 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1176 $entityprefix = (
$conf->entity !=
'1') ?
$conf->entity.
'/' :
'';
1177 $relativepath =
'expensereport/'.$object->ref.
'/'.$arrayoffiles[0];
1179 $ecmfiles->fetch(0,
'', $relativepath);
1180 $fk_ecm_files = $ecmfiles->id;
1185 if (empty($vatrate)) {
1188 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $vatrate));
1192 if (empty($value_unit)) {
1193 $value_unit =
price2num((
float) $value_unit_ht + ((
float) $value_unit_ht * (
float) $tmpvat / 100),
'MU');
1196 $fk_c_exp_tax_cat =
GETPOSTINT(
'fk_c_exp_tax_cat');
1203 if (!($fk_c_type_fees > 0)) {
1205 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1209 if ((
float) $tmpvat < 0 || $tmpvat ===
'') {
1211 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"VAT")),
null,
'errors');
1216 if (empty($date) || $date ==
"--") {
1218 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1219 } elseif ($date < $object->date_debut || $date > (
$object->date_fin + (24 * 3600 - 1))) {
1225 $langs->load(
"errors");
1226 $type = $error > 0 ?
'errors' :
'warnings';
1227 setEventMessages($langs->trans(
"WarningDateOfLineMustBeInExpenseReportRange"),
null, $type);
1231 if ($value_unit == 0) {
1233 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"PriceUTTC")),
null,
'errors');
1237 if ($projectRequired && $fk_project <= 0) {
1239 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Project")),
null,
'errors');
1243 if ($fileRequired && $fk_ecm_files == 0) {
1245 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"File")),
null,
'errors');
1252 $result =
$object->addline($qty, $value_unit, $fk_c_type_fees, $vatrate, $date, $comments, $fk_project, $fk_c_exp_tax_cat, $type, $fk_ecm_files);
1258 $outputlangs = $langs;
1259 $newlang =
GETPOST(
'lang_id',
'alpha');
1261 $tmpuser =
new User($db);
1262 $tmpuser->fetch(
$object->fk_user_author);
1263 $newlang = $tmpuser->lang;
1265 if (!empty($newlang)) {
1267 $outputlangs->setDefaultLang($newlang);
1270 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1274 unset($value_unit_ht);
1278 unset($fk_c_type_fees);
1289 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
GETPOSTINT(
'id'));
1296 if ($action ==
'confirm_delete_line' &&
GETPOST(
"confirm",
'alpha') ==
"yes" && $user->hasRight(
'expensereport',
'creer')) {
1302 $total_ht = $object_ligne->total_ht;
1303 $total_tva = $object_ligne->total_tva;
1310 $outputlangs = $langs;
1313 $newlang =
GETPOST(
'lang_id',
'aZ09');
1316 $tmpuser =
new User($db);
1317 $tmpuser->fetch(
$object->fk_user_author);
1318 $newlang = $tmpuser->lang;
1320 if (!empty($newlang)) {
1322 $outputlangs->setDefaultLang($newlang);
1327 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1331 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
GETPOSTINT(
'id'));
1338 if ($action ==
"updateline" && $permissiontoadd) {
1345 $arrayoffiles =
GETPOST(
'attachfile',
'array');
1346 if (is_array($arrayoffiles) && !empty($arrayoffiles[0])) {
1347 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1348 $relativepath =
'expensereport/'.$object->ref.
'/'.$arrayoffiles[0];
1350 $ecmfiles->fetch(0,
'', $relativepath);
1351 $fk_ecm_files = $ecmfiles->id;
1356 $type_fees_id =
GETPOSTINT(
'fk_c_type_fees');
1357 $fk_c_exp_tax_cat =
GETPOSTINT(
'fk_c_exp_tax_cat');
1358 $projet_id = $fk_project;
1359 $comments =
GETPOST(
'comments',
'restricthtml');
1361 $vatrate =
GETPOST(
'vatrate',
'alpha');
1364 if (empty($vatrate)) {
1367 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $vatrate));
1371 if (empty($value_unit)) {
1372 $value_unit =
price2num((
float) $value_unit_ht + ((
float) $value_unit_ht * (
float) $tmpvat / 100),
'MU');
1377 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1380 if ((
float) $tmpvat < 0 || $tmpvat ==
'') {
1382 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Vat")),
null,
'errors');
1386 if ($date < $object->date_debut || $date > (
$object->date_fin + (24 * 3600 - 1))) {
1391 $langs->load(
"errors");
1392 $type = $error > 0 ?
'errors' :
'warnings';
1393 setEventMessages($langs->trans(
"WarningDateOfLineMustBeInExpenseReportRange"),
null, $type);
1397 if ($projectRequired && $projet_id <= 0) {
1399 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Project")),
null,
'errors');
1404 $result =
$object->updateline($rowid, $type_fees_id, $projet_id, $vatrate, $comments, (
float) $qty, (
float) $value_unit, $date, $id, $fk_c_exp_tax_cat, $fk_ecm_files);
1409 $outputlangs = $langs;
1412 $newlang =
GETPOST(
'lang_id',
'aZ09');
1415 $tmpuser =
new User($db);
1416 $tmpuser->fetch(
$object->fk_user_author);
1417 $newlang = $tmpuser->lang;
1419 if (!empty($newlang)) {
1421 $outputlangs->setDefaultLang($newlang);
1426 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1430 unset($value_unit_ht);
1434 unset($fk_c_type_fees);
1447 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
1450 $triggersendname =
'EXPENSEREPORT_SENTBYMAIL';
1451 $autocopy =
'MAIN_MAIL_AUTOCOPY_EXPENSEREPORT_TO';
1452 $trackid =
'exp'.$object->id;
1453 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
1456 $upload_dir =
$conf->expensereport->dir_output;
1457 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1465$title = $langs->trans(
"ExpenseReport").
" - ".$langs->trans(
"Card");
1466$help_url =
"EN:Module_Expense_Reports|FR:Module_Notes_de_frais";
1470$form =
new Form($db);
1473$projecttmp =
new Project($db);
1475$bankaccountstatic =
new Account($db);
1476$ecmfilesstatic =
new EcmFiles($db);
1481if ($action ==
'create') {
1484 print
'<form action="'.$_SERVER[
'PHP_SELF'].
'" method="post" name="create">';
1485 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1486 print
'<input type="hidden" name="action" value="add">';
1487 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
1491 print
'<table class="border centpercent">';
1496 print
'<td class="fieldrequired">'.$langs->trans(
"User").
'</td>';
1498 $defaultselectuser = $user->id;
1500 $defaultselectuser =
GETPOSTINT(
'fk_user_author');
1502 $include_users =
'hierarchyme';
1503 if (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'expensereport',
'writeall_advance')) {
1504 $include_users = array();
1506 print img_picto(
'',
'user',
'class="pictofixedwidth"').$form->select_dolusers($defaultselectuser,
'fk_user_author', 0,
null, 0, $include_users,
'',
'0,'.
$conf->entity, 0, 0,
'', 0,
'',
'minwidth200 maxwidth500 inline-block');
1512 print
'<td class="titlefieldcreate fieldrequired">'.$langs->trans(
"DateStart").
'</td>';
1513 print
'<td>'.img_picto(
'',
'action',
'class="pictofixedwidth"');
1520 print
'<td class="fieldrequired">'.$langs->trans(
"DateEnd").
'</td>';
1521 print
'<td>'.img_picto(
'',
'action',
'class="pictofixedwidth"');
1522 print $form->selectDate($date_end ? $date_end : -1,
'date_fin', 0, 0, 0,
'', 1, 1);
1529 print
'<td>'.$langs->trans(
"ReviewedByCP").
'</td>';
1532 $include_users =
$object->fetch_users_approver_expensereport();
1533 if (empty($include_users)) {
1534 print img_warning().
' '.$langs->trans(
"NobodyHasPermissionToValidateExpenseReport");
1536 $defaultselectuser = (empty($user->fk_user_expense_validator) ? $user->fk_user : $user->fk_user_expense_validator);
1541 $defaultselectuser =
GETPOSTINT(
'fk_user_validator');
1543 $s = $form->select_dolusers($defaultselectuser,
"fk_user_validator", 1,
null, ((empty($defaultselectuser) || !
getDolGlobalString(
'EXPENSEREPORT_DEFAULT_VALIDATOR_UNCHANGEABLE')) ? 0 : 1), $include_users);
1544 print img_picto(
'',
'user',
'class="pictofixedwidth"').$form->textwithpicto($s, $langs->trans(
"AnyOtherInThisListCanValidate"));
1552 print
'<td>'.$langs->trans(
"ModePaiement").
'</td>';
1554 $form->select_types_paiements(
'',
'fk_c_paiement');
1563 print
'<td class="tdtop">'.$langs->trans(
'NotePublic').
'</td>';
1566 $doleditor =
new DolEditor(
'note_public', $note_public,
'', 80,
'dolibarr_notes',
'In',
false,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3,
'90%');
1567 print $doleditor->Create(1);
1571 $note_private =
GETPOSTISSET(
'note_private') ?
GETPOST(
'note_private',
'restricthtml') :
'';
1573 if (empty($user->socid)) {
1575 print
'<td class="tdtop">'.$langs->trans(
'NotePrivate').
'</td>';
1578 $doleditor =
new DolEditor(
'note_private', $note_private,
'', 80,
'dolibarr_notes',
'In',
false,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3,
'90%');
1579 print $doleditor->Create(1);
1584 $parameters = array(
'colspan' =>
' colspan="3"',
'cols' => 3);
1585 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
1586 print $hookmanager->resPrint;
1587 if (empty($reshook)) {
1588 print
$object->showOptionals($extrafields,
'create', $parameters);
1596 print $form->buttonsSaveCancel(
"AddTrip");
1601 $result =
$object->fetch($id, $ref);
1604 if (!in_array(
$object->fk_user_author, $childids)) {
1605 if (!$user->hasRight(
'expensereport',
'readall') && !$user->hasRight(
'expensereport',
'lire_tous')
1606 && (!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') || !$user->hasRight(
'expensereport',
'writeall_advance'))) {
1609 print
'<div class="tabBar">';
1610 print $langs->trans(
'NotUserRightToView');
1625 print
"<form name='update' action=\"".$_SERVER[
'PHP_SELF'].
"\" method=\"post\">\n";
1626 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1627 print
'<input type="hidden" name="id" value="'.$id.
'">';
1628 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
1630 print
dol_get_fiche_head($head,
'card', $langs->trans(
"ExpenseReport"), 0,
'trip', 0,
'',
'', 0,
'', 0);
1633 print
'<input type="hidden" name="action" value="updateFromRefuse">';
1635 print
'<input type="hidden" name="action" value="update">';
1638 $linkback =
'<a href="'.DOL_URL_ROOT.
'/expensereport/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
1640 print
'<table class="border centpercent">';
1643 print
'<td>'.$langs->trans(
"User").
'</td>';
1645 $userfee =
new User($db);
1646 if (
$object->fk_user_author > 0) {
1647 $userfee->fetch(
$object->fk_user_author);
1648 print $userfee->getNomUrl(-1);
1653 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Ref").
'</td><td>';
1654 print $form->showrefnav($object,
'ref', $linkback, 1,
'ref',
'ref',
'');
1658 print
'<td>'.$langs->trans(
"DateStart").
'</td>';
1660 print $form->selectDate(
$object->date_debut,
'date_debut');
1664 print
'<td>'.$langs->trans(
"DateEnd").
'</td>';
1666 print $form->selectDate(
$object->date_fin,
'date_fin');
1672 print
'<td>'.$langs->trans(
"ModePaiement").
'</td>';
1674 $form->select_types_paiements((
string)
$object->fk_c_paiement,
'fk_c_paiement');
1681 print
'<td>'.$langs->trans(
"VALIDATOR").
'</td>';
1683 $include_users =
$object->fetch_users_approver_expensereport();
1684 $s = $form->select_dolusers(
$object->fk_user_validator,
"fk_user_validator", 1,
null, 0, $include_users);
1685 print $form->textwithpicto($s, $langs->trans(
"AnyOtherInThisListCanValidate"));
1690 print
'<td>'.$langs->trans(
"VALIDOR").
'</td>';
1692 $userfee =
new User($db);
1693 $userfee->fetch(
$object->fk_user_valid);
1694 print $userfee->getNomUrl(-1);
1700 print
'<td>'.$langs->trans(
"AUTHORPAIEMENT").
'</td>';
1702 $userfee =
new User($db);
1703 $userfee->fetch($user->id);
1704 print $userfee->getNomUrl(-1);
1716 print $form->buttonsSaveCancel(
"Modify");
1720 $taxlessUnitPriceDisabled =
getDolGlobalString(
'EXPENSEREPORT_FORCE_LINE_AMOUNTS_INCLUDING_TAXES_ONLY') ?
' disabled' :
'';
1722 print
dol_get_fiche_head($head,
'card', $langs->trans(
"ExpenseReport"), -1,
'trip', 0,
'',
'', 0,
'', 1);
1727 if ($action ==
'clone') {
1729 $criteriaforfilter =
'hierarchyme';
1730 if ($user->hasRight(
'expensereport',
'readall')) {
1731 $criteriaforfilter =
'';
1733 $formquestion = array(
1735 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'))
1738 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneExpenseReport',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1);
1741 if ($action ==
'save') {
1742 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"SaveTrip"), $langs->trans(
"ConfirmSaveTrip"),
"confirm_validate",
"",
"", 1);
1745 if ($action ==
'save_from_refuse') {
1746 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"SaveTrip"), $langs->trans(
"ConfirmSaveTrip"),
"confirm_save_from_refuse",
"",
"", 1);
1749 if ($action ==
'delete') {
1750 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"DeleteTrip"), $langs->trans(
"ConfirmDeleteTrip"),
"confirm_delete",
"",
"", 1);
1753 if ($action ==
'validate') {
1754 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"ValideTrip"), $langs->trans(
"ConfirmValideTrip"),
"confirm_approve",
"",
"", 1);
1757 if ($action ==
'paid') {
1758 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"PaidTrip"), $langs->trans(
"ConfirmPaidTrip"),
"confirm_paid",
"",
"", 1);
1761 if ($action ==
'cancel') {
1762 $array_input = array(
'text' => $langs->trans(
"ConfirmCancelTrip"), 0 => array(
'type' =>
"text",
'label' =>
'<strong>'.$langs->trans(
"Comment").
'</strong>',
'name' =>
"detail_cancel",
'value' =>
""));
1763 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"Cancel"),
"",
"confirm_cancel", $array_input,
"", 1);
1766 if ($action ==
'setdraft') {
1767 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"BrouillonnerTrip"), $langs->trans(
"ConfirmBrouillonnerTrip"),
"confirm_setdraft",
"",
"", 1);
1770 if ($action ==
'refuse') {
1771 $array_input = array(
'text' => $langs->trans(
"ConfirmRefuseTrip"), 0 => array(
'type' =>
"text",
'label' => $langs->trans(
"Comment"),
'name' =>
"detail_refuse",
'value' =>
""));
1772 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"Deny"),
'',
"confirm_refuse", $array_input,
"yes", 1);
1775 if ($action ==
'delete_line') {
1776 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".
$id.
"&rowid=".
GETPOSTINT(
'rowid'), $langs->trans(
"DeleteLine"), $langs->trans(
"ConfirmDeleteLine"),
"confirm_delete_line",
'',
'yes', 1);
1780 $parameters = array(
'formConfirm' => $formconfirm);
1781 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
1782 if (empty($reshook)) {
1783 $formconfirm .= $hookmanager->resPrint;
1784 } elseif ($reshook > 0) {
1785 $formconfirm = $hookmanager->resPrint;
1792 $linkback =
'<a href="'.DOL_URL_ROOT.
'/expensereport/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
1794 $morehtmlref =
'<div class="refidno">';
1795 $summary =
$object->getSummary();
1796 if ($summary !==
'') {
1799 $morehtmlref .=
'</div>';
1801 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
1803 print
'<div class="fichecenter">';
1804 print
'<div class="fichehalfleft">';
1805 print
'<div class="underbanner clearboth"></div>';
1807 print
'<table class="border tableforfield centpercent">';
1811 print
'<td class="titlefield">'.$langs->trans(
"User").
'</td>';
1813 if (
$object->fk_user_author > 0) {
1814 $userauthor =
new User($db);
1815 $result = $userauthor->fetch(
$object->fk_user_author);
1817 dol_print_error(
null, $userauthor->error);
1818 } elseif ($result > 0) {
1819 print $userauthor->getNomUrl(-1);
1826 print
'<td class="titlefield">'.$langs->trans(
"Period").
'</td>';
1833 print
'<td>'.$langs->trans(
"ModePaiement").
'</td>';
1834 print
'<td>'.$object->fk_c_paiement.
'</td>';
1840 print
'<td>'.$langs->trans(
"DATE_SAVE").
'</td>';
1841 print
'<td>'.dol_print_date(
$object->date_valid,
'dayhour',
'tzuser');
1843 print
' '.img_warning($langs->trans(
"Late").
' - '.$langs->trans(
"ToApprove"));
1846 print
' '.img_warning($langs->trans(
"Late").
' - '.$langs->trans(
"ToPay"));
1854 print
'<td>'.$langs->trans(
"VALIDATOR").
'</td>';
1856 if (
$object->fk_user_validator > 0) {
1857 $userfee =
new User($db);
1858 $result = $userfee->fetch(
$object->fk_user_validator);
1860 print $userfee->getNomUrl(-1);
1862 if (empty($userfee->email) || !
isValidEmail($userfee->email)) {
1863 $langs->load(
"errors");
1864 print img_warning($langs->trans(
"ErrorBadEMail", $userfee->email));
1870 print
'<td>'.$langs->trans(
"CANCEL_USER").
'</span></td>';
1872 if (
$object->fk_user_cancel > 0) {
1873 $userfee =
new User($db);
1874 $result = $userfee->fetch(
$object->fk_user_cancel);
1876 print $userfee->getNomUrl(-1);
1882 print
'<td>'.$langs->trans(
"MOTIF_CANCEL").
'</td>';
1883 print
'<td>'.$object->detail_cancel.
'</td></tr>';
1886 print
'<td>'.$langs->trans(
"DATE_CANCEL").
'</td>';
1887 print
'<td>'.dol_print_date(
$object->date_cancel,
'dayhour',
'tzuser').
'</td></tr>';
1891 print
'<td>'.$langs->trans(
"ApprovedBy").
'</td>';
1893 if (
$object->fk_user_approve > 0) {
1894 $userapp =
new User($db);
1895 $result = $userapp->fetch(
$object->fk_user_approve);
1897 print $userapp->getNomUrl(-1);
1903 print
'<td>'.$langs->trans(
"DateApprove").
'</td>';
1904 print
'<td>'.dol_print_date(
$object->date_approve,
'dayhour',
'tzuser').
'</td></tr>';
1910 print
'<td>'.$langs->trans(
"REFUSEUR").
'</td>';
1912 $userfee =
new User($db);
1913 $result = $userfee->fetch(
$object->fk_user_refuse);
1915 print $userfee->getNomUrl(-1);
1920 print
'<td>'.$langs->trans(
"DATE_REFUS").
'</td>';
1921 print
'<td>'.dol_print_date(
$object->date_refuse,
'dayhour',
'tzuser');
1923 print
' - '.$object->detail_refuse;
1947 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
1952 print
'<div class="fichehalfright">';
1953 print
'<div class="underbanner clearboth"></div>';
1955 print
'<table class="border tableforfield centpercent">';
1959 print
'<td class="titlefieldmiddle">'.$langs->trans(
"AmountHT").
'</td>';
1960 print
'<td class="nowrap amountcard">'.price(
$object->total_ht, 1,
'', 1, - 1, - 1,
$conf->currency).
'</td>';
1977 print
'<td>'.$langs->trans(
"AmountVAT").
'</td>';
1978 print
'<td class="nowrap amountcard">'.price(
$object->total_tva, 1,
'', 1, -1, -1,
$conf->currency).
'</td>';
1982 if (
$mysoc->localtax1_assuj ==
"1" ||
$object->total_localtax1 != 0) {
1983 print
'<tr><td>'.$langs->transcountry(
"AmountLT1",
$mysoc->country_code).
'</td>';
1984 print
'<td class="valuefield">'.price(
$object->total_localtax1, 1,
'', 1, -1, -1,
$conf->currency).
'</td></tr>';
1986 if (
$mysoc->localtax2_assuj ==
"1" ||
$object->total_localtax2 != 0) {
1987 print
'<tr><td>'.$langs->transcountry(
"AmountLT2",
$mysoc->country_code).
'</td>';
1988 print
'<td class="valuefield">'.price(
$object->total_localtax2, 1,
'', 1, -1, -1,
$conf->currency).
'</td></tr>';
1992 print
'<td>'.$langs->trans(
"AmountTTC").
'</td>';
1993 print
'<td class="nowrap amountcard">'.price(
$object->total_ttc, 1,
'', 1, -1, -1,
$conf->currency).
'</td>';
1997 $canSeeBankAccount =
isModEnabled(
'bank') && $user->hasRight(
'banque',
'lire');
2000 if ($canSeeBankAccount) {
2005 print
'<div class="div-table-responsive-no-min">';
2006 print
'<table class="noborder paymenttable centpercent">';
2008 print
'<tr class="liste_titre">';
2009 print
'<td class="liste_titre">'.$langs->trans(
'Payments').
'</td>';
2010 print
'<td class="liste_titre">'.$langs->trans(
'Date').
'</td>';
2011 print
'<td class="liste_titre">'.$langs->trans(
'Type').
'</td>';
2012 if ($canSeeBankAccount) {
2013 print
'<td class="liste_titre right">'.$langs->trans(
'BankAccount').
'</td>';
2015 print
'<td class="liste_titre" width="18"> </td>';
2016 print
'<td class="liste_titre right">'.$langs->trans(
'Amount').
'</td>';
2020 $sql =
"SELECT p.rowid, p.num_payment, p.datep as dp, p.amount, p.fk_bank,";
2021 $sql .=
"c.code as payment_code, c.libelle as payment_type,";
2022 $sql .=
"ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal";
2023 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as e, ".MAIN_DB_PREFIX.
"payment_expensereport as p";
2024 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON p.fk_typepayment = c.id";
2025 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
2026 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
2027 $sql .=
" WHERE e.rowid = ".((int) $id);
2028 $sql .=
" AND p.fk_expensereport = e.rowid";
2029 $sql .=
' AND e.entity IN ('.getEntity(
'expensereport').
')';
2030 $sql .=
" ORDER BY dp";
2032 $resql = $db->query($sql);
2034 $num = $db->num_rows($resql);
2038 $objp = $db->fetch_object($resql);
2040 $paymentexpensereportstatic->id = $objp->rowid;
2041 $paymentexpensereportstatic->datep = $db->jdate($objp->dp);
2042 $paymentexpensereportstatic->ref = $objp->rowid;
2043 $paymentexpensereportstatic->num_payment = $objp->num_payment;
2044 $paymentexpensereportstatic->type_code = $objp->payment_code;
2045 $paymentexpensereportstatic->type_label = $objp->payment_type;
2047 print
'<tr class="oddeven">';
2049 print $paymentexpensereportstatic->getNomUrl(1);
2051 print
'<td>'.dol_print_date($db->jdate($objp->dp),
'day').
"</td>\n";
2052 $labeltype = $langs->trans(
"PaymentType".$objp->payment_code) !=
"PaymentType".$objp->payment_code ? $langs->trans(
"PaymentType".$objp->payment_code) : $objp->payment_type;
2053 print
"<td>".$labeltype.
' '.$objp->num_payment.
"</td>\n";
2055 if ($canSeeBankAccount) {
2056 $bankaccountstatic->id = $objp->baid;
2057 $bankaccountstatic->ref = $objp->baref;
2058 $bankaccountstatic->label = $objp->baref;
2059 $bankaccountstatic->number = $objp->banumber;
2062 $bankaccountstatic->account_number = $objp->account_number;
2065 $accountingjournal->fetch($objp->fk_accountancy_journal);
2066 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
2069 print
'<td class="right">';
2070 if ($bankaccountstatic->id) {
2071 print $bankaccountstatic->getNomUrl(1,
'transactions');
2076 print
'<td class="right">'.price($objp->amount).
"</td>";
2078 $totalpaid += $objp->amount;
2084 $resteapayeraffiche = $remaintopay;
2086 if ($remaintopay > 0) {
2087 $cssforamountpaymentcomplete =
'amountremaintopay';
2089 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
2093 $cssforamountpaymentcomplete =
'amountpaymentneutral strikefordisabled';
2094 } elseif (
$object->paid == 1 && $remaintopay > 0) {
2095 $cssforamountpaymentcomplete =
'amountpaymentneutral strikefordisabled';
2097 print
'<tr><td colspan="'.$nbcols.
'" class="right">'.$langs->trans(
"AlreadyPaid").
':</td>';
2099 print
'<td class="right">'.price($totalpaid).
'</td></tr>';
2101 print
'<tr><td colspan="'.$nbcols.
'" class="right">'.$langs->trans(
"AmountExpected").
':</td>';
2103 print
'<td class="right">'.price(
$object->total_ttc).
'</td></tr>';
2105 print
'<tr><td colspan="'.$nbcols.
'" class="right">'.$langs->trans(
"RemainderToPay").
':</td>';
2107 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td></tr>';
2111 dol_print_error($db);
2116 print
'<div class="clearboth"></div>';
2122 print
'<div style="clear: both;"></div>';
2124 $actiontouse =
'updateline';
2126 $actiontouse =
'addline';
2129 print
'<form name="expensereport" action="'.$_SERVER[
"PHP_SELF"].
'" enctype="multipart/form-data" method="post" >';
2130 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2131 print
'<input type="hidden" name="action" value="'.$actiontouse.
'">';
2132 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
2133 print
'<input type="hidden" name="fk_expensereport" value="'.$object->id.
'" />';
2134 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
2135 print
'<input type="hidden" name="page_y" value="">';
2137 print
'<div class="div-table-responsive-no-min">';
2138 print
'<table id="tablelines" class="noborder centpercent">';
2144 print
'<tr class="liste_titre headerexpensereportdet">';
2145 print
'<td class="center linecollinenb">'.$langs->trans(
'LineNb').
'</td>';
2147 print
'<td class="center linecoldate">'.$langs->trans(
'Date').
'</td>';
2149 print
'<td class="minwidth100imp linecolproject">'.$langs->trans(
'Project').
'</td>';
2151 print
'<td class="center linecoltype">'.$langs->trans(
'Type').
'</td>';
2153 print
'<td class="center linecolcarcategory">'.$langs->trans(
'CarCategory').
'</td>';
2155 print
'<td class="linecoldescription">'.$langs->trans(
'Description').
'</td>';
2156 print
'<td class="right linecolvat">'.$langs->trans(
'VAT').
'</td>';
2157 print
'<td class="right linecolpriceuht">'.$langs->trans(
'PriceUHT').
'</td>';
2158 print
'<td class="right linecolpriceuttc">'.$langs->trans(
'PriceUTTC').
'</td>';
2159 print
'<td class="right linecolqty">'.$langs->trans(
'Qty').
'</td>';
2160 if ($action !=
'editline') {
2161 print
'<td class="right linecolamountht">'.$langs->trans(
'AmountHT').
'</td>';
2162 print
'<td class="right linecolamountttc">'.$langs->trans(
'AmountTTC').
'</td>';
2174 print
'<td class="right"></td>';
2178 foreach (
$object->lines as &$line) {
2181 if ($action !=
'editline' || $line->id !=
GETPOSTINT(
'rowid')) {
2182 print
'<tr class="oddeven linetr" data-id="'.$line->id.
'">';
2185 print
'<td class="center linecollinenb">';
2190 print
'<td class="center linecoldate">'.dol_print_date($db->jdate($line->date),
'day').
'</td>';
2194 print
'<td class="lineproject">';
2195 if ($line->fk_project > 0) {
2196 $projecttmp->id = $line->fk_project;
2197 $projecttmp->ref = $line->projet_ref;
2198 $projecttmp->title = $line->projet_title;
2199 print $projecttmp->getNomUrl(1);
2206 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
2208 $resaccountingaccount = $accountingaccount->fetch(0, $line->type_fees_accountancy_code, 1);
2210 $titlealt .= $langs->trans(
"AccountancyCode").
': ';
2211 if ($resaccountingaccount > 0) {
2212 $titlealt .= $accountingaccount->account_number;
2214 $titlealt .= $langs->trans(
"NotFound");
2220 print
'<td class="center linecoltype" title="'.dol_escape_htmltag($titlealt).
'">';
2221 $labeltype = ($langs->trans(($line->type_fees_code)) == $line->type_fees_code ? $line->type_fees_libelle : $langs->trans($line->type_fees_code));
2227 print
'<td class="fk_c_exp_tax_cat linecoltaxcat">';
2228 $exp_tax_cat_label =
dol_getIdFromCode($db, $line->fk_c_exp_tax_cat,
'c_exp_tax_cat',
'rowid',
'label');
2229 print $langs->trans($exp_tax_cat_label);
2234 print
'<td class="left linecolcomment minwidth100">'.dol_nl2br($line->comments).
'</td>';
2237 $senderissupplier = 0;
2238 $tooltiponprice =
'';
2239 $tooltiponpriceend =
'';
2241 $tooltiponprice = $langs->transcountry(
"TotalHT",
$mysoc->country_code).
'='.
price($line->total_ht);
2242 $tooltiponprice .=
'<br>'.$langs->transcountry(
"TotalVAT", ($senderissupplier ?
$object->thirdparty->country_code :
$mysoc->country_code)).
'='.
price($line->total_tva);
2243 if (is_object(
$object->thirdparty)) {
2244 if ($senderissupplier) {
2245 $seller =
$object->thirdparty;
2252 if (
$mysoc->useLocalTax(1)) {
2253 if (($seller->country_code == $buyer->country_code) || $line->total_localtax1 || $seller->useLocalTax(1)) {
2254 $tooltiponprice .=
'<br>'.$langs->transcountry(
"TotalLT1", $seller->country_code).
'='.
price($line->total_localtax1);
2256 $tooltiponprice .=
'<br>'.$langs->transcountry(
"TotalLT1", $seller->country_code).
'=<span class="opacitymedium">'.$langs->trans($senderissupplier ?
"NotUsedForThisVendor" :
"NotUsedForThisCustomer").
'</span>';
2259 if (
$mysoc->useLocalTax(2)) {
2260 if ((isset($seller->country_code) && isset($buyer->thirdparty->country_code) && $seller->country_code == $buyer->thirdparty->country_code) || $line->total_localtax2 || $seller->useLocalTax(2)) {
2261 $tooltiponprice .=
'<br>'.$langs->transcountry(
"TotalLT2", $seller->country_code).
'='.
price($line->total_localtax2);
2263 $tooltiponprice .=
'<br>'.$langs->transcountry(
"TotalLT2", $seller->country_code).
'=<span class="opacitymedium">'.$langs->trans($senderissupplier ?
"NotUsedForThisVendor" :
"NotUsedForThisCustomer").
'</span>';
2267 $tooltiponprice .=
'<br>'.$langs->transcountry(
"TotalTTC",
$mysoc->country_code).
'='.
price($line->total_ttc);
2269 $tooltiponprice =
'<span class="classfortooltip" title="'.dol_escape_htmltag($tooltiponprice).
'">';
2270 $tooltiponpriceend =
'</span>';
2273 print
'<td class="right linecolvatrate">';
2274 print $tooltiponprice;
2275 print
vatrate($line->vatrate.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
''), true);
2276 print $tooltiponpriceend;
2280 print
'<td class="right linecolunitht">';
2281 if (!empty($line->value_unit_ht)) {
2282 print
price($line->value_unit_ht);
2284 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $line->vatrate));
2285 $pricenettoshow =
price2num((
float) $line->value_unit / (1 + (
float) $tmpvat / 100),
'MU');
2286 print
price($pricenettoshow);
2290 print
'<td class="right linecolunitttc">'.price($line->value_unit).
'</td>';
2292 print
'<td class="right linecolqty">'.dol_escape_htmltag((
string) $line->qty).
'</td>';
2294 if ($action !=
'editline') {
2295 print
'<td class="right linecoltotalht">'.price($line->total_ht).
'</td>';
2296 print
'<td class="right linecoltotalttc">'.price($line->total_ttc).
'</td>';
2300 print
'<td class="center linecolpreview">';
2301 if ($line->fk_ecm_files > 0) {
2302 $modulepart =
'expensereport';
2303 $maxheightmini = 32;
2305 $result = $ecmfilesstatic->fetch($line->fk_ecm_files);
2307 $relativepath = preg_replace(
'/expensereport\//',
'', $ecmfilesstatic->filepath);
2308 $fileinfo = pathinfo($ecmfilesstatic->filepath.
'/'.$ecmfilesstatic->filename);
2311 if (!
dol_is_file(
$conf->expensereport->dir_output.
'/'.$relativepath.
'/'.$minifile)) {
2315 $urlforhref =
getAdvancedPreviewUrl($modulepart, $relativepath.
'/'.$fileinfo[
'filename'].
'.'.strtolower($fileinfo[
'extension']), 1,
'&entity='.(empty(
$object->entity) ?
$conf->entity :
$object->entity));
2316 if (empty($urlforhref)) {
2317 $urlforhref = DOL_URL_ROOT.
'/viewimage.php?modulepart='.$modulepart.
'&entity='.(empty(
$object->entity) ?
$conf->entity :
$object->entity).
'&file='.urlencode($relativepath.$fileinfo[
'filename'].
'.'.strtolower($fileinfo[
'extension']));
2318 print
'<a href="'.$urlforhref.
'" class="aphoto" target="_blank" rel="noopener noreferrer">';
2320 print
'<a href="'.$urlforhref[
'url'].
'" class="'.$urlforhref[
'css'].
'" target="'.$urlforhref[
'target'].
'" mime="'.$urlforhref[
'mime'].
'">';
2322 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="">';
2325 if (preg_match(
'/\.pdf$/i', $ecmfilesstatic->filename)) {
2326 $filepdf =
$conf->expensereport->dir_output.
'/'.$relativepath.
'/'.$ecmfilesstatic->filename;
2327 $fileimage =
$conf->expensereport->dir_output.
'/'.$relativepath.
'/'.$ecmfilesstatic->filename.
'_preview.png';
2328 $relativepathimage = $relativepath.
'/'.$ecmfilesstatic->filename.
'_preview.png';
2330 $pdfexists = file_exists($filepdf);
2333 if (!file_exists($fileimage) || (filemtime($fileimage) < filemtime($filepdf))) {
2335 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2344 if ($pdfexists && !$error) {
2345 $heightforphotref = 70;
2346 if (!empty(
$conf->dol_optimize_smallscreen)) {
2347 $heightforphotref = 60;
2349 $urlforhref =
getAdvancedPreviewUrl($modulepart, $relativepath.
'/'.$fileinfo[
'filename'].
'.'.strtolower($fileinfo[
'extension']), 1,
'&entity='.(empty(
$object->entity) ?
$conf->entity :
$object->entity));
2350 print
'<a href="'.$urlforhref[
'url'].
'" class="'.$urlforhref[
'css'].
'" target="'.$urlforhref[
'target'].
'" mime="'.$urlforhref[
'mime'].
'">';
2352 if (file_exists($fileimage)) {
2353 print
'<img height="'.$heightforphotref.
'" class="photo photowithmargin photowithborder" src="'.DOL_URL_ROOT.
'/viewimage.php?modulepart=apercu'.$modulepart.
'&file='.urlencode($relativepathimage).
'">';
2356 print
img_mime($ecmfilesstatic->filename);
2366 print
'<td class="nowrap right linecolwarning">';
2367 print !empty($line->rule_warning_message) ? img_warning(html_entity_decode($line->rule_warning_message)) :
'';
2372 print
'<td class="nowrap right linecolaction">';
2374 print
'<a class="editfielda reposition paddingrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=editline&token='.
newToken().
'&rowid='.$line->rowid.
'">';
2376 print
'</a> ';
2377 print
'<a class="paddingrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=delete_line&token='.
newToken().
'&rowid='.$line->rowid.
'">';
2387 if ($action ==
'editline' && $line->id ==
GETPOSTINT(
'rowid')) {
2397 print
'<!-- line of expense report -->'.
"\n";
2398 print
'<tr class="tredited">';
2400 print
'<td class="center">';
2404 print
'<td colspan="'.($colspan - 1).
'" class="liste_titre"> ';
2405 print
'<a href="" class="commonlink auploadnewfilenow reposition">'.$langs->trans(
"UploadANewFileNow");
2406 print img_picto($langs->trans(
"UploadANewFileNow"),
'chevron-down',
'', 0, 0, 0,
'',
'marginleftonly');
2409 print
' - <a href="" class="commonlink aattachtodoc reposition">'.$langs->trans(
"AttachTheNewLineToTheDocument");
2410 print img_picto($langs->trans(
"AttachTheNewLineToTheDocument"),
'chevron-down',
'', 0, 0, 0,
'',
'marginleftonly');
2414 print
'<!-- Code to open/close section to submit or link files in edit mode -->'.
"\n";
2415 print
'<script type="text/javascript">'.
"\n";
2416 print
'$(document).ready(function() {
2417 $( ".auploadnewfilenow" ).click(function() {
2418 jQuery(".truploadnewfilenow").toggle();
2419 jQuery(".trattachnewfilenow").hide();
2422 $( ".aattachtodoc" ).click(function() {
2423 jQuery(".trattachnewfilenow").toggle();
2424 jQuery(".truploadnewfilenow").hide();
2427 if (is_array(
GETPOST(
'attachfile',
'array')) && count(
GETPOST(
'attachfile',
'array'))) {
2428 print
'jQuery(".trattachnewfilenow").toggle();'.
"\n";
2431 jQuery("form[name=\"expensereport\"]").submit(function() {
2432 if (jQuery(".truploadnewfilenow").is(":hidden")) {
2433 jQuery("input[name=\"sendit\"]").val("");
2440 print
'</script>'.
"\n";
2443 $filenamelinked =
'';
2444 if ($line->fk_ecm_files > 0) {
2445 $result = $ecmfilesstatic->fetch($line->fk_ecm_files);
2447 $filenamelinked = $ecmfilesstatic->filename;
2451 $tredited =
'tredited';
2452 include DOL_DOCUMENT_ROOT.
'/expensereport/tpl/expensereport_addfile.tpl.php';
2453 include DOL_DOCUMENT_ROOT.
'/expensereport/tpl/expensereport_linktofile.tpl.php';
2455 print
'<tr class="oddeven tredited">';
2460 print
'<td class="center">';
2461 print $form->selectDate($line->date,
'date');
2466 print
'<td class="nowraponall">';
2467 print $formproject->select_projects(-1, (
string) $line->fk_project,
'fk_project', 0, 0, $projectRequired ? 0 : 1, 1, 0, 0, 0,
'', 1, 0,
'maxwidth300');
2472 print
'<td class="center">';
2473 print $formexpensereport->selectTypeExpenseReport($line->fk_c_type_fees,
'fk_c_type_fees');
2477 print
'<td class="fk_c_exp_tax_cat">';
2478 $params = array(
'fk_expense' =>
$object->id,
'fk_expense_det' => $line->id,
'date' => $line->date);
2479 print $form->selectExpenseCategories((
string) $line->fk_c_exp_tax_cat,
'fk_c_exp_tax_cat', 1, array(),
'fk_c_type_fees', (
int) $userauthor->default_c_exp_tax_cat, $params);
2485 print
'<textarea name="comments" class="flat_ndf centpercent">'.dol_escape_htmltag($line->comments, 0, 1).
'</textarea>';
2489 $selectedvat =
price2num($line->vatrate).(!empty($line->vat_src_code) ?
' ('.$line->vat_src_code.
')' :
'');
2490 print
'<td class="right">';
2492 print $form->load_tva(
'vatrate', (
GETPOSTISSET(
"vatrate") ?
GETPOST(
"vatrate") : $selectedvat), null, null, 0, 0,
'', false, 1, 2);
2496 print
'<td class="right">';
2497 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.
' />';
2501 print
'<td class="right">';
2502 print
'<input type="text" min="0" class="right maxwidth50" id="value_unit" name="value_unit" value="'.dol_escape_htmltag(
price2num($line->value_unit)).
'" />';
2506 print
'<td class="right">';
2507 print
'<input type="text" min="0" class="input_qty right maxwidth50" name="qty" value="'.dol_escape_htmltag((
string) $line->qty).
'" />';
2514 print
'<td class="center">';
2518 print
'<td class="center">';
2522 print
'<input type="hidden" name="rowid" value="'.$line->rowid.
'">';
2523 print $form->buttonsSaveCancel(
'Save',
'Cancel', array(),
false,
'small');
2542 if ($action !=
'editline') {
2546 $nbFiles = $nbLinks = 0;
2547 $arrayoffiles = array();
2549 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2550 require_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
2551 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
2554 $nbFiles = count($arrayoffiles);
2559 print
'<tr class="liste_titre">';
2560 print
'<td colspan="'.$colspan.
'" class="liste_titre expensereportautoload">';
2561 print
'<a href="" class="commonlink auploadnewfilenow reposition">'.$langs->trans(
"UploadANewFileNow");
2562 print img_picto($langs->trans(
"UploadANewFileNow"),
'chevron-down',
'', 0, 0, 0,
'',
'marginleftonly');
2565 print
' - <a href="" class="commonlink aattachtodoc reposition">'.$langs->trans(
"AttachTheNewLineToTheDocument");
2566 print img_picto($langs->trans(
"AttachTheNewLineToTheDocument"),
'chevron-down',
'', 0, 0, 0,
'',
'marginleftonly');
2570 print
'<!-- Code to open/close section to submit or link files in the form to add new line -->'.
"\n";
2571 print
'<script type="text/javascript">'.
"\n";
2572 print
'$(document).ready(function() {
2573 $( ".auploadnewfilenow" ).click(function() {
2574 console.log("We click on toggle of auploadnewfilenow");
2575 jQuery(".truploadnewfilenow").toggle();
2576 jQuery(".trattachnewfilenow").hide();
2577 if (jQuery(".truploadnewfilenow").is(":hidden")) {
2578 jQuery("input[name=\"sendit\"]").prop("name", "senditdisabled");
2580 jQuery("input[name=\"senditdisabled\"]").prop("name", "sendit");
2582 // TODO Switch css fa-chevron-dow and add fa-chevron-up
2585 $( ".aattachtodoc" ).click(function() {
2586 console.log("We click on toggle of aattachtodoc");
2587 jQuery(".trattachnewfilenow").toggle();
2588 jQuery(".truploadnewfilenow").hide();
2589 // TODO Switch css fa-chevron-dow and add fa-chevron-up
2592 if (is_array(
GETPOST(
'attachfile',
'array')) && count(
GETPOST(
'attachfile',
'array')) && $action !=
'updateline') {
2593 print
'jQuery(".trattachnewfilenow").show();'.
"\n";
2596 jQuery("form[name=\"expensereport\"]").submit(function() {
2597 if (jQuery(".truploadnewfilenow").is(":hidden")) {
2598 /* 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. */
2599 jQuery("input[name=\"sendit\"]").val("");
2600 jQuery("input[name=\"sendit\"]").prop("name", "senditdisabled");
2602 jQuery("input[name=\"senditdisabled\"]").prop("name", "sendit");
2609 print
'</script>'.
"\n";
2613 include DOL_DOCUMENT_ROOT.
'/expensereport/tpl/expensereport_linktofile.tpl.php';
2614 include DOL_DOCUMENT_ROOT.
'/expensereport/tpl/expensereport_addfile.tpl.php';
2616 print
'<tr class="liste_titre expensereportcreate">';
2618 print
'<td class="center expensereportcreatedate">'.$langs->trans(
'Date').
'</td>';
2620 print
'<td class="minwidth100imp">'.$form->textwithpicto($langs->trans(
'Project'), $langs->trans(
"ClosedProjectsAreHidden")).
'</td>';
2622 print
'<td class="center expensereportcreatetype">'.$langs->trans(
'Type').
'</td>';
2624 print
'<td>'.$langs->trans(
'CarCategory').
'</td>';
2626 print
'<td class="expensereportcreatedescription">'.$langs->trans(
'Description').
'</td>';
2627 print
'<td class="right expensereportcreatevat">'.$langs->trans(
'VAT').
'</td>';
2628 print
'<td class="right expensereportcreatepriceuth">'.$langs->trans(
'PriceUHT').
'</td>';
2629 print
'<td class="right expensereportcreatepricettc">'.$langs->trans(
'PriceUTTC').
'</td>';
2630 print
'<td class="right expensereportcreateqty">'.$langs->trans(
'Qty').
'</td>';
2637 print
'<tr class="oddeven nohover">';
2643 print
'<td class="center inputdate">';
2644 print $form->selectDate(!empty($date) ? $date : -1,
'date', 0, 0, 0,
'', 1, 1);
2649 print
'<td class="inputproject">';
2650 $formproject->select_projects(-1, !empty($fk_project) ? (
string) $fk_project :
'0',
'fk_project', 0, 0, $projectRequired ? 0 : 1, -1, 0, 0, 0,
'', 0, 0,
'maxwidth300');
2655 print
'<td class="center inputtype">';
2656 print $formexpensereport->selectTypeExpenseReport(!empty($fk_c_type_fees) ? $fk_c_type_fees :
"",
'fk_c_type_fees', 1);
2660 print
'<td class="fk_c_exp_tax_cat">';
2661 $params = array(
'fk_expense' =>
$object->id);
2662 print $form->selectExpenseCategories(
'',
'fk_c_exp_tax_cat', 1, array(),
'fk_c_type_fees', $userauthor->default_c_exp_tax_cat, $params, 0);
2667 print
'<td class="inputcomment">';
2668 print
'<textarea class="flat_ndf centpercent" name="comments" rows="'.ROWS_2.
'">'.
dol_escape_htmltag(!empty($comments) ? $comments :
"", 0, 1).
'</textarea>';
2672 print
'<td class="right inputvat">';
2676 $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS =
'none';
2679 print $form->load_tva(
'vatrate', (!empty($vatrate) ? $vatrate : $defaultvat), null, null, 0, 0,
'', false, 1);
2683 print
'<td class="right inputpricenet">';
2684 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.
' />';
2688 print
'<td class="right inputtax">';
2689 print
'<input type="text" class="right maxwidth50" id="value_unit" name="value_unit" value="'.dol_escape_htmltag((!empty($value_unit) ? $value_unit :
"")).
'">';
2693 print
'<td class="right inputqty">';
2694 print
'<input type="text" min="0" class=" input_qty right maxwidth50" name="qty" value="'.dol_escape_htmltag(!empty($qty) ? $qty : 1).
'">';
2700 if ($action !=
'editline') {
2701 print
'<td class="right"></td>';
2702 print
'<td class="right"></td>';
2706 print
'<td class="center inputbuttons">';
2707 print $form->buttonsSaveCancel(
"Add",
'', array(),
true,
'reposition');
2718 /* JQuery for product free or predefined select */
2719 jQuery(document).ready(function() {
2720 jQuery("#value_unit_ht").keyup(function(event) {
2721 console.log(event.which); // discard event tag and arrows
2722 if (event.which != 9 && (event.which < 37 ||event.which > 40) && jQuery("#value_unit_ht").val() != "") {
2723 jQuery("#value_unit").val("");
2726 jQuery("#value_unit").keyup(function(event) {
2727 console.log(event.which); // discard event tag and arrows
2728 if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#value_unit").val() != "") {
2729 jQuery("#value_unit_ht").val("");
2737 /* unit price coef calculation */
2738 jQuery(".input_qty, #fk_c_type_fees, #select_fk_c_exp_tax_cat, #vatrate ").change(function(event) {
2739 console.log("We change a parameter");
2741 let type_fee = jQuery("#fk_c_type_fees").find(":selected").val();
2742 let tax_cat = jQuery("#select_fk_c_exp_tax_cat").find(":selected").val();
2743 let tva = jQuery("#vatrate").find(":selected").val();
2744 let qty = jQuery(".input_qty").val();
2746 let path = "'.DOL_URL_ROOT.
'/expensereport/ajax/ajaxik.php";
2747 path += "?fk_c_exp_tax_cat="+tax_cat;
2748 path += "&fk_expense="+'.((int)
$object->id).
';
2749 path += "&vatrate="+tva;
2750 path += "&qty="+qty;
2752 if (type_fee == 4) { // mileage expenses
2753 if (tax_cat == "" || parseInt(tax_cat) <= 0){
2761 success: function(response) {
2762 if (response.response_status == "success"){';
2766 jQuery("#value_unit").val(parseFloat(response.data) * (100 + parseFloat(tva)) / 100);
2767 jQuery("#value_unit").trigger("change");
2771 jQuery("#value_unit_ht").val(response.data);
2772 jQuery("#value_unit_ht").trigger("change");
2773 jQuery("#value_unit").val("");
2778 } else if(response.response_status == "error" && response.errorMessage != undefined && response.errorMessage.length > 0 ) {
2779 console.log("We get an error result");
2780 $.jnotify(response.errorMessage, "error", {timeout: 0, type: "error"},{ remove: function (){} } );
2786 /*console.log(event.which); // discard event tag and arrows
2787 if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#value_unit").val() != "") {
2788 jQuery("#value_unit_ht").val("");
2805 dol_print_error($db);
2808 print
'Record not found';
2819print
'<div class="tabsAction">';
2821if ($action !=
'create' && $action !=
'edit' && $action !=
'editline') {
2826 if (empty($user->socid)) {
2828 print dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email',
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'id' =>
$object->id,
'action' =>
'presend',
'mode' =>
'init'],
true).
'#formmailbeforetitle',
'');
2838 if (in_array(
$object->fk_user_author, $childids) || $user->hasRight(
'expensereport',
'writeall_advance')) {
2840 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>';
2843 if (count(
$object->lines) > 0) {
2844 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>';
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=edit&token='.
newToken().
'&id='.
$object->id.
'">'.$langs->trans(
'Modify').
'</a></div>';
2859 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>';
2864 if ($user->id ==
$object->fk_user_author || $user->id ==
$object->fk_user_valid) {
2866 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>';
2876 if (in_array(
$object->fk_user_author, $childids)) {
2878 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>';
2886 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>';
2888 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>';
2891 if ($user->id ==
$object->fk_user_author || $user->id ==
$object->fk_user_valid) {
2893 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>';
2902 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>';
2908 if ($remaintopay == 0) {
2909 print
'<div class="inline-block divButAction"><span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPayment').
'</span></div>';
2911 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>';
2919 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>";
2925 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>';
2934 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>';
2939 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>';
2943 if ($user->hasRight(
'expensereport',
'creer')) {
2944 print
'<div class="inline-block divButAction">'.dolGetButtonAction($langs->trans(
"ToClone"), $langs->trans(
"ToClone"),
'clone', $_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=clone&token='.
newToken(),
'',
true, array(
'attr' => array(
'class' =>
'reposition'))).
'</div>';
2950 print
'<div class="inline-block divButAction">'.dolGetButtonAction($langs->trans(
'Delete'), $langs->trans(
'Delete'),
'delete', $_SERVER[
"PHP_SELF"].
'?action=delete&token='.
newToken().
'&id='.
$object->id,
'',
true, array(
'attr' => array(
'class' =>
'reposition'))).
'</div>'.
"\n";
2953 print
'<div class="inline-block divButAction">'.dolGetButtonAction($langs->trans(
'Delete'), $langs->trans(
'Delete'),
'delete', $_SERVER[
"PHP_SELF"].
'?action=delete&token='.
newToken().
'&id='.
$object->id,
'',
true, array(
'attr' => array(
'class' =>
'reposition'))).
'</div>'.
"\n";
2956 $parameters = array();
2957 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
2964if (
GETPOST(
'modelselected',
'alpha')) {
2965 $action =
'presend';
2968if ($action !=
'presend') {
2973 print
'<div class="fichecenter"><div class="fichehalfleft">';
2974 print
'<a name="builddoc"></a>';
2976 if ($user->hasRight(
'expensereport',
'creer') && $action !=
'create' && $action !=
'edit') {
2979 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".
$object->id;
2980 $genallowed = $user->hasRight(
'expensereport',
'creer');
2981 $delallowed = $user->hasRight(
'expensereport',
'creer');
2983 print $formfile->showdocuments(
'expensereport', $filename, $filedir, $urlsource, $genallowed, $delallowed);
2984 $somethingshown = $formfile->numoffiles;
3000 print
'</div><div class="fichehalfright">';
3002 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
3004 $somethingshown = $formactions->showactions($object,
'expensereport', 0);
3006 print
'</div></div>';
3010$modelmail =
'expensereport_send';
3011$defaulttopic =
'SendExpenseReportRef';
3012$diroutput =
$conf->expensereport->dir_output;
3013$trackid =
'exp'.$object->id;
3015include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
global $dolibarr_main_url_root
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 a PDF file 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.
$date_start
Variables from include:
dol_now($mode='gmt')
Return date for now.
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.
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.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
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.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
img_mime($file, $titlealt='', $morecss='')
Show MIME img of a file.
getAdvancedPreviewUrl($modulepart, $relativepath, $alldata=0, $param='')
Return URL we can use for advanced preview links.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
image_format_supported($file, $acceptsvg=0)
Return if a filename is file name of a supported image format.
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as date
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
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.