31require
'../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formexpensereport.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
36require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
37require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
39require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
40require_once DOL_DOCUMENT_ROOT.
'/core/lib/expensereport.lib.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
42require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
43require_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
44require_once DOL_DOCUMENT_ROOT.
'/core/modules/expensereport/modules_expensereport.php';
45require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
46require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/paymentexpensereport.class.php';
47require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
48require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
49if (isModEnabled(
'accounting')) {
50 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
65$langs->loadLangs(array(
"trips",
"bills",
"mails"));
67$action =
GETPOST(
'action',
'aZ09');
68$cancel =
GETPOST(
'cancel',
'alpha');
69$confirm =
GETPOST(
'confirm',
'alpha');
70$backtopage =
GETPOST(
'backtopage',
'alpha');
77$vatrate =
GETPOST(
'vatrate',
'alpha');
79$comments =
GETPOST(
'comments',
'restricthtml');
84$childids = $user->getAllChildIds(1);
87 if (empty($date_start)) {
91 if (empty($date_end)) {
98$rootfordata = DOL_DATA_ROOT;
99$rootforuser = DOL_DATA_ROOT;
101if (isModEnabled(
'multicompany') && !empty(
$conf->entity) &&
$conf->entity > 1) {
102 $rootfordata .=
'/'.$conf->entity;
104$conf->expensereport->dir_output = $rootfordata.
'/expensereport';
107$urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
108$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
121$extrafields->fetch_name_optionals_label(
$object->table_element);
124include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
127$hookmanager->initHooks(array(
'expensereportcard',
'globalcard'));
129$permissionnote = $user->hasRight(
'expensereport',
'creer');
130$permissiondellink = $user->hasRight(
'expensereport',
'creer');
131$permissiontoadd = $user->hasRight(
'expensereport',
'creer');
135$projectRequired = isModEnabled(
'project') &&
getDolGlobalString(
'EXPENSEREPORT_PROJECT_IS_REQUIRED');
141 if ($user->hasRight(
'expensereport',
'readall')) {
144 if ($user->hasRight(
'expensereport',
'lire') && in_array(
$object->fk_user_author, $childids)) {
153if ($user->hasRight(
'expensereport',
'supprimer')) {
162 $socid = $user->socid;
166$permissiontoadd = $user->hasRight(
'expensereport',
'creer');
178$parameters = array(
'socid' => $socid);
179$reshook = $hookmanager->executeHooks(
'doActions', $parameters,
$object, $action);
184if (empty($reshook)) {
185 $backurlforlist = DOL_URL_ROOT.
'/expensereport/list.php';
187 if (empty($backtopage) || ($cancel && empty($id))) {
188 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
189 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
190 $backtopage = $backurlforlist;
192 $backtopage = DOL_URL_ROOT.
'/expensereport/card.php?id='.((!empty($id) &&
$id > 0) ? $id :
'__ID__');
198 if (!empty($backtopageforcancel)) {
199 header(
"Location: ".$backtopageforcancel);
201 } elseif (!empty($backtopage)) {
202 header(
"Location: ".$backtopage);
216 $fk_c_type_fees = -1;
219 include DOL_DOCUMENT_ROOT.
'/core/actions_linkedfiles.inc.php';
221 if (!empty(
GETPOST(
'sendit',
'alpha'))) {
222 if ($action ==
'updateline') {
223 $action =
'editline';
229 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
231 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
233 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
236 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontoadd) {
237 if (1 == 0 && !
GETPOST(
'clone_content',
'alpha') && !
GETPOST(
'clone_receivers',
'alpha')) {
246 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
257 if ($action ==
'confirm_delete' &&
GETPOST(
"confirm",
'alpha') ==
"yes" && $id > 0 && $candelete) {
260 $result =
$object->delete($user);
262 header(
"Location: index.php");
269 if ($action ==
'add' && $permissiontoadd) {
272 $object->date_debut = $date_start;
276 if (!(
$object->fk_user_author > 0)) {
277 $object->fk_user_author = $user->id;
281 if ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'expensereport',
'creer'))
282 || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'expensereport',
'creer') && !$user->hasRight(
'expensereport',
'writeall_advance'))) {
287 if (!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') || !$user->hasRight(
'expensereport',
'writeall_advance')) {
288 if (!in_array(
$object->fk_user_author, $childids)) {
295 $fuser =
new User($db);
296 $fuser->fetch(
$object->fk_user_author);
305 $ret = $extrafields->setOptionalsFromPost(
null,
$object);
312 $overlappingExpenseReportID =
$object->periode_existe($fuser,
$object->date_debut,
$object->date_fin);
314 if ($overlappingExpenseReportID > 0) {
316 setEventMessages($langs->trans(
"ErrorDoubleDeclaration").
' <a href="'.$_SERVER[
'PHP_SELF'].
'?id='.$overlappingExpenseReportID.
'">'. $langs->trans(
'ShowTrip').
'</a>',
null,
'errors');
331 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
341 if (($action ==
'update' || $action ==
'updateFromRefuse') && $permissiontoadd) {
345 $object->date_debut = $date_start;
355 $object->fk_user_modif = $user->id;
357 $result =
$object->update($user);
359 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
GETPOSTINT(
'id'));
366 if ($action ==
'update_extras' && $permissiontoadd) {
370 $ret = $extrafields->setOptionalsFromPost(
null,
$object,
GETPOST(
'attribute',
'restricthtml'));
377 $result =
$object->insertExtraFields(
'EXPENSEREPORT_MODIFY');
385 $action =
'edit_extras';
389 if ($action ==
"confirm_validate" &&
GETPOST(
"confirm",
'alpha') ==
"yes" && $id > 0 && $permissiontoadd) {
395 $result =
$object->setValidate($user);
400 $outputlangs = $langs;
403 $newlang =
GETPOST(
'lang_id',
'aZ09');
406 $newlang =
$object->thirdparty->default_lang;
408 if (!empty($newlang)) {
410 $outputlangs->setDefaultLang($newlang);
415 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
422 if (!$error && $result > 0 &&
$object->fk_user_validator > 0) {
423 $langs->load(
"mails");
426 $destinataire =
new User($db);
427 $destinataire->fetch(
$object->fk_user_validator);
428 $emailTo = $destinataire->email;
431 $expediteur =
new User($db);
432 $expediteur->fetch(
$object->fk_user_author);
435 if ($emailTo && $emailFrom) {
446 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportWaitingForApproval");
449 $link = $urlwithroot.
'/expensereport/card.php?id='.
$object->id;
450 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
451 $message = $langs->transnoentities(
"ExpenseReportWaitingForApprovalMessage", $expediteur->getFullName($langs),
get_date_range(
$object->date_debut,
$object->date_fin,
'', $langs), $link);
466 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
468 if (!empty($mailfile->error)) {
470 $result = $mailfile->sendfile();
472 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
475 $langs->load(
"other");
476 if ($mailfile->error) {
478 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
479 $mesg .=
'<br>'.$mailfile->error;
482 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
490 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
497 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
504 if ($action ==
"confirm_save_from_refuse" &&
GETPOST(
"confirm",
'alpha') ==
"yes" && $id > 0 && $permissiontoadd) {
507 $result =
$object->set_save_from_refuse($user);
512 $outputlangs = $langs;
515 $newlang =
GETPOST(
'lang_id',
'aZ09');
518 $newlang =
$object->thirdparty->default_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>';
561 $message .=
'<br>'.$langs->transnoentities(
"ExpenseReportWaitingForReApprovalMessage2", $link);
580 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
582 if (!empty($mailfile->error)) {
584 $result = $mailfile->sendfile();
586 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
588 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
591 $langs->load(
"other");
592 if ($mailfile->error) {
594 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
595 $mesg .=
'<br>'.$mailfile->error;
598 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
606 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
615 if ($action ==
"confirm_approve" &&
GETPOST(
"confirm",
'alpha') ==
"yes" && $id > 0 && $user->hasRight(
'expensereport',
'approve')) {
619 $result =
$object->setApproved($user);
624 $outputlangs = $langs;
627 $newlang =
GETPOST(
'lang_id',
'aZ09');
630 $newlang =
$object->thirdparty->default_lang;
632 if (!empty($newlang)) {
634 $outputlangs->setDefaultLang($newlang);
639 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
647 $destinataire =
new User($db);
648 $destinataire->fetch(
$object->fk_user_author);
649 $emailTo = $destinataire->email;
653 if (empty($emailTo)) {
658 $expediteur =
new User($db);
659 $expediteur->fetch(
$object->fk_user_approve > 0 ?
$object->fk_user_approve :
$object->fk_user_validator);
662 if ($emailFrom && $emailTo) {
673 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportApproved");
676 $link = $urlwithroot.
'/expensereport/card.php?id='.
$object->id;
677 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
678 $message = $langs->transnoentities(
"ExpenseReportApprovedMessage",
$object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $link);
695 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, $emailCC,
'', 0, -1);
697 if (!empty($mailfile->error)) {
699 $result = $mailfile->sendfile();
701 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
703 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
706 $langs->load(
"other");
707 if ($mailfile->error) {
709 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
710 $mesg .=
'<br>'.$mailfile->error;
713 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
721 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
730 if ($action ==
"confirm_refuse" &&
GETPOST(
'confirm',
'alpha') ==
"yes" && $id > 0 && $user->hasRight(
'expensereport',
'approve')) {
734 $detailRefuse =
GETPOST(
'detail_refuse',
'alpha');
735 $result =
$object->setDeny($user, $detailRefuse);
740 $outputlangs = $langs;
743 $newlang =
GETPOST(
'lang_id',
'aZ09');
746 $newlang =
$object->thirdparty->default_lang;
748 if (!empty($newlang)) {
750 $outputlangs->setDefaultLang($newlang);
755 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
763 $destinataire =
new User($db);
764 $destinataire->fetch(
$object->fk_user_author);
765 $emailTo = $destinataire->email;
768 $expediteur =
new User($db);
769 $expediteur->fetch(
$object->fk_user_refuse);
772 if ($emailFrom && $emailTo) {
783 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportRefused");
786 $link = $urlwithroot.
'/expensereport/card.php?id='.
$object->id;
787 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
788 $message = $langs->transnoentities(
"ExpenseReportRefusedMessage",
$object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $detailRefuse, $link);
806 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
808 if (!empty($mailfile->error)) {
810 $result = $mailfile->sendfile();
812 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
814 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
817 $langs->load(
"other");
818 if ($mailfile->error) {
820 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
821 $mesg .=
'<br>'.$mailfile->error;
824 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
832 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
842 if ($action ==
"confirm_cancel" &&
GETPOST(
'confirm',
'alpha') ==
"yes" && $id > 0 && $user->hasRight(
'expensereport',
'creer')) {
843 if (!
GETPOST(
'detail_cancel',
'alpha')) {
844 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Comment")),
null,
'errors');
849 if ($user->id ==
$object->fk_user_valid || $user->id ==
$object->fk_user_author) {
850 $detailCancel =
GETPOST(
'detail_cancel',
'alpha');
851 $result =
$object->set_cancel($user, $detailCancel);
856 $outputlangs = $langs;
859 $newlang =
GETPOST(
'lang_id',
'aZ09');
862 $newlang =
$object->thirdparty->default_lang;
864 if (!empty($newlang)) {
866 $outputlangs->setDefaultLang($newlang);
871 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
879 $destinataire =
new User($db);
880 $destinataire->fetch(
$object->fk_user_author);
881 $emailTo = $destinataire->email;
884 $expediteur =
new User($db);
885 $expediteur->fetch(
$object->fk_user_cancel);
888 if ($emailFrom && $emailTo) {
899 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportCanceled");
902 $link = $urlwithroot.
'/expensereport/card.php?id='.
$object->id;
903 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
904 $message = $langs->transnoentities(
"ExpenseReportCanceledMessage",
$object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $detailCancel, $link);
922 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
924 if (!empty($mailfile->error)) {
926 $result = $mailfile->sendfile();
928 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
930 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
933 $langs->load(
"other");
934 if ($mailfile->error) {
936 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
937 $mesg .=
'<br>'.$mailfile->error;
940 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
948 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
961 if ($action ==
"confirm_setdraft" &&
GETPOST(
'confirm',
'alpha') ==
"yes" && $id > 0 && $user->hasRight(
'expensereport',
'creer')) {
964 if ($user->id ==
$object->fk_user_author || $user->id ==
$object->fk_user_valid || in_array(
$object->fk_user_author, $childids)) {
965 $result =
$object->setStatut(0);
970 $outputlangs = $langs;
973 $newlang =
GETPOST(
'lang_id',
'aZ09');
976 $newlang =
$object->thirdparty->default_lang;
978 if (!empty($newlang)) {
980 $outputlangs->setDefaultLang($newlang);
985 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
990 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
1000 if ($action ==
'set_unpaid' && $id > 0 && $user->hasRight(
'expensereport',
'to_paid')) {
1004 $result =
$object->setUnpaid($user);
1009 $outputlangs = $langs;
1012 $newlang =
GETPOST(
'lang_id',
'aZ09');
1015 $newlang =
$object->thirdparty->default_lang;
1017 if (!empty($newlang)) {
1019 $outputlangs->setDefaultLang($newlang);
1024 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1029 if ($action ==
'set_paid' && $id > 0 && $user->hasRight(
'expensereport',
'to_paid')) {
1033 $result =
$object->setPaid($id, $user);
1038 $outputlangs = $langs;
1041 $newlang =
GETPOST(
'lang_id',
'aZ09');
1044 $newlang =
$object->thirdparty->default_lang;
1046 if (!empty($newlang)) {
1048 $outputlangs->setDefaultLang($newlang);
1053 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1061 $destinataire =
new User($db);
1062 $destinataire->fetch(
$object->fk_user_author);
1063 $emailTo = $destinataire->email;
1066 $expediteur =
new User($db);
1067 $expediteur->fetch($user->id);
1070 if ($emailFrom && $emailTo) {
1071 $filename = array();
1073 $mimetype = array();
1081 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportPaid");
1084 $link = $urlwithroot.
'/expensereport/card.php?id='.
$object->id;
1085 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
1086 $message = $langs->transnoentities(
"ExpenseReportPaidMessage",
$object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $link);
1089 $object->setDocModel($user,
"");
1090 $resultPDF = expensereport_pdf_create($db,
$object,
'',
"", $langs);
1093 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
1095 if (!empty($mailfile->error)) {
1097 $result = $mailfile->sendfile();
1099 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
1101 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
1104 $langs->load(
"other");
1105 if ($mailfile->error) {
1107 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
1108 $mesg .=
'<br>'.$mailfile->error;
1111 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
1119 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
1128 if ($action ==
"addline" && $user->hasRight(
'expensereport',
'creer')) {
1131 if (GETPOSTISSET(
'attachfile')) {
1132 $arrayoffiles =
GETPOST(
'attachfile',
'array');
1133 if (is_array($arrayoffiles) && !empty($arrayoffiles[0])) {
1134 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1135 $entityprefix = (
$conf->entity !=
'1') ?
$conf->entity.
'/' :
'';
1136 $relativepath =
'expensereport/'.$object->ref.
'/'.$arrayoffiles[0];
1138 $ecmfiles->fetch(0,
'', $relativepath);
1139 $fk_ecm_files = $ecmfiles->id;
1144 if (empty($vatrate)) {
1147 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $vatrate));
1151 if (empty($value_unit)) {
1152 $value_unit =
price2num((
float) $value_unit_ht + ((
float) $value_unit_ht * (
float) $tmpvat / 100),
'MU');
1155 $fk_c_exp_tax_cat =
GETPOSTINT(
'fk_c_exp_tax_cat');
1162 if (!($fk_c_type_fees > 0)) {
1164 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1168 if ((
float) $tmpvat < 0 || $tmpvat ===
'') {
1170 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"VAT")),
null,
'errors');
1175 if (empty($date) || $date ==
"--") {
1177 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1178 } elseif ($date < $object->date_debut || $date > (
$object->date_fin + (24 * 3600 - 1))) {
1184 $langs->load(
"errors");
1185 $type = $error > 0 ?
'errors' :
'warnings';
1186 setEventMessages($langs->trans(
"WarningDateOfLineMustBeInExpenseReportRange"),
null, $type);
1190 if ($value_unit == 0) {
1192 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"PriceUTTC")),
null,
'errors');
1196 if ($projectRequired && $fk_project <= 0) {
1198 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Project")),
null,
'errors');
1202 if ($fileRequired && $fk_ecm_files == 0) {
1204 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"File")),
null,
'errors');
1211 $result =
$object->addline($qty, $value_unit, $fk_c_type_fees, $vatrate, $date, $comments, $fk_project, $fk_c_exp_tax_cat, $type, $fk_ecm_files);
1217 $outputlangs = $langs;
1218 $newlang =
GETPOST(
'lang_id',
'alpha');
1220 $user =
new User($db);
1221 $user->fetch(
$object->fk_user_author);
1222 $newlang = $user->lang;
1224 if (!empty($newlang)) {
1226 $outputlangs->setDefaultLang($newlang);
1229 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1233 unset($value_unit_ht);
1237 unset($fk_c_type_fees);
1248 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
GETPOSTINT(
'id'));
1255 if ($action ==
'confirm_delete_line' &&
GETPOST(
"confirm",
'alpha') ==
"yes" && $user->hasRight(
'expensereport',
'creer')) {
1261 $total_ht = $object_ligne->total_ht;
1262 $total_tva = $object_ligne->total_tva;
1269 $outputlangs = $langs;
1272 $newlang =
GETPOST(
'lang_id',
'aZ09');
1275 $newlang =
$object->thirdparty->default_lang;
1277 if (!empty($newlang)) {
1279 $outputlangs->setDefaultLang($newlang);
1284 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1288 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
GETPOSTINT(
'id'));
1295 if ($action ==
"updateline" && $permissiontoadd) {
1301 if (GETPOSTISSET(
'attachfile')) {
1302 $arrayoffiles =
GETPOST(
'attachfile',
'array');
1303 if (is_array($arrayoffiles) && !empty($arrayoffiles[0])) {
1304 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1305 $relativepath =
'expensereport/'.$object->ref.
'/'.$arrayoffiles[0];
1307 $ecmfiles->fetch(0,
'', $relativepath);
1308 $fk_ecm_files = $ecmfiles->id;
1313 $type_fees_id =
GETPOSTINT(
'fk_c_type_fees');
1314 $fk_c_exp_tax_cat =
GETPOSTINT(
'fk_c_exp_tax_cat');
1315 $projet_id = $fk_project;
1316 $comments =
GETPOST(
'comments',
'restricthtml');
1318 $vatrate =
GETPOST(
'vatrate',
'alpha');
1321 if (empty($vatrate)) {
1324 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $vatrate));
1328 if (empty($value_unit)) {
1329 $value_unit =
price2num((
float) $value_unit_ht + ((
float) $value_unit_ht * (
float) $tmpvat / 100),
'MU');
1334 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1337 if ((
float) $tmpvat < 0 || $tmpvat ==
'') {
1339 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Vat")),
null,
'errors');
1343 if ($date < $object->date_debut || $date > (
$object->date_fin + (24 * 3600 - 1))) {
1348 $langs->load(
"errors");
1349 $type = $error > 0 ?
'errors' :
'warnings';
1350 setEventMessages($langs->trans(
"WarningDateOfLineMustBeInExpenseReportRange"),
null, $type);
1354 if ($projectRequired && $projet_id <= 0) {
1356 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Project")),
null,
'errors');
1361 $result =
$object->updateline($rowid, $type_fees_id, $projet_id, $vatrate, $comments, $qty, $value_unit, $date, $id, $fk_c_exp_tax_cat, $fk_ecm_files);
1366 $outputlangs = $langs;
1369 $newlang =
GETPOST(
'lang_id',
'aZ09');
1372 $newlang =
$object->thirdparty->default_lang;
1374 if (!empty($newlang)) {
1376 $outputlangs->setDefaultLang($newlang);
1381 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1385 unset($value_unit_ht);
1389 unset($fk_c_type_fees);
1403 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
1406 $triggersendname =
'EXPENSEREPORT_SENTBYMAIL';
1407 $autocopy =
'MAIN_MAIL_AUTOCOPY_EXPENSEREPORT_TO';
1408 $trackid =
'exp'.$object->id;
1409 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
1412 $upload_dir =
$conf->expensereport->dir_output;
1413 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1421$title = $langs->trans(
"ExpenseReport").
" - ".$langs->trans(
"Card");
1422$help_url =
"EN:Module_Expense_Reports|FR:Module_Notes_de_frais";
1426$form =
new Form($db);
1429$projecttmp =
new Project($db);
1431$bankaccountstatic =
new Account($db);
1432$ecmfilesstatic =
new EcmFiles($db);
1436if ($action ==
'create') {
1439 print
'<form action="'.$_SERVER[
'PHP_SELF'].
'" method="post" name="create">';
1440 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1441 print
'<input type="hidden" name="action" value="add">';
1442 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
1446 print
'<table class="border centpercent">';
1451 print
'<td class="titlefieldcreate fieldrequired">'.$langs->trans(
"DateStart").
'</td>';
1453 print $form->selectDate($date_start ? $date_start : -1,
'date_debut', 0, 0, 0,
'', 1, 1);
1459 print
'<td class="fieldrequired">'.$langs->trans(
"DateEnd").
'</td>';
1461 print $form->selectDate($date_end ? $date_end : -1,
'date_fin', 0, 0, 0,
'', 1, 1);
1467 print
'<td class="fieldrequired">'.$langs->trans(
"User").
'</td>';
1469 $defaultselectuser = $user->id;
1471 $defaultselectuser =
GETPOSTINT(
'fk_user_author');
1473 $include_users =
'hierarchyme';
1474 if (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'expensereport',
'writeall_advance')) {
1475 $include_users = array();
1477 $s = $form->select_dolusers($defaultselectuser,
"fk_user_author", 0,
"", 0, $include_users,
'',
'0,'.
$conf->entity);
1484 print
'<td>'.$langs->trans(
"VALIDATOR").
'</td>';
1487 $include_users =
$object->fetch_users_approver_expensereport();
1488 if (empty($include_users)) {
1489 print
img_warning().
' '.$langs->trans(
"NobodyHasPermissionToValidateExpenseReport");
1491 $defaultselectuser = (empty($user->fk_user_expense_validator) ? $user->fk_user : $user->fk_user_expense_validator);
1496 $defaultselectuser =
GETPOSTINT(
'fk_user_validator');
1498 $s = $form->select_dolusers($defaultselectuser,
"fk_user_validator", 1,
"", ((empty($defaultselectuser) || !
getDolGlobalString(
'EXPENSEREPORT_DEFAULT_VALIDATOR_UNCHANGEABLE')) ? 0 : 1), $include_users);
1499 print $form->textwithpicto($s, $langs->trans(
"AnyOtherInThisListCanValidate"));
1507 print
'<td>'.$langs->trans(
"ModePaiement").
'</td>';
1509 $form->select_types_paiements(
'',
'fk_c_paiement');
1515 $note_public = GETPOSTISSET(
'note_public') ?
GETPOST(
'note_public',
'restricthtml') :
'';
1518 print
'<td class="tdtop">'.$langs->trans(
'NotePublic').
'</td>';
1521 $doleditor =
new DolEditor(
'note_public', $note_public,
'', 80,
'dolibarr_notes',
'In',
false,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3,
'90%');
1522 print $doleditor->Create(1);
1526 $note_private = GETPOSTISSET(
'note_private') ?
GETPOST(
'note_private',
'restricthtml') :
'';
1528 if (empty($user->socid)) {
1530 print
'<td class="tdtop">'.$langs->trans(
'NotePrivate').
'</td>';
1533 $doleditor =
new DolEditor(
'note_private', $note_private,
'', 80,
'dolibarr_notes',
'In',
false,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3,
'90%');
1534 print $doleditor->Create(1);
1539 $parameters = array(
'colspan' =>
' colspan="3"',
'cols' => 3);
1540 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters,
$object, $action);
1541 print $hookmanager->resPrint;
1542 if (empty($reshook)) {
1543 print
$object->showOptionals($extrafields,
'create', $parameters);
1551 print $form->buttonsSaveCancel(
"AddTrip");
1554} elseif ($id > 0 || $ref) {
1555 $result =
$object->fetch($id, $ref);
1558 if (!in_array(
$object->fk_user_author, $childids)) {
1559 if (!$user->hasRight(
'expensereport',
'readall') && !$user->hasRight(
'expensereport',
'lire_tous')
1560 && (!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') || !$user->hasRight(
'expensereport',
'writeall_advance'))) {
1563 print
'<div class="tabBar">';
1564 print $langs->trans(
'NotUserRightToView');
1578 print
"<form name='update' action=\"".$_SERVER[
'PHP_SELF'].
"\" method=\"post\">\n";
1579 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1580 print
'<input type="hidden" name="id" value="'.$id.
'">';
1581 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
1586 print
'<input type="hidden" name="action" value="updateFromRefuse">';
1588 print
'<input type="hidden" name="action" value="update">';
1591 $linkback =
'<a href="'.DOL_URL_ROOT.
'/expensereport/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
1593 print
'<table class="border centpercent">';
1596 print
'<td>'.$langs->trans(
"User").
'</td>';
1598 $userfee =
new User($db);
1599 if (
$object->fk_user_author > 0) {
1600 $userfee->fetch(
$object->fk_user_author);
1601 print $userfee->getNomUrl(-1);
1606 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Ref").
'</td><td>';
1607 print $form->showrefnav(
$object,
'ref', $linkback, 1,
'ref',
'ref',
'');
1611 print
'<td>'.$langs->trans(
"DateStart").
'</td>';
1613 print $form->selectDate(
$object->date_debut,
'date_debut');
1617 print
'<td>'.$langs->trans(
"DateEnd").
'</td>';
1619 print $form->selectDate(
$object->date_fin,
'date_fin');
1625 print
'<td>'.$langs->trans(
"ModePaiement").
'</td>';
1627 $form->select_types_paiements(
$object->fk_c_paiement,
'fk_c_paiement');
1634 print
'<td>'.$langs->trans(
"VALIDATOR").
'</td>';
1636 $include_users =
$object->fetch_users_approver_expensereport();
1637 $s = $form->select_dolusers(
$object->fk_user_validator,
"fk_user_validator", 1,
"", 0, $include_users);
1638 print $form->textwithpicto($s, $langs->trans(
"AnyOtherInThisListCanValidate"));
1643 print
'<td>'.$langs->trans(
"VALIDOR").
'</td>';
1645 $userfee =
new User($db);
1646 $userfee->fetch(
$object->fk_user_valid);
1647 print $userfee->getNomUrl(-1);
1653 print
'<td>'.$langs->trans(
"AUTHORPAIEMENT").
'</td>';
1655 $userfee =
new User($db);
1656 $userfee->fetch($user->id);
1657 print $userfee->getNomUrl(-1);
1669 print $form->buttonsSaveCancel(
"Modify");
1673 $taxlessUnitPriceDisabled =
getDolGlobalString(
'EXPENSEREPORT_FORCE_LINE_AMOUNTS_INCLUDING_TAXES_ONLY') ?
' disabled' :
'';
1680 if ($action ==
'clone') {
1682 $criteriaforfilter =
'hierarchyme';
1683 if ($user->hasRight(
'expensereport',
'readall')) {
1684 $criteriaforfilter =
'';
1686 $formquestion = array(
1688 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'))
1691 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneExpenseReport',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1);
1694 if ($action ==
'save') {
1695 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"SaveTrip"), $langs->trans(
"ConfirmSaveTrip"),
"confirm_validate",
"",
"", 1);
1698 if ($action ==
'save_from_refuse') {
1699 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"SaveTrip"), $langs->trans(
"ConfirmSaveTrip"),
"confirm_save_from_refuse",
"",
"", 1);
1702 if ($action ==
'delete') {
1703 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"DeleteTrip"), $langs->trans(
"ConfirmDeleteTrip"),
"confirm_delete",
"",
"", 1);
1706 if ($action ==
'validate') {
1707 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"ValideTrip"), $langs->trans(
"ConfirmValideTrip"),
"confirm_approve",
"",
"", 1);
1710 if ($action ==
'paid') {
1711 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"PaidTrip"), $langs->trans(
"ConfirmPaidTrip"),
"confirm_paid",
"",
"", 1);
1714 if ($action ==
'cancel') {
1715 $array_input = array(
'text' => $langs->trans(
"ConfirmCancelTrip"), 0 => array(
'type' =>
"text",
'label' =>
'<strong>'.$langs->trans(
"Comment").
'</strong>',
'name' =>
"detail_cancel",
'value' =>
""));
1716 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"Cancel"),
"",
"confirm_cancel", $array_input,
"", 1);
1719 if ($action ==
'setdraft') {
1720 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"BrouillonnerTrip"), $langs->trans(
"ConfirmBrouillonnerTrip"),
"confirm_setdraft",
"",
"", 1);
1723 if ($action ==
'refuse') {
1724 $array_input = array(
'text' => $langs->trans(
"ConfirmRefuseTrip"), 0 => array(
'type' =>
"text",
'label' => $langs->trans(
"Comment"),
'name' =>
"detail_refuse",
'value' =>
""));
1725 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"Deny"),
'',
"confirm_refuse", $array_input,
"yes", 1);
1728 if ($action ==
'delete_line') {
1729 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".
$id.
"&rowid=".
GETPOSTINT(
'rowid'), $langs->trans(
"DeleteLine"), $langs->trans(
"ConfirmDeleteLine"),
"confirm_delete_line",
'',
'yes', 1);
1733 $parameters = array(
'formConfirm' => $formconfirm);
1734 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters,
$object, $action);
1735 if (empty($reshook)) {
1736 $formconfirm .= $hookmanager->resPrint;
1737 } elseif ($reshook > 0) {
1738 $formconfirm = $hookmanager->resPrint;
1745 $linkback =
'<a href="'.DOL_URL_ROOT.
'/expensereport/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
1747 $morehtmlref =
'<div class="refidno">';
1748 $morehtmlref .=
'</div>';
1750 dol_banner_tab(
$object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
1752 print
'<div class="fichecenter">';
1753 print
'<div class="fichehalfleft">';
1754 print
'<div class="underbanner clearboth"></div>';
1756 print
'<table class="border tableforfield centpercent">';
1760 print
'<td class="titlefield">'.$langs->trans(
"User").
'</td>';
1762 if (
$object->fk_user_author > 0) {
1763 $userauthor =
new User($db);
1764 $result = $userauthor->fetch(
$object->fk_user_author);
1767 } elseif ($result > 0) {
1768 print $userauthor->getNomUrl(-1);
1775 print
'<td class="titlefield">'.$langs->trans(
"Period").
'</td>';
1782 print
'<td>'.$langs->trans(
"ModePaiement").
'</td>';
1783 print
'<td>'.$object->fk_c_paiement.
'</td>';
1789 print
'<td>'.$langs->trans(
"DATE_SAVE").
'</td>';
1790 print
'<td>'.dol_print_date(
$object->date_valid,
'dayhour',
'tzuser');
1792 print
' '.img_warning($langs->trans(
"Late").
' - '.$langs->trans(
"ToApprove"));
1795 print
' '.img_warning($langs->trans(
"Late").
' - '.$langs->trans(
"ToPay"));
1803 print
'<td>'.$langs->trans(
"VALIDATOR").
'</td>';
1805 if (
$object->fk_user_validator > 0) {
1806 $userfee =
new User($db);
1807 $result = $userfee->fetch(
$object->fk_user_validator);
1809 print $userfee->getNomUrl(-1);
1811 if (empty($userfee->email) || !
isValidEmail($userfee->email)) {
1812 $langs->load(
"errors");
1813 print
img_warning($langs->trans(
"ErrorBadEMail", $userfee->email));
1819 print
'<td>'.$langs->trans(
"CANCEL_USER").
'</span></td>';
1821 if (
$object->fk_user_cancel > 0) {
1822 $userfee =
new User($db);
1823 $result = $userfee->fetch(
$object->fk_user_cancel);
1825 print $userfee->getNomUrl(-1);
1831 print
'<td>'.$langs->trans(
"MOTIF_CANCEL").
'</td>';
1832 print
'<td>'.$object->detail_cancel.
'</td></tr>';
1835 print
'<td>'.$langs->trans(
"DATE_CANCEL").
'</td>';
1836 print
'<td>'.dol_print_date(
$object->date_cancel,
'dayhour',
'tzuser').
'</td></tr>';
1840 print
'<td>'.$langs->trans(
"ApprovedBy").
'</td>';
1842 if (
$object->fk_user_approve > 0) {
1843 $userapp =
new User($db);
1844 $result = $userapp->fetch(
$object->fk_user_approve);
1846 print $userapp->getNomUrl(-1);
1852 print
'<td>'.$langs->trans(
"DateApprove").
'</td>';
1853 print
'<td>'.dol_print_date(
$object->date_approve,
'dayhour',
'tzuser').
'</td></tr>';
1859 print
'<td>'.$langs->trans(
"REFUSEUR").
'</td>';
1861 $userfee =
new User($db);
1862 $result = $userfee->fetch(
$object->fk_user_refuse);
1864 print $userfee->getNomUrl(-1);
1869 print
'<td>'.$langs->trans(
"DATE_REFUS").
'</td>';
1870 print
'<td>'.dol_print_date(
$object->date_refuse,
'dayhour',
'tzuser');
1872 print
' - '.$object->detail_refuse;
1878 if (
$object->status == $object::STATUS_CLOSED) {
1896 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
1901 print
'<div class="fichehalfright">';
1902 print
'<div class="underbanner clearboth"></div>';
1904 print
'<table class="border tableforfield centpercent">';
1908 print
'<td class="titlefieldmiddle">'.$langs->trans(
"AmountHT").
'</td>';
1909 print
'<td class="nowrap amountcard">'.price(
$object->total_ht, 1,
'', 1, - 1, - 1,
$conf->currency).
'</td>';
1926 print
'<td>'.$langs->trans(
"AmountVAT").
'</td>';
1927 print
'<td class="nowrap amountcard">'.price(
$object->total_tva, 1,
'', 1, -1, -1,
$conf->currency).
'</td>';
1931 if ($mysoc->localtax1_assuj ==
"1" ||
$object->total_localtax1 != 0) {
1932 print
'<tr><td>'.$langs->transcountry(
"AmountLT1", $mysoc->country_code).
'</td>';
1933 print
'<td class="valuefield">'.price(
$object->total_localtax1, 1,
'', 1, -1, -1,
$conf->currency).
'</td></tr>';
1935 if ($mysoc->localtax2_assuj ==
"1" ||
$object->total_localtax2 != 0) {
1936 print
'<tr><td>'.$langs->transcountry(
"AmountLT2", $mysoc->country_code).
'</td>';
1937 print
'<td class="valuefield">'.price(
$object->total_localtax2, 1,
'', 1, -1, -1,
$conf->currency).
'</td></tr>';
1941 print
'<td>'.$langs->trans(
"AmountTTC").
'</td>';
1942 print
'<td class="nowrap amountcard">'.price(
$object->total_ttc, 1,
'', 1, -1, -1,
$conf->currency).
'</td>';
1948 if (isModEnabled(
"bank")) {
1953 print
'<table class="noborder paymenttable centpercent">';
1955 print
'<tr class="liste_titre">';
1956 print
'<td class="liste_titre">'.$langs->trans(
'Payments').
'</td>';
1957 print
'<td class="liste_titre">'.$langs->trans(
'Date').
'</td>';
1958 print
'<td class="liste_titre">'.$langs->trans(
'Type').
'</td>';
1959 if (isModEnabled(
"bank")) {
1960 print
'<td class="liste_titre right">'.$langs->trans(
'BankAccount').
'</td>';
1962 print
'<td class="liste_titre right">'.$langs->trans(
'Amount').
'</td>';
1963 print
'<td class="liste_titre" width="18"> </td>';
1967 $sql =
"SELECT p.rowid, p.num_payment, p.datep as dp, p.amount, p.fk_bank,";
1968 $sql .=
"c.code as payment_code, c.libelle as payment_type,";
1969 $sql .=
"ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal";
1970 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as e, ".MAIN_DB_PREFIX.
"payment_expensereport as p";
1971 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON p.fk_typepayment = c.id";
1972 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
1973 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
1974 $sql .=
" WHERE e.rowid = ".((int) $id);
1975 $sql .=
" AND p.fk_expensereport = e.rowid";
1976 $sql .=
' AND e.entity IN ('.getEntity(
'expensereport').
')';
1977 $sql .=
" ORDER BY dp";
1979 $resql = $db->query($sql);
1981 $num = $db->num_rows($resql);
1985 $objp = $db->fetch_object($resql);
1987 $paymentexpensereportstatic->id = $objp->rowid;
1988 $paymentexpensereportstatic->datep = $db->jdate($objp->dp);
1989 $paymentexpensereportstatic->ref = $objp->rowid;
1990 $paymentexpensereportstatic->num_payment = $objp->num_payment;
1991 $paymentexpensereportstatic->type_code = $objp->payment_code;
1992 $paymentexpensereportstatic->type_label = $objp->payment_type;
1994 print
'<tr class="oddeven">';
1996 print $paymentexpensereportstatic->getNomUrl(1);
1998 print
'<td>'.dol_print_date($db->jdate($objp->dp),
'day').
"</td>\n";
1999 $labeltype = $langs->trans(
"PaymentType".$objp->payment_code) !=
"PaymentType".$objp->payment_code ? $langs->trans(
"PaymentType".$objp->payment_code) : $objp->payment_type;
2000 print
"<td>".$labeltype.
' '.$objp->num_payment.
"</td>\n";
2002 if (isModEnabled(
"bank")) {
2003 $bankaccountstatic->id = $objp->baid;
2004 $bankaccountstatic->ref = $objp->baref;
2005 $bankaccountstatic->label = $objp->baref;
2006 $bankaccountstatic->number = $objp->banumber;
2008 if (isModEnabled(
'accounting')) {
2009 $bankaccountstatic->account_number = $objp->account_number;
2012 $accountingjournal->fetch($objp->fk_accountancy_journal);
2013 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
2016 print
'<td class="right">';
2017 if ($bankaccountstatic->id) {
2018 print $bankaccountstatic->getNomUrl(1,
'transactions');
2022 print
'<td class="right">'.price($objp->amount).
"</td>";
2025 $totalpaid += $objp->amount;
2031 $resteapayeraffiche = $remaintopay;
2033 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
2036 $cssforamountpaymentcomplete =
'amountpaymentneutral';
2037 $resteapayeraffiche = 0;
2038 } elseif (
$object->paid == 0) {
2039 $cssforamountpaymentcomplete =
'amountpaymentneutral';
2041 print
'<tr><td colspan="'.$nbcols.
'" class="right">'.$langs->trans(
"AlreadyPaid").
':</td><td class="right">'.
price($totalpaid).
'</td><td></td></tr>';
2042 print
'<tr><td colspan="'.$nbcols.
'" class="right">'.$langs->trans(
"AmountExpected").
':</td><td class="right">'.
price(
$object->total_ttc).
'</td><td></td></tr>';
2044 print
'<tr><td colspan="'.$nbcols.
'" class="right">'.$langs->trans(
"RemainderToPay").
':</td>';
2045 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td><td></td></tr>';
2056 print
'<div class="clearboth"></div><br><br>';
2058 print
'<div style="clear: both;"></div>';
2060 $actiontouse =
'updateline';
2062 $actiontouse =
'addline';
2065 print
'<form name="expensereport" action="'.$_SERVER[
"PHP_SELF"].
'" enctype="multipart/form-data" method="post" >';
2066 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2067 print
'<input type="hidden" name="action" value="'.$actiontouse.
'">';
2068 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
2069 print
'<input type="hidden" name="fk_expensereport" value="'.$object->id.
'" />';
2070 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
2071 print
'<input type="hidden" name="page_y" value="">';
2073 print
'<div class="div-table-responsive-no-min">';
2074 print
'<table id="tablelines" class="noborder centpercent">';
2080 print
'<tr class="liste_titre headerexpensereportdet">';
2081 print
'<td class="center linecollinenb">'.$langs->trans(
'LineNb').
'</td>';
2083 print
'<td class="center linecoldate">'.$langs->trans(
'Date').
'</td>';
2084 if (isModEnabled(
'project')) {
2085 print
'<td class="minwidth100imp linecolproject">'.$langs->trans(
'Project').
'</td>';
2087 print
'<td class="center linecoltype">'.$langs->trans(
'Type').
'</td>';
2089 print
'<td class="center linecolcarcategory">'.$langs->trans(
'CarCategory').
'</td>';
2091 print
'<td class="linecoldescription">'.$langs->trans(
'Description').
'</td>';
2092 print
'<td class="right linecolvat">'.$langs->trans(
'VAT').
'</td>';
2093 print
'<td class="right linecolpriceuht">'.$langs->trans(
'PriceUHT').
'</td>';
2094 print
'<td class="right linecolpriceuttc">'.$langs->trans(
'PriceUTTC').
'</td>';
2095 print
'<td class="right linecolqty">'.$langs->trans(
'Qty').
'</td>';
2096 if ($action !=
'editline') {
2097 print
'<td class="right linecolamountht">'.$langs->trans(
'AmountHT').
'</td>';
2098 print
'<td class="right linecolamountttc">'.$langs->trans(
'AmountTTC').
'</td>';
2110 print
'<td class="right"></td>';
2114 foreach (
$object->lines as &$line) {
2117 if ($action !=
'editline' || $line->id !=
GETPOSTINT(
'rowid')) {
2118 print
'<tr class="oddeven linetr" data-id="'.$line->id.
'">';
2121 print
'<td class="center linecollinenb">';
2126 print
'<td class="center linecoldate">'.dol_print_date($db->jdate($line->date),
'day').
'</td>';
2129 if (isModEnabled(
'project')) {
2130 print
'<td class="lineproject">';
2131 if ($line->fk_project > 0) {
2132 $projecttmp->id = $line->fk_project;
2133 $projecttmp->ref = $line->projet_ref;
2134 $projecttmp->title = $line->projet_title;
2135 print $projecttmp->getNomUrl(1);
2141 if (isModEnabled(
'accounting')) {
2142 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
2144 $resaccountingaccount = $accountingaccount->fetch(0, $line->type_fees_accountancy_code, 1);
2146 $titlealt .= $langs->trans(
"AccountancyCode").
': ';
2147 if ($resaccountingaccount > 0) {
2148 $titlealt .= $accountingaccount->account_number;
2150 $titlealt .= $langs->trans(
"NotFound");
2156 print
'<td class="center linecoltype" title="'.dol_escape_htmltag($titlealt).
'">';
2157 $labeltype = ($langs->trans(($line->type_fees_code)) == $line->type_fees_code ? $line->type_fees_libelle : $langs->trans($line->type_fees_code));
2163 print
'<td class="fk_c_exp_tax_cat linecoltaxcat">';
2164 $exp_tax_cat_label =
dol_getIdFromCode($db, $line->fk_c_exp_tax_cat,
'c_exp_tax_cat',
'rowid',
'label');
2165 print $langs->trans($exp_tax_cat_label);
2170 print
'<td class="left linecolcomment">'.dol_nl2br($line->comments).
'</td>';
2173 $senderissupplier = 0;
2174 $tooltiponprice =
'';
2175 $tooltiponpriceend =
'';
2177 $tooltiponprice = $langs->transcountry(
"TotalHT", $mysoc->country_code).
'='.
price($line->total_ht);
2178 $tooltiponprice .=
'<br>'.$langs->transcountry(
"TotalVAT", ($senderissupplier ?
$object->thirdparty->country_code : $mysoc->country_code)).
'='.
price($line->total_tva);
2179 if (is_object(
$object->thirdparty)) {
2180 if ($senderissupplier) {
2181 $seller =
$object->thirdparty;
2188 if ($mysoc->useLocalTax(1)) {
2189 if (($seller->country_code == $buyer->country_code) || $line->total_localtax1 || $seller->useLocalTax(1)) {
2190 $tooltiponprice .=
'<br>'.$langs->transcountry(
"TotalLT1", $seller->country_code).
'='.
price($line->total_localtax1);
2192 $tooltiponprice .=
'<br>'.$langs->transcountry(
"TotalLT1", $seller->country_code).
'=<span class="opacitymedium">'.$langs->trans($senderissupplier ?
"NotUsedForThisVendor" :
"NotUsedForThisCustomer").
'</span>';
2195 if ($mysoc->useLocalTax(2)) {
2196 if ((isset($seller->country_code) && isset($buyer->thirdparty->country_code) && $seller->country_code == $buyer->thirdparty->country_code) || $line->total_localtax2 || $seller->useLocalTax(2)) {
2197 $tooltiponprice .=
'<br>'.$langs->transcountry(
"TotalLT2", $seller->country_code).
'='.
price($line->total_localtax2);
2199 $tooltiponprice .=
'<br>'.$langs->transcountry(
"TotalLT2", $seller->country_code).
'=<span class="opacitymedium">'.$langs->trans($senderissupplier ?
"NotUsedForThisVendor" :
"NotUsedForThisCustomer").
'</span>';
2203 $tooltiponprice .=
'<br>'.$langs->transcountry(
"TotalTTC", $mysoc->country_code).
'='.
price($line->total_ttc);
2205 $tooltiponprice =
'<span class="classfortooltip" title="'.dol_escape_htmltag($tooltiponprice).
'">';
2206 $tooltiponpriceend =
'</span>';
2209 print
'<td class="right linecolvatrate">';
2210 print $tooltiponprice;
2211 print
vatrate($line->vatrate.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
''), true);
2212 print $tooltiponpriceend;
2216 print
'<td class="right linecolunitht">';
2217 if (!empty($line->value_unit_ht)) {
2218 print
price($line->value_unit_ht);
2220 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $line->vatrate));
2221 $pricenettoshow =
price2num((
float) $line->value_unit / (1 + (
float) $tmpvat / 100),
'MU');
2222 print
price($pricenettoshow);
2226 print
'<td class="right linecolunitttc">'.price($line->value_unit).
'</td>';
2228 print
'<td class="right linecolqty">'.dol_escape_htmltag($line->qty).
'</td>';
2230 if ($action !=
'editline') {
2231 print
'<td class="right linecoltotalht">'.price($line->total_ht).
'</td>';
2232 print
'<td class="right linecoltotalttc">'.price($line->total_ttc).
'</td>';
2236 print
'<td class="center linecolpreview">';
2237 if ($line->fk_ecm_files > 0) {
2238 $modulepart =
'expensereport';
2239 $maxheightmini = 32;
2241 $result = $ecmfilesstatic->fetch($line->fk_ecm_files);
2243 $relativepath = preg_replace(
'/expensereport\//',
'', $ecmfilesstatic->filepath);
2244 $fileinfo = pathinfo($ecmfilesstatic->filepath.
'/'.$ecmfilesstatic->filename);
2247 if (!
dol_is_file(
$conf->expensereport->dir_output.
'/'.$relativepath.
'/'.$minifile)) {
2251 $urlforhref =
getAdvancedPreviewUrl($modulepart, $relativepath.
'/'.$fileinfo[
'filename'].
'.'.strtolower($fileinfo[
'extension']), 1,
'&entity='.(empty(
$object->entity) ?
$conf->entity :
$object->entity));
2252 if (empty($urlforhref)) {
2253 $urlforhref = DOL_URL_ROOT.
'/viewimage.php?modulepart='.$modulepart.
'&entity='.(empty(
$object->entity) ?
$conf->entity :
$object->entity).
'&file='.urlencode($relativepath.$fileinfo[
'filename'].
'.'.strtolower($fileinfo[
'extension']));
2254 print
'<a href="'.$urlforhref.
'" class="aphoto" target="_blank" rel="noopener noreferrer">';
2256 print
'<a href="'.$urlforhref[
'url'].
'" class="'.$urlforhref[
'css'].
'" target="'.$urlforhref[
'target'].
'" mime="'.$urlforhref[
'mime'].
'">';
2258 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="">';
2261 if (preg_match(
'/\.pdf$/i', $ecmfilesstatic->filename)) {
2262 $filepdf =
$conf->expensereport->dir_output.
'/'.$relativepath.
'/'.$ecmfilesstatic->filename;
2263 $fileimage =
$conf->expensereport->dir_output.
'/'.$relativepath.
'/'.$ecmfilesstatic->filename.
'_preview.png';
2264 $relativepathimage = $relativepath.
'/'.$ecmfilesstatic->filename.
'_preview.png';
2266 $pdfexists = file_exists($filepdf);
2269 if (!file_exists($fileimage) || (filemtime($fileimage) < filemtime($filepdf))) {
2271 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2280 if ($pdfexists && !$error) {
2281 $heightforphotref = 70;
2282 if (!empty(
$conf->dol_optimize_smallscreen)) {
2283 $heightforphotref = 60;
2285 $urlforhref =
getAdvancedPreviewUrl($modulepart, $relativepath.
'/'.$fileinfo[
'filename'].
'.'.strtolower($fileinfo[
'extension']), 1,
'&entity='.(empty(
$object->entity) ?
$conf->entity :
$object->entity));
2286 print
'<a href="'.$urlforhref[
'url'].
'" class="'.$urlforhref[
'css'].
'" target="'.$urlforhref[
'target'].
'" mime="'.$urlforhref[
'mime'].
'">';
2288 if (file_exists($fileimage)) {
2289 print
'<img height="'.$heightforphotref.
'" class="photo photowithmargin photowithborder" src="'.DOL_URL_ROOT.
'/viewimage.php?modulepart=apercu'.$modulepart.
'&file='.urlencode($relativepathimage).
'">';
2292 print
img_mime($ecmfilesstatic->filename);
2302 print
'<td class="nowrap right linecolwarning">';
2303 print !empty($line->rule_warning_message) ?
img_warning(html_entity_decode($line->rule_warning_message)) :
' ';
2308 print
'<td class="nowrap right linecolaction">';
2310 print
'<a class="editfielda reposition paddingrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=editline&token='.
newToken().
'&rowid='.$line->rowid.
'">';
2312 print
'</a> ';
2313 print
'<a class="paddingrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=delete_line&token='.
newToken().
'&rowid='.$line->rowid.
'">';
2323 if ($action ==
'editline' && $line->id ==
GETPOSTINT(
'rowid')) {
2326 if (isModEnabled(
'project')) {
2333 print
'<!-- line of expense report -->'.
"\n";
2334 print
'<tr class="tredited">';
2336 print
'<td class="center">';
2340 print
'<td colspan="'.($colspan - 1).
'" class="liste_titre"> ';
2341 print
'<a href="" class="commonlink auploadnewfilenow reposition">'.$langs->trans(
"UploadANewFileNow");
2342 print
img_picto($langs->trans(
"UploadANewFileNow"),
'chevron-down',
'', 0, 0, 0,
'',
'marginleftonly');
2345 print
' - <a href="" class="commonlink aattachtodoc reposition">'.$langs->trans(
"AttachTheNewLineToTheDocument");
2346 print
img_picto($langs->trans(
"AttachTheNewLineToTheDocument"),
'chevron-down',
'', 0, 0, 0,
'',
'marginleftonly');
2350 print
'<!-- Code to open/close section to submit or link files in edit mode -->'.
"\n";
2351 print
'<script type="text/javascript">'.
"\n";
2352 print
'$(document).ready(function() {
2353 $( ".auploadnewfilenow" ).click(function() {
2354 jQuery(".truploadnewfilenow").toggle();
2355 jQuery(".trattachnewfilenow").hide();
2358 $( ".aattachtodoc" ).click(function() {
2359 jQuery(".trattachnewfilenow").toggle();
2360 jQuery(".truploadnewfilenow").hide();
2363 if (is_array(
GETPOST(
'attachfile',
'array')) && count(
GETPOST(
'attachfile',
'array'))) {
2364 print
'jQuery(".trattachnewfilenow").toggle();'.
"\n";
2367 jQuery("form[name=\"expensereport\"]").submit(function() {
2368 if (jQuery(".truploadnewfilenow").is(":hidden")) {
2369 jQuery("input[name=\"sendit\"]").val("");
2376 print
'</script>'.
"\n";
2379 $filenamelinked =
'';
2380 if ($line->fk_ecm_files > 0) {
2381 $result = $ecmfilesstatic->fetch($line->fk_ecm_files);
2383 $filenamelinked = $ecmfilesstatic->filename;
2387 $tredited =
'tredited';
2388 include DOL_DOCUMENT_ROOT.
'/expensereport/tpl/expensereport_addfile.tpl.php';
2389 include DOL_DOCUMENT_ROOT.
'/expensereport/tpl/expensereport_linktofile.tpl.php';
2391 print
'<tr class="oddeven tredited">';
2396 print
'<td class="center">';
2397 print $form->selectDate($line->date,
'date');
2401 if (isModEnabled(
'project')) {
2403 $formproject->select_projects(-1, $line->fk_project,
'fk_project', 0, 0, $projectRequired ? 0 : 1, 1, 0, 0, 0,
'', 0, 0,
'maxwidth300');
2408 print
'<td class="center">';
2409 print $formexpensereport->selectTypeExpenseReport($line->fk_c_type_fees,
'fk_c_type_fees');
2413 print
'<td class="fk_c_exp_tax_cat">';
2414 $params = array(
'fk_expense' =>
$object->id,
'fk_expense_det' => $line->id,
'date' => $line->date);
2415 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);
2421 print
'<textarea name="comments" class="flat_ndf centpercent">'.dol_escape_htmltag($line->comments, 0, 1).
'</textarea>';
2425 $selectedvat =
price2num($line->vatrate).(!empty($line->vat_src_code) ?
' ('.$line->vat_src_code.
')' :
'');
2426 print
'<td class="right">';
2427 print $form->load_tva(
'vatrate', (GETPOSTISSET(
"vatrate") ?
GETPOST(
"vatrate") : $selectedvat), $mysoc,
'', 0, 0,
'', false, 1, 2);
2431 print
'<td class="right">';
2432 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.
' />';
2436 print
'<td class="right">';
2437 print
'<input type="text" min="0" class="right maxwidth50" id="value_unit" name="value_unit" value="'.dol_escape_htmltag(
price2num($line->value_unit)).
'" />';
2441 print
'<td class="right">';
2442 print
'<input type="text" min="0" class="input_qty right maxwidth50" name="qty" value="'.dol_escape_htmltag($line->qty).
'" />';
2449 print
'<td class="center">';
2453 print
'<td class="center">';
2457 print
'<input type="hidden" name="rowid" value="'.$line->rowid.
'">';
2458 print $form->buttonsSaveCancel(
'Save',
'Cancel', array(), 0,
'small');
2474 if (isModEnabled(
'project')) {
2477 if ($action !=
'editline') {
2481 $nbFiles = $nbLinks = 0;
2482 $arrayoffiles = array();
2484 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2485 require_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
2486 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
2489 $nbFiles = count($arrayoffiles);
2494 print
'<tr class="liste_titre">';
2495 print
'<td colspan="'.$colspan.
'" class="liste_titre expensereportautoload">';
2496 print
'<a href="" class="commonlink auploadnewfilenow reposition">'.$langs->trans(
"UploadANewFileNow");
2497 print
img_picto($langs->trans(
"UploadANewFileNow"),
'chevron-down',
'', 0, 0, 0,
'',
'marginleftonly');
2500 print
' - <a href="" class="commonlink aattachtodoc reposition">'.$langs->trans(
"AttachTheNewLineToTheDocument");
2501 print
img_picto($langs->trans(
"AttachTheNewLineToTheDocument"),
'chevron-down',
'', 0, 0, 0,
'',
'marginleftonly');
2505 print
'<!-- Code to open/close section to submit or link files in the form to add new line -->'.
"\n";
2506 print
'<script type="text/javascript">'.
"\n";
2507 print
'$(document).ready(function() {
2508 $( ".auploadnewfilenow" ).click(function() {
2509 console.log("We click on toggle of auploadnewfilenow");
2510 jQuery(".truploadnewfilenow").toggle();
2511 jQuery(".trattachnewfilenow").hide();
2512 if (jQuery(".truploadnewfilenow").is(":hidden")) {
2513 jQuery("input[name=\"sendit\"]").prop("name", "senditdisabled");
2515 jQuery("input[name=\"senditdisabled\"]").prop("name", "sendit");
2517 // TODO Switch css fa-chevron-dow and add fa-chevron-up
2520 $( ".aattachtodoc" ).click(function() {
2521 console.log("We click on toggle of aattachtodoc");
2522 jQuery(".trattachnewfilenow").toggle();
2523 jQuery(".truploadnewfilenow").hide();
2524 // TODO Switch css fa-chevron-dow and add fa-chevron-up
2527 if (is_array(
GETPOST(
'attachfile',
'array')) && count(
GETPOST(
'attachfile',
'array')) && $action !=
'updateline') {
2528 print
'jQuery(".trattachnewfilenow").show();'.
"\n";
2531 jQuery("form[name=\"expensereport\"]").submit(function() {
2532 if (jQuery(".truploadnewfilenow").is(":hidden")) {
2533 /* 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. */
2534 jQuery("input[name=\"sendit\"]").val("");
2535 jQuery("input[name=\"sendit\"]").prop("name", "senditdisabled");
2537 jQuery("input[name=\"senditdisabled\"]").prop("name", "sendit");
2544 print
'</script>'.
"\n";
2548 include DOL_DOCUMENT_ROOT.
'/expensereport/tpl/expensereport_linktofile.tpl.php';
2549 include DOL_DOCUMENT_ROOT.
'/expensereport/tpl/expensereport_addfile.tpl.php';
2551 print
'<tr class="liste_titre expensereportcreate">';
2553 print
'<td class="center expensereportcreatedate">'.$langs->trans(
'Date').
'</td>';
2554 if (isModEnabled(
'project')) {
2555 print
'<td class="minwidth100imp">'.$form->textwithpicto($langs->trans(
'Project'), $langs->trans(
"ClosedProjectsAreHidden")).
'</td>';
2557 print
'<td class="center expensereportcreatetype">'.$langs->trans(
'Type').
'</td>';
2559 print
'<td>'.$langs->trans(
'CarCategory').
'</td>';
2561 print
'<td class="expensereportcreatedescription">'.$langs->trans(
'Description').
'</td>';
2562 print
'<td class="right expensereportcreatevat">'.$langs->trans(
'VAT').
'</td>';
2563 print
'<td class="right expensereportcreatepriceuth">'.$langs->trans(
'PriceUHT').
'</td>';
2564 print
'<td class="right expensereportcreatepricettc">'.$langs->trans(
'PriceUTTC').
'</td>';
2565 print
'<td class="right expensereportcreateqty">'.$langs->trans(
'Qty').
'</td>';
2572 print
'<tr class="oddeven nohover">';
2578 print
'<td class="center inputdate">';
2579 print $form->selectDate(!empty($date) ? $date : -1,
'date', 0, 0, 0,
'', 1, 1);
2583 if (isModEnabled(
'project')) {
2584 print
'<td class="inputproject">';
2585 $formproject->select_projects(-1, !empty($fk_project) ? $fk_project : 0,
'fk_project', 0, 0, $projectRequired ? 0 : 1, -1, 0, 0, 0,
'', 0, 0,
'maxwidth300');
2590 print
'<td class="center inputtype">';
2591 print $formexpensereport->selectTypeExpenseReport(!empty($fk_c_type_fees) ? $fk_c_type_fees :
"",
'fk_c_type_fees', 1);
2595 print
'<td class="fk_c_exp_tax_cat">';
2596 $params = array(
'fk_expense' =>
$object->id);
2597 print $form->selectExpenseCategories(
'',
'fk_c_exp_tax_cat', 1, array(),
'fk_c_type_fees', $userauthor->default_c_exp_tax_cat, $params, 0);
2602 print
'<td class="inputcomment">';
2603 print
'<textarea class="flat_ndf centpercent" name="comments" rows="'.ROWS_2.
'">'.
dol_escape_htmltag(!empty($comments) ? $comments :
"", 0, 1).
'</textarea>';
2607 print
'<td class="right inputvat">';
2611 $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS =
'none';
2613 print $form->load_tva(
'vatrate', (!empty($vatrate) ? $vatrate : $defaultvat), $mysoc,
'', 0, 0,
'', false, 1);
2617 print
'<td class="right inputpricenet">';
2618 print
'<input type="text" class="right maxwidth50" id="value_unit_ht" name="value_unit_ht" value="'.dol_escape_htmltag((!empty($value_unit_ht) ? $value_unit_ht : 0)).
'"'.$taxlessUnitPriceDisabled.
' />';
2622 print
'<td class="right inputtax">';
2623 print
'<input type="text" class="right maxwidth50" id="value_unit" name="value_unit" value="'.dol_escape_htmltag((!empty($value_unit) ? $value_unit : 0)).
'">';
2627 print
'<td class="right inputqty">';
2628 print
'<input type="text" min="0" class=" input_qty right maxwidth50" name="qty" value="'.dol_escape_htmltag(!empty($qty) ? $qty : 1).
'">';
2634 if ($action !=
'editline') {
2635 print
'<td class="right"></td>';
2636 print
'<td class="right"></td>';
2640 print
'<td class="center inputbuttons">';
2641 print $form->buttonsSaveCancel(
"Add",
'',
'', 1,
'reposition');
2652 /* JQuery for product free or predefined select */
2653 jQuery(document).ready(function() {
2654 jQuery("#value_unit_ht").keyup(function(event) {
2655 console.log(event.which); // discard event tag and arrows
2656 if (event.which != 9 && (event.which < 37 ||event.which > 40) && jQuery("#value_unit_ht").val() != "") {
2657 jQuery("#value_unit").val("");
2660 jQuery("#value_unit").keyup(function(event) {
2661 console.log(event.which); // discard event tag and arrows
2662 if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#value_unit").val() != "") {
2663 jQuery("#value_unit_ht").val("");
2671 /* unit price coef calculation */
2672 jQuery(".input_qty, #fk_c_type_fees, #select_fk_c_exp_tax_cat, #vatrate ").change(function(event) {
2673 console.log("We change a parameter");
2675 let type_fee = jQuery("#fk_c_type_fees").find(":selected").val();
2676 let tax_cat = jQuery("#select_fk_c_exp_tax_cat").find(":selected").val();
2677 let tva = jQuery("#vatrate").find(":selected").val();
2678 let qty = jQuery(".input_qty").val();
2680 let path = "'.DOL_URL_ROOT.
'/expensereport/ajax/ajaxik.php";
2681 path += "?fk_c_exp_tax_cat="+tax_cat;
2682 path += "&fk_expense="+'.((int)
$object->id).
';
2683 path += "&vatrate="+tva;
2684 path += "&qty="+qty;
2686 if (type_fee == 4) { // frais_kilométriques
2687 if (tax_cat == "" || parseInt(tax_cat) <= 0){
2695 success: function(response) {
2696 if (response.response_status == "success"){';
2700 jQuery("#value_unit").val(parseFloat(response.data) * (100 + parseFloat(tva)) / 100);
2701 jQuery("#value_unit").trigger("change");
2705 jQuery("#value_unit_ht").val(response.data);
2706 jQuery("#value_unit_ht").trigger("change");
2707 jQuery("#value_unit").val("");
2712 } else if(response.response_status == "error" && response.errorMessage != undefined && response.errorMessage.length > 0 ) {
2713 console.log("We get an error result");
2714 $.jnotify(response.errorMessage, "error", {timeout: 0, type: "error"},{ remove: function (){} } );
2720 /*console.log(event.which); // discard event tag and arrows
2721 if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#value_unit").val() != "") {
2722 jQuery("#value_unit_ht").val("");
2742 print
'Record not found';
2753print
'<div class="tabsAction">';
2755if ($action !=
'create' && $action !=
'edit' && $action !=
'editline') {
2760 if (empty($user->socid)) {
2763 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>';
2775 if (in_array(
$object->fk_user_author, $childids) || $user->hasRight(
'expensereport',
'writeall_advance')) {
2777 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>';
2780 if (count(
$object->lines) > 0) {
2781 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>';
2792 if ($user->id ==
$object->fk_user_author || $user->id ==
$object->fk_user_valid) {
2794 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>';
2799 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>';
2804 if ($user->id ==
$object->fk_user_author || $user->id ==
$object->fk_user_valid) {
2806 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>';
2816 if (in_array(
$object->fk_user_author, $childids)) {
2818 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>';
2826 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>';
2828 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>';
2831 if ($user->id ==
$object->fk_user_author || $user->id ==
$object->fk_user_valid) {
2833 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=cancel&id='.
$object->id.
'">'.$langs->trans(
"Cancel").
'</a></div>';
2842 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>';
2848 if ($remaintopay == 0) {
2849 print
'<div class="inline-block divButAction"><span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPayment').
'</span></div>';
2851 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>';
2859 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>";
2865 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>';
2871 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>';
2876 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>';
2880 if ($user->hasRight(
'expensereport',
'creer')) {
2881 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>';
2887 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>';
2890 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>';
2893 $parameters = array();
2894 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters,
$object, $action);
2901if (
GETPOST(
'modelselected',
'alpha')) {
2902 $action =
'presend';
2905if ($action !=
'presend') {
2910 print
'<div class="fichecenter"><div class="fichehalfleft">';
2911 print
'<a name="builddoc"></a>';
2913 if ($user->hasRight(
'expensereport',
'creer') && $action !=
'create' && $action !=
'edit') {
2916 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".
$object->id;
2917 $genallowed = $user->hasRight(
'expensereport',
'creer');
2918 $delallowed = $user->hasRight(
'expensereport',
'creer');
2920 print $formfile->showdocuments(
'expensereport', $filename, $filedir, $urlsource, $genallowed, $delallowed);
2921 $somethingshown = $formfile->numoffiles;
2937 print
'</div><div class="fichehalfright">';
2939 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
2941 $somethingshown = $formactions->showactions(
$object,
'expensereport',
null);
2943 print
'</div></div>';
2947$modelmail =
'expensereport_send';
2948$defaulttopic =
'SendExpenseReportRef';
2949$diroutput =
$conf->expensereport->dir_output;
2950$trackid =
'exp'.$object->id;
2952include 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($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class to manage bank accounts.
Class to manage accounting accounts.
Class to manage accounting journals.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Class to manage a WYSIWYG editor.
Class to manage ECM files.
Class to manage Trips and Expenses.
const STATUS_DRAFT
Draft status.
const STATUS_APPROVED
Classified approved.
const STATUS_CANCELED
Classified canceled.
const STATUS_CLOSED
Classified paid.
const STATUS_REFUSED
Classified refused.
const STATUS_VALIDATED
Validated (need to be paid)
Class of expense report details lines.
static count($dbs, $objecttype, $objectid)
Return nb of links.
Class to manage payments of expense report.
Class to manage projects.
Class to manage translations.
Class to manage Dolibarr users.
expensereport_prepare_head($object)
Prepare array with list of tabs.
dol_convert_file($fileinput, $ext='png', $fileoutput='', $page='')
Convert an image file or a PDF into another image format.
dol_is_file($pathoffile)
Return if path is a file.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formatted for view output Used into pdf and HTML pages.
img_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_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
newToken()
Return the value of token currently saved into session with name 'newtoken'.
getImageFileNameForSize($file, $extName, $extImgTarget='')
Return the filename of file to get the thumbs.
get_date_range($date_start, $date_end, $format='', $outputlangs=null, $withparenthesis=1)
Format output for start and end date.
getAdvancedPreviewUrl($modulepart, $relativepath, $alldata=0, $param='')
Return URL we can use for advanced preview links.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_clone($object, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_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 a Dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
image_format_supported($file, $acceptsvg=0)
Return if a filename is file name of a supported image format.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.