2015-02-14 18:39:45 +01:00
< ? php
2018-09-09 09:36:12 +02:00
/* Copyright ( C ) 2003 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2004 - 2017 Laurent Destailleur < eldy @ users . sourceforge . net >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2009 Regis Houssin < regis . houssin @ inodbox . com >
2018-09-09 09:36:12 +02:00
* Copyright ( C ) 2015 - 2017 Alexandre Spangaro < aspangaro @ zendsi . com >
* Copyright ( C ) 2017 Ferran Marcet < fmarcet @ 2 byte . es >
* Copyright ( C ) 2018 Frédéric France < frederic . france @ netlogic . fr >
2015-02-14 18:39:45 +01:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2015-02-23 22:04:01 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2015-02-14 18:39:45 +01:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2015-02-15 19:13:16 +01:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2015-02-14 18:39:45 +01:00
*/
/**
* \file htdocs / expensereport / card . php
2015-03-17 11:23:45 +01:00
* \ingroup expensereport
* \brief Page for trip and expense report card
2015-02-14 18:39:45 +01:00
*/
$res = 0 ;
require '../main.inc.php' ;
2015-02-23 21:51:29 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/expensereport.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/price.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/modules/expensereport/modules_expensereport.php' ;
require_once DOL_DOCUMENT_ROOT . '/expensereport/class/expensereport.class.php' ;
2017-05-28 06:49:17 +02:00
require_once DOL_DOCUMENT_ROOT . '/expensereport/class/paymentexpensereport.class.php' ;
2015-02-23 21:51:29 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php' ;
2016-09-06 13:39:44 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php' ;
2017-05-28 06:49:17 +02:00
if ( ! empty ( $conf -> accounting -> enabled )) {
require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php' ;
}
2015-02-14 18:39:45 +01:00
2018-05-26 20:51:17 +02:00
// Load translation files required by the page
2018-04-16 19:25:27 +02:00
$langs -> loadLangs ( array ( " trips " , " bills " , " mails " ));
2015-02-14 18:39:45 +01:00
2017-05-16 13:27:32 +02:00
$action = GETPOST ( 'action' , 'aZ09' );
2017-09-15 10:50:50 +02:00
$cancel = GETPOST ( 'cancel' , 'alpha' );
2016-11-13 22:00:57 +01:00
$confirm = GETPOST ( 'confirm' , 'alpha' );
2018-03-10 15:52:11 +01:00
$date_start = dol_mktime ( 0 , 0 , 0 , GETPOST ( 'date_debutmonth' , 'int' ), GETPOST ( 'date_debutday' , 'int' ), GETPOST ( 'date_debutyear' , 'int' ));
$date_end = dol_mktime ( 0 , 0 , 0 , GETPOST ( 'date_finmonth' , 'int' ), GETPOST ( 'date_finday' , 'int' ), GETPOST ( 'date_finyear' , 'int' ));
$date = dol_mktime ( 0 , 0 , 0 , GETPOST ( 'datemonth' , 'int' ), GETPOST ( 'dateday' , 'int' ), GETPOST ( 'dateyear' , 'int' ));
$fk_projet = GETPOST ( 'fk_projet' , 'int' );
$vatrate = GETPOST ( 'vatrate' , 'alpha' );
2015-06-08 13:49:09 +02:00
$ref = GETPOST ( " ref " , 'alpha' );
2018-03-10 15:52:11 +01:00
$comments = GETPOST ( 'comments' , 'none' );
2015-11-28 15:28:59 +01:00
$fk_c_type_fees = GETPOST ( 'fk_c_type_fees' , 'int' );
2018-03-10 15:52:11 +01:00
$socid = GETPOST ( 'socid' , 'int' ) ? GETPOST ( 'socid' , 'int' ) : GETPOST ( 'socid_id' , 'int' );
2015-02-14 18:39:45 +01:00
// Security check
$id = GETPOST ( " id " , 'int' );
if ( $user -> societe_id ) $socid = $user -> societe_id ;
$result = restrictedArea ( $user , 'expensereport' , 0 , 'expensereport' );
// Hack to use expensereport dir
$rootfordata = DOL_DATA_ROOT ;
$rootforuser = DOL_DATA_ROOT ;
// If multicompany module is enabled, we redefine the root of data
if ( ! empty ( $conf -> multicompany -> enabled ) && ! empty ( $conf -> entity ) && $conf -> entity > 1 )
{
$rootfordata .= '/' . $conf -> entity ;
}
$conf -> expensereport -> dir_output = $rootfordata . '/expensereport' ;
2015-02-21 16:15:54 +01:00
// Define $urlwithroot
$urlwithouturlroot = preg_replace ( '/' . preg_quote ( DOL_URL_ROOT , '/' ) . '$/i' , '' , trim ( $dolibarr_main_url_root ));
$urlwithroot = $urlwithouturlroot . DOL_URL_ROOT ; // This is to use external domain name found into config file
//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
2015-02-22 13:16:49 +01:00
// PDF
$hidedetails = ( GETPOST ( 'hidedetails' , 'int' ) ? GETPOST ( 'hidedetails' , 'int' ) : ( ! empty ( $conf -> global -> MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS ) ? 1 : 0 ));
$hidedesc = ( GETPOST ( 'hidedesc' , 'int' ) ? GETPOST ( 'hidedesc' , 'int' ) : ( ! empty ( $conf -> global -> MAIN_GENERATE_DOCUMENTS_HIDE_DESC ) ? 1 : 0 ));
$hideref = ( GETPOST ( 'hideref' , 'int' ) ? GETPOST ( 'hideref' , 'int' ) : ( ! empty ( $conf -> global -> MAIN_GENERATE_DOCUMENTS_HIDE_REF ) ? 1 : 0 ));
2015-02-14 18:39:45 +01:00
2016-09-06 13:39:44 +02:00
$object = new ExpenseReport ( $db );
$extrafields = new ExtraFields ( $db );
2015-02-14 18:39:45 +01:00
2016-09-06 13:39:44 +02:00
// fetch optionals attributes and labels
$extralabels = $extrafields -> fetch_name_optionals_label ( $object -> table_element );
2015-02-15 22:49:23 +01:00
2016-09-06 13:39:44 +02:00
// Load object
include DOL_DOCUMENT_ROOT . '/core/actions_fetchobject.inc.php' ; // Must be include, not include_once
2015-02-14 18:39:45 +01:00
2017-06-10 12:56:28 +02:00
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
2016-09-06 13:39:44 +02:00
$hookmanager -> initHooks ( array ( 'expensereportcard' , 'globalcard' ));
2015-02-14 18:39:45 +01:00
2016-09-06 13:39:44 +02:00
$permissionnote = $user -> rights -> expensereport -> creer ; // Used by the include of actions_setnotes.inc.php
$permissiondellink = $user -> rights -> expensereport -> creer ; // Used by the include of actions_dellink.inc.php
$permissionedit = $user -> rights -> expensereport -> creer ; // Used by the include of actions_lineupdown.inc.php
2015-02-14 18:39:45 +01:00
2015-02-15 22:49:23 +01:00
2015-02-14 18:39:45 +01:00
/*
2016-09-06 13:39:44 +02:00
* Actions
2015-02-14 18:39:45 +01:00
*/
2016-09-06 13:39:44 +02:00
$parameters = array ( 'socid' => $socid );
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
if ( $reshook < 0 ) setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
2015-02-14 18:39:45 +01:00
2016-09-06 13:39:44 +02:00
if ( empty ( $reshook ))
2015-02-14 18:39:45 +01:00
{
2017-09-17 15:38:50 +02:00
if ( $cancel )
{
if ( ! empty ( $backtopage ))
{
header ( " Location: " . $backtopage );
exit ;
}
$action = '' ;
2016-09-06 13:39:44 +02:00
$fk_projet = '' ;
$date_start = '' ;
$date_end = '' ;
$date = '' ;
$comments = '' ;
$vatrate = '' ;
$value_unit = '' ;
$qty = 1 ;
$fk_c_type_fees =- 1 ;
2017-09-17 15:38:50 +02:00
}
2015-02-14 18:39:45 +01:00
2016-09-06 13:39:44 +02:00
include DOL_DOCUMENT_ROOT . '/core/actions_setnotes.inc.php' ; // Must be include, not include_once
include DOL_DOCUMENT_ROOT . '/core/actions_dellink.inc.php' ; // Must be include, not include_once
include DOL_DOCUMENT_ROOT . '/core/actions_lineupdown.inc.php' ; // Must be include, not include_once
// Action clone object
if ( $action == 'confirm_clone' && $confirm == 'yes' && $user -> rights -> expensereport -> creer )
{
2018-03-10 15:52:11 +01:00
if ( 1 == 0 && ! GETPOST ( 'clone_content' , 'alpha' ) && ! GETPOST ( 'clone_receivers' , 'alpha' ))
2016-09-06 13:39:44 +02:00
{
setEventMessages ( $langs -> trans ( " NoCloneOptionsSpecified " ), null , 'errors' );
}
else
{
if ( $object -> id > 0 )
{
2017-05-29 13:19:45 +02:00
// Because createFromClone modifies the object, we must clone it so that we can restore it later if it fails
2016-09-06 13:39:44 +02:00
$orig = clone $object ;
2017-06-11 10:37:58 +02:00
2017-05-29 13:19:45 +02:00
$result = $object -> createFromClone ( GETPOST ( 'fk_user_author' , 'int' ));
2016-09-06 13:39:44 +02:00
if ( $result > 0 )
{
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . '?id=' . $result );
exit ;
}
else
{
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$object = $orig ;
$action = '' ;
}
}
}
}
2017-06-11 10:37:58 +02:00
2018-03-10 15:52:11 +01:00
if ( $action == 'confirm_delete' && GETPOST ( " confirm " , 'alpha' ) == " yes " && $id > 0 && $user -> rights -> expensereport -> supprimer )
2016-09-06 13:39:44 +02:00
{
$object = new ExpenseReport ( $db );
2016-09-09 15:36:33 +02:00
$result = $object -> fetch ( $id );
$result = $object -> delete ( $user );
2016-09-06 13:39:44 +02:00
if ( $result >= 0 )
{
header ( " Location: index.php " );
exit ;
}
else
{
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
}
2017-06-11 10:37:58 +02:00
2016-09-06 13:39:44 +02:00
if ( $action == 'add' && $user -> rights -> expensereport -> creer )
{
$object = new ExpenseReport ( $db );
2017-06-11 10:37:58 +02:00
2016-09-06 13:39:44 +02:00
$object -> date_debut = $date_start ;
$object -> date_fin = $date_end ;
2017-06-11 10:37:58 +02:00
2016-11-13 22:00:57 +01:00
$object -> fk_user_author = GETPOST ( 'fk_user_author' , 'int' );
if ( ! ( $object -> fk_user_author > 0 )) $object -> fk_user_author = $user -> id ;
2017-06-11 10:37:58 +02:00
2016-11-13 22:00:57 +01:00
$fuser = new User ( $db );
$fuser -> fetch ( $object -> fk_user_author );
2017-06-11 10:37:58 +02:00
2016-09-06 13:39:44 +02:00
$object -> fk_statut = 1 ;
$object -> fk_c_paiement = GETPOST ( 'fk_c_paiement' , 'int' );
$object -> fk_user_validator = GETPOST ( 'fk_user_validator' , 'int' );
2017-09-25 00:16:52 +02:00
$object -> note_public = GETPOST ( 'note_public' , 'none' );
$object -> note_private = GETPOST ( 'note_private' , 'none' );
2016-09-06 13:39:44 +02:00
// Fill array 'array_options' with data from add form
if ( ! $error )
{
$ret = $extrafields -> setOptionalsFromPost ( $extralabels , $object );
if ( $ret < 0 ) $error ++ ;
}
2017-06-11 10:37:58 +02:00
2017-11-26 00:14:54 +01:00
if ( empty ( $conf -> global -> EXPENSEREPORT_ALLOW_OVERLAPPING_PERIODS ) && $object -> periode_existe ( $fuser , $object -> date_debut , $object -> date_fin ))
2016-09-06 13:39:44 +02:00
{
$error ++ ;
setEventMessages ( $langs -> trans ( " ErrorDoubleDeclaration " ), null , 'errors' );
$action = 'create' ;
}
2017-06-11 10:37:58 +02:00
2016-09-06 13:39:44 +02:00
if ( ! $error )
{
$db -> begin ();
2017-06-11 10:37:58 +02:00
2016-09-06 13:39:44 +02:00
$id = $object -> create ( $user );
2017-11-12 20:41:25 +01:00
if ( $id <= 0 )
{
$error ++ ;
}
2017-06-11 10:37:58 +02:00
2017-11-12 20:41:25 +01:00
if ( ! $error )
2016-09-06 13:39:44 +02:00
{
$db -> commit ();
Header ( " Location: " . $_SERVER [ " PHP_SELF " ] . " ?id= " . $id );
exit ;
}
else
{
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$db -> rollback ();
$action = 'create' ;
}
}
}
2017-06-11 10:37:58 +02:00
2016-09-06 13:39:44 +02:00
if ( $action == 'update' && $user -> rights -> expensereport -> creer )
{
$object = new ExpenseReport ( $db );
$object -> fetch ( $id );
2017-06-11 10:37:58 +02:00
2016-09-06 13:39:44 +02:00
$object -> date_debut = $date_start ;
$object -> date_fin = $date_end ;
2017-06-11 10:37:58 +02:00
2016-09-06 13:39:44 +02:00
if ( $object -> fk_statut < 3 )
{
$object -> fk_user_validator = GETPOST ( 'fk_user_validator' , 'int' );
}
2017-06-11 10:37:58 +02:00
2016-09-06 13:39:44 +02:00
$object -> fk_c_paiement = GETPOST ( 'fk_c_paiement' , 'int' );
2017-09-25 00:16:52 +02:00
$object -> note_public = GETPOST ( 'note_public' , 'none' );
$object -> note_private = GETPOST ( 'note_private' , 'none' );
2016-09-06 13:39:44 +02:00
$object -> fk_user_modif = $user -> id ;
2017-06-11 10:37:58 +02:00
2016-09-06 13:39:44 +02:00
$result = $object -> update ( $user );
if ( $result > 0 )
{
header ( " Location: " . $_SERVER [ " PHP_SELF " ] . " ?id= " . $_POST [ 'id' ]);
exit ;
}
else
{
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
}
2017-06-11 10:37:58 +02:00
2016-09-06 13:39:44 +02:00
if ( $action == 'update_extras' )
{
2018-02-23 16:11:00 +01:00
$object -> oldcopy = dol_clone ( $object );
// Fill array 'array_options' with data from update form
2016-09-06 13:39:44 +02:00
$extralabels = $extrafields -> fetch_name_optionals_label ( $object -> table_element );
2018-02-23 16:11:00 +01:00
$ret = $extrafields -> setOptionalsFromPost ( $extralabels , $object , GETPOST ( 'attribute' , 'none' ));
2016-09-06 13:39:44 +02:00
if ( $ret < 0 ) $error ++ ;
2017-06-11 10:37:58 +02:00
2016-09-06 13:39:44 +02:00
if ( ! $error )
{
2018-04-10 12:03:01 +02:00
// Actions on extra fields
2018-12-01 16:19:54 +01:00
$result = $object -> insertExtraFields ( 'EXPENSEREPORT_MODIFY' );
2018-04-10 12:03:01 +02:00
if ( $result < 0 )
{
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$error ++ ;
}
2016-09-06 13:39:44 +02:00
}
2017-06-11 10:37:58 +02:00
2016-09-06 13:39:44 +02:00
if ( $error )
$action = 'edit_extras' ;
}
2017-06-11 10:37:58 +02:00
2018-03-10 15:52:11 +01:00
if ( $action == " confirm_validate " && GETPOST ( " confirm " , 'alpha' ) == " yes " && $id > 0 && $user -> rights -> expensereport -> creer )
2016-09-06 13:39:44 +02:00
{
2018-02-07 14:21:57 +01:00
$error = 0 ;
$db -> begin ();
2016-09-06 13:39:44 +02:00
$object = new ExpenseReport ( $db );
$object -> fetch ( $id );
2018-02-07 14:21:57 +01:00
2016-09-06 13:39:44 +02:00
$result = $object -> setValidate ( $user );
2017-06-11 10:37:58 +02:00
2018-02-07 14:21:57 +01:00
if ( $result >= 0 )
2016-09-06 13:39:44 +02:00
{
// Define output language
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE ))
{
$outputlangs = $langs ;
$newlang = '' ;
2017-06-27 17:27:01 +02:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) $newlang = GETPOST ( 'lang_id' , 'aZ09' );
2016-09-06 13:39:44 +02:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $object -> thirdparty -> default_lang ;
if ( ! empty ( $newlang )) {
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
$model = $object -> modelpdf ;
$ret = $object -> fetch ( $id ); // Reload to get new records
2017-06-11 10:37:58 +02:00
2016-09-06 13:39:44 +02:00
$object -> generateDocument ( $model , $outputlangs , $hidedetails , $hidedesc , $hideref );
}
}
2018-02-07 14:21:57 +01:00
else
{
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$error ++ ;
}
2017-06-11 10:37:58 +02:00
2018-02-07 14:21:57 +01:00
if ( ! $error && $result > 0 && $object -> fk_user_validator > 0 )
2016-09-06 13:39:44 +02:00
{
$langs -> load ( " mails " );
2017-06-11 10:37:58 +02:00
2016-09-06 13:39:44 +02:00
// TO
$destinataire = new User ( $db );
$destinataire -> fetch ( $object -> fk_user_validator );
$emailTo = $destinataire -> email ;
2017-06-11 10:37:58 +02:00
2016-09-06 13:39:44 +02:00
// FROM
$expediteur = new User ( $db );
$expediteur -> fetch ( $object -> fk_user_author );
$emailFrom = $expediteur -> email ;
2017-06-11 10:37:58 +02:00
2016-09-06 13:39:44 +02:00
if ( $emailTo && $emailFrom )
{
$filename = array (); $filedir = array (); $mimetype = array ();
2017-06-11 10:37:58 +02:00
2016-09-06 13:39:44 +02:00
// SUBJECT
2018-10-25 14:05:22 +02:00
$societeName = $conf -> global -> MAIN_INFO_SOCIETE_NOM ;
if ( ! empty ( $conf -> global -> MAIN_APPLICATION_TITLE )) $societeName = $conf -> global -> MAIN_APPLICATION_TITLE ;
$subject = $societeName . " - " . $langs -> transnoentities ( " ExpenseReportWaitingForApproval " );
2017-06-11 10:37:58 +02:00
2016-09-06 13:39:44 +02:00
// CONTENT
$link = $urlwithroot . '/expensereport/card.php?id=' . $object -> id ;
2016-12-27 06:45:36 +01:00
$message = $langs -> transnoentities ( " ExpenseReportWaitingForApprovalMessage " , $expediteur -> getFullName ( $langs ), get_date_range ( $object -> date_debut , $object -> date_fin , '' , $langs ), $link );
2017-06-11 10:37:58 +02:00
2016-09-06 13:39:44 +02:00
// Rebuild pdf
/*
$object -> setDocModel ( $user , " " );
$resultPDF = expensereport_pdf_create ( $db , $id , '' , " " , $langs );
2017-06-11 10:37:58 +02:00
2016-09-06 13:39:44 +02:00
if ( $resultPDF ) :
// ATTACHMENT
array_push ( $filename , dol_sanitizeFileName ( $object -> ref ) . " .pdf " );
array_push ( $filedir , $conf -> expensereport -> dir_output . " / " . dol_sanitizeFileName ( $object -> ref ) . " / " . dol_sanitizeFileName ( $object -> ref ) . " .pdf " );
array_push ( $mimetype , " application/pdf " );
*/
2017-06-11 10:37:58 +02:00
2016-09-06 13:39:44 +02:00
// PREPARE SEND
2018-10-25 13:19:56 +02:00
$mailfile = new CMailFile ( $subject , $emailTo , $emailFrom , $message , $filedir , $mimetype , $filename , '' , '' , 0 , - 1 );
2017-06-11 10:37:58 +02:00
2016-09-06 13:39:44 +02:00
if ( $mailfile )
{
// SEND
$result = $mailfile -> sendfile ();
if ( $result )
{
$mesg = $langs -> trans ( 'MailSuccessfulySent' , $mailfile -> getValidAddress ( $emailFrom , 2 ), $mailfile -> getValidAddress ( $emailTo , 2 ));
setEventMessages ( $mesg , null , 'mesgs' );
}
else
{
$langs -> load ( " other " );
if ( $mailfile -> error )
{
$mesg = '' ;
$mesg .= $langs -> trans ( 'ErrorFailedToSendMail' , $emailFrom , $emailTo );
$mesg .= '<br>' . $mailfile -> error ;
setEventMessages ( $mesg , null , 'errors' );
}
else
{
setEventMessages ( 'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS' , null , 'warnings' );
}
}
}
else
{
setEventMessages ( $mailfile -> error , $mailfile -> errors , 'errors' );
$action = '' ;
}
}
else
{
setEventMessages ( $langs -> trans ( " NoEmailSentBadSenderOrRecipientEmail " ), null , 'warnings' );
$action = '' ;
}
}
2018-02-07 14:21:57 +01:00
if ( ! $error )
{
$db -> commit ();
2018-02-07 16:03:31 +01:00
header ( " Location: " . $_SERVER [ " PHP_SELF " ] . " ?id= " . $id );
exit ;
2018-02-07 14:21:57 +01:00
}
else
{
$db -> rollback ();
}
2016-09-06 13:39:44 +02:00
}
2017-06-11 10:37:58 +02:00
2018-03-10 15:52:11 +01:00
if ( $action == " confirm_save_from_refuse " && GETPOST ( " confirm " , 'alpha' ) == " yes " && $id > 0 && $user -> rights -> expensereport -> creer )
2016-09-06 13:39:44 +02:00
{
$object = new ExpenseReport ( $db );
$object -> fetch ( $id );
$result = $object -> set_save_from_refuse ( $user );
2017-06-11 10:37:58 +02:00
2016-09-06 13:39:44 +02:00
if ( $result > 0 )
{
// Define output language
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE ))
{
$outputlangs = $langs ;
$newlang = '' ;
2017-06-27 17:27:01 +02:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) $newlang = GETPOST ( 'lang_id' , 'aZ09' );
2016-09-06 13:39:44 +02:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $object -> thirdparty -> default_lang ;
if ( ! empty ( $newlang )) {
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
$model = $object -> modelpdf ;
$ret = $object -> fetch ( $id ); // Reload to get new records
2017-06-11 10:37:58 +02:00
2016-09-06 13:39:44 +02:00
$object -> generateDocument ( $model , $outputlangs , $hidedetails , $hidedesc , $hideref );
}
}
2017-06-11 10:37:58 +02:00
2016-09-06 13:39:44 +02:00
if ( $result > 0 )
{
2016-12-27 06:45:36 +01:00
// Send mail
// TO
$destinataire = new User ( $db );
$destinataire -> fetch ( $object -> fk_user_validator );
$emailTo = $destinataire -> email ;
2017-06-11 10:37:58 +02:00
2017-05-02 11:28:40 +02:00
// FROM
$expediteur = new User ( $db );
$expediteur -> fetch ( $object -> fk_user_author );
$emailFrom = $expediteur -> email ;
2016-12-27 06:45:36 +01:00
2017-05-02 11:28:40 +02:00
if ( $emailFrom && $emailTo )
{
$filename = array (); $filedir = array (); $mimetype = array ();
2017-06-11 10:37:58 +02:00
2017-05-02 11:28:40 +02:00
// SUBJECT
2018-10-25 14:05:22 +02:00
$societeName = $conf -> global -> MAIN_INFO_SOCIETE_NOM ;
if ( ! empty ( $conf -> global -> MAIN_APPLICATION_TITLE )) $societeName = $conf -> global -> MAIN_APPLICATION_TITLE ;
$subject = $societeName . " - " . $langs -> transnoentities ( " ExpenseReportWaitingForReApproval " );
2017-06-11 10:37:58 +02:00
2016-12-27 06:45:36 +01:00
// CONTENT
$link = $urlwithroot . '/expensereport/card.php?id=' . $object -> id ;
$dateRefusEx = explode ( " " , $object -> date_refuse );
2016-12-27 14:48:14 +01:00
$message = $langs -> transnoentities ( " ExpenseReportWaitingForReApprovalMessage " , $dateRefusEx [ 0 ], $object -> detail_refuse , $expediteur -> getFullName ( $langs ), $link );
2016-12-27 06:45:36 +01:00
// Rebuild pdf
/*
$object -> setDocModel ( $user , " " );
$resultPDF = expensereport_pdf_create ( $db , $object , '' , " " , $langs );
if ( $resultPDF )
{
// ATTACHMENT
$filename = array (); $filedir = array (); $mimetype = array ();
array_push ( $filename , dol_sanitizeFileName ( $object -> ref ) . " .pdf " );
array_push ( $filedir , $conf -> expensereport -> dir_output . " / " . dol_sanitizeFileName ( $object -> ref ) . " / " . dol_sanitizeFileName ( $object -> ref_number ) . " .pdf " );
array_push ( $mimetype , " application/pdf " );
}
*/
2017-07-08 17:57:35 +02:00
2016-12-27 08:14:05 +01:00
// PREPARE SEND
2018-10-25 13:19:56 +02:00
$mailfile = new CMailFile ( $subject , $emailTo , $emailFrom , $message , $filedir , $mimetype , $filename , '' , '' , 0 , - 1 );
2017-06-11 10:37:58 +02:00
2016-12-27 08:14:05 +01:00
if ( $mailfile )
{
// SEND
$result = $mailfile -> sendfile ();
if ( $result )
{
$mesg = $langs -> trans ( 'MailSuccessfulySent' , $mailfile -> getValidAddress ( $emailFrom , 2 ), $mailfile -> getValidAddress ( $emailTo , 2 ));
setEventMessages ( $mesg , null , 'mesgs' );
header ( " Location: " . $_SERVER [ " PHP_SELF " ] . " ?id= " . $id );
exit ;
}
else
{
$langs -> load ( " other " );
if ( $mailfile -> error )
{
$mesg = '' ;
$mesg .= $langs -> trans ( 'ErrorFailedToSendMail' , $emailFrom , $emailTo );
$mesg .= '<br>' . $mailfile -> error ;
setEventMessages ( $mesg , null , 'errors' );
}
else
{
setEventMessages ( 'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS' , null , 'warnings' );
}
}
}
else
{
setEventMessages ( $mailfile -> error , $mailfile -> errors , 'errors' );
$action = '' ;
}
}
else
{
setEventMessages ( $langs -> trans ( " NoEmailSentBadSenderOrRecipientEmail " ), null , 'warnings' );
$action = '' ;
}
}
else
{
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
}
2017-06-11 10:37:58 +02:00
2016-09-06 13:39:44 +02:00
// Approve
2018-03-10 15:52:11 +01:00
if ( $action == " confirm_approve " && GETPOST ( " confirm " , 'alpha' ) == " yes " && $id > 0 && $user -> rights -> expensereport -> approve )
2016-09-06 13:39:44 +02:00
{
$object = new ExpenseReport ( $db );
$object -> fetch ( $id );
2017-06-11 10:37:58 +02:00
2016-09-06 13:39:44 +02:00
$result = $object -> setApproved ( $user );
2017-06-11 10:37:58 +02:00
2016-09-06 13:39:44 +02:00
if ( $result > 0 )
{
// Define output language
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE ))
{
$outputlangs = $langs ;
$newlang = '' ;
2017-06-27 17:27:01 +02:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) $newlang = GETPOST ( 'lang_id' , 'aZ09' );
2016-09-06 13:39:44 +02:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $object -> thirdparty -> default_lang ;
if ( ! empty ( $newlang )) {
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
$model = $object -> modelpdf ;
$ret = $object -> fetch ( $id ); // Reload to get new records
2017-06-11 10:37:58 +02:00
2016-09-06 13:39:44 +02:00
$object -> generateDocument ( $model , $outputlangs , $hidedetails , $hidedesc , $hideref );
}
}
2017-06-11 10:37:58 +02:00
2016-09-06 13:39:44 +02:00
if ( $result > 0 )
{
2016-12-27 08:14:05 +01:00
// Send mail
// TO
$destinataire = new User ( $db );
$destinataire -> fetch ( $object -> fk_user_author );
$emailTo = $destinataire -> email ;
// CC
$emailCC = $conf -> global -> NDF_CC_EMAILS ;
2017-05-02 11:28:40 +02:00
if ( empty ( $emailTo )) $emailTo = $emailCC ;
2016-12-27 08:14:05 +01:00
// FROM
$expediteur = new User ( $db );
2018-03-19 17:20:44 +01:00
$expediteur -> fetch ( $object -> fk_user_approve > 0 ? $object -> fk_user_approve : $object -> fk_user_validator );
2016-12-27 08:14:05 +01:00
$emailFrom = $expediteur -> email ;
2017-05-02 11:28:40 +02:00
if ( $emailFrom && $emailTo )
{
2016-12-27 08:14:05 +01:00
$filename = array (); $filedir = array (); $mimetype = array ();
2017-06-11 10:37:58 +02:00
2017-05-02 11:28:40 +02:00
// SUBJECT
2018-10-25 14:05:22 +02:00
$societeName = $conf -> global -> MAIN_INFO_SOCIETE_NOM ;
if ( ! empty ( $conf -> global -> MAIN_APPLICATION_TITLE )) $societeName = $conf -> global -> MAIN_APPLICATION_TITLE ;
$subject = $societeName . " - " . $langs -> transnoentities ( " ExpenseReportApproved " );
2017-06-11 10:37:58 +02:00
2017-05-02 11:28:40 +02:00
// CONTENT
$link = $urlwithroot . '/expensereport/card.php?id=' . $object -> id ;
$message = $langs -> transnoentities ( " ExpenseReportApprovedMessage " , $object -> ref , $destinataire -> getFullName ( $langs ), $expediteur -> getFullName ( $langs ), $link );
2017-06-11 10:37:58 +02:00
2017-05-02 11:28:40 +02:00
// Rebuilt pdf
/*
$object -> setDocModel ( $user , " " );
$resultPDF = expensereport_pdf_create ( $db , $object , '' , " " , $langs );
2017-06-11 10:37:58 +02:00
2017-05-02 11:28:40 +02:00
if ( $resultPDF
{
// ATTACHMENT
$filename = array (); $filedir = array (); $mimetype = array ();
array_push ( $filename , dol_sanitizeFileName ( $object -> ref ) . " .pdf " );
array_push ( $filedir , $conf -> expensereport -> dir_output . " / " . dol_sanitizeFileName ( $object -> ref ) . " / " . dol_sanitizeFileName ( $object -> ref ) . " .pdf " );
array_push ( $mimetype , " application/pdf " );
}
*/
2016-12-27 14:48:14 +01:00
2018-10-25 13:19:56 +02:00
$mailfile = new CMailFile ( $subject , $emailTo , $emailFrom , $message , $filedir , $mimetype , $filename , '' , '' , 0 , - 1 );
2017-06-11 10:37:58 +02:00
2017-05-02 11:28:40 +02:00
if ( $mailfile )
{
// SEND
$result = $mailfile -> sendfile ();
if ( $result )
{
$mesg = $langs -> trans ( 'MailSuccessfulySent' , $mailfile -> getValidAddress ( $emailFrom , 2 ), $mailfile -> getValidAddress ( $emailTo , 2 ));
setEventMessages ( $mesg , null , 'mesgs' );
header ( " Location: " . $_SERVER [ " PHP_SELF " ] . " ?id= " . $id );
exit ;
}
else
{
$langs -> load ( " other " );
if ( $mailfile -> error )
{
$mesg = '' ;
$mesg .= $langs -> trans ( 'ErrorFailedToSendMail' , $emailFrom , $emailTo );
$mesg .= '<br>' . $mailfile -> error ;
setEventMessages ( $mesg , null , 'errors' );
}
else
{
setEventMessages ( 'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS' , null , 'warnings' );
}
}
}
else
{
setEventMessages ( $mailfile -> error , $mailfile -> errors , 'errors' );
$action = '' ;
}
2016-12-27 14:48:14 +01:00
}
2017-05-02 11:28:40 +02:00
else
{
setEventMessages ( $langs -> trans ( " NoEmailSentBadSenderOrRecipientEmail " ), null , 'warnings' );
$action = '' ;
}
}
2016-12-27 14:48:14 +01:00
else
{
2017-05-02 11:28:40 +02:00
setEventMessages ( $langs -> trans ( " FailedtoSetToApprove " ), null , 'warnings' );
2016-12-27 14:48:14 +01:00
$action = '' ;
}
}
else
{
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2017-05-28 06:49:17 +02:00
2018-03-10 15:52:11 +01:00
if ( $action == " confirm_refuse " && GETPOST ( 'confirm' , 'alpha' ) == " yes " && $id > 0 && $user -> rights -> expensereport -> approve )
2016-09-06 13:39:44 +02:00
{
$object = new ExpenseReport ( $db );
$object -> fetch ( $id );
2017-05-28 06:49:17 +02:00
2018-03-10 15:52:11 +01:00
$result = $object -> setDeny ( $user , GETPOST ( 'detail_refuse' , 'alpha' ));
2017-05-28 06:49:17 +02:00
2016-09-06 13:39:44 +02:00
if ( $result > 0 )
{
// Define output language
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE ))
{
$outputlangs = $langs ;
$newlang = '' ;
2017-06-27 17:27:01 +02:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) $newlang = GETPOST ( 'lang_id' , 'aZ09' );
2016-09-06 13:39:44 +02:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $object -> thirdparty -> default_lang ;
if ( ! empty ( $newlang )) {
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
$model = $object -> modelpdf ;
$ret = $object -> fetch ( $id ); // Reload to get new records
2017-06-11 10:37:58 +02:00
2016-09-06 13:39:44 +02:00
$object -> generateDocument ( $model , $outputlangs , $hidedetails , $hidedesc , $hideref );
}
}
2017-05-28 06:49:17 +02:00
2016-09-06 13:39:44 +02:00
if ( $result > 0 )
{
2016-12-27 08:14:05 +01:00
// Send mail
2017-05-28 06:49:17 +02:00
2016-12-27 08:14:05 +01:00
// TO
$destinataire = new User ( $db );
$destinataire -> fetch ( $object -> fk_user_author );
$emailTo = $destinataire -> email ;
2017-06-11 10:37:58 +02:00
2016-12-27 08:14:05 +01:00
// FROM
$expediteur = new User ( $db );
$expediteur -> fetch ( $object -> fk_user_refuse );
$emailFrom = $expediteur -> email ;
2017-06-11 10:37:58 +02:00
2017-05-02 11:28:40 +02:00
if ( $emailFrom && $emailTo )
{
2016-12-27 14:48:14 +01:00
$filename = array (); $filedir = array (); $mimetype = array ();
2017-06-11 10:37:58 +02:00
2017-05-02 11:28:40 +02:00
// SUBJECT
2018-10-25 14:05:22 +02:00
$societeName = $conf -> global -> MAIN_INFO_SOCIETE_NOM ;
if ( ! empty ( $conf -> global -> MAIN_APPLICATION_TITLE )) $societeName = $conf -> global -> MAIN_APPLICATION_TITLE ;
$subject = $societeName . " - " . $langs -> transnoentities ( " ExpenseReportRefused " );
2017-06-11 10:37:58 +02:00
2017-05-02 11:28:40 +02:00
// CONTENT
$link = $urlwithroot . '/expensereport/card.php?id=' . $object -> id ;
$message = $langs -> transnoentities ( " ExpenseReportRefusedMessage " , $object -> ref , $destinataire -> getFullName ( $langs ), $expediteur -> getFullName ( $langs ), $_POST [ 'detail_refuse' ], $link );
2017-06-11 10:37:58 +02:00
2017-05-02 11:28:40 +02:00
// Rebuilt pdf
/*
$object -> setDocModel ( $user , " " );
$resultPDF = expensereport_pdf_create ( $db , $object , '' , " " , $langs );
2017-06-11 10:37:58 +02:00
2017-05-02 11:28:40 +02:00
if ( $resultPDF
2016-09-06 13:39:44 +02:00
{
2017-05-02 11:28:40 +02:00
// ATTACHMENT
$filename = array (); $filedir = array (); $mimetype = array ();
array_push ( $filename , dol_sanitizeFileName ( $object -> ref ) . " .pdf " );
array_push ( $filedir , $conf -> expensereport -> dir_output . " / " . dol_sanitizeFileName ( $object -> ref ) . " / " . dol_sanitizeFileName ( $object -> ref ) . " .pdf " );
array_push ( $mimetype , " application/pdf " );
2016-12-27 08:14:05 +01:00
}
2017-05-02 11:28:40 +02:00
*/
2017-05-28 06:49:17 +02:00
2017-05-02 11:28:40 +02:00
// PREPARE SEND
2018-10-25 13:19:56 +02:00
$mailfile = new CMailFile ( $subject , $emailTo , $emailFrom , $message , $filedir , $mimetype , $filename , '' , '' , 0 , - 1 );
2017-05-28 06:49:17 +02:00
2017-05-02 11:28:40 +02:00
if ( $mailfile )
{
// SEND
$result = $mailfile -> sendfile ();
if ( $result )
{
$mesg = $langs -> trans ( 'MailSuccessfulySent' , $mailfile -> getValidAddress ( $emailFrom , 2 ), $mailfile -> getValidAddress ( $emailTo , 2 ));
setEventMessages ( $mesg , null , 'mesgs' );
header ( " Location: " . $_SERVER [ " PHP_SELF " ] . " ?id= " . $id );
exit ;
}
else
{
$langs -> load ( " other " );
if ( $mailfile -> error )
{
$mesg = '' ;
$mesg .= $langs -> trans ( 'ErrorFailedToSendMail' , $emailFrom , $emailTo );
$mesg .= '<br>' . $mailfile -> error ;
setEventMessages ( $mesg , null , 'errors' );
}
else
{
setEventMessages ( 'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS' , null , 'warnings' );
}
}
}
else
{
setEventMessages ( $mailfile -> error , $mailfile -> errors , 'errors' );
$action = '' ;
}
}
else
{
setEventMessages ( $langs -> trans ( " NoEmailSentBadSenderOrRecipientEmail " ), null , 'warnings' );
$action = '' ;
}
2016-09-06 13:39:44 +02:00
}
else
{
2017-05-02 11:28:40 +02:00
setEventMessages ( $langs -> trans ( " FailedtoSetToDeny " ), null , 'warnings' );
$action = '' ;
2016-09-06 13:39:44 +02:00
}
}
2016-12-27 08:14:05 +01:00
else
{
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2017-05-28 06:49:17 +02:00
2016-09-06 13:39:44 +02:00
//var_dump($user->id == $object->fk_user_validator);exit;
2018-10-25 13:19:56 +02:00
if ( $action == " confirm_cancel " && GETPOST ( 'confirm' , 'alpha' ) == " yes " && $id > 0 && $user -> rights -> expensereport -> creer )
2016-09-06 13:39:44 +02:00
{
2018-10-25 13:19:56 +02:00
if ( ! GETPOST ( 'detail_cancel' , 'alpha' ))
2016-09-06 13:39:44 +02:00
{
2018-10-25 13:19:56 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Comment " )), null , 'errors' );
2016-09-06 13:39:44 +02:00
}
else
{
2018-10-25 13:19:56 +02:00
$object = new ExpenseReport ( $db );
$object -> fetch ( $id );
if ( $user -> id == $object -> fk_user_valid || $user -> id == $object -> fk_user_author )
{
$result = $object -> set_cancel ( $user , GETPOST ( 'detail_cancel' , 'alpha' ));
if ( $result > 0 )
{
// Define output language
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE ))
{
$outputlangs = $langs ;
$newlang = '' ;
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) $newlang = GETPOST ( 'lang_id' , 'aZ09' );
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $object -> thirdparty -> default_lang ;
if ( ! empty ( $newlang )) {
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
$model = $object -> modelpdf ;
$ret = $object -> fetch ( $id ); // Reload to get new records
$object -> generateDocument ( $model , $outputlangs , $hidedetails , $hidedesc , $hideref );
}
}
if ( $result > 0 )
{
// Send mail
// TO
$destinataire = new User ( $db );
$destinataire -> fetch ( $object -> fk_user_author );
$emailTo = $destinataire -> email ;
// FROM
$expediteur = new User ( $db );
$expediteur -> fetch ( $object -> fk_user_cancel );
$emailFrom = $expediteur -> email ;
if ( $emailFrom && $emailTo )
{
$filename = array (); $filedir = array (); $mimetype = array ();
// SUBJECT
2018-10-25 14:05:22 +02:00
$societeName = $conf -> global -> MAIN_INFO_SOCIETE_NOM ;
if ( ! empty ( $conf -> global -> MAIN_APPLICATION_TITLE )) $societeName = $conf -> global -> MAIN_APPLICATION_TITLE ;
$subject = $societeName . " - " . $langs -> transnoentities ( " ExpenseReportCanceled " );
2018-10-25 13:19:56 +02:00
// CONTENT
$link = $urlwithroot . '/expensereport/card.php?id=' . $object -> id ;
$message = $langs -> transnoentities ( " ExpenseReportCanceledMessage " , $object -> ref , $destinataire -> getFullName ( $langs ), $expediteur -> getFullName ( $langs ), GETPOST ( 'detail_cancel' , 'alpha' ), $link );
// Rebuilt pdf
/*
$object -> setDocModel ( $user , " " );
$resultPDF = expensereport_pdf_create ( $db , $object , '' , " " , $langs );
if ( $resultPDF
{
// ATTACHMENT
$filename = array (); $filedir = array (); $mimetype = array ();
array_push ( $filename , dol_sanitizeFileName ( $object -> ref ) . " .pdf " );
array_push ( $filedir , $conf -> expensereport -> dir_output . " / " . dol_sanitizeFileName ( $object -> ref ) . " / " . dol_sanitizeFileName ( $object -> ref ) . " .pdf " );
array_push ( $mimetype , " application/pdf " );
}
*/
// PREPARE SEND
$mailfile = new CMailFile ( $subject , $emailTo , $emailFrom , $message , $filedir , $mimetype , $filename , '' , '' , 0 , - 1 );
if ( $mailfile )
{
// SEND
$result = $mailfile -> sendfile ();
if ( $result )
{
$mesg = $langs -> trans ( 'MailSuccessfulySent' , $mailfile -> getValidAddress ( $emailFrom , 2 ), $mailfile -> getValidAddress ( $emailTo , 2 ));
setEventMessages ( $mesg , null , 'mesgs' );
header ( " Location: " . $_SERVER [ " PHP_SELF " ] . " ?id= " . $id );
exit ;
}
else
{
$langs -> load ( " other " );
if ( $mailfile -> error )
{
$mesg = '' ;
$mesg .= $langs -> trans ( 'ErrorFailedToSendMail' , $emailFrom , $emailTo );
$mesg .= '<br>' . $mailfile -> error ;
setEventMessages ( $mesg , null , 'errors' );
}
else
{
setEventMessages ( 'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS' , null , 'warnings' );
}
}
}
else
{
setEventMessages ( $mailfile -> error , $mailfile -> errors , 'errors' );
$action = '' ;
}
}
else
{
setEventMessages ( $langs -> trans ( " NoEmailSentBadSenderOrRecipientEmail " ), null , 'warnings' );
$action = '' ;
}
}
else
{
setEventMessages ( $langs -> trans ( " FailedToSetToCancel " ), null , 'warnings' );
$action = '' ;
}
}
else
{
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2016-09-06 13:39:44 +02:00
}
}
2017-05-28 06:49:17 +02:00
2018-03-10 15:52:11 +01:00
if ( $action == " confirm_brouillonner " && GETPOST ( 'confirm' , 'alpha' ) == " yes " && $id > 0 && $user -> rights -> expensereport -> creer )
2016-09-06 13:39:44 +02:00
{
$object = new ExpenseReport ( $db );
$object -> fetch ( $id );
if ( $user -> id == $object -> fk_user_author || $user -> id == $object -> fk_user_valid )
{
$result = $object -> setStatut ( 0 );
2017-05-28 06:49:17 +02:00
2016-09-06 13:39:44 +02:00
if ( $result > 0 )
{
// Define output language
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE ))
{
$outputlangs = $langs ;
$newlang = '' ;
2017-06-27 17:27:01 +02:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) $newlang = GETPOST ( 'lang_id' , 'aZ09' );
2016-09-06 13:39:44 +02:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $object -> thirdparty -> default_lang ;
if ( ! empty ( $newlang )) {
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
$model = $object -> modelpdf ;
$ret = $object -> fetch ( $id ); // Reload to get new records
2017-06-11 10:37:58 +02:00
2016-09-06 13:39:44 +02:00
$object -> generateDocument ( $model , $outputlangs , $hidedetails , $hidedesc , $hideref );
}
}
2017-05-28 06:49:17 +02:00
2016-09-06 13:39:44 +02:00
if ( $result > 0 )
{
header ( " Location: " . $_SERVER [ " PHP_SELF " ] . " ?id= " . $id );
exit ;
}
else
{
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
}
else
{
setEventMessages ( " NOT_AUTHOR " , '' , 'errors' );
}
}
2017-05-28 06:49:17 +02:00
2016-09-06 13:39:44 +02:00
if ( $action == 'set_paid' && $id > 0 && $user -> rights -> expensereport -> to_paid )
{
$object = new ExpenseReport ( $db );
$object -> fetch ( $id );
2017-05-28 06:49:17 +02:00
2016-09-06 13:39:44 +02:00
$result = $object -> set_paid ( $id , $user );
2017-05-28 06:49:17 +02:00
2016-09-06 13:39:44 +02:00
if ( $result > 0 )
{
// Define output language
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE ))
{
$outputlangs = $langs ;
$newlang = '' ;
2017-06-27 17:27:01 +02:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) $newlang = GETPOST ( 'lang_id' , 'aZ09' );
2016-09-06 13:39:44 +02:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $object -> thirdparty -> default_lang ;
if ( ! empty ( $newlang )) {
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
$model = $object -> modelpdf ;
$ret = $object -> fetch ( $id ); // Reload to get new records
2017-06-11 10:37:58 +02:00
2016-09-06 13:39:44 +02:00
$object -> generateDocument ( $model , $outputlangs , $hidedetails , $hidedesc , $hideref );
}
}
2017-05-28 06:49:17 +02:00
2016-09-06 13:39:44 +02:00
if ( $result > 0 )
{
2016-12-27 08:14:05 +01:00
// Send mail
2017-05-28 06:49:17 +02:00
2016-12-27 08:14:05 +01:00
// TO
$destinataire = new User ( $db );
$destinataire -> fetch ( $object -> fk_user_author );
$emailTo = $destinataire -> email ;
2017-05-28 06:49:17 +02:00
2016-12-27 08:14:05 +01:00
// FROM
$expediteur = new User ( $db );
$expediteur -> fetch ( $user -> id );
$emailFrom = $expediteur -> email ;
2017-05-28 06:49:17 +02:00
2017-05-02 11:28:40 +02:00
if ( $emailFrom && $emailTo )
2016-12-27 08:14:05 +01:00
{
2017-05-02 11:28:40 +02:00
$filename = array (); $filedir = array (); $mimetype = array ();
2017-06-11 10:37:58 +02:00
2017-05-02 11:28:40 +02:00
// SUBJECT
2018-10-25 14:05:22 +02:00
$societeName = $conf -> global -> MAIN_INFO_SOCIETE_NOM ;
if ( ! empty ( $conf -> global -> MAIN_APPLICATION_TITLE )) $societeName = $conf -> global -> MAIN_APPLICATION_TITLE ;
$subject = $societeName . " - " . $langs -> transnoentities ( " ExpenseReportPaid " );
2017-05-28 06:49:17 +02:00
2017-05-02 11:28:40 +02:00
// CONTENT
$link = $urlwithroot . '/expensereport/card.php?id=' . $object -> id ;
$message = $langs -> transnoentities ( " ExpenseReportPaidMessage " , $object -> ref , $destinataire -> getFullName ( $langs ), $expediteur -> getFullName ( $langs ), $link );
2017-05-28 06:49:17 +02:00
2017-05-02 11:28:40 +02:00
// Generate pdf before attachment
$object -> setDocModel ( $user , " " );
$resultPDF = expensereport_pdf_create ( $db , $object , '' , " " , $langs );
2017-05-28 06:49:17 +02:00
2017-05-02 11:28:40 +02:00
// PREPARE SEND
2018-10-25 13:19:56 +02:00
$mailfile = new CMailFile ( $subject , $emailTo , $emailFrom , $message , $filedir , $mimetype , $filename , '' , '' , 0 , - 1 );
2017-05-28 06:49:17 +02:00
2017-05-02 11:28:40 +02:00
if ( $mailfile )
{
// SEND
$result = $mailfile -> sendfile ();
if ( $result )
{
$mesg = $langs -> trans ( 'MailSuccessfulySent' , $mailfile -> getValidAddress ( $emailFrom , 2 ), $mailfile -> getValidAddress ( $emailTo , 2 ));
setEventMessages ( $mesg , null , 'mesgs' );
header ( " Location: " . $_SERVER [ " PHP_SELF " ] . " ?id= " . $id );
exit ;
}
else
{
$langs -> load ( " other " );
if ( $mailfile -> error )
{
$mesg = '' ;
$mesg .= $langs -> trans ( 'ErrorFailedToSendMail' , $emailFrom , $emailTo );
$mesg .= '<br>' . $mailfile -> error ;
setEventMessages ( $mesg , null , 'errors' );
}
else
{
setEventMessages ( 'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS' , null , 'warnings' );
}
}
}
else
{
setEventMessages ( $mailfile -> error , $mailfile -> errors , 'errors' );
$action = '' ;
}
2016-12-27 08:14:05 +01:00
}
else
{
2017-05-02 11:28:40 +02:00
setEventMessages ( $langs -> trans ( " NoEmailSentBadSenderOrRecipientEmail " ), null , 'warnings' );
$action = '' ;
2016-09-06 13:39:44 +02:00
}
}
else
{
2017-05-02 11:28:40 +02:00
setEventMessages ( $langs -> trans ( " FailedToSetPaid " ), null , 'warnings' );
2016-12-27 08:14:05 +01:00
$action = '' ;
2016-09-06 13:39:44 +02:00
}
}
2016-12-27 08:14:05 +01:00
else
{
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2016-09-06 13:39:44 +02:00
if ( $action == " addline " && $user -> rights -> expensereport -> creer )
{
$error = 0 ;
2017-05-28 06:49:17 +02:00
2017-06-15 11:08:53 +02:00
// if VAT is not used in Dolibarr, set VAT rate to 0 because VAT rate is necessary.
if ( empty ( $vatrate )) $vatrate = " 0.000 " ;
$vatrate = price2num ( $vatrate );
2017-05-28 06:49:17 +02:00
2018-03-10 15:52:11 +01:00
$value_unit = price2num ( GETPOST ( 'value_unit' , 'alpha' ), 'MU' );
$fk_c_exp_tax_cat = GETPOST ( 'fk_c_exp_tax_cat' , 'int' );
2017-07-08 17:57:35 +02:00
2018-03-10 15:52:11 +01:00
$qty = GETPOST ( 'qty' , 'int' );
2016-09-06 13:39:44 +02:00
if ( empty ( $qty )) $qty = 1 ;
2017-05-28 06:49:17 +02:00
2017-06-15 11:08:53 +02:00
if ( ! $fk_c_type_fees > 0 )
2016-09-06 13:39:44 +02:00
{
$error ++ ;
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Type " )), null , 'errors' );
$action = '' ;
}
2017-05-28 06:49:17 +02:00
2016-09-06 13:39:44 +02:00
if ( $vatrate < 0 || $vatrate == '' )
{
$error ++ ;
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " VAT " )), null , 'errors' );
$action = '' ;
}
2017-05-28 06:49:17 +02:00
2016-09-06 13:39:44 +02:00
/* Projects are never required . To force them , check module forceproject
if ( $conf -> projet -> enabled )
{
if ( empty ( $object_ligne -> fk_projet ) || $object_ligne -> fk_projet ==- 1 )
{
$error ++ ;
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Project " )), null , 'errors' );
}
} */
2017-05-28 06:49:17 +02:00
2016-09-06 13:39:44 +02:00
// Si aucune date n'est rentrée
2017-06-15 11:08:53 +02:00
if ( empty ( $date ) || $date == " -- " )
2016-09-06 13:39:44 +02:00
{
$error ++ ;
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Date " )), null , 'errors' );
}
// Si aucun prix n'est rentré
2018-03-10 15:52:11 +01:00
if ( $value_unit == 0 )
2016-09-06 13:39:44 +02:00
{
$error ++ ;
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " PriceUTTC " )), null , 'errors' );
}
2018-03-26 14:13:18 +02:00
// Warning if date out of range
if ( $date < $object -> date_debut || $date > ( $object -> date_fin + ( 24 * 3600 - 1 )))
{
$langs -> load ( " errors " );
setEventMessages ( $langs -> trans ( " WarningDateOfLineMustBeInExpenseReportRange " ), null , 'warnings' );
}
2017-05-28 06:49:17 +02:00
2016-09-06 13:39:44 +02:00
// S'il y'a eu au moins une erreur
if ( ! $error )
{
2018-03-26 14:13:18 +02:00
$type = 0 ; // TODO What if service ? We should take the type product/service from the type of expense report llx_c_type_fees
2017-05-28 06:49:17 +02:00
2017-06-15 11:08:53 +02:00
// Insert line
$result = $object -> addline ( $qty , $value_unit , $fk_c_type_fees , $vatrate , $date , $comments , $fk_projet , $fk_c_exp_tax_cat , $type );
if ( $result > 0 ) {
$ret = $object -> fetch ( $object -> id ); // Reload to get new records
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE )) {
// Define output language
$outputlangs = $langs ;
$newlang = GETPOST ( 'lang_id' , 'alpha' );
if ( ! empty ( $conf -> global -> MAIN_MULTILANGS ) && empty ( $newlang ))
$newlang = $object -> thirdparty -> default_lang ;
if ( ! empty ( $newlang )) {
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
2017-05-28 06:49:17 +02:00
2017-06-15 11:08:53 +02:00
$object -> generateDocument ( $object -> modelpdf , $outputlangs , $hidedetails , $hidedesc , $hideref );
}
unset ( $qty );
unset ( $value_unit );
unset ( $vatrate );
unset ( $comments );
unset ( $fk_c_type_fees );
unset ( $fk_projet );
unset ( $date );
} else {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2016-09-06 13:39:44 +02:00
}
2017-05-28 06:49:17 +02:00
2016-09-06 13:39:44 +02:00
$action = '' ;
}
2017-05-28 06:49:17 +02:00
2018-03-10 15:52:11 +01:00
if ( $action == 'confirm_delete_line' && GETPOST ( " confirm " , 'alpha' ) == " yes " && $user -> rights -> expensereport -> creer )
2016-09-06 13:39:44 +02:00
{
$object = new ExpenseReport ( $db );
$object -> fetch ( $id );
2017-06-11 10:37:58 +02:00
2016-09-06 13:39:44 +02:00
$object_ligne = new ExpenseReportLine ( $db );
2018-03-10 15:52:11 +01:00
$object_ligne -> fetch ( GETPOST ( " rowid " , 'int' ));
2016-09-06 13:39:44 +02:00
$total_ht = $object_ligne -> total_ht ;
$total_tva = $object_ligne -> total_tva ;
2017-05-28 06:49:17 +02:00
2018-03-10 15:52:11 +01:00
$result = $object -> deleteline ( GETPOST ( " rowid " , 'int' ), $user );
2016-09-06 13:39:44 +02:00
if ( $result >= 0 )
{
if ( $result > 0 )
{
// Define output language
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE ))
{
$outputlangs = $langs ;
$newlang = '' ;
2017-06-27 17:27:01 +02:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) $newlang = GETPOST ( 'lang_id' , 'aZ09' );
2016-09-06 13:39:44 +02:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $object -> thirdparty -> default_lang ;
if ( ! empty ( $newlang )) {
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
$model = $object -> modelpdf ;
$ret = $object -> fetch ( $id ); // Reload to get new records
2017-06-11 10:37:58 +02:00
2016-09-06 13:39:44 +02:00
$object -> generateDocument ( $model , $outputlangs , $hidedetails , $hidedesc , $hideref );
}
}
2017-06-11 10:37:58 +02:00
2016-09-06 13:39:44 +02:00
$object -> update_totaux_del ( $object_ligne -> total_ht , $object_ligne -> total_tva );
header ( " Location: " . $_SERVER [ " PHP_SELF " ] . " ?id= " . $_GET [ 'id' ]);
exit ;
}
else
{
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
}
2017-05-28 06:49:17 +02:00
2018-09-28 16:15:17 +02:00
if ( $action == " updateline " && $user -> rights -> expensereport -> creer )
2016-09-06 13:39:44 +02:00
{
$object = new ExpenseReport ( $db );
$object -> fetch ( $id );
2017-05-28 06:49:17 +02:00
2016-09-06 13:39:44 +02:00
$rowid = $_POST [ 'rowid' ];
2018-03-10 15:52:11 +01:00
$type_fees_id = GETPOST ( 'fk_c_type_fees' , 'int' );
$fk_c_exp_tax_cat = GETPOST ( 'fk_c_exp_tax_cat' , 'int' );
2016-09-06 13:39:44 +02:00
$projet_id = $fk_projet ;
2018-03-10 15:52:11 +01:00
$comments = GETPOST ( 'comments' , 'none' );
$qty = GETPOST ( 'qty' , 'int' );
$value_unit = price2num ( GETPOST ( 'value_unit' , 'alpha' ), 'MU' );
$vatrate = GETPOST ( 'vatrate' , 'alpha' );
2017-02-24 12:07:32 +01:00
// if VAT is not used in Dolibarr, set VAT rate to 0 because VAT rate is necessary.
if ( empty ( $vatrate )) $vatrate = " 0.000 " ;
$vatrate = price2num ( $vatrate );
2017-05-28 06:49:17 +02:00
2018-03-10 15:52:11 +01:00
if ( ! GETPOST ( 'fk_c_type_fees' , 'int' ) > 0 )
2016-09-06 13:39:44 +02:00
{
$error ++ ;
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Type " )), null , 'errors' );
$action = '' ;
}
2017-02-24 12:31:14 +01:00
if (( int ) $vatrate < 0 || $vatrate == '' )
2016-09-06 13:39:44 +02:00
{
$error ++ ;
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Vat " )), null , 'errors' );
$action = '' ;
}
2018-03-26 14:13:18 +02:00
// Warning if date out of range
if ( $date < $object -> date_debut || $date > ( $object -> date_fin + ( 24 * 3600 - 1 )))
{
$langs -> load ( " errors " );
setEventMessages ( $langs -> trans ( " WarningDateOfLineMustBeInExpenseReportRange " ), null , 'warnings' );
}
2017-05-28 06:49:17 +02:00
2016-09-06 13:39:44 +02:00
if ( ! $error )
{
// TODO Use update method of ExpenseReportLine
2017-06-15 11:08:53 +02:00
$result = $object -> updateline ( $rowid , $type_fees_id , $projet_id , $vatrate , $comments , $qty , $value_unit , $date , $id , $fk_c_exp_tax_cat );
2016-09-06 13:39:44 +02:00
if ( $result >= 0 )
{
if ( $result > 0 )
{
// Define output language
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE ))
{
$outputlangs = $langs ;
$newlang = '' ;
2017-06-27 17:27:01 +02:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && GETPOST ( 'lang_id' , 'aZ09' )) $newlang = GETPOST ( 'lang_id' , 'aZ09' );
2016-09-06 13:39:44 +02:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $object -> thirdparty -> default_lang ;
if ( ! empty ( $newlang )) {
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
$model = $object -> modelpdf ;
$ret = $object -> fetch ( $id ); // Reload to get new records
2017-06-11 10:37:58 +02:00
2016-09-06 13:39:44 +02:00
$object -> generateDocument ( $model , $outputlangs , $hidedetails , $hidedesc , $hideref );
}
}
2017-06-11 10:37:58 +02:00
2016-09-06 13:39:44 +02:00
$result = $object -> recalculer ( $id );
2017-06-11 10:37:58 +02:00
2018-03-26 14:13:18 +02:00
//header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
//exit;
2016-09-06 13:39:44 +02:00
}
else
{
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
}
}
2017-05-28 06:49:17 +02:00
2017-09-17 15:38:50 +02:00
// Actions when printing a doc from card
include DOL_DOCUMENT_ROOT . '/core/actions_printing.inc.php' ;
// Actions to send emails
$trigger_name = 'EXPENSEREPORT_SENTBYMAIL' ;
$autocopy = 'MAIN_MAIL_AUTOCOPY_EXPENSEREPORT_TO' ;
$trackid = 'exp' . $object -> id ;
include DOL_DOCUMENT_ROOT . '/core/actions_sendmails.inc.php' ;
2017-03-21 17:50:52 +01:00
// Actions to build doc
$upload_dir = $conf -> expensereport -> dir_output ;
$permissioncreate = $user -> rights -> expensereport -> creer ;
include DOL_DOCUMENT_ROOT . '/core/actions_builddoc.inc.php' ;
2015-02-14 18:39:45 +01:00
}
/*
* View
*/
2016-09-06 13:39:44 +02:00
2016-08-30 07:02:44 +02:00
$title = $langs -> trans ( " ExpenseReport " ) . " - " . $langs -> trans ( " Card " );
$helpurl = " EN:Module_Expense_Reports " ;
llxHeader ( " " , $title , $helpurl );
2015-02-14 18:39:45 +01:00
$form = new Form ( $db );
2015-02-15 22:49:23 +01:00
$formfile = new FormFile ( $db );
2015-02-14 18:39:45 +01:00
$formproject = new FormProjets ( $db );
2015-02-15 22:49:23 +01:00
$projecttmp = new Project ( $db );
2017-05-28 06:49:17 +02:00
$paymentexpensereportstatic = new PaymentExpenseReport ( $db );
$bankaccountstatic = new Account ( $db );
2015-02-14 18:39:45 +01:00
2015-02-21 12:57:17 +01:00
// Create
2015-02-14 18:39:45 +01:00
if ( $action == 'create' )
{
2015-10-03 00:35:26 +02:00
print load_fiche_titre ( $langs -> trans ( " NewTrip " ));
2015-02-14 18:39:45 +01:00
print '<form action="' . $_SERVER [ 'PHP_SELF' ] . '" method="post" name="create">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<input type="hidden" name="action" value="add">' ;
dol_fiche_head ( '' );
print '<table class="border" width="100%">' ;
print '<tbody>' ;
2017-06-11 10:37:58 +02:00
2016-11-13 22:00:57 +01:00
// Date start
2015-02-14 18:39:45 +01:00
print '<tr>' ;
2016-08-02 07:47:15 +02:00
print '<td class="titlefieldcreate fieldrequired">' . $langs -> trans ( " DateStart " ) . '</td>' ;
2015-02-14 18:39:45 +01:00
print '<td>' ;
2018-09-09 08:02:26 +02:00
print $form -> selectDate ( $date_start ? $date_start :- 1 , 'date_debut' , 0 , 0 , 0 , '' , 1 , 1 );
2015-02-14 18:39:45 +01:00
print '</td>' ;
print '</tr>' ;
2017-06-11 10:37:58 +02:00
2016-11-13 22:00:57 +01:00
// Date end
2015-02-14 18:39:45 +01:00
print '<tr>' ;
2015-10-17 02:03:59 +02:00
print '<td class="fieldrequired">' . $langs -> trans ( " DateEnd " ) . '</td>' ;
2015-02-14 18:39:45 +01:00
print '<td>' ;
2018-09-09 08:02:26 +02:00
print $form -> selectDate ( $date_end ? $date_end :- 1 , 'date_fin' , 0 , 0 , 0 , '' , 1 , 1 );
2015-02-14 18:39:45 +01:00
print '</td>' ;
print '</tr>' ;
2017-06-11 10:37:58 +02:00
2018-05-10 18:56:21 +02:00
// User for expense report
2016-11-13 22:00:57 +01:00
print '<tr>' ;
print '<td class="fieldrequired">' . $langs -> trans ( " User " ) . '</td>' ;
print '<td>' ;
$defaultselectuser = $user -> id ;
2018-03-10 15:52:11 +01:00
if ( GETPOST ( 'fk_user_author' , 'int' ) > 0 ) $defaultselectuser = GETPOST ( 'fk_user_author' , 'int' );
2017-03-21 17:56:11 +01:00
$include_users = 'hierarchyme' ;
if ( ! empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && ! empty ( $user -> rights -> expensereport -> writeall_advance )) $include_users = array ();
2018-06-25 10:09:01 +02:00
$s = $form -> select_dolusers ( $defaultselectuser , " fk_user_author " , 0 , " " , 0 , $include_users , '' , '0,' . $conf -> entity );
2016-11-13 22:00:57 +01:00
print $s ;
print '</td>' ;
print '</tr>' ;
2017-05-28 06:49:17 +02:00
2018-05-10 18:56:21 +02:00
// Approver
2015-02-14 18:39:45 +01:00
print '<tr>' ;
print '<td>' . $langs -> trans ( " VALIDATOR " ) . '</td>' ;
print '<td>' ;
$object = new ExpenseReport ( $db );
$include_users = $object -> fetch_users_approver_expensereport ();
2016-12-03 18:13:23 +01:00
if ( empty ( $include_users )) print img_warning () . ' ' . $langs -> trans ( " NobodyHasPermissionToValidateExpenseReport " );
else
{
$defaultselectuser = $user -> fk_user ; // Will work only if supervisor has permission to approve so is inside include_users
if ( ! empty ( $conf -> global -> EXPENSEREPORT_DEFAULT_VALIDATOR )) $defaultselectuser = $conf -> global -> EXPENSEREPORT_DEFAULT_VALIDATOR ; // Can force default approver
2018-03-10 15:52:11 +01:00
if ( GETPOST ( 'fk_user_validator' , 'int' ) > 0 ) $defaultselectuser = GETPOST ( 'fk_user_validator' , 'int' );
2018-10-31 16:05:50 +01:00
$s = $form -> select_dolusers ( $defaultselectuser , " fk_user_validator " , 1 , " " , (( empty ( $defaultselectuser ) || empty ( $conf -> global -> EXPENSEREPORT_DEFAULT_VALIDATOR_UNCHANGEABLE )) ? 0 : 1 ), $include_users );
2016-12-03 18:13:23 +01:00
print $form -> textwithpicto ( $s , $langs -> trans ( " AnyOtherInThisListCanValidate " ));
}
2015-02-14 18:39:45 +01:00
print '</td>' ;
print '</tr>' ;
2017-06-11 10:37:58 +02:00
2016-11-13 22:00:57 +01:00
// Payment mode
2015-02-14 18:39:45 +01:00
if ( ! empty ( $conf -> global -> EXPENSEREPORT_ASK_PAYMENTMODE_ON_CREATION ))
{
print '<tr>' ;
print '<td>' . $langs -> trans ( " ModePaiement " ) . '</td>' ;
print '<td>' ;
2015-02-15 22:49:23 +01:00
$form -> select_types_paiements ( 2 , 'fk_c_paiement' );
2015-02-14 18:39:45 +01:00
print '</td>' ;
print '</tr>' ;
}
2015-03-17 11:23:45 +01:00
2015-02-23 21:44:33 +01:00
// Public note
2015-02-14 18:39:45 +01:00
print '<tr>' ;
2017-03-21 17:50:52 +01:00
print '<td class="tdtop">' . $langs -> trans ( 'NotePublic' ) . '</td>' ;
print '<td>' ;
2015-02-23 21:44:33 +01:00
2016-01-02 20:48:19 +01:00
$doleditor = new DolEditor ( 'note_public' , $note_public , '' , 80 , 'dolibarr_notes' , 'In' , 0 , false , true , ROWS_3 , '90%' );
2015-02-23 21:44:33 +01:00
print $doleditor -> Create ( 1 );
print '</td></tr>' ;
// Private note
if ( empty ( $user -> societe_id )) {
print '<tr>' ;
2017-03-21 17:50:52 +01:00
print '<td class="tdtop">' . $langs -> trans ( 'NotePrivate' ) . '</td>' ;
print '<td>' ;
2015-02-23 21:44:33 +01:00
2016-01-02 20:48:19 +01:00
$doleditor = new DolEditor ( 'note_private' , $note_private , '' , 80 , 'dolibarr_notes' , 'In' , 0 , false , true , ROWS_3 , '90%' );
2015-02-23 21:44:33 +01:00
print $doleditor -> Create ( 1 );
print '</td></tr>' ;
}
2015-03-17 11:23:45 +01:00
2016-09-06 13:39:44 +02:00
// Other attributes
$parameters = array ( 'colspan' => ' colspan="3"' );
$reshook = $hookmanager -> executeHooks ( 'formObjectOptions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by
2017-06-11 10:37:58 +02:00
print $hookmanager -> resPrint ;
2018-04-13 13:28:48 +02:00
if ( empty ( $reshook )) {
2016-09-06 13:39:44 +02:00
print $object -> showOptionals ( $extrafields , 'edit' );
}
2017-05-28 06:49:17 +02:00
2015-02-14 18:39:45 +01:00
print '<tbody>' ;
print '</table>' ;
dol_fiche_end ();
2016-08-30 07:02:44 +02:00
print '<div class="center">' ;
2015-02-14 18:39:45 +01:00
print '<input type="submit" value="' . $langs -> trans ( " AddTrip " ) . '" name="bouton" class="button" />' ;
2015-02-23 21:44:33 +01:00
print ' <input type="button" value="' . $langs -> trans ( " Cancel " ) . '" class="button" onclick="history.go(-1)" />' ;
print '</div>' ;
2015-02-14 18:39:45 +01:00
print '</form>' ;
}
else
{
2015-06-08 13:49:09 +02:00
if ( $id > 0 || $ref )
2015-02-14 18:39:45 +01:00
{
2015-06-08 13:49:09 +02:00
$result = $object -> fetch ( $id , $ref );
2015-02-14 18:39:45 +01:00
2018-02-21 14:48:25 +01:00
$res = $object -> fetch_optionals ();
2017-06-11 10:37:58 +02:00
2015-02-15 22:49:23 +01:00
if ( $result > 0 )
2015-02-14 18:39:45 +01:00
{
2017-01-26 18:08:00 +01:00
if ( ! in_array ( $object -> fk_user_author , $user -> getAllChildIds ( 1 )))
2015-02-14 18:39:45 +01:00
{
2016-11-13 22:00:57 +01:00
if ( empty ( $user -> rights -> expensereport -> readall ) && empty ( $user -> rights -> expensereport -> lire_tous )
2017-01-26 18:08:00 +01:00
&& ( empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) || empty ( $user -> rights -> expensereport -> writeall_advance )))
2015-02-14 18:39:45 +01:00
{
2015-09-24 18:33:48 +02:00
print load_fiche_titre ( $langs -> trans ( 'TripCard' ));
2015-02-14 18:39:45 +01:00
print '<div class="tabBar">' ;
print $langs -> trans ( 'NotUserRightToView' );
print '</div>' ;
2018-08-02 14:03:50 +02:00
// End of page
llxFooter ();
$db -> close ();
2015-02-14 18:39:45 +01:00
exit ;
}
}
2015-02-15 22:49:23 +01:00
$head = expensereport_prepare_head ( $object );
2015-02-14 18:39:45 +01:00
2015-03-08 07:21:07 +01:00
if ( $action == 'edit' && ( $object -> fk_statut < 3 || $object -> fk_statut == 99 ))
2015-02-14 18:39:45 +01:00
{
print " <form name='update' action= \" " . $_SERVER [ 'PHP_SELF' ] . " \" method= \" post \" > \n " ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
2015-02-15 22:49:23 +01:00
print '<input type="hidden" name="id" value="' . $id . '">' ;
2016-08-30 07:02:44 +02:00
dol_fiche_head ( $head , 'card' , $langs -> trans ( " ExpenseReport " ), 0 , 'trip' );
2015-02-14 18:39:45 +01:00
2015-03-08 07:21:07 +01:00
if ( $object -> fk_statut == 99 )
2015-02-14 18:39:45 +01:00
{
print '<input type="hidden" name="action" value="updateFromRefuse">' ;
}
else
{
print '<input type="hidden" name="action" value="update">' ;
}
2017-10-03 16:00:52 +02:00
$linkback = '<a href="' . DOL_URL_ROOT . '/expensereport/list.php?restore_lastsearch_values=1' . ( ! empty ( $socid ) ? '&socid=' . $socid : '' ) . '">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2015-02-14 18:39:45 +01:00
2016-12-13 23:59:26 +01:00
print '<table class="border" style="width:100%;">' ;
2016-11-13 22:00:57 +01:00
print '<tr>' ;
print '<td>' . $langs -> trans ( " User " ) . '</td>' ;
print '<td>' ;
$userfee = new User ( $db );
2017-05-29 13:19:45 +02:00
if ( $object -> fk_user_author > 0 )
{
$userfee -> fetch ( $object -> fk_user_author );
print $userfee -> getNomUrl ( - 1 );
}
2016-11-13 22:00:57 +01:00
print '</td></tr>' ;
2017-05-28 06:49:17 +02:00
2015-02-14 18:39:45 +01:00
// Ref
2016-08-30 07:02:44 +02:00
print '<tr><td class="titlefieldcreate">' . $langs -> trans ( " Ref " ) . '</td><td>' ;
2016-03-25 15:53:44 +01:00
print $form -> showrefnav ( $object , 'ref' , $linkback , 1 , 'ref' , 'ref' , '' );
2015-02-14 18:39:45 +01:00
print '</td></tr>' ;
print '<tr>' ;
print '<td>' . $langs -> trans ( " DateStart " ) . '</td>' ;
print '<td>' ;
2018-09-09 08:02:26 +02:00
print $form -> selectDate ( $object -> date_debut , 'date_debut' );
2015-02-14 18:39:45 +01:00
print '</td>' ;
print '</tr>' ;
print '<tr>' ;
print '<td>' . $langs -> trans ( " DateEnd " ) . '</td>' ;
print '<td>' ;
2018-09-09 08:02:26 +02:00
print $form -> selectDate ( $object -> date_fin , 'date_fin' );
2015-02-14 18:39:45 +01:00
print '</td>' ;
print '</tr>' ;
if ( ! empty ( $conf -> global -> EXPENSEREPORT_ASK_PAYMENTMODE_ON_CREATION ))
{
print '<tr>' ;
print '<td>' . $langs -> trans ( " ModePaiement " ) . '</td>' ;
print '<td>' ;
2015-02-15 22:49:23 +01:00
$form -> select_types_paiements ( $object -> fk_c_paiement , 'fk_c_paiement' );
2015-02-14 18:39:45 +01:00
print '</td>' ;
print '</tr>' ;
}
2015-03-08 07:21:07 +01:00
if ( $object -> fk_statut < 3 )
2015-02-14 18:39:45 +01:00
{
print '<tr>' ;
2015-02-21 12:57:17 +01:00
print '<td>' . $langs -> trans ( " VALIDATOR " ) . '</td>' ; // Approbator
2015-02-14 18:39:45 +01:00
print '<td>' ;
$include_users = $object -> fetch_users_approver_expensereport ();
2015-02-21 12:57:17 +01:00
$s = $form -> select_dolusers ( $object -> fk_user_validator , " fk_user_validator " , 1 , " " , 0 , $include_users );
2016-03-25 15:24:57 +01:00
print $form -> textwithpicto ( $s , $langs -> trans ( " AnyOtherInThisListCanValidate " ));
2015-02-14 18:39:45 +01:00
print '</td>' ;
print '</tr>' ;
}
else
{
print '<tr>' ;
print '<td>' . $langs -> trans ( " VALIDOR " ) . '</td>' ;
print '<td>' ;
$userfee = new User ( $db );
$userfee -> fetch ( $object -> fk_user_valid );
2016-09-01 11:29:30 +02:00
print $userfee -> getNomUrl ( - 1 );
2015-02-14 18:39:45 +01:00
print '</td></tr>' ;
}
2015-03-08 07:21:07 +01:00
if ( $object -> fk_statut == 6 )
2015-02-14 18:39:45 +01:00
{
print '<tr>' ;
print '<td>' . $langs -> trans ( " AUTHORPAIEMENT " ) . '</td>' ;
print '<td>' ;
$userfee = new User ( $db );
2015-06-23 06:39:55 +02:00
$userfee -> fetch ( $user -> id );
2016-09-01 11:29:30 +02:00
print $userfee -> getNomUrl ( - 1 );
2015-02-14 18:39:45 +01:00
print '</td></tr>' ;
}
2015-03-17 11:23:45 +01:00
2016-09-06 13:39:44 +02:00
// Other attributes
//$cols = 3;
//include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_edit.tpl.php';
2015-03-17 11:23:45 +01:00
2015-02-14 18:39:45 +01:00
print '</table>' ;
2015-02-15 22:49:23 +01:00
dol_fiche_end ();
print '<div class="center">' ;
2015-02-23 21:44:33 +01:00
print '<input type="submit" value="' . $langs -> trans ( " Modify " ) . '" name="bouton" class="button">' ;
print ' <input type="button" value="' . $langs -> trans ( " Cancel " ) . '" class="button" onclick="history.go(-1)" />' ;
2015-02-14 18:39:45 +01:00
print '</div>' ;
print '</form>' ;
}
else
{
2017-03-21 17:56:11 +01:00
dol_fiche_head ( $head , 'card' , $langs -> trans ( " ExpenseReport " ), - 1 , 'trip' );
2015-02-14 18:39:45 +01:00
2016-11-13 22:00:57 +01:00
// Clone confirmation
if ( $action == 'clone' ) {
// Create an array for form
2017-05-29 13:19:45 +02:00
$criteriaforfilter = 'hierarchyme' ;
if ( ! empty ( $user -> rights -> expensereport -> readall )) $criteriaforfilter = '' ;
2016-11-13 22:00:57 +01:00
$formquestion = array (
2017-05-29 13:19:45 +02:00
'text' => '' ,
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 ))
2016-11-13 22:00:57 +01:00
);
// Paiement incomplet. On demande si motif = escompte ou autre
$formconfirm = $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id , $langs -> trans ( 'CloneExpenseReport' ), $langs -> trans ( 'ConfirmCloneExpenseReport' , $object -> ref ), 'confirm_clone' , $formquestion , 'yes' , 1 );
}
2017-05-28 06:49:17 +02:00
2015-08-28 20:11:16 +02:00
if ( $action == 'save' )
{
2018-10-22 21:57:18 +02:00
$formconfirm = $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . " ?id= " . $id , $langs -> trans ( " SaveTrip " ), $langs -> trans ( " ConfirmSaveTrip " ), " confirm_validate " , " " , " " , 1 );
2015-08-28 20:11:16 +02:00
}
2015-02-14 18:39:45 +01:00
2015-08-28 20:11:16 +02:00
if ( $action == 'save_from_refuse' )
{
2018-10-22 21:57:18 +02:00
$formconfirm = $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . " ?id= " . $id , $langs -> trans ( " SaveTrip " ), $langs -> trans ( " ConfirmSaveTrip " ), " confirm_save_from_refuse " , " " , " " , 1 );
2015-08-28 20:11:16 +02:00
}
2015-02-14 18:39:45 +01:00
2015-08-28 20:11:16 +02:00
if ( $action == 'delete' )
{
2018-10-22 21:57:18 +02:00
$formconfirm = $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . " ?id= " . $id , $langs -> trans ( " DeleteTrip " ), $langs -> trans ( " ConfirmDeleteTrip " ), " confirm_delete " , " " , " " , 1 );
2015-08-28 20:11:16 +02:00
}
2015-02-14 18:39:45 +01:00
2015-08-28 20:11:16 +02:00
if ( $action == 'validate' )
{
2018-10-22 21:57:18 +02:00
$formconfirm = $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . " ?id= " . $id , $langs -> trans ( " ValideTrip " ), $langs -> trans ( " ConfirmValideTrip " ), " confirm_approve " , " " , " " , 1 );
2015-08-28 20:11:16 +02:00
}
2015-02-14 18:39:45 +01:00
2015-08-28 20:11:16 +02:00
if ( $action == 'paid' )
{
2018-10-22 21:57:18 +02:00
$formconfirm = $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . " ?id= " . $id , $langs -> trans ( " PaidTrip " ), $langs -> trans ( " ConfirmPaidTrip " ), " confirm_paid " , " " , " " , 1 );
2015-08-28 20:11:16 +02:00
}
2015-02-14 18:39:45 +01:00
2015-02-21 15:18:05 +01:00
if ( $action == 'cancel' )
{
2018-10-25 13:19:56 +02:00
$array_input = array ( 'text' => $langs -> trans ( " ConfirmCancelTrip " ), array ( 'type' => " text " , 'label' => '<strong>' . $langs -> trans ( " Comment " ) . '</strong>' , 'name' => " detail_cancel " , 'size' => " 50 " , 'value' => " " ));
2018-10-22 21:57:18 +02:00
$formconfirm = $form -> formconfirm ( $_SEVER [ " PHP_SELF " ] . " ?id= " . $id , $langs -> trans ( " Cancel " ), " " , " confirm_cancel " , $array_input , " " , 1 );
2015-02-21 15:18:05 +01:00
}
2015-02-14 18:39:45 +01:00
2016-10-14 17:44:41 +02:00
if ( $action == 'brouillonner' )
{
2018-10-22 21:57:18 +02:00
$formconfirm = $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . " ?id= " . $id , $langs -> trans ( " BrouillonnerTrip " ), $langs -> trans ( " ConfirmBrouillonnerTrip " ), " confirm_brouillonner " , " " , " " , 1 );
2016-10-14 17:44:41 +02:00
}
2015-02-14 18:39:45 +01:00
2015-02-21 15:18:05 +01:00
if ( $action == 'refuse' ) // Deny
{
$array_input = array ( 'text' => $langs -> trans ( " ConfirmRefuseTrip " ), array ( 'type' => " text " , 'label' => $langs -> trans ( " Comment " ), 'name' => " detail_refuse " , 'size' => " 50 " , 'value' => " " ));
2018-10-22 21:57:18 +02:00
$formconfirm = $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . " ?id= " . $id , $langs -> trans ( " Deny " ), '' , " confirm_refuse " , $array_input , " yes " , 1 );
2015-02-21 15:18:05 +01:00
}
2015-02-14 18:39:45 +01:00
if ( $action == 'delete_line' )
{
2018-10-22 21:57:18 +02:00
$formconfirm = $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . " ?id= " . $id . " &rowid= " . GETPOST ( 'rowid' , 'int' ), $langs -> trans ( " DeleteLine " ), $langs -> trans ( " ConfirmDeleteLine " ), " confirm_delete_line " , '' , 'yes' , 1 );
2015-02-14 18:39:45 +01:00
}
2016-10-14 17:44:41 +02:00
// Print form confirm
print $formconfirm ;
2017-05-28 06:49:17 +02:00
2016-10-14 17:44:41 +02:00
// Expense report card
2017-10-03 16:00:52 +02:00
$linkback = '<a href="' . DOL_URL_ROOT . '/expensereport/list.php?restore_lastsearch_values=1' . ( ! empty ( $socid ) ? '&socid=' . $socid : '' ) . '">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2017-05-28 06:49:17 +02:00
2016-10-14 17:44:41 +02:00
$morehtmlref = '<div class="refidno">' ;
/*
// Ref customer
$morehtmlref .= $form -> editfieldkey ( " RefCustomer " , 'ref_client' , $object -> ref_client , $object , $user -> rights -> commande -> creer , 'string' , '' , 0 , 1 );
$morehtmlref .= $form -> editfieldval ( " RefCustomer " , 'ref_client' , $object -> ref_client , $object , $user -> rights -> commande -> creer , 'string' , '' , null , null , '' , 1 );
// Thirdparty
$morehtmlref .= '<br>' . $langs -> trans ( 'ThirdParty' ) . ' : ' . $soc -> getNomUrl ( 1 );
// Project
if ( ! empty ( $conf -> projet -> enabled ))
{
$langs -> load ( " projects " );
$morehtmlref .= '<br>' . $langs -> trans ( 'Project' ) . ' ' ;
if ( $user -> rights -> commande -> creer )
{
if ( $action != 'classify' )
$morehtmlref .= '<a href="' . $_SERVER [ 'PHP_SELF' ] . '?action=classify&id=' . $object -> id . '">' . img_edit ( $langs -> transnoentitiesnoconv ( 'SetProject' )) . '</a> : ' ;
if ( $action == 'classify' ) {
//$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
$morehtmlref .= '<form method="post" action="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '">' ;
$morehtmlref .= '<input type="hidden" name="action" value="classin">' ;
$morehtmlref .= '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
$morehtmlref .= $formproject -> select_projects ( $object -> socid , $object -> fk_project , 'projectid' , $maxlength , 0 , 1 , 0 , 1 , 0 , 0 , '' , 1 );
$morehtmlref .= '<input type="submit" class="button valignmiddle" value="' . $langs -> trans ( " Modify " ) . '">' ;
$morehtmlref .= '</form>' ;
} else {
$morehtmlref .= $form -> form_project ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> socid , $object -> fk_project , 'none' , 0 , 0 , 0 , 1 );
}
} else {
if ( ! empty ( $object -> fk_project )) {
$proj = new Project ( $db );
$proj -> fetch ( $object -> fk_project );
$morehtmlref .= '<a href="' . DOL_URL_ROOT . '/projet/card.php?id=' . $object -> fk_project . '" title="' . $langs -> trans ( 'ShowProject' ) . '">' ;
$morehtmlref .= $proj -> ref ;
$morehtmlref .= '</a>' ;
} else {
$morehtmlref .= '' ;
}
}
} */
$morehtmlref .= '</div>' ;
2017-05-28 06:49:17 +02:00
2016-10-14 17:44:41 +02:00
dol_banner_tab ( $object , 'ref' , $linkback , 1 , 'ref' , 'ref' , $morehtmlref );
2017-05-28 06:49:17 +02:00
2016-10-14 17:44:41 +02:00
print '<div class="fichecenter">' ;
print '<div class="fichehalfleft">' ;
print '<div class="underbanner clearboth"></div>' ;
2017-05-28 06:49:17 +02:00
2016-10-14 17:44:41 +02:00
print '<table class="border centpercent">' ;
2015-02-14 18:39:45 +01:00
2016-11-13 22:00:57 +01:00
// Author
print '<tr>' ;
print '<td class="titlefield">' . $langs -> trans ( " User " ) . '</td>' ;
print '<td>' ;
if ( $object -> fk_user_author > 0 )
{
$userauthor = new User ( $db );
$result = $userauthor -> fetch ( $object -> fk_user_author );
if ( $result < 0 ) dol_print_error ( '' , $userauthor -> error );
2017-05-29 13:19:45 +02:00
elseif ( $result > 0 ) print $userauthor -> getNomUrl ( - 1 );
2016-11-13 22:00:57 +01:00
}
print '</td></tr>' ;
2017-05-28 06:49:17 +02:00
2015-02-14 18:39:45 +01:00
print '<tr>' ;
2016-10-14 17:44:41 +02:00
print '<td class="titlefield">' . $langs -> trans ( " Period " ) . '</td>' ;
print '<td>' ;
2016-12-13 23:59:26 +01:00
print get_date_range ( $object -> date_debut , $object -> date_fin , 'day' , $langs , 0 );
2015-02-14 18:39:45 +01:00
print '</td>' ;
print '</tr>' ;
if ( ! empty ( $conf -> global -> EXPENSEREPORT_ASK_PAYMENTMODE_ON_CREATION ))
{
print '<tr>' ;
print '<td>' . $langs -> trans ( " ModePaiement " ) . '</td>' ;
2016-10-14 17:44:41 +02:00
print '<td>' . $object -> libelle_paiement . '</td>' ;
2015-02-14 18:39:45 +01:00
print '</tr>' ;
}
2015-07-15 15:04:44 +02:00
2016-06-06 16:31:50 +02:00
// Validation date
2015-02-21 12:57:17 +01:00
print '<tr>' ;
print '<td>' . $langs -> trans ( " DATE_SAVE " ) . '</td>' ;
2016-12-22 15:49:06 +01:00
print '<td>' . dol_print_date ( $object -> date_valid , 'dayhour' );
2016-06-06 16:31:50 +02:00
if ( $object -> status == 2 && $object -> hasDelay ( 'toapprove' )) print ' ' . img_warning ( $langs -> trans ( " Late " ));
if ( $object -> status == 5 && $object -> hasDelay ( 'topay' )) print ' ' . img_warning ( $langs -> trans ( " Late " ));
print '</td></tr>' ;
2015-02-21 12:57:17 +01:00
print '</tr>' ;
2015-02-21 15:18:05 +01:00
2016-12-22 15:49:06 +01:00
// User to inform for approval
2015-07-15 15:39:50 +02:00
if ( $object -> fk_statut < 3 ) // informed
2015-02-14 18:39:45 +01:00
{
print '<tr>' ;
2016-12-22 15:49:06 +01:00
print '<td>' . $langs -> trans ( " VALIDATOR " ) . '</td>' ; // approver
2015-02-14 18:39:45 +01:00
print '<td>' ;
2015-02-15 19:13:16 +01:00
if ( $object -> fk_user_validator > 0 )
{
$userfee = new User ( $db );
2017-05-29 13:19:45 +02:00
$result = $userfee -> fetch ( $object -> fk_user_validator );
if ( $result > 0 ) print $userfee -> getNomUrl ( - 1 );
2017-06-11 10:37:58 +02:00
if ( empty ( $userfee -> email ) || ! isValidEmail ( $userfee -> email ))
2016-06-06 16:31:50 +02:00
{
$langs -> load ( " errors " );
print img_warning ( $langs -> trans ( " ErrorBadEMail " , $userfee -> email ));
}
2015-02-15 19:13:16 +01:00
}
2015-02-14 18:39:45 +01:00
print '</td></tr>' ;
}
2015-07-15 15:39:50 +02:00
elseif ( $object -> fk_statut == 4 )
2015-02-14 18:39:45 +01:00
{
print '<tr>' ;
2015-02-21 12:57:17 +01:00
print '<td>' . $langs -> trans ( " CANCEL_USER " ) . '</span></td>' ;
print '<td>' ;
2015-02-15 19:13:16 +01:00
if ( $object -> fk_user_cancel > 0 )
{
$userfee = new User ( $db );
2017-05-29 13:19:45 +02:00
$result = $userfee -> fetch ( $object -> fk_user_cancel );
if ( $result > 0 ) print $userfee -> getNomUrl ( - 1 );
2015-02-15 19:13:16 +01:00
}
2015-02-21 12:57:17 +01:00
print '</td></tr>' ;
2017-05-28 06:49:17 +02:00
2015-02-14 18:39:45 +01:00
print '<tr>' ;
2015-02-21 12:57:17 +01:00
print '<td>' . $langs -> trans ( " MOTIF_CANCEL " ) . '</td>' ;
print '<td>' . $object -> detail_cancel . '</td></tr>' ;
2015-02-14 18:39:45 +01:00
print '</tr>' ;
print '<tr>' ;
2015-02-21 12:57:17 +01:00
print '<td>' . $langs -> trans ( " DATE_CANCEL " ) . '</td>' ;
2015-02-21 15:18:05 +01:00
print '<td>' . dol_print_date ( $object -> date_cancel , 'dayhour' ) . '</td></tr>' ;
2015-02-14 18:39:45 +01:00
print '</tr>' ;
}
else
{
print '<tr>' ;
2015-07-30 14:47:56 +02:00
print '<td>' . $langs -> trans ( " ApprovedBy " ) . '</td>' ;
2015-02-14 18:39:45 +01:00
print '<td>' ;
2015-02-21 15:18:05 +01:00
if ( $object -> fk_user_approve > 0 )
2015-02-15 19:13:16 +01:00
{
2015-02-21 15:18:05 +01:00
$userapp = new User ( $db );
2017-05-29 13:19:45 +02:00
$result = $userapp -> fetch ( $object -> fk_user_approve );
if ( $result > 0 ) print $userapp -> getNomUrl ( - 1 );
2015-02-15 19:13:16 +01:00
}
2015-02-14 18:39:45 +01:00
print '</td></tr>' ;
2017-05-28 06:49:17 +02:00
2015-02-14 18:39:45 +01:00
print '<tr>' ;
2015-02-21 15:18:05 +01:00
print '<td>' . $langs -> trans ( " DateApprove " ) . '</td>' ;
print '<td>' . dol_print_date ( $object -> date_approve , 'dayhour' ) . '</td></tr>' ;
2015-02-14 18:39:45 +01:00
print '</tr>' ;
}
2015-07-15 15:39:50 +02:00
if ( $object -> fk_statut == 99 || ! empty ( $object -> detail_refuse ))
2015-02-14 18:39:45 +01:00
{
print '<tr>' ;
2015-02-21 12:57:17 +01:00
print '<td>' . $langs -> trans ( " REFUSEUR " ) . '</td>' ;
print '<td>' ;
2015-02-14 18:39:45 +01:00
$userfee = new User ( $db );
2017-05-29 13:19:45 +02:00
$result = $userfee -> fetch ( $object -> fk_user_refuse );
if ( $result > 0 ) print $userfee -> getNomUrl ( - 1 );
2015-02-21 12:57:17 +01:00
print '</td></tr>' ;
2017-05-28 06:49:17 +02:00
2015-02-14 18:39:45 +01:00
print '<tr>' ;
2015-02-21 12:57:17 +01:00
print '<td>' . $langs -> trans ( " DATE_REFUS " ) . '</td>' ;
2015-02-21 15:18:05 +01:00
print '<td>' . dol_print_date ( $object -> date_refuse , 'dayhour' );
2015-02-21 12:57:17 +01:00
if ( $object -> detail_refuse ) print ' - ' . $object -> detail_refuse ;
print '</td>' ;
2015-02-14 18:39:45 +01:00
print '</tr>' ;
}
2015-06-23 10:13:08 +02:00
if ( $object -> fk_statut == 6 )
{
2015-07-30 14:47:56 +02:00
/* TODO this fields are not yet filled
2015-06-23 10:13:08 +02:00
print '<tr>' ;
print '<td>' . $langs -> trans ( " AUTHORPAIEMENT " ) . '</td>' ;
print '<td>' ;
$userfee = new User ( $db );
$userfee -> fetch ( $object -> fk_user_paid );
2016-09-01 11:29:30 +02:00
print $userfee -> getNomUrl ( - 1 );
2015-06-23 10:13:08 +02:00
print '</td></tr>' ;
print '<tr>' ;
print '<td>' . $langs -> trans ( " DATE_PAIEMENT " ) . '</td>' ;
print '<td>' . $object -> date_paiement . '</td></tr>' ;
print '</tr>' ;
2015-07-30 14:47:56 +02:00
*/
2015-06-23 10:13:08 +02:00
}
2015-07-15 15:04:44 +02:00
2016-09-06 13:39:44 +02:00
// Other attributes
2017-05-28 06:49:17 +02:00
$cols = 2 ;
2016-09-06 13:39:44 +02:00
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php' ;
2017-05-28 06:49:17 +02:00
2015-02-14 18:39:45 +01:00
print '</table>' ;
2016-10-14 17:44:41 +02:00
print '</div>' ;
print '<div class="fichehalfright">' ;
print '<div class="ficheaddleft">' ;
2017-05-28 06:49:17 +02:00
print '<div class="underbanner clearboth"></div>' ;
print '<table class="border centpercent">' ;
// Amount
print '<tr>' ;
print '<td class="titlefieldmiddle">' . $langs -> trans ( " AmountHT " ) . '</td>' ;
print '<td class="nowrap amountcard">' . price ( $object -> total_ht , 1 , '' , 1 , - 1 , - 1 , $conf -> currency ) . '</td>' ;
$rowspan = 5 ;
if ( $object -> fk_statut < 3 ) $rowspan ++ ;
elseif ( $object -> fk_statut == 4 ) $rowspan += 2 ;
else $rowspan += 2 ;
if ( $object -> fk_statut == 99 || ! empty ( $object -> detail_refuse )) $rowspan += 2 ;
if ( $object -> fk_statut == 6 ) $rowspan += 2 ;
print " </td> " ;
print '</tr>' ;
print '<tr>' ;
print '<td>' . $langs -> trans ( " AmountVAT " ) . '</td>' ;
print '<td class="nowrap amountcard">' . price ( $object -> total_tva , 1 , '' , 1 , - 1 , - 1 , $conf -> currency ) . '</td>' ;
print '</tr>' ;
print '<tr>' ;
print '<td>' . $langs -> trans ( " AmountTTC " ) . '</td>' ;
print '<td class="nowrap amountcard">' . price ( $object -> total_ttc , 1 , '' , 1 , - 1 , - 1 , $conf -> currency ) . '</td>' ;
print '</tr>' ;
// List of payments already done
$nbcols = 3 ;
if ( ! empty ( $conf -> banque -> enabled )) {
$nbrows ++ ;
$nbcols ++ ;
}
print '<table class="noborder paymenttable" width="100%">' ;
print '<tr class="liste_titre">' ;
print '<td class="liste_titre">' . $langs -> trans ( 'Payments' ) . '</td>' ;
print '<td class="liste_titre">' . $langs -> trans ( 'Date' ) . '</td>' ;
print '<td class="liste_titre">' . $langs -> trans ( 'Type' ) . '</td>' ;
if ( ! empty ( $conf -> banque -> enabled )) {
print '<td class="liste_titre" align="right">' . $langs -> trans ( 'BankAccount' ) . '</td>' ;
}
print '<td class="liste_titre" align="right">' . $langs -> trans ( 'Amount' ) . '</td>' ;
print '<td class="liste_titre" width="18"> </td>' ;
print '</tr>' ;
// Payments already done (from payment on this expensereport)
$sql = " SELECT p.rowid, p.num_payment, p.datep as dp, p.amount, p.fk_bank, " ;
$sql .= " c.code as p_code, c.libelle as payment_type, " ;
$sql .= " ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal " ;
2017-11-23 15:06:16 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " expensereport as e, " . MAIN_DB_PREFIX . " payment_expensereport as p " ;
2018-03-07 17:32:57 +01:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " c_paiement as c ON p.fk_typepayment = c.id " ;
2017-11-23 15:06:16 +01:00
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank as b ON p.fk_bank = b.rowid' ;
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank_account as ba ON b.fk_account = ba.rowid' ;
2016-10-14 17:44:41 +02:00
$sql .= " WHERE e.rowid = ' " . $id . " ' " ;
$sql .= " AND p.fk_expensereport = e.rowid " ;
2017-08-21 23:41:19 +02:00
$sql .= ' AND e.entity IN (' . getEntity ( 'expensereport' ) . ')' ;
2016-10-14 17:44:41 +02:00
$sql .= " ORDER BY dp " ;
2017-05-28 06:49:17 +02:00
2016-10-14 17:44:41 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
{
$num = $db -> num_rows ( $resql );
$i = 0 ; $total = 0 ;
while ( $i < $num )
{
$objp = $db -> fetch_object ( $resql );
2017-05-28 06:49:17 +02:00
2017-11-23 15:24:25 +01:00
$paymentexpensereportstatic -> id = $objp -> rowid ;
$paymentexpensereportstatic -> datepaye = $db -> jdate ( $objp -> dp );
$paymentexpensereportstatic -> ref = $objp -> rowid ;
$paymentexpensereportstatic -> num_paiement = $objp -> num_paiement ;
$paymentexpensereportstatic -> payment_code = $objp -> payment_code ;
2017-07-08 18:32:34 +02:00
print '<tr class="oddseven">' ;
print '<td>' ;
2017-05-28 06:49:17 +02:00
print $paymentexpensereportstatic -> getNomUrl ( 1 );
print '</td>' ;
2016-10-14 17:44:41 +02:00
print '<td>' . dol_print_date ( $db -> jdate ( $objp -> dp ), 'day' ) . " </td> \n " ;
2018-11-25 21:36:25 +01:00
$labeltype = $langs -> trans ( " PaymentType " . $objp -> p_code ) != ( " PaymentType " . $objp -> p_code ) ? $langs -> trans ( " PaymentType " . $objp -> p_code ) : $objp -> payment_type ;
2016-10-14 17:44:41 +02:00
print " <td> " . $labeltype . ' ' . $objp -> num_payment . " </td> \n " ;
2017-11-23 15:24:25 +01:00
if ( ! empty ( $conf -> banque -> enabled ))
{
2017-05-28 06:49:17 +02:00
$bankaccountstatic -> id = $objp -> baid ;
$bankaccountstatic -> ref = $objp -> baref ;
$bankaccountstatic -> label = $objp -> baref ;
$bankaccountstatic -> number = $objp -> banumber ;
if ( ! empty ( $conf -> accounting -> enabled )) {
$bankaccountstatic -> account_number = $objp -> account_number ;
$accountingjournal = new AccountingJournal ( $db );
$accountingjournal -> fetch ( $objp -> fk_accountancy_journal );
$bankaccountstatic -> accountancy_journal = $accountingjournal -> getNomUrl ( 0 , 1 , 1 , '' , 1 );
}
print '<td align="right">' ;
if ( $bankaccountstatic -> id )
print $bankaccountstatic -> getNomUrl ( 1 , 'transactions' );
print '</td>' ;
}
print '<td align="right">' . price ( $objp -> amount ) . " </td> " ;
2017-07-08 18:32:34 +02:00
print '<td></td>' ;
2016-10-14 17:44:41 +02:00
print " </tr> " ;
$totalpaid += $objp -> amount ;
$i ++ ;
}
2018-12-17 10:42:30 +01:00
$totalpaid = price2num ( $totalpaid ); // Round $totalpaid to fix floating problem after addition into loop
2017-05-28 06:49:17 +02:00
2018-12-17 13:57:30 +01:00
$remaintopay = price2num ( $object -> total_ttc - $totalpaid );
$resteapayeraffiche = $remaintopay ;
2017-06-11 10:37:58 +02:00
2018-12-17 13:57:30 +01:00
$cssforamountpaymentcomplete = 'amountpaymentcomplete' ;
2017-06-11 10:37:58 +02:00
2018-12-17 13:57:30 +01:00
if ( $object -> status == ExpenseReport :: STATUS_REFUSED )
{
$cssforamountpaymentcomplete = 'amountpaymentneutral' ;
$resteapayeraffiche = 0 ;
2016-10-14 17:44:41 +02:00
}
2018-12-17 13:57:30 +01:00
elseif ( $object -> paid == 0 )
{
$cssforamountpaymentcomplete = 'amountpaymentneutral' ;
}
print '<tr><td colspan="' . $nbcols . '" align="right">' . $langs -> trans ( " AlreadyPaid " ) . ':</td><td align="right">' . price ( $totalpaid ) . '</td><td></td></tr>' ;
print '<tr><td colspan="' . $nbcols . '" align="right">' . $langs -> trans ( " AmountExpected " ) . ':</td><td align="right">' . price ( $object -> total_ttc ) . '</td><td></td></tr>' ;
print '<tr><td colspan="' . $nbcols . '" align="right">' . $langs -> trans ( " RemainderToPay " ) . ':</td>' ;
print '<td align="right"' . ( $resteapayeraffiche ? ' class="amountremaintopay"' : ( ' class="' . $cssforamountpaymentcomplete . '"' )) . '>' . price ( $resteapayeraffiche ) . '</td><td></td></tr>' ;
2016-10-14 17:44:41 +02:00
$db -> free ( $resql );
}
else
{
dol_print_error ( $db );
2017-05-28 06:49:17 +02:00
}
2017-07-08 18:32:34 +02:00
print " </table> " ;
2017-05-28 06:49:17 +02:00
2016-10-14 17:44:41 +02:00
print '</div>' ;
print '</div>' ;
print '</div>' ;
2017-05-28 06:49:17 +02:00
2016-10-14 17:44:41 +02:00
print '<div class="clearboth"></div><br>' ;
2015-02-14 18:39:45 +01:00
2017-02-23 01:29:35 +01:00
print '<div style="clear: both;"></div>' ;
2015-11-28 15:28:59 +01:00
2018-09-28 16:15:17 +02:00
$actiontouse = 'updateline' ;
2015-11-28 15:28:59 +01:00
if (( $object -> fk_statut == 0 || $object -> fk_statut == 99 ) && $action != 'editline' ) $actiontouse = 'addline' ;
2017-05-28 06:49:17 +02:00
2015-11-28 15:28:59 +01:00
print '<form name="expensereport" action="' . $_SERVER [ " PHP_SELF " ] . '" method="post">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<input type="hidden" name="action" value="' . $actiontouse . '">' ;
print '<input type="hidden" name="id" value="' . $object -> id . '">' ;
print '<input type="hidden" name="fk_expensereport" value="' . $object -> id . '" />' ;
2017-05-28 06:49:17 +02:00
2018-02-07 17:01:14 +01:00
print '<div class="div-table-responsive-no-min">' ;
2017-02-23 01:29:35 +01:00
print '<table id="tablelines" class="noborder" width="100%">' ;
2017-05-28 06:49:17 +02:00
2017-06-15 11:08:53 +02:00
if ( ! empty ( $object -> lines ))
2015-02-14 18:39:45 +01:00
{
$i = 0 ; $total = 0 ;
2017-06-15 11:08:53 +02:00
print '<tr class="liste_titre">' ;
2018-02-23 15:16:49 +01:00
print '<td style="text-align:center;">' . $langs -> trans ( 'LineNb' ) . '</td>' ;
//print '<td style="text-align:center;">'.$langs->trans('Piece').'</td>';
2017-06-15 11:08:53 +02:00
print '<td style="text-align:center;">' . $langs -> trans ( 'Date' ) . '</td>' ;
if ( ! empty ( $conf -> projet -> enabled )) print '<td class="minwidth100imp">' . $langs -> trans ( 'Project' ) . '</td>' ;
if ( ! empty ( $conf -> global -> MAIN_USE_EXPENSE_IK )) print '<td>' . $langs -> trans ( 'CarCategory' ) . '</td>' ;
print '<td style="text-align:center;">' . $langs -> trans ( 'Type' ) . '</td>' ;
print '<td style="text-align:left;">' . $langs -> trans ( 'Description' ) . '</td>' ;
print '<td style="text-align:right;">' . $langs -> trans ( 'VAT' ) . '</td>' ;
print '<td style="text-align:right;">' . $langs -> trans ( 'PriceUTTC' ) . '</td>' ;
print '<td style="text-align:right;">' . $langs -> trans ( 'Qty' ) . '</td>' ;
if ( $action != 'editline' )
2015-02-14 18:39:45 +01:00
{
2017-06-15 11:08:53 +02:00
print '<td style="text-align:right;">' . $langs -> trans ( 'AmountHT' ) . '</td>' ;
print '<td style="text-align:right;">' . $langs -> trans ( 'AmountTTC' ) . '</td>' ;
}
// Ajout des boutons de modification/suppression
if (( $object -> fk_statut < 2 || $object -> fk_statut == 99 ) && $user -> rights -> expensereport -> creer )
{
print '<td style="text-align:right;"></td>' ;
}
print '</tr>' ;
2015-02-14 18:39:45 +01:00
2017-06-15 11:08:53 +02:00
foreach ( $object -> lines as & $line )
{
2018-02-23 15:16:49 +01:00
$numline = $i + 1 ;
2017-06-15 11:08:53 +02:00
2018-03-10 15:52:11 +01:00
if ( $action != 'editline' || $line -> rowid != GETPOST ( 'rowid' , 'int' ))
2015-02-14 18:39:45 +01:00
{
2017-06-15 11:08:53 +02:00
print '<tr class="oddeven">' ;
2017-04-05 11:51:55 +02:00
2017-06-15 11:08:53 +02:00
print '<td style="text-align:center;">' ;
2018-02-23 15:16:49 +01:00
print $numline ;
print '</td>' ;
/* print '<td style="text-align:center;">' ;
2017-06-15 11:08:53 +02:00
print img_picto ( $langs -> trans ( " Document " ), " object_generic " );
2018-02-23 15:16:49 +01:00
print ' <span>' . $piece_comptable . '</span>' ;
print '</td>' ; */
2017-06-15 11:08:53 +02:00
print '<td style="text-align:center;">' . dol_print_date ( $db -> jdate ( $line -> date ), 'day' ) . '</td>' ;
if ( ! empty ( $conf -> projet -> enabled ))
2015-02-14 18:39:45 +01:00
{
2017-06-15 11:08:53 +02:00
print '<td>' ;
if ( $line -> fk_projet > 0 )
2015-02-21 12:57:17 +01:00
{
2017-06-15 11:08:53 +02:00
$projecttmp -> id = $line -> fk_projet ;
$projecttmp -> ref = $line -> projet_ref ;
print $projecttmp -> getNomUrl ( 1 );
2015-02-21 12:57:17 +01:00
}
2017-06-15 11:08:53 +02:00
print '</td>' ;
}
if ( ! empty ( $conf -> global -> MAIN_USE_EXPENSE_IK ))
{
print '<td class="fk_c_exp_tax_cat">' ;
print dol_getIdFromCode ( $db , $line -> fk_c_exp_tax_cat , 'c_exp_tax_cat' , 'rowid' , 'label' );
print '</td>' ;
}
2018-03-10 18:40:45 +01:00
print '<td class="center">' ;
2018-02-07 17:01:14 +01:00
$labeltype = ( $langs -> trans (( $line -> type_fees_code )) == $line -> type_fees_code ? $line -> type_fees_libelle : $langs -> trans ( $line -> type_fees_code ));
print $labeltype ;
print '</td>' ;
2018-03-10 18:40:45 +01:00
print '<td style="text-align:left;">' . dol_escape_htmltag ( $line -> comments ) . '</td>' ;
2017-06-15 11:08:53 +02:00
print '<td style="text-align:right;">' . vatrate ( $line -> vatrate , true ) . '</td>' ;
print '<td style="text-align:right;">' . price ( $line -> value_unit ) . '</td>' ;
2018-03-10 18:40:45 +01:00
print '<td style="text-align:right;">' . dol_escape_htmltag ( $line -> qty ) . '</td>' ;
2017-06-15 11:08:53 +02:00
if ( $action != 'editline' )
{
print '<td style="text-align:right;">' . price ( $line -> total_ht ) . '</td>' ;
print '<td style="text-align:right;">' . price ( $line -> total_ttc ) . '</td>' ;
}
2015-02-14 18:39:45 +01:00
2017-06-15 11:08:53 +02:00
// Ajout des boutons de modification/suppression
if (( $object -> fk_statut < 2 || $object -> fk_statut == 99 ) && $user -> rights -> expensereport -> creer )
{
print '<td style="text-align:right;" class="nowrap">' ;
2016-08-30 07:02:44 +02:00
2017-06-15 11:08:53 +02:00
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=editline&rowid=' . $line -> rowid . '#' . $line -> rowid . '">' ;
print img_edit ();
print '</a> ' ;
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=delete_line&rowid=' . $line -> rowid . '">' ;
print img_delete ();
print '</a>' ;
2017-05-28 06:49:17 +02:00
2017-06-15 11:08:53 +02:00
print '</td>' ;
2015-02-14 18:39:45 +01:00
}
2015-02-21 15:18:05 +01:00
2017-06-15 11:08:53 +02:00
print '</tr>' ;
}
2017-06-11 10:37:58 +02:00
2018-03-10 15:52:11 +01:00
if ( $action == 'editline' && $line -> rowid == GETPOST ( 'rowid' , 'int' ))
2017-06-15 11:08:53 +02:00
{
print '<tr class="oddeven">' ;
2015-11-28 15:28:59 +01:00
2017-06-15 11:08:53 +02:00
print '<td></td>' ;
2015-02-14 18:39:45 +01:00
2017-06-15 11:08:53 +02:00
// Select date
print '<td class="center">' ;
2018-09-09 08:02:26 +02:00
print $form -> selectDate ( $line -> date , 'date' );
2017-06-15 11:08:53 +02:00
print '</td>' ;
2015-02-14 18:39:45 +01:00
2017-06-15 11:08:53 +02:00
// Select project
if ( ! empty ( $conf -> projet -> enabled ))
{
2015-02-21 12:57:17 +01:00
print '<td>' ;
2018-03-29 15:31:21 +02:00
$formproject -> select_projects ( - 1 , $line -> fk_projet , 'fk_projet' , 0 , 0 , 1 , 1 , 0 , 0 , 0 , '' , 0 , 0 , 'maxwidth300' );
2015-02-14 18:39:45 +01:00
print '</td>' ;
2017-06-15 11:08:53 +02:00
}
2015-02-14 18:39:45 +01:00
2017-06-15 11:08:53 +02:00
if ( ! empty ( $conf -> global -> MAIN_USE_EXPENSE_IK ))
{
print '<td class="fk_c_exp_tax_cat">' ;
$params = array ( 'fk_expense' => $object -> id , 'fk_expense_det' => $line -> rowid , 'date' => $line -> dates );
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 );
2015-02-14 18:39:45 +01:00
print '</td>' ;
2017-06-15 11:08:53 +02:00
}
2015-02-14 18:39:45 +01:00
2017-06-15 11:08:53 +02:00
// Select type
print '<td class="center">' ;
select_type_fees_id ( $line -> fk_c_type_fees , 'fk_c_type_fees' );
print '</td>' ;
2015-02-14 18:39:45 +01:00
2017-06-15 11:08:53 +02:00
// Add comments
print '<td>' ;
2018-03-10 18:40:45 +01:00
print '<textarea name="comments" class="flat_ndf centpercent">' . dol_escape_htmltag ( $line -> comments ) . '</textarea>' ;
2017-06-15 11:08:53 +02:00
print '</td>' ;
2015-02-14 18:39:45 +01:00
2017-06-15 11:08:53 +02:00
// VAT
print '<td style="text-align:right;">' ;
print $form -> load_tva ( 'vatrate' , ( isset ( $_POST [ " vatrate " ]) ? $_POST [ " vatrate " ] : $line -> vatrate ), $mysoc , '' );
print '</td>' ;
2017-05-28 06:49:17 +02:00
2017-06-15 11:08:53 +02:00
// Unit price
print '<td style="text-align:right;">' ;
2018-03-10 15:52:11 +01:00
print '<input type="text" min="0" class="maxwidth100" name="value_unit" value="' . dol_escape_htmltag ( $line -> value_unit ) . '" />' ;
2017-06-15 11:08:53 +02:00
print '</td>' ;
2015-02-14 18:39:45 +01:00
2017-06-15 11:08:53 +02:00
// Quantity
print '<td style="text-align:right;">' ;
2018-03-10 15:52:11 +01:00
print '<input type="number" min="0" class="maxwidth100" name="qty" value="' . dol_escape_htmltag ( $line -> qty ) . '" />' ;
2017-06-15 11:08:53 +02:00
print '</td>' ;
if ( $action != 'editline' )
{
print '<td style="text-align:right;">' . $langs -> trans ( 'AmountHT' ) . '</td>' ;
print '<td style="text-align:right;">' . $langs -> trans ( 'AmountTTC' ) . '</td>' ;
}
print '<td style="text-align:center;">' ;
print '<input type="hidden" name="rowid" value="' . $line -> rowid . '">' ;
print '<input type="submit" class="button" name="save" value="' . $langs -> trans ( 'Save' ) . '">' ;
2017-09-15 23:49:04 +02:00
print '<br><input type="submit" class="button" name="cancel" value="' . $langs -> trans ( 'Cancel' ) . '">' ;
2017-06-15 11:08:53 +02:00
print '</td>' ;
2015-02-14 18:39:45 +01:00
}
2017-06-15 11:08:53 +02:00
$i ++ ;
2015-02-14 18:39:45 +01:00
}
2017-07-27 16:01:53 +02:00
}
2015-02-14 18:39:45 +01:00
2017-07-27 16:01:53 +02:00
// Add a line
if (( $object -> fk_statut == 0 || $object -> fk_statut == 99 ) && $action != 'editline' && $user -> rights -> expensereport -> creer )
{
print '<tr class="liste_titre">' ;
print '<td></td>' ;
print '<td align="center">' . $langs -> trans ( 'Date' ) . '</td>' ;
if ( ! empty ( $conf -> projet -> enabled )) print '<td class="minwidth100imp">' . $langs -> trans ( 'Project' ) . '</td>' ;
if ( ! empty ( $conf -> global -> MAIN_USE_EXPENSE_IK )) print '<td>' . $langs -> trans ( 'CarCategory' ) . '</td>' ;
print '<td align="center">' . $langs -> trans ( 'Type' ) . '</td>' ;
print '<td>' . $langs -> trans ( 'Description' ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( 'VAT' ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( 'PriceUTTC' ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( 'Qty' ) . '</td>' ;
print '<td colspan="3"></td>' ;
print '</tr>' ;
2015-02-14 18:39:45 +01:00
2018-03-10 18:40:45 +01:00
print '<tr class="oddeven">' ;
2015-02-14 18:39:45 +01:00
2017-07-27 16:01:53 +02:00
print '<td></td>' ;
2017-05-28 06:49:17 +02:00
2017-07-27 16:01:53 +02:00
// Select date
print '<td align="center">' ;
2018-09-09 08:02:26 +02:00
print $form -> selectDate ( $date ? $date :- 1 , 'date' );
2017-07-27 16:01:53 +02:00
print '</td>' ;
2015-02-14 18:39:45 +01:00
2017-07-27 16:01:53 +02:00
// Select project
if ( ! empty ( $conf -> projet -> enabled ))
{
2016-11-12 15:18:38 +01:00
print '<td>' ;
2018-03-10 18:17:54 +01:00
$formproject -> select_projects ( - 1 , $fk_projet , 'fk_projet' , 0 , 0 , 1 , 1 , 0 , 0 , 0 , '' , 0 , 0 , 'maxwidth300' );
2015-02-14 18:39:45 +01:00
print '</td>' ;
2017-07-27 16:01:53 +02:00
}
2015-02-14 18:39:45 +01:00
2017-07-27 16:01:53 +02:00
if ( ! empty ( $conf -> global -> MAIN_USE_EXPENSE_IK ))
{
print '<td class="fk_c_exp_tax_cat">' ;
$params = array ( 'fk_expense' => $object -> id );
print $form -> selectExpenseCategories ( '' , 'fk_c_exp_tax_cat' , 1 , array (), 'fk_c_type_fees' , $userauthor -> default_c_exp_tax_cat , $params );
2015-02-14 18:39:45 +01:00
print '</td>' ;
2017-07-27 16:01:53 +02:00
}
2015-02-14 18:39:45 +01:00
2017-07-27 16:01:53 +02:00
// Select type
print '<td align="center">' ;
select_type_fees_id ( $fk_c_type_fees , 'fk_c_type_fees' , 1 );
print '</td>' ;
2015-02-14 18:39:45 +01:00
2017-07-27 16:01:53 +02:00
// Add comments
print '<td>' ;
2018-03-10 18:40:45 +01:00
print '<textarea class="flat_ndf centpercent" name="comments">' . dol_escape_htmltag ( $comments ) . '</textarea>' ;
2017-07-27 16:01:53 +02:00
print '</td>' ;
2015-02-14 18:39:45 +01:00
2017-07-27 16:01:53 +02:00
// Select VAT
print '<td align="right">' ;
$defaultvat =- 1 ;
if ( ! empty ( $conf -> global -> EXPENSEREPORT_NO_DEFAULT_VAT )) $conf -> global -> MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS = 'none' ;
print $form -> load_tva ( 'vatrate' , ( $vatrate != '' ? $vatrate : $defaultvat ), $mysoc , '' , 0 , 0 , '' , false , 1 );
print '</td>' ;
2015-11-28 15:28:59 +01:00
2017-07-27 16:01:53 +02:00
// Unit price
print '<td align="right">' ;
2018-03-10 15:52:11 +01:00
print '<input type="text" class="right maxwidth50" name="value_unit" value="' . dol_escape_htmltag ( $value_unit ) . '">' ;
2017-07-27 16:01:53 +02:00
print '</td>' ;
2017-06-11 10:37:58 +02:00
2017-07-27 16:01:53 +02:00
// Quantity
print '<td align="right">' ;
2018-03-10 15:52:11 +01:00
print '<input type="text" min="0" class="right maxwidth50" name="qty" value="' . dol_escape_htmltag ( $qty ? $qty : 1 ) . '">' ; // We must be able to enter decimal qty
2017-07-27 16:01:53 +02:00
print '</td>' ;
2015-02-14 18:39:45 +01:00
2017-07-27 16:01:53 +02:00
if ( $action != 'editline' )
{
print '<td align="right"></td>' ;
print '<td align="right"></td>' ;
}
2017-06-11 10:37:58 +02:00
2017-07-27 16:01:53 +02:00
print '<td align="center"><input type="submit" value="' . $langs -> trans ( " Add " ) . '" name="bouton" class="button"></td>' ;
print '</tr>' ;
} // Fin si c'est payé/validé
print '</table>' ;
print '</div>' ;
print '</form>' ;
2015-02-14 18:39:45 +01:00
2015-02-15 22:49:23 +01:00
dol_fiche_end ();
} // end edit or not edit
2015-02-14 18:39:45 +01:00
} // end of if result
else
{
dol_print_error ( $db );
}
} //fin si id > 0
}
/*
* Barre d ' actions
*/
print '<div class="tabsAction">' ;
if ( $action != 'create' && $action != 'edit' )
{
$object = new ExpenseReport ( $db );
2015-06-08 13:49:09 +02:00
$object -> fetch ( $id , $ref );
2015-02-15 22:49:23 +01:00
2017-09-17 15:38:50 +02:00
// Send
if ( $object -> fk_statut > ExpenseReport :: STATUS_DRAFT ) {
//if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->expensereport->expensereport_advance->send)) {
2018-03-11 21:34:38 +01:00
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>' ;
2017-09-17 15:38:50 +02:00
//} else
2018-11-13 21:40:17 +01:00
// print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">' . $langs->trans('SendMail') . '</a></div>';
2017-09-17 15:38:50 +02:00
}
2015-02-14 18:39:45 +01:00
/* Si l ' état est " Brouillon "
* ET user à droit " creer/supprimer "
* ET fk_user_author == user courant
* Afficher : " Enregistrer " / " Modifier " / " Supprimer "
*/
2015-03-08 07:21:07 +01:00
if ( $user -> rights -> expensereport -> creer && $object -> fk_statut == 0 )
2015-02-14 18:39:45 +01:00
{
2017-02-24 11:01:52 +01:00
if ( in_array ( $object -> fk_user_author , $user -> getAllChildIds ( 1 )) || ! empty ( $user -> rights -> expensereport -> writeall_advance ))
2015-02-14 18:39:45 +01:00
{
2015-05-14 08:26:41 +02:00
// Modify
2016-08-30 07:02:44 +02:00
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?action=edit&id=' . $object -> id . '">' . $langs -> trans ( 'Modify' ) . '</a></div>' ;
2015-02-14 18:39:45 +01:00
2015-02-15 22:49:23 +01:00
// Validate
2017-04-14 16:50:30 +02:00
if ( count ( $object -> lines ) > 0 )
2015-02-15 22:49:23 +01:00
{
2016-08-30 07:02:44 +02:00
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?action=save&id=' . $object -> id . '">' . $langs -> trans ( 'ValidateAndSubmit' ) . '</a></div>' ;
2015-02-15 22:49:23 +01:00
}
2015-02-14 18:39:45 +01:00
}
}
/* Si l ' état est " Refusée "
* ET user à droit " creer/supprimer "
* ET fk_user_author == user courant
* Afficher : " Enregistrer " / " Modifier " / " Supprimer "
*/
2015-03-08 07:21:07 +01:00
if ( $user -> rights -> expensereport -> creer && $object -> fk_statut == 99 )
2015-02-14 18:39:45 +01:00
{
2015-02-21 12:57:17 +01:00
if ( $user -> id == $object -> fk_user_author || $user -> id == $object -> fk_user_valid )
2015-02-14 18:39:45 +01:00
{
2015-05-14 08:26:41 +02:00
// Modify
2016-08-30 07:02:44 +02:00
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?action=edit&id=' . $object -> id . '">' . $langs -> trans ( 'Modify' ) . '</a></div>' ;
2015-02-14 18:39:45 +01:00
// Brouillonner (le statut refusée est identique à brouillon)
//print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=brouillonner&id='.$id.'">'.$langs->trans('BROUILLONNER').'</a>';
// Enregistrer depuis le statut "Refusée"
2016-08-30 07:02:44 +02:00
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>' ;
2015-02-14 18:39:45 +01:00
}
}
2015-03-08 07:21:07 +01:00
if ( $user -> rights -> expensereport -> to_paid && $object -> fk_statut == 5 )
2015-02-14 18:39:45 +01:00
{
2015-02-21 12:57:17 +01:00
if ( $user -> id == $object -> fk_user_author || $user -> id == $object -> fk_user_valid )
2015-02-14 18:39:45 +01:00
{
// Brouillonner
2016-08-30 07:02:44 +02:00
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?action=brouillonner&id=' . $object -> id . '">' . $langs -> trans ( 'SetToDraft' ) . '</a></div>' ;
2015-02-14 18:39:45 +01:00
}
}
/* Si l 'état est "En attente d' approbation "
2015-02-21 16:15:54 +01:00
* ET user à droit de " approve "
2015-06-16 06:56:58 +02:00
* ET fk_user_validator == user courant
* Afficher : " Valider " / " Refuser " / " Supprimer "
*/
2015-03-08 07:21:07 +01:00
if ( $object -> fk_statut == 2 )
2015-02-14 18:39:45 +01:00
{
2017-01-26 18:08:00 +01:00
if ( in_array ( $object -> fk_user_author , $user -> getAllChildIds ( 1 )))
2015-02-14 18:39:45 +01:00
{
// Brouillonner
2016-08-30 07:02:44 +02:00
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?action=brouillonner&id=' . $object -> id . '">' . $langs -> trans ( 'SetToDraft' ) . '</a></div>' ;
2015-02-14 18:39:45 +01:00
}
}
2015-03-08 07:21:07 +01:00
if ( $user -> rights -> expensereport -> approve && $object -> fk_statut == 2 )
2015-02-14 18:39:45 +01:00
{
//if($object->fk_user_validator==$user->id)
//{
2015-05-14 08:26:41 +02:00
// Validate
2016-08-30 07:02:44 +02:00
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?action=validate&id=' . $object -> id . '">' . $langs -> trans ( 'Approve' ) . '</a></div>' ;
2015-05-14 08:26:41 +02:00
// Deny
2016-08-30 07:02:44 +02:00
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?action=refuse&id=' . $object -> id . '">' . $langs -> trans ( 'Deny' ) . '</a></div>' ;
2015-02-14 18:39:45 +01:00
//}
2015-02-21 12:57:17 +01:00
if ( $user -> id == $object -> fk_user_author || $user -> id == $object -> fk_user_valid )
2015-02-14 18:39:45 +01:00
{
2015-02-21 12:57:17 +01:00
// Cancel
2016-08-30 07:02:44 +02:00
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?action=cancel&id=' . $object -> id . '">' . $langs -> trans ( 'Cancel' ) . '</a></div>' ;
2015-02-14 18:39:45 +01:00
}
}
2015-07-15 15:04:44 +02:00
2017-05-28 06:49:17 +02:00
2016-07-28 20:00:56 +02:00
// If status is Appoved
// --------------------
2017-06-11 10:37:58 +02:00
2016-07-20 16:07:15 +02:00
if ( $user -> rights -> expensereport -> approve && $object -> fk_statut == 5 )
{
2016-08-30 07:02:44 +02:00
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?action=refuse&id=' . $object -> id . '">' . $langs -> trans ( 'Deny' ) . '</a></div>' ;
2016-07-20 16:07:15 +02:00
}
2017-05-28 06:49:17 +02:00
2016-07-28 20:00:56 +02:00
// If bank module is used
2015-08-28 20:11:16 +02:00
if ( $user -> rights -> expensereport -> to_paid && ! empty ( $conf -> banque -> enabled ) && $object -> fk_statut == 5 )
2015-02-14 18:39:45 +01:00
{
2015-05-14 08:26:41 +02:00
// Pay
2015-06-16 06:56:58 +02:00
if ( $remaintopay == 0 )
{
2018-11-13 21:40:17 +01:00
print '<div class="inline-block divButAction"><span class="butActionRefused classfortooltip" title="' . $langs -> trans ( " DisabledBecauseRemainderToPayIsZero " ) . '">' . $langs -> trans ( 'DoPayment' ) . '</span></div>' ;
2015-06-16 06:56:58 +02:00
}
else
{
2015-06-17 07:19:25 +02:00
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>' ;
2015-06-16 06:56:58 +02:00
}
2015-08-28 20:11:16 +02:00
}
2017-06-11 10:37:58 +02:00
2017-05-28 06:49:17 +02:00
// If bank module is not used
2015-08-28 20:11:16 +02:00
if (( $user -> rights -> expensereport -> to_paid || empty ( $conf -> banque -> enabled )) && $object -> fk_statut == 5 )
{
2016-12-02 14:52:38 +01:00
//if ((round($remaintopay) == 0 || empty($conf->banque->enabled)) && $object->paid == 0)
if ( $object -> paid == 0 )
2015-06-18 06:12:05 +02:00
{
2015-06-21 08:07:06 +02:00
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=set_paid">' . $langs -> trans ( " ClassifyPaid " ) . " </a></div> " ;
2015-06-18 06:12:05 +02:00
}
2015-02-14 18:39:45 +01:00
}
2017-06-11 10:37:58 +02:00
2016-07-28 20:00:56 +02:00
if ( $user -> rights -> expensereport -> creer && ( $user -> id == $object -> fk_user_author || $user -> id == $object -> fk_user_valid ) && $object -> fk_statut == 5 )
2015-02-14 18:39:45 +01:00
{
2016-07-28 20:00:56 +02:00
// Cancel
2016-08-30 07:02:44 +02:00
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?action=cancel&id=' . $object -> id . '">' . $langs -> trans ( 'Cancel' ) . '</a></div>' ;
2015-02-14 18:39:45 +01:00
}
2017-06-11 10:37:58 +02:00
2016-07-28 20:00:56 +02:00
// TODO Replace this. It should be SetUnpaid and should go back to status unpaid not canceled.
if (( $user -> rights -> expensereport -> approve || $user -> rights -> expensereport -> to_paid ) && $object -> fk_statut == 6 )
2015-02-14 18:39:45 +01:00
{
2016-07-28 20:00:56 +02:00
// Cancel
2016-08-30 07:02:44 +02:00
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?action=cancel&id=' . $object -> id . '">' . $langs -> trans ( 'Cancel' ) . '</a></div>' ;
2016-07-28 20:00:56 +02:00
}
2017-06-11 10:37:58 +02:00
2016-11-13 22:00:57 +01:00
// Clone
if ( $user -> rights -> expensereport -> creer ) {
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '&action=clone">' . $langs -> trans ( " ToClone " ) . '</a></div>' ;
}
2017-06-11 10:37:58 +02:00
/* If draft, validated, cancel, and user can create, he can always delete its card before it is approved */
2016-07-28 20:00:56 +02:00
if ( $user -> rights -> expensereport -> creer && $user -> id == $object -> fk_user_author && $object -> fk_statut <= 4 )
{
// Delete
2016-08-30 07:02:44 +02:00
print '<div class="inline-block divButAction"><a class="butActionDelete" href="' . $_SERVER [ " PHP_SELF " ] . '?action=delete&id=' . $object -> id . '">' . $langs -> trans ( 'Delete' ) . '</a></div>' ;
2015-02-14 18:39:45 +01:00
}
2016-07-28 20:00:56 +02:00
else if ( $user -> rights -> expensereport -> supprimer && $object -> fk_statut != 6 )
{
// Delete
2016-08-30 07:02:44 +02:00
print '<div class="inline-block divButAction"><a class="butActionDelete" href="' . $_SERVER [ " PHP_SELF " ] . '?action=delete&id=' . $object -> id . '">' . $langs -> trans ( 'Delete' ) . '</a></div>' ;
2016-07-28 20:00:56 +02:00
}
2017-06-15 11:08:53 +02:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'addMoreActionsButtons' , $parameters , $object , $action ); // Note that $action and $object may have been
2015-02-14 18:39:45 +01:00
}
print '</div>' ;
2015-02-21 12:57:17 +01:00
//$conf->global->DOL_URL_ROOT_DOCUMENT_PHP=dol_buildpath('/expensereport/documentwrapper.php',1);
2015-02-14 18:39:45 +01:00
2017-09-17 15:38:50 +02:00
// Select mail models is same action as presend
2018-03-10 15:52:11 +01:00
if ( GETPOST ( 'modelselected' , 'alpha' )) {
2017-09-17 15:38:50 +02:00
$action = 'presend' ;
}
2016-09-06 13:39:44 +02:00
2017-09-17 15:38:50 +02:00
if ( $action != 'presend' )
2015-02-14 18:39:45 +01:00
{
2017-09-17 15:38:50 +02:00
/*
* Generate documents
*/
2015-02-14 18:39:45 +01:00
2017-11-14 08:48:41 +01:00
print '<div class="fichecenter"><div class="fichehalfleft">' ;
print '<a name="builddoc"></a>' ; // ancre
if ( $user -> rights -> expensereport -> creer && $action != 'create' && $action != 'edit' )
2017-09-17 15:38:50 +02:00
{
$filename = dol_sanitizeFileName ( $object -> ref );
$filedir = $conf -> expensereport -> dir_output . " / " . dol_sanitizeFileName ( $object -> ref );
$urlsource = $_SERVER [ " PHP_SELF " ] . " ?id= " . $object -> id ;
2017-11-14 08:48:41 +01:00
$genallowed = $user -> rights -> expensereport -> creer ;
$delallowed = $user -> rights -> expensereport -> creer ;
2017-09-17 15:38:50 +02:00
$var = true ;
2017-11-14 08:48:41 +01:00
print $formfile -> showdocuments ( 'expensereport' , $filename , $filedir , $urlsource , $genallowed , $delallowed );
2017-09-17 15:38:50 +02:00
$somethingshown = $formfile -> numoffiles ;
}
2017-06-11 10:37:58 +02:00
2017-09-17 15:38:50 +02:00
if ( $action != 'create' && $action != 'edit' && ( $id || $ref ))
{
2017-11-14 08:48:41 +01:00
$linktoelem = $form -> showLinkToObjectBlock ( $object , null , array ( 'expensereport' ));
$somethingshown = $form -> showLinkedObjectBlock ( $object , $linktoelem );
2017-09-17 15:38:50 +02:00
}
2017-11-14 08:48:41 +01:00
print '</div><div class="fichehalfright"><div class="ficheaddleft">' ;
// List of actions on element
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php' ;
$formactions = new FormActions ( $db );
$somethingshown = $formactions -> showactions ( $object , 'expensereport' , null );
print '</div></div></div>' ;
2016-01-31 18:56:05 +01:00
}
2016-08-05 15:30:28 +02:00
2017-09-17 15:38:50 +02:00
// Presend form
$modelmail = 'expensereport' ;
$defaulttopic = 'SendExpenseReportRef' ;
$diroutput = $conf -> expensereport -> dir_output ;
$trackid = 'exp' . $object -> id ;
include DOL_DOCUMENT_ROOT . '/core/tpl/card_presend.tpl.php' ;
2015-02-14 18:39:45 +01:00
llxFooter ();
$db -> close ();