29 require
'../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formexpensereport.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
37 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
38 require_once DOL_DOCUMENT_ROOT.
'/core/lib/expensereport.lib.php';
39 require_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
40 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
41 require_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
42 require_once DOL_DOCUMENT_ROOT.
'/core/modules/expensereport/modules_expensereport.php';
43 require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
44 require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/paymentexpensereport.class.php';
45 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
46 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
47 if (!empty($conf->accounting->enabled)) {
48 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
52 $langs->loadLangs(array(
"trips",
"bills",
"mails"));
54 $action =
GETPOST(
'action',
'aZ09');
55 $cancel =
GETPOST(
'cancel',
'alpha');
56 $confirm =
GETPOST(
'confirm',
'alpha');
61 $fk_project =
GETPOST(
'fk_project',
'int');
62 $vatrate =
GETPOST(
'vatrate',
'alpha');
64 $comments =
GETPOST(
'comments',
'restricthtml');
65 $fk_c_type_fees =
GETPOST(
'fk_c_type_fees',
'int');
68 $childids = $user->getAllChildIds(1);
72 if ($user->socid) $socid = $user->socid;
73 $result =
restrictedArea($user,
'expensereport', $id,
'expensereport');
77 $rootfordata = DOL_DATA_ROOT;
78 $rootforuser = DOL_DATA_ROOT;
80 if (!empty($conf->multicompany->enabled) && !empty($conf->entity) && $conf->entity > 1)
82 $rootfordata .=
'/'.$conf->entity;
84 $conf->expensereport->dir_output = $rootfordata.
'/expensereport';
87 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
88 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
92 $hidedetails = (
GETPOST(
'hidedetails',
'int') ?
GETPOST(
'hidedetails',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
93 $hidedesc = (
GETPOST(
'hidedesc',
'int') ?
GETPOST(
'hidedesc',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
94 $hideref = (
GETPOST(
'hideref',
'int') ?
GETPOST(
'hideref',
'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
101 $extrafields->fetch_name_optionals_label($object->table_element);
104 include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
107 $hookmanager->initHooks(array(
'expensereportcard',
'globalcard'));
109 $permissionnote = $user->rights->expensereport->creer;
110 $permissiondellink = $user->rights->expensereport->creer;
111 $permissiontoadd = $user->rights->expensereport->creer;
121 if (!empty($user->rights->expensereport->readall)) $canread = 1;
122 if (!empty($user->rights->expensereport->lire) && in_array($object->fk_user_author, $childids)) $canread = 1;
134 $parameters = array(
'socid' => $socid);
135 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
136 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
142 if (!empty($backtopage))
144 header(
"Location: ".$backtopage);
158 $fk_c_type_fees = -1;
161 include DOL_DOCUMENT_ROOT.
'/core/actions_linkedfiles.inc.php';
165 if ($action ==
'updateline') $action =
'editline';
169 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
171 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
173 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
176 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $user->rights->expensereport->creer)
178 if (1 == 0 && !
GETPOST(
'clone_content',
'alpha') && !
GETPOST(
'clone_receivers',
'alpha'))
185 $orig = clone $object;
187 $result = $object->createFromClone($user,
GETPOST(
'fk_user_author',
'int'));
190 header(
"Location: ".
$_SERVER[
'PHP_SELF'].
'?id='.$result);
201 if ($action ==
'confirm_delete' &&
GETPOST(
"confirm",
'alpha') ==
"yes" && $id > 0 && $user->rights->expensereport->supprimer)
204 $result = $object->fetch($id);
205 $result = $object->delete($user);
208 header(
"Location: index.php");
215 if ($action ==
'add' && $user->rights->expensereport->creer)
221 $object->date_debut = $date_start;
222 $object->date_fin = $date_end;
224 $object->fk_user_author =
GETPOST(
'fk_user_author',
'int');
225 if (!($object->fk_user_author > 0)) $object->fk_user_author = $user->id;
228 if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->expensereport->creer))
229 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->expensereport->creer) && empty($user->rights->expensereport->writeall_advance))) {
234 if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->expensereport->writeall_advance)) {
235 if (!in_array($object->fk_user_author, $childids)) {
242 $fuser =
new User($db);
243 $fuser->fetch($object->fk_user_author);
246 $object->fk_c_paiement =
GETPOST(
'fk_c_paiement',
'int');
247 $object->fk_user_validator =
GETPOST(
'fk_user_validator',
'int');
248 $object->note_public =
GETPOST(
'note_public',
'restricthtml');
249 $object->note_private =
GETPOST(
'note_private',
'restricthtml');
253 $ret = $extrafields->setOptionalsFromPost(null, $object);
254 if ($ret < 0) $error++;
257 if (!$error && empty($conf->global->EXPENSEREPORT_ALLOW_OVERLAPPING_PERIODS) && $object->periode_existe($fuser, $object->date_debut, $object->date_fin))
268 $id = $object->create($user);
277 Header(
"Location: ".
$_SERVER[
"PHP_SELF"].
"?id=".$id);
287 if ($action ==
'update' && $user->rights->expensereport->creer)
292 $object->date_debut = $date_start;
293 $object->date_fin = $date_end;
295 if ($object->status < 3)
297 $object->fk_user_validator =
GETPOST(
'fk_user_validator',
'int');
300 $object->fk_c_paiement =
GETPOST(
'fk_c_paiement',
'int');
301 $object->note_public =
GETPOST(
'note_public',
'restricthtml');
302 $object->note_private =
GETPOST(
'note_private',
'restricthtml');
303 $object->fk_user_modif = $user->id;
305 $result = $object->update($user);
315 if ($action ==
'update_extras')
320 $ret = $extrafields->setOptionalsFromPost(null, $object,
GETPOST(
'attribute',
'restricthtml'));
321 if ($ret < 0) $error++;
326 $result = $object->insertExtraFields(
'EXPENSEREPORT_MODIFY');
335 $action =
'edit_extras';
338 if ($action ==
"confirm_validate" &&
GETPOST(
"confirm",
'alpha') ==
"yes" && $id > 0 && $user->rights->expensereport->creer)
347 $result = $object->setValidate($user);
352 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
354 $outputlangs = $langs;
356 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) $newlang =
GETPOST(
'lang_id',
'aZ09');
357 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
358 if (!empty($newlang)) {
360 $outputlangs->setDefaultLang($newlang);
362 $model = $object->model_pdf;
363 $ret = $object->fetch($id);
365 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
372 if (!$error && $result > 0 && $object->fk_user_validator > 0)
374 $langs->load(
"mails");
377 $destinataire =
new User($db);
378 $destinataire->fetch($object->fk_user_validator);
379 $emailTo = $destinataire->email;
382 $expediteur =
new User($db);
383 $expediteur->fetch($object->fk_user_author);
384 $emailFrom = $expediteur->email;
386 if ($emailTo && $emailFrom)
388 $filename = array(); $filedir = array(); $mimetype = array();
391 $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
392 if (!empty($conf->global->MAIN_APPLICATION_TITLE)) $societeName = $conf->global->MAIN_APPLICATION_TITLE;
394 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportWaitingForApproval");
397 $link = $urlwithroot.
'/expensereport/card.php?id='.$object->id;
398 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
399 $message = $langs->transnoentities(
"ExpenseReportWaitingForApprovalMessage", $expediteur->getFullName($langs),
get_date_range($object->date_debut, $object->date_fin,
'', $langs), $link);
414 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
419 $result = $mailfile->sendfile();
422 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
425 $langs->load(
"other");
426 if ($mailfile->error)
429 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
430 $mesg .=
'<br>'.$mailfile->error;
433 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null,
'warnings');
441 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"), null,
'warnings');
449 header(
"Location: ".
$_SERVER[
"PHP_SELF"].
"?id=".$id);
456 if ($action ==
"confirm_save_from_refuse" &&
GETPOST(
"confirm",
'alpha') ==
"yes" && $id > 0 && $user->rights->expensereport->creer)
460 $result = $object->set_save_from_refuse($user);
465 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
467 $outputlangs = $langs;
469 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) $newlang =
GETPOST(
'lang_id',
'aZ09');
470 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
471 if (!empty($newlang)) {
473 $outputlangs->setDefaultLang($newlang);
475 $model = $object->model_pdf;
476 $ret = $object->fetch($id);
478 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
487 $destinataire =
new User($db);
488 $destinataire->fetch($object->fk_user_validator);
489 $emailTo = $destinataire->email;
492 $expediteur =
new User($db);
493 $expediteur->fetch($object->fk_user_author);
494 $emailFrom = $expediteur->email;
496 if ($emailFrom && $emailTo)
498 $filename = array(); $filedir = array(); $mimetype = array();
501 $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
502 if (!empty($conf->global->MAIN_APPLICATION_TITLE)) $societeName = $conf->global->MAIN_APPLICATION_TITLE;
504 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportWaitingForReApproval");
507 $link = $urlwithroot.
'/expensereport/card.php?id='.$object->id;
508 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
509 $dateRefusEx = explode(
" ", $object->date_refuse);
510 $message = $langs->transnoentities(
"ExpenseReportWaitingForReApprovalMessage", $dateRefusEx[0], $object->detail_refuse, $expediteur->getFullName($langs), $link);
529 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
534 $result = $mailfile->sendfile();
537 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
539 header(
"Location: ".
$_SERVER[
"PHP_SELF"].
"?id=".$id);
542 $langs->load(
"other");
543 if ($mailfile->error)
546 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
547 $mesg .=
'<br>'.$mailfile->error;
550 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null,
'warnings');
558 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"), null,
'warnings');
567 if ($action ==
"confirm_approve" &&
GETPOST(
"confirm",
'alpha') ==
"yes" && $id > 0 && $user->rights->expensereport->approve)
572 $result = $object->setApproved($user);
577 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
579 $outputlangs = $langs;
581 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) $newlang =
GETPOST(
'lang_id',
'aZ09');
582 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
583 if (!empty($newlang)) {
585 $outputlangs->setDefaultLang($newlang);
587 $model = $object->model_pdf;
588 $ret = $object->fetch($id);
590 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
599 $destinataire =
new User($db);
600 $destinataire->fetch($object->fk_user_author);
601 $emailTo = $destinataire->email;
604 $emailCC = $conf->global->NDF_CC_EMAILS;
605 if (empty($emailTo)) $emailTo = $emailCC;
608 $expediteur =
new User($db);
609 $expediteur->fetch($object->fk_user_approve > 0 ? $object->fk_user_approve : $object->fk_user_validator);
610 $emailFrom = $expediteur->email;
612 if ($emailFrom && $emailTo)
614 $filename = array(); $filedir = array(); $mimetype = array();
617 $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
618 if (!empty($conf->global->MAIN_APPLICATION_TITLE)) $societeName = $conf->global->MAIN_APPLICATION_TITLE;
620 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportApproved");
623 $link = $urlwithroot.
'/expensereport/card.php?id='.$object->id;
624 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
625 $message = $langs->transnoentities(
"ExpenseReportApprovedMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $link);
642 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
647 $result = $mailfile->sendfile();
650 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
652 header(
"Location: ".
$_SERVER[
"PHP_SELF"].
"?id=".$id);
655 $langs->load(
"other");
656 if ($mailfile->error)
659 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
660 $mesg .=
'<br>'.$mailfile->error;
663 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null,
'warnings');
671 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"), null,
'warnings');
680 if ($action ==
"confirm_refuse" &&
GETPOST(
'confirm',
'alpha') ==
"yes" && $id > 0 && $user->rights->expensereport->approve)
685 $detailRefuse =
GETPOST(
'detail_refuse',
'alpha');
686 $result = $object->setDeny($user, $detailRefuse);
691 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
693 $outputlangs = $langs;
695 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) $newlang =
GETPOST(
'lang_id',
'aZ09');
696 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
697 if (!empty($newlang)) {
699 $outputlangs->setDefaultLang($newlang);
701 $model = $object->model_pdf;
702 $ret = $object->fetch($id);
704 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
713 $destinataire =
new User($db);
714 $destinataire->fetch($object->fk_user_author);
715 $emailTo = $destinataire->email;
718 $expediteur =
new User($db);
719 $expediteur->fetch($object->fk_user_refuse);
720 $emailFrom = $expediteur->email;
722 if ($emailFrom && $emailTo)
724 $filename = array(); $filedir = array(); $mimetype = array();
727 $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
728 if (!empty($conf->global->MAIN_APPLICATION_TITLE)) $societeName = $conf->global->MAIN_APPLICATION_TITLE;
730 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportRefused");
733 $link = $urlwithroot.
'/expensereport/card.php?id='.$object->id;
734 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
735 $message = $langs->transnoentities(
"ExpenseReportRefusedMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $detailRefuse, $link);
753 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
758 $result = $mailfile->sendfile();
761 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
763 header(
"Location: ".
$_SERVER[
"PHP_SELF"].
"?id=".$id);
766 $langs->load(
"other");
767 if ($mailfile->error)
770 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
771 $mesg .=
'<br>'.$mailfile->error;
774 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null,
'warnings');
782 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"), null,
'warnings');
792 if ($action ==
"confirm_cancel" &&
GETPOST(
'confirm',
'alpha') ==
"yes" && $id > 0 && $user->rights->expensereport->creer)
794 if (!
GETPOST(
'detail_cancel',
'alpha'))
796 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Comment")), null,
'errors');
801 if ($user->id == $object->fk_user_valid || $user->id == $object->fk_user_author)
803 $detailCancel =
GETPOST(
'detail_cancel',
'alpha');
804 $result = $object->set_cancel($user, $detailCancel);
809 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
811 $outputlangs = $langs;
813 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) $newlang =
GETPOST(
'lang_id',
'aZ09');
814 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
815 if (!empty($newlang)) {
817 $outputlangs->setDefaultLang($newlang);
819 $model = $object->model_pdf;
820 $ret = $object->fetch($id);
822 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
831 $destinataire =
new User($db);
832 $destinataire->fetch($object->fk_user_author);
833 $emailTo = $destinataire->email;
836 $expediteur =
new User($db);
837 $expediteur->fetch($object->fk_user_cancel);
838 $emailFrom = $expediteur->email;
840 if ($emailFrom && $emailTo)
842 $filename = array(); $filedir = array(); $mimetype = array();
845 $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
846 if (!empty($conf->global->MAIN_APPLICATION_TITLE)) $societeName = $conf->global->MAIN_APPLICATION_TITLE;
848 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportCanceled");
851 $link = $urlwithroot.
'/expensereport/card.php?id='.$object->id;
852 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
853 $message = $langs->transnoentities(
"ExpenseReportCanceledMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $detailCancel, $link);
871 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
876 $result = $mailfile->sendfile();
879 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
881 header(
"Location: ".
$_SERVER[
"PHP_SELF"].
"?id=".$id);
884 $langs->load(
"other");
885 if ($mailfile->error)
888 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
889 $mesg .=
'<br>'.$mailfile->error;
892 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null,
'warnings');
900 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"), null,
'warnings');
913 if ($action ==
"confirm_setdraft" &&
GETPOST(
'confirm',
'alpha') ==
"yes" && $id > 0 && $user->rights->expensereport->creer)
917 if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid)
919 $result = $object->setStatut(0);
924 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
926 $outputlangs = $langs;
928 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) $newlang =
GETPOST(
'lang_id',
'aZ09');
929 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
930 if (!empty($newlang)) {
932 $outputlangs->setDefaultLang($newlang);
934 $model = $object->model_pdf;
935 $ret = $object->fetch($id);
937 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
943 header(
"Location: ".
$_SERVER[
"PHP_SELF"].
"?id=".$id);
953 if ($action ==
'set_unpaid' && $id > 0 && $user->rights->expensereport->to_paid)
958 $result = $object->set_unpaid($user);
963 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
965 $outputlangs = $langs;
967 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) $newlang =
GETPOST(
'lang_id',
'aZ09');
968 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
969 if (!empty($newlang)) {
971 $outputlangs->setDefaultLang($newlang);
973 $model = $object->model_pdf;
974 $ret = $object->fetch($id);
976 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
981 if ($action ==
'set_paid' && $id > 0 && $user->rights->expensereport->to_paid)
986 $result = $object->set_paid($id, $user);
991 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
993 $outputlangs = $langs;
995 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) $newlang =
GETPOST(
'lang_id',
'aZ09');
996 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
997 if (!empty($newlang)) {
999 $outputlangs->setDefaultLang($newlang);
1001 $model = $object->model_pdf;
1002 $ret = $object->fetch($id);
1004 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1013 $destinataire =
new User($db);
1014 $destinataire->fetch($object->fk_user_author);
1015 $emailTo = $destinataire->email;
1018 $expediteur =
new User($db);
1019 $expediteur->fetch($user->id);
1020 $emailFrom = $expediteur->email;
1022 if ($emailFrom && $emailTo)
1024 $filename = array(); $filedir = array(); $mimetype = array();
1027 $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM;
1028 if (!empty($conf->global->MAIN_APPLICATION_TITLE)) $societeName = $conf->global->MAIN_APPLICATION_TITLE;
1030 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportPaid");
1033 $link = $urlwithroot.
'/expensereport/card.php?id='.$object->id;
1034 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
1035 $message = $langs->transnoentities(
"ExpenseReportPaidMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $link);
1038 $object->setDocModel($user,
"");
1039 $resultPDF = expensereport_pdf_create($db, $object,
'',
"", $langs);
1042 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
1047 $result = $mailfile->sendfile();
1050 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
1052 header(
"Location: ".
$_SERVER[
"PHP_SELF"].
"?id=".$id);
1055 $langs->load(
"other");
1056 if ($mailfile->error)
1059 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
1060 $mesg .=
'<br>'.$mailfile->error;
1063 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null,
'warnings');
1071 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"), null,
'warnings');
1080 if ($action ==
"addline" && $user->rights->expensereport->creer)
1088 $arrayoffiles =
GETPOST(
'attachfile',
'array');
1089 if (is_array($arrayoffiles) && !empty($arrayoffiles[0]))
1091 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1092 $relativepath =
'expensereport/'.$object->ref.
'/'.$arrayoffiles[0];
1094 $ecmfiles->fetch(0,
'', $relativepath);
1095 $fk_ecm_files = $ecmfiles->id;
1100 if (empty($vatrate)) $vatrate =
"0.000";
1101 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $vatrate));
1105 if (empty($value_unit))
1107 $value_unit =
price2num($value_unit_ht + ($value_unit_ht * $tmpvat / 100),
'MU');
1110 $fk_c_exp_tax_cat =
GETPOST(
'fk_c_exp_tax_cat',
'int');
1113 if (empty($qty)) $qty = 1;
1115 if (!($fk_c_type_fees > 0))
1118 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")), null,
'errors');
1122 if ((
int) $tmpvat < 0 || $tmpvat ==
'')
1125 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"VAT")), null,
'errors');
1130 if (empty($date) || $date ==
"--")
1133 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")), null,
'errors');
1136 if ($value_unit == 0)
1139 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"PriceUTTC")), null,
'errors');
1142 if ($date < $object->date_debut || $date > ($object->date_fin + (24 * 3600 - 1)))
1144 $langs->load(
"errors");
1145 setEventMessages($langs->trans(
"WarningDateOfLineMustBeInExpenseReportRange"), null,
'warnings');
1153 $result = $object->addline($qty, $value_unit, $fk_c_type_fees, $vatrate, $date, $comments, $fk_project, $fk_c_exp_tax_cat, $type, $fk_ecm_files);
1156 $ret = $object->fetch($object->id);
1158 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1160 $outputlangs = $langs;
1161 $newlang =
GETPOST(
'lang_id',
'alpha');
1162 if (!empty($conf->global->MAIN_MULTILANGS) && empty($newlang))
1163 $newlang = $object->thirdparty->default_lang;
1164 if (!empty($newlang)) {
1165 $outputlangs =
new Translate(
"", $conf);
1166 $outputlangs->setDefaultLang($newlang);
1169 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1173 unset($value_unit_ht);
1177 unset($fk_c_type_fees);
1189 if ($action ==
'confirm_delete_line' &&
GETPOST(
"confirm",
'alpha') ==
"yes" && $user->rights->expensereport->creer)
1192 $object->fetch($id);
1195 $object_ligne->fetch(
GETPOST(
"rowid",
'int'));
1196 $total_ht = $object_ligne->total_ht;
1197 $total_tva = $object_ligne->total_tva;
1199 $result = $object->deleteline(
GETPOST(
"rowid",
'int'), $user);
1205 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
1207 $outputlangs = $langs;
1209 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) $newlang =
GETPOST(
'lang_id',
'aZ09');
1210 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
1211 if (!empty($newlang)) {
1212 $outputlangs =
new Translate(
"", $conf);
1213 $outputlangs->setDefaultLang($newlang);
1215 $model = $object->model_pdf;
1216 $ret = $object->fetch($id);
1218 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1222 $object->update_totaux_del($object_ligne->total_ht, $object_ligne->total_tva);
1223 header(
"Location: ".
$_SERVER[
"PHP_SELF"].
"?id=".$_GET[
'id']);
1230 if ($action ==
"updateline" && $user->rights->expensereport->creer)
1233 $object->fetch($id);
1239 $arrayoffiles =
GETPOST(
'attachfile',
'array');
1240 if (is_array($arrayoffiles) && !empty($arrayoffiles[0]))
1242 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1243 $relativepath =
'expensereport/'.$object->ref.
'/'.$arrayoffiles[0];
1245 $ecmfiles->fetch(0,
'', $relativepath);
1246 $fk_ecm_files = $ecmfiles->id;
1250 $rowid = $_POST[
'rowid'];
1251 $type_fees_id =
GETPOST(
'fk_c_type_fees',
'int');
1252 $fk_c_exp_tax_cat =
GETPOST(
'fk_c_exp_tax_cat',
'int');
1253 $projet_id = $fk_project;
1254 $comments =
GETPOST(
'comments',
'restricthtml');
1256 $vatrate =
GETPOST(
'vatrate',
'alpha');
1259 if (empty($vatrate)) $vatrate =
"0.000";
1260 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $vatrate));
1264 if (empty($value_unit))
1266 $value_unit =
price2num($value_unit_ht + ($value_unit_ht * $tmpvat / 100),
'MU');
1269 if (!
GETPOST(
'fk_c_type_fees',
'int') > 0)
1272 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")), null,
'errors');
1275 if ((
int) $tmpvat < 0 || $tmpvat ==
'')
1278 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Vat")), null,
'errors');
1282 if ($date < $object->date_debut || $date > ($object->date_fin + (24 * 3600 - 1)))
1284 $langs->load(
"errors");
1285 setEventMessages($langs->trans(
"WarningDateOfLineMustBeInExpenseReportRange"), null,
'warnings');
1291 $result = $object->updateline($rowid, $type_fees_id, $projet_id, $vatrate, $comments, $qty, $value_unit, $date, $id, $fk_c_exp_tax_cat, $fk_ecm_files);
1297 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
1299 $outputlangs = $langs;
1301 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) $newlang =
GETPOST(
'lang_id',
'aZ09');
1302 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
1303 if (!empty($newlang)) {
1304 $outputlangs =
new Translate(
"", $conf);
1305 $outputlangs->setDefaultLang($newlang);
1307 $model = $object->model_pdf;
1308 $ret = $object->fetch($id);
1310 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1314 $result = $object->recalculer($id);
1325 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
1328 $triggersendname =
'EXPENSEREPORT_SENTBYMAIL';
1329 $autocopy =
'MAIN_MAIL_AUTOCOPY_EXPENSEREPORT_TO';
1330 $trackid =
'exp'.$object->id;
1331 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
1334 $upload_dir = $conf->expensereport->dir_output;
1335 $permissiontoadd = $user->rights->expensereport->creer;
1336 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1344 $title = $langs->trans(
"ExpenseReport").
" - ".$langs->trans(
"Card");
1345 $helpurl =
"EN:Module_Expense_Reports";
1349 $form =
new Form($db);
1352 $projecttmp =
new Project($db);
1354 $bankaccountstatic =
new Account($db);
1355 $ecmfilesstatic =
new EcmFiles($db);
1359 if ($action ==
'create')
1363 print '<form action="'.$_SERVER[
'PHP_SELF'].
'" method="post" name="create">';
1364 print '<input type="hidden" name="token" value="'.newToken().
'">';
1365 print '<input type="hidden" name="action" value="add">';
1369 print '<table class="border centpercent">';
1374 print '<td class="titlefieldcreate fieldrequired">'.$langs->trans(
"DateStart").
'</td>';
1376 print $form->selectDate($date_start ? $date_start : -1,
'date_debut', 0, 0, 0,
'', 1, 1);
1382 print '<td class="fieldrequired">'.$langs->trans(
"DateEnd").
'</td>';
1384 print $form->selectDate($date_end ? $date_end : -1,
'date_fin', 0, 0, 0,
'', 1, 1);
1390 print '<td class="fieldrequired">'.$langs->trans(
"User").
'</td>';
1392 $defaultselectuser = $user->id;
1393 if (
GETPOST(
'fk_user_author',
'int') > 0) $defaultselectuser =
GETPOST(
'fk_user_author',
'int');
1394 $include_users =
'hierarchyme';
1395 if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expensereport->writeall_advance)) $include_users = array();
1396 $s = $form->select_dolusers($defaultselectuser,
"fk_user_author", 0,
"", 0, $include_users,
'',
'0,'.$conf->entity);
1403 print '<td>'.$langs->trans(
"VALIDATOR").
'</td>';
1406 $include_users = $object->fetch_users_approver_expensereport();
1407 if (empty($include_users))
print img_warning().
' '.$langs->trans(
"NobodyHasPermissionToValidateExpenseReport");
1409 $defaultselectuser = (empty($user->fk_user_expense_validator) ? $user->fk_user : $user->fk_user_expense_validator);
1410 if (!empty($conf->global->EXPENSEREPORT_DEFAULT_VALIDATOR)) $defaultselectuser = $conf->global->EXPENSEREPORT_DEFAULT_VALIDATOR;
1411 if (
GETPOST(
'fk_user_validator',
'int') > 0) $defaultselectuser =
GETPOST(
'fk_user_validator',
'int');
1412 $s = $form->select_dolusers($defaultselectuser,
"fk_user_validator", 1,
"", ((empty($defaultselectuser) || empty($conf->global->EXPENSEREPORT_DEFAULT_VALIDATOR_UNCHANGEABLE)) ? 0 : 1), $include_users);
1413 print $form->textwithpicto($s, $langs->trans(
"AnyOtherInThisListCanValidate"));
1419 if (!empty($conf->global->EXPENSEREPORT_ASK_PAYMENTMODE_ON_CREATION))
1422 print '<td>'.$langs->trans(
"ModePaiement").
'</td>';
1424 $form->select_types_paiements(
'',
'fk_c_paiement');
1431 print '<td class="tdtop">'.$langs->trans(
'NotePublic').
'</td>';
1434 $doleditor =
new DolEditor(
'note_public', $note_public,
'', 80,
'dolibarr_notes',
'In', 0,
false,
true, ROWS_3,
'90%');
1435 print $doleditor->Create(1);
1439 if (empty($user->socid)) {
1441 print '<td class="tdtop">'.$langs->trans(
'NotePrivate').
'</td>';
1444 $doleditor =
new DolEditor(
'note_private', $note_private,
'', 80,
'dolibarr_notes',
'In', 0,
false,
true, ROWS_3,
'90%');
1445 print $doleditor->Create(1);
1450 $parameters = array(
'colspan' =>
' colspan="3"',
'cols' => 3);
1451 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
1452 print $hookmanager->resPrint;
1453 if (empty($reshook)) {
1454 print $object->showOptionals($extrafields,
'edit', $parameters);
1462 print '<div class="center">';
1463 print '<input type="submit" value="'.$langs->trans(
"AddTrip").
'" name="bouton" class="button" />';
1464 print ' <input type="button" value="'.$langs->trans(
"Cancel").
'" class="button button-cancel" onclick="history.go(-1)" />';
1469 if ($id > 0 || $ref) {
1470 $result = $object->fetch($id, $ref);
1472 $res = $object->fetch_optionals();
1476 if (!in_array($object->fk_user_author, $user->getAllChildIds(1)))
1478 if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)
1479 && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->expensereport->writeall_advance)))
1483 print '<div class="tabBar">';
1484 print $langs->trans(
'NotUserRightToView');
1497 if ($action ==
'edit' && ($object->status < 3 || $object->status == 99))
1499 print
"<form name='update' action=\"".$_SERVER[
'PHP_SELF'].
"\" method=\"post\">\n";
1500 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1501 print
'<input type="hidden" name="id" value="'.$id.
'">';
1505 if ($object->status == 99)
1507 print
'<input type="hidden" name="action" value="updateFromRefuse">';
1509 print
'<input type="hidden" name="action" value="update">';
1512 $linkback =
'<a href="'.DOL_URL_ROOT.
'/expensereport/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
1514 print
'<table class="border" style="width:100%;">';
1517 print
'<td>'.$langs->trans(
"User").
'</td>';
1519 $userfee =
new User($db);
1520 if ($object->fk_user_author > 0)
1522 $userfee->fetch($object->fk_user_author);
1523 print $userfee->getNomUrl(-1);
1528 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Ref").
'</td><td>';
1529 print $form->showrefnav($object,
'ref', $linkback, 1,
'ref',
'ref',
'');
1533 print
'<td>'.$langs->trans(
"DateStart").
'</td>';
1535 print $form->selectDate($object->date_debut,
'date_debut');
1539 print
'<td>'.$langs->trans(
"DateEnd").
'</td>';
1541 print $form->selectDate($object->date_fin,
'date_fin');
1545 if (!empty($conf->global->EXPENSEREPORT_ASK_PAYMENTMODE_ON_CREATION))
1548 print
'<td>'.$langs->trans(
"ModePaiement").
'</td>';
1550 $form->select_types_paiements($object->fk_c_paiement,
'fk_c_paiement');
1555 if ($object->status < 3)
1558 print
'<td>'.$langs->trans(
"VALIDATOR").
'</td>';
1560 $include_users = $object->fetch_users_approver_expensereport();
1561 $s = $form->select_dolusers($object->fk_user_validator,
"fk_user_validator", 1,
"", 0, $include_users);
1562 print $form->textwithpicto($s, $langs->trans(
"AnyOtherInThisListCanValidate"));
1567 print
'<td>'.$langs->trans(
"VALIDOR").
'</td>';
1569 $userfee =
new User($db);
1570 $userfee->fetch($object->fk_user_valid);
1571 print $userfee->getNomUrl(-1);
1575 if ($object->status == 6)
1578 print
'<td>'.$langs->trans(
"AUTHORPAIEMENT").
'</td>';
1580 $userfee =
new User($db);
1581 $userfee->fetch($user->id);
1582 print $userfee->getNomUrl(-1);
1594 print
'<div class="center">';
1595 print
'<input type="submit" value="'.$langs->trans(
"Modify").
'" name="bouton" class="button">';
1596 print
' <input type="button" value="'.$langs->trans(
"Cancel").
'" class="button button-cancel" onclick="history.go(-1)" />';
1604 if ($action ==
'clone') {
1606 $criteriaforfilter =
'hierarchyme';
1607 if (!empty($user->rights->expensereport->readall)) $criteriaforfilter =
'';
1608 $formquestion = array(
1610 array(
'type' =>
'other',
'name' =>
'fk_user_author',
'label' => $langs->trans(
"SelectTargetUser"),
'value' => $form->select_dolusers((
GETPOST(
'fk_user_author',
'int') > 0 ?
GETPOST(
'fk_user_author',
'int') : $user->id),
'fk_user_author', 0, null, 0, $criteriaforfilter,
'',
'0', 0, 0,
'', 0,
'',
'maxwidth150'))
1613 $formconfirm = $form->formconfirm(
$_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneExpenseReport', $object->ref),
'confirm_clone', $formquestion,
'yes', 1);
1616 if ($action ==
'save')
1618 $formconfirm = $form->formconfirm(
$_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"SaveTrip"), $langs->trans(
"ConfirmSaveTrip"),
"confirm_validate",
"",
"", 1);
1621 if ($action ==
'save_from_refuse')
1623 $formconfirm = $form->formconfirm(
$_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"SaveTrip"), $langs->trans(
"ConfirmSaveTrip"),
"confirm_save_from_refuse",
"",
"", 1);
1626 if ($action ==
'delete')
1628 $formconfirm = $form->formconfirm(
$_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"DeleteTrip"), $langs->trans(
"ConfirmDeleteTrip"),
"confirm_delete",
"",
"", 1);
1631 if ($action ==
'validate')
1633 $formconfirm = $form->formconfirm(
$_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"ValideTrip"), $langs->trans(
"ConfirmValideTrip"),
"confirm_approve",
"",
"", 1);
1636 if ($action ==
'paid')
1638 $formconfirm = $form->formconfirm(
$_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"PaidTrip"), $langs->trans(
"ConfirmPaidTrip"),
"confirm_paid",
"",
"", 1);
1641 if ($action ==
'cancel')
1643 $array_input = array(
'text'=>$langs->trans(
"ConfirmCancelTrip"), array(
'type'=>
"text",
'label'=>
'<strong>'.$langs->trans(
"Comment").
'</strong>',
'name'=>
"detail_cancel",
'value'=>
""));
1644 $formconfirm = $form->formconfirm(
$_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"Cancel"),
"",
"confirm_cancel", $array_input,
"", 1);
1647 if ($action ==
'setdraft')
1649 $formconfirm = $form->formconfirm(
$_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"BrouillonnerTrip"), $langs->trans(
"ConfirmBrouillonnerTrip"),
"confirm_setdraft",
"",
"", 1);
1652 if ($action ==
'refuse')
1654 $array_input = array(
'text'=>$langs->trans(
"ConfirmRefuseTrip"), array(
'type'=>
"text",
'label'=>$langs->trans(
"Comment"),
'name'=>
"detail_refuse",
'value'=>
""));
1655 $formconfirm = $form->formconfirm(
$_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"Deny"),
'',
"confirm_refuse", $array_input,
"yes", 1);
1658 if ($action ==
'delete_line')
1660 $formconfirm = $form->formconfirm(
$_SERVER[
"PHP_SELF"].
"?id=".$id.
"&rowid=".
GETPOST(
'rowid',
'int'), $langs->trans(
"DeleteLine"), $langs->trans(
"ConfirmDeleteLine"),
"confirm_delete_line",
'',
'yes', 1);
1667 $linkback =
'<a href="'.DOL_URL_ROOT.
'/expensereport/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
1669 $morehtmlref =
'<div class="refidno">';
1708 $morehtmlref .=
'</div>';
1710 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
1712 print
'<div class="fichecenter">';
1713 print
'<div class="fichehalfleft">';
1714 print
'<div class="underbanner clearboth"></div>';
1716 print
'<table class="border tableforfield centpercent">';
1720 print
'<td class="titlefield">'.$langs->trans(
"User").
'</td>';
1722 if ($object->fk_user_author > 0)
1724 $userauthor =
new User($db);
1725 $result = $userauthor->fetch($object->fk_user_author);
1727 elseif ($result > 0) print $userauthor->getNomUrl(-1);
1733 print '<td class="titlefield">'.$langs->trans("Period").'</td>';
1735 print
get_date_range($object->date_debut, $object->date_fin, 'day', $langs, 0);
1738 if (!empty($conf->global->EXPENSEREPORT_ASK_PAYMENTMODE_ON_CREATION))
1741 print
'<td>'.$langs->trans(
"ModePaiement").
'</td>';
1742 print
'<td>'.$object->fk_c_paiement.
'</td>';
1748 print
'<td>'.$langs->trans(
"DATE_SAVE").
'</td>';
1749 print
'<td>'.dol_print_date($object->date_valid,
'dayhour',
'tzuser');
1750 if ($object->status == 2 && $object->hasDelay(
'toapprove')) print
' '.
img_warning($langs->trans(
"Late").
' - '.$langs->trans(
"ToApprove"));
1751 if ($object->status == 5 && $object->hasDelay(
'topay')) print
' '.
img_warning($langs->trans(
"Late").
' - '.$langs->trans(
"ToPay"));
1759 print
'<td>'.$langs->trans(
"VALIDATOR").
'</td>';
1761 if ($object->fk_user_validator > 0)
1763 $userfee =
new User($db);
1764 $result = $userfee->fetch($object->fk_user_validator);
1765 if ($result > 0) print $userfee->getNomUrl(-1);
1766 if (empty($userfee->email) || !
isValidEmail($userfee->email))
1768 $langs->load(
"errors");
1769 print
img_warning($langs->trans(
"ErrorBadEMail", $userfee->email));
1776 print
'<td>'.$langs->trans(
"CANCEL_USER").
'</span></td>';
1778 if ($object->fk_user_cancel > 0)
1780 $userfee =
new User($db);
1781 $result = $userfee->fetch($object->fk_user_cancel);
1782 if ($result > 0) print $userfee->getNomUrl(-1);
1787 print
'<td>'.$langs->trans(
"MOTIF_CANCEL").
'</td>';
1788 print
'<td>'.$object->detail_cancel.
'</td></tr>';
1791 print
'<td>'.$langs->trans(
"DATE_CANCEL").
'</td>';
1792 print
'<td>'.dol_print_date($object->date_cancel,
'dayhour',
'tzuser').
'</td></tr>';
1796 print
'<td>'.$langs->trans(
"ApprovedBy").
'</td>';
1798 if ($object->fk_user_approve > 0)
1800 $userapp =
new User($db);
1801 $result = $userapp->fetch($object->fk_user_approve);
1802 if ($result > 0) print $userapp->getNomUrl(-1);
1807 print
'<td>'.$langs->trans(
"DateApprove").
'</td>';
1808 print
'<td>'.dol_print_date($object->date_approve,
'dayhour',
'tzuser').
'</td></tr>';
1812 if ($object->status == 99 || !empty($object->detail_refuse))
1815 print
'<td>'.$langs->trans(
"REFUSEUR").
'</td>';
1817 $userfee =
new User($db);
1818 $result = $userfee->fetch($object->fk_user_refuse);
1819 if ($result > 0) print $userfee->getNomUrl(-1);
1823 print
'<td>'.$langs->trans(
"DATE_REFUS").
'</td>';
1824 print
'<td>'.dol_print_date($object->date_refuse,
'dayhour',
'tzuser');
1825 if ($object->detail_refuse) print
' - '.$object->detail_refuse;
1830 if ($object->status == $object::STATUS_CLOSED)
1849 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
1854 print
'<div class="fichehalfright">';
1855 print
'<div class="ficheaddleft">';
1856 print
'<div class="underbanner clearboth"></div>';
1858 print
'<table class="border tableforfield centpercent">';
1862 print
'<td class="titlefieldmiddle">'.$langs->trans(
"AmountHT").
'</td>';
1863 print
'<td class="nowrap amountcard">'.price($object->total_ht, 1,
'', 1, - 1, - 1, $conf->currency).
'</td>';
1868 if ($object->status ==
ExpenseReport::STATUS_REFUSED || !empty($object->detail_refuse)) $rowspan += 2;
1874 print '<td>'.$langs->trans("AmountVAT").'</td>';
1875 print '<td class="nowrap amountcard">'.
price($object->total_tva, 1, '', 1, - 1, - 1, $conf->currency).'</td>';
1879 print '<td>'.$langs->trans("AmountTTC").'</td>';
1880 print '<td class="nowrap amountcard">'.
price($object->total_ttc, 1, '', 1, - 1, - 1, $conf->currency).'</td>';
1885 if (!empty($conf->banque->enabled)) {
1890 print
'<table class="noborder paymenttable" width="100%">';
1892 print
'<tr class="liste_titre">';
1893 print
'<td class="liste_titre">'.$langs->trans(
'Payments').
'</td>';
1894 print
'<td class="liste_titre">'.$langs->trans(
'Date').
'</td>';
1895 print
'<td class="liste_titre">'.$langs->trans(
'Type').
'</td>';
1896 if (!empty($conf->banque->enabled)) {
1897 print
'<td class="liste_titre right">'.$langs->trans(
'BankAccount').
'</td>';
1899 print
'<td class="liste_titre right">'.$langs->trans(
'Amount').
'</td>';
1900 print
'<td class="liste_titre" width="18"> </td>';
1904 $sql =
"SELECT p.rowid, p.num_payment, p.datep as dp, p.amount, p.fk_bank,";
1905 $sql .=
"c.code as p_code, c.libelle as payment_type,";
1906 $sql .=
"ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal";
1907 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as e, ".MAIN_DB_PREFIX.
"payment_expensereport as p";
1908 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON p.fk_typepayment = c.id";
1909 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
1910 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
1911 $sql .=
" WHERE e.rowid = '".$id.
"'";
1912 $sql .=
" AND p.fk_expensereport = e.rowid";
1913 $sql .=
' AND e.entity IN ('.getEntity(
'expensereport').
')';
1914 $sql .=
" ORDER BY dp";
1916 $resql = $db->query($sql);
1919 $num = $db->num_rows(
$resql);
1920 $i = 0; $totalpaid = 0;
1923 $objp = $db->fetch_object(
$resql);
1925 $paymentexpensereportstatic->id = $objp->rowid;
1926 $paymentexpensereportstatic->datepaye = $db->jdate($objp->dp);
1927 $paymentexpensereportstatic->ref = $objp->rowid;
1928 $paymentexpensereportstatic->num_payment = $objp->num_payment;
1929 $paymentexpensereportstatic->payment_code = $objp->payment_code;
1931 print
'<tr class="oddseven">';
1933 print $paymentexpensereportstatic->getNomUrl(1);
1935 print
'<td>'.dol_print_date($db->jdate($objp->dp),
'day').
"</td>\n";
1936 $labeltype = $langs->trans(
"PaymentType".$objp->p_code) != (
"PaymentType".$objp->p_code) ? $langs->trans(
"PaymentType".$objp->p_code) : $objp->payment_type;
1937 print
"<td>".$labeltype.
' '.$objp->num_payment.
"</td>\n";
1938 if (!empty($conf->banque->enabled))
1940 $bankaccountstatic->id = $objp->baid;
1941 $bankaccountstatic->ref = $objp->baref;
1942 $bankaccountstatic->label = $objp->baref;
1943 $bankaccountstatic->number = $objp->banumber;
1945 if (!empty($conf->accounting->enabled)) {
1946 $bankaccountstatic->account_number = $objp->account_number;
1949 $accountingjournal->fetch($objp->fk_accountancy_journal);
1950 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
1953 print
'<td class="right">';
1954 if ($bankaccountstatic->id)
1955 print $bankaccountstatic->getNomUrl(1,
'transactions');
1958 print
'<td class="right">'.price($objp->amount).
"</td>";
1961 $totalpaid += $objp->amount;
1964 if (!is_null($totalpaid))
1969 $remaintopay =
price2num($object->total_ttc - $totalpaid);
1970 $resteapayeraffiche = $remaintopay;
1972 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
1976 $cssforamountpaymentcomplete =
'amountpaymentneutral';
1977 $resteapayeraffiche = 0;
1978 } elseif ($object->paid == 0)
1980 $cssforamountpaymentcomplete =
'amountpaymentneutral';
1982 print
'<tr><td colspan="'.$nbcols.
'" class="right">'.$langs->trans(
"AlreadyPaid").
':</td><td class="right">'.
price($totalpaid).
'</td><td></td></tr>';
1983 print
'<tr><td colspan="'.$nbcols.
'" class="right">'.$langs->trans(
"AmountExpected").
':</td><td class="right">'.
price($object->total_ttc).
'</td><td></td></tr>';
1985 print
'<tr><td colspan="'.$nbcols.
'" class="right">'.$langs->trans(
"RemainderToPay").
':</td>';
1986 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td><td></td></tr>';
1998 print
'<div class="clearboth"></div><br>';
2000 print
'<div style="clear: both;"></div>';
2002 $actiontouse =
'updateline';
2003 if (($object->status == 0 || $object->status == 99) && $action !=
'editline') $actiontouse =
'addline';
2005 print
'<form name="expensereport" action="'.$_SERVER[
"PHP_SELF"].
'" enctype="multipart/form-data" method="post" >';
2006 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2007 print
'<input type="hidden" name="action" value="'.$actiontouse.
'">';
2008 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
2009 print
'<input type="hidden" name="fk_expensereport" value="'.$object->id.
'" />';
2011 print
'<div class="div-table-responsive-no-min">';
2012 print
'<table id="tablelines" class="noborder centpercent">';
2014 if (!empty($object->lines))
2018 print
'<tr class="liste_titre">';
2019 print
'<td class="center">'.$langs->trans(
'LineNb').
'</td>';
2021 print
'<td class="center">'.$langs->trans(
'Date').
'</td>';
2022 if (!empty($conf->projet->enabled)) print
'<td class="minwidth100imp">'.$langs->trans(
'Project').
'</td>';
2023 print
'<td class="center">'.$langs->trans(
'Type').
'</td>';
2024 if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) print
'<td>'.$langs->trans(
'CarCategory').
'</td>';
2025 print
'<td>'.$langs->trans(
'Description').
'</td>';
2026 print
'<td class="right">'.$langs->trans(
'VAT').
'</td>';
2027 print
'<td class="right">'.$langs->trans(
'PriceUHT').
'</td>';
2028 print
'<td class="right">'.$langs->trans(
'PriceUTTC').
'</td>';
2029 print
'<td class="right">'.$langs->trans(
'Qty').
'</td>';
2030 if ($action !=
'editline')
2032 print
'<td class="right">'.$langs->trans(
'AmountHT').
'</td>';
2033 print
'<td class="right">'.$langs->trans(
'AmountTTC').
'</td>';
2039 if (($object->status < 2 || $object->status == 99) && $user->rights->expensereport->creer)
2041 print
'<td class="right"></td>';
2045 foreach ($object->lines as &$line)
2049 if ($action !=
'editline' || $line->rowid !=
GETPOST(
'rowid',
'int'))
2051 print
'<tr class="oddeven">';
2054 print
'<td class="center">';
2059 print
'<td class="center">'.dol_print_date($db->jdate($line->date),
'day').
'</td>';
2062 if (!empty($conf->projet->enabled))
2065 if ($line->fk_project > 0)
2067 $projecttmp->id = $line->fk_project;
2068 $projecttmp->ref = $line->projet_ref;
2069 $projecttmp->title = $line->projet_title;
2070 print $projecttmp->getNomUrl(1);
2076 print
'<td class="center">';
2077 $labeltype = ($langs->trans(($line->type_fees_code)) == $line->type_fees_code ? $line->type_fees_libelle : $langs->trans($line->type_fees_code));
2082 if (!empty($conf->global->MAIN_USE_EXPENSE_IK))
2084 print
'<td class="fk_c_exp_tax_cat">';
2085 print
dol_getIdFromCode($db, $line->fk_c_exp_tax_cat,
'c_exp_tax_cat',
'rowid',
'label');
2090 print
'<td class="left">'.dol_nl2br($line->comments).
'</td>';
2092 print
'<td class="right">'.vatrate($line->vatrate,
true).
'</td>';
2094 print
'<td class="right">';
2095 if (!empty($line->value_unit_ht))
2097 print
price($line->value_unit_ht);
2099 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $line->vatrate));
2100 $pricenettoshow =
price2num($line->value_unit / (1 + $tmpvat / 100),
'MU');
2101 print $pricenettoshow;
2105 print
'<td class="right">'.price($line->value_unit).
'</td>';
2107 print
'<td class="right">'.dol_escape_htmltag($line->qty).
'</td>';
2109 if ($action !=
'editline')
2111 print
'<td class="right">'.price($line->total_ht).
'</td>';
2112 print
'<td class="right">'.price($line->total_ttc).
'</td>';
2116 print
'<td class="center">';
2117 if ($line->fk_ecm_files > 0)
2119 $modulepart =
'expensereport';
2120 $maxheightmini = 32;
2122 $result = $ecmfilesstatic->fetch($line->fk_ecm_files);
2125 $relativepath = preg_replace(
'/expensereport\//',
'', $ecmfilesstatic->filepath);
2126 $fileinfo = pathinfo($ecmfilesstatic->filepath.
'/'.$ecmfilesstatic->filename);
2132 $urlforhref =
getAdvancedPreviewUrl($modulepart, $relativepath.
'/'.$fileinfo[
'filename'].
'.'.strtolower($fileinfo[
'extension']), 1,
'&entity='.(!empty($object->entity) ? $object->entity : $conf->entity));
2133 if (empty($urlforhref)) {
2134 $urlforhref = DOL_URL_ROOT.
'/viewimage.php?modulepart='.$modulepart.
'&entity='.(!empty($object->entity) ? $object->entity : $conf->entity).
'&file='.urlencode($relativepath.$fileinfo[
'filename'].
'.'.strtolower($fileinfo[
'extension']));
2135 print
'<a href="'.$urlforhref.
'" class="aphoto" target="_blank">';
2137 print
'<a href="'.$urlforhref[
'url'].
'" class="'.$urlforhref[
'css'].
'" target="'.$urlforhref[
'target'].
'" mime="'.$urlforhref[
'mime'].
'">';
2139 print
'<img class="photo" height="'.$maxheightmini.
'" src="'.DOL_URL_ROOT.
'/viewimage.php?modulepart='.$modulepart.
'&entity='.(!empty($object->entity) ? $object->entity : $conf->entity).
'&file='.urlencode($relativepath.
'/'.$minifile).
'" title="">';
2142 $modulepart =
'expensereport';
2144 if (preg_match(
'/\.pdf$/i', $ecmfilesstatic->filename))
2146 $filepdf = $conf->expensereport->dir_output.
'/'.$relativepath.
'/'.$ecmfilesstatic->filename;
2147 $fileimage = $conf->expensereport->dir_output.
'/'.$relativepath.
'/'.$ecmfilesstatic->filename.
'_preview.png';
2148 $relativepathimage = $relativepath.
'/'.$ecmfilesstatic->filename.
'_preview.png';
2150 $pdfexists = file_exists($filepdf);
2154 if (!file_exists($fileimage) || (filemtime($fileimage) < filemtime($filepdf)))
2156 if (empty($conf->global->MAIN_DISABLE_PDF_THUMBS))
2158 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2160 if ($ret < 0) $error++;
2165 if ($pdfexists && !$error)
2167 $heightforphotref = 70;
2168 if (!empty($conf->dol_optimize_smallscreen)) $heightforphotref = 60;
2170 if (file_exists($fileimage))
2173 print
'<img height="'.$heightforphotref.
'" class="photo photowithmargin photowithborder" src="'.DOL_URL_ROOT.
'/viewimage.php?modulepart=apercu'.$modulepart.
'&file='.urlencode($relativepathimage).
'">';
2180 print
img_mime($ecmfilesstatic->filename);
2190 print
'<td class="nowrap right">';
2192 print
'<a class="editfielda reposition paddingrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=editline&token='.
newToken().
'&rowid='.$line->rowid.
'">';
2194 print
'</a> ';
2195 print
'<a class="paddingrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delete_line&token='.
newToken().
'&rowid='.$line->rowid.
'">';
2205 if ($action ==
'editline' && $line->rowid ==
GETPOST(
'rowid',
'int'))
2209 if (!empty($conf->projet->enabled)) $colspan++;
2210 if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) $colspan++;
2212 print
'<tr class="tredited">';
2214 print
'<td class="center">';
2218 print
'<td colspan="'.($colspan - 1).
'" class="liste_titre">';
2219 print
'<a href="" class="commonlink auploadnewfilenow reposition">'.$langs->trans(
"UploadANewFileNow");
2220 print
img_picto($langs->trans(
"UploadANewFileNow"),
'chevron-down',
'',
false, 0, 0,
'',
'marginleftonly');
2222 if (empty($conf->global->EXPENSEREPORT_DISABLE_ATTACHMENT_ON_LINES))
2224 print
' - <a href="" class="commonlink aattachtodoc reposition">'.$langs->trans(
"AttachTheNewLineToTheDocument");
2225 print
img_picto($langs->trans(
"AttachTheNewLineToTheDocument"),
'chevron-down',
'',
false, 0, 0,
'',
'marginleftonly');
2229 print
'<script language="javascript">'.
"\n";
2230 print
'$(document).ready(function() {
2231 $( ".auploadnewfilenow" ).click(function() {
2232 jQuery(".truploadnewfilenow").toggle();
2233 jQuery(".trattachnewfilenow").hide();
2236 $( ".aattachtodoc" ).click(function() {
2237 jQuery(".trattachnewfilenow").toggle();
2238 jQuery(".truploadnewfilenow").hide();
2241 if (is_array(
GETPOST(
'attachfile',
'array')) && count(
GETPOST(
'attachfile',
'array')))
2243 print
'jQuery(".trattachnewfilenow").toggle();'.
"\n";
2248 print
'</script>'.
"\n";
2251 $filenamelinked =
'';
2252 if ($line->fk_ecm_files > 0)
2254 $result = $ecmfilesstatic->fetch($line->fk_ecm_files);
2257 $filenamelinked = $ecmfilesstatic->filename;
2261 $tredited =
'tredited';
2262 include DOL_DOCUMENT_ROOT.
'/expensereport/tpl/expensereport_addfile.tpl.php';
2263 include DOL_DOCUMENT_ROOT.
'/expensereport/tpl/expensereport_linktofile.tpl.php';
2265 print
'<tr class="oddeven tredited">';
2270 print
'<td class="center">';
2271 print $form->selectDate($line->date,
'date');
2275 if (!empty($conf->projet->enabled))
2278 $formproject->select_projects(-1, $line->fk_project,
'fk_project', 0, 0, 1, 1, 0, 0, 0,
'', 0, 0,
'maxwidth300');
2283 print
'<td class="center">';
2284 print $formexpensereport->selectTypeExpenseReport($line->fk_c_type_fees,
'fk_c_type_fees');
2287 if (!empty($conf->global->MAIN_USE_EXPENSE_IK))
2289 print
'<td class="fk_c_exp_tax_cat">';
2290 $params = array(
'fk_expense' => $object->id,
'fk_expense_det' => $line->rowid,
'date' => $line->dates);
2291 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);
2297 print
'<textarea name="comments" class="flat_ndf centpercent">'.dol_escape_htmltag($line->comments, 0, 1).
'</textarea>';
2301 print
'<td class="right">';
2302 print $form->load_tva(
'vatrate', (isset($_POST[
"vatrate"]) ? $_POST[
"vatrate"] : $line->vatrate), $mysoc,
'', 0, 0,
'',
false, 1);
2306 print
'<td class="right">';
2307 print
'<input type="text" min="0" class="right maxwidth50" id="value_unit_ht" name="value_unit_ht" value="'.dol_escape_htmltag(
price2num($line->value_unit_ht)).
'" />';
2311 print
'<td class="right">';
2312 print
'<input type="text" min="0" class="right maxwidth50" id="value_unit" name="value_unit" value="'.dol_escape_htmltag(
price2num($line->value_unit)).
'" />';
2316 print
'<td class="right">';
2317 print
'<input type="number" min="0" class="right maxwidth50" name="qty" value="'.dol_escape_htmltag($line->qty).
'" />';
2324 print
'<td class="center">';
2328 print
'<td class="center">';
2329 print
'<input type="hidden" name="rowid" value="'.$line->rowid.
'">';
2330 print
'<input type="submit" class="button button-save" name="save" value="'.$langs->trans(
"Save").
'">';
2331 print
'<br><input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
2343 && $action !=
'editline'
2344 && $user->rights->expensereport->creer)
2347 if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) $colspan++;
2348 if (!empty($conf->projet->enabled)) $colspan++;
2349 if ($action !=
'editline') $colspan++;
2351 $nbFiles = $nbLinks = 0;
2352 $arrayoffiles = array();
2353 if (empty($conf->global->EXPENSEREPORT_DISABLE_ATTACHMENT_ON_LINES))
2355 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2356 require_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
2357 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
2360 $nbFiles = count($arrayoffiles);
2361 $nbLinks =
Link::count($db, $object->element, $object->id);
2365 print
'<tr class="liste_titre">';
2366 print
'<td colspan="'.$colspan.
'" class="liste_titre">';
2367 print
'<a href="" class="commonlink auploadnewfilenow reposition">'.$langs->trans(
"UploadANewFileNow");
2368 print
img_picto($langs->trans(
"UploadANewFileNow"),
'chevron-down',
'',
false, 0, 0,
'',
'marginleftonly');
2370 if (empty($conf->global->EXPENSEREPORT_DISABLE_ATTACHMENT_ON_LINES))
2372 print
' - <a href="" class="commonlink aattachtodoc reposition">'.$langs->trans(
"AttachTheNewLineToTheDocument");
2373 print
img_picto($langs->trans(
"AttachTheNewLineToTheDocument"),
'chevron-down',
'',
false, 0, 0,
'',
'marginleftonly');
2377 print
'<script language="javascript">'.
"\n";
2378 print
'$(document).ready(function() {
2379 $( ".auploadnewfilenow" ).click(function() {
2380 jQuery(".truploadnewfilenow").toggle();
2381 jQuery(".trattachnewfilenow").hide();
2384 $( ".aattachtodoc" ).click(function() {
2385 jQuery(".trattachnewfilenow").toggle();
2386 jQuery(".truploadnewfilenow").hide();
2389 if (is_array(
GETPOST(
'attachfile',
'array')) && count(
GETPOST(
'attachfile',
'array')) && $action !=
'updateline')
2391 print
'jQuery(".trattachnewfilenow").show();'.
"\n";
2396 print
'</script>'.
"\n";
2399 include DOL_DOCUMENT_ROOT.
'/expensereport/tpl/expensereport_addfile.tpl.php';
2400 include DOL_DOCUMENT_ROOT.
'/expensereport/tpl/expensereport_linktofile.tpl.php';
2402 print
'<tr class="liste_titre">';
2404 print
'<td class="center">'.$langs->trans(
'Date').
'</td>';
2405 if (!empty($conf->projet->enabled)) {
2406 print
'<td class="minwidth100imp">'.$form->textwithpicto($langs->trans(
'Project'), $langs->trans(
"ClosedProjectsAreHidden")).
'</td>';
2408 print
'<td class="center">'.$langs->trans(
'Type').
'</td>';
2409 if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) {
2410 print
'<td>'.$langs->trans(
'CarCategory').
'</td>';
2412 print
'<td>'.$langs->trans(
'Description').
'</td>';
2413 print
'<td class="right">'.$langs->trans(
'VAT').
'</td>';
2414 print
'<td class="right">'.$langs->trans(
'PriceUHT').
'</td>';
2415 print
'<td class="right">'.$langs->trans(
'PriceUTTC').
'</td>';
2416 print
'<td class="right">'.$langs->trans(
'Qty').
'</td>';
2423 print
'<tr class="oddeven nohover">';
2429 print
'<td class="center">';
2430 print $form->selectDate($date ? $date : -1,
'date', 0, 0, 0,
'', 1, 1);
2434 if (!empty($conf->projet->enabled))
2437 $formproject->select_projects(-1, $fk_project,
'fk_project', 0, 0, 1, -1, 0, 0, 0,
'', 0, 0,
'maxwidth300');
2442 print
'<td class="center">';
2443 print $formexpensereport->selectTypeExpenseReport($fk_c_type_fees,
'fk_c_type_fees', 1);
2446 if (!empty($conf->global->MAIN_USE_EXPENSE_IK))
2448 print
'<td class="fk_c_exp_tax_cat">';
2449 $params = array(
'fk_expense' => $object->id);
2450 print $form->selectExpenseCategories(
'',
'fk_c_exp_tax_cat', 1, array(),
'fk_c_type_fees', $userauthor->default_c_exp_tax_cat, $params, 0);
2456 print
'<textarea class="flat_ndf centpercent" name="comments" rows="'.ROWS_2.
'">'.
dol_escape_htmltag($comments, 0, 1).
'</textarea>';
2460 print
'<td class="right">';
2462 if (!empty($conf->global->EXPENSEREPORT_NO_DEFAULT_VAT)) $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS =
'none';
2463 print $form->load_tva(
'vatrate', ($vatrate !=
'' ? $vatrate : $defaultvat), $mysoc,
'', 0, 0,
'',
false, 1);
2467 print
'<td class="right">';
2468 print
'<input type="text" class="right maxwidth50" id="value_unit_ht" name="value_unit_ht" value="'.dol_escape_htmltag($value_unit_ht).
'">';
2472 print
'<td class="right">';
2473 print
'<input type="text" class="right maxwidth50" id="value_unit" name="value_unit" value="'.dol_escape_htmltag($value_unit).
'">';
2477 print
'<td class="right">';
2478 print
'<input type="text" min="0" class="right maxwidth50" name="qty" value="'.dol_escape_htmltag($qty ? $qty : 1).
'">';
2484 if ($action !=
'editline')
2486 print
'<td class="right"></td>';
2487 print
'<td class="right"></td>';
2490 print
'<td class="center"><input type="submit" value="'.$langs->trans(
"Add").
'" name="bouton" class="button"></td>';
2498 print
'<script javascript>
2500 /* JQuery for product free or predefined select */
2501 jQuery(document).ready(function() {
2502 jQuery("#value_unit_ht").keyup(function(event) {
2503 console.log(event.which); // discard event tag and arrows
2504 if (event.which != 9 && (event.which < 37 ||event.which > 40) && jQuery("#value_unit_ht").val() != "") {
2505 jQuery("#value_unit").val("");
2508 jQuery("#value_unit").keyup(function(event) {
2509 console.log(event.which); // discard event tag and arrows
2510 if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#value_unit").val() != "") {
2511 jQuery("#value_unit_ht").val("");
2533 print
'<div class="tabsAction">';
2535 if ($action !=
'create' && $action !=
'edit')
2538 $object->fetch($id, $ref);
2541 if (empty($user->socid)) {
2544 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>';
2557 if (in_array($object->fk_user_author, $user->getAllChildIds(1)) || !empty($user->rights->expensereport->writeall_advance))
2560 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=edit&id='.$object->id.
'">'.$langs->trans(
'Modify').
'</a></div>';
2563 if (count($object->lines) > 0)
2565 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=save&id='.$object->id.
'">'.$langs->trans(
'ValidateAndSubmit').
'</a></div>';
2577 if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid)
2580 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=edit&id='.$object->id.
'">'.$langs->trans(
'Modify').
'</a></div>';
2585 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=save_from_refuse&id='.$object->id.
'">'.$langs->trans(
'ValidateAndSubmit').
'</a></div>';
2591 if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid)
2594 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>';
2605 if (in_array($object->fk_user_author, $user->getAllChildIds(1)))
2608 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>';
2617 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=validate&id='.$object->id.
'">'.$langs->trans(
'Approve').
'</a></div>';
2619 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=refuse&id='.$object->id.
'">'.$langs->trans(
'Deny').
'</a></div>';
2622 if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid)
2625 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=cancel&id='.$object->id.
'">'.$langs->trans(
"Cancel").
'</a></div>';
2635 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=refuse&id='.$object->id.
'">'.$langs->trans(
'Deny').
'</a></div>';
2642 if ($remaintopay == 0)
2644 print
'<div class="inline-block divButAction"><span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPayment').
'</span></div>';
2646 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>';
2654 if ($object->paid == 0)
2656 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>";
2660 if ($user->rights->expensereport->creer && ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) && $object->status ==
ExpenseReport::STATUS_APPROVED)
2663 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>';
2667 if (($user->rights->expensereport->approve || $user->rights->expensereport->to_paid) && $object->status ==
ExpenseReport::STATUS_CLOSED)
2670 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>';
2676 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>';
2680 if ($user->rights->expensereport->creer) {
2681 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>';
2688 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>';
2692 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>';
2695 $parameters = array();
2696 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
2703 if (
GETPOST(
'modelselected',
'alpha')) {
2704 $action =
'presend';
2707 if ($action !=
'presend')
2713 print
'<div class="fichecenter"><div class="fichehalfleft">';
2714 print
'<a name="builddoc"></a>';
2716 if ($user->rights->expensereport->creer && $action !=
'create' && $action !=
'edit')
2720 $urlsource =
$_SERVER[
"PHP_SELF"].
"?id=".$object->id;
2721 $genallowed = $user->rights->expensereport->creer;
2722 $delallowed = $user->rights->expensereport->creer;
2724 print $formfile->showdocuments(
'expensereport', $filename, $filedir, $urlsource, $genallowed, $delallowed);
2725 $somethingshown = $formfile->numoffiles;
2737 print
'</div><div class="fichehalfright"><div class="ficheaddleft">';
2739 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
2741 $somethingshown =
$formactions->showactions($object,
'expensereport', null);
2743 print
'</div></div></div>';
2747 $modelmail =
'expensereport';
2748 $defaulttopic =
'SendExpenseReportRef';
2749 $diroutput = $conf->expensereport->dir_output;
2750 $trackid =
'exp'.$object->id;
2752 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
dol_convert_file($fileinput, $ext= 'png', $fileoutput= '', $page= '')
Convert an image file into another format.
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action== 'set') elseif($action== 'specimen') elseif($action== 'setmodel') elseif($action== 'del') elseif($action== 'setdoc') $formactions
View.
const STATUS_APPROVED
Classified approved.
const STATUS_VALIDATED
Validated (need to be paid)
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Class of expense report details lines.
get_date_range($date_start, $date_end, $format= '', $outputlangs= '', $withparenthesis=1)
Format output for start and end date.
Class to manage Dolibarr users.
const STATUS_CLOSED
Classified paid.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for properties) With native = 0: P...
const STATUS_CANCELED
Classified canceled.
img_mime($file, $titlealt= '', $morecss= '')
Show MIME img of a file.
const STATUS_REFUSED
Classified refused.
Class to manage bank accounts.
image_format_supported($file, $acceptsvg=0)
Return if a filename is file name of a supported image format.
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning logo.
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...
getImageFileNameForSize($file, $extName, $extImgTarget= '')
Return the filename of file to get the thumbs.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
Class to manage projects.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,$sendto,$replyto,$message,$filepath,$mimetype,$filename,$cc,$ccc,$deliveryreceipt,$msgishtml,$errors_to,$css,$trackid,$moreinheader,$sendcontext,$replyto); $mailfile->sendfile();.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
expensereport_prepare_head($object)
Prepare array with list of tabs.
if(!GETPOST('transkey', 'alphanohtml')&&!GETPOST('transphrase', 'alphanohtml')) else
View.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=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 Calling this function terminate execution ...
Class to manage translations.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
Class to manage Trips and Expenses.
dol_is_file($pathoffile)
Return if path is a file.
print $_SERVER["PHP_SELF"]
Edit parameters.
static count($db, $objecttype, $objectid)
Return nb of links.
dol_getIdFromCode($db, $key, $tablename, $fieldkey= 'code', $fieldid= 'id', $entityfilter=0)
Return an id or code from a code or id.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Class to manage payments of expense report.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Class to manage a WYSIWYG editor.
Class to manage accounting accounts.
dol_banner_tab($object, $paramid, $morehtml= '', $shownav=1, $fieldid= 'rowid', $fieldref= 'ref', $morehtmlref= '', $moreparam= '', $nodbprefix=0, $morehtmlleft= '', $morehtmlstatus= '', $onlybanner=0, $morehtmlright= '')
Show tab footer of a card.
img_delete($titlealt= 'default', $other= 'class="pictodelete"', $morecss= '')
Show delete logo.
Class to manage ECM files.
isValidEmail($address, $acceptsupervisorkey=0)
Return true if email syntax is ok.
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
const STATUS_DRAFT
Draft status.
getAdvancedPreviewUrl($modulepart, $relativepath, $alldata=0, $param= '')
Return URL we can use for advanced preview links.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...