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';
54$langs->loadLangs(array(
"trips",
"bills",
"mails"));
56$action =
GETPOST(
'action',
'aZ09');
57$cancel =
GETPOST(
'cancel',
'alpha');
58$confirm =
GETPOST(
'confirm',
'alpha');
59$backtopage =
GETPOST(
'backtopage',
'alpha');
66$vatrate =
GETPOST(
'vatrate',
'alpha');
68$comments =
GETPOST(
'comments',
'restricthtml');
73$childids = $user->getAllChildIds(1);
76 if (empty($date_start)) {
80 if (empty($date_end)) {
87$rootfordata = DOL_DATA_ROOT;
88$rootforuser = DOL_DATA_ROOT;
90if (isModEnabled(
'multicompany') && !empty($conf->entity) && $conf->entity > 1) {
91 $rootfordata .=
'/'.$conf->entity;
93$conf->expensereport->dir_output = $rootfordata.
'/expensereport';
96$urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
97$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
110$extrafields->fetch_name_optionals_label(
$object->table_element);
113include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
116$hookmanager->initHooks(array(
'expensereportcard',
'globalcard'));
118$permissionnote = $user->hasRight(
'expensereport',
'creer');
119$permissiondellink = $user->hasRight(
'expensereport',
'creer');
120$permissiontoadd = $user->hasRight(
'expensereport',
'creer');
124$projectRequired = isModEnabled(
'project') &&
getDolGlobalString(
'EXPENSEREPORT_PROJECT_IS_REQUIRED');
130 if ($user->hasRight(
'expensereport',
'readall')) {
133 if ($user->hasRight(
'expensereport',
'lire') && in_array(
$object->fk_user_author, $childids)) {
142if ($user->hasRight(
'expensereport',
'supprimer')) {
151 $socid = $user->socid;
155$permissiontoadd = $user->hasRight(
'expensereport',
'creer');
165$parameters = array(
'socid' => $socid);
166$reshook = $hookmanager->executeHooks(
'doActions', $parameters,
$object, $action);
171if (empty($reshook)) {
172 $backurlforlist = DOL_URL_ROOT.
'/expensereport/list.php';
174 if (empty($backtopage) || ($cancel && empty($id))) {
175 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
176 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
177 $backtopage = $backurlforlist;
179 $backtopage = DOL_URL_ROOT.
'/expensereport/card.php?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
185 if (!empty($backtopageforcancel)) {
186 header(
"Location: ".$backtopageforcancel);
188 } elseif (!empty($backtopage)) {
189 header(
"Location: ".$backtopage);
203 $fk_c_type_fees = -1;
206 include DOL_DOCUMENT_ROOT.
'/core/actions_linkedfiles.inc.php';
208 if (!empty(
GETPOST(
'sendit',
'alpha'))) {
209 if ($action ==
'updateline') {
210 $action =
'editline';
216 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
218 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
220 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
223 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $user->hasRight(
'expensereport',
'creer')) {
224 if (1 == 0 && !
GETPOST(
'clone_content',
'alpha') && !
GETPOST(
'clone_receivers',
'alpha')) {
233 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
244 if ($action ==
'confirm_delete' &&
GETPOST(
"confirm",
'alpha') ==
"yes" && $id > 0 && $candelete) {
247 $result =
$object->delete($user);
249 header(
"Location: index.php");
256 if ($action ==
'add' && $user->hasRight(
'expensereport',
'creer')) {
261 $object->date_debut = $date_start;
265 if (!(
$object->fk_user_author > 0)) {
266 $object->fk_user_author = $user->id;
270 if ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'expensereport',
'creer'))
271 || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'expensereport',
'creer') && !$user->hasRight(
'expensereport',
'writeall_advance'))) {
276 if (!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') || !$user->hasRight(
'expensereport',
'writeall_advance')) {
277 if (!in_array(
$object->fk_user_author, $childids)) {
284 $fuser =
new User($db);
285 $fuser->fetch(
$object->fk_user_author);
294 $ret = $extrafields->setOptionalsFromPost(
null,
$object);
301 $overlappingExpenseReportID =
$object->periode_existe($fuser,
$object->date_debut,
$object->date_fin);
303 if ($overlappingExpenseReportID > 0) {
305 setEventMessages($langs->trans(
"ErrorDoubleDeclaration").
' <a href="'.$_SERVER[
'PHP_SELF'].
'?id='.$overlappingExpenseReportID.
'">'. $langs->trans(
'ShowTrip').
'</a>',
null,
'errors');
320 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
330 if (($action ==
'update' || $action ==
'updateFromRefuse') && $user->hasRight(
'expensereport',
'creer')) {
334 $object->date_debut = $date_start;
344 $object->fk_user_modif = $user->id;
346 $result =
$object->update($user);
348 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
GETPOSTINT(
'id'));
355 if ($action ==
'update_extras' && $user->hasRight(
'expensereport',
'creer')) {
359 $ret = $extrafields->setOptionalsFromPost(
null,
$object,
GETPOST(
'attribute',
'restricthtml'));
366 $result =
$object->insertExtraFields(
'EXPENSEREPORT_MODIFY');
374 $action =
'edit_extras';
378 if ($action ==
"confirm_validate" &&
GETPOST(
"confirm",
'alpha') ==
"yes" && $id > 0 && $user->hasRight(
'expensereport',
'creer')) {
386 $result =
$object->setValidate($user);
391 $outputlangs = $langs;
394 $newlang =
GETPOST(
'lang_id',
'aZ09');
397 $user =
new User($db);
398 $user->fetch(
$object->fk_user_author);
399 $newlang = $user->lang;
401 if (!empty($newlang)) {
403 $outputlangs->setDefaultLang($newlang);
408 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
415 if (!$error && $result > 0 &&
$object->fk_user_validator > 0) {
416 $langs->load(
"mails");
419 $destinataire =
new User($db);
420 $destinataire->fetch(
$object->fk_user_validator);
421 $emailTo = $destinataire->email;
424 $expediteur =
new User($db);
425 $expediteur->fetch(
$object->fk_user_author);
428 if ($emailTo && $emailFrom) {
439 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportWaitingForApproval");
442 $link = $urlwithroot.
'/expensereport/card.php?id='.
$object->id;
443 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
444 $message = $langs->transnoentities(
"ExpenseReportWaitingForApprovalMessage", $expediteur->getFullName($langs),
get_date_range(
$object->date_debut,
$object->date_fin,
'', $langs), $link);
459 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
463 $result = $mailfile->sendfile();
465 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
468 $langs->load(
"other");
469 if (!empty($mailfile->error) || !empty($mailfile->errors)) {
472 if (!empty($mailfile->error)) {
473 $mesg .=
'<br>' . $mailfile->error;
475 if (!empty($mailfile->errors) && is_array($mailfile->errors)) {
476 $mesg .=
'<br>' . implode(
'<br>', $mailfile->errors);
480 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
488 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
495 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
502 if ($action ==
"confirm_save_from_refuse" &&
GETPOST(
"confirm",
'alpha') ==
"yes" && $id > 0 && $user->hasRight(
'expensereport',
'creer')) {
505 $result =
$object->set_save_from_refuse($user);
510 $outputlangs = $langs;
513 $newlang =
GETPOST(
'lang_id',
'aZ09');
516 $user =
new User($db);
517 $user->fetch(
$object->fk_user_author);
518 $newlang = $user->lang;
520 if (!empty($newlang)) {
522 $outputlangs->setDefaultLang($newlang);
527 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
535 $destinataire =
new User($db);
536 $destinataire->fetch(
$object->fk_user_validator);
537 $emailTo = $destinataire->email;
540 $expediteur =
new User($db);
541 $expediteur->fetch(
$object->fk_user_author);
544 if ($emailFrom && $emailTo) {
555 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportWaitingForReApproval");
558 $link = $urlwithroot.
'/expensereport/card.php?id='.
$object->id;
559 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
579 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
583 $result = $mailfile->sendfile();
585 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
587 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
590 $langs->load(
"other");
591 if ($mailfile->error) {
593 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
594 $mesg .=
'<br>'.$mailfile->error;
597 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
605 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
614 if ($action ==
"confirm_approve" &&
GETPOST(
"confirm",
'alpha') ==
"yes" && $id > 0 && $user->hasRight(
'expensereport',
'approve')) {
618 $result =
$object->setApproved($user);
623 $outputlangs = $langs;
626 $newlang =
GETPOST(
'lang_id',
'aZ09');
629 $user =
new User($db);
630 $user->fetch(
$object->fk_user_author);
631 $newlang = $user->lang;
633 if (!empty($newlang)) {
635 $outputlangs->setDefaultLang($newlang);
640 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
648 $destinataire =
new User($db);
649 $destinataire->fetch(
$object->fk_user_author);
650 $emailTo = $destinataire->email;
654 if (empty($emailTo)) {
659 $expediteur =
new User($db);
660 $expediteur->fetch(
$object->fk_user_approve > 0 ?
$object->fk_user_approve :
$object->fk_user_validator);
663 if ($emailFrom && $emailTo) {
674 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportApproved");
677 $link = $urlwithroot.
'/expensereport/card.php?id='.
$object->id;
678 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
679 $message = $langs->transnoentities(
"ExpenseReportApprovedMessage",
$object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $link);
696 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, $emailCC,
'', 0, -1);
700 $result = $mailfile->sendfile();
702 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
704 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
707 $langs->load(
"other");
708 if ($mailfile->error) {
710 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
711 $mesg .=
'<br>'.$mailfile->error;
714 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
722 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
731 if ($action ==
"confirm_refuse" &&
GETPOST(
'confirm',
'alpha') ==
"yes" && $id > 0 && $user->hasRight(
'expensereport',
'approve')) {
735 $detailRefuse =
GETPOST(
'detail_refuse',
'alpha');
736 $result =
$object->setDeny($user, $detailRefuse);
741 $outputlangs = $langs;
744 $newlang =
GETPOST(
'lang_id',
'aZ09');
747 $user =
new User($db);
748 $user->fetch(
$object->fk_user_author);
749 $newlang = $user->lang;
751 if (!empty($newlang)) {
753 $outputlangs->setDefaultLang($newlang);
758 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
766 $destinataire =
new User($db);
767 $destinataire->fetch(
$object->fk_user_author);
768 $emailTo = $destinataire->email;
771 $expediteur =
new User($db);
772 $expediteur->fetch(
$object->fk_user_refuse);
775 if ($emailFrom && $emailTo) {
786 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportRefused");
789 $link = $urlwithroot.
'/expensereport/card.php?id='.
$object->id;
790 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
791 $message = $langs->transnoentities(
"ExpenseReportRefusedMessage",
$object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $detailRefuse, $link);
809 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
813 $result = $mailfile->sendfile();
815 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
817 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
820 $langs->load(
"other");
821 if ($mailfile->error) {
823 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
824 $mesg .=
'<br>'.$mailfile->error;
827 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
835 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
845 if ($action ==
"confirm_cancel" &&
GETPOST(
'confirm',
'alpha') ==
"yes" && $id > 0 && $user->hasRight(
'expensereport',
'creer')) {
846 if (!
GETPOST(
'detail_cancel',
'alpha')) {
847 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Comment")),
null,
'errors');
852 if ($user->id ==
$object->fk_user_valid || $user->id ==
$object->fk_user_author) {
853 $detailCancel =
GETPOST(
'detail_cancel',
'alpha');
854 $result =
$object->set_cancel($user, $detailCancel);
859 $outputlangs = $langs;
862 $newlang =
GETPOST(
'lang_id',
'aZ09');
865 $user =
new User($db);
866 $user->fetch(
$object->fk_user_author);
867 $newlang = $user->lang;
869 if (!empty($newlang)) {
871 $outputlangs->setDefaultLang($newlang);
876 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
884 $destinataire =
new User($db);
885 $destinataire->fetch(
$object->fk_user_author);
886 $emailTo = $destinataire->email;
889 $expediteur =
new User($db);
890 $expediteur->fetch(
$object->fk_user_cancel);
893 if ($emailFrom && $emailTo) {
904 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportCanceled");
907 $link = $urlwithroot.
'/expensereport/card.php?id='.
$object->id;
908 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
909 $message = $langs->transnoentities(
"ExpenseReportCanceledMessage",
$object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $detailCancel, $link);
927 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
931 $result = $mailfile->sendfile();
933 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
935 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
938 $langs->load(
"other");
939 if ($mailfile->error) {
941 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
942 $mesg .=
'<br>'.$mailfile->error;
945 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
953 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
966 if ($action ==
"confirm_setdraft" &&
GETPOST(
'confirm',
'alpha') ==
"yes" && $id > 0 && $user->hasRight(
'expensereport',
'creer')) {
969 if ($user->id ==
$object->fk_user_author || $user->id ==
$object->fk_user_valid || in_array(
$object->fk_user_author, $childids)) {
970 $result =
$object->setStatut(0);
975 $outputlangs = $langs;
978 $newlang =
GETPOST(
'lang_id',
'aZ09');
981 $user =
new User($db);
982 $user->fetch(
$object->fk_user_author);
983 $newlang = $user->lang;
985 if (!empty($newlang)) {
987 $outputlangs->setDefaultLang($newlang);
992 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
997 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
1007 if ($action ==
'set_unpaid' && $id > 0 && $user->hasRight(
'expensereport',
'to_paid')) {
1011 $result =
$object->setUnpaid($user);
1016 $outputlangs = $langs;
1019 $newlang =
GETPOST(
'lang_id',
'aZ09');
1022 $user =
new User($db);
1023 $user->fetch(
$object->fk_user_author);
1024 $newlang = $user->lang;
1026 if (!empty($newlang)) {
1027 $outputlangs =
new Translate(
"", $conf);
1028 $outputlangs->setDefaultLang($newlang);
1033 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1038 if ($action ==
'set_paid' && $id > 0 && $user->hasRight(
'expensereport',
'to_paid')) {
1042 $result =
$object->setPaid($id, $user);
1047 $outputlangs = $langs;
1050 $newlang =
GETPOST(
'lang_id',
'aZ09');
1053 $user =
new User($db);
1054 $user->fetch(
$object->fk_user_author);
1055 $newlang = $user->lang;
1057 if (!empty($newlang)) {
1058 $outputlangs =
new Translate(
"", $conf);
1059 $outputlangs->setDefaultLang($newlang);
1064 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1072 $destinataire =
new User($db);
1073 $destinataire->fetch(
$object->fk_user_author);
1074 $emailTo = $destinataire->email;
1077 $expediteur =
new User($db);
1078 $expediteur->fetch($user->id);
1081 if ($emailFrom && $emailTo) {
1082 $filename = array();
1084 $mimetype = array();
1092 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportPaid");
1095 $link = $urlwithroot.
'/expensereport/card.php?id='.
$object->id;
1096 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
1097 $message = $langs->transnoentities(
"ExpenseReportPaidMessage",
$object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $link);
1100 $object->setDocModel($user,
"");
1101 $resultPDF = expensereport_pdf_create($db,
$object,
'',
"", $langs);
1104 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
1108 $result = $mailfile->sendfile();
1110 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
1112 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
1115 $langs->load(
"other");
1116 if ($mailfile->error) {
1118 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
1119 $mesg .=
'<br>'.$mailfile->error;
1122 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
1130 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
1139 if ($action ==
"addline" && $user->hasRight(
'expensereport',
'creer')) {
1144 if (GETPOSTISSET(
'attachfile')) {
1145 $arrayoffiles =
GETPOST(
'attachfile',
'array');
1146 if (is_array($arrayoffiles) && !empty($arrayoffiles[0])) {
1147 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1148 $entityprefix = ($conf->entity !=
'1') ? $conf->entity.
'/' :
'';
1149 $relativepath =
'expensereport/'.$object->ref.
'/'.$arrayoffiles[0];
1151 $ecmfiles->fetch(0,
'', $relativepath);
1152 $fk_ecm_files = $ecmfiles->id;
1157 if (empty($vatrate)) {
1160 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $vatrate));
1164 if (empty($value_unit)) {
1165 $value_unit =
price2num((
float) $value_unit_ht + ((
float) $value_unit_ht * (
float) $tmpvat / 100),
'MU');
1168 $fk_c_exp_tax_cat =
GETPOSTINT(
'fk_c_exp_tax_cat');
1175 if (!($fk_c_type_fees > 0)) {
1177 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1181 if ((
float) $tmpvat < 0 || $tmpvat ===
'') {
1183 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"VAT")),
null,
'errors');
1188 if (empty($date) || $date ==
"--") {
1190 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1191 } elseif ($date < $object->date_debut || $date > (
$object->date_fin + (24 * 3600 - 1))) {
1197 $langs->load(
"errors");
1198 $type = $error > 0 ?
'errors' :
'warnings';
1199 setEventMessages($langs->trans(
"WarningDateOfLineMustBeInExpenseReportRange"),
null, $type);
1203 if ($value_unit == 0) {
1205 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"PriceUTTC")),
null,
'errors');
1209 if ($projectRequired && $fk_project <= 0) {
1211 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Project")),
null,
'errors');
1215 if ($fileRequired && $fk_ecm_files == 0) {
1217 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"File")),
null,
'errors');
1224 $result =
$object->addline($qty, $value_unit, $fk_c_type_fees, $vatrate, $date, $comments, $fk_project, $fk_c_exp_tax_cat, $type, $fk_ecm_files);
1230 $outputlangs = $langs;
1231 $newlang =
GETPOST(
'lang_id',
'alpha');
1233 $user =
new User($db);
1234 $user->fetch(
$object->fk_user_author);
1235 $newlang = $user->lang;
1237 if (!empty($newlang)) {
1238 $outputlangs =
new Translate(
"", $conf);
1239 $outputlangs->setDefaultLang($newlang);
1242 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1246 unset($value_unit_ht);
1250 unset($fk_c_type_fees);
1261 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
GETPOSTINT(
'id'));
1268 if ($action ==
'confirm_delete_line' &&
GETPOST(
"confirm",
'alpha') ==
"yes" && $user->hasRight(
'expensereport',
'creer')) {
1274 $total_ht = $object_ligne->total_ht;
1275 $total_tva = $object_ligne->total_tva;
1282 $outputlangs = $langs;
1285 $newlang =
GETPOST(
'lang_id',
'aZ09');
1288 $user =
new User($db);
1289 $user->fetch(
$object->fk_user_author);
1290 $newlang = $user->lang;
1292 if (!empty($newlang)) {
1293 $outputlangs =
new Translate(
"", $conf);
1294 $outputlangs->setDefaultLang($newlang);
1299 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1303 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
GETPOSTINT(
'id'));
1310 if ($action ==
"updateline" && $user->hasRight(
'expensereport',
'creer')) {
1316 if (GETPOSTISSET(
'attachfile')) {
1317 $arrayoffiles =
GETPOST(
'attachfile',
'array');
1318 if (is_array($arrayoffiles) && !empty($arrayoffiles[0])) {
1319 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1320 $relativepath =
'expensereport/'.$object->ref.
'/'.$arrayoffiles[0];
1322 $ecmfiles->fetch(0,
'', $relativepath);
1323 $fk_ecm_files = $ecmfiles->id;
1328 $type_fees_id =
GETPOSTINT(
'fk_c_type_fees');
1329 $fk_c_exp_tax_cat =
GETPOSTINT(
'fk_c_exp_tax_cat');
1330 $projet_id = $fk_project;
1331 $comments =
GETPOST(
'comments',
'restricthtml');
1333 $vatrate =
GETPOST(
'vatrate',
'alpha');
1336 if (empty($vatrate)) {
1339 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $vatrate));
1343 if (empty($value_unit)) {
1344 $value_unit =
price2num((
float) $value_unit_ht + ((
float) $value_unit_ht * (
float) $tmpvat / 100),
'MU');
1349 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1352 if ((
float) $tmpvat < 0 || $tmpvat ==
'') {
1354 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Vat")),
null,
'errors');
1358 if ($date < $object->date_debut || $date > (
$object->date_fin + (24 * 3600 - 1))) {
1363 $langs->load(
"errors");
1364 $type = $error > 0 ?
'errors' :
'warnings';
1365 setEventMessages($langs->trans(
"WarningDateOfLineMustBeInExpenseReportRange"),
null, $type);
1369 if ($projectRequired && $projet_id <= 0) {
1371 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Project")),
null,
'errors');
1376 $result =
$object->updateline($rowid, $type_fees_id, $projet_id, $vatrate, $comments, $qty, $value_unit, $date, $id, $fk_c_exp_tax_cat, $fk_ecm_files);
1381 $outputlangs = $langs;
1384 $newlang =
GETPOST(
'lang_id',
'aZ09');
1387 $user =
new User($db);
1388 $user->fetch(
$object->fk_user_author);
1389 $newlang = $user->lang;
1391 if (!empty($newlang)) {
1392 $outputlangs =
new Translate(
"", $conf);
1393 $outputlangs->setDefaultLang($newlang);
1398 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1402 unset($value_unit_ht);
1406 unset($fk_c_type_fees);
1420 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
1423 $triggersendname =
'EXPENSEREPORT_SENTBYMAIL';
1424 $autocopy =
'MAIN_MAIL_AUTOCOPY_EXPENSEREPORT_TO';
1425 $trackid =
'exp'.$object->id;
1426 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
1429 $upload_dir = $conf->expensereport->dir_output;
1430 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1438$title = $langs->trans(
"ExpenseReport").
" - ".$langs->trans(
"Card");
1439$help_url =
"EN:Module_Expense_Reports|FR:Module_Notes_de_frais";
1443$form =
new Form($db);
1446$projecttmp =
new Project($db);
1448$bankaccountstatic =
new Account($db);
1449$ecmfilesstatic =
new EcmFiles($db);
1453if ($action ==
'create') {
1456 print
'<form action="'.$_SERVER[
'PHP_SELF'].
'" method="post" name="create">';
1457 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1458 print
'<input type="hidden" name="action" value="add">';
1459 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
1463 print
'<table class="border centpercent">';
1468 print
'<td class="titlefieldcreate fieldrequired">'.$langs->trans(
"DateStart").
'</td>';
1470 print $form->selectDate($date_start ? $date_start : -1,
'date_debut', 0, 0, 0,
'', 1, 1);
1476 print
'<td class="fieldrequired">'.$langs->trans(
"DateEnd").
'</td>';
1478 print $form->selectDate($date_end ? $date_end : -1,
'date_fin', 0, 0, 0,
'', 1, 1);
1484 print
'<td class="fieldrequired">'.$langs->trans(
"User").
'</td>';
1486 $defaultselectuser = $user->id;
1488 $defaultselectuser =
GETPOSTINT(
'fk_user_author');
1490 $include_users =
'hierarchyme';
1491 if (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'expensereport',
'writeall_advance')) {
1492 $include_users = array();
1494 $s = $form->select_dolusers($defaultselectuser,
"fk_user_author", 0,
"", 0, $include_users,
'',
'0,'.$conf->entity);
1501 print
'<td>'.$langs->trans(
"VALIDATOR").
'</td>';
1504 $include_users =
$object->fetch_users_approver_expensereport();
1505 if (empty($include_users)) {
1506 print
img_warning().
' '.$langs->trans(
"NobodyHasPermissionToValidateExpenseReport");
1508 $defaultselectuser = (empty($user->fk_user_expense_validator) ? $user->fk_user : $user->fk_user_expense_validator);
1513 $defaultselectuser =
GETPOSTINT(
'fk_user_validator');
1515 $s = $form->select_dolusers($defaultselectuser,
"fk_user_validator", 1,
"", ((empty($defaultselectuser) || !
getDolGlobalString(
'EXPENSEREPORT_DEFAULT_VALIDATOR_UNCHANGEABLE')) ? 0 : 1), $include_users);
1516 print $form->textwithpicto($s, $langs->trans(
"AnyOtherInThisListCanValidate"));
1524 print
'<td>'.$langs->trans(
"ModePaiement").
'</td>';
1526 $form->select_types_paiements(
'',
'fk_c_paiement');
1532 $note_public = GETPOSTISSET(
'note_public') ?
GETPOST(
'note_public',
'restricthtml') :
'';
1535 print
'<td class="tdtop">'.$langs->trans(
'NotePublic').
'</td>';
1538 $doleditor =
new DolEditor(
'note_public', $note_public,
'', 80,
'dolibarr_notes',
'In', 0,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3,
'90%');
1539 print $doleditor->Create(1);
1543 $note_private = GETPOSTISSET(
'note_private') ?
GETPOST(
'note_private',
'restricthtml') :
'';
1545 if (empty($user->socid)) {
1547 print
'<td class="tdtop">'.$langs->trans(
'NotePrivate').
'</td>';
1550 $doleditor =
new DolEditor(
'note_private', $note_private,
'', 80,
'dolibarr_notes',
'In', 0,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3,
'90%');
1551 print $doleditor->Create(1);
1556 $parameters = array(
'colspan' =>
' colspan="3"',
'cols' => 3);
1557 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters,
$object, $action);
1558 print $hookmanager->resPrint;
1559 if (empty($reshook)) {
1560 print
$object->showOptionals($extrafields,
'create', $parameters);
1568 print $form->buttonsSaveCancel(
"AddTrip");
1571} elseif ($id > 0 || $ref) {
1572 $result =
$object->fetch($id, $ref);
1575 if (!in_array(
$object->fk_user_author, $childids)) {
1576 if (!$user->hasRight(
'expensereport',
'readall') && !$user->hasRight(
'expensereport',
'lire_tous')
1577 && (!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') || !$user->hasRight(
'expensereport',
'writeall_advance'))) {
1580 print
'<div class="tabBar">';
1581 print $langs->trans(
'NotUserRightToView');
1595 print
"<form name='update' action=\"".$_SERVER[
'PHP_SELF'].
"\" method=\"post\">\n";
1596 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1597 print
'<input type="hidden" name="id" value="'.$id.
'">';
1598 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
1603 print
'<input type="hidden" name="action" value="updateFromRefuse">';
1605 print
'<input type="hidden" name="action" value="update">';
1608 $linkback =
'<a href="'.DOL_URL_ROOT.
'/expensereport/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
1610 print
'<table class="border centpercent">';
1613 print
'<td>'.$langs->trans(
"User").
'</td>';
1615 $userfee =
new User($db);
1616 if (
$object->fk_user_author > 0) {
1617 $userfee->fetch(
$object->fk_user_author);
1618 print $userfee->getNomUrl(-1);
1623 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Ref").
'</td><td>';
1624 print $form->showrefnav(
$object,
'ref', $linkback, 1,
'ref',
'ref',
'');
1628 print
'<td>'.$langs->trans(
"DateStart").
'</td>';
1630 print $form->selectDate(
$object->date_debut,
'date_debut');
1634 print
'<td>'.$langs->trans(
"DateEnd").
'</td>';
1636 print $form->selectDate(
$object->date_fin,
'date_fin');
1642 print
'<td>'.$langs->trans(
"ModePaiement").
'</td>';
1644 $form->select_types_paiements(
$object->fk_c_paiement,
'fk_c_paiement');
1651 print
'<td>'.$langs->trans(
"VALIDATOR").
'</td>';
1653 $include_users =
$object->fetch_users_approver_expensereport();
1654 $s = $form->select_dolusers(
$object->fk_user_validator,
"fk_user_validator", 1,
"", 0, $include_users);
1655 print $form->textwithpicto($s, $langs->trans(
"AnyOtherInThisListCanValidate"));
1660 print
'<td>'.$langs->trans(
"VALIDOR").
'</td>';
1662 $userfee =
new User($db);
1663 $userfee->fetch(
$object->fk_user_valid);
1664 print $userfee->getNomUrl(-1);
1670 print
'<td>'.$langs->trans(
"AUTHORPAIEMENT").
'</td>';
1672 $userfee =
new User($db);
1673 $userfee->fetch($user->id);
1674 print $userfee->getNomUrl(-1);
1686 print $form->buttonsSaveCancel(
"Modify");
1690 $taxlessUnitPriceDisabled =
getDolGlobalString(
'EXPENSEREPORT_FORCE_LINE_AMOUNTS_INCLUDING_TAXES_ONLY') ?
' disabled' :
'';
1697 if ($action ==
'clone') {
1699 $criteriaforfilter =
'hierarchyme';
1700 if ($user->hasRight(
'expensereport',
'readall')) {
1701 $criteriaforfilter =
'';
1703 $formquestion = array(
1705 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'))
1708 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneExpenseReport',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1);
1711 if ($action ==
'save') {
1712 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"SaveTrip"), $langs->trans(
"ConfirmSaveTrip"),
"confirm_validate",
"",
"", 1);
1715 if ($action ==
'save_from_refuse') {
1716 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"SaveTrip"), $langs->trans(
"ConfirmSaveTrip"),
"confirm_save_from_refuse",
"",
"", 1);
1719 if ($action ==
'delete') {
1720 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"DeleteTrip"), $langs->trans(
"ConfirmDeleteTrip"),
"confirm_delete",
"",
"", 1);
1723 if ($action ==
'validate') {
1724 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"ValideTrip"), $langs->trans(
"ConfirmValideTrip"),
"confirm_approve",
"",
"", 1);
1727 if ($action ==
'paid') {
1728 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"PaidTrip"), $langs->trans(
"ConfirmPaidTrip"),
"confirm_paid",
"",
"", 1);
1731 if ($action ==
'cancel') {
1732 $array_input = array(
'text' => $langs->trans(
"ConfirmCancelTrip"), 0 => array(
'type' =>
"text",
'label' =>
'<strong>'.$langs->trans(
"Comment").
'</strong>',
'name' =>
"detail_cancel",
'value' =>
""));
1733 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"Cancel"),
"",
"confirm_cancel", $array_input,
"", 1);
1736 if ($action ==
'setdraft') {
1737 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"BrouillonnerTrip"), $langs->trans(
"ConfirmBrouillonnerTrip"),
"confirm_setdraft",
"",
"", 1);
1740 if ($action ==
'refuse') {
1741 $array_input = array(
'text' => $langs->trans(
"ConfirmRefuseTrip"), 0 => array(
'type' =>
"text",
'label' => $langs->trans(
"Comment"),
'name' =>
"detail_refuse",
'value' =>
""));
1742 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"Deny"),
'',
"confirm_refuse", $array_input,
"yes", 1);
1745 if ($action ==
'delete_line') {
1746 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id.
"&rowid=".
GETPOSTINT(
'rowid'), $langs->trans(
"DeleteLine"), $langs->trans(
"ConfirmDeleteLine"),
"confirm_delete_line",
'',
'yes', 1);
1753 $linkback =
'<a href="'.DOL_URL_ROOT.
'/expensereport/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
1755 $morehtmlref =
'<div class="refidno">';
1756 $morehtmlref .=
'</div>';
1758 dol_banner_tab(
$object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
1760 print
'<div class="fichecenter">';
1761 print
'<div class="fichehalfleft">';
1762 print
'<div class="underbanner clearboth"></div>';
1764 print
'<table class="border tableforfield centpercent">';
1768 print
'<td class="titlefield">'.$langs->trans(
"User").
'</td>';
1770 if (
$object->fk_user_author > 0) {
1771 $userauthor =
new User($db);
1772 $result = $userauthor->fetch(
$object->fk_user_author);
1775 } elseif ($result > 0) {
1776 print $userauthor->getNomUrl(-1);
1783 print
'<td class="titlefield">'.$langs->trans(
"Period").
'</td>';
1790 print
'<td>'.$langs->trans(
"ModePaiement").
'</td>';
1791 print
'<td>'.$object->fk_c_paiement.
'</td>';
1797 print
'<td>'.$langs->trans(
"DATE_SAVE").
'</td>';
1798 print
'<td>'.dol_print_date(
$object->date_valid,
'dayhour',
'tzuser');
1800 print
' '.img_warning($langs->trans(
"Late").
' - '.$langs->trans(
"ToApprove"));
1803 print
' '.img_warning($langs->trans(
"Late").
' - '.$langs->trans(
"ToPay"));
1811 print
'<td>'.$langs->trans(
"VALIDATOR").
'</td>';
1813 if (
$object->fk_user_validator > 0) {
1814 $userfee =
new User($db);
1815 $result = $userfee->fetch(
$object->fk_user_validator);
1817 print $userfee->getNomUrl(-1);
1819 if (empty($userfee->email) || !
isValidEmail($userfee->email)) {
1820 $langs->load(
"errors");
1821 print
img_warning($langs->trans(
"ErrorBadEMail", $userfee->email));
1827 print
'<td>'.$langs->trans(
"CANCEL_USER").
'</span></td>';
1829 if (
$object->fk_user_cancel > 0) {
1830 $userfee =
new User($db);
1831 $result = $userfee->fetch(
$object->fk_user_cancel);
1833 print $userfee->getNomUrl(-1);
1839 print
'<td>'.$langs->trans(
"MOTIF_CANCEL").
'</td>';
1840 print
'<td>'.$object->detail_cancel.
'</td></tr>';
1843 print
'<td>'.$langs->trans(
"DATE_CANCEL").
'</td>';
1844 print
'<td>'.dol_print_date(
$object->date_cancel,
'dayhour',
'tzuser').
'</td></tr>';
1848 print
'<td>'.$langs->trans(
"ApprovedBy").
'</td>';
1850 if (
$object->fk_user_approve > 0) {
1851 $userapp =
new User($db);
1852 $result = $userapp->fetch(
$object->fk_user_approve);
1854 print $userapp->getNomUrl(-1);
1860 print
'<td>'.$langs->trans(
"DateApprove").
'</td>';
1861 print
'<td>'.dol_print_date(
$object->date_approve,
'dayhour',
'tzuser').
'</td></tr>';
1867 print
'<td>'.$langs->trans(
"REFUSEUR").
'</td>';
1869 $userfee =
new User($db);
1870 $result = $userfee->fetch(
$object->fk_user_refuse);
1872 print $userfee->getNomUrl(-1);
1877 print
'<td>'.$langs->trans(
"DATE_REFUS").
'</td>';
1878 print
'<td>'.dol_print_date(
$object->date_refuse,
'dayhour',
'tzuser');
1880 print
' - '.$object->detail_refuse;
1904 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
1909 print
'<div class="fichehalfright">';
1910 print
'<div class="underbanner clearboth"></div>';
1912 print
'<table class="border tableforfield centpercent">';
1916 print
'<td class="titlefieldmiddle">'.$langs->trans(
"AmountHT").
'</td>';
1917 print
'<td class="nowrap amountcard">'.price(
$object->total_ht, 1,
'', 1, - 1, - 1, $conf->currency).
'</td>';
1934 print
'<td>'.$langs->trans(
"AmountVAT").
'</td>';
1935 print
'<td class="nowrap amountcard">'.price(
$object->total_tva, 1,
'', 1, -1, -1, $conf->currency).
'</td>';
1939 if ($mysoc->localtax1_assuj ==
"1" ||
$object->total_localtax1 != 0) {
1940 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td>';
1941 print
'<td class="valuefield">'.price(
$object->total_localtax1, 1,
'', 1, -1, -1, $conf->currency).
'</td></tr>';
1943 if ($mysoc->localtax2_assuj ==
"1" ||
$object->total_localtax2 != 0) {
1944 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td>';
1945 print
'<td class="valuefield">'.price(
$object->total_localtax2, 1,
'', 1, -1, -1, $conf->currency).
'</td></tr>';
1949 print
'<td>'.$langs->trans(
"AmountTTC").
'</td>';
1950 print
'<td class="nowrap amountcard">'.price(
$object->total_ttc, 1,
'', 1, -1, -1, $conf->currency).
'</td>';
1954 $canSeeBankAccount = isModEnabled(
'bank') && $user->hasRight(
'banque',
'lire');
1957 if ($canSeeBankAccount) {
1962 print
'<table class="noborder paymenttable centpercent">';
1964 print
'<tr class="liste_titre">';
1965 print
'<td class="liste_titre">'.$langs->trans(
'Payments').
'</td>';
1966 print
'<td class="liste_titre">'.$langs->trans(
'Date').
'</td>';
1967 print
'<td class="liste_titre">'.$langs->trans(
'Type').
'</td>';
1968 if ($canSeeBankAccount) {
1969 print
'<td class="liste_titre right">'.$langs->trans(
'BankAccount').
'</td>';
1971 print
'<td class="liste_titre right">'.$langs->trans(
'Amount').
'</td>';
1972 print
'<td class="liste_titre" width="18"> </td>';
1976 $sql =
"SELECT p.rowid, p.num_payment, p.datep as dp, p.amount, p.fk_bank,";
1977 $sql .=
"c.code as payment_code, c.libelle as payment_type,";
1978 $sql .=
"ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal";
1979 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as e, ".MAIN_DB_PREFIX.
"payment_expensereport as p";
1980 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON p.fk_typepayment = c.id";
1981 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
1982 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
1983 $sql .=
" WHERE e.rowid = ".((int) $id);
1984 $sql .=
" AND p.fk_expensereport = e.rowid";
1985 $sql .=
' AND e.entity IN ('.getEntity(
'expensereport').
')';
1986 $sql .=
" ORDER BY dp";
1988 $resql = $db->query($sql);
1990 $num = $db->num_rows($resql);
1994 $objp = $db->fetch_object($resql);
1996 $paymentexpensereportstatic->id = $objp->rowid;
1997 $paymentexpensereportstatic->datep = $db->jdate($objp->dp);
1998 $paymentexpensereportstatic->ref = $objp->rowid;
1999 $paymentexpensereportstatic->num_payment = $objp->num_payment;
2000 $paymentexpensereportstatic->type_code = $objp->payment_code;
2001 $paymentexpensereportstatic->type_label = $objp->payment_type;
2003 print
'<tr class="oddseven">';
2005 print $paymentexpensereportstatic->getNomUrl(1);
2007 print
'<td>'.dol_print_date($db->jdate($objp->dp),
'day').
"</td>\n";
2008 $labeltype = $langs->trans(
"PaymentType".$objp->payment_code) !=
"PaymentType".$objp->payment_code ? $langs->trans(
"PaymentType".$objp->payment_code) : $objp->payment_type;
2009 print
"<td>".$labeltype.
' '.$objp->num_payment.
"</td>\n";
2011 if ($canSeeBankAccount) {
2012 $bankaccountstatic->id = $objp->baid;
2013 $bankaccountstatic->ref = $objp->baref;
2014 $bankaccountstatic->label = $objp->baref;
2015 $bankaccountstatic->number = $objp->banumber;
2017 if (isModEnabled(
'accounting')) {
2018 $bankaccountstatic->account_number = $objp->account_number;
2021 $accountingjournal->fetch($objp->fk_accountancy_journal);
2022 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
2025 print
'<td class="right">';
2026 if ($bankaccountstatic->id) {
2027 print $bankaccountstatic->getNomUrl(1,
'transactions');
2031 print
'<td class="right">'.price($objp->amount).
"</td>";
2034 $totalpaid += $objp->amount;
2037 if (!is_null($totalpaid)) {
2042 $resteapayeraffiche = $remaintopay;
2044 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
2047 $cssforamountpaymentcomplete =
'amountpaymentneutral';
2048 $resteapayeraffiche = 0;
2049 } elseif (
$object->paid == 0) {
2050 $cssforamountpaymentcomplete =
'amountpaymentneutral';
2052 print
'<tr><td colspan="'.$nbcols.
'" class="right">'.$langs->trans(
"AlreadyPaid").
':</td><td class="right">'.
price($totalpaid).
'</td><td></td></tr>';
2053 print
'<tr><td colspan="'.$nbcols.
'" class="right">'.$langs->trans(
"AmountExpected").
':</td><td class="right">'.
price(
$object->total_ttc).
'</td><td></td></tr>';
2055 print
'<tr><td colspan="'.$nbcols.
'" class="right">'.$langs->trans(
"RemainderToPay").
':</td>';
2056 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td><td></td></tr>';
2067 print
'<div class="clearboth"></div><br><br>';
2069 print
'<div style="clear: both;"></div>';
2071 $actiontouse =
'updateline';
2072 if ((
$object->status == 0 ||
$object->status == 99) && $action !=
'editline') {
2073 $actiontouse =
'addline';
2076 print
'<form name="expensereport" action="'.$_SERVER[
"PHP_SELF"].
'" enctype="multipart/form-data" method="post" >';
2077 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2078 print
'<input type="hidden" name="action" value="'.$actiontouse.
'">';
2079 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
2080 print
'<input type="hidden" name="fk_expensereport" value="'.$object->id.
'" />';
2081 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
2082 print
'<input type="hidden" name="page_y" value="">';
2084 print
'<div class="div-table-responsive-no-min">';
2085 print
'<table id="tablelines" class="noborder centpercent">';
2091 print
'<tr class="liste_titre headerexpensereportdet">';
2092 print
'<td class="center linecollinenb">'.$langs->trans(
'LineNb').
'</td>';
2094 print
'<td class="center linecoldate">'.$langs->trans(
'Date').
'</td>';
2095 if (isModEnabled(
'project')) {
2096 print
'<td class="minwidth100imp linecolproject">'.$langs->trans(
'Project').
'</td>';
2098 print
'<td class="center linecoltype">'.$langs->trans(
'Type').
'</td>';
2100 print
'<td class="center linecolcarcategory">'.$langs->trans(
'CarCategory').
'</td>';
2102 print
'<td class="linecoldescription">'.$langs->trans(
'Description').
'</td>';
2103 print
'<td class="right linecolvat">'.$langs->trans(
'VAT').
'</td>';
2104 print
'<td class="right linecolpriceuht">'.$langs->trans(
'PriceUHT').
'</td>';
2105 print
'<td class="right linecolpriceuttc">'.$langs->trans(
'PriceUTTC').
'</td>';
2106 print
'<td class="right linecolqty">'.$langs->trans(
'Qty').
'</td>';
2107 if ($action !=
'editline') {
2108 print
'<td class="right linecolamountht">'.$langs->trans(
'AmountHT').
'</td>';
2109 print
'<td class="right linecolamountttc">'.$langs->trans(
'AmountTTC').
'</td>';
2120 if ((
$object->status < 2 ||
$object->status == 99) && $user->hasRight(
'expensereport',
'creer')) {
2121 print
'<td class="right"></td>';
2125 foreach (
$object->lines as &$line) {
2128 if ($action !=
'editline' || $line->id !=
GETPOSTINT(
'rowid')) {
2129 print
'<tr class="oddeven linetr" data-id="'.$line->id.
'">';
2132 print
'<td class="center linecollinenb">';
2137 print
'<td class="center linecoldate">'.dol_print_date($db->jdate($line->date),
'day').
'</td>';
2140 if (isModEnabled(
'project')) {
2141 print
'<td class="lineproject">';
2142 if ($line->fk_project > 0) {
2143 $projecttmp->id = $line->fk_project;
2144 $projecttmp->ref = $line->projet_ref;
2145 $projecttmp->title = $line->projet_title;
2146 print $projecttmp->getNomUrl(1);
2152 if (isModEnabled(
'accounting')) {
2153 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
2155 $resaccountingaccount = $accountingaccount->fetch(0, $line->type_fees_accountancy_code, 1);
2157 $titlealt .= $langs->trans(
"AccountancyCode").
': ';
2158 if ($resaccountingaccount > 0) {
2159 $titlealt .= $accountingaccount->account_number;
2161 $titlealt .= $langs->trans(
"NotFound");
2167 print
'<td class="center linecoltype" title="'.dol_escape_htmltag($titlealt).
'">';
2168 $labeltype = ($langs->trans(($line->type_fees_code)) == $line->type_fees_code ? $line->type_fees_libelle : $langs->trans($line->type_fees_code));
2174 print
'<td class="fk_c_exp_tax_cat linecoltaxcat">';
2175 $exp_tax_cat_label =
dol_getIdFromCode($db, $line->fk_c_exp_tax_cat,
'c_exp_tax_cat',
'rowid',
'label');
2176 print $langs->trans($exp_tax_cat_label);
2181 print
'<td class="left linecolcomment">'.dol_nl2br($line->comments).
'</td>';
2184 $senderissupplier = 0;
2185 $tooltiponprice =
'';
2186 $tooltiponpriceend =
'';
2188 $tooltiponprice = $langs->transcountry(
"TotalHT", $mysoc->country_code).
'='.
price($line->total_ht);
2189 $tooltiponprice .=
'<br>'.$langs->transcountry(
"TotalVAT", ($senderissupplier ?
$object->thirdparty->country_code : $mysoc->country_code)).
'='.
price($line->total_tva);
2190 if (is_object(
$object->thirdparty)) {
2191 if ($senderissupplier) {
2192 $seller =
$object->thirdparty;
2199 if ($mysoc->useLocalTax(1)) {
2200 if (($seller->country_code == $buyer->country_code) || $line->total_localtax1 || $seller->useLocalTax(1)) {
2201 $tooltiponprice .=
'<br>'.$langs->transcountry(
"TotalLT1", $seller->country_code).
'='.
price($line->total_localtax1);
2203 $tooltiponprice .=
'<br>'.$langs->transcountry(
"TotalLT1", $seller->country_code).
'=<span class="opacitymedium">'.$langs->trans($senderissupplier ?
"NotUsedForThisVendor" :
"NotUsedForThisCustomer").
'</span>';
2206 if ($mysoc->useLocalTax(2)) {
2207 if ((isset($seller->country_code) && isset($buyer->thirdparty->country_code) && $seller->country_code == $buyer->thirdparty->country_code) || $line->total_localtax2 || $seller->useLocalTax(2)) {
2208 $tooltiponprice .=
'<br>'.$langs->transcountry(
"TotalLT2", $seller->country_code).
'='.
price($line->total_localtax2);
2210 $tooltiponprice .=
'<br>'.$langs->transcountry(
"TotalLT2", $seller->country_code).
'=<span class="opacitymedium">'.$langs->trans($senderissupplier ?
"NotUsedForThisVendor" :
"NotUsedForThisCustomer").
'</span>';
2214 $tooltiponprice .=
'<br>'.$langs->transcountry(
"TotalTTC", $mysoc->country_code).
'='.
price($line->total_ttc);
2216 $tooltiponprice =
'<span class="classfortooltip" title="'.dol_escape_htmltag($tooltiponprice).
'">';
2217 $tooltiponpriceend =
'</span>';
2220 print
'<td class="right linecolvatrate">';
2221 print $tooltiponprice;
2222 print
vatrate($line->vatrate.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
''), true);
2223 print $tooltiponpriceend;
2227 print
'<td class="right linecolunitht">';
2228 if (!empty($line->value_unit_ht)) {
2229 print
price($line->value_unit_ht);
2231 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $line->vatrate));
2232 $pricenettoshow =
price2num((
float) $line->value_unit / (1 + $tmpvat / 100),
'MU');
2233 print
price($pricenettoshow);
2237 print
'<td class="right linecolunitttc">'.price($line->value_unit).
'</td>';
2239 print
'<td class="right linecolqty">'.dol_escape_htmltag($line->qty).
'</td>';
2241 if ($action !=
'editline') {
2242 print
'<td class="right linecoltotalht">'.price($line->total_ht).
'</td>';
2243 print
'<td class="right linecoltotalttc">'.price($line->total_ttc).
'</td>';
2247 print
'<td class="center linecolpreview">';
2248 if ($line->fk_ecm_files > 0) {
2249 $modulepart =
'expensereport';
2250 $maxheightmini = 32;
2252 $result = $ecmfilesstatic->fetch($line->fk_ecm_files);
2254 $relativepath = preg_replace(
'/expensereport\//',
'', $ecmfilesstatic->filepath);
2255 $fileinfo = pathinfo($ecmfilesstatic->filepath.
'/'.$ecmfilesstatic->filename);
2258 if (!
dol_is_file($conf->expensereport->dir_output.
'/'.$relativepath.
'/'.$minifile)) {
2262 $urlforhref =
getAdvancedPreviewUrl($modulepart, $relativepath.
'/'.$fileinfo[
'filename'].
'.'.strtolower($fileinfo[
'extension']), 1,
'&entity='.(empty(
$object->entity) ? $conf->entity :
$object->entity));
2263 if (empty($urlforhref)) {
2264 $urlforhref = DOL_URL_ROOT.
'/viewimage.php?modulepart='.$modulepart.
'&entity='.(empty(
$object->entity) ? $conf->entity :
$object->entity).
'&file='.urlencode($relativepath.$fileinfo[
'filename'].
'.'.strtolower($fileinfo[
'extension']));
2265 print
'<a href="'.$urlforhref.
'" class="aphoto" target="_blank" rel="noopener noreferrer">';
2267 print
'<a href="'.$urlforhref[
'url'].
'" class="'.$urlforhref[
'css'].
'" target="'.$urlforhref[
'target'].
'" mime="'.$urlforhref[
'mime'].
'">';
2269 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="">';
2272 if (preg_match(
'/\.pdf$/i', $ecmfilesstatic->filename)) {
2273 $filepdf = $conf->expensereport->dir_output.
'/'.$relativepath.
'/'.$ecmfilesstatic->filename;
2274 $fileimage = $conf->expensereport->dir_output.
'/'.$relativepath.
'/'.$ecmfilesstatic->filename.
'_preview.png';
2275 $relativepathimage = $relativepath.
'/'.$ecmfilesstatic->filename.
'_preview.png';
2277 $pdfexists = file_exists($filepdf);
2280 if (!file_exists($fileimage) || (filemtime($fileimage) < filemtime($filepdf))) {
2282 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2291 if ($pdfexists && !$error) {
2292 $heightforphotref = 70;
2293 if (!empty($conf->dol_optimize_smallscreen)) {
2294 $heightforphotref = 60;
2296 $urlforhref =
getAdvancedPreviewUrl($modulepart, $relativepath.
'/'.$fileinfo[
'filename'].
'.'.strtolower($fileinfo[
'extension']), 1,
'&entity='.(empty(
$object->entity) ? $conf->entity :
$object->entity));
2297 print
'<a href="'.$urlforhref[
'url'].
'" class="'.$urlforhref[
'css'].
'" target="'.$urlforhref[
'target'].
'" mime="'.$urlforhref[
'mime'].
'">';
2299 if (file_exists($fileimage)) {
2300 print
'<img height="'.$heightforphotref.
'" class="photo photowithmargin photowithborder" src="'.DOL_URL_ROOT.
'/viewimage.php?modulepart=apercu'.$modulepart.
'&file='.urlencode($relativepathimage).
'">';
2303 print
img_mime($ecmfilesstatic->filename);
2313 print
'<td class="nowrap right linecolwarning">';
2314 print !empty($line->rule_warning_message) ?
img_warning(html_entity_decode($line->rule_warning_message)) :
' ';
2319 print
'<td class="nowrap right linecolaction">';
2321 print
'<a class="editfielda reposition paddingrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=editline&token='.
newToken().
'&rowid='.$line->rowid.
'">';
2323 print
'</a> ';
2324 print
'<a class="paddingrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=delete_line&token='.
newToken().
'&rowid='.$line->rowid.
'">';
2334 if ($action ==
'editline' && $line->id ==
GETPOSTINT(
'rowid')) {
2337 if (isModEnabled(
'project')) {
2344 print
'<!-- line of expense report -->'.
"\n";
2345 print
'<tr class="tredited">';
2347 print
'<td class="center">';
2351 print
'<td colspan="'.($colspan - 1).
'" class="liste_titre"> ';
2352 print
'<a href="" class="commonlink auploadnewfilenow reposition">'.$langs->trans(
"UploadANewFileNow");
2353 print
img_picto($langs->trans(
"UploadANewFileNow"),
'chevron-down',
'',
false, 0, 0,
'',
'marginleftonly');
2356 print
' - <a href="" class="commonlink aattachtodoc reposition">'.$langs->trans(
"AttachTheNewLineToTheDocument");
2357 print
img_picto($langs->trans(
"AttachTheNewLineToTheDocument"),
'chevron-down',
'',
false, 0, 0,
'',
'marginleftonly');
2361 print
'<!-- Code to open/close section to submit or link files in edit mode -->'.
"\n";
2362 print
'<script type="text/javascript">'.
"\n";
2363 print
'$(document).ready(function() {
2364 $( ".auploadnewfilenow" ).click(function() {
2365 jQuery(".truploadnewfilenow").toggle();
2366 jQuery(".trattachnewfilenow").hide();
2369 $( ".aattachtodoc" ).click(function() {
2370 jQuery(".trattachnewfilenow").toggle();
2371 jQuery(".truploadnewfilenow").hide();
2374 if (is_array(
GETPOST(
'attachfile',
'array')) && count(
GETPOST(
'attachfile',
'array'))) {
2375 print
'jQuery(".trattachnewfilenow").toggle();'.
"\n";
2378 jQuery("form[name=\"expensereport\"]").submit(function() {
2379 if (jQuery(".truploadnewfilenow").is(":hidden")) {
2380 jQuery("input[name=\"sendit\"]").val("");
2387 print
'</script>'.
"\n";
2390 $filenamelinked =
'';
2391 if ($line->fk_ecm_files > 0) {
2392 $result = $ecmfilesstatic->fetch($line->fk_ecm_files);
2394 $filenamelinked = $ecmfilesstatic->filename;
2398 $tredited =
'tredited';
2399 include DOL_DOCUMENT_ROOT.
'/expensereport/tpl/expensereport_addfile.tpl.php';
2400 include DOL_DOCUMENT_ROOT.
'/expensereport/tpl/expensereport_linktofile.tpl.php';
2402 print
'<tr class="oddeven tredited">';
2407 print
'<td class="center">';
2408 print $form->selectDate($line->date,
'date');
2412 if (isModEnabled(
'project')) {
2414 $formproject->select_projects(-1, $line->fk_project,
'fk_project', 0, 0, $projectRequired ? 0 : 1, 1, 0, 0, 0,
'', 0, 0,
'maxwidth300');
2419 print
'<td class="center">';
2420 print $formexpensereport->selectTypeExpenseReport($line->fk_c_type_fees,
'fk_c_type_fees');
2424 print
'<td class="fk_c_exp_tax_cat">';
2425 $params = array(
'fk_expense' =>
$object->id,
'fk_expense_det' => $line->id,
'date' => $line->date);
2426 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);
2432 print
'<textarea name="comments" class="flat_ndf centpercent">'.dol_escape_htmltag($line->comments, 0, 1).
'</textarea>';
2436 $selectedvat =
price2num($line->vatrate).(!empty($line->vat_src_code) ?
' ('.$line->vat_src_code.
')' :
'');
2437 print
'<td class="right">';
2438 print $form->load_tva(
'vatrate', (GETPOSTISSET(
"vatrate") ?
GETPOST(
"vatrate") : $selectedvat), $mysoc,
'', 0, 0,
'', false, 1, 2);
2442 print
'<td class="right">';
2443 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.
' />';
2447 print
'<td class="right">';
2448 print
'<input type="text" min="0" class="right maxwidth50" id="value_unit" name="value_unit" value="'.dol_escape_htmltag(
price2num($line->value_unit)).
'" />';
2452 print
'<td class="right">';
2453 print
'<input type="text" min="0" class="input_qty right maxwidth50" name="qty" value="'.dol_escape_htmltag($line->qty).
'" />';
2460 print
'<td class="center">';
2464 print
'<td class="center">';
2468 print
'<input type="hidden" name="rowid" value="'.$line->rowid.
'">';
2469 print $form->buttonsSaveCancel(
'Save',
'Cancel', array(), 0,
'small');
2485 if (isModEnabled(
'project')) {
2488 if ($action !=
'editline') {
2492 $nbFiles = $nbLinks = 0;
2493 $arrayoffiles = array();
2495 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2496 require_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
2497 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
2500 $nbFiles = count($arrayoffiles);
2505 print
'<tr class="liste_titre">';
2506 print
'<td colspan="'.$colspan.
'" class="liste_titre expensereportautoload">';
2507 print
'<a href="" class="commonlink auploadnewfilenow reposition">'.$langs->trans(
"UploadANewFileNow");
2508 print
img_picto($langs->trans(
"UploadANewFileNow"),
'chevron-down',
'',
false, 0, 0,
'',
'marginleftonly');
2511 print
' - <a href="" class="commonlink aattachtodoc reposition">'.$langs->trans(
"AttachTheNewLineToTheDocument");
2512 print
img_picto($langs->trans(
"AttachTheNewLineToTheDocument"),
'chevron-down',
'',
false, 0, 0,
'',
'marginleftonly');
2516 print
'<!-- Code to open/close section to submit or link files in the form to add new line -->'.
"\n";
2517 print
'<script type="text/javascript">'.
"\n";
2518 print
'$(document).ready(function() {
2519 $( ".auploadnewfilenow" ).click(function() {
2520 console.log("We click on toggle of auploadnewfilenow");
2521 jQuery(".truploadnewfilenow").toggle();
2522 jQuery(".trattachnewfilenow").hide();
2523 if (jQuery(".truploadnewfilenow").is(":hidden")) {
2524 jQuery("input[name=\"sendit\"]").prop("name", "senditdisabled");
2526 jQuery("input[name=\"senditdisabled\"]").prop("name", "sendit");
2528 // TODO Switch css fa-chevron-dow and add fa-chevron-up
2531 $( ".aattachtodoc" ).click(function() {
2532 console.log("We click on toggle of aattachtodoc");
2533 jQuery(".trattachnewfilenow").toggle();
2534 jQuery(".truploadnewfilenow").hide();
2535 // TODO Switch css fa-chevron-dow and add fa-chevron-up
2538 if (is_array(
GETPOST(
'attachfile',
'array')) && count(
GETPOST(
'attachfile',
'array')) && $action !=
'updateline') {
2539 print
'jQuery(".trattachnewfilenow").show();'.
"\n";
2542 jQuery("form[name=\"expensereport\"]").submit(function() {
2543 if (jQuery(".truploadnewfilenow").is(":hidden")) {
2544 /* 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. */
2545 jQuery("input[name=\"sendit\"]").val("");
2546 jQuery("input[name=\"sendit\"]").prop("name", "senditdisabled");
2548 jQuery("input[name=\"senditdisabled\"]").prop("name", "sendit");
2555 print
'</script>'.
"\n";
2559 include DOL_DOCUMENT_ROOT.
'/expensereport/tpl/expensereport_linktofile.tpl.php';
2560 include DOL_DOCUMENT_ROOT.
'/expensereport/tpl/expensereport_addfile.tpl.php';
2562 print
'<tr class="liste_titre expensereportcreate">';
2564 print
'<td class="center expensereportcreatedate">'.$langs->trans(
'Date').
'</td>';
2565 if (isModEnabled(
'project')) {
2566 print
'<td class="minwidth100imp">'.$form->textwithpicto($langs->trans(
'Project'), $langs->trans(
"ClosedProjectsAreHidden")).
'</td>';
2568 print
'<td class="center expensereportcreatetype">'.$langs->trans(
'Type').
'</td>';
2570 print
'<td>'.$langs->trans(
'CarCategory').
'</td>';
2572 print
'<td class="expensereportcreatedescription">'.$langs->trans(
'Description').
'</td>';
2573 print
'<td class="right expensereportcreatevat">'.$langs->trans(
'VAT').
'</td>';
2574 print
'<td class="right expensereportcreatepriceuth">'.$langs->trans(
'PriceUHT').
'</td>';
2575 print
'<td class="right expensereportcreatepricettc">'.$langs->trans(
'PriceUTTC').
'</td>';
2576 print
'<td class="right expensereportcreateqty">'.$langs->trans(
'Qty').
'</td>';
2583 print
'<tr class="oddeven nohover">';
2589 print
'<td class="center inputdate">';
2590 print $form->selectDate(!empty($date) ? $date : -1,
'date', 0, 0, 0,
'', 1, 1);
2594 if (isModEnabled(
'project')) {
2595 print
'<td class="inputproject">';
2596 $formproject->select_projects(-1, !empty($fk_project) ? $fk_project : 0,
'fk_project', 0, 0, $projectRequired ? 0 : 1, -1, 0, 0, 0,
'', 0, 0,
'maxwidth300');
2601 print
'<td class="center inputtype">';
2602 print $formexpensereport->selectTypeExpenseReport(!empty($fk_c_type_fees) ? $fk_c_type_fees :
"",
'fk_c_type_fees', 1);
2606 print
'<td class="fk_c_exp_tax_cat">';
2607 $params = array(
'fk_expense' =>
$object->id);
2608 print $form->selectExpenseCategories(
'',
'fk_c_exp_tax_cat', 1, array(),
'fk_c_type_fees', $userauthor->default_c_exp_tax_cat, $params, 0);
2613 print
'<td class="inputcomment">';
2614 print
'<textarea class="flat_ndf centpercent" name="comments" rows="'.ROWS_2.
'">'.
dol_escape_htmltag(!empty($comments) ? $comments :
"", 0, 1).
'</textarea>';
2618 print
'<td class="right inputvat">';
2622 $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS =
'none';
2624 print $form->load_tva(
'vatrate', (!empty($vatrate) ? $vatrate : $defaultvat), null, null, 0, 0,
'', false, 1);
2628 print
'<td class="right inputpricenet">';
2629 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.
' />';
2633 print
'<td class="right inputtax">';
2634 print
'<input type="text" class="right maxwidth50" id="value_unit" name="value_unit" value="'.dol_escape_htmltag((!empty($value_unit) ? $value_unit :
"")).
'">';
2638 print
'<td class="right inputqty">';
2639 print
'<input type="text" min="0" class=" input_qty right maxwidth50" name="qty" value="'.dol_escape_htmltag(!empty($qty) ? $qty : 1).
'">';
2645 if ($action !=
'editline') {
2646 print
'<td class="right"></td>';
2647 print
'<td class="right"></td>';
2651 print
'<td class="center inputbuttons">';
2652 print $form->buttonsSaveCancel(
"Add",
'',
'', 1,
'reposition');
2663 /* JQuery for product free or predefined select */
2664 jQuery(document).ready(function() {
2665 jQuery("#value_unit_ht").keyup(function(event) {
2666 console.log(event.which); // discard event tag and arrows
2667 if (event.which != 9 && (event.which < 37 ||event.which > 40) && jQuery("#value_unit_ht").val() != "") {
2668 jQuery("#value_unit").val("");
2671 jQuery("#value_unit").keyup(function(event) {
2672 console.log(event.which); // discard event tag and arrows
2673 if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#value_unit").val() != "") {
2674 jQuery("#value_unit_ht").val("");
2682 /* unit price coef calculation */
2683 jQuery(".input_qty, #fk_c_type_fees, #select_fk_c_exp_tax_cat, #vatrate ").change(function(event) {
2684 console.log("We change a parameter");
2686 let type_fee = jQuery("#fk_c_type_fees").find(":selected").val();
2687 let tax_cat = jQuery("#select_fk_c_exp_tax_cat").find(":selected").val();
2688 let tva = jQuery("#vatrate").find(":selected").val();
2689 let qty = jQuery(".input_qty").val();
2691 let path = "'.DOL_URL_ROOT.
'/expensereport/ajax/ajaxik.php";
2692 path += "?fk_c_exp_tax_cat="+tax_cat;
2693 path += "&fk_expense="+'.((int)
$object->id).
';
2694 path += "&vatrate="+tva;
2695 path += "&qty="+qty;
2697 if (type_fee == 4) { // frais_kilométriques
2698 if (tax_cat == "" || parseInt(tax_cat) <= 0){
2706 success: function(response) {
2707 if (response.response_status == "success"){';
2711 jQuery("#value_unit").val(parseFloat(response.data) * (100 + parseFloat(tva)) / 100);
2712 jQuery("#value_unit").trigger("change");
2716 jQuery("#value_unit_ht").val(response.data);
2717 jQuery("#value_unit_ht").trigger("change");
2718 jQuery("#value_unit").val("");
2723 } else if(response.response_status == "error" && response.errorMessage != undefined && response.errorMessage.length > 0 ) {
2724 console.log("We get an error result");
2725 $.jnotify(response.errorMessage, "error", {timeout: 0, type: "error"},{ remove: function (){} } );
2731 /*console.log(event.which); // discard event tag and arrows
2732 if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#value_unit").val() != "") {
2733 jQuery("#value_unit_ht").val("");
2753 print
'Record not found';
2764print
'<div class="tabsAction">';
2766if ($action !=
'create' && $action !=
'edit' && $action !=
'editline') {
2771 if (empty($user->socid)) {
2774 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>';
2786 if (in_array(
$object->fk_user_author, $childids) || $user->hasRight(
'expensereport',
'writeall_advance')) {
2788 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>';
2791 if (count(
$object->lines) > 0) {
2792 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>';
2803 if ($user->id ==
$object->fk_user_author || $user->id ==
$object->fk_user_valid) {
2805 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>';
2810 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>';
2815 if ($user->id ==
$object->fk_user_author || $user->id ==
$object->fk_user_valid) {
2817 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>';
2827 if (in_array(
$object->fk_user_author, $childids)) {
2829 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>';
2837 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>';
2839 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>';
2842 if ($user->id ==
$object->fk_user_author || $user->id ==
$object->fk_user_valid) {
2844 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=cancel&id='.
$object->id.
'">'.$langs->trans(
"Cancel").
'</a></div>';
2853 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>';
2859 if ($remaintopay == 0) {
2860 print
'<div class="inline-block divButAction"><span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPayment').
'</span></div>';
2862 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>';
2870 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>";
2876 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>';
2882 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>';
2887 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>';
2891 if ($user->hasRight(
'expensereport',
'creer')) {
2892 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>';
2898 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>';
2901 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>';
2904 $parameters = array();
2905 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters,
$object, $action);
2912if (
GETPOST(
'modelselected',
'alpha')) {
2913 $action =
'presend';
2916if ($action !=
'presend') {
2921 print
'<div class="fichecenter"><div class="fichehalfleft">';
2922 print
'<a name="builddoc"></a>';
2924 if ($user->hasRight(
'expensereport',
'creer') && $action !=
'create' && $action !=
'edit') {
2927 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".
$object->id;
2928 $genallowed = $user->hasRight(
'expensereport',
'creer');
2929 $delallowed = $user->hasRight(
'expensereport',
'creer');
2931 print $formfile->showdocuments(
'expensereport', $filename, $filedir, $urlsource, $genallowed, $delallowed);
2932 $somethingshown = $formfile->numoffiles;
2944 print
'</div><div class="fichehalfright">';
2946 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
2948 $somethingshown = $formactions->showactions(
$object,
'expensereport',
null);
2950 print
'</div></div>';
2954$modelmail =
'expensereport_send';
2955$defaulttopic =
'SendExpenseReportRef';
2956$diroutput = $conf->expensereport->dir_output;
2957$trackid =
'exp'.$object->id;
2959include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage bank accounts.
Class to manage accounting accounts.
Class to manage accounting journals.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Class to manage a WYSIWYG editor.
Class to manage ECM files.
Class to manage Trips and Expenses.
const STATUS_DRAFT
Draft status.
const STATUS_APPROVED
Classified approved.
const STATUS_CANCELED
Classified canceled.
const STATUS_CLOSED
Classified paid.
const STATUS_REFUSED
Classified refused.
const STATUS_VALIDATED
Validated (need to be paid)
Class of expense report details lines.
static count($dbs, $objecttype, $objectid)
Return nb of links.
Class to manage payments of expense report.
Class to manage projects.
Class to manage translations.
Class to manage Dolibarr users.
expensereport_prepare_head($object)
Prepare array with list of tabs.
dol_convert_file($fileinput, $ext='png', $fileoutput='', $page='')
Convert an image file or a PDF into another image format.
dol_is_file($pathoffile)
Return if path is a file.
dol_dir_list($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.
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_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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'.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
getImageFileNameForSize($file, $extName, $extImgTarget='')
Return the filename of file to get the thumbs.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
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.
getDolGlobalString($key, $default='')
Return 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.
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.