32require
'../main.inc.php';
44require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formexpensereport.class.php';
45require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
46require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
47require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
48require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
49require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
50require_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
51require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
52require_once DOL_DOCUMENT_ROOT.
'/core/lib/expensereport.lib.php';
53require_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
54require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
55require_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
56require_once DOL_DOCUMENT_ROOT.
'/core/modules/expensereport/modules_expensereport.php';
57require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
58require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/paymentexpensereport.class.php';
59require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
61 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
65$langs->loadLangs(array(
"trips",
"bills",
"mails"));
67$action =
GETPOST(
'action',
'aZ09');
68$cancel =
GETPOST(
'cancel',
'alpha');
69$confirm =
GETPOST(
'confirm',
'alpha');
70$backtopage =
GETPOST(
'backtopage',
'alpha');
77$vatrate =
GETPOST(
'vatrate',
'alpha');
79$comments =
GETPOST(
'comments',
'restricthtml');
84$childids = $user->getAllChildIds(1);
91 if (empty($date_end)) {
98$rootfordata = DOL_DATA_ROOT;
99$rootforuser = DOL_DATA_ROOT;
102 $rootfordata .=
'/'.$conf->entity;
104$conf->expensereport->dir_output = $rootfordata.
'/expensereport';
108$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
120$extrafields->fetch_name_optionals_label(
$object->table_element);
123include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
126$hookmanager->initHooks(array(
'expensereportcard',
'globalcard'));
130$caneditreport = (empty(
$object->id) || in_array(
$object->fk_user_author, $childids) || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'expensereport',
'writeall_advance')));
132$permissionnote = $user->hasRight(
'expensereport',
'creer') && $caneditreport;
133$permissiondellink = $user->hasRight(
'expensereport',
'creer') && $caneditreport;
134$permissiontoadd = $user->hasRight(
'expensereport',
'creer') && $caneditreport;
135$permissiontoeditextra = $permissiontoadd;
136if (
GETPOST(
'attribute',
'aZ09') && isset($extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')])) {
138 $permissiontoeditextra =
dol_eval((
string) $extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')]);
149 if ($user->hasRight(
'expensereport',
'readall')) {
152 if (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'expensereport',
'writeall_advance')) {
155 if ($user->hasRight(
'expensereport',
'lire') && in_array(
$object->fk_user_author, $childids)) {
164if ($user->hasRight(
'expensereport',
'supprimer')) {
173 $socid = $user->socid;
177$permissiontoadd = $user->hasRight(
'expensereport',
'creer') && $caneditreport;
190$parameters = array(
'socid' => $socid);
191$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
196if (empty($reshook)) {
197 $backurlforlist = DOL_URL_ROOT.
'/expensereport/list.php';
199 if (empty($backtopage) || ($cancel && empty($id))) {
200 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
201 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
202 $backtopage = $backurlforlist;
204 $backtopage = DOL_URL_ROOT.
'/expensereport/card.php?id='.((!empty($id) &&
$id > 0) ? $id :
'__ID__');
210 if (!empty($backtopageforcancel)) {
211 header(
"Location: ".$backtopageforcancel);
213 } elseif (!empty($backtopage)) {
214 header(
"Location: ".$backtopage);
228 $fk_c_type_fees = -1;
232 $allowedstatusforaction = array(
240 if ($user->hasRight(
'expensereport',
'approve') || $user->hasRight(
'expensereport',
'to_paid')) {
243 if ($user->hasRight(
'expensereport',
'to_paid')) {
246 if (array_key_exists($action, $allowedstatusforaction) &&
$object->id > 0 && !in_array(
$object->status, $allowedstatusforaction[$action])) {
247 $labelsofallowedstatus = array();
248 foreach ($allowedstatusforaction[$action] as $allowedstatus) {
249 $labelsofallowedstatus[] =
$object->LibStatut($allowedstatus, 0);
251 setEventMessages($langs->trans(
"StatusOfRefMustBe",
$object->ref, implode(
' / ', $labelsofallowedstatus)),
null,
'errors');
255 include DOL_DOCUMENT_ROOT.
'/core/actions_linkedfiles.inc.php';
257 if (!empty(
GETPOST(
'sendit',
'alpha'))) {
258 if ($action ==
'updateline') {
259 $action =
'editline';
265 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
267 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
269 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
272 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontoadd) {
277 $fk_user_author_clone = (
GETPOSTINT(
'fk_user_author') > 0 ?
GETPOSTINT(
'fk_user_author') : $user->id);
278 if ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') || !$user->hasRight(
'expensereport',
'writeall_advance')) && !in_array($fk_user_author_clone, $childids)) {
287 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
298 if ($action ==
'confirm_delete' &&
GETPOST(
"confirm",
'alpha') ==
"yes" && $id > 0 && $candelete) {
301 $result =
$object->delete($user);
303 header(
"Location: index.php");
310 if ($action ==
'add' && $permissiontoadd) {
317 if (!(
$object->fk_user_author > 0)) {
318 $object->fk_user_author = $user->id;
322 if ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'expensereport',
'creer'))
323 || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'expensereport',
'creer') && !$user->hasRight(
'expensereport',
'writeall_advance'))) {
328 if (!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') || !$user->hasRight(
'expensereport',
'writeall_advance')) {
329 if (!in_array(
$object->fk_user_author, $childids)) {
337 $fuser->fetch(
$object->fk_user_author);
346 $ret = $extrafields->setOptionalsFromPost(
null, $object);
355 if ($overlappingExpenseReportID > 0) {
357 setEventMessages($langs->trans(
"ErrorDoubleDeclaration").
' <a href="'.$_SERVER[
'PHP_SELF'].
'?id='.$overlappingExpenseReportID.
'">'. $langs->trans(
'ShowTrip').
'</a>',
null,
'errors');
372 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
382 if (($action ==
'update' || $action ==
'updateFromRefuse') && $permissiontoadd) {
396 $object->fk_user_modif = $user->id;
398 $result =
$object->update($user);
400 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
GETPOSTINT(
'id'));
407 if ($action ==
'update_extras' && $permissiontoeditextra) {
410 $attribute_name =
GETPOST(
'attribute',
'aZ09');
413 $ret = $extrafields->setOptionalsFromPost(
null, $object, $attribute_name);
419 $result =
$object->updateExtraField($attribute_name,
'EXPENSEREPORT_MODIFY');
427 $action =
'edit_extras';
431 if ($action ==
"confirm_validate" &&
GETPOST(
"confirm",
'alpha') ==
"yes" && $id > 0 && $permissiontoadd) {
437 $result =
$object->setValidate($user);
442 $outputlangs = $langs;
445 $newlang =
GETPOST(
'lang_id',
'aZ09');
449 $tmpuser->fetch(
$object->fk_user_author);
450 $newlang = $tmpuser->lang;
452 if (!empty($newlang)) {
454 $outputlangs->setDefaultLang($newlang);
459 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
466 if (!$error && $result > 0 &&
$object->fk_user_validator > 0) {
467 $langs->load(
"mails");
471 $destinataire->fetch(
$object->fk_user_validator);
472 $emailTo = $destinataire->email;
476 $expediteur->fetch(
$object->fk_user_author);
479 if ($emailTo && $emailFrom) {
490 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportWaitingForApproval");
493 $link = $urlwithroot.
'/expensereport/card.php?id='.
$object->id;
494 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
495 $message = $langs->transnoentities(
"ExpenseReportWaitingForApprovalMessage", $expediteur->getFullName($langs),
get_date_range(
$object->date_debut,
$object->date_fin,
'', $langs), $link);
510 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
512 if (empty($mailfile->error)) {
514 $result = $mailfile->sendfile();
516 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
519 $langs->load(
"other");
520 if (!empty($mailfile->error) || !empty($mailfile->errors)) {
523 if (!empty($mailfile->error)) {
524 $mesg .=
'<br>' . $mailfile->error;
526 if (!empty($mailfile->errors) && is_array($mailfile->errors)) {
527 $mesg .=
'<br>' . implode(
'<br>', $mailfile->errors);
531 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
539 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
546 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
553 if ($action ==
"confirm_save_from_refuse" &&
GETPOST(
"confirm",
'alpha') ==
"yes" && $id > 0 && $permissiontoadd) {
556 $result =
$object->set_save_from_refuse($user);
561 $outputlangs = $langs;
564 $newlang =
GETPOST(
'lang_id',
'aZ09');
568 $tmpuser->fetch(
$object->fk_user_author);
569 $newlang = $tmpuser->lang;
571 if (!empty($newlang)) {
573 $outputlangs->setDefaultLang($newlang);
578 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
587 $destinataire->fetch(
$object->fk_user_validator);
588 $emailTo = $destinataire->email;
592 $expediteur->fetch(
$object->fk_user_author);
595 if ($emailFrom && $emailTo) {
606 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportWaitingForReApproval");
609 $link = $urlwithroot.
'/expensereport/card.php?id='.
$object->id;
610 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
612 $message .=
'<br>'.$langs->transnoentities(
"ExpenseReportWaitingForReApprovalMessage2", $link);
631 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
633 if (empty($mailfile->error)) {
635 $result = $mailfile->sendfile();
637 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
639 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
642 $langs->load(
"other");
643 if ($mailfile->error) {
645 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
646 $mesg .=
'<br>'.$mailfile->error;
649 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
657 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
666 if ($action ==
"confirm_approve" &&
GETPOST(
"confirm",
'alpha') ==
"yes" && $id > 0 && $user->hasRight(
'expensereport',
'approve')) {
670 $result =
$object->setApproved($user);
675 $outputlangs = $langs;
678 $newlang =
GETPOST(
'lang_id',
'aZ09');
682 $tmpuser->fetch(
$object->fk_user_author);
683 $newlang = $tmpuser->lang;
685 if (!empty($newlang)) {
687 $outputlangs->setDefaultLang($newlang);
692 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
701 $destinataire->fetch(
$object->fk_user_author);
702 $emailTo = $destinataire->email;
706 if (empty($emailTo)) {
712 $expediteur->fetch(
$object->fk_user_approve > 0 ?
$object->fk_user_approve :
$object->fk_user_validator);
715 if ($emailFrom && $emailTo) {
726 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportApproved");
729 $link = $urlwithroot.
'/expensereport/card.php?id='.
$object->id;
730 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
731 $message = $langs->transnoentities(
"ExpenseReportApprovedMessage",
$object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $link);
748 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, $emailCC,
'', 0, -1);
750 if (empty($mailfile->error)) {
752 $result = $mailfile->sendfile();
754 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
756 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
759 $langs->load(
"other");
760 if ($mailfile->error) {
762 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
763 $mesg .=
'<br>'.$mailfile->error;
766 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
774 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
783 if ($action ==
"confirm_refuse" &&
GETPOST(
'confirm',
'alpha') ==
"yes" && $id > 0 && $user->hasRight(
'expensereport',
'approve')) {
787 $detailRefuse =
GETPOST(
'detail_refuse',
'alpha');
788 $result =
$object->setDeny($user, $detailRefuse);
793 $outputlangs = $langs;
796 $newlang =
GETPOST(
'lang_id',
'aZ09');
800 $tmpuser->fetch(
$object->fk_user_author);
801 $newlang = $tmpuser->lang;
803 if (!empty($newlang)) {
805 $outputlangs->setDefaultLang($newlang);
810 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
819 $destinataire->fetch(
$object->fk_user_author);
820 $emailTo = $destinataire->email;
824 $expediteur->fetch(
$object->fk_user_refuse);
827 if ($emailFrom && $emailTo) {
838 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportRefused");
841 $link = $urlwithroot.
'/expensereport/card.php?id='.
$object->id;
842 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
843 $message = $langs->transnoentities(
"ExpenseReportRefusedMessage",
$object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $detailRefuse, $link);
861 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
863 if (empty($mailfile->error)) {
865 $result = $mailfile->sendfile();
867 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
869 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
872 $langs->load(
"other");
873 if ($mailfile->error) {
875 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
876 $mesg .=
'<br>'.$mailfile->error;
879 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
887 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
897 if ($action ==
"confirm_cancel" &&
GETPOST(
'confirm',
'alpha') ==
"yes" && $id > 0 && $user->hasRight(
'expensereport',
'creer')) {
898 if (!
GETPOST(
'detail_cancel',
'alpha')) {
899 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Comment")),
null,
'errors');
904 if ($user->id ==
$object->fk_user_valid || $user->id ==
$object->fk_user_author) {
905 $detailCancel =
GETPOST(
'detail_cancel',
'alpha');
906 $result =
$object->set_cancel($user, $detailCancel);
911 $outputlangs = $langs;
914 $newlang =
GETPOST(
'lang_id',
'aZ09');
918 $tmpuser->fetch(
$object->fk_user_author);
919 $newlang = $tmpuser->lang;
921 if (!empty($newlang)) {
923 $outputlangs->setDefaultLang($newlang);
928 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
937 $destinataire->fetch(
$object->fk_user_author);
938 $emailTo = $destinataire->email;
942 $expediteur->fetch(
$object->fk_user_cancel);
945 if ($emailFrom && $emailTo) {
956 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportCanceled");
959 $link = $urlwithroot.
'/expensereport/card.php?id='.
$object->id;
960 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
961 $message = $langs->transnoentities(
"ExpenseReportCanceledMessage",
$object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $detailCancel, $link);
979 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
981 if (empty($mailfile->error)) {
983 $result = $mailfile->sendfile();
985 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
987 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
990 $langs->load(
"other");
991 if ($mailfile->error) {
993 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
994 $mesg .=
'<br>'.$mailfile->error;
997 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
1005 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
1018 if ($action ==
"confirm_setdraft" &&
GETPOST(
'confirm',
'alpha') ==
"yes" && $id > 0 && $user->hasRight(
'expensereport',
'creer')) {
1021 if ($user->id ==
$object->fk_user_author || $user->id ==
$object->fk_user_valid || in_array(
$object->fk_user_author, $childids)) {
1027 $outputlangs = $langs;
1030 $newlang =
GETPOST(
'lang_id',
'aZ09');
1034 $tmpuser->fetch(
$object->fk_user_author);
1035 $newlang = $tmpuser->lang;
1037 if (!empty($newlang)) {
1039 $outputlangs->setDefaultLang($newlang);
1044 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1049 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
1059 if ($action ==
'set_unpaid' && $id > 0 && $user->hasRight(
'expensereport',
'to_paid')) {
1063 $result =
$object->setUnpaid($user);
1068 $outputlangs = $langs;
1071 $newlang =
GETPOST(
'lang_id',
'aZ09');
1075 $tmpuser->fetch(
$object->fk_user_author);
1076 $newlang = $tmpuser->lang;
1078 if (!empty($newlang)) {
1080 $outputlangs->setDefaultLang($newlang);
1085 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1088 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
1094 if ($action ==
'set_paid' && $id > 0 && $user->hasRight(
'expensereport',
'to_paid')) {
1098 $result =
$object->setPaid($id, $user);
1103 $outputlangs = $langs;
1106 $newlang =
GETPOST(
'lang_id',
'aZ09');
1110 $tmpuser->fetch(
$object->fk_user_author);
1111 $newlang = $tmpuser->lang;
1113 if (!empty($newlang)) {
1115 $outputlangs->setDefaultLang($newlang);
1120 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1131 $destinataire =
new User(
$db);
1132 $destinataire->fetch(
$object->fk_user_author);
1133 $emailTo = $destinataire->email;
1137 $expediteur->fetch($user->id);
1140 if ($emailFrom && $emailTo) {
1141 $filename = array();
1143 $mimetype = array();
1151 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportPaid");
1154 $link = $urlwithroot.
'/expensereport/card.php?id='.
$object->id;
1155 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
1156 $message = $langs->transnoentities(
"ExpenseReportPaidMessage",
$object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $link);
1159 $object->setDocModel($user,
"");
1160 $resultPDF = expensereport_pdf_create(
$db, $object,
'',
"", $langs);
1163 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
1165 if (empty($mailfile->error)) {
1167 $result = $mailfile->sendfile();
1169 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
1172 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
1175 $langs->load(
"other");
1176 if ($mailfile->error) {
1178 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
1179 $mesg .=
'<br>'.$mailfile->error;
1182 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
1189 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
1199 if ($action ==
"addline" && $permissiontoadd) {
1203 $arrayoffiles =
GETPOST(
'attachfile',
'array');
1204 if (is_array($arrayoffiles) && !empty($arrayoffiles[0])) {
1205 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1206 $entityprefix = (
$conf->entity !=
'1') ?
$conf->entity.
'/' :
'';
1207 $relativepath =
'expensereport/'.$object->ref.
'/'.$arrayoffiles[0];
1209 $ecmfiles->fetch(0,
'', $relativepath);
1210 $fk_ecm_files = $ecmfiles->id;
1215 if (empty($vatrate)) {
1218 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $vatrate));
1222 if (empty($value_unit)) {
1223 $value_unit =
price2num((
float) $value_unit_ht + ((
float) $value_unit_ht * (
float) $tmpvat / 100),
'MU');
1226 $fk_c_exp_tax_cat =
GETPOSTINT(
'fk_c_exp_tax_cat');
1233 if (!($fk_c_type_fees > 0)) {
1235 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1239 if ((
float) $tmpvat < 0 || $tmpvat ===
'') {
1241 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"VAT")),
null,
'errors');
1246 if (empty($date) || $date ==
"--") {
1248 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1249 } elseif ($date < $object->date_debut || $date > (
$object->date_fin + (24 * 3600 - 1))) {
1255 $langs->load(
"errors");
1256 $type = $error > 0 ?
'errors' :
'warnings';
1257 setEventMessages($langs->trans(
"WarningDateOfLineMustBeInExpenseReportRange"),
null, $type);
1261 if ($value_unit == 0) {
1263 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"PriceUTTC")),
null,
'errors');
1267 if ($projectRequired && $fk_project <= 0) {
1269 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Project")),
null,
'errors');
1273 if ($fileRequired && $fk_ecm_files == 0) {
1275 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"File")),
null,
'errors');
1282 $result =
$object->addline($qty, $value_unit, $fk_c_type_fees, $vatrate, $date, $comments, $fk_project, $fk_c_exp_tax_cat, $type, $fk_ecm_files);
1288 $outputlangs = $langs;
1289 $newlang =
GETPOST(
'lang_id',
'alpha');
1292 $tmpuser->fetch(
$object->fk_user_author);
1293 $newlang = $tmpuser->lang;
1295 if (!empty($newlang)) {
1297 $outputlangs->setDefaultLang($newlang);
1300 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1304 unset($value_unit_ht);
1308 unset($fk_c_type_fees);
1319 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
GETPOSTINT(
'id'));
1328 setEventMessages($langs->trans(
"ErrorDeleteLineNotAllowedByObjectStatus"),
null,
'errors');
1332 if ($action ==
'confirm_delete_line' &&
GETPOST(
"confirm",
'alpha') ==
"yes" && $permissiontoadd) {
1338 $total_ht = $object_ligne->total_ht;
1339 $total_tva = $object_ligne->total_tva;
1346 $outputlangs = $langs;
1349 $newlang =
GETPOST(
'lang_id',
'aZ09');
1353 $tmpuser->fetch(
$object->fk_user_author);
1354 $newlang = $tmpuser->lang;
1356 if (!empty($newlang)) {
1358 $outputlangs->setDefaultLang($newlang);
1363 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1367 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
GETPOSTINT(
'id'));
1374 if ($action ==
"updateline" && $permissiontoadd) {
1381 $arrayoffiles =
GETPOST(
'attachfile',
'array');
1382 if (is_array($arrayoffiles) && !empty($arrayoffiles[0])) {
1383 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1384 $relativepath =
'expensereport/'.$object->ref.
'/'.$arrayoffiles[0];
1386 $ecmfiles->fetch(0,
'', $relativepath);
1387 $fk_ecm_files = $ecmfiles->id;
1392 $type_fees_id =
GETPOSTINT(
'fk_c_type_fees');
1393 $fk_c_exp_tax_cat =
GETPOSTINT(
'fk_c_exp_tax_cat');
1394 $projet_id = $fk_project;
1395 $comments =
GETPOST(
'comments',
'restricthtml');
1397 $vatrate =
GETPOST(
'vatrate',
'alpha');
1400 if (empty($vatrate)) {
1403 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $vatrate));
1407 if (empty($value_unit)) {
1408 $value_unit =
price2num((
float) $value_unit_ht + ((
float) $value_unit_ht * (
float) $tmpvat / 100),
'MU');
1413 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1416 if ((
float) $tmpvat < 0 || $tmpvat ==
'') {
1418 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Vat")),
null,
'errors');
1422 if ($date < $object->date_debut || $date > (
$object->date_fin + (24 * 3600 - 1))) {
1427 $langs->load(
"errors");
1428 $type = $error > 0 ?
'errors' :
'warnings';
1429 setEventMessages($langs->trans(
"WarningDateOfLineMustBeInExpenseReportRange"),
null, $type);
1433 if ($projectRequired && $projet_id <= 0) {
1435 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Project")),
null,
'errors');
1440 $result =
$object->updateline($rowid, $type_fees_id, $projet_id, $vatrate, $comments, (
float) $qty, (
float) $value_unit, $date, $id, $fk_c_exp_tax_cat, $fk_ecm_files);
1445 $outputlangs = $langs;
1448 $newlang =
GETPOST(
'lang_id',
'aZ09');
1452 $tmpuser->fetch(
$object->fk_user_author);
1453 $newlang = $tmpuser->lang;
1455 if (!empty($newlang)) {
1457 $outputlangs->setDefaultLang($newlang);
1462 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1466 unset($value_unit_ht);
1470 unset($fk_c_type_fees);
1483 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
1486 $triggersendname =
'EXPENSEREPORT_SENTBYMAIL';
1487 $autocopy =
'MAIN_MAIL_AUTOCOPY_EXPENSEREPORT_TO';
1488 $trackid =
'exp'.$object->id;
1489 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
1492 $upload_dir =
$conf->expensereport->dir_output;
1493 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1501$title = $langs->trans(
"ExpenseReport").
" - ".$langs->trans(
"Card");
1502$help_url =
"EN:Module_Expense_Reports|FR:Module_Notes_de_frais";
1517if ($action ==
'create') {
1520 print
'<form action="'.$_SERVER[
'PHP_SELF'].
'" method="post" name="create">';
1521 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1522 print
'<input type="hidden" name="action" value="add">';
1523 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
1527 print
'<table class="border centpercent">';
1532 print
'<td class="fieldrequired">'.$langs->trans(
"User").
'</td>';
1534 $defaultselectuser = $user->id;
1536 $defaultselectuser =
GETPOSTINT(
'fk_user_author');
1538 $include_users =
'hierarchyme';
1539 if (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'expensereport',
'writeall_advance')) {
1540 $include_users = array();
1542 print
img_picto(
'',
'user',
'class="pictofixedwidth"').$form->select_dolusers($defaultselectuser,
'fk_user_author', 0,
null, 0, $include_users,
'',
'0,'.
$conf->entity, 0, 0,
'', 0,
'',
'minwidth200 maxwidth500 inline-block');
1548 print
'<td class="titlefieldcreate fieldrequired">'.$langs->trans(
"DateStart").
'</td>';
1549 print
'<td>'.img_picto(
'',
'action',
'class="pictofixedwidth"');
1556 print
'<td class="fieldrequired">'.$langs->trans(
"DateEnd").
'</td>';
1557 print
'<td>'.img_picto(
'',
'action',
'class="pictofixedwidth"');
1558 print $form->selectDate($date_end ? $date_end : -1,
'date_fin', 0, 0, 0,
'', 1, 1);
1565 print
'<td>'.$langs->trans(
"ReviewedByCP").
'</td>';
1568 $include_users =
$object->fetch_users_approver_expensereport();
1569 if (empty($include_users)) {
1570 print
img_warning().
' '.$langs->trans(
"NobodyHasPermissionToValidateExpenseReport");
1572 $defaultselectuser = (empty($user->fk_user_expense_validator) ? $user->fk_user : $user->fk_user_expense_validator);
1577 $defaultselectuser =
GETPOSTINT(
'fk_user_validator');
1579 $s = $form->select_dolusers($defaultselectuser,
"fk_user_validator", 1,
null, ((empty($defaultselectuser) || !
getDolGlobalString(
'EXPENSEREPORT_DEFAULT_VALIDATOR_UNCHANGEABLE')) ? 0 : 1), $include_users);
1580 print
img_picto(
'',
'user',
'class="pictofixedwidth"').$form->textwithpicto($s, $langs->trans(
"AnyOtherInThisListCanValidate"));
1588 print
'<td>'.$langs->trans(
"ModePaiement").
'</td>';
1590 $form->select_types_paiements(
'',
'fk_c_paiement');
1599 print
'<td class="tdtop">'.$langs->trans(
'NotePublic').
'</td>';
1602 $doleditor =
new DolEditor(
'note_public', $note_public,
'', 80,
'dolibarr_notes',
'In',
false,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3,
'90%');
1603 print $doleditor->Create(1);
1607 $note_private =
GETPOSTISSET(
'note_private') ?
GETPOST(
'note_private',
'restricthtml') :
'';
1609 if (empty($user->socid)) {
1611 print
'<td class="tdtop">'.$langs->trans(
'NotePrivate').
'</td>';
1614 $doleditor =
new DolEditor(
'note_private', $note_private,
'', 80,
'dolibarr_notes',
'In',
false,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3,
'90%');
1615 print $doleditor->Create(1);
1620 $parameters = array(
'colspan' =>
' colspan="3"',
'cols' => 3);
1621 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
1622 print $hookmanager->resPrint;
1623 if (empty($reshook)) {
1624 print
$object->showOptionals($extrafields,
'create', $parameters);
1632 print $form->buttonsSaveCancel(
"AddTrip");
1637 $result =
$object->fetch($id, $ref);
1640 if (!in_array(
$object->fk_user_author, $childids)) {
1641 if (!$user->hasRight(
'expensereport',
'readall') && !$user->hasRight(
'expensereport',
'lire_tous')
1642 && (!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') || !$user->hasRight(
'expensereport',
'writeall_advance'))) {
1645 print
'<div class="tabBar">';
1646 print $langs->trans(
'NotUserRightToView');
1661 print
"<form name='update' action=\"".$_SERVER[
'PHP_SELF'].
"\" method=\"post\">\n";
1662 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1663 print
'<input type="hidden" name="id" value="'.$id.
'">';
1664 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
1666 print
dol_get_fiche_head($head,
'card', $langs->trans(
"ExpenseReport"), 0,
'trip', 0,
'',
'', 0,
'', 1);
1669 print
'<input type="hidden" name="action" value="updateFromRefuse">';
1671 print
'<input type="hidden" name="action" value="update">';
1674 $linkback =
'<a href="'.DOL_URL_ROOT.
'/expensereport/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
1676 print
'<table class="border centpercent">';
1679 print
'<td>'.$langs->trans(
"User").
'</td>';
1682 if (
$object->fk_user_author > 0) {
1683 $userfee->fetch(
$object->fk_user_author);
1684 print $userfee->getNomUrl(-1);
1689 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Ref").
'</td><td>';
1690 print $form->showrefnav($object,
'ref', $linkback, 1,
'ref',
'ref',
'');
1694 print
'<td>'.$langs->trans(
"DateStart").
'</td>';
1696 print $form->selectDate(
$object->date_debut,
'date_debut');
1700 print
'<td>'.$langs->trans(
"DateEnd").
'</td>';
1702 print $form->selectDate(
$object->date_fin,
'date_fin');
1708 print
'<td>'.$langs->trans(
"ModePaiement").
'</td>';
1710 $form->select_types_paiements((
string)
$object->fk_c_paiement,
'fk_c_paiement');
1717 print
'<td>'.$langs->trans(
"VALIDATOR").
'</td>';
1719 $include_users =
$object->fetch_users_approver_expensereport();
1720 $s = $form->select_dolusers(
$object->fk_user_validator,
"fk_user_validator", 1,
null, 0, $include_users);
1721 print $form->textwithpicto($s, $langs->trans(
"AnyOtherInThisListCanValidate"));
1726 print
'<td>'.$langs->trans(
"VALIDOR").
'</td>';
1729 $userfee->fetch(
$object->fk_user_valid);
1730 print $userfee->getNomUrl(-1);
1736 print
'<td>'.$langs->trans(
"AUTHORPAIEMENT").
'</td>';
1739 $userfee->fetch($user->id);
1740 print $userfee->getNomUrl(-1);
1752 print $form->buttonsSaveCancel(
"Modify");
1756 $taxlessUnitPriceDisabled =
getDolGlobalString(
'EXPENSEREPORT_FORCE_LINE_AMOUNTS_INCLUDING_TAXES_ONLY') ?
' disabled' :
'';
1758 print
dol_get_fiche_head($head,
'card', $langs->trans(
"ExpenseReport"), -1,
'trip', 0,
'',
'', 0,
'', 1);
1763 if ($action ==
'clone') {
1765 $criteriaforfilter =
'hierarchyme';
1766 if (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'expensereport',
'writeall_advance')) {
1767 $criteriaforfilter =
'';
1769 $formquestion = array(
1771 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'))
1774 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneExpenseReport',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1);
1777 if ($action ==
'save') {
1778 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"SaveTrip"), $langs->trans(
"ConfirmSaveTrip"),
"confirm_validate",
"",
"", 1);
1781 if ($action ==
'save_from_refuse') {
1782 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"SaveTrip"), $langs->trans(
"ConfirmSaveTrip"),
"confirm_save_from_refuse",
"",
"", 1);
1785 if ($action ==
'delete') {
1786 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"DeleteTrip"), $langs->trans(
"ConfirmDeleteTrip"),
"confirm_delete",
"",
"", 1);
1789 if ($action ==
'validate') {
1790 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"ValideTrip"), $langs->trans(
"ConfirmValideTrip"),
"confirm_approve",
"",
"", 1);
1793 if ($action ==
'paid') {
1794 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"PaidTrip"), $langs->trans(
"ConfirmPaidTrip"),
"confirm_paid",
"",
"", 1);
1797 if ($action ==
'cancel') {
1798 $array_input = array(
'text' => $langs->trans(
"ConfirmCancelTrip"), 0 => array(
'type' =>
"text",
'label' =>
'<strong>'.$langs->trans(
"Comment").
'</strong>',
'name' =>
"detail_cancel",
'value' =>
""));
1799 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"Cancel"),
"",
"confirm_cancel", $array_input,
"", 1);
1802 if ($action ==
'setdraft') {
1803 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"BrouillonnerTrip"), $langs->trans(
"ConfirmBrouillonnerTrip"),
"confirm_setdraft",
"",
"", 1);
1806 if ($action ==
'refuse') {
1807 $array_input = array(
'text' => $langs->trans(
"ConfirmRefuseTrip"), 0 => array(
'type' =>
"text",
'label' => $langs->trans(
"Comment"),
'name' =>
"detail_refuse",
'value' =>
""));
1808 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"Deny"),
'',
"confirm_refuse", $array_input,
"yes", 1);
1811 if ($action ==
'delete_line') {
1812 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".
$id.
"&rowid=".
GETPOSTINT(
'rowid'), $langs->trans(
"DeleteLine"), $langs->trans(
"ConfirmDeleteLine"),
"confirm_delete_line",
'',
'yes', 1);
1816 $parameters = array(
'formConfirm' => $formconfirm);
1817 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
1818 if (empty($reshook)) {
1819 $formconfirm .= $hookmanager->resPrint;
1820 } elseif ($reshook > 0) {
1821 $formconfirm = $hookmanager->resPrint;
1828 $linkback =
'<a href="'.DOL_URL_ROOT.
'/expensereport/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
1830 $morehtmlref =
'<div class="refidno">';
1831 $morehtmlref .=
'</div>';
1833 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
1835 print
'<div class="fichecenter">';
1836 print
'<div class="fichehalfleft">';
1837 print
'<div class="underbanner clearboth"></div>';
1839 print
'<table class="border tableforfield centpercent">';
1843 print
'<td class="titlefield">'.$langs->trans(
"User").
'</td>';
1845 if (
$object->fk_user_author > 0) {
1847 $result = $userauthor->fetch(
$object->fk_user_author);
1850 } elseif ($result > 0) {
1851 print $userauthor->getNomUrl(-1);
1858 print
'<td class="titlefield">'.$langs->trans(
"Period").
'</td>';
1865 print
'<td>'.$langs->trans(
"ModePaiement").
'</td>';
1866 print
'<td>'.$object->fk_c_paiement.
'</td>';
1872 print
'<td>'.$langs->trans(
"DATE_SAVE").
'</td>';
1873 print
'<td>'.dol_print_date(
$object->date_valid,
'dayhour',
'tzuser');
1875 print
' '.img_warning($langs->trans(
"Late").
' - '.$langs->trans(
"ToApprove"));
1878 print
' '.img_warning($langs->trans(
"Late").
' - '.$langs->trans(
"ToPay"));
1886 print
'<td>'.$langs->trans(
"VALIDATOR").
'</td>';
1888 if (
$object->fk_user_validator > 0) {
1890 $result = $userfee->fetch(
$object->fk_user_validator);
1892 print $userfee->getNomUrl(-1);
1894 if (empty($userfee->email) || !
isValidEmail($userfee->email)) {
1895 $langs->load(
"errors");
1896 print
img_warning($langs->trans(
"ErrorBadEMail", $userfee->email));
1902 print
'<td>'.$langs->trans(
"CANCEL_USER").
'</span></td>';
1904 if (
$object->fk_user_cancel > 0) {
1906 $result = $userfee->fetch(
$object->fk_user_cancel);
1908 print $userfee->getNomUrl(-1);
1914 print
'<td>'.$langs->trans(
"MOTIF_CANCEL").
'</td>';
1915 print
'<td>'.$object->detail_cancel.
'</td></tr>';
1918 print
'<td>'.$langs->trans(
"DATE_CANCEL").
'</td>';
1919 print
'<td>'.dol_print_date(
$object->date_cancel,
'dayhour',
'tzuser').
'</td></tr>';
1923 print
'<td>'.$langs->trans(
"ApprovedBy").
'</td>';
1925 if (
$object->fk_user_approve > 0) {
1927 $result = $userapp->fetch(
$object->fk_user_approve);
1929 print $userapp->getNomUrl(-1);
1935 print
'<td>'.$langs->trans(
"DateApprove").
'</td>';
1936 print
'<td>'.dol_print_date(
$object->date_approve,
'dayhour',
'tzuser').
'</td></tr>';
1942 print
'<td>'.$langs->trans(
"REFUSEUR").
'</td>';
1945 $result = $userfee->fetch(
$object->fk_user_refuse);
1947 print $userfee->getNomUrl(-1);
1952 print
'<td>'.$langs->trans(
"DATE_REFUS").
'</td>';
1953 print
'<td>'.dol_print_date(
$object->date_refuse,
'dayhour',
'tzuser');
1955 print
' - '.$object->detail_refuse;
1979 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
1984 print
'<div class="fichehalfright">';
1985 print
'<div class="underbanner clearboth"></div>';
1987 print
'<table class="border tableforfield centpercent">';
1991 print
'<td class="titlefieldmiddle">'.$langs->trans(
"AmountHT").
'</td>';
1992 print
'<td class="nowrap amountcard">'.price(
$object->total_ht, 1,
'', 1, - 1, - 1,
$conf->currency).
'</td>';
2009 print
'<td>'.$langs->trans(
"AmountVAT").
'</td>';
2010 print
'<td class="nowrap amountcard">'.price(
$object->total_tva, 1,
'', 1, -1, -1,
$conf->currency).
'</td>';
2014 if (
$mysoc->localtax1_assuj ==
"1" ||
$object->total_localtax1 != 0) {
2015 print
'<tr><td>'.$langs->transcountry(
"AmountLT1",
$mysoc->country_code).
'</td>';
2016 print
'<td class="valuefield">'.price(
$object->total_localtax1, 1,
'', 1, -1, -1,
$conf->currency).
'</td></tr>';
2018 if (
$mysoc->localtax2_assuj ==
"1" ||
$object->total_localtax2 != 0) {
2019 print
'<tr><td>'.$langs->transcountry(
"AmountLT2",
$mysoc->country_code).
'</td>';
2020 print
'<td class="valuefield">'.price(
$object->total_localtax2, 1,
'', 1, -1, -1,
$conf->currency).
'</td></tr>';
2024 print
'<td>'.$langs->trans(
"AmountTTC").
'</td>';
2025 print
'<td class="nowrap amountcard">'.price(
$object->total_ttc, 1,
'', 1, -1, -1,
$conf->currency).
'</td>';
2029 $canSeeBankAccount =
isModEnabled(
'bank') && $user->hasRight(
'banque',
'lire');
2032 if ($canSeeBankAccount) {
2037 print
'<div class="div-table-responsive-no-min">';
2038 print
'<table class="noborder paymenttable centpercent">';
2040 print
'<tr class="liste_titre">';
2041 print
'<td class="liste_titre">'.$langs->trans(
'Payments').
'</td>';
2042 print
'<td class="liste_titre">'.$langs->trans(
'Date').
'</td>';
2043 print
'<td class="liste_titre">'.$langs->trans(
'Type').
'</td>';
2044 if ($canSeeBankAccount) {
2045 print
'<td class="liste_titre right">'.$langs->trans(
'BankAccount').
'</td>';
2047 print
'<td class="liste_titre" width="18"> </td>';
2048 print
'<td class="liste_titre right">'.$langs->trans(
'Amount').
'</td>';
2052 $sql =
"SELECT p.rowid, p.num_payment, p.datep as dp, p.amount, p.fk_bank,";
2053 $sql .=
"c.code as payment_code, c.libelle as payment_type,";
2054 $sql .=
"ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal";
2055 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as e, ".MAIN_DB_PREFIX.
"payment_expensereport as p";
2056 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON p.fk_typepayment = c.id";
2057 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
2058 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
2059 $sql .=
" WHERE e.rowid = ".((int) $id);
2060 $sql .=
" AND p.fk_expensereport = e.rowid";
2061 $sql .=
' AND e.entity IN ('.getEntity(
'expensereport').
')';
2062 $sql .=
" ORDER BY dp";
2064 $resql =
$db->query($sql);
2066 $num =
$db->num_rows($resql);
2070 $objp =
$db->fetch_object($resql);
2072 $paymentexpensereportstatic->id = $objp->rowid;
2073 $paymentexpensereportstatic->datep =
$db->jdate($objp->dp);
2074 $paymentexpensereportstatic->ref = $objp->rowid;
2075 $paymentexpensereportstatic->num_payment = $objp->num_payment;
2076 $paymentexpensereportstatic->type_code = $objp->payment_code;
2077 $paymentexpensereportstatic->type_label = $objp->payment_type;
2079 print
'<tr class="oddeven">';
2081 print $paymentexpensereportstatic->getNomUrl(1);
2083 print
'<td>'.dol_print_date(
$db->jdate($objp->dp),
'day').
"</td>\n";
2084 $labeltype = $langs->trans(
"PaymentType".$objp->payment_code) !=
"PaymentType".$objp->payment_code ? $langs->trans(
"PaymentType".$objp->payment_code) : $objp->payment_type;
2085 print
"<td>".$labeltype.
' '.$objp->num_payment.
"</td>\n";
2087 if ($canSeeBankAccount) {
2088 $bankaccountstatic->id = $objp->baid;
2089 $bankaccountstatic->ref = $objp->baref;
2090 $bankaccountstatic->label = $objp->baref;
2091 $bankaccountstatic->number = $objp->banumber;
2094 $bankaccountstatic->account_number = $objp->account_number;
2097 $accountingjournal->fetch($objp->fk_accountancy_journal);
2098 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
2101 print
'<td class="right">';
2102 if ($bankaccountstatic->id) {
2103 print $bankaccountstatic->getNomUrl(1,
'transactions');
2108 print
'<td class="right">'.price($objp->amount).
"</td>";
2110 $totalpaid += $objp->amount;
2116 $resteapayeraffiche = $remaintopay;
2118 if ($remaintopay > 0) {
2119 $cssforamountpaymentcomplete =
'amountremaintopay';
2121 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
2125 $cssforamountpaymentcomplete =
'amountpaymentneutral strikefordisabled';
2126 } elseif (
$object->paid == 1 && $remaintopay > 0) {
2127 $cssforamountpaymentcomplete =
'amountpaymentneutral strikefordisabled';
2129 print
'<tr><td colspan="'.$nbcols.
'" class="right">'.$langs->trans(
"AlreadyPaid").
':</td>';
2131 print
'<td class="right">'.price($totalpaid).
'</td></tr>';
2133 print
'<tr><td colspan="'.$nbcols.
'" class="right">'.$langs->trans(
"AmountExpected").
':</td>';
2135 print
'<td class="right">'.price(
$object->total_ttc).
'</td></tr>';
2137 print
'<tr><td colspan="'.$nbcols.
'" class="right">'.$langs->trans(
"RemainderToPay").
':</td>';
2139 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td></tr>';
2148 print
'<div class="clearboth"></div>';
2154 print
'<div style="clear: both;"></div>';
2156 $actiontouse =
'updateline';
2158 $actiontouse =
'addline';
2161 print
'<form name="expensereport" action="'.$_SERVER[
"PHP_SELF"].
'" enctype="multipart/form-data" method="post" >';
2162 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2163 print
'<input type="hidden" name="action" value="'.$actiontouse.
'">';
2164 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
2165 print
'<input type="hidden" name="fk_expensereport" value="'.$object->id.
'" />';
2166 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
2167 print
'<input type="hidden" name="page_y" value="">';
2169 print
'<div class="div-table-responsive-no-min">';
2170 print
'<table id="tablelines" class="noborder centpercent">';
2176 print
'<tr class="liste_titre headerexpensereportdet">';
2177 print
'<td class="center linecollinenb">'.$langs->trans(
'LineNb').
'</td>';
2179 print
'<td class="center linecoldate">'.$langs->trans(
'Date').
'</td>';
2181 print
'<td class="minwidth100imp linecolproject">'.$langs->trans(
'Project').
'</td>';
2183 print
'<td class="center linecoltype">'.$langs->trans(
'Type').
'</td>';
2185 print
'<td class="center linecolcarcategory">'.$langs->trans(
'CarCategory').
'</td>';
2187 print
'<td class="linecoldescription">'.$langs->trans(
'Description').
'</td>';
2188 print
'<td class="right linecolvat">'.$langs->trans(
'VAT').
'</td>';
2189 print
'<td class="right linecolpriceuht">'.$langs->trans(
'PriceUHT').
'</td>';
2190 print
'<td class="right linecolpriceuttc">'.$langs->trans(
'PriceUTTC').
'</td>';
2191 print
'<td class="right linecolqty">'.$langs->trans(
'Qty').
'</td>';
2192 if ($action !=
'editline') {
2193 print
'<td class="right linecolamountht">'.$langs->trans(
'AmountHT').
'</td>';
2194 print
'<td class="right linecolamountttc">'.$langs->trans(
'AmountTTC').
'</td>';
2206 print
'<td class="right"></td>';
2210 foreach (
$object->lines as &$line) {
2213 if ($action !=
'editline' || $line->id !=
GETPOSTINT(
'rowid')) {
2214 print
'<tr class="oddeven linetr" data-id="'.$line->id.
'">';
2217 print
'<td class="center linecollinenb">';
2222 print
'<td class="center linecoldate">'.dol_print_date(
$db->jdate($line->date),
'day').
'</td>';
2226 print
'<td class="lineproject">';
2227 if ($line->fk_project > 0) {
2228 $projecttmp->id = $line->fk_project;
2229 $projecttmp->ref = $line->projet_ref;
2230 $projecttmp->title = $line->projet_title;
2231 print $projecttmp->getNomUrl(1);
2238 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
2240 $resaccountingaccount = $accountingaccount->fetch(0, $line->type_fees_accountancy_code, 1);
2242 $titlealt .= $langs->trans(
"AccountancyCode").
': ';
2243 if ($resaccountingaccount > 0) {
2244 $titlealt .= $accountingaccount->account_number;
2246 $titlealt .= $langs->trans(
"NotFound");
2252 print
'<td class="center linecoltype" title="'.dol_escape_htmltag($titlealt).
'">';
2253 $labeltype = ($langs->trans(($line->type_fees_code)) == $line->type_fees_code ? $line->type_fees_libelle : $langs->trans($line->type_fees_code));
2259 print
'<td class="fk_c_exp_tax_cat linecoltaxcat">';
2260 $exp_tax_cat_label =
dol_getIdFromCode(
$db, $line->fk_c_exp_tax_cat,
'c_exp_tax_cat',
'rowid',
'label');
2261 print $langs->trans($exp_tax_cat_label);
2266 print
'<td class="left linecolcomment minwidth100">'.dol_nl2br($line->comments).
'</td>';
2269 $senderissupplier = 0;
2270 $tooltiponprice =
'';
2271 $tooltiponpriceend =
'';
2273 $tooltiponprice = $langs->transcountry(
"TotalHT",
$mysoc->country_code).
'='.
price($line->total_ht);
2274 $tooltiponprice .=
'<br>'.$langs->transcountry(
"TotalVAT", ($senderissupplier ?
$object->thirdparty->country_code :
$mysoc->country_code)).
'='.
price($line->total_tva);
2275 if (is_object(
$object->thirdparty)) {
2276 if ($senderissupplier) {
2277 $seller =
$object->thirdparty;
2284 if (
$mysoc->useLocalTax(1)) {
2285 if (($seller->country_code == $buyer->country_code) || $line->total_localtax1 || $seller->useLocalTax(1)) {
2286 $tooltiponprice .=
'<br>'.$langs->transcountry(
"TotalLT1", $seller->country_code).
'='.
price($line->total_localtax1);
2288 $tooltiponprice .=
'<br>'.$langs->transcountry(
"TotalLT1", $seller->country_code).
'=<span class="opacitymedium">'.$langs->trans($senderissupplier ?
"NotUsedForThisVendor" :
"NotUsedForThisCustomer").
'</span>';
2291 if (
$mysoc->useLocalTax(2)) {
2292 if ((isset($seller->country_code) && isset($buyer->thirdparty->country_code) && $seller->country_code == $buyer->thirdparty->country_code) || $line->total_localtax2 || $seller->useLocalTax(2)) {
2293 $tooltiponprice .=
'<br>'.$langs->transcountry(
"TotalLT2", $seller->country_code).
'='.
price($line->total_localtax2);
2295 $tooltiponprice .=
'<br>'.$langs->transcountry(
"TotalLT2", $seller->country_code).
'=<span class="opacitymedium">'.$langs->trans($senderissupplier ?
"NotUsedForThisVendor" :
"NotUsedForThisCustomer").
'</span>';
2299 $tooltiponprice .=
'<br>'.$langs->transcountry(
"TotalTTC",
$mysoc->country_code).
'='.
price($line->total_ttc);
2301 $tooltiponprice =
'<span class="classfortooltip" title="'.dol_escape_htmltag($tooltiponprice).
'">';
2302 $tooltiponpriceend =
'</span>';
2305 print
'<td class="right linecolvatrate">';
2306 print $tooltiponprice;
2307 print
vatrate($line->vatrate.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
''), true);
2308 print $tooltiponpriceend;
2312 print
'<td class="right linecolunitht">';
2313 if (!empty($line->value_unit_ht)) {
2314 print
price($line->value_unit_ht);
2316 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $line->vatrate));
2317 $pricenettoshow =
price2num((
float) $line->value_unit / (1 + (
float) $tmpvat / 100),
'MU');
2318 print
price($pricenettoshow);
2322 print
'<td class="right linecolunitttc">'.price($line->value_unit).
'</td>';
2324 print
'<td class="right linecolqty">'.dol_escape_htmltag((
string) $line->qty).
'</td>';
2326 if ($action !=
'editline') {
2327 print
'<td class="right linecoltotalht">'.price($line->total_ht).
'</td>';
2328 print
'<td class="right linecoltotalttc">'.price($line->total_ttc).
'</td>';
2332 print
'<td class="center linecolpreview">';
2333 if ($line->fk_ecm_files > 0) {
2334 $modulepart =
'expensereport';
2335 $maxheightmini = 32;
2337 $result = $ecmfilesstatic->fetch($line->fk_ecm_files);
2339 $relativepath = preg_replace(
'/expensereport\//',
'', $ecmfilesstatic->filepath);
2340 $fileinfo = pathinfo($ecmfilesstatic->filepath.
'/'.$ecmfilesstatic->filename);
2343 if (!
dol_is_file(
$conf->expensereport->dir_output.
'/'.$relativepath.
'/'.$minifile)) {
2347 $urlforhref =
getAdvancedPreviewUrl($modulepart, $relativepath.
'/'.$fileinfo[
'filename'].
'.'.strtolower($fileinfo[
'extension']), 1,
'&entity='.(empty(
$object->entity) ?
$conf->entity :
$object->entity));
2348 if (empty($urlforhref)) {
2349 $urlforhref = DOL_URL_ROOT.
'/viewimage.php?modulepart='.$modulepart.
'&entity='.(empty(
$object->entity) ?
$conf->entity :
$object->entity).
'&file='.urlencode($relativepath.$fileinfo[
'filename'].
'.'.strtolower($fileinfo[
'extension']));
2350 print
'<a href="'.$urlforhref.
'" class="aphoto" target="_blank" rel="noopener noreferrer">';
2352 print
'<a href="'.$urlforhref[
'url'].
'" class="'.$urlforhref[
'css'].
'" target="'.$urlforhref[
'target'].
'" mime="'.$urlforhref[
'mime'].
'">';
2354 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="">';
2357 if (preg_match(
'/\.pdf$/i', $ecmfilesstatic->filename)) {
2358 $filepdf =
$conf->expensereport->dir_output.
'/'.$relativepath.
'/'.$ecmfilesstatic->filename;
2359 $fileimage =
$conf->expensereport->dir_output.
'/'.$relativepath.
'/'.$ecmfilesstatic->filename.
'_preview.png';
2360 $relativepathimage = $relativepath.
'/'.$ecmfilesstatic->filename.
'_preview.png';
2362 $pdfexists = file_exists($filepdf);
2365 if (!file_exists($fileimage) || (filemtime($fileimage) < filemtime($filepdf))) {
2367 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2376 if ($pdfexists && !$error) {
2377 $heightforphotref = 70;
2378 if (!empty(
$conf->dol_optimize_smallscreen)) {
2379 $heightforphotref = 60;
2381 $urlforhref =
getAdvancedPreviewUrl($modulepart, $relativepath.
'/'.$fileinfo[
'filename'].
'.'.strtolower($fileinfo[
'extension']), 1,
'&entity='.(empty(
$object->entity) ?
$conf->entity :
$object->entity));
2382 print
'<a href="'.$urlforhref[
'url'].
'" class="'.$urlforhref[
'css'].
'" target="'.$urlforhref[
'target'].
'" mime="'.$urlforhref[
'mime'].
'">';
2384 if (file_exists($fileimage)) {
2385 print
'<img height="'.$heightforphotref.
'" class="photo photowithmargin photowithborder" src="'.DOL_URL_ROOT.
'/viewimage.php?modulepart=apercu'.$modulepart.
'&file='.urlencode($relativepathimage).
'">';
2388 print
img_mime($ecmfilesstatic->filename);
2398 print
'<td class="nowrap right linecolwarning">';
2399 print !empty($line->rule_warning_message) ?
img_warning($line->rule_warning_message) :
' ';
2404 print
'<td class="nowrap right linecolaction">';
2406 print
'<a class="editfielda reposition paddingrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=editline&token='.
newToken().
'&rowid='.$line->rowid.
'">';
2408 print
'</a> ';
2409 print
'<a class="paddingrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=delete_line&token='.
newToken().
'&rowid='.$line->rowid.
'">';
2419 if ($action ==
'editline' && $line->id ==
GETPOSTINT(
'rowid')) {
2429 print
'<!-- line of expense report -->'.
"\n";
2430 print
'<tr class="tredited">';
2432 print
'<td class="center">';
2436 print
'<td colspan="'.($colspan - 1).
'" class="liste_titre"> ';
2437 print
'<a href="" class="commonlink auploadnewfilenow reposition">'.$langs->trans(
"UploadANewFileNow");
2438 print
img_picto($langs->trans(
"UploadANewFileNow"),
'chevron-down',
'', 0, 0, 0,
'',
'marginleftonly');
2441 print
' - <a href="" class="commonlink aattachtodoc reposition">'.$langs->trans(
"AttachTheNewLineToTheDocument");
2442 print
img_picto($langs->trans(
"AttachTheNewLineToTheDocument"),
'chevron-down',
'', 0, 0, 0,
'',
'marginleftonly');
2446 print
'<!-- Code to open/close section to submit or link files in edit mode -->'.
"\n";
2447 print
'<script type="text/javascript">'.
"\n";
2448 print
'$(document).ready(function() {
2449 $( ".auploadnewfilenow" ).click(function() {
2450 jQuery(".truploadnewfilenow").toggle();
2451 jQuery(".trattachnewfilenow").hide();
2454 $( ".aattachtodoc" ).click(function() {
2455 jQuery(".trattachnewfilenow").toggle();
2456 jQuery(".truploadnewfilenow").hide();
2459 if (is_array(
GETPOST(
'attachfile',
'array')) && count(
GETPOST(
'attachfile',
'array'))) {
2460 print
'jQuery(".trattachnewfilenow").toggle();'.
"\n";
2463 jQuery("form[name=\"expensereport\"]").submit(function() {
2464 if (jQuery(".truploadnewfilenow").is(":hidden")) {
2465 jQuery("input[name=\"sendit\"]").val("");
2472 print
'</script>'.
"\n";
2475 $filenamelinked =
'';
2476 if ($line->fk_ecm_files > 0) {
2477 $result = $ecmfilesstatic->fetch($line->fk_ecm_files);
2479 $filenamelinked = $ecmfilesstatic->filename;
2483 $tredited =
'tredited';
2484 include DOL_DOCUMENT_ROOT.
'/expensereport/tpl/expensereport_addfile.tpl.php';
2485 include DOL_DOCUMENT_ROOT.
'/expensereport/tpl/expensereport_linktofile.tpl.php';
2487 print
'<tr class="oddeven tredited">';
2492 print
'<td class="center">';
2493 print $form->selectDate($line->date,
'date');
2498 print
'<td class="nowraponall">';
2499 print $formproject->select_projects(-1, (
string) $line->fk_project,
'fk_project', 0, 0, $projectRequired ? 0 : 1, 1, 0, 0, 0,
'', 1, 0,
'maxwidth300');
2504 print
'<td class="center">';
2505 print $formexpensereport->selectTypeExpenseReport($line->fk_c_type_fees,
'fk_c_type_fees');
2509 print
'<td class="fk_c_exp_tax_cat">';
2510 $params = array(
'fk_expense' =>
$object->id,
'fk_expense_det' => $line->id,
'date' => $line->date);
2511 print $form->selectExpenseCategories((
string) $line->fk_c_exp_tax_cat,
'fk_c_exp_tax_cat', 1, array(),
'fk_c_type_fees', (
int) $userauthor->default_c_exp_tax_cat, $params);
2517 print
'<textarea name="comments" class="flat_ndf centpercent">'.dol_escape_htmltag($line->comments, 0, 1).
'</textarea>';
2521 $selectedvat =
price2num($line->vatrate).(!empty($line->vat_src_code) ?
' ('.$line->vat_src_code.
')' :
'');
2522 print
'<td class="right">';
2524 print $form->load_tva(
'vatrate', (
GETPOSTISSET(
"vatrate") ?
GETPOST(
"vatrate") : $selectedvat), null, null, 0, 0,
'', false, 1, 2);
2528 print
'<td class="right">';
2529 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.
' />';
2533 print
'<td class="right">';
2534 print
'<input type="text" min="0" class="right maxwidth50" id="value_unit" name="value_unit" value="'.dol_escape_htmltag(
price2num($line->value_unit)).
'" />';
2538 print
'<td class="right">';
2539 print
'<input type="text" min="0" class="input_qty right maxwidth50" name="qty" value="'.dol_escape_htmltag((
string) $line->qty).
'" />';
2546 print
'<td class="center">';
2550 print
'<td class="center">';
2554 print
'<input type="hidden" name="rowid" value="'.$line->rowid.
'">';
2555 print $form->buttonsSaveCancel(
'Save',
'Cancel', array(),
false,
'small');
2574 if ($action !=
'editline') {
2578 $nbFiles = $nbLinks = 0;
2579 $arrayoffiles = array();
2581 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2582 require_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
2583 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
2586 $nbFiles = count($arrayoffiles);
2591 print
'<tr class="liste_titre">';
2592 print
'<td colspan="'.$colspan.
'" class="liste_titre expensereportautoload">';
2593 print
'<a href="" class="commonlink auploadnewfilenow reposition">'.$langs->trans(
"UploadANewFileNow");
2594 print
img_picto($langs->trans(
"UploadANewFileNow"),
'chevron-down',
'', 0, 0, 0,
'',
'marginleftonly');
2597 print
' - <a href="" class="commonlink aattachtodoc reposition">'.$langs->trans(
"AttachTheNewLineToTheDocument");
2598 print
img_picto($langs->trans(
"AttachTheNewLineToTheDocument"),
'chevron-down',
'', 0, 0, 0,
'',
'marginleftonly');
2602 print
'<!-- Code to open/close section to submit or link files in the form to add new line -->'.
"\n";
2603 print
'<script type="text/javascript">'.
"\n";
2604 print
'$(document).ready(function() {
2605 $( ".auploadnewfilenow" ).click(function() {
2606 console.log("We click on toggle of auploadnewfilenow");
2607 jQuery(".truploadnewfilenow").toggle();
2608 jQuery(".trattachnewfilenow").hide();
2609 if (jQuery(".truploadnewfilenow").is(":hidden")) {
2610 jQuery("input[name=\"sendit\"]").prop("name", "senditdisabled");
2612 jQuery("input[name=\"senditdisabled\"]").prop("name", "sendit");
2614 // TODO Switch css fa-chevron-dow and add fa-chevron-up
2617 $( ".aattachtodoc" ).click(function() {
2618 console.log("We click on toggle of aattachtodoc");
2619 jQuery(".trattachnewfilenow").toggle();
2620 jQuery(".truploadnewfilenow").hide();
2621 // TODO Switch css fa-chevron-dow and add fa-chevron-up
2624 if (is_array(
GETPOST(
'attachfile',
'array')) && count(
GETPOST(
'attachfile',
'array')) && $action !=
'updateline') {
2625 print
'jQuery(".trattachnewfilenow").show();'.
"\n";
2628 jQuery("form[name=\"expensereport\"]").submit(function() {
2629 if (jQuery(".truploadnewfilenow").is(":hidden")) {
2630 /* 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. */
2631 jQuery("input[name=\"sendit\"]").val("");
2632 jQuery("input[name=\"sendit\"]").prop("name", "senditdisabled");
2634 jQuery("input[name=\"senditdisabled\"]").prop("name", "sendit");
2641 print
'</script>'.
"\n";
2645 include DOL_DOCUMENT_ROOT.
'/expensereport/tpl/expensereport_linktofile.tpl.php';
2646 include DOL_DOCUMENT_ROOT.
'/expensereport/tpl/expensereport_addfile.tpl.php';
2648 print
'<tr class="liste_titre expensereportcreate">';
2650 print
'<td class="center expensereportcreatedate">'.$langs->trans(
'Date').
'</td>';
2652 print
'<td class="minwidth100imp">'.$form->textwithpicto($langs->trans(
'Project'), $langs->trans(
"ClosedProjectsAreHidden")).
'</td>';
2654 print
'<td class="center expensereportcreatetype">'.$langs->trans(
'Type').
'</td>';
2656 print
'<td>'.$langs->trans(
'CarCategory').
'</td>';
2658 print
'<td class="expensereportcreatedescription">'.$langs->trans(
'Description').
'</td>';
2659 print
'<td class="right expensereportcreatevat">'.$langs->trans(
'VAT').
'</td>';
2660 print
'<td class="right expensereportcreatepriceuth">'.$langs->trans(
'PriceUHT').
'</td>';
2661 print
'<td class="right expensereportcreatepricettc">'.$langs->trans(
'PriceUTTC').
'</td>';
2662 print
'<td class="right expensereportcreateqty">'.$langs->trans(
'Qty').
'</td>';
2669 print
'<tr class="oddeven nohover">';
2675 print
'<td class="center inputdate">';
2676 print $form->selectDate(!empty($date) ? $date : -1,
'date', 0, 0, 0,
'', 1, 1);
2681 print
'<td class="inputproject">';
2682 $formproject->select_projects(-1, !empty($fk_project) ? (
string) $fk_project :
'0',
'fk_project', 0, 0, $projectRequired ? 0 : 1, -1, 0, 0, 0,
'', 0, 0,
'maxwidth300');
2687 print
'<td class="center inputtype">';
2688 print $formexpensereport->selectTypeExpenseReport(!empty($fk_c_type_fees) ? $fk_c_type_fees :
"",
'fk_c_type_fees', 1);
2692 print
'<td class="fk_c_exp_tax_cat">';
2693 $params = array(
'fk_expense' =>
$object->id);
2694 print $form->selectExpenseCategories(
'',
'fk_c_exp_tax_cat', 1, array(),
'fk_c_type_fees', $userauthor->default_c_exp_tax_cat, $params, 0);
2699 print
'<td class="inputcomment">';
2700 print
'<textarea class="flat_ndf centpercent" name="comments" rows="'.ROWS_2.
'">'.
dol_escape_htmltag(!empty($comments) ? $comments :
"", 0, 1).
'</textarea>';
2704 print
'<td class="right inputvat">';
2708 $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS =
'none';
2711 print $form->load_tva(
'vatrate', (!empty($vatrate) ? $vatrate : $defaultvat), null, null, 0, 0,
'', false, 1);
2715 print
'<td class="right inputpricenet">';
2716 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.
' />';
2720 print
'<td class="right inputtax">';
2721 print
'<input type="text" class="right maxwidth50" id="value_unit" name="value_unit" value="'.dol_escape_htmltag((!empty($value_unit) ? $value_unit :
"")).
'">';
2725 print
'<td class="right inputqty">';
2726 print
'<input type="text" min="0" class=" input_qty right maxwidth50" name="qty" value="'.dol_escape_htmltag(!empty($qty) ? $qty : 1).
'">';
2732 if ($action !=
'editline') {
2733 print
'<td class="right"></td>';
2734 print
'<td class="right"></td>';
2738 print
'<td class="center inputbuttons">';
2739 print $form->buttonsSaveCancel(
"Add",
'', array(),
true,
'reposition');
2750 /* JQuery for product free or predefined select */
2751 jQuery(document).ready(function() {
2752 jQuery("#value_unit_ht").keyup(function(event) {
2753 console.log(event.which); // discard event tag and arrows
2754 if (event.which != 9 && (event.which < 37 ||event.which > 40) && jQuery("#value_unit_ht").val() != "") {
2755 jQuery("#value_unit").val("");
2758 jQuery("#value_unit").keyup(function(event) {
2759 console.log(event.which); // discard event tag and arrows
2760 if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#value_unit").val() != "") {
2761 jQuery("#value_unit_ht").val("");
2769 /* unit price coef calculation */
2770 jQuery(".input_qty, #fk_c_type_fees, #select_fk_c_exp_tax_cat, #vatrate ").change(function(event) {
2771 console.log("We change a parameter");
2773 let type_fee = jQuery("#fk_c_type_fees").find(":selected").val();
2774 let tax_cat = jQuery("#select_fk_c_exp_tax_cat").find(":selected").val();
2775 let tva = jQuery("#vatrate").find(":selected").val();
2776 let qty = jQuery(".input_qty").val();
2778 let path = "'.DOL_URL_ROOT.
'/expensereport/ajax/ajaxik.php";
2779 path += "?fk_c_exp_tax_cat="+tax_cat;
2780 path += "&fk_expense="+'.((int)
$object->id).
';
2781 path += "&vatrate="+tva;
2782 path += "&qty="+qty;
2784 if (type_fee == 4) { // mileage expenses
2785 if (tax_cat == "" || parseInt(tax_cat) <= 0){
2793 success: function(response) {
2794 if (response.response_status == "success"){';
2798 jQuery("#value_unit").val(parseFloat(response.data) * (100 + parseFloat(tva)) / 100);
2799 jQuery("#value_unit").trigger("change");
2803 jQuery("#value_unit_ht").val(response.data);
2804 jQuery("#value_unit_ht").trigger("change");
2805 jQuery("#value_unit").val("");
2810 } else if(response.response_status == "error" && response.errorMessage != undefined && response.errorMessage.length > 0 ) {
2811 console.log("We get an error result");
2812 $.jnotify(response.errorMessage, "error", {timeout: 0, type: "error"},{ remove: function (){} } );
2818 /*console.log(event.which); // discard event tag and arrows
2819 if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#value_unit").val() != "") {
2820 jQuery("#value_unit_ht").val("");
2840 print
'Record not found';
2851print
'<div class="tabsAction">';
2853if ($action !=
'create' && $action !=
'edit' && $action !=
'editline') {
2858 if (empty($user->socid)) {
2860 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email',
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'id' =>
$object->id,
'action' =>
'presend',
'mode' =>
'init'],
true).
'#formmailbeforetitle',
'');
2870 if (in_array(
$object->fk_user_author, $childids) || $user->hasRight(
'expensereport',
'writeall_advance')) {
2872 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>';
2875 if (count(
$object->lines) > 0) {
2876 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>';
2887 if ($user->id ==
$object->fk_user_author || $user->id ==
$object->fk_user_valid) {
2889 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>';
2891 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>';
2896 if ($user->id ==
$object->fk_user_author || $user->id ==
$object->fk_user_valid) {
2898 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>';
2908 if (in_array(
$object->fk_user_author, $childids)) {
2910 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>';
2918 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>';
2920 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>';
2923 if ($user->id ==
$object->fk_user_author || $user->id ==
$object->fk_user_valid) {
2925 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=cancel&token='.
newToken().
'&id='.
$object->id.
'">'.$langs->trans(
"Cancel").
'</a></div>';
2934 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=refuse&token='.
newToken().
'&id='.
$object->id.
'">'.$langs->trans(
'Deny').
'</a></div>';
2940 if ($remaintopay == 0) {
2941 print
'<div class="inline-block divButAction"><span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPayment').
'</span></div>';
2943 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>';
2951 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>";
2957 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>';
2966 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>';
2971 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>';
2975 if ($user->hasRight(
'expensereport',
'creer')) {
2976 print
'<div class="inline-block divButAction"><a class="butAction butActionClone" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=clone&token='.
newToken().
'">'.$langs->trans(
"ToClone").
'</a></div>';
2982 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>';
2985 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>';
2988 $parameters = array();
2989 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
2996if (
GETPOST(
'modelselected',
'alpha')) {
2997 $action =
'presend';
3000if ($action !=
'presend') {
3005 print
'<div class="fichecenter"><div class="fichehalfleft">';
3006 print
'<a name="builddoc"></a>';
3008 if ($user->hasRight(
'expensereport',
'creer') && $action !=
'create' && $action !=
'edit') {
3011 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".
$object->id;
3012 $genallowed = $user->hasRight(
'expensereport',
'creer');
3013 $delallowed = $user->hasRight(
'expensereport',
'creer');
3015 print $formfile->showdocuments(
'expensereport', $filename, $filedir, $urlsource, $genallowed, $delallowed);
3016 $somethingshown = $formfile->numoffiles;
3032 print
'</div><div class="fichehalfright">';
3034 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
3036 $somethingshown = $formactions->showactions($object,
'expensereport', 0);
3038 print
'</div></div>';
3042$modelmail =
'expensereport_send';
3043$defaulttopic =
'SendExpenseReportRef';
3044$diroutput =
$conf->expensereport->dir_output;
3045$trackid =
'exp'.$object->id;
3047include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
global $dolibarr_main_url_root
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class to manage bank accounts.
Class to manage accounting accounts.
Class to manage accounting journals.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Class to manage a WYSIWYG editor.
Class to manage ECM files.
Class to manage Trips and Expenses.
const STATUS_DRAFT
Draft status.
const STATUS_APPROVED
Classified approved.
const STATUS_CANCELED
Classified canceled.
const STATUS_CLOSED
Classified paid.
const STATUS_REFUSED
Classified refused.
const STATUS_VALIDATED
Validated (need to be paid)
Class of expense report details lines.
static count($dbs, $objecttype, $objectid)
Return nb of links.
Class to manage payments of expense report.
Class to manage projects.
Class to manage translations.
Class to manage Dolibarr users.
expensereport_prepare_head($object)
Prepare array with list of tabs.
dol_convert_file($fileinput, $ext='png', $fileoutput='', $page='')
Convert a PDF file into another image format.
dol_is_file($pathoffile)
Return if path is a file.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
$date_start
Variables from include:
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formatted for view output Used into pdf and HTML pages.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
img_mime($file, $titlealt='', $morecss='')
Show MIME img of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
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.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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.
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as date
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.