32require
'../main.inc.php';
44require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formexpensereport.class.php';
45require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
46require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
47require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
48require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
49require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
50require_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
51require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
52require_once DOL_DOCUMENT_ROOT.
'/core/lib/expensereport.lib.php';
53require_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
54require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
55require_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
56require_once DOL_DOCUMENT_ROOT.
'/core/modules/expensereport/modules_expensereport.php';
57require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
58require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/paymentexpensereport.class.php';
59require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
61 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
65$langs->loadLangs(array(
"trips",
"bills",
"mails"));
67$action =
GETPOST(
'action',
'aZ09');
68$cancel =
GETPOST(
'cancel',
'alpha');
69$confirm =
GETPOST(
'confirm',
'alpha');
70$backtopage =
GETPOST(
'backtopage',
'alpha');
77$vatrate =
GETPOST(
'vatrate',
'alpha');
79$comments =
GETPOST(
'comments',
'restricthtml');
84$childids = $user->getAllChildIds(1);
91 if (empty($date_end)) {
98$rootfordata = DOL_DATA_ROOT;
99$rootforuser = DOL_DATA_ROOT;
102 $rootfordata .=
'/'.$conf->entity;
104$conf->expensereport->dir_output = $rootfordata.
'/expensereport';
108$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
120$extrafields->fetch_name_optionals_label(
$object->table_element);
123include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
126$hookmanager->initHooks(array(
'expensereportcard',
'globalcard'));
128$permissionnote = $user->hasRight(
'expensereport',
'creer');
129$permissiondellink = $user->hasRight(
'expensereport',
'creer');
130$permissiontoadd = $user->hasRight(
'expensereport',
'creer');
131$permissiontoeditextra = $permissiontoadd;
132if (
GETPOST(
'attribute',
'aZ09') && isset($extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')])) {
134 $permissiontoeditextra =
dol_eval((
string) $extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')]);
145 if ($user->hasRight(
'expensereport',
'readall')) {
148 if ($user->hasRight(
'expensereport',
'lire') && in_array(
$object->fk_user_author, $childids)) {
157if ($user->hasRight(
'expensereport',
'supprimer')) {
166 $socid = $user->socid;
170$permissiontoadd = $user->hasRight(
'expensereport',
'creer');
183$parameters = array(
'socid' => $socid);
184$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
189if (empty($reshook)) {
190 $backurlforlist = DOL_URL_ROOT.
'/expensereport/list.php';
192 if (empty($backtopage) || ($cancel && empty($id))) {
193 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
194 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
195 $backtopage = $backurlforlist;
197 $backtopage = DOL_URL_ROOT.
'/expensereport/card.php?id='.((!empty($id) &&
$id > 0) ? $id :
'__ID__');
203 if (!empty($backtopageforcancel)) {
204 header(
"Location: ".$backtopageforcancel);
206 } elseif (!empty($backtopage)) {
207 header(
"Location: ".$backtopage);
221 $fk_c_type_fees = -1;
224 include DOL_DOCUMENT_ROOT.
'/core/actions_linkedfiles.inc.php';
226 if (!empty(
GETPOST(
'sendit',
'alpha'))) {
227 if ($action ==
'updateline') {
228 $action =
'editline';
234 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
236 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
238 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
241 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $permissiontoadd) {
251 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
262 if ($action ==
'confirm_delete' &&
GETPOST(
"confirm",
'alpha') ==
"yes" && $id > 0 && $candelete) {
265 $result =
$object->delete($user);
267 header(
"Location: index.php");
274 if ($action ==
'add' && $permissiontoadd) {
281 if (!(
$object->fk_user_author > 0)) {
282 $object->fk_user_author = $user->id;
286 if ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'expensereport',
'creer'))
287 || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'expensereport',
'creer') && !$user->hasRight(
'expensereport',
'writeall_advance'))) {
292 if (!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') || !$user->hasRight(
'expensereport',
'writeall_advance')) {
293 if (!in_array(
$object->fk_user_author, $childids)) {
301 $fuser->fetch(
$object->fk_user_author);
310 $ret = $extrafields->setOptionalsFromPost(
null, $object);
319 if ($overlappingExpenseReportID > 0) {
321 setEventMessages($langs->trans(
"ErrorDoubleDeclaration").
' <a href="'.$_SERVER[
'PHP_SELF'].
'?id='.$overlappingExpenseReportID.
'">'. $langs->trans(
'ShowTrip').
'</a>',
null,
'errors');
336 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
346 if (($action ==
'update' || $action ==
'updateFromRefuse') && $permissiontoadd) {
360 $object->fk_user_modif = $user->id;
362 $result =
$object->update($user);
364 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
GETPOSTINT(
'id'));
371 if ($action ==
'update_extras' && $permissiontoeditextra) {
374 $attribute_name =
GETPOST(
'attribute',
'aZ09');
377 $ret = $extrafields->setOptionalsFromPost(
null, $object, $attribute_name);
383 $result =
$object->updateExtraField($attribute_name,
'EXPENSEREPORT_MODIFY');
391 $action =
'edit_extras';
395 if ($action ==
"confirm_validate" &&
GETPOST(
"confirm",
'alpha') ==
"yes" && $id > 0 && $permissiontoadd) {
401 $result =
$object->setValidate($user);
406 $outputlangs = $langs;
409 $newlang =
GETPOST(
'lang_id',
'aZ09');
413 $tmpuser->fetch(
$object->fk_user_author);
414 $newlang = $tmpuser->lang;
416 if (!empty($newlang)) {
418 $outputlangs->setDefaultLang($newlang);
423 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
430 if (!$error && $result > 0 &&
$object->fk_user_validator > 0) {
431 $langs->load(
"mails");
435 $destinataire->fetch(
$object->fk_user_validator);
436 $emailTo = $destinataire->email;
440 $expediteur->fetch(
$object->fk_user_author);
443 if ($emailTo && $emailFrom) {
454 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportWaitingForApproval");
457 $link = $urlwithroot.
'/expensereport/card.php?id='.
$object->id;
458 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
459 $message = $langs->transnoentities(
"ExpenseReportWaitingForApprovalMessage", $expediteur->getFullName($langs),
get_date_range(
$object->date_debut,
$object->date_fin,
'', $langs), $link);
474 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
476 if (empty($mailfile->error)) {
478 $result = $mailfile->sendfile();
480 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
483 $langs->load(
"other");
484 if (!empty($mailfile->error) || !empty($mailfile->errors)) {
487 if (!empty($mailfile->error)) {
488 $mesg .=
'<br>' . $mailfile->error;
490 if (!empty($mailfile->errors) && is_array($mailfile->errors)) {
491 $mesg .=
'<br>' . implode(
'<br>', $mailfile->errors);
495 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
503 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
510 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
517 if ($action ==
"confirm_save_from_refuse" &&
GETPOST(
"confirm",
'alpha') ==
"yes" && $id > 0 && $permissiontoadd) {
520 $result =
$object->set_save_from_refuse($user);
525 $outputlangs = $langs;
528 $newlang =
GETPOST(
'lang_id',
'aZ09');
532 $tmpuser->fetch(
$object->fk_user_author);
533 $newlang = $tmpuser->lang;
535 if (!empty($newlang)) {
537 $outputlangs->setDefaultLang($newlang);
542 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
551 $destinataire->fetch(
$object->fk_user_validator);
552 $emailTo = $destinataire->email;
556 $expediteur->fetch(
$object->fk_user_author);
559 if ($emailFrom && $emailTo) {
570 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportWaitingForReApproval");
573 $link = $urlwithroot.
'/expensereport/card.php?id='.
$object->id;
574 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
576 $message .=
'<br>'.$langs->transnoentities(
"ExpenseReportWaitingForReApprovalMessage2", $link);
595 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
597 if (empty($mailfile->error)) {
599 $result = $mailfile->sendfile();
601 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
603 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
606 $langs->load(
"other");
607 if ($mailfile->error) {
609 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
610 $mesg .=
'<br>'.$mailfile->error;
613 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
621 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
630 if ($action ==
"confirm_approve" &&
GETPOST(
"confirm",
'alpha') ==
"yes" && $id > 0 && $user->hasRight(
'expensereport',
'approve')) {
634 $result =
$object->setApproved($user);
639 $outputlangs = $langs;
642 $newlang =
GETPOST(
'lang_id',
'aZ09');
646 $tmpuser->fetch(
$object->fk_user_author);
647 $newlang = $tmpuser->lang;
649 if (!empty($newlang)) {
651 $outputlangs->setDefaultLang($newlang);
656 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
665 $destinataire->fetch(
$object->fk_user_author);
666 $emailTo = $destinataire->email;
670 if (empty($emailTo)) {
676 $expediteur->fetch(
$object->fk_user_approve > 0 ?
$object->fk_user_approve :
$object->fk_user_validator);
679 if ($emailFrom && $emailTo) {
690 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportApproved");
693 $link = $urlwithroot.
'/expensereport/card.php?id='.
$object->id;
694 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
695 $message = $langs->transnoentities(
"ExpenseReportApprovedMessage",
$object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $link);
712 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, $emailCC,
'', 0, -1);
714 if (empty($mailfile->error)) {
716 $result = $mailfile->sendfile();
718 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
720 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
723 $langs->load(
"other");
724 if ($mailfile->error) {
726 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
727 $mesg .=
'<br>'.$mailfile->error;
730 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
738 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
747 if ($action ==
"confirm_refuse" &&
GETPOST(
'confirm',
'alpha') ==
"yes" && $id > 0 && $user->hasRight(
'expensereport',
'approve')) {
751 $detailRefuse =
GETPOST(
'detail_refuse',
'alpha');
752 $result =
$object->setDeny($user, $detailRefuse);
757 $outputlangs = $langs;
760 $newlang =
GETPOST(
'lang_id',
'aZ09');
764 $tmpuser->fetch(
$object->fk_user_author);
765 $newlang = $tmpuser->lang;
767 if (!empty($newlang)) {
769 $outputlangs->setDefaultLang($newlang);
774 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
783 $destinataire->fetch(
$object->fk_user_author);
784 $emailTo = $destinataire->email;
788 $expediteur->fetch(
$object->fk_user_refuse);
791 if ($emailFrom && $emailTo) {
802 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportRefused");
805 $link = $urlwithroot.
'/expensereport/card.php?id='.
$object->id;
806 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
807 $message = $langs->transnoentities(
"ExpenseReportRefusedMessage",
$object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $detailRefuse, $link);
825 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
827 if (empty($mailfile->error)) {
829 $result = $mailfile->sendfile();
831 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
833 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
836 $langs->load(
"other");
837 if ($mailfile->error) {
839 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
840 $mesg .=
'<br>'.$mailfile->error;
843 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
851 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
861 if ($action ==
"confirm_cancel" &&
GETPOST(
'confirm',
'alpha') ==
"yes" && $id > 0 && $user->hasRight(
'expensereport',
'creer')) {
862 if (!
GETPOST(
'detail_cancel',
'alpha')) {
863 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Comment")),
null,
'errors');
868 if ($user->id ==
$object->fk_user_valid || $user->id ==
$object->fk_user_author) {
869 $detailCancel =
GETPOST(
'detail_cancel',
'alpha');
870 $result =
$object->set_cancel($user, $detailCancel);
875 $outputlangs = $langs;
878 $newlang =
GETPOST(
'lang_id',
'aZ09');
882 $tmpuser->fetch(
$object->fk_user_author);
883 $newlang = $tmpuser->lang;
885 if (!empty($newlang)) {
887 $outputlangs->setDefaultLang($newlang);
892 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
901 $destinataire->fetch(
$object->fk_user_author);
902 $emailTo = $destinataire->email;
906 $expediteur->fetch(
$object->fk_user_cancel);
909 if ($emailFrom && $emailTo) {
920 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportCanceled");
923 $link = $urlwithroot.
'/expensereport/card.php?id='.
$object->id;
924 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
925 $message = $langs->transnoentities(
"ExpenseReportCanceledMessage",
$object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $detailCancel, $link);
943 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
945 if (empty($mailfile->error)) {
947 $result = $mailfile->sendfile();
949 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
951 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
954 $langs->load(
"other");
955 if ($mailfile->error) {
957 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
958 $mesg .=
'<br>'.$mailfile->error;
961 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
969 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
982 if ($action ==
"confirm_setdraft" &&
GETPOST(
'confirm',
'alpha') ==
"yes" && $id > 0 && $user->hasRight(
'expensereport',
'creer')) {
985 if ($user->id ==
$object->fk_user_author || $user->id ==
$object->fk_user_valid || in_array(
$object->fk_user_author, $childids)) {
991 $outputlangs = $langs;
994 $newlang =
GETPOST(
'lang_id',
'aZ09');
998 $tmpuser->fetch(
$object->fk_user_author);
999 $newlang = $tmpuser->lang;
1001 if (!empty($newlang)) {
1003 $outputlangs->setDefaultLang($newlang);
1008 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1013 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
1023 if ($action ==
'set_unpaid' && $id > 0 && $user->hasRight(
'expensereport',
'to_paid')) {
1027 $result =
$object->setUnpaid($user);
1032 $outputlangs = $langs;
1035 $newlang =
GETPOST(
'lang_id',
'aZ09');
1039 $tmpuser->fetch(
$object->fk_user_author);
1040 $newlang = $tmpuser->lang;
1042 if (!empty($newlang)) {
1044 $outputlangs->setDefaultLang($newlang);
1049 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1052 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
1058 if ($action ==
'set_paid' && $id > 0 && $user->hasRight(
'expensereport',
'to_paid')) {
1062 $result =
$object->setPaid($id, $user);
1067 $outputlangs = $langs;
1070 $newlang =
GETPOST(
'lang_id',
'aZ09');
1074 $tmpuser->fetch(
$object->fk_user_author);
1075 $newlang = $tmpuser->lang;
1077 if (!empty($newlang)) {
1079 $outputlangs->setDefaultLang($newlang);
1084 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1095 $destinataire =
new User(
$db);
1096 $destinataire->fetch(
$object->fk_user_author);
1097 $emailTo = $destinataire->email;
1101 $expediteur->fetch($user->id);
1104 if ($emailFrom && $emailTo) {
1105 $filename = array();
1107 $mimetype = array();
1115 $subject = $societeName.
" - ".$langs->transnoentities(
"ExpenseReportPaid");
1118 $link = $urlwithroot.
'/expensereport/card.php?id='.
$object->id;
1119 $link =
'<a href="'.$link.
'">'.$link.
'</a>';
1120 $message = $langs->transnoentities(
"ExpenseReportPaidMessage",
$object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $link);
1123 $object->setDocModel($user,
"");
1124 $resultPDF = expensereport_pdf_create(
$db, $object,
'',
"", $langs);
1127 $mailfile =
new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename,
'',
'', 0, -1);
1129 if (empty($mailfile->error)) {
1131 $result = $mailfile->sendfile();
1133 $mesg = $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
1136 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".$id);
1139 $langs->load(
"other");
1140 if ($mailfile->error) {
1142 $mesg .= $langs->trans(
'ErrorFailedToSendMail', $emailFrom, $emailTo);
1143 $mesg .=
'<br>'.$mailfile->error;
1146 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'warnings');
1153 setEventMessages($langs->trans(
"NoEmailSentBadSenderOrRecipientEmail"),
null,
'warnings');
1163 if ($action ==
"addline" && $user->hasRight(
'expensereport',
'creer')) {
1166 if (GETPOSTISSET(
'attachfile')) {
1167 $arrayoffiles =
GETPOST(
'attachfile',
'array');
1168 if (is_array($arrayoffiles) && !empty($arrayoffiles[0])) {
1169 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1170 $entityprefix = (
$conf->entity !=
'1') ?
$conf->entity.
'/' :
'';
1171 $relativepath =
'expensereport/'.$object->ref.
'/'.$arrayoffiles[0];
1173 $ecmfiles->fetch(0,
'', $relativepath);
1174 $fk_ecm_files = $ecmfiles->id;
1179 if (empty($vatrate)) {
1182 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $vatrate));
1186 if (empty($value_unit)) {
1187 $value_unit =
price2num((
float) $value_unit_ht + ((
float) $value_unit_ht * (
float) $tmpvat / 100),
'MU');
1190 $fk_c_exp_tax_cat =
GETPOSTINT(
'fk_c_exp_tax_cat');
1197 if (!($fk_c_type_fees > 0)) {
1199 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1203 if ((
float) $tmpvat < 0 || $tmpvat ===
'') {
1205 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"VAT")),
null,
'errors');
1210 if (empty($date) || $date ==
"--") {
1212 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
1213 } elseif ($date < $object->date_debut || $date > (
$object->date_fin + (24 * 3600 - 1))) {
1219 $langs->load(
"errors");
1220 $type = $error > 0 ?
'errors' :
'warnings';
1221 setEventMessages($langs->trans(
"WarningDateOfLineMustBeInExpenseReportRange"),
null, $type);
1225 if ($value_unit == 0) {
1227 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"PriceUTTC")),
null,
'errors');
1231 if ($projectRequired && $fk_project <= 0) {
1233 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Project")),
null,
'errors');
1237 if ($fileRequired && $fk_ecm_files == 0) {
1239 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"File")),
null,
'errors');
1246 $result =
$object->addline($qty, $value_unit, $fk_c_type_fees, $vatrate, $date, $comments, $fk_project, $fk_c_exp_tax_cat, $type, $fk_ecm_files);
1252 $outputlangs = $langs;
1253 $newlang =
GETPOST(
'lang_id',
'alpha');
1256 $tmpuser->fetch(
$object->fk_user_author);
1257 $newlang = $tmpuser->lang;
1259 if (!empty($newlang)) {
1261 $outputlangs->setDefaultLang($newlang);
1264 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1268 unset($value_unit_ht);
1272 unset($fk_c_type_fees);
1283 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
GETPOSTINT(
'id'));
1290 if ($action ==
'confirm_delete_line' &&
GETPOST(
"confirm",
'alpha') ==
"yes" && $user->hasRight(
'expensereport',
'creer')) {
1296 $total_ht = $object_ligne->total_ht;
1297 $total_tva = $object_ligne->total_tva;
1304 $outputlangs = $langs;
1307 $newlang =
GETPOST(
'lang_id',
'aZ09');
1311 $tmpuser->fetch(
$object->fk_user_author);
1312 $newlang = $tmpuser->lang;
1314 if (!empty($newlang)) {
1316 $outputlangs->setDefaultLang($newlang);
1321 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1325 header(
"Location: ".$_SERVER[
"PHP_SELF"].
"?id=".
GETPOSTINT(
'id'));
1332 if ($action ==
"updateline" && $permissiontoadd) {
1338 if (GETPOSTISSET(
'attachfile')) {
1339 $arrayoffiles =
GETPOST(
'attachfile',
'array');
1340 if (is_array($arrayoffiles) && !empty($arrayoffiles[0])) {
1341 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1342 $relativepath =
'expensereport/'.$object->ref.
'/'.$arrayoffiles[0];
1344 $ecmfiles->fetch(0,
'', $relativepath);
1345 $fk_ecm_files = $ecmfiles->id;
1350 $type_fees_id =
GETPOSTINT(
'fk_c_type_fees');
1351 $fk_c_exp_tax_cat =
GETPOSTINT(
'fk_c_exp_tax_cat');
1352 $projet_id = $fk_project;
1353 $comments =
GETPOST(
'comments',
'restricthtml');
1355 $vatrate =
GETPOST(
'vatrate',
'alpha');
1358 if (empty($vatrate)) {
1361 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $vatrate));
1365 if (empty($value_unit)) {
1366 $value_unit =
price2num((
float) $value_unit_ht + ((
float) $value_unit_ht * (
float) $tmpvat / 100),
'MU');
1371 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
1374 if ((
float) $tmpvat < 0 || $tmpvat ==
'') {
1376 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Vat")),
null,
'errors');
1380 if ($date < $object->date_debut || $date > (
$object->date_fin + (24 * 3600 - 1))) {
1385 $langs->load(
"errors");
1386 $type = $error > 0 ?
'errors' :
'warnings';
1387 setEventMessages($langs->trans(
"WarningDateOfLineMustBeInExpenseReportRange"),
null, $type);
1391 if ($projectRequired && $projet_id <= 0) {
1393 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Project")),
null,
'errors');
1398 $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);
1403 $outputlangs = $langs;
1406 $newlang =
GETPOST(
'lang_id',
'aZ09');
1410 $tmpuser->fetch(
$object->fk_user_author);
1411 $newlang = $tmpuser->lang;
1413 if (!empty($newlang)) {
1415 $outputlangs->setDefaultLang($newlang);
1420 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1424 unset($value_unit_ht);
1428 unset($fk_c_type_fees);
1441 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
1444 $triggersendname =
'EXPENSEREPORT_SENTBYMAIL';
1445 $autocopy =
'MAIN_MAIL_AUTOCOPY_EXPENSEREPORT_TO';
1446 $trackid =
'exp'.$object->id;
1447 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
1450 $upload_dir =
$conf->expensereport->dir_output;
1451 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1459$title = $langs->trans(
"ExpenseReport").
" - ".$langs->trans(
"Card");
1460$help_url =
"EN:Module_Expense_Reports|FR:Module_Notes_de_frais";
1475if ($action ==
'create') {
1478 print
'<form action="'.$_SERVER[
'PHP_SELF'].
'" method="post" name="create">';
1479 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1480 print
'<input type="hidden" name="action" value="add">';
1481 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
1485 print
'<table class="border centpercent">';
1490 print
'<td class="fieldrequired">'.$langs->trans(
"User").
'</td>';
1492 $defaultselectuser = $user->id;
1494 $defaultselectuser =
GETPOSTINT(
'fk_user_author');
1496 $include_users =
'hierarchyme';
1497 if (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'expensereport',
'writeall_advance')) {
1498 $include_users = array();
1500 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');
1506 print
'<td class="titlefieldcreate fieldrequired">'.$langs->trans(
"DateStart").
'</td>';
1507 print
'<td>'.img_picto(
'',
'action',
'class="pictofixedwidth"');
1514 print
'<td class="fieldrequired">'.$langs->trans(
"DateEnd").
'</td>';
1515 print
'<td>'.img_picto(
'',
'action',
'class="pictofixedwidth"');
1516 print $form->selectDate($date_end ? $date_end : -1,
'date_fin', 0, 0, 0,
'', 1, 1);
1523 print
'<td>'.$langs->trans(
"ReviewedByCP").
'</td>';
1526 $include_users =
$object->fetch_users_approver_expensereport();
1527 if (empty($include_users)) {
1528 print
img_warning().
' '.$langs->trans(
"NobodyHasPermissionToValidateExpenseReport");
1530 $defaultselectuser = (empty($user->fk_user_expense_validator) ? $user->fk_user : $user->fk_user_expense_validator);
1535 $defaultselectuser =
GETPOSTINT(
'fk_user_validator');
1537 $s = $form->select_dolusers($defaultselectuser,
"fk_user_validator", 1,
null, ((empty($defaultselectuser) || !
getDolGlobalString(
'EXPENSEREPORT_DEFAULT_VALIDATOR_UNCHANGEABLE')) ? 0 : 1), $include_users);
1538 print
img_picto(
'',
'user',
'class="pictofixedwidth"').$form->textwithpicto($s, $langs->trans(
"AnyOtherInThisListCanValidate"));
1546 print
'<td>'.$langs->trans(
"ModePaiement").
'</td>';
1548 $form->select_types_paiements(
'',
'fk_c_paiement');
1554 $note_public = GETPOSTISSET(
'note_public') ?
GETPOST(
'note_public',
'restricthtml') :
'';
1557 print
'<td class="tdtop">'.$langs->trans(
'NotePublic').
'</td>';
1560 $doleditor =
new DolEditor(
'note_public', $note_public,
'', 80,
'dolibarr_notes',
'In',
false,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3,
'90%');
1561 print $doleditor->Create(1);
1565 $note_private = GETPOSTISSET(
'note_private') ?
GETPOST(
'note_private',
'restricthtml') :
'';
1567 if (empty($user->socid)) {
1569 print
'<td class="tdtop">'.$langs->trans(
'NotePrivate').
'</td>';
1572 $doleditor =
new DolEditor(
'note_private', $note_private,
'', 80,
'dolibarr_notes',
'In',
false,
false, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3,
'90%');
1573 print $doleditor->Create(1);
1578 $parameters = array(
'colspan' =>
' colspan="3"',
'cols' => 3);
1579 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
1580 print $hookmanager->resPrint;
1581 if (empty($reshook)) {
1582 print
$object->showOptionals($extrafields,
'create', $parameters);
1590 print $form->buttonsSaveCancel(
"AddTrip");
1595 $result =
$object->fetch($id, $ref);
1598 if (!in_array(
$object->fk_user_author, $childids)) {
1599 if (!$user->hasRight(
'expensereport',
'readall') && !$user->hasRight(
'expensereport',
'lire_tous')
1600 && (!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') || !$user->hasRight(
'expensereport',
'writeall_advance'))) {
1603 print
'<div class="tabBar">';
1604 print $langs->trans(
'NotUserRightToView');
1619 print
"<form name='update' action=\"".$_SERVER[
'PHP_SELF'].
"\" method=\"post\">\n";
1620 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1621 print
'<input type="hidden" name="id" value="'.$id.
'">';
1622 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
1624 print
dol_get_fiche_head($head,
'card', $langs->trans(
"ExpenseReport"), 0,
'trip', 0,
'',
'', 0,
'', 1);
1627 print
'<input type="hidden" name="action" value="updateFromRefuse">';
1629 print
'<input type="hidden" name="action" value="update">';
1632 $linkback =
'<a href="'.DOL_URL_ROOT.
'/expensereport/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
1634 print
'<table class="border centpercent">';
1637 print
'<td>'.$langs->trans(
"User").
'</td>';
1640 if (
$object->fk_user_author > 0) {
1641 $userfee->fetch(
$object->fk_user_author);
1642 print $userfee->getNomUrl(-1);
1647 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"Ref").
'</td><td>';
1648 print $form->showrefnav($object,
'ref', $linkback, 1,
'ref',
'ref',
'');
1652 print
'<td>'.$langs->trans(
"DateStart").
'</td>';
1654 print $form->selectDate(
$object->date_debut,
'date_debut');
1658 print
'<td>'.$langs->trans(
"DateEnd").
'</td>';
1660 print $form->selectDate(
$object->date_fin,
'date_fin');
1666 print
'<td>'.$langs->trans(
"ModePaiement").
'</td>';
1668 $form->select_types_paiements((
string)
$object->fk_c_paiement,
'fk_c_paiement');
1675 print
'<td>'.$langs->trans(
"VALIDATOR").
'</td>';
1677 $include_users =
$object->fetch_users_approver_expensereport();
1678 $s = $form->select_dolusers(
$object->fk_user_validator,
"fk_user_validator", 1,
null, 0, $include_users);
1679 print $form->textwithpicto($s, $langs->trans(
"AnyOtherInThisListCanValidate"));
1684 print
'<td>'.$langs->trans(
"VALIDOR").
'</td>';
1687 $userfee->fetch(
$object->fk_user_valid);
1688 print $userfee->getNomUrl(-1);
1694 print
'<td>'.$langs->trans(
"AUTHORPAIEMENT").
'</td>';
1697 $userfee->fetch($user->id);
1698 print $userfee->getNomUrl(-1);
1710 print $form->buttonsSaveCancel(
"Modify");
1714 $taxlessUnitPriceDisabled =
getDolGlobalString(
'EXPENSEREPORT_FORCE_LINE_AMOUNTS_INCLUDING_TAXES_ONLY') ?
' disabled' :
'';
1716 print
dol_get_fiche_head($head,
'card', $langs->trans(
"ExpenseReport"), -1,
'trip', 0,
'',
'', 0,
'', 1);
1721 if ($action ==
'clone') {
1723 $criteriaforfilter =
'hierarchyme';
1724 if ($user->hasRight(
'expensereport',
'readall')) {
1725 $criteriaforfilter =
'';
1727 $formquestion = array(
1729 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'))
1732 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneExpenseReport',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1);
1735 if ($action ==
'save') {
1736 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"SaveTrip"), $langs->trans(
"ConfirmSaveTrip"),
"confirm_validate",
"",
"", 1);
1739 if ($action ==
'save_from_refuse') {
1740 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"SaveTrip"), $langs->trans(
"ConfirmSaveTrip"),
"confirm_save_from_refuse",
"",
"", 1);
1743 if ($action ==
'delete') {
1744 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"DeleteTrip"), $langs->trans(
"ConfirmDeleteTrip"),
"confirm_delete",
"",
"", 1);
1747 if ($action ==
'validate') {
1748 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"ValideTrip"), $langs->trans(
"ConfirmValideTrip"),
"confirm_approve",
"",
"", 1);
1751 if ($action ==
'paid') {
1752 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"PaidTrip"), $langs->trans(
"ConfirmPaidTrip"),
"confirm_paid",
"",
"", 1);
1755 if ($action ==
'cancel') {
1756 $array_input = array(
'text' => $langs->trans(
"ConfirmCancelTrip"), 0 => array(
'type' =>
"text",
'label' =>
'<strong>'.$langs->trans(
"Comment").
'</strong>',
'name' =>
"detail_cancel",
'value' =>
""));
1757 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"Cancel"),
"",
"confirm_cancel", $array_input,
"", 1);
1760 if ($action ==
'setdraft') {
1761 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"BrouillonnerTrip"), $langs->trans(
"ConfirmBrouillonnerTrip"),
"confirm_setdraft",
"",
"", 1);
1764 if ($action ==
'refuse') {
1765 $array_input = array(
'text' => $langs->trans(
"ConfirmRefuseTrip"), 0 => array(
'type' =>
"text",
'label' => $langs->trans(
"Comment"),
'name' =>
"detail_refuse",
'value' =>
""));
1766 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$id, $langs->trans(
"Deny"),
'',
"confirm_refuse", $array_input,
"yes", 1);
1769 if ($action ==
'delete_line') {
1770 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".
$id.
"&rowid=".
GETPOSTINT(
'rowid'), $langs->trans(
"DeleteLine"), $langs->trans(
"ConfirmDeleteLine"),
"confirm_delete_line",
'',
'yes', 1);
1774 $parameters = array(
'formConfirm' => $formconfirm);
1775 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
1776 if (empty($reshook)) {
1777 $formconfirm .= $hookmanager->resPrint;
1778 } elseif ($reshook > 0) {
1779 $formconfirm = $hookmanager->resPrint;
1786 $linkback =
'<a href="'.DOL_URL_ROOT.
'/expensereport/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
1788 $morehtmlref =
'<div class="refidno">';
1789 $morehtmlref .=
'</div>';
1791 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
1793 print
'<div class="fichecenter">';
1794 print
'<div class="fichehalfleft">';
1795 print
'<div class="underbanner clearboth"></div>';
1797 print
'<table class="border tableforfield centpercent">';
1801 print
'<td class="titlefield">'.$langs->trans(
"User").
'</td>';
1803 if (
$object->fk_user_author > 0) {
1805 $result = $userauthor->fetch(
$object->fk_user_author);
1808 } elseif ($result > 0) {
1809 print $userauthor->getNomUrl(-1);
1816 print
'<td class="titlefield">'.$langs->trans(
"Period").
'</td>';
1823 print
'<td>'.$langs->trans(
"ModePaiement").
'</td>';
1824 print
'<td>'.$object->fk_c_paiement.
'</td>';
1830 print
'<td>'.$langs->trans(
"DATE_SAVE").
'</td>';
1831 print
'<td>'.dol_print_date(
$object->date_valid,
'dayhour',
'tzuser');
1833 print
' '.img_warning($langs->trans(
"Late").
' - '.$langs->trans(
"ToApprove"));
1836 print
' '.img_warning($langs->trans(
"Late").
' - '.$langs->trans(
"ToPay"));
1844 print
'<td>'.$langs->trans(
"VALIDATOR").
'</td>';
1846 if (
$object->fk_user_validator > 0) {
1848 $result = $userfee->fetch(
$object->fk_user_validator);
1850 print $userfee->getNomUrl(-1);
1852 if (empty($userfee->email) || !
isValidEmail($userfee->email)) {
1853 $langs->load(
"errors");
1854 print
img_warning($langs->trans(
"ErrorBadEMail", $userfee->email));
1860 print
'<td>'.$langs->trans(
"CANCEL_USER").
'</span></td>';
1862 if (
$object->fk_user_cancel > 0) {
1864 $result = $userfee->fetch(
$object->fk_user_cancel);
1866 print $userfee->getNomUrl(-1);
1872 print
'<td>'.$langs->trans(
"MOTIF_CANCEL").
'</td>';
1873 print
'<td>'.$object->detail_cancel.
'</td></tr>';
1876 print
'<td>'.$langs->trans(
"DATE_CANCEL").
'</td>';
1877 print
'<td>'.dol_print_date(
$object->date_cancel,
'dayhour',
'tzuser').
'</td></tr>';
1881 print
'<td>'.$langs->trans(
"ApprovedBy").
'</td>';
1883 if (
$object->fk_user_approve > 0) {
1885 $result = $userapp->fetch(
$object->fk_user_approve);
1887 print $userapp->getNomUrl(-1);
1893 print
'<td>'.$langs->trans(
"DateApprove").
'</td>';
1894 print
'<td>'.dol_print_date(
$object->date_approve,
'dayhour',
'tzuser').
'</td></tr>';
1900 print
'<td>'.$langs->trans(
"REFUSEUR").
'</td>';
1903 $result = $userfee->fetch(
$object->fk_user_refuse);
1905 print $userfee->getNomUrl(-1);
1910 print
'<td>'.$langs->trans(
"DATE_REFUS").
'</td>';
1911 print
'<td>'.dol_print_date(
$object->date_refuse,
'dayhour',
'tzuser');
1913 print
' - '.$object->detail_refuse;
1937 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
1942 print
'<div class="fichehalfright">';
1943 print
'<div class="underbanner clearboth"></div>';
1945 print
'<table class="border tableforfield centpercent">';
1949 print
'<td class="titlefieldmiddle">'.$langs->trans(
"AmountHT").
'</td>';
1950 print
'<td class="nowrap amountcard">'.price(
$object->total_ht, 1,
'', 1, - 1, - 1,
$conf->currency).
'</td>';
1967 print
'<td>'.$langs->trans(
"AmountVAT").
'</td>';
1968 print
'<td class="nowrap amountcard">'.price(
$object->total_tva, 1,
'', 1, -1, -1,
$conf->currency).
'</td>';
1972 if (
$mysoc->localtax1_assuj ==
"1" ||
$object->total_localtax1 != 0) {
1973 print
'<tr><td>'.$langs->transcountry(
"AmountLT1",
$mysoc->country_code).
'</td>';
1974 print
'<td class="valuefield">'.price(
$object->total_localtax1, 1,
'', 1, -1, -1,
$conf->currency).
'</td></tr>';
1976 if (
$mysoc->localtax2_assuj ==
"1" ||
$object->total_localtax2 != 0) {
1977 print
'<tr><td>'.$langs->transcountry(
"AmountLT2",
$mysoc->country_code).
'</td>';
1978 print
'<td class="valuefield">'.price(
$object->total_localtax2, 1,
'', 1, -1, -1,
$conf->currency).
'</td></tr>';
1982 print
'<td>'.$langs->trans(
"AmountTTC").
'</td>';
1983 print
'<td class="nowrap amountcard">'.price(
$object->total_ttc, 1,
'', 1, -1, -1,
$conf->currency).
'</td>';
1987 $canSeeBankAccount =
isModEnabled(
'bank') && $user->hasRight(
'banque',
'lire');
1990 if ($canSeeBankAccount) {
1995 print
'<div class="div-table-responsive-no-min">';
1996 print
'<table class="noborder paymenttable centpercent">';
1998 print
'<tr class="liste_titre">';
1999 print
'<td class="liste_titre">'.$langs->trans(
'Payments').
'</td>';
2000 print
'<td class="liste_titre">'.$langs->trans(
'Date').
'</td>';
2001 print
'<td class="liste_titre">'.$langs->trans(
'Type').
'</td>';
2002 if ($canSeeBankAccount) {
2003 print
'<td class="liste_titre right">'.$langs->trans(
'BankAccount').
'</td>';
2005 print
'<td class="liste_titre" width="18"> </td>';
2006 print
'<td class="liste_titre right">'.$langs->trans(
'Amount').
'</td>';
2010 $sql =
"SELECT p.rowid, p.num_payment, p.datep as dp, p.amount, p.fk_bank,";
2011 $sql .=
"c.code as payment_code, c.libelle as payment_type,";
2012 $sql .=
"ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal";
2013 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as e, ".MAIN_DB_PREFIX.
"payment_expensereport as p";
2014 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON p.fk_typepayment = c.id";
2015 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON p.fk_bank = b.rowid';
2016 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank_account as ba ON b.fk_account = ba.rowid';
2017 $sql .=
" WHERE e.rowid = ".((int) $id);
2018 $sql .=
" AND p.fk_expensereport = e.rowid";
2019 $sql .=
' AND e.entity IN ('.getEntity(
'expensereport').
')';
2020 $sql .=
" ORDER BY dp";
2022 $resql =
$db->query($sql);
2024 $num =
$db->num_rows($resql);
2028 $objp =
$db->fetch_object($resql);
2030 $paymentexpensereportstatic->id = $objp->rowid;
2031 $paymentexpensereportstatic->datep =
$db->jdate($objp->dp);
2032 $paymentexpensereportstatic->ref = $objp->rowid;
2033 $paymentexpensereportstatic->num_payment = $objp->num_payment;
2034 $paymentexpensereportstatic->type_code = $objp->payment_code;
2035 $paymentexpensereportstatic->type_label = $objp->payment_type;
2037 print
'<tr class="oddeven">';
2039 print $paymentexpensereportstatic->getNomUrl(1);
2041 print
'<td>'.dol_print_date(
$db->jdate($objp->dp),
'day').
"</td>\n";
2042 $labeltype = $langs->trans(
"PaymentType".$objp->payment_code) !=
"PaymentType".$objp->payment_code ? $langs->trans(
"PaymentType".$objp->payment_code) : $objp->payment_type;
2043 print
"<td>".$labeltype.
' '.$objp->num_payment.
"</td>\n";
2045 if ($canSeeBankAccount) {
2046 $bankaccountstatic->id = $objp->baid;
2047 $bankaccountstatic->ref = $objp->baref;
2048 $bankaccountstatic->label = $objp->baref;
2049 $bankaccountstatic->number = $objp->banumber;
2052 $bankaccountstatic->account_number = $objp->account_number;
2055 $accountingjournal->fetch($objp->fk_accountancy_journal);
2056 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1,
'', 1);
2059 print
'<td class="right">';
2060 if ($bankaccountstatic->id) {
2061 print $bankaccountstatic->getNomUrl(1,
'transactions');
2066 print
'<td class="right">'.price($objp->amount).
"</td>";
2068 $totalpaid += $objp->amount;
2074 $resteapayeraffiche = $remaintopay;
2076 if ($remaintopay > 0) {
2077 $cssforamountpaymentcomplete =
'amountremaintopay';
2079 $cssforamountpaymentcomplete =
'amountpaymentcomplete';
2083 $cssforamountpaymentcomplete =
'amountpaymentneutral strikefordisabled';
2084 } elseif (
$object->paid == 1 && $remaintopay > 0) {
2085 $cssforamountpaymentcomplete =
'amountpaymentneutral strikefordisabled';
2087 print
'<tr><td colspan="'.$nbcols.
'" class="right">'.$langs->trans(
"AlreadyPaid").
':</td>';
2089 print
'<td class="right">'.price($totalpaid).
'</td></tr>';
2091 print
'<tr><td colspan="'.$nbcols.
'" class="right">'.$langs->trans(
"AmountExpected").
':</td>';
2093 print
'<td class="right">'.price(
$object->total_ttc).
'</td></tr>';
2095 print
'<tr><td colspan="'.$nbcols.
'" class="right">'.$langs->trans(
"RemainderToPay").
':</td>';
2097 print
'<td class="right'.($resteapayeraffiche ?
' amountremaintopay' : (
' '.$cssforamountpaymentcomplete)).
'">'.
price($resteapayeraffiche).
'</td></tr>';
2106 print
'<div class="clearboth"></div>';
2112 print
'<div style="clear: both;"></div>';
2114 $actiontouse =
'updateline';
2116 $actiontouse =
'addline';
2119 print
'<form name="expensereport" action="'.$_SERVER[
"PHP_SELF"].
'" enctype="multipart/form-data" method="post" >';
2120 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2121 print
'<input type="hidden" name="action" value="'.$actiontouse.
'">';
2122 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
2123 print
'<input type="hidden" name="fk_expensereport" value="'.$object->id.
'" />';
2124 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
2125 print
'<input type="hidden" name="page_y" value="">';
2127 print
'<div class="div-table-responsive-no-min">';
2128 print
'<table id="tablelines" class="noborder centpercent">';
2134 print
'<tr class="liste_titre headerexpensereportdet">';
2135 print
'<td class="center linecollinenb">'.$langs->trans(
'LineNb').
'</td>';
2137 print
'<td class="center linecoldate">'.$langs->trans(
'Date').
'</td>';
2139 print
'<td class="minwidth100imp linecolproject">'.$langs->trans(
'Project').
'</td>';
2141 print
'<td class="center linecoltype">'.$langs->trans(
'Type').
'</td>';
2143 print
'<td class="center linecolcarcategory">'.$langs->trans(
'CarCategory').
'</td>';
2145 print
'<td class="linecoldescription">'.$langs->trans(
'Description').
'</td>';
2146 print
'<td class="right linecolvat">'.$langs->trans(
'VAT').
'</td>';
2147 print
'<td class="right linecolpriceuht">'.$langs->trans(
'PriceUHT').
'</td>';
2148 print
'<td class="right linecolpriceuttc">'.$langs->trans(
'PriceUTTC').
'</td>';
2149 print
'<td class="right linecolqty">'.$langs->trans(
'Qty').
'</td>';
2150 if ($action !=
'editline') {
2151 print
'<td class="right linecolamountht">'.$langs->trans(
'AmountHT').
'</td>';
2152 print
'<td class="right linecolamountttc">'.$langs->trans(
'AmountTTC').
'</td>';
2164 print
'<td class="right"></td>';
2168 foreach (
$object->lines as &$line) {
2171 if ($action !=
'editline' || $line->id !=
GETPOSTINT(
'rowid')) {
2172 print
'<tr class="oddeven linetr" data-id="'.$line->id.
'">';
2175 print
'<td class="center linecollinenb">';
2180 print
'<td class="center linecoldate">'.dol_print_date(
$db->jdate($line->date),
'day').
'</td>';
2184 print
'<td class="lineproject">';
2185 if ($line->fk_project > 0) {
2186 $projecttmp->id = $line->fk_project;
2187 $projecttmp->ref = $line->projet_ref;
2188 $projecttmp->title = $line->projet_title;
2189 print $projecttmp->getNomUrl(1);
2196 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
2198 $resaccountingaccount = $accountingaccount->fetch(0, $line->type_fees_accountancy_code, 1);
2200 $titlealt .= $langs->trans(
"AccountancyCode").
': ';
2201 if ($resaccountingaccount > 0) {
2202 $titlealt .= $accountingaccount->account_number;
2204 $titlealt .= $langs->trans(
"NotFound");
2210 print
'<td class="center linecoltype" title="'.dol_escape_htmltag($titlealt).
'">';
2211 $labeltype = ($langs->trans(($line->type_fees_code)) == $line->type_fees_code ? $line->type_fees_libelle : $langs->trans($line->type_fees_code));
2217 print
'<td class="fk_c_exp_tax_cat linecoltaxcat">';
2218 $exp_tax_cat_label =
dol_getIdFromCode(
$db, $line->fk_c_exp_tax_cat,
'c_exp_tax_cat',
'rowid',
'label');
2219 print $langs->trans($exp_tax_cat_label);
2224 print
'<td class="left linecolcomment minwidth100">'.dol_nl2br($line->comments).
'</td>';
2227 $senderissupplier = 0;
2228 $tooltiponprice =
'';
2229 $tooltiponpriceend =
'';
2231 $tooltiponprice = $langs->transcountry(
"TotalHT",
$mysoc->country_code).
'='.
price($line->total_ht);
2232 $tooltiponprice .=
'<br>'.$langs->transcountry(
"TotalVAT", ($senderissupplier ?
$object->thirdparty->country_code :
$mysoc->country_code)).
'='.
price($line->total_tva);
2233 if (is_object(
$object->thirdparty)) {
2234 if ($senderissupplier) {
2235 $seller =
$object->thirdparty;
2242 if (
$mysoc->useLocalTax(1)) {
2243 if (($seller->country_code == $buyer->country_code) || $line->total_localtax1 || $seller->useLocalTax(1)) {
2244 $tooltiponprice .=
'<br>'.$langs->transcountry(
"TotalLT1", $seller->country_code).
'='.
price($line->total_localtax1);
2246 $tooltiponprice .=
'<br>'.$langs->transcountry(
"TotalLT1", $seller->country_code).
'=<span class="opacitymedium">'.$langs->trans($senderissupplier ?
"NotUsedForThisVendor" :
"NotUsedForThisCustomer").
'</span>';
2249 if (
$mysoc->useLocalTax(2)) {
2250 if ((isset($seller->country_code) && isset($buyer->thirdparty->country_code) && $seller->country_code == $buyer->thirdparty->country_code) || $line->total_localtax2 || $seller->useLocalTax(2)) {
2251 $tooltiponprice .=
'<br>'.$langs->transcountry(
"TotalLT2", $seller->country_code).
'='.
price($line->total_localtax2);
2253 $tooltiponprice .=
'<br>'.$langs->transcountry(
"TotalLT2", $seller->country_code).
'=<span class="opacitymedium">'.$langs->trans($senderissupplier ?
"NotUsedForThisVendor" :
"NotUsedForThisCustomer").
'</span>';
2257 $tooltiponprice .=
'<br>'.$langs->transcountry(
"TotalTTC",
$mysoc->country_code).
'='.
price($line->total_ttc);
2259 $tooltiponprice =
'<span class="classfortooltip" title="'.dol_escape_htmltag($tooltiponprice).
'">';
2260 $tooltiponpriceend =
'</span>';
2263 print
'<td class="right linecolvatrate">';
2264 print $tooltiponprice;
2265 print
vatrate($line->vatrate.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
''), true);
2266 print $tooltiponpriceend;
2270 print
'<td class="right linecolunitht">';
2271 if (!empty($line->value_unit_ht)) {
2272 print
price($line->value_unit_ht);
2274 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $line->vatrate));
2275 $pricenettoshow =
price2num((
float) $line->value_unit / (1 + (
float) $tmpvat / 100),
'MU');
2276 print
price($pricenettoshow);
2280 print
'<td class="right linecolunitttc">'.price($line->value_unit).
'</td>';
2282 print
'<td class="right linecolqty">'.dol_escape_htmltag((
string) $line->qty).
'</td>';
2284 if ($action !=
'editline') {
2285 print
'<td class="right linecoltotalht">'.price($line->total_ht).
'</td>';
2286 print
'<td class="right linecoltotalttc">'.price($line->total_ttc).
'</td>';
2290 print
'<td class="center linecolpreview">';
2291 if ($line->fk_ecm_files > 0) {
2292 $modulepart =
'expensereport';
2293 $maxheightmini = 32;
2295 $result = $ecmfilesstatic->fetch($line->fk_ecm_files);
2297 $relativepath = preg_replace(
'/expensereport\//',
'', $ecmfilesstatic->filepath);
2298 $fileinfo = pathinfo($ecmfilesstatic->filepath.
'/'.$ecmfilesstatic->filename);
2300 $minifile = getImageFileNameForSize($fileinfo[
'basename'],
'_mini');
2301 if (!
dol_is_file(
$conf->expensereport->dir_output.
'/'.$relativepath.
'/'.$minifile)) {
2302 $minifile = getImageFileNameForSize($fileinfo[
'basename'],
'_mini',
'.png');
2305 $urlforhref = getAdvancedPreviewUrl($modulepart, $relativepath.
'/'.$fileinfo[
'filename'].
'.'.strtolower($fileinfo[
'extension']), 1,
'&entity='.(empty(
$object->entity) ?
$conf->entity :
$object->entity));
2306 if (empty($urlforhref)) {
2307 $urlforhref = DOL_URL_ROOT.
'/viewimage.php?modulepart='.$modulepart.
'&entity='.(empty(
$object->entity) ?
$conf->entity :
$object->entity).
'&file='.urlencode($relativepath.$fileinfo[
'filename'].
'.'.strtolower($fileinfo[
'extension']));
2308 print
'<a href="'.$urlforhref.
'" class="aphoto" target="_blank" rel="noopener noreferrer">';
2310 print
'<a href="'.$urlforhref[
'url'].
'" class="'.$urlforhref[
'css'].
'" target="'.$urlforhref[
'target'].
'" mime="'.$urlforhref[
'mime'].
'">';
2312 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="">';
2315 if (preg_match(
'/\.pdf$/i', $ecmfilesstatic->filename)) {
2316 $filepdf =
$conf->expensereport->dir_output.
'/'.$relativepath.
'/'.$ecmfilesstatic->filename;
2317 $fileimage =
$conf->expensereport->dir_output.
'/'.$relativepath.
'/'.$ecmfilesstatic->filename.
'_preview.png';
2318 $relativepathimage = $relativepath.
'/'.$ecmfilesstatic->filename.
'_preview.png';
2320 $pdfexists = file_exists($filepdf);
2323 if (!file_exists($fileimage) || (filemtime($fileimage) < filemtime($filepdf))) {
2325 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2334 if ($pdfexists && !$error) {
2335 $heightforphotref = 70;
2336 if (!empty(
$conf->dol_optimize_smallscreen)) {
2337 $heightforphotref = 60;
2339 $urlforhref = getAdvancedPreviewUrl($modulepart, $relativepath.
'/'.$fileinfo[
'filename'].
'.'.strtolower($fileinfo[
'extension']), 1,
'&entity='.(empty(
$object->entity) ?
$conf->entity :
$object->entity));
2340 print
'<a href="'.$urlforhref[
'url'].
'" class="'.$urlforhref[
'css'].
'" target="'.$urlforhref[
'target'].
'" mime="'.$urlforhref[
'mime'].
'">';
2342 if (file_exists($fileimage)) {
2343 print
'<img height="'.$heightforphotref.
'" class="photo photowithmargin photowithborder" src="'.DOL_URL_ROOT.
'/viewimage.php?modulepart=apercu'.$modulepart.
'&file='.urlencode($relativepathimage).
'">';
2346 print
img_mime($ecmfilesstatic->filename);
2356 print
'<td class="nowrap right linecolwarning">';
2357 print !empty($line->rule_warning_message) ?
img_warning(html_entity_decode($line->rule_warning_message)) :
'';
2362 print
'<td class="nowrap right linecolaction">';
2364 print
'<a class="editfielda reposition paddingrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=editline&token='.newToken().
'&rowid='.$line->rowid.
'">';
2366 print
'</a> ';
2367 print
'<a class="paddingrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=delete_line&token='.newToken().
'&rowid='.$line->rowid.
'">';
2377 if ($action ==
'editline' && $line->id ==
GETPOSTINT(
'rowid')) {
2387 print
'<!-- line of expense report -->'.
"\n";
2388 print
'<tr class="tredited">';
2390 print
'<td class="center">';
2394 print
'<td colspan="'.($colspan - 1).
'" class="liste_titre"> ';
2395 print
'<a href="" class="commonlink auploadnewfilenow reposition">'.$langs->trans(
"UploadANewFileNow");
2396 print
img_picto($langs->trans(
"UploadANewFileNow"),
'chevron-down',
'', 0, 0, 0,
'',
'marginleftonly');
2399 print
' - <a href="" class="commonlink aattachtodoc reposition">'.$langs->trans(
"AttachTheNewLineToTheDocument");
2400 print
img_picto($langs->trans(
"AttachTheNewLineToTheDocument"),
'chevron-down',
'', 0, 0, 0,
'',
'marginleftonly');
2404 print
'<!-- Code to open/close section to submit or link files in edit mode -->'.
"\n";
2405 print
'<script type="text/javascript">'.
"\n";
2406 print
'$(document).ready(function() {
2407 $( ".auploadnewfilenow" ).click(function() {
2408 jQuery(".truploadnewfilenow").toggle();
2409 jQuery(".trattachnewfilenow").hide();
2412 $( ".aattachtodoc" ).click(function() {
2413 jQuery(".trattachnewfilenow").toggle();
2414 jQuery(".truploadnewfilenow").hide();
2417 if (is_array(
GETPOST(
'attachfile',
'array')) && count(
GETPOST(
'attachfile',
'array'))) {
2418 print
'jQuery(".trattachnewfilenow").toggle();'.
"\n";
2421 jQuery("form[name=\"expensereport\"]").submit(function() {
2422 if (jQuery(".truploadnewfilenow").is(":hidden")) {
2423 jQuery("input[name=\"sendit\"]").val("");
2430 print
'</script>'.
"\n";
2433 $filenamelinked =
'';
2434 if ($line->fk_ecm_files > 0) {
2435 $result = $ecmfilesstatic->fetch($line->fk_ecm_files);
2437 $filenamelinked = $ecmfilesstatic->filename;
2441 $tredited =
'tredited';
2442 include DOL_DOCUMENT_ROOT.
'/expensereport/tpl/expensereport_addfile.tpl.php';
2443 include DOL_DOCUMENT_ROOT.
'/expensereport/tpl/expensereport_linktofile.tpl.php';
2445 print
'<tr class="oddeven tredited">';
2450 print
'<td class="center">';
2451 print $form->selectDate($line->date,
'date');
2456 print
'<td class="nowraponall">';
2457 print $formproject->select_projects(-1, (
string) $line->fk_project,
'fk_project', 0, 0, $projectRequired ? 0 : 1, 1, 0, 0, 0,
'', 1, 0,
'maxwidth300');
2462 print
'<td class="center">';
2463 print $formexpensereport->selectTypeExpenseReport($line->fk_c_type_fees,
'fk_c_type_fees');
2467 print
'<td class="fk_c_exp_tax_cat">';
2468 $params = array(
'fk_expense' =>
$object->id,
'fk_expense_det' => $line->id,
'date' => $line->date);
2469 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);
2475 print
'<textarea name="comments" class="flat_ndf centpercent">'.dol_escape_htmltag($line->comments, 0, 1).
'</textarea>';
2479 $selectedvat =
price2num($line->vatrate).(!empty($line->vat_src_code) ?
' ('.$line->vat_src_code.
')' :
'');
2480 print
'<td class="right">';
2482 print $form->load_tva(
'vatrate', (GETPOSTISSET(
"vatrate") ?
GETPOST(
"vatrate") : $selectedvat), null, null, 0, 0,
'', false, 1, 2);
2486 print
'<td class="right">';
2487 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.
' />';
2491 print
'<td class="right">';
2492 print
'<input type="text" min="0" class="right maxwidth50" id="value_unit" name="value_unit" value="'.dol_escape_htmltag(
price2num($line->value_unit)).
'" />';
2496 print
'<td class="right">';
2497 print
'<input type="text" min="0" class="input_qty right maxwidth50" name="qty" value="'.dol_escape_htmltag((
string) $line->qty).
'" />';
2504 print
'<td class="center">';
2508 print
'<td class="center">';
2512 print
'<input type="hidden" name="rowid" value="'.$line->rowid.
'">';
2513 print $form->buttonsSaveCancel(
'Save',
'Cancel', array(),
false,
'small');
2532 if ($action !=
'editline') {
2536 $nbFiles = $nbLinks = 0;
2537 $arrayoffiles = array();
2539 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2540 require_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
2541 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
2544 $nbFiles = count($arrayoffiles);
2549 print
'<tr class="liste_titre">';
2550 print
'<td colspan="'.$colspan.
'" class="liste_titre expensereportautoload">';
2551 print
'<a href="" class="commonlink auploadnewfilenow reposition">'.$langs->trans(
"UploadANewFileNow");
2552 print
img_picto($langs->trans(
"UploadANewFileNow"),
'chevron-down',
'', 0, 0, 0,
'',
'marginleftonly');
2555 print
' - <a href="" class="commonlink aattachtodoc reposition">'.$langs->trans(
"AttachTheNewLineToTheDocument");
2556 print
img_picto($langs->trans(
"AttachTheNewLineToTheDocument"),
'chevron-down',
'', 0, 0, 0,
'',
'marginleftonly');
2560 print
'<!-- Code to open/close section to submit or link files in the form to add new line -->'.
"\n";
2561 print
'<script type="text/javascript">'.
"\n";
2562 print
'$(document).ready(function() {
2563 $( ".auploadnewfilenow" ).click(function() {
2564 console.log("We click on toggle of auploadnewfilenow");
2565 jQuery(".truploadnewfilenow").toggle();
2566 jQuery(".trattachnewfilenow").hide();
2567 if (jQuery(".truploadnewfilenow").is(":hidden")) {
2568 jQuery("input[name=\"sendit\"]").prop("name", "senditdisabled");
2570 jQuery("input[name=\"senditdisabled\"]").prop("name", "sendit");
2572 // TODO Switch css fa-chevron-dow and add fa-chevron-up
2575 $( ".aattachtodoc" ).click(function() {
2576 console.log("We click on toggle of aattachtodoc");
2577 jQuery(".trattachnewfilenow").toggle();
2578 jQuery(".truploadnewfilenow").hide();
2579 // TODO Switch css fa-chevron-dow and add fa-chevron-up
2582 if (is_array(
GETPOST(
'attachfile',
'array')) && count(
GETPOST(
'attachfile',
'array')) && $action !=
'updateline') {
2583 print
'jQuery(".trattachnewfilenow").show();'.
"\n";
2586 jQuery("form[name=\"expensereport\"]").submit(function() {
2587 if (jQuery(".truploadnewfilenow").is(":hidden")) {
2588 /* 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. */
2589 jQuery("input[name=\"sendit\"]").val("");
2590 jQuery("input[name=\"sendit\"]").prop("name", "senditdisabled");
2592 jQuery("input[name=\"senditdisabled\"]").prop("name", "sendit");
2599 print
'</script>'.
"\n";
2603 include DOL_DOCUMENT_ROOT.
'/expensereport/tpl/expensereport_linktofile.tpl.php';
2604 include DOL_DOCUMENT_ROOT.
'/expensereport/tpl/expensereport_addfile.tpl.php';
2606 print
'<tr class="liste_titre expensereportcreate">';
2608 print
'<td class="center expensereportcreatedate">'.$langs->trans(
'Date').
'</td>';
2610 print
'<td class="minwidth100imp">'.$form->textwithpicto($langs->trans(
'Project'), $langs->trans(
"ClosedProjectsAreHidden")).
'</td>';
2612 print
'<td class="center expensereportcreatetype">'.$langs->trans(
'Type').
'</td>';
2614 print
'<td>'.$langs->trans(
'CarCategory').
'</td>';
2616 print
'<td class="expensereportcreatedescription">'.$langs->trans(
'Description').
'</td>';
2617 print
'<td class="right expensereportcreatevat">'.$langs->trans(
'VAT').
'</td>';
2618 print
'<td class="right expensereportcreatepriceuth">'.$langs->trans(
'PriceUHT').
'</td>';
2619 print
'<td class="right expensereportcreatepricettc">'.$langs->trans(
'PriceUTTC').
'</td>';
2620 print
'<td class="right expensereportcreateqty">'.$langs->trans(
'Qty').
'</td>';
2627 print
'<tr class="oddeven nohover">';
2633 print
'<td class="center inputdate">';
2634 print $form->selectDate(!empty($date) ? $date : -1,
'date', 0, 0, 0,
'', 1, 1);
2639 print
'<td class="inputproject">';
2640 $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');
2645 print
'<td class="center inputtype">';
2646 print $formexpensereport->selectTypeExpenseReport(!empty($fk_c_type_fees) ? $fk_c_type_fees :
"",
'fk_c_type_fees', 1);
2650 print
'<td class="fk_c_exp_tax_cat">';
2651 $params = array(
'fk_expense' =>
$object->id);
2652 print $form->selectExpenseCategories(
'',
'fk_c_exp_tax_cat', 1, array(),
'fk_c_type_fees', $userauthor->default_c_exp_tax_cat, $params, 0);
2657 print
'<td class="inputcomment">';
2658 print
'<textarea class="flat_ndf centpercent" name="comments" rows="'.ROWS_2.
'">'.
dol_escape_htmltag(!empty($comments) ? $comments :
"", 0, 1).
'</textarea>';
2662 print
'<td class="right inputvat">';
2666 $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS =
'none';
2669 print $form->load_tva(
'vatrate', (!empty($vatrate) ? $vatrate : $defaultvat), null, null, 0, 0,
'', false, 1);
2673 print
'<td class="right inputpricenet">';
2674 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.
' />';
2678 print
'<td class="right inputtax">';
2679 print
'<input type="text" class="right maxwidth50" id="value_unit" name="value_unit" value="'.dol_escape_htmltag((!empty($value_unit) ? $value_unit :
"")).
'">';
2683 print
'<td class="right inputqty">';
2684 print
'<input type="text" min="0" class=" input_qty right maxwidth50" name="qty" value="'.dol_escape_htmltag(!empty($qty) ? $qty : 1).
'">';
2690 if ($action !=
'editline') {
2691 print
'<td class="right"></td>';
2692 print
'<td class="right"></td>';
2696 print
'<td class="center inputbuttons">';
2697 print $form->buttonsSaveCancel(
"Add",
'', array(),
true,
'reposition');
2708 /* JQuery for product free or predefined select */
2709 jQuery(document).ready(function() {
2710 jQuery("#value_unit_ht").keyup(function(event) {
2711 console.log(event.which); // discard event tag and arrows
2712 if (event.which != 9 && (event.which < 37 ||event.which > 40) && jQuery("#value_unit_ht").val() != "") {
2713 jQuery("#value_unit").val("");
2716 jQuery("#value_unit").keyup(function(event) {
2717 console.log(event.which); // discard event tag and arrows
2718 if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#value_unit").val() != "") {
2719 jQuery("#value_unit_ht").val("");
2727 /* unit price coef calculation */
2728 jQuery(".input_qty, #fk_c_type_fees, #select_fk_c_exp_tax_cat, #vatrate ").change(function(event) {
2729 console.log("We change a parameter");
2731 let type_fee = jQuery("#fk_c_type_fees").find(":selected").val();
2732 let tax_cat = jQuery("#select_fk_c_exp_tax_cat").find(":selected").val();
2733 let tva = jQuery("#vatrate").find(":selected").val();
2734 let qty = jQuery(".input_qty").val();
2736 let path = "'.DOL_URL_ROOT.
'/expensereport/ajax/ajaxik.php";
2737 path += "?fk_c_exp_tax_cat="+tax_cat;
2738 path += "&fk_expense="+'.((int)
$object->id).
';
2739 path += "&vatrate="+tva;
2740 path += "&qty="+qty;
2742 if (type_fee == 4) { // frais_kilométriques
2743 if (tax_cat == "" || parseInt(tax_cat) <= 0){
2751 success: function(response) {
2752 if (response.response_status == "success"){';
2756 jQuery("#value_unit").val(parseFloat(response.data) * (100 + parseFloat(tva)) / 100);
2757 jQuery("#value_unit").trigger("change");
2761 jQuery("#value_unit_ht").val(response.data);
2762 jQuery("#value_unit_ht").trigger("change");
2763 jQuery("#value_unit").val("");
2768 } else if(response.response_status == "error" && response.errorMessage != undefined && response.errorMessage.length > 0 ) {
2769 console.log("We get an error result");
2770 $.jnotify(response.errorMessage, "error", {timeout: 0, type: "error"},{ remove: function (){} } );
2776 /*console.log(event.which); // discard event tag and arrows
2777 if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#value_unit").val() != "") {
2778 jQuery("#value_unit_ht").val("");
2798 print
'Record not found';
2809print
'<div class="tabsAction">';
2811if ($action !=
'create' && $action !=
'edit' && $action !=
'editline') {
2816 if (empty($user->socid)) {
2818 print dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'email',
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'id' =>
$object->id,
'action' =>
'presend',
'mode' =>
'init'],
true).
'#formmailbeforetitle',
'');
2828 if (in_array(
$object->fk_user_author, $childids) || $user->hasRight(
'expensereport',
'writeall_advance')) {
2830 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>';
2833 if (count(
$object->lines) > 0) {
2834 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>';
2845 if ($user->id ==
$object->fk_user_author || $user->id ==
$object->fk_user_valid) {
2847 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>';
2849 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>';
2854 if ($user->id ==
$object->fk_user_author || $user->id ==
$object->fk_user_valid) {
2856 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>';
2866 if (in_array(
$object->fk_user_author, $childids)) {
2868 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=setdraft&token='.newToken().
'&id='.
$object->id.
'">'.$langs->trans(
'SetToDraft').
'</a></div>';
2876 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>';
2878 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>';
2881 if ($user->id ==
$object->fk_user_author || $user->id ==
$object->fk_user_valid) {
2883 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=cancel&id='.
$object->id.
'">'.$langs->trans(
"Cancel").
'</a></div>';
2892 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>';
2898 if ($remaintopay == 0) {
2899 print
'<div class="inline-block divButAction"><span class="butActionRefused classfortooltip" title="'.$langs->trans(
"DisabledBecauseRemainderToPayIsZero").
'">'.$langs->trans(
'DoPayment').
'</span></div>';
2901 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>';
2909 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>";
2915 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>';
2924 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>';
2929 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>';
2933 if ($user->hasRight(
'expensereport',
'creer')) {
2934 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>';
2940 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>';
2943 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>';
2946 $parameters = array();
2947 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
2954if (
GETPOST(
'modelselected',
'alpha')) {
2955 $action =
'presend';
2958if ($action !=
'presend') {
2963 print
'<div class="fichecenter"><div class="fichehalfleft">';
2964 print
'<a name="builddoc"></a>';
2966 if ($user->hasRight(
'expensereport',
'creer') && $action !=
'create' && $action !=
'edit') {
2969 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".
$object->id;
2970 $genallowed = $user->hasRight(
'expensereport',
'creer');
2971 $delallowed = $user->hasRight(
'expensereport',
'creer');
2973 print $formfile->showdocuments(
'expensereport', $filename, $filedir, $urlsource, $genallowed, $delallowed);
2974 $somethingshown = $formfile->numoffiles;
2990 print
'</div><div class="fichehalfright">';
2992 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
2994 $somethingshown = $formactions->showactions($object,
'expensereport', 0);
2996 print
'</div></div>';
3000$modelmail =
'expensereport_send';
3001$defaulttopic =
'SendExpenseReportRef';
3002$diroutput =
$conf->expensereport->dir_output;
3003$trackid =
'exp'.$object->id;
3005include 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.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $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.
get_date_range($date_start, $date_end, $format='', $outputlangs=null, $withparenthesis=1)
Format output for start and end date.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
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, $mode=0)
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.