diff --git a/htdocs/expensereport/ajax/ajaxik.php b/htdocs/expensereport/ajax/ajaxik.php index 413bc061fbf..72c38959ef8 100644 --- a/htdocs/expensereport/ajax/ajaxik.php +++ b/htdocs/expensereport/ajax/ajaxik.php @@ -22,12 +22,24 @@ * \brief File to return Ajax response on third parties request */ -if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', 1); // Disables token renewal -if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); -if (!defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); -if (!defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); -if (!defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); -if (!defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); +if (!defined('NOTOKENRENEWAL')) { + define('NOTOKENRENEWAL', 1); // Disables token renewal +} +if (!defined('NOREQUIREMENU')) { + define('NOREQUIREMENU', '1'); +} +if (!defined('NOREQUIREHTML')) { + define('NOREQUIREHTML', '1'); +} +if (!defined('NOREQUIREAJAX')) { + define('NOREQUIREAJAX', '1'); +} +if (!defined('NOREQUIRESOC')) { + define('NOREQUIRESOC', '1'); +} +if (!defined('NOCSRFCHECK')) { + define('NOCSRFCHECK', '1'); +} $res = 0; require '../../main.inc.php'; @@ -50,20 +62,25 @@ $fk_expense = GETPOST('fk_expense'); $fk_c_exp_tax_cat = GETPOST('fk_c_exp_tax_cat'); -if (empty($fk_expense) || $fk_expense < 0) echo json_encode(array('error' => $langs->transnoentitiesnoconv('ErrorBadValueForParameter', $fk_expense, 'fk_expense'))); -elseif (empty($fk_c_exp_tax_cat) || $fk_c_exp_tax_cat < 0) echo json_encode(array('error' => $langs->transnoentitiesnoconv('ErrorBadValueForParameter', $fk_c_exp_tax_cat, 'fk_c_exp_tax_cat'))); -else { +if (empty($fk_expense) || $fk_expense < 0) { + echo json_encode(array('error' => $langs->transnoentitiesnoconv('ErrorBadValueForParameter', $fk_expense, 'fk_expense'))); +} elseif (empty($fk_c_exp_tax_cat) || $fk_c_exp_tax_cat < 0) { + echo json_encode(array('error' => $langs->transnoentitiesnoconv('ErrorBadValueForParameter', $fk_c_exp_tax_cat, 'fk_c_exp_tax_cat'))); +} else { // @see ndfp.class.php:3576 (method: compute_total_km) $expense = new ExpenseReport($db); - if ($expense->fetch($fk_expense) <= 0) echo json_encode(array('error' => $langs->transnoentitiesnoconv('ErrorRecordNotFound'), 'fk_expense' => $fk_expense)); - else { + if ($expense->fetch($fk_expense) <= 0) { + echo json_encode(array('error' => $langs->transnoentitiesnoconv('ErrorRecordNotFound'), 'fk_expense' => $fk_expense)); + } else { $userauthor = new User($db); - if ($userauthor->fetch($expense->fk_user_author) <= 0) echo json_encode(array('error' => $langs->transnoentitiesnoconv('ErrorRecordNotFound'), 'fk_user_author' => $expense->fk_user_author)); - else { + if ($userauthor->fetch($expense->fk_user_author) <= 0) { + echo json_encode(array('error' => $langs->transnoentitiesnoconv('ErrorRecordNotFound'), 'fk_user_author' => $expense->fk_user_author)); + } else { $range = ExpenseReportIk::getRangeByUser($userauthor, $fk_c_exp_tax_cat); - if (empty($range)) echo json_encode(array('error' => $langs->transnoentitiesnoconv('ErrorRecordNotFound'), 'range' => $range)); - else { + if (empty($range)) { + echo json_encode(array('error' => $langs->transnoentitiesnoconv('ErrorRecordNotFound'), 'range' => $range)); + } else { $ikoffset = price($range->ikoffset, 0, $langs, 1, -1, -1, $conf->currency); echo json_encode(array('up' => $range->coef, 'ikoffset' => $range->ikoffset, 'title' => $langs->transnoentitiesnoconv('ExpenseRangeOffset', $offset), 'comment' => 'offset should be apply on addline or updateline')); } diff --git a/htdocs/expensereport/ajax/ajaxprojet.php b/htdocs/expensereport/ajax/ajaxprojet.php index 62ceb504dac..8549d62fa62 100644 --- a/htdocs/expensereport/ajax/ajaxprojet.php +++ b/htdocs/expensereport/ajax/ajaxprojet.php @@ -24,12 +24,24 @@ * \brief File to return Ajax response on third parties request */ -if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', 1); // Disables token renewal -if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); -if (!defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); -if (!defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); -if (!defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); -if (!defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); +if (!defined('NOTOKENRENEWAL')) { + define('NOTOKENRENEWAL', 1); // Disables token renewal +} +if (!defined('NOREQUIREMENU')) { + define('NOREQUIREMENU', '1'); +} +if (!defined('NOREQUIREHTML')) { + define('NOREQUIREHTML', '1'); +} +if (!defined('NOREQUIREAJAX')) { + define('NOREQUIREAJAX', '1'); +} +if (!defined('NOREQUIRESOC')) { + define('NOREQUIRESOC', '1'); +} +if (!defined('NOCSRFCHECK')) { + define('NOCSRFCHECK', '1'); +} $res = 0; require '../../main.inc.php'; @@ -52,21 +64,20 @@ dol_syslog(join(',', $_GET)); // Generation liste des projets -if (GETPOST('fk_projet') != '') -{ +if (GETPOST('fk_projet') != '') { $return_arr = array(); $sql = "SELECT p.rowid, p.ref, p.title, s.nom"; $sql .= " FROM ".MAIN_DB_PREFIX."projet as p"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON p.fk_soc = s.rowid"; - if (!empty($_GET["fk_projet"])) $sql .= " WHERE p.ref LIKE '%".$db->escape($_GET["fk_projet"])."%' OR p.title LIKE '%".$db->escape($_GET["fk_projet"])."%' OR s.nom LIKE '%".$db->escape($_GET["fk_projet"])."%'"; // Add other filters + if (!empty($_GET["fk_projet"])) { + $sql .= " WHERE p.ref LIKE '%".$db->escape($_GET["fk_projet"])."%' OR p.title LIKE '%".$db->escape($_GET["fk_projet"])."%' OR s.nom LIKE '%".$db->escape($_GET["fk_projet"])."%'"; // Add other filters + } $sql .= " ORDER BY p.ref ASC"; $resql = $db->query($sql); - if ($resql) - { - while ($row = $db->fetch_array($resql)) - { + if ($resql) { + while ($row = $db->fetch_array($resql)) { $label = $row['ref'].' - '.$row['title']; $row_array['label'] = $label; $row_array['value'] = $label; diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index f41f2902e71..70db8856327 100644 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -69,7 +69,9 @@ $childids = $user->getAllChildIds(1); // Security check $id = GETPOST("id", 'int'); -if ($user->socid) $socid = $user->socid; +if ($user->socid) { + $socid = $user->socid; +} $result = restrictedArea($user, 'expensereport', $id, 'expensereport'); @@ -77,8 +79,7 @@ $result = restrictedArea($user, 'expensereport', $id, 'expensereport'); $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) -{ +if (!empty($conf->multicompany->enabled) && !empty($conf->entity) && $conf->entity > 1) { $rootfordata .= '/'.$conf->entity; } $conf->expensereport->dir_output = $rootfordata.'/expensereport'; @@ -114,14 +115,16 @@ $permissiontoadd = $user->rights->expensereport->creer; // Used by the include o $upload_dir = $conf->expensereport->dir_output.'/'.dol_sanitizeFileName($object->ref); -if ($object->id > 0) -{ +if ($object->id > 0) { // Check current user can read this expense report $canread = 0; - if (!empty($user->rights->expensereport->readall)) $canread = 1; - if (!empty($user->rights->expensereport->lire) && in_array($object->fk_user_author, $childids)) $canread = 1; - if (!$canread) - { + if (!empty($user->rights->expensereport->readall)) { + $canread = 1; + } + if (!empty($user->rights->expensereport->lire) && in_array($object->fk_user_author, $childids)) { + $canread = 1; + } + if (!$canread) { accessforbidden(); } } @@ -133,14 +136,13 @@ if ($object->id > 0) $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'); +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} -if (empty($reshook)) -{ - if ($cancel) - { - if (!empty($backtopage)) - { +if (empty($reshook)) { + if ($cancel) { + if (!empty($backtopage)) { header("Location: ".$backtopage); exit; } @@ -160,10 +162,12 @@ if (empty($reshook)) include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php'; - if (GETPOSTISSET('sendit')) // If we just submit a file - { - if ($action == 'updateline') $action = 'editline'; // To avoid to make the updateline now - else $action = ''; // To avoid to make the addline now + if (GETPOSTISSET('sendit')) { // If we just submit a file + if ($action == 'updateline') { + $action = 'editline'; // To avoid to make the updateline now + } else { + $action = ''; // To avoid to make the addline now + } } include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once @@ -173,20 +177,16 @@ if (empty($reshook)) 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) - { - if (1 == 0 && !GETPOST('clone_content', 'alpha') && !GETPOST('clone_receivers', 'alpha')) - { + if ($action == 'confirm_clone' && $confirm == 'yes' && $user->rights->expensereport->creer) { + if (1 == 0 && !GETPOST('clone_content', 'alpha') && !GETPOST('clone_receivers', 'alpha')) { setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors'); } else { - if ($object->id > 0) - { + if ($object->id > 0) { // Because createFromClone modifies the object, we must clone it so that we can restore it later if it fails $orig = clone $object; $result = $object->createFromClone($user, GETPOST('fk_user_author', 'int')); - if ($result > 0) - { + if ($result > 0) { header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result); exit; } else { @@ -198,13 +198,11 @@ if (empty($reshook)) } } - if ($action == 'confirm_delete' && GETPOST("confirm", 'alpha') == "yes" && $id > 0 && $user->rights->expensereport->supprimer) - { + if ($action == 'confirm_delete' && GETPOST("confirm", 'alpha') == "yes" && $id > 0 && $user->rights->expensereport->supprimer) { $object = new ExpenseReport($db); $result = $object->fetch($id); $result = $object->delete($user); - if ($result >= 0) - { + if ($result >= 0) { header("Location: index.php"); exit; } else { @@ -212,8 +210,7 @@ if (empty($reshook)) } } - if ($action == 'add' && $user->rights->expensereport->creer) - { + if ($action == 'add' && $user->rights->expensereport->creer) { $error = 0; $object = new ExpenseReport($db); @@ -222,7 +219,9 @@ if (empty($reshook)) $object->date_fin = $date_end; $object->fk_user_author = GETPOST('fk_user_author', 'int'); - if (!($object->fk_user_author > 0)) $object->fk_user_author = $user->id; + if (!($object->fk_user_author > 0)) { + $object->fk_user_author = $user->id; + } // Check that expense report is for a user inside the hierarchy or advanced permission for all is set if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->expensereport->creer)) @@ -248,31 +247,28 @@ if (empty($reshook)) $object->note_public = GETPOST('note_public', 'restricthtml'); $object->note_private = GETPOST('note_private', 'restricthtml'); // Fill array 'array_options' with data from add form - if (!$error) - { + if (!$error) { $ret = $extrafields->setOptionalsFromPost(null, $object); - if ($ret < 0) $error++; + if ($ret < 0) { + $error++; + } } - if (!$error && empty($conf->global->EXPENSEREPORT_ALLOW_OVERLAPPING_PERIODS) && $object->periode_existe($fuser, $object->date_debut, $object->date_fin)) - { + if (!$error && empty($conf->global->EXPENSEREPORT_ALLOW_OVERLAPPING_PERIODS) && $object->periode_existe($fuser, $object->date_debut, $object->date_fin)) { $error++; setEventMessages($langs->trans("ErrorDoubleDeclaration"), null, 'errors'); $action = 'create'; } - if (!$error) - { + if (!$error) { $db->begin(); $id = $object->create($user); - if ($id <= 0) - { + if ($id <= 0) { $error++; } - if (!$error) - { + if (!$error) { $db->commit(); Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); exit; @@ -284,16 +280,14 @@ if (empty($reshook)) } } - if ($action == 'update' && $user->rights->expensereport->creer) - { + if ($action == 'update' && $user->rights->expensereport->creer) { $object = new ExpenseReport($db); $object->fetch($id); $object->date_debut = $date_start; $object->date_fin = $date_end; - if ($object->status < 3) - { + if ($object->status < 3) { $object->fk_user_validator = GETPOST('fk_user_validator', 'int'); } @@ -303,8 +297,7 @@ if (empty($reshook)) $object->fk_user_modif = $user->id; $result = $object->update($user); - if ($result > 0) - { + if ($result > 0) { header("Location: ".$_SERVER["PHP_SELF"]."?id=".GETPOST('id', 'int')); exit; } else { @@ -312,31 +305,30 @@ if (empty($reshook)) } } - if ($action == 'update_extras') - { + if ($action == 'update_extras') { $object->oldcopy = dol_clone($object); // Fill array 'array_options' with data from update form $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml')); - if ($ret < 0) $error++; + if ($ret < 0) { + $error++; + } - if (!$error) - { + if (!$error) { // Actions on extra fields - $result = $object->insertExtraFields('EXPENSEREPORT_MODIFY'); - if ($result < 0) - { + $result = $object->insertExtraFields('EXPENSEREPORT_MODIFY'); + if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); $error++; } } - if ($error) + if ($error) { $action = 'edit_extras'; + } } - if ($action == "confirm_validate" && GETPOST("confirm", 'alpha') == "yes" && $id > 0 && $user->rights->expensereport->creer) - { + if ($action == "confirm_validate" && GETPOST("confirm", 'alpha') == "yes" && $id > 0 && $user->rights->expensereport->creer) { $error = 0; $db->begin(); @@ -346,15 +338,17 @@ if (empty($reshook)) $result = $object->setValidate($user); - if ($result >= 0) - { + if ($result >= 0) { // Define output language - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { + 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 ($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); @@ -369,8 +363,7 @@ if (empty($reshook)) $error++; } - if (!$error && $result > 0 && $object->fk_user_validator > 0) - { + if (!$error && $result > 0 && $object->fk_user_validator > 0) { $langs->load("mails"); // TO @@ -383,13 +376,14 @@ if (empty($reshook)) $expediteur->fetch($object->fk_user_author); $emailFrom = $expediteur->email; - if ($emailTo && $emailFrom) - { + if ($emailTo && $emailFrom) { $filename = array(); $filedir = array(); $mimetype = array(); // SUBJECT $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM; - if (!empty($conf->global->MAIN_APPLICATION_TITLE)) $societeName = $conf->global->MAIN_APPLICATION_TITLE; + if (!empty($conf->global->MAIN_APPLICATION_TITLE)) { + $societeName = $conf->global->MAIN_APPLICATION_TITLE; + } $subject = $societeName." - ".$langs->transnoentities("ExpenseReportWaitingForApproval"); @@ -400,31 +394,28 @@ if (empty($reshook)) // Rebuild pdf /* - $object->setDocModel($user,""); - $resultPDF = expensereport_pdf_create($db,$id,'',"",$langs); + $object->setDocModel($user,""); + $resultPDF = expensereport_pdf_create($db,$id,'',"",$langs); - 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"); - */ + 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"); + */ // PREPARE SEND $mailfile = new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, '', '', 0, -1); - if ($mailfile) - { + if ($mailfile) { // SEND $result = $mailfile->sendfile(); - if ($result) - { + 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) - { + if ($mailfile->error) { $mesg = ''; $mesg .= $langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo); $mesg .= '
'.$mailfile->error; @@ -443,8 +434,7 @@ if (empty($reshook)) } } - if (!$error) - { + if (!$error) { $db->commit(); header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); exit; @@ -453,21 +443,22 @@ if (empty($reshook)) } } - if ($action == "confirm_save_from_refuse" && GETPOST("confirm", 'alpha') == "yes" && $id > 0 && $user->rights->expensereport->creer) - { + if ($action == "confirm_save_from_refuse" && GETPOST("confirm", 'alpha') == "yes" && $id > 0 && $user->rights->expensereport->creer) { $object = new ExpenseReport($db); $object->fetch($id); $result = $object->set_save_from_refuse($user); - if ($result > 0) - { + if ($result > 0) { // Define output language - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { + 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 ($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); @@ -479,27 +470,27 @@ if (empty($reshook)) } } - if ($result > 0) - { + if ($result > 0) { // Send mail - // TO - $destinataire = new User($db); - $destinataire->fetch($object->fk_user_validator); - $emailTo = $destinataire->email; + // TO + $destinataire = new User($db); + $destinataire->fetch($object->fk_user_validator); + $emailTo = $destinataire->email; // FROM $expediteur = new User($db); $expediteur->fetch($object->fk_user_author); $emailFrom = $expediteur->email; - if ($emailFrom && $emailTo) - { + if ($emailFrom && $emailTo) { $filename = array(); $filedir = array(); $mimetype = array(); - // SUBJECT + // SUBJECT $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM; - if (!empty($conf->global->MAIN_APPLICATION_TITLE)) $societeName = $conf->global->MAIN_APPLICATION_TITLE; + if (!empty($conf->global->MAIN_APPLICATION_TITLE)) { + $societeName = $conf->global->MAIN_APPLICATION_TITLE; + } $subject = $societeName." - ".$langs->transnoentities("ExpenseReportWaitingForReApproval"); @@ -509,18 +500,18 @@ if (empty($reshook)) $dateRefusEx = explode(" ", $object->date_refuse); $message = $langs->transnoentities("ExpenseReportWaitingForReApprovalMessage", $dateRefusEx[0], $object->detail_refuse, $expediteur->getFullName($langs), $link); - // Rebuild pdf + // 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"); + 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"); } */ @@ -528,20 +519,17 @@ if (empty($reshook)) // PREPARE SEND $mailfile = new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, '', '', 0, -1); - if ($mailfile) - { + if ($mailfile) { // SEND $result = $mailfile->sendfile(); - if ($result) - { + 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) - { + if ($mailfile->error) { $mesg = ''; $mesg .= $langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo); $mesg .= '
'.$mailfile->error; @@ -564,22 +552,23 @@ if (empty($reshook)) } // Approve - if ($action == "confirm_approve" && GETPOST("confirm", 'alpha') == "yes" && $id > 0 && $user->rights->expensereport->approve) - { + if ($action == "confirm_approve" && GETPOST("confirm", 'alpha') == "yes" && $id > 0 && $user->rights->expensereport->approve) { $object = new ExpenseReport($db); $object->fetch($id); $result = $object->setApproved($user); - if ($result > 0) - { + if ($result > 0) { // Define output language - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { + 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 ($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); @@ -591,109 +580,109 @@ if (empty($reshook)) } } - if ($result > 0) - { + if ($result > 0) { // Send mail - // TO - $destinataire = new User($db); - $destinataire->fetch($object->fk_user_author); - $emailTo = $destinataire->email; + // TO + $destinataire = new User($db); + $destinataire->fetch($object->fk_user_author); + $emailTo = $destinataire->email; - // CC - $emailCC = $conf->global->NDF_CC_EMAILS; - if (empty($emailTo)) $emailTo = $emailCC; + // CC + $emailCC = $conf->global->NDF_CC_EMAILS; + if (empty($emailTo)) { + $emailTo = $emailCC; + } // FROM - $expediteur = new User($db); - $expediteur->fetch($object->fk_user_approve > 0 ? $object->fk_user_approve : $object->fk_user_validator); - $emailFrom = $expediteur->email; + $expediteur = new User($db); + $expediteur->fetch($object->fk_user_approve > 0 ? $object->fk_user_approve : $object->fk_user_validator); + $emailFrom = $expediteur->email; - if ($emailFrom && $emailTo) - { + if ($emailFrom && $emailTo) { $filename = array(); $filedir = array(); $mimetype = array(); - // SUBJECT + // SUBJECT $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM; - if (!empty($conf->global->MAIN_APPLICATION_TITLE)) $societeName = $conf->global->MAIN_APPLICATION_TITLE; + if (!empty($conf->global->MAIN_APPLICATION_TITLE)) { + $societeName = $conf->global->MAIN_APPLICATION_TITLE; + } $subject = $societeName." - ".$langs->transnoentities("ExpenseReportApproved"); - // CONTENT - $link = $urlwithroot.'/expensereport/card.php?id='.$object->id; + // CONTENT + $link = $urlwithroot.'/expensereport/card.php?id='.$object->id; $link = ''.$link.''; - $message = $langs->transnoentities("ExpenseReportApprovedMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $link); + $message = $langs->transnoentities("ExpenseReportApprovedMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $link); - // Rebuilt pdf + // Rebuilt pdf /* - $object->setDocModel($user,""); - $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs); + $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"); - } - */ + 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"); + } + */ $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 .= '
'.$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 { + 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 .= '
'.$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("FailedtoSetToApprove"), null, 'warnings'); - $action = ''; - } - } + setEventMessages($langs->trans("FailedtoSetToApprove"), null, 'warnings'); + $action = ''; + } + } - if ($action == "confirm_refuse" && GETPOST('confirm', 'alpha') == "yes" && $id > 0 && $user->rights->expensereport->approve) - { + if ($action == "confirm_refuse" && GETPOST('confirm', 'alpha') == "yes" && $id > 0 && $user->rights->expensereport->approve) { $object = new ExpenseReport($db); $object->fetch($id); $detailRefuse = GETPOST('detail_refuse', 'alpha'); $result = $object->setDeny($user, $detailRefuse); - if ($result > 0) - { + if ($result > 0) { // Define output language - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { + 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 ($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); @@ -705,8 +694,7 @@ if (empty($reshook)) } } - if ($result > 0) - { + if ($result > 0) { // Send mail // TO @@ -719,53 +707,51 @@ if (empty($reshook)) $expediteur->fetch($object->fk_user_refuse); $emailFrom = $expediteur->email; - if ($emailFrom && $emailTo) - { + if ($emailFrom && $emailTo) { $filename = array(); $filedir = array(); $mimetype = array(); // SUBJECT $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM; - if (!empty($conf->global->MAIN_APPLICATION_TITLE)) $societeName = $conf->global->MAIN_APPLICATION_TITLE; + if (!empty($conf->global->MAIN_APPLICATION_TITLE)) { + $societeName = $conf->global->MAIN_APPLICATION_TITLE; + } $subject = $societeName." - ".$langs->transnoentities("ExpenseReportRefused"); - // CONTENT - $link = $urlwithroot.'/expensereport/card.php?id='.$object->id; + // CONTENT + $link = $urlwithroot.'/expensereport/card.php?id='.$object->id; $link = ''.$link.''; $message = $langs->transnoentities("ExpenseReportRefusedMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $detailRefuse, $link); - // Rebuilt pdf + // Rebuilt pdf /* - $object->setDocModel($user,""); - $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs); + $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"); - } - */ + 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) - { + if ($mailfile) { // SEND $result = $mailfile->sendfile(); - if ($result) - { + 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) - { + if ($mailfile->error) { $mesg = ''; $mesg .= $langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo); $mesg .= '
'.$mailfile->error; @@ -789,29 +775,28 @@ if (empty($reshook)) } //var_dump($user->id == $object->fk_user_validator);exit; - if ($action == "confirm_cancel" && GETPOST('confirm', 'alpha') == "yes" && $id > 0 && $user->rights->expensereport->creer) - { - if (!GETPOST('detail_cancel', 'alpha')) - { + if ($action == "confirm_cancel" && GETPOST('confirm', 'alpha') == "yes" && $id > 0 && $user->rights->expensereport->creer) { + if (!GETPOST('detail_cancel', 'alpha')) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Comment")), null, 'errors'); } else { $object = new ExpenseReport($db); $object->fetch($id); - if ($user->id == $object->fk_user_valid || $user->id == $object->fk_user_author) - { + if ($user->id == $object->fk_user_valid || $user->id == $object->fk_user_author) { $detailCancel = GETPOST('detail_cancel', 'alpha'); $result = $object->set_cancel($user, $detailCancel); - if ($result > 0) - { + if ($result > 0) { // Define output language - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { + 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 ($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); @@ -823,8 +808,7 @@ if (empty($reshook)) } } - if ($result > 0) - { + if ($result > 0) { // Send mail // TO @@ -837,13 +821,14 @@ if (empty($reshook)) $expediteur->fetch($object->fk_user_cancel); $emailFrom = $expediteur->email; - if ($emailFrom && $emailTo) - { + if ($emailFrom && $emailTo) { $filename = array(); $filedir = array(); $mimetype = array(); // SUBJECT $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM; - if (!empty($conf->global->MAIN_APPLICATION_TITLE)) $societeName = $conf->global->MAIN_APPLICATION_TITLE; + if (!empty($conf->global->MAIN_APPLICATION_TITLE)) { + $societeName = $conf->global->MAIN_APPLICATION_TITLE; + } $subject = $societeName." - ".$langs->transnoentities("ExpenseReportCanceled"); @@ -854,36 +839,33 @@ if (empty($reshook)) // Rebuilt pdf /* - $object->setDocModel($user,""); - $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs); + $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"); - } - */ + 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) - { + if ($mailfile) { // SEND $result = $mailfile->sendfile(); - if ($result) - { + 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) - { + if ($mailfile->error) { $mesg = ''; $mesg .= $langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo); $mesg .= '
'.$mailfile->error; @@ -910,23 +892,23 @@ if (empty($reshook)) } } - if ($action == "confirm_setdraft" && GETPOST('confirm', 'alpha') == "yes" && $id > 0 && $user->rights->expensereport->creer) - { + if ($action == "confirm_setdraft" && GETPOST('confirm', 'alpha') == "yes" && $id > 0 && $user->rights->expensereport->creer) { $object = new ExpenseReport($db); $object->fetch($id); - if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) - { + if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) { $result = $object->setStatut(0); - if ($result > 0) - { + if ($result > 0) { // Define output language - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { + 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 ($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); @@ -938,8 +920,7 @@ if (empty($reshook)) } } - if ($result > 0) - { + if ($result > 0) { header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); exit; } else { @@ -950,22 +931,23 @@ if (empty($reshook)) } } - if ($action == 'set_unpaid' && $id > 0 && $user->rights->expensereport->to_paid) - { + if ($action == 'set_unpaid' && $id > 0 && $user->rights->expensereport->to_paid) { $object = new ExpenseReport($db); $object->fetch($id); $result = $object->setUnpaid($user); - if ($result > 0) - { + if ($result > 0) { // Define output language - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { + 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 ($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); @@ -978,22 +960,23 @@ if (empty($reshook)) } } - if ($action == 'set_paid' && $id > 0 && $user->rights->expensereport->to_paid) - { + if ($action == 'set_paid' && $id > 0 && $user->rights->expensereport->to_paid) { $object = new ExpenseReport($db); $object->fetch($id); $result = $object->setPaid($id, $user); - if ($result > 0) - { + if ($result > 0) { // Define output language - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { + 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 ($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); @@ -1005,8 +988,7 @@ if (empty($reshook)) } } - if ($result > 0) - { + if ($result > 0) { // Send mail // TO @@ -1019,13 +1001,14 @@ if (empty($reshook)) $expediteur->fetch($user->id); $emailFrom = $expediteur->email; - if ($emailFrom && $emailTo) - { + if ($emailFrom && $emailTo) { $filename = array(); $filedir = array(); $mimetype = array(); // SUBJECT $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM; - if (!empty($conf->global->MAIN_APPLICATION_TITLE)) $societeName = $conf->global->MAIN_APPLICATION_TITLE; + if (!empty($conf->global->MAIN_APPLICATION_TITLE)) { + $societeName = $conf->global->MAIN_APPLICATION_TITLE; + } $subject = $societeName." - ".$langs->transnoentities("ExpenseReportPaid"); @@ -1041,20 +1024,17 @@ if (empty($reshook)) // PREPARE SEND $mailfile = new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, '', '', 0, -1); - if ($mailfile) - { + if ($mailfile) { // SEND $result = $mailfile->sendfile(); - if ($result) - { + 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) - { + if ($mailfile->error) { $mesg = ''; $mesg .= $langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo); $mesg .= '
'.$mailfile->error; @@ -1077,17 +1057,14 @@ if (empty($reshook)) } } - if ($action == "addline" && $user->rights->expensereport->creer) - { + if ($action == "addline" && $user->rights->expensereport->creer) { $error = 0; // First save uploaded file $fk_ecm_files = 0; - if (GETPOSTISSET('attachfile')) - { + if (GETPOSTISSET('attachfile')) { $arrayoffiles = GETPOST('attachfile', 'array'); - if (is_array($arrayoffiles) && !empty($arrayoffiles[0])) - { + if (is_array($arrayoffiles) && !empty($arrayoffiles[0])) { include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; $relativepath = 'expensereport/'.$object->ref.'/'.$arrayoffiles[0]; $ecmfiles = new EcmFiles($db); @@ -1097,70 +1074,67 @@ if (empty($reshook)) } // if VAT is not used in Dolibarr, set VAT rate to 0 because VAT rate is necessary. - if (empty($vatrate)) $vatrate = "0.000"; + if (empty($vatrate)) { + $vatrate = "0.000"; + } $tmpvat = price2num(preg_replace('/\s*\(.*\)/', '', $vatrate)); $value_unit_ht = price2num(GETPOST('value_unit_ht', 'alpha'), 'MU'); $value_unit = price2num(GETPOST('value_unit', 'alpha'), 'MU'); - if (empty($value_unit)) - { + if (empty($value_unit)) { $value_unit = price2num($value_unit_ht + ($value_unit_ht * $tmpvat / 100), 'MU'); } $fk_c_exp_tax_cat = GETPOST('fk_c_exp_tax_cat', 'int'); $qty = GETPOST('qty', 'int'); - if (empty($qty)) $qty = 1; + if (empty($qty)) { + $qty = 1; + } - if (!($fk_c_type_fees > 0)) - { + if (!($fk_c_type_fees > 0)) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors'); $action = ''; } - if ((int) $tmpvat < 0 || $tmpvat == '') - { + if ((int) $tmpvat < 0 || $tmpvat == '') { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("VAT")), null, 'errors'); $action = ''; } // Si aucune date n'est rentrée - if (empty($date) || $date == "--") - { + if (empty($date) || $date == "--") { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors'); } // Si aucun prix n'est rentré - if ($value_unit == 0) - { + if ($value_unit == 0) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PriceUTTC")), null, 'errors'); } // Warning if date out of range - if ($date < $object->date_debut || $date > ($object->date_fin + (24 * 3600 - 1))) - { + if ($date < $object->date_debut || $date > ($object->date_fin + (24 * 3600 - 1))) { $langs->load("errors"); setEventMessages($langs->trans("WarningDateOfLineMustBeInExpenseReportRange"), null, 'warnings'); } - if (!$error) - { + if (!$error) { $type = 0; // TODO What if service ? We should take the type product/service from the type of expense report llx_c_type_fees // Insert line $result = $object->addline($qty, $value_unit, $fk_c_type_fees, $vatrate, $date, $comments, $fk_project, $fk_c_exp_tax_cat, $type, $fk_ecm_files); - if ($result > 0) - { + 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)) + if (!empty($conf->global->MAIN_MULTILANGS) && empty($newlang)) { $newlang = $object->thirdparty->default_lang; + } if (!empty($newlang)) { $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang); @@ -1186,8 +1160,7 @@ if (empty($reshook)) $action = ''; } - if ($action == 'confirm_delete_line' && GETPOST("confirm", 'alpha') == "yes" && $user->rights->expensereport->creer) - { + if ($action == 'confirm_delete_line' && GETPOST("confirm", 'alpha') == "yes" && $user->rights->expensereport->creer) { $object = new ExpenseReport($db); $object->fetch($id); @@ -1197,17 +1170,18 @@ if (empty($reshook)) $total_tva = $object_ligne->total_tva; $result = $object->deleteline(GETPOST("rowid", 'int'), $user); - if ($result >= 0) - { - if ($result > 0) - { + if ($result >= 0) { + if ($result > 0) { // Define output language - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { + 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 ($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); @@ -1227,18 +1201,15 @@ if (empty($reshook)) } } - if ($action == "updateline" && $user->rights->expensereport->creer) - { + if ($action == "updateline" && $user->rights->expensereport->creer) { $object = new ExpenseReport($db); $object->fetch($id); // First save uploaded file $fk_ecm_files = 0; - if (GETPOSTISSET('attachfile')) - { + if (GETPOSTISSET('attachfile')) { $arrayoffiles = GETPOST('attachfile', 'array'); - if (is_array($arrayoffiles) && !empty($arrayoffiles[0])) - { + if (is_array($arrayoffiles) && !empty($arrayoffiles[0])) { include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; $relativepath = 'expensereport/'.$object->ref.'/'.$arrayoffiles[0]; $ecmfiles = new EcmFiles($db); @@ -1256,50 +1227,48 @@ if (empty($reshook)) $vatrate = GETPOST('vatrate', 'alpha'); // if VAT is not used in Dolibarr, set VAT rate to 0 because VAT rate is necessary. - if (empty($vatrate)) $vatrate = "0.000"; + if (empty($vatrate)) { + $vatrate = "0.000"; + } $tmpvat = price2num(preg_replace('/\s*\(.*\)/', '', $vatrate)); $value_unit_ht = price2num(GETPOST('value_unit_ht', 'alpha'), 'MU'); $value_unit = price2num(GETPOST('value_unit', 'alpha'), 'MU'); - if (empty($value_unit)) - { + if (empty($value_unit)) { $value_unit = price2num($value_unit_ht + ($value_unit_ht * $tmpvat / 100), 'MU'); } - if (!GETPOST('fk_c_type_fees', 'int') > 0) - { + if (!GETPOST('fk_c_type_fees', 'int') > 0) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors'); $action = ''; } - if ((int) $tmpvat < 0 || $tmpvat == '') - { + if ((int) $tmpvat < 0 || $tmpvat == '') { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Vat")), null, 'errors'); $action = ''; } // Warning if date out of range - if ($date < $object->date_debut || $date > ($object->date_fin + (24 * 3600 - 1))) - { + if ($date < $object->date_debut || $date > ($object->date_fin + (24 * 3600 - 1))) { $langs->load("errors"); setEventMessages($langs->trans("WarningDateOfLineMustBeInExpenseReportRange"), null, 'warnings'); } - if (!$error) - { + if (!$error) { // TODO Use update method of ExpenseReportLine $result = $object->updateline($rowid, $type_fees_id, $projet_id, $vatrate, $comments, $qty, $value_unit, $date, $id, $fk_c_exp_tax_cat, $fk_ecm_files); - if ($result >= 0) - { - if ($result > 0) - { + if ($result >= 0) { + if ($result > 0) { // Define output language - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { + 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 ($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); @@ -1356,8 +1325,7 @@ $ecmfilesstatic = new EcmFiles($db); $formexpensereport = new FormExpenseReport($db); // Create -if ($action == 'create') -{ +if ($action == 'create') { print load_fiche_titre($langs->trans("NewTrip"), '', 'trip'); print '
'; @@ -1390,9 +1358,13 @@ if ($action == 'create') print ''.$langs->trans("User").''; print ''; $defaultselectuser = $user->id; - if (GETPOST('fk_user_author', 'int') > 0) $defaultselectuser = GETPOST('fk_user_author', 'int'); + if (GETPOST('fk_user_author', 'int') > 0) { + $defaultselectuser = GETPOST('fk_user_author', 'int'); + } $include_users = 'hierarchyme'; - if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expensereport->writeall_advance)) $include_users = array(); + if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expensereport->writeall_advance)) { + $include_users = array(); + } $s = $form->select_dolusers($defaultselectuser, "fk_user_author", 0, "", 0, $include_users, '', '0,'.$conf->entity); print $s; print ''; @@ -1404,11 +1376,16 @@ if ($action == 'create') print ''; $object = new ExpenseReport($db); $include_users = $object->fetch_users_approver_expensereport(); - if (empty($include_users)) print img_warning().' '.$langs->trans("NobodyHasPermissionToValidateExpenseReport"); - else { + if (empty($include_users)) { + print img_warning().' '.$langs->trans("NobodyHasPermissionToValidateExpenseReport"); + } else { $defaultselectuser = (empty($user->fk_user_expense_validator) ? $user->fk_user : $user->fk_user_expense_validator); // 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 - if (GETPOST('fk_user_validator', 'int') > 0) $defaultselectuser = GETPOST('fk_user_validator', 'int'); + if (!empty($conf->global->EXPENSEREPORT_DEFAULT_VALIDATOR)) { + $defaultselectuser = $conf->global->EXPENSEREPORT_DEFAULT_VALIDATOR; // Can force default approver + } + if (GETPOST('fk_user_validator', 'int') > 0) { + $defaultselectuser = GETPOST('fk_user_validator', 'int'); + } $s = $form->select_dolusers($defaultselectuser, "fk_user_validator", 1, "", ((empty($defaultselectuser) || empty($conf->global->EXPENSEREPORT_DEFAULT_VALIDATOR_UNCHANGEABLE)) ? 0 : 1), $include_users); print $form->textwithpicto($s, $langs->trans("AnyOtherInThisListCanValidate")); } @@ -1416,8 +1393,7 @@ if ($action == 'create') print ''; // Payment mode - if (!empty($conf->global->EXPENSEREPORT_ASK_PAYMENTMODE_ON_CREATION)) - { + if (!empty($conf->global->EXPENSEREPORT_ASK_PAYMENTMODE_ON_CREATION)) { print ''; print ''.$langs->trans("ModePaiement").''; print ''; @@ -1471,13 +1447,10 @@ if ($action == 'create') $res = $object->fetch_optionals(); - if ($result > 0) - { - if (!in_array($object->fk_user_author, $user->getAllChildIds(1))) - { + if ($result > 0) { + if (!in_array($object->fk_user_author, $user->getAllChildIds(1))) { if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous) - && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->expensereport->writeall_advance))) - { + && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->expensereport->writeall_advance))) { print load_fiche_titre($langs->trans('TripCard'), '', 'trip'); print '
'; @@ -1494,16 +1467,14 @@ if ($action == 'create') $head = expensereport_prepare_head($object); - if ($action == 'edit' && ($object->status < 3 || $object->status == 99)) - { + if ($action == 'edit' && ($object->status < 3 || $object->status == 99)) { print "\n"; print ''; print ''; print dol_get_fiche_head($head, 'card', $langs->trans("ExpenseReport"), 0, 'trip'); - if ($object->status == 99) - { + if ($object->status == 99) { print ''; } else { print ''; @@ -1517,8 +1488,7 @@ if ($action == 'create') print ''.$langs->trans("User").''; print ''; $userfee = new User($db); - if ($object->fk_user_author > 0) - { + if ($object->fk_user_author > 0) { $userfee->fetch($object->fk_user_author); print $userfee->getNomUrl(-1); } @@ -1542,8 +1512,7 @@ if ($action == 'create') print ''; print ''; - if (!empty($conf->global->EXPENSEREPORT_ASK_PAYMENTMODE_ON_CREATION)) - { + if (!empty($conf->global->EXPENSEREPORT_ASK_PAYMENTMODE_ON_CREATION)) { print ''; print ''.$langs->trans("ModePaiement").''; print ''; @@ -1552,8 +1521,7 @@ if ($action == 'create') print ''; } - if ($object->status < 3) - { + if ($object->status < 3) { print ''; print ''.$langs->trans("VALIDATOR").''; // Approbator print ''; @@ -1572,8 +1540,7 @@ if ($action == 'create') print ''; } - if ($object->status == 6) - { + if ($object->status == 6) { print ''; print ''.$langs->trans("AUTHORPAIEMENT").''; print ''; @@ -1604,7 +1571,9 @@ if ($action == 'create') if ($action == 'clone') { // Create an array for form $criteriaforfilter = 'hierarchyme'; - if (!empty($user->rights->expensereport->readall)) $criteriaforfilter = ''; + if (!empty($user->rights->expensereport->readall)) { + $criteriaforfilter = ''; + } $formquestion = array( '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, '', '0', 0, 0, '', 0, '', 'maxwidth150')) @@ -1613,50 +1582,41 @@ if ($action == 'create') $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneExpenseReport', $object->ref), 'confirm_clone', $formquestion, 'yes', 1); } - if ($action == 'save') - { + if ($action == 'save') { $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("SaveTrip"), $langs->trans("ConfirmSaveTrip"), "confirm_validate", "", "", 1); } - if ($action == 'save_from_refuse') - { + if ($action == 'save_from_refuse') { $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("SaveTrip"), $langs->trans("ConfirmSaveTrip"), "confirm_save_from_refuse", "", "", 1); } - if ($action == 'delete') - { + if ($action == 'delete') { $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("DeleteTrip"), $langs->trans("ConfirmDeleteTrip"), "confirm_delete", "", "", 1); } - if ($action == 'validate') - { + if ($action == 'validate') { $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("ValideTrip"), $langs->trans("ConfirmValideTrip"), "confirm_approve", "", "", 1); } - if ($action == 'paid') - { + if ($action == 'paid') { $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("PaidTrip"), $langs->trans("ConfirmPaidTrip"), "confirm_paid", "", "", 1); } - if ($action == 'cancel') - { + if ($action == 'cancel') { $array_input = array('text'=>$langs->trans("ConfirmCancelTrip"), array('type'=>"text", 'label'=>''.$langs->trans("Comment").'', 'name'=>"detail_cancel", 'value'=>"")); $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("Cancel"), "", "confirm_cancel", $array_input, "", 1); } - if ($action == 'setdraft') - { + if ($action == 'setdraft') { $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("BrouillonnerTrip"), $langs->trans("ConfirmBrouillonnerTrip"), "confirm_setdraft", "", "", 1); } - if ($action == 'refuse') // Deny - { + if ($action == 'refuse') { // Deny $array_input = array('text'=>$langs->trans("ConfirmRefuseTrip"), array('type'=>"text", 'label'=>$langs->trans("Comment"), 'name'=>"detail_refuse", 'value'=>"")); $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("Deny"), '', "confirm_refuse", $array_input, "yes", 1); } - if ($action == 'delete_line') - { + if ($action == 'delete_line') { $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id."&rowid=".GETPOST('rowid', 'int'), $langs->trans("DeleteLine"), $langs->trans("ConfirmDeleteLine"), "confirm_delete_line", '', 'yes', 1); } @@ -1676,34 +1636,34 @@ if ($action == 'create') // Project if (! empty($conf->projet->enabled)) { - $langs->load("projects"); - $morehtmlref.='
'.$langs->trans('Project') . ' '; - if ($user->rights->commande->creer) - { - if ($action != 'classify') - $morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; - if ($action == 'classify') { - //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); - $morehtmlref.=''; - $morehtmlref.=''; - $morehtmlref.=''; - $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); - $morehtmlref.=''; - $morehtmlref.=''; - } 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.=''; - $morehtmlref.=$proj->ref; - $morehtmlref.=''; - } else { - $morehtmlref.=''; - } - } + $langs->load("projects"); + $morehtmlref.='
'.$langs->trans('Project') . ' '; + if ($user->rights->commande->creer) + { + if ($action != 'classify') + $morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; + if ($action == 'classify') { + //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); + $morehtmlref.='
'; + $morehtmlref.=''; + $morehtmlref.=''; + $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); + $morehtmlref.=''; + $morehtmlref.='
'; + } 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.=''; + $morehtmlref.=$proj->ref; + $morehtmlref.=''; + } else { + $morehtmlref.=''; + } + } }*/ $morehtmlref .= '
'; @@ -1719,12 +1679,14 @@ if ($action == 'create') print ''; print ''.$langs->trans("User").''; print ''; - if ($object->fk_user_author > 0) - { + 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); - elseif ($result > 0) print $userauthor->getNomUrl(-1); + if ($result < 0) { + dol_print_error('', $userauthor->error); + } elseif ($result > 0) { + print $userauthor->getNomUrl(-1); + } } print ''; @@ -1735,8 +1697,7 @@ if ($action == 'create') print get_date_range($object->date_debut, $object->date_fin, 'day', $langs, 0); print ''; print ''; - if (!empty($conf->global->EXPENSEREPORT_ASK_PAYMENTMODE_ON_CREATION)) - { + if (!empty($conf->global->EXPENSEREPORT_ASK_PAYMENTMODE_ON_CREATION)) { print ''; print ''.$langs->trans("ModePaiement").''; print ''.$object->fk_c_paiement.''; @@ -1747,39 +1708,42 @@ if ($action == 'create') print ''; print ''.$langs->trans("DATE_SAVE").''; print ''.dol_print_date($object->date_valid, 'dayhour', 'tzuser'); - if ($object->status == 2 && $object->hasDelay('toapprove')) print ' '.img_warning($langs->trans("Late").' - '.$langs->trans("ToApprove")); - if ($object->status == 5 && $object->hasDelay('topay')) print ' '.img_warning($langs->trans("Late").' - '.$langs->trans("ToPay")); + if ($object->status == 2 && $object->hasDelay('toapprove')) { + print ' '.img_warning($langs->trans("Late").' - '.$langs->trans("ToApprove")); + } + if ($object->status == 5 && $object->hasDelay('topay')) { + print ' '.img_warning($langs->trans("Late").' - '.$langs->trans("ToPay")); + } print ''; print ''; // User to inform for approval - if ($object->status <= ExpenseReport::STATUS_VALIDATED) // informed - { + if ($object->status <= ExpenseReport::STATUS_VALIDATED) { // informed print ''; print ''.$langs->trans("VALIDATOR").''; // approver print ''; - if ($object->fk_user_validator > 0) - { + if ($object->fk_user_validator > 0) { $userfee = new User($db); $result = $userfee->fetch($object->fk_user_validator); - if ($result > 0) print $userfee->getNomUrl(-1); - if (empty($userfee->email) || !isValidEmail($userfee->email)) - { + if ($result > 0) { + print $userfee->getNomUrl(-1); + } + if (empty($userfee->email) || !isValidEmail($userfee->email)) { $langs->load("errors"); print img_warning($langs->trans("ErrorBadEMail", $userfee->email)); } } print ''; - } elseif ($object->status == ExpenseReport::STATUS_CANCELED) - { + } elseif ($object->status == ExpenseReport::STATUS_CANCELED) { print ''; print ''.$langs->trans("CANCEL_USER").''; print ''; - if ($object->fk_user_cancel > 0) - { + if ($object->fk_user_cancel > 0) { $userfee = new User($db); $result = $userfee->fetch($object->fk_user_cancel); - if ($result > 0) print $userfee->getNomUrl(-1); + if ($result > 0) { + print $userfee->getNomUrl(-1); + } } print ''; @@ -1795,11 +1759,12 @@ if ($action == 'create') print ''; print ''.$langs->trans("ApprovedBy").''; print ''; - if ($object->fk_user_approve > 0) - { + if ($object->fk_user_approve > 0) { $userapp = new User($db); $result = $userapp->fetch($object->fk_user_approve); - if ($result > 0) print $userapp->getNomUrl(-1); + if ($result > 0) { + print $userapp->getNomUrl(-1); + } } print ''; @@ -1809,26 +1774,28 @@ if ($action == 'create') print ''; } - if ($object->status == 99 || !empty($object->detail_refuse)) - { + if ($object->status == 99 || !empty($object->detail_refuse)) { print ''; print ''.$langs->trans("REFUSEUR").''; print ''; $userfee = new User($db); $result = $userfee->fetch($object->fk_user_refuse); - if ($result > 0) print $userfee->getNomUrl(-1); + if ($result > 0) { + print $userfee->getNomUrl(-1); + } print ''; print ''; print ''.$langs->trans("DATE_REFUS").''; print ''.dol_print_date($object->date_refuse, 'dayhour', 'tzuser'); - if ($object->detail_refuse) print ' - '.$object->detail_refuse; + if ($object->detail_refuse) { + print ' - '.$object->detail_refuse; + } print ''; print ''; } - if ($object->status == $object::STATUS_CLOSED) - { + if ($object->status == $object::STATUS_CLOSED) { /* TODO this fields are not yet filled print ''; print ''.$langs->trans("AUTHORPAIEMENT").''; @@ -1862,11 +1829,19 @@ if ($action == 'create') print ''.$langs->trans("AmountHT").''; print ''.price($object->total_ht, 1, '', 1, - 1, - 1, $conf->currency).''; $rowspan = 5; - if ($object->status <= ExpenseReport::STATUS_VALIDATED) $rowspan++; - elseif ($object->status == ExpenseReport::STATUS_CANCELED) $rowspan += 2; - else $rowspan += 2; - if ($object->status == ExpenseReport::STATUS_REFUSED || !empty($object->detail_refuse)) $rowspan += 2; - if ($object->status == ExpenseReport::STATUS_CLOSED) $rowspan += 2; + if ($object->status <= ExpenseReport::STATUS_VALIDATED) { + $rowspan++; + } elseif ($object->status == ExpenseReport::STATUS_CANCELED) { + $rowspan += 2; + } else { + $rowspan += 2; + } + if ($object->status == ExpenseReport::STATUS_REFUSED || !empty($object->detail_refuse)) { + $rowspan += 2; + } + if ($object->status == ExpenseReport::STATUS_CLOSED) { + $rowspan += 2; + } print ""; print ''; @@ -1914,12 +1889,10 @@ if ($action == 'create') $sql .= " ORDER BY dp"; $resql = $db->query($sql); - if ($resql) - { + if ($resql) { $num = $db->num_rows($resql); $i = 0; $totalpaid = 0; - while ($i < $num) - { + while ($i < $num) { $objp = $db->fetch_object($resql); $paymentexpensereportstatic->id = $objp->rowid; @@ -1935,8 +1908,7 @@ if ($action == 'create') print ''.dol_print_date($db->jdate($objp->dp), 'day')."\n"; $labeltype = $langs->trans("PaymentType".$objp->p_code) != ("PaymentType".$objp->p_code) ? $langs->trans("PaymentType".$objp->p_code) : $objp->payment_type; print "".$labeltype.' '.$objp->num_payment."\n"; - if (!empty($conf->banque->enabled)) - { + if (!empty($conf->banque->enabled)) { $bankaccountstatic->id = $objp->baid; $bankaccountstatic->ref = $objp->baref; $bankaccountstatic->label = $objp->baref; @@ -1951,8 +1923,9 @@ if ($action == 'create') } print ''; - if ($bankaccountstatic->id) + if ($bankaccountstatic->id) { print $bankaccountstatic->getNomUrl(1, 'transactions'); + } print ''; } print ''.price($objp->amount).""; @@ -1961,8 +1934,7 @@ if ($action == 'create') $totalpaid += $objp->amount; $i++; } - if (!is_null($totalpaid)) - { + if (!is_null($totalpaid)) { $totalpaid = price2num($totalpaid); // Round $totalpaid to fix floating problem after addition into loop } @@ -1971,12 +1943,10 @@ if ($action == 'create') $cssforamountpaymentcomplete = 'amountpaymentcomplete'; - if ($object->status == ExpenseReport::STATUS_REFUSED) - { + if ($object->status == ExpenseReport::STATUS_REFUSED) { $cssforamountpaymentcomplete = 'amountpaymentneutral'; $resteapayeraffiche = 0; - } elseif ($object->paid == 0) - { + } elseif ($object->paid == 0) { $cssforamountpaymentcomplete = 'amountpaymentneutral'; } print ''.$langs->trans("AlreadyPaid").':'.price($totalpaid).''; @@ -2000,7 +1970,9 @@ if ($action == 'create') print '
'; $actiontouse = 'updateline'; - if (($object->status == 0 || $object->status == 99) && $action != 'editline') $actiontouse = 'addline'; + if (($object->status == 0 || $object->status == 99) && $action != 'editline') { + $actiontouse = 'addline'; + } print '
'; print ''; @@ -2011,24 +1983,26 @@ if ($action == 'create') print '
'; print ''; - if (!empty($object->lines)) - { + if (!empty($object->lines)) { $i = 0; $total = 0; print ''; print ''; //print ''; print ''; - if (!empty($conf->projet->enabled)) print ''; + if (!empty($conf->projet->enabled)) { + print ''; + } print ''; - if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) print ''; + if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) { + print ''; + } print ''; print ''; print ''; print ''; print ''; - if ($action != 'editline') - { + if ($action != 'editline') { print ''; print ''; } @@ -2036,18 +2010,15 @@ if ($action == 'create') print ''; // Ajout des boutons de modification/suppression - if (($object->status < 2 || $object->status == 99) && $user->rights->expensereport->creer) - { + if (($object->status < 2 || $object->status == 99) && $user->rights->expensereport->creer) { print ''; } print ''; - foreach ($object->lines as &$line) - { + foreach ($object->lines as &$line) { $numline = $i + 1; - if ($action != 'editline' || $line->rowid != GETPOST('rowid', 'int')) - { + if ($action != 'editline' || $line->rowid != GETPOST('rowid', 'int')) { print ''; // Num @@ -2059,11 +2030,9 @@ if ($action == 'create') print ''; // Project - if (!empty($conf->projet->enabled)) - { + if (!empty($conf->projet->enabled)) { print ''; // IK - if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) - { + if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) { print ''; @@ -2092,8 +2060,7 @@ if ($action == 'create') print ''; // Unit price HT print ''; - if ($action != 'editline') - { + if ($action != 'editline') { print ''; print ''; } // Column with preview print ''; // Ajout des boutons de modification/suppression - if (($object->status < ExpenseReport::STATUS_VALIDATED || $object->status == ExpenseReport::STATUS_REFUSED) && $user->rights->expensereport->creer) - { + if (($object->status < ExpenseReport::STATUS_VALIDATED || $object->status == ExpenseReport::STATUS_REFUSED) && $user->rights->expensereport->creer) { print ''; } - if ($action == 'editline' && $line->rowid == GETPOST('rowid', 'int')) - { + if ($action == 'editline' && $line->rowid == GETPOST('rowid', 'int')) { // Add line with link to add new file or attach line to an existing file $colspan = 10; - if (!empty($conf->projet->enabled)) $colspan++; - if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) $colspan++; + if (!empty($conf->projet->enabled)) { + $colspan++; + } + if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) { + $colspan++; + } print ''; @@ -2219,8 +2183,7 @@ if ($action == 'create') print ''.$langs->trans("UploadANewFileNow"); print img_picto($langs->trans("UploadANewFileNow"), 'chevron-down', '', false, 0, 0, '', 'marginleftonly'); print ''; - if (empty($conf->global->EXPENSEREPORT_DISABLE_ATTACHMENT_ON_LINES)) - { + if (empty($conf->global->EXPENSEREPORT_DISABLE_ATTACHMENT_ON_LINES)) { print '   -   '.$langs->trans("AttachTheNewLineToTheDocument"); print img_picto($langs->trans("AttachTheNewLineToTheDocument"), 'chevron-down', '', false, 0, 0, '', 'marginleftonly'); print ''; @@ -2238,8 +2201,7 @@ if ($action == 'create') jQuery(".truploadnewfilenow").hide(); return false; });'; - if (is_array(GETPOST('attachfile', 'array')) && count(GETPOST('attachfile', 'array'))) - { + if (is_array(GETPOST('attachfile', 'array')) && count(GETPOST('attachfile', 'array'))) { print 'jQuery(".trattachnewfilenow").toggle();'."\n"; } print ' @@ -2249,11 +2211,9 @@ if ($action == 'create') print ''; $filenamelinked = ''; - if ($line->fk_ecm_files > 0) - { + if ($line->fk_ecm_files > 0) { $result = $ecmfilesstatic->fetch($line->fk_ecm_files); - if ($result > 0) - { + if ($result > 0) { $filenamelinked = $ecmfilesstatic->filename; } } @@ -2272,8 +2232,7 @@ if ($action == 'create') print ''; // Select project - if (!empty($conf->projet->enabled)) - { + if (!empty($conf->projet->enabled)) { print ''; @@ -2284,8 +2243,7 @@ if ($action == 'create') print $formexpensereport->selectTypeExpenseReport($line->fk_c_type_fees, 'fk_c_type_fees'); print ''; - if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) - { + if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) { print ''; // Select project - if (!empty($conf->projet->enabled)) - { + if (!empty($conf->projet->enabled)) { print ''; @@ -2443,8 +2402,7 @@ if ($action == 'create') print $formexpensereport->selectTypeExpenseReport($fk_c_type_fees, 'fk_c_type_fees', 1); print ''; - if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) - { + if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) { print ''; @@ -2481,8 +2441,7 @@ if ($action == 'create') // Picture print ''; - if ($action != 'editline') - { + if ($action != 'editline') { print ''; print ''; } @@ -2499,31 +2458,30 @@ if ($action == 'create') /* JQuery for product free or predefined select */ jQuery(document).ready(function() { - jQuery("#value_unit_ht").keyup(function(event) { - console.log(event.which); // discard event tag and arrows - if (event.which != 9 && (event.which < 37 ||event.which > 40) && jQuery("#value_unit_ht").val() != "") { - jQuery("#value_unit").val(""); - } - }); - jQuery("#value_unit").keyup(function(event) { - console.log(event.which); // discard event tag and arrows - if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#value_unit").val() != "") { - jQuery("#value_unit_ht").val(""); - } - }); + jQuery("#value_unit_ht").keyup(function(event) { + console.log(event.which); // discard event tag and arrows + if (event.which != 9 && (event.which < 37 ||event.which > 40) && jQuery("#value_unit_ht").val() != "") { + jQuery("#value_unit").val(""); + } + }); + jQuery("#value_unit").keyup(function(event) { + console.log(event.which); // discard event tag and arrows + if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#value_unit").val() != "") { + jQuery("#value_unit_ht").val(""); + } + }); }); - '; + '; print ''; print dol_get_fiche_end(); - } // end edit or not edit - } // end of if result - else { + } + } else { dol_print_error($db); } - } //fin si id > 0 + } } /* @@ -2532,8 +2490,7 @@ if ($action == 'create') print '
'; -if ($action != 'create' && $action != 'edit') -{ +if ($action != 'create' && $action != 'edit') { $object = new ExpenseReport($db); $object->fetch($id, $ref); @@ -2552,16 +2509,13 @@ if ($action != 'create' && $action != 'edit') * ET fk_user_author == user courant * Afficher : "Enregistrer" / "Modifier" / "Supprimer" */ - if ($user->rights->expensereport->creer && $object->status == ExpenseReport::STATUS_DRAFT) - { - if (in_array($object->fk_user_author, $user->getAllChildIds(1)) || !empty($user->rights->expensereport->writeall_advance)) - { + if ($user->rights->expensereport->creer && $object->status == ExpenseReport::STATUS_DRAFT) { + if (in_array($object->fk_user_author, $user->getAllChildIds(1)) || !empty($user->rights->expensereport->writeall_advance)) { // Modify print ''; // Validate - if (count($object->lines) > 0) - { + if (count($object->lines) > 0) { print ''; } } @@ -2572,10 +2526,8 @@ if ($action != 'create' && $action != 'edit') * ET fk_user_author == user courant * Afficher : "Enregistrer" / "Modifier" / "Supprimer" */ - if ($user->rights->expensereport->creer && $object->status == ExpenseReport::STATUS_REFUSED) - { - if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) - { + if ($user->rights->expensereport->creer && $object->status == ExpenseReport::STATUS_REFUSED) { + if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) { // Modify print ''; @@ -2586,10 +2538,8 @@ if ($action != 'create' && $action != 'edit') } } - if ($user->rights->expensereport->to_paid && $object->status == ExpenseReport::STATUS_APPROVED) - { - if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) - { + if ($user->rights->expensereport->to_paid && $object->status == ExpenseReport::STATUS_APPROVED) { + if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) { // setdraft print ''; } @@ -2600,17 +2550,14 @@ if ($action != 'create' && $action != 'edit') * ET fk_user_validator == user courant * Afficher : "Valider" / "Refuser" / "Supprimer" */ - if ($object->status == ExpenseReport::STATUS_VALIDATED) - { - if (in_array($object->fk_user_author, $user->getAllChildIds(1))) - { + if ($object->status == ExpenseReport::STATUS_VALIDATED) { + if (in_array($object->fk_user_author, $user->getAllChildIds(1))) { // set draft print ''; } } - if ($user->rights->expensereport->approve && $object->status == ExpenseReport::STATUS_VALIDATED) - { + if ($user->rights->expensereport->approve && $object->status == ExpenseReport::STATUS_VALIDATED) { //if($object->fk_user_validator==$user->id) //{ // Validate @@ -2619,8 +2566,7 @@ if ($action != 'create' && $action != 'edit') print ''; //} - if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) - { + if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) { // Cancel print ''; } @@ -2630,17 +2576,14 @@ if ($action != 'create' && $action != 'edit') // If status is Approved // --------------------- - if ($user->rights->expensereport->approve && $object->status == ExpenseReport::STATUS_APPROVED) - { + if ($user->rights->expensereport->approve && $object->status == ExpenseReport::STATUS_APPROVED) { print ''; } // If bank module is used - if ($user->rights->expensereport->to_paid && !empty($conf->banque->enabled) && $object->status == ExpenseReport::STATUS_APPROVED) - { + if ($user->rights->expensereport->to_paid && !empty($conf->banque->enabled) && $object->status == ExpenseReport::STATUS_APPROVED) { // Pay - if ($remaintopay == 0) - { + if ($remaintopay == 0) { print '
'.$langs->trans('DoPayment').'
'; } else { print ''; @@ -2648,30 +2591,25 @@ if ($action != 'create' && $action != 'edit') } // If bank module is not used - if (($user->rights->expensereport->to_paid || empty($conf->banque->enabled)) && $object->status == ExpenseReport::STATUS_APPROVED) - { + if (($user->rights->expensereport->to_paid || empty($conf->banque->enabled)) && $object->status == ExpenseReport::STATUS_APPROVED) { //if ((round($remaintopay) == 0 || empty($conf->banque->enabled)) && $object->paid == 0) - if ($object->paid == 0) - { + if ($object->paid == 0) { print '"; } } - if ($user->rights->expensereport->creer && ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) && $object->status == ExpenseReport::STATUS_APPROVED) - { - // Cancel - print ''; - } - - // 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->status == ExpenseReport::STATUS_CLOSED) - { + if ($user->rights->expensereport->creer && ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) && $object->status == ExpenseReport::STATUS_APPROVED) { // Cancel print ''; } - if ($user->rights->expensereport->to_paid && $object->paid && $object->status == ExpenseReport::STATUS_CLOSED) - { + // 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->status == ExpenseReport::STATUS_CLOSED) { + // Cancel + print ''; + } + + if ($user->rights->expensereport->to_paid && $object->paid && $object->status == ExpenseReport::STATUS_CLOSED) { // Set unpaid print ''; } @@ -2682,12 +2620,10 @@ if ($action != 'create' && $action != 'edit') } /* If draft, validated, cancel, and user can create, he can always delete its card before it is approved */ - if ($user->rights->expensereport->creer && $user->id == $object->fk_user_author && $object->status < ExpenseReport::STATUS_APPROVED) - { + if ($user->rights->expensereport->creer && $user->id == $object->fk_user_author && $object->status < ExpenseReport::STATUS_APPROVED) { // Delete print ''; - } elseif ($user->rights->expensereport->supprimer && $object->status != ExpenseReport::STATUS_CLOSED) - { + } elseif ($user->rights->expensereport->supprimer && $object->status != ExpenseReport::STATUS_CLOSED) { // Delete print ''; } @@ -2704,8 +2640,7 @@ if (GETPOST('modelselected', 'alpha')) { $action = 'presend'; } -if ($action != 'presend') -{ +if ($action != 'presend') { /* * Generate documents */ @@ -2713,8 +2648,7 @@ if ($action != 'presend') print '
'; print ''; // ancre - if ($user->rights->expensereport->creer && $action != 'create' && $action != 'edit') - { + if ($user->rights->expensereport->creer && $action != 'create' && $action != 'edit') { $filename = dol_sanitizeFileName($object->ref); $filedir = $conf->expensereport->dir_output."/".dol_sanitizeFileName($object->ref); $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id; @@ -2732,7 +2666,7 @@ if ($action != 'presend') $linktoelem = $form->showLinkToObjectBlock($object, null, array('expensereport')); $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem); } - */ + */ print '
'; // List of actions on element diff --git a/htdocs/expensereport/class/api_expensereports.class.php b/htdocs/expensereport/class/api_expensereports.class.php index aa892e50fc0..98da4534e0c 100644 --- a/htdocs/expensereport/class/api_expensereports.class.php +++ b/htdocs/expensereport/class/api_expensereports.class.php @@ -33,7 +33,7 @@ class ExpenseReports extends DolibarrApi /** * @var array $FIELDS Mandatory fields, checked when create and update object */ - static $FIELDS = array( + public static $FIELDS = array( 'fk_user_author' ); @@ -107,11 +107,12 @@ class ExpenseReports extends DolibarrApi $sql = "SELECT t.rowid"; $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as t"; $sql .= ' WHERE t.entity IN ('.getEntity('expensereport').')'; - if ($user_ids) $sql .= " AND t.fk_user_author IN (".$user_ids.")"; + if ($user_ids) { + $sql .= " AND t.fk_user_author IN (".$user_ids.")"; + } // Add sql filters - if ($sqlfilters) - { + if ($sqlfilters) { if (!DolibarrApi::_checkFilters($sqlfilters)) { throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); } @@ -131,13 +132,11 @@ class ExpenseReports extends DolibarrApi $result = $this->db->query($sql); - if ($result) - { + if ($result) { $num = $this->db->num_rows($result); $min = min($num, ($limit <= 0 ? $num : $limit)); $i = 0; - while ($i < $min) - { + while ($i < $min) { $obj = $this->db->fetch_object($result); $expensereport_static = new ExpenseReport($this->db); if ($expensereport_static->fetch($obj->rowid)) { @@ -172,12 +171,12 @@ class ExpenseReports extends DolibarrApi $this->expensereport->$field = $value; } /*if (isset($request_data["lines"])) { - $lines = array(); - foreach ($request_data["lines"] as $line) { - array_push($lines, (object) $line); - } - $this->expensereport->lines = $lines; - }*/ + $lines = array(); + foreach ($request_data["lines"] as $line) { + array_push($lines, (object) $line); + } + $this->expensereport->lines = $lines; + }*/ if ($this->expensereport->create(DolibarrApiAccess::$user) < 0) { throw new RestException(500, "Error creating expensereport", array_merge(array($this->expensereport->error), $this->expensereport->errors)); } @@ -195,28 +194,28 @@ class ExpenseReports extends DolibarrApi * @return int */ /* - public function getLines($id) - { - if(! DolibarrApiAccess::$user->rights->expensereport->lire) { - throw new RestException(401); - } + public function getLines($id) + { + if(! DolibarrApiAccess::$user->rights->expensereport->lire) { + throw new RestException(401); + } - $result = $this->expensereport->fetch($id); - if( ! $result ) { - throw new RestException(404, 'expensereport not found'); - } + $result = $this->expensereport->fetch($id); + if( ! $result ) { + throw new RestException(404, 'expensereport not found'); + } - if( ! DolibarrApi::_checkAccessToResource('expensereport',$this->expensereport->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - $this->expensereport->getLinesArray(); - $result = array(); - foreach ($this->expensereport->lines as $line) { - array_push($result,$this->_cleanObjectDatas($line)); - } - return $result; - } - */ + if( ! DolibarrApi::_checkAccessToResource('expensereport',$this->expensereport->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + $this->expensereport->getLinesArray(); + $result = array(); + foreach ($this->expensereport->lines as $line) { + array_push($result,$this->_cleanObjectDatas($line)); + } + return $result; + } + */ /** * Add a line to given Expense Report @@ -229,56 +228,56 @@ class ExpenseReports extends DolibarrApi * @return int */ /* - public function postLine($id, $request_data = null) - { - if(! DolibarrApiAccess::$user->rights->expensereport->creer) { - throw new RestException(401); - } + public function postLine($id, $request_data = null) + { + if(! DolibarrApiAccess::$user->rights->expensereport->creer) { + throw new RestException(401); + } - $result = $this->expensereport->fetch($id); - if( ! $result ) { - throw new RestException(404, 'expensereport not found'); - } + $result = $this->expensereport->fetch($id); + if( ! $result ) { + throw new RestException(404, 'expensereport not found'); + } - if( ! DolibarrApi::_checkAccessToResource('expensereport',$this->expensereport->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - $request_data = (object) $request_data; - $updateRes = $this->expensereport->addline( - $request_data->desc, - $request_data->subprice, - $request_data->qty, - $request_data->tva_tx, - $request_data->localtax1_tx, - $request_data->localtax2_tx, - $request_data->fk_product, - $request_data->remise_percent, - $request_data->info_bits, - $request_data->fk_remise_except, - 'HT', - 0, - $request_data->date_start, - $request_data->date_end, - $request_data->product_type, - $request_data->rang, - $request_data->special_code, - $fk_parent_line, - $request_data->fk_fournprice, - $request_data->pa_ht, - $request_data->label, - $request_data->array_options, - $request_data->fk_unit, - $this->element, - $request_data->id - ); + if( ! DolibarrApi::_checkAccessToResource('expensereport',$this->expensereport->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + $request_data = (object) $request_data; + $updateRes = $this->expensereport->addline( + $request_data->desc, + $request_data->subprice, + $request_data->qty, + $request_data->tva_tx, + $request_data->localtax1_tx, + $request_data->localtax2_tx, + $request_data->fk_product, + $request_data->remise_percent, + $request_data->info_bits, + $request_data->fk_remise_except, + 'HT', + 0, + $request_data->date_start, + $request_data->date_end, + $request_data->product_type, + $request_data->rang, + $request_data->special_code, + $fk_parent_line, + $request_data->fk_fournprice, + $request_data->pa_ht, + $request_data->label, + $request_data->array_options, + $request_data->fk_unit, + $this->element, + $request_data->id + ); - if ($updateRes > 0) { - return $updateRes; + if ($updateRes > 0) { + return $updateRes; - } - return false; - } - */ + } + return false; + } + */ /** * Update a line to given Expense Report @@ -292,53 +291,53 @@ class ExpenseReports extends DolibarrApi * @return object */ /* - public function putLine($id, $lineid, $request_data = null) - { - if(! DolibarrApiAccess::$user->rights->expensereport->creer) { - throw new RestException(401); - } + public function putLine($id, $lineid, $request_data = null) + { + if(! DolibarrApiAccess::$user->rights->expensereport->creer) { + throw new RestException(401); + } - $result = $this->expensereport->fetch($id); - if( ! $result ) { - throw new RestException(404, 'expensereport not found'); - } + $result = $this->expensereport->fetch($id); + if( ! $result ) { + throw new RestException(404, 'expensereport not found'); + } - if( ! DolibarrApi::_checkAccessToResource('expensereport',$this->expensereport->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - $request_data = (object) $request_data; - $updateRes = $this->expensereport->updateline( - $lineid, - $request_data->desc, - $request_data->subprice, - $request_data->qty, - $request_data->remise_percent, - $request_data->tva_tx, - $request_data->localtax1_tx, - $request_data->localtax2_tx, - 'HT', - $request_data->info_bits, - $request_data->date_start, - $request_data->date_end, - $request_data->product_type, - $request_data->fk_parent_line, - 0, - $request_data->fk_fournprice, - $request_data->pa_ht, - $request_data->label, - $request_data->special_code, - $request_data->array_options, - $request_data->fk_unit - ); + if( ! DolibarrApi::_checkAccessToResource('expensereport',$this->expensereport->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + $request_data = (object) $request_data; + $updateRes = $this->expensereport->updateline( + $lineid, + $request_data->desc, + $request_data->subprice, + $request_data->qty, + $request_data->remise_percent, + $request_data->tva_tx, + $request_data->localtax1_tx, + $request_data->localtax2_tx, + 'HT', + $request_data->info_bits, + $request_data->date_start, + $request_data->date_end, + $request_data->product_type, + $request_data->fk_parent_line, + 0, + $request_data->fk_fournprice, + $request_data->pa_ht, + $request_data->label, + $request_data->special_code, + $request_data->array_options, + $request_data->fk_unit + ); - if ($updateRes > 0) { - $result = $this->get($id); - unset($result->line); - return $this->_cleanObjectDatas($result); - } - return false; - } - */ + if ($updateRes > 0) { + $result = $this->get($id); + unset($result->line); + return $this->_cleanObjectDatas($result); + } + return false; + } + */ /** * Delete a line of given Expense Report @@ -351,30 +350,30 @@ class ExpenseReports extends DolibarrApi * @return int */ /* - public function deleteLine($id, $lineid) - { - if(! DolibarrApiAccess::$user->rights->expensereport->creer) { - throw new RestException(401); - } + public function deleteLine($id, $lineid) + { + if(! DolibarrApiAccess::$user->rights->expensereport->creer) { + throw new RestException(401); + } - $result = $this->expensereport->fetch($id); - if( ! $result ) { - throw new RestException(404, 'expensereport not found'); - } + $result = $this->expensereport->fetch($id); + if( ! $result ) { + throw new RestException(404, 'expensereport not found'); + } - if( ! DolibarrApi::_checkAccessToResource('expensereport',$this->expensereport->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } + if( ! DolibarrApi::_checkAccessToResource('expensereport',$this->expensereport->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } - // TODO Check the lineid $lineid is a line of ojbect + // TODO Check the lineid $lineid is a line of ojbect - $updateRes = $this->expensereport->deleteline($lineid); - if ($updateRes == 1) { - return $this->get($id); - } - return false; - } - */ + $updateRes = $this->expensereport->deleteline($lineid); + if ($updateRes == 1) { + return $this->get($id); + } + return false; + } + */ /** * Update Expense Report general fields (won't touch lines of expensereport) @@ -403,12 +402,13 @@ class ExpenseReports extends DolibarrApi throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } foreach ($request_data as $field => $value) { - if ($field == 'id') continue; + if ($field == 'id') { + continue; + } $this->expensereport->$field = $value; } - if ($this->expensereport->update(DolibarrApiAccess::$user) > 0) - { + if ($this->expensereport->update(DolibarrApiAccess::$user) > 0) { return $this->get($id); } else { throw new RestException(500, $this->expensereport->error); @@ -464,31 +464,31 @@ class ExpenseReports extends DolibarrApi * } */ /* - public function validate($id, $idwarehouse=0) - { - if(! DolibarrApiAccess::$user->rights->expensereport->creer) { - throw new RestException(401); - } - $result = $this->expensereport->fetch($id); - if( ! $result ) { - throw new RestException(404, 'expensereport not found'); - } + public function validate($id, $idwarehouse=0) + { + if(! DolibarrApiAccess::$user->rights->expensereport->creer) { + throw new RestException(401); + } + $result = $this->expensereport->fetch($id); + if( ! $result ) { + throw new RestException(404, 'expensereport not found'); + } - if( ! DolibarrApi::_checkAccessToResource('expensereport',$this->expensereport->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } + if( ! DolibarrApi::_checkAccessToResource('expensereport',$this->expensereport->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } - if( ! $this->expensereport->valid(DolibarrApiAccess::$user, $idwarehouse)) { - throw new RestException(500, 'Error when validate expensereport'); - } + if( ! $this->expensereport->valid(DolibarrApiAccess::$user, $idwarehouse)) { + throw new RestException(500, 'Error when validate expensereport'); + } - return array( - 'success' => array( - 'code' => 200, - 'message' => 'expensereport validated' - ) - ); - }*/ + return array( + 'success' => array( + 'code' => 200, + 'message' => 'expensereport validated' + ) + ); + }*/ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore /** @@ -555,8 +555,9 @@ class ExpenseReports extends DolibarrApi { $expensereport = array(); foreach (ExpenseReports::$FIELDS as $field) { - if (!isset($data[$field])) + if (!isset($data[$field])) { throw new RestException(400, "$field field missing"); + } $expensereport[$field] = $data[$field]; } return $expensereport; diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php index cdc4fe4da5d..f95302cdba2 100644 --- a/htdocs/expensereport/class/expensereport.class.php +++ b/htdocs/expensereport/class/expensereport.class.php @@ -237,14 +237,15 @@ class ExpenseReport extends CommonObject $error = 0; // Check parameters - if (empty($this->date_debut) || empty($this->date_fin)) - { + if (empty($this->date_debut) || empty($this->date_fin)) { $this->error = $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Date')); return -1; } $fuserid = $this->fk_user_author; // Note fk_user_author is not the 'author' but the guy the expense report is for. - if (empty($fuserid)) $fuserid = $user->id; + if (empty($fuserid)) { + $fuserid = $user->id; + } $this->db->begin(); @@ -289,25 +290,20 @@ class ExpenseReport extends CommonObject $sql .= ")"; $result = $this->db->query($sql); - if ($result) - { + if ($result) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); $this->ref = '(PROV'.$this->id.')'; $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element." SET ref='".$this->db->escape($this->ref)."' WHERE rowid=".$this->id; $resql = $this->db->query($sql); - if (!$resql) - { + if (!$resql) { $this->error = $this->db->lasterror(); $error++; } - if (!$error) - { - if (is_array($this->lines) && count($this->lines) > 0) - { - foreach ($this->lines as $line) - { + if (!$error) { + if (is_array($this->lines) && count($this->lines) > 0) { + foreach ($this->lines as $line) { // Test and convert into object this->lines[$i]. When coming from REST API, we may still have an array //if (! is_object($line)) $line=json_decode(json_encode($line), false); // convert recursively array into object. if (!is_object($line)) { @@ -334,8 +330,7 @@ class ExpenseReport extends CommonObject //$newndfline=new ExpenseReportLine($this->db); $newndfline->fk_expensereport = $this->id; $result = $newndfline->insert(); - if ($result < 0) - { + if ($result < 0) { $this->error = $newndfline->error; $this->errors = $newndfline->errors; $error++; @@ -345,19 +340,17 @@ class ExpenseReport extends CommonObject } } - if (!$error) - { + if (!$error) { $result = $this->insertExtraFields(); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } } - if (!$error) - { + if (!$error) { $result = $this->update_price(); - if ($result > 0) - { - if (!$notrigger) - { + if ($result > 0) { + if (!$notrigger) { // Call trigger $result = $this->call_trigger('EXPENSE_REPORT_CREATE', $user); @@ -367,8 +360,7 @@ class ExpenseReport extends CommonObject // End call triggers } - if (empty($error)) - { + if (empty($error)) { $this->db->commit(); return $this->id; } else { @@ -405,7 +397,9 @@ class ExpenseReport extends CommonObject $error = 0; - if (empty($fk_user_author)) $fk_user_author = $user->id; + if (empty($fk_user_author)) { + $fk_user_author = $user->id; + } $this->db->begin(); @@ -430,10 +424,8 @@ class ExpenseReport extends CommonObject $this->date_validation = ''; // Remove link on lines to a joined file - if (is_array($this->lines) && count($this->lines) > 0) - { - foreach ($this->lines as $key => $line) - { + if (is_array($this->lines) && count($this->lines) > 0) { + foreach ($this->lines as $key => $line) { $this->lines[$key]->fk_ecm_files = 0; } } @@ -441,25 +433,26 @@ class ExpenseReport extends CommonObject // Create clone $this->context['createfromclone'] = 'createfromclone'; $result = $this->create($user); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } - if (!$error) - { + if (!$error) { // Hook of thirdparty module - if (is_object($hookmanager)) - { + if (is_object($hookmanager)) { $parameters = array('objFrom'=>$objFrom); $action = ''; $reshook = $hookmanager->executeHooks('createFrom', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks - if ($reshook < 0) $error++; + if ($reshook < 0) { + $error++; + } } } unset($this->context['createfromclone']); // End - if (!$error) - { + if (!$error) { $this->db->commit(); return $this->id; } else { @@ -490,8 +483,7 @@ class ExpenseReport extends CommonObject $sql .= " , total_tva = ".$this->total_tva; $sql .= " , date_debut = '".$this->db->idate($this->date_debut)."'"; $sql .= " , date_fin = '".$this->db->idate($this->date_fin)."'"; - if ($userofexpensereport && is_object($userofexpensereport)) - { + if ($userofexpensereport && is_object($userofexpensereport)) { $sql .= " , fk_user_author = ".($userofexpensereport->id > 0 ? $userofexpensereport->id : "null"); // Note fk_user_author is not the 'author' but the guy the expense report is for. } $sql .= " , fk_user_validator = ".($this->fk_user_validator > 0 ? $this->fk_user_validator : "null"); @@ -507,10 +499,8 @@ class ExpenseReport extends CommonObject dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG); $result = $this->db->query($sql); - if ($result) - { - if (!$notrigger) - { + if ($result) { + if (!$notrigger) { // Call trigger $result = $this->call_trigger('EXPENSE_REPORT_UPDATE', $user); @@ -520,8 +510,7 @@ class ExpenseReport extends CommonObject // End call triggers } - if (empty($error)) - { + if (empty($error)) { $this->db->commit(); return 1; } else { @@ -556,17 +545,18 @@ class ExpenseReport extends CommonObject $sql .= " d.fk_user_valid, d.fk_user_approve,"; $sql .= " d.fk_statut as status, d.fk_c_paiement, d.paid"; $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as d"; - if ($ref) $sql .= " WHERE d.ref = '".$this->db->escape($ref)."'"; - else $sql .= " WHERE d.rowid = ".$id; + if ($ref) { + $sql .= " WHERE d.ref = '".$this->db->escape($ref)."'"; + } else { + $sql .= " WHERE d.rowid = ".$id; + } //$sql.= $restrict; dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $obj = $this->db->fetch_object($resql); - if ($obj) - { + if ($obj) { $this->id = $obj->rowid; $this->ref = $obj->ref; @@ -599,13 +589,18 @@ class ExpenseReport extends CommonObject $this->fk_user_approve = $obj->fk_user_approve; $user_author = new User($this->db); - if ($this->fk_user_author > 0) $user_author->fetch($this->fk_user_author); + if ($this->fk_user_author > 0) { + $user_author->fetch($this->fk_user_author); + } $this->user_author_infos = dolGetFirstLastname($user_author->firstname, $user_author->lastname); $user_approver = new User($this->db); - if ($this->fk_user_approve > 0) $user_approver->fetch($this->fk_user_approve); - elseif ($this->fk_user_validator > 0) $user_approver->fetch($this->fk_user_validator); // For backward compatibility + if ($this->fk_user_approve > 0) { + $user_approver->fetch($this->fk_user_approve); + } elseif ($this->fk_user_validator > 0) { + $user_approver->fetch($this->fk_user_validator); // For backward compatibility + } $this->user_validator_infos = dolGetFirstLastname($user_approver->firstname, $user_approver->lastname); $this->fk_statut = $obj->status; // deprecated @@ -613,10 +608,11 @@ class ExpenseReport extends CommonObject $this->fk_c_paiement = $obj->fk_c_paiement; $this->paid = $obj->paid; - if ($this->status == self::STATUS_APPROVED || $this->status == self::STATUS_CLOSED) - { + if ($this->status == self::STATUS_APPROVED || $this->status == self::STATUS_CLOSED) { $user_valid = new User($this->db); - if ($this->fk_user_valid > 0) $user_valid->fetch($this->fk_user_valid); + if ($this->fk_user_valid > 0) { + $user_valid->fetch($this->fk_user_valid); + } $this->user_valid_infos = dolGetFirstLastname($user_valid->firstname, $user_valid->lastname); } @@ -671,12 +667,9 @@ class ExpenseReport extends CommonObject dol_syslog(get_class($this)."::set_paid sql=".$sql, LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { - if ($this->db->affected_rows($resql)) - { - if (!$notrigger) - { + if ($resql) { + if ($this->db->affected_rows($resql)) { + if (!$notrigger) { // Call trigger $result = $this->call_trigger('EXPENSE_REPORT_PAID', $fuser); @@ -686,8 +679,7 @@ class ExpenseReport extends CommonObject // End call triggers } - if (empty($error)) - { + if (empty($error)) { $this->db->commit(); return 1; } else { @@ -763,10 +755,8 @@ class ExpenseReport extends CommonObject $sql .= " AND f.entity = ".$conf->entity; $resql = $this->db->query($sql); - if ($resql) - { - if ($this->db->num_rows($resql)) - { + if ($resql) { + if ($this->db->num_rows($resql)) { $obj = $this->db->fetch_object($resql); $this->id = $obj->rowid; @@ -780,26 +770,22 @@ class ExpenseReport extends CommonObject $cuser->fetch($obj->fk_user_author); $this->user_creation = $cuser; - if ($obj->fk_user_creation) - { + if ($obj->fk_user_creation) { $cuser = new User($this->db); $cuser->fetch($obj->fk_user_creation); $this->user_creation = $cuser; } - if ($obj->fk_user_valid) - { + if ($obj->fk_user_valid) { $vuser = new User($this->db); $vuser->fetch($obj->fk_user_valid); $this->user_validation = $vuser; } - if ($obj->fk_user_modification) - { + if ($obj->fk_user_modification) { $muser = new User($this->db); $muser->fetch($obj->fk_user_modification); $this->user_modification = $muser; } - if ($obj->fk_user_approve) - { + if ($obj->fk_user_approve) { $auser = new User($this->db); $auser->fetch($obj->fk_user_approve); $this->user_approve = $auser; @@ -898,15 +884,13 @@ class ExpenseReport extends CommonObject dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG); $result = $this->db->query($sql); - if ($result) - { + if ($result) { $num = $this->db->num_rows($result); $i = 0; $total_HT = 0; $total_TTC = 0; - while ($i < $num) - { + while ($i < $num) { $objp = $this->db->fetch_object($result); $sql2 = "SELECT d.rowid, d.fk_user_author, d.ref, d.fk_statut as status"; @@ -953,13 +937,13 @@ class ExpenseReport extends CommonObject break; } /* - if ($status==4) return img_picto($langs->trans('StatusOrderCanceled'),'statut5'); - if ($status==1) return img_picto($langs->trans('StatusOrderDraft'),'statut0'); - if ($status==2) return img_picto($langs->trans('StatusOrderValidated'),'statut1'); - if ($status==2) return img_picto($langs->trans('StatusOrderOnProcess'),'statut3'); - if ($status==5) return img_picto($langs->trans('StatusOrderToBill'),'statut4'); - if ($status==6) return img_picto($langs->trans('StatusOrderOnProcess'),'statut6'); - */ + if ($status==4) return img_picto($langs->trans('StatusOrderCanceled'),'statut5'); + if ($status==1) return img_picto($langs->trans('StatusOrderDraft'),'statut0'); + if ($status==2) return img_picto($langs->trans('StatusOrderValidated'),'statut1'); + if ($status==2) return img_picto($langs->trans('StatusOrderOnProcess'),'statut3'); + if ($status==5) return img_picto($langs->trans('StatusOrderToBill'),'statut4'); + if ($status==6) return img_picto($langs->trans('StatusOrderOnProcess'),'statut6'); + */ print ''; print '
'; @@ -994,11 +978,10 @@ class ExpenseReport extends CommonObject $total_ht = 0; $total_tva = 0; $total_ttc = 0; $result = $this->db->query($sql); - if ($result) - { + if ($result) { $num = $this->db->num_rows($result); $i = 0; - while ($i < $num): + while ($i < $num) : $objp = $this->db->fetch_object($result); $total_ht += $objp->total_ht; $total_tva += $objp->total_tva; @@ -1012,7 +995,7 @@ class ExpenseReport extends CommonObject $sql .= " , total_tva = ".$total_tva; $sql .= " WHERE rowid = ".$id; $result = $this->db->query($sql); - if ($result): + if ($result) : $this->db->free($result); return 1; else : @@ -1049,20 +1032,17 @@ class ExpenseReport extends CommonObject $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_type_fees as ctf ON de.fk_c_type_fees = ctf.id'; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as p ON de.fk_projet = p.rowid'; $sql .= ' WHERE de.'.$this->fk_element.' = '.$this->id; - if (!empty($conf->global->EXPENSEREPORT_LINES_SORTED_BY_ROWID)) - { + if (!empty($conf->global->EXPENSEREPORT_LINES_SORTED_BY_ROWID)) { $sql .= ' ORDER BY de.rang ASC, de.rowid ASC'; } else { $sql .= ' ORDER BY de.rang ASC, de.date ASC'; } $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $num = $this->db->num_rows($resql); $i = 0; - while ($i < $num) - { + while ($i < $num) { $objp = $this->db->fetch_object($resql); $deplig = new ExpenseReportLine($this->db); @@ -1128,7 +1108,9 @@ class ExpenseReport extends CommonObject if (!$notrigger) { // Call trigger $result = $this->call_trigger('EXPENSEREPORT_DELETE', $user); - if ($result < 0) { $error++; } + if ($result < 0) { + $error++; + } // End call triggers } @@ -1148,13 +1130,17 @@ class ExpenseReport extends CommonObject if (!$error) { // Delete linked object $res = $this->deleteObjectLinked(); - if ($res < 0) $error++; + if ($res < 0) { + $error++; + } } if (!$error) { // Delete linked contacts $res = $this->delete_linked_contact(); - if ($res < 0) $error++; + if ($res < 0) { + $error++; + } } // Removed extrafields of object @@ -1239,8 +1225,7 @@ class ExpenseReport extends CommonObject $now = dol_now(); // Protection - if ($this->status == self::STATUS_VALIDATED) - { + if ($this->status == self::STATUS_VALIDATED) { dol_syslog(get_class($this)."::valid action abandonned: already validated", LOG_WARNING); return 0; } @@ -1248,13 +1233,14 @@ class ExpenseReport extends CommonObject $this->date_valid = $now; // Required for the getNextNum later. // Define new ref - if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life - { + if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life $num = $this->getNextNumRef(); } else { $num = $this->ref; } - if (empty($num) || $num < 0) return -1; + if (empty($num) || $num < 0) { + return -1; + } $this->newref = dol_sanitizeFileName($num); @@ -1269,10 +1255,8 @@ class ExpenseReport extends CommonObject $sql .= " WHERE rowid = ".$this->id; $resql = $this->db->query($sql); - if ($resql) - { - if (!$error && !$notrigger) - { + if ($resql) { + if (!$error && !$notrigger) { // Call trigger $result = $this->call_trigger('EXPENSE_REPORT_VALIDATE', $fuser); if ($result < 0) { @@ -1281,37 +1265,34 @@ class ExpenseReport extends CommonObject // End call triggers } - if (!$error) - { + if (!$error) { $this->oldref = $this->ref; // Rename directory if dir was a temporary ref - if (preg_match('/^[\(]?PROV/i', $this->ref)) - { + if (preg_match('/^[\(]?PROV/i', $this->ref)) { require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; // Now we rename also files into index $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'expensereport/".$this->db->escape($this->newref)."'"; $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'expensereport/".$this->db->escape($this->ref)."' and entity = ".$conf->entity; $resql = $this->db->query($sql); - if (!$resql) { $error++; $this->error = $this->db->lasterror(); } + if (!$resql) { + $error++; $this->error = $this->db->lasterror(); + } // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments $oldref = dol_sanitizeFileName($this->ref); $newref = dol_sanitizeFileName($num); $dirsource = $conf->expensereport->dir_output.'/'.$oldref; $dirdest = $conf->expensereport->dir_output.'/'.$newref; - if (!$error && file_exists($dirsource)) - { + if (!$error && file_exists($dirsource)) { dol_syslog(get_class($this)."::setValidate() rename dir ".$dirsource." into ".$dirdest); - if (@rename($dirsource, $dirdest)) - { + if (@rename($dirsource, $dirdest)) { dol_syslog("Rename ok"); // Rename docs starting with $oldref with $newref $listoffiles = dol_dir_list($conf->expensereport->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/')); - foreach ($listoffiles as $fileentry) - { + foreach ($listoffiles as $fileentry) { $dirsource = $fileentry['name']; $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource); $dirsource = $fileentry['path'].'/'.$dirsource; @@ -1324,14 +1305,12 @@ class ExpenseReport extends CommonObject } // Set new ref and current status - if (!$error) - { + if (!$error) { $this->ref = $num; $this->status = self::STATUS_VALIDATED; } - if (empty($error)) - { + if (empty($error)) { $this->db->commit(); return 1; } else { @@ -1369,16 +1348,14 @@ class ExpenseReport extends CommonObject $this->date_debut = $this->db->jdate($objp->date_debut); - if ($this->status != self::STATUS_VALIDATED) - { + if ($this->status != self::STATUS_VALIDATED) { $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; $sql .= " SET fk_statut = ".self::STATUS_VALIDATED; $sql .= ' WHERE rowid = '.$this->id; dol_syslog(get_class($this)."::set_save_from_refuse sql=".$sql, LOG_DEBUG); - if ($this->db->query($sql)) - { + if ($this->db->query($sql)) { return 1; } else { $this->error = $this->db->lasterror(); @@ -1403,18 +1380,15 @@ class ExpenseReport extends CommonObject // date approval $this->date_approve = $now; - if ($this->status != self::STATUS_APPROVED) - { + if ($this->status != self::STATUS_APPROVED) { $this->db->begin(); $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; $sql .= " SET ref = '".$this->db->escape($this->ref)."', fk_statut = ".self::STATUS_APPROVED.", fk_user_approve = ".$fuser->id.","; $sql .= " date_approve='".$this->db->idate($this->date_approve)."'"; $sql .= ' WHERE rowid = '.$this->id; - if ($this->db->query($sql)) - { - if (!$notrigger) - { + if ($this->db->query($sql)) { + if (!$notrigger) { // Call trigger $result = $this->call_trigger('EXPENSE_REPORT_APPROVE', $fuser); @@ -1424,8 +1398,7 @@ class ExpenseReport extends CommonObject // End call triggers } - if (empty($error)) - { + if (empty($error)) { $this->db->commit(); return 1; } else { @@ -1459,24 +1432,21 @@ class ExpenseReport extends CommonObject $error = 0; // date de refus - if ($this->status != self::STATUS_REFUSED) - { + if ($this->status != self::STATUS_REFUSED) { $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; $sql .= " SET ref = '".$this->db->escape($this->ref)."', fk_statut = ".self::STATUS_REFUSED.", fk_user_refuse = ".$fuser->id.","; $sql .= " date_refuse='".$this->db->idate($now)."',"; $sql .= " detail_refuse='".$this->db->escape($details)."',"; $sql .= " fk_user_approve = NULL"; $sql .= ' WHERE rowid = '.$this->id; - if ($this->db->query($sql)) - { + if ($this->db->query($sql)) { $this->fk_statut = 99; // deprecated $this->status = 99; $this->fk_user_refuse = $fuser->id; $this->detail_refuse = $details; $this->date_refuse = $now; - if (!$notrigger) - { + if (!$notrigger) { // Call trigger $result = $this->call_trigger('EXPENSE_REPORT_DENY', $fuser); @@ -1486,8 +1456,7 @@ class ExpenseReport extends CommonObject // End call triggers } - if (empty($error)) - { + if (empty($error)) { $this->db->commit(); return 1; } else { @@ -1533,8 +1502,7 @@ class ExpenseReport extends CommonObject { $error = 0; - if ($this->paid) - { + if ($this->paid) { $this->db->begin(); $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; @@ -1543,10 +1511,8 @@ class ExpenseReport extends CommonObject dol_syslog(get_class($this)."::set_unpaid sql=".$sql, LOG_DEBUG); - if ($this->db->query($sql)) - { - if (!$notrigger) - { + if ($this->db->query($sql)) { + if (!$notrigger) { // Call trigger $result = $this->call_trigger('EXPENSE_REPORT_UNPAID', $fuser); @@ -1556,8 +1522,7 @@ class ExpenseReport extends CommonObject // End call triggers } - if (empty($error)) - { + if (empty($error)) { $this->db->commit(); return 1; } else { @@ -1589,8 +1554,7 @@ class ExpenseReport extends CommonObject // phpcs:enable $error = 0; $this->date_cancel = $this->db->idate(dol_now()); - if ($this->status != self::STATUS_CANCELED) - { + if ($this->status != self::STATUS_CANCELED) { $this->db->begin(); $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; @@ -1601,10 +1565,8 @@ class ExpenseReport extends CommonObject dol_syslog(get_class($this)."::set_cancel sql=".$sql, LOG_DEBUG); - if ($this->db->query($sql)) - { - if (!$notrigger) - { + if ($this->db->query($sql)) { + if (!$notrigger) { // Call trigger $result = $this->call_trigger('EXPENSE_REPORT_CANCEL', $fuser); @@ -1614,8 +1576,7 @@ class ExpenseReport extends CommonObject // End call triggers } - if (empty($error)) - { + if (empty($error)) { $this->db->commit(); return 1; } else { @@ -1643,8 +1604,7 @@ class ExpenseReport extends CommonObject global $langs, $conf; $langs->load("trips"); - if (!empty($conf->global->EXPENSEREPORT_ADDON)) - { + if (!empty($conf->global->EXPENSEREPORT_ADDON)) { $mybool = false; $file = $conf->global->EXPENSEREPORT_ADDON.".php"; @@ -1652,8 +1612,7 @@ class ExpenseReport extends CommonObject // Include file with class $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); - foreach ($dirmodels as $reldir) - { + foreach ($dirmodels as $reldir) { $dir = dol_buildpath($reldir."core/modules/expensereport/"); // Load file with numbering class (if found) @@ -1668,8 +1627,7 @@ class ExpenseReport extends CommonObject $obj = new $classname(); $numref = $obj->getNextValue($this); - if ($numref != "") - { + if ($numref != "") { return $numref; } else { $this->error = $obj->error; @@ -1702,38 +1660,50 @@ class ExpenseReport extends CommonObject $url = DOL_URL_ROOT.'/expensereport/card.php?id='.$this->id; - if ($short) return $url; + if ($short) { + return $url; + } $label = img_picto('', $this->picto).' '.$langs->trans("ExpenseReport").''; if (isset($this->status)) { $label .= ' '.$this->getLibStatut(5); } - if (!empty($this->ref)) + if (!empty($this->ref)) { $label .= '
'.$langs->trans('Ref').': '.$this->ref; - if (!empty($this->total_ht)) + } + if (!empty($this->total_ht)) { $label .= '
'.$langs->trans('AmountHT').': '.price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency); - if (!empty($this->total_tva)) + } + if (!empty($this->total_tva)) { $label .= '
'.$langs->trans('VAT').': '.price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency); - if (!empty($this->total_ttc)) + } + if (!empty($this->total_ttc)) { $label .= '
'.$langs->trans('AmountTTC').': '.price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency); - if ($moretitle) $label .= ' - '.$moretitle; + } + if ($moretitle) { + $label .= ' - '.$moretitle; + } //if ($option != 'nolink') //{ // Add param to save lastsearch_values or not $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); - if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1; - if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1'; + if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) { + $add_save_lastsearch_values = 1; + } + if ($add_save_lastsearch_values) { + $url .= '&save_lastsearch_values=1'; + } //} $ref = $this->ref; - if (empty($ref)) $ref = $this->id; + if (empty($ref)) { + $ref = $this->id; + } $linkclose = ''; - if (empty($notooltip)) - { - if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) - { + if (empty($notooltip)) { + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { $label = $langs->trans("ShowExpenseReport"); $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; } @@ -1746,8 +1716,12 @@ class ExpenseReport extends CommonObject $linkend = ''; $result .= $linkstart; - if ($withpicto) $result .= img_object(($notooltip ? '' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); - if ($withpicto != 2) $result .= ($max ?dol_trunc($ref, $max) : $ref); + if ($withpicto) { + $result .= img_object(($notooltip ? '' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); + } + if ($withpicto != 2) { + $result .= ($max ?dol_trunc($ref, $max) : $ref); + } $result .= $linkend; return $result; @@ -1775,7 +1749,7 @@ class ExpenseReport extends CommonObject $sql .= " WHERE rowid = ".$this->id; $result = $this->db->query($sql); - if ($result): + if ($result) : return 1; else : $this->error = $this->db->error(); @@ -1805,7 +1779,7 @@ class ExpenseReport extends CommonObject $sql .= " WHERE rowid = ".$this->id; $result = $this->db->query($sql); - if ($result): + if ($result) : return 1; else : $this->error = $this->db->error(); @@ -1834,14 +1808,25 @@ class ExpenseReport extends CommonObject dol_syslog(get_class($this)."::addline qty=$qty, up=$up, fk_c_type_fees=$fk_c_type_fees, vatrate=$vatrate, date=$date, fk_project=$fk_project, type=$type, comments=$comments", LOG_DEBUG); - if ($this->status == self::STATUS_DRAFT) - { - if (empty($qty)) $qty = 0; - if (empty($fk_c_type_fees) || $fk_c_type_fees < 0) $fk_c_type_fees = 0; - if (empty($fk_c_exp_tax_cat) || $fk_c_exp_tax_cat < 0) $fk_c_exp_tax_cat = 0; - if (empty($vatrate) || $vatrate < 0) $vatrate = 0; - if (empty($date)) $date = ''; - if (empty($fk_project)) $fk_project = 0; + if ($this->status == self::STATUS_DRAFT) { + if (empty($qty)) { + $qty = 0; + } + if (empty($fk_c_type_fees) || $fk_c_type_fees < 0) { + $fk_c_type_fees = 0; + } + if (empty($fk_c_exp_tax_cat) || $fk_c_exp_tax_cat < 0) { + $fk_c_exp_tax_cat = 0; + } + if (empty($vatrate) || $vatrate < 0) { + $vatrate = 0; + } + if (empty($date)) { + $date = ''; + } + if (empty($fk_project)) { + $fk_project = 0; + } $qty = price2num($qty); if (!preg_match('/\s*\((.*)\)/', $vatrate)) { @@ -1857,8 +1842,7 @@ class ExpenseReport extends CommonObject $vat_src_code = ''; $reg = array(); - if (preg_match('/\s*\((.*)\)/', $vatrate, $reg)) - { + if (preg_match('/\s*\((.*)\)/', $vatrate, $reg)) { $vat_src_code = $reg[1]; $vatrate = preg_replace('/\s*\(.*\)/', '', $vatrate); // Remove code into vatrate. } @@ -1890,11 +1874,9 @@ class ExpenseReport extends CommonObject $this->checkRules($type, $seller); $result = $this->line->insert(0, true); - if ($result > 0) - { + if ($result > 0) { $result = $this->update_price(); // This method is designed to add line from user input so total calculation must be done using 'auto' mode. - if ($result > 0) - { + if ($result > 0) { $this->db->commit(); return $this->line->id; } else { @@ -1927,7 +1909,9 @@ class ExpenseReport extends CommonObject $langs->load('trips'); - if (empty($conf->global->MAIN_USE_EXPENSE_RULE)) return true; // if don't use rules + if (empty($conf->global->MAIN_USE_EXPENSE_RULE)) { + return true; // if don't use rules + } $rulestocheck = ExpenseReportRule::getAllRule($this->line->fk_c_type_fees, $this->line->date, $this->fk_user_author); @@ -1938,19 +1922,19 @@ class ExpenseReport extends CommonObject $new_current_total_ttc = $this->line->total_ttc; // check if one is violated - foreach ($rulestocheck as $rule) - { - if (in_array($rule->code_expense_rules_type, array('EX_DAY', 'EX_MON', 'EX_YEA'))) $amount_to_test = $this->line->getExpAmount($rule, $this->fk_user_author, $rule->code_expense_rules_type); - else $amount_to_test = $current_total_ttc; // EX_EXP + foreach ($rulestocheck as $rule) { + if (in_array($rule->code_expense_rules_type, array('EX_DAY', 'EX_MON', 'EX_YEA'))) { + $amount_to_test = $this->line->getExpAmount($rule, $this->fk_user_author, $rule->code_expense_rules_type); + } else { + $amount_to_test = $current_total_ttc; // EX_EXP + } $amount_to_test = $amount_to_test - $current_total_ttc + $new_current_total_ttc; // if amount as been modified by a previous rule - if ($amount_to_test > $rule->amount) - { + if ($amount_to_test > $rule->amount) { $violation++; - if ($rule->restrictive) - { + if ($rule->restrictive) { $this->error = 'ExpenseReportConstraintViolationError'; $this->errors[] = $this->error; @@ -1969,8 +1953,7 @@ class ExpenseReport extends CommonObject $this->line->rule_warning_message = implode('\n', $rule_warning_message_tab); - if ($violation > 0) - { + if ($violation > 0) { $tmp = calcul_price_total($this->line->qty, $new_current_total_ttc / $this->line->qty, 0, $this->line->vatrate, 0, 0, 0, 'TTC', 0, $type, $seller); $this->line->value_unit = $tmp[5]; @@ -1979,7 +1962,9 @@ class ExpenseReport extends CommonObject $this->line->total_tva = $tmp[1]; return false; - } else return true; + } else { + return true; + } } /** @@ -1991,11 +1976,12 @@ class ExpenseReport extends CommonObject { global $conf; - if (empty($conf->global->MAIN_USE_EXPENSE_IK)) return false; + if (empty($conf->global->MAIN_USE_EXPENSE_IK)) { + return false; + } $userauthor = new User($this->db); - if ($userauthor->fetch($this->fk_user_author) <= 0) - { + if ($userauthor->fetch($this->fk_user_author) <= 0) { $this->error = 'ErrorCantFetchUser'; $this->errors[] = 'ErrorCantFetchUser'; return false; @@ -2003,19 +1989,20 @@ class ExpenseReport extends CommonObject $range = ExpenseReportIk::getRangeByUser($userauthor, $this->line->fk_c_exp_tax_cat); - if (empty($range)) - { + if (empty($range)) { $this->error = 'ErrorNoRangeAvailable'; $this->errors[] = 'ErrorNoRangeAvailable'; return false; } - if (!empty($conf->global->MAIN_EXPENSE_APPLY_ENTIRE_OFFSET)) $ikoffset = $range->ikoffset; - else $ikoffset = $range->ikoffset / 12; // The amount of offset is a global value for the year + if (!empty($conf->global->MAIN_EXPENSE_APPLY_ENTIRE_OFFSET)) { + $ikoffset = $range->ikoffset; + } else { + $ikoffset = $range->ikoffset / 12; // The amount of offset is a global value for the year + } // Test if ikoffset has been applied for the current month - if (!$this->offsetAlreadyGiven()) - { + if (!$this->offsetAlreadyGiven()) { $new_up = $range->coef + ($ikoffset / $this->line->qty); $tmp = calcul_price_total($this->line->qty, $new_up, 0, $this->line->vatrate, 0, 0, 0, 'TTC', 0, $type, $seller); @@ -2042,14 +2029,17 @@ class ExpenseReport extends CommonObject $sql .= ' INNER JOIN '.MAIN_DB_PREFIX.'c_type_fees f ON (d.fk_c_type_fees = f.id AND f.code = "EX_KME")'; $sql .= ' WHERE e.fk_user_author = '.(int) $this->fk_user_author; $sql .= ' AND YEAR(d.date) = "'.dol_print_date($this->line->date, '%Y').'" AND MONTH(d.date) = "'.dol_print_date($this->line->date, '%m').'"'; - if (!empty($this->line->id)) $sql .= ' AND d.rowid <> '.$this->line->id; + if (!empty($this->line->id)) { + $sql .= ' AND d.rowid <> '.$this->line->id; + } dol_syslog(get_class($this)."::offsetAlreadyGiven sql=".$sql); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $num = $this->db->num_rows($resql); - if ($num > 0) return true; + if ($num > 0) { + return true; + } } else { dol_print_error($this->db); } @@ -2077,8 +2067,7 @@ class ExpenseReport extends CommonObject { global $user, $mysoc; - if ($this->status == self::STATUS_DRAFT || $this->status == self::STATUS_REFUSED) - { + if ($this->status == self::STATUS_DRAFT || $this->status == self::STATUS_REFUSED) { $this->db->begin(); $type = 0; // TODO What if type is service ? @@ -2092,8 +2081,7 @@ class ExpenseReport extends CommonObject // Clean vat code $reg = array(); $vat_src_code = ''; - if (preg_match('/\((.*)\)/', $vatrate, $reg)) - { + if (preg_match('/\((.*)\)/', $vatrate, $reg)) { $vat_src_code = $reg[1]; $vatrate = preg_replace('/\s*\(.*\)/', '', $vatrate); // Remove code into vatrate. } @@ -2138,8 +2126,7 @@ class ExpenseReport extends CommonObject $sql .= " FROM ".MAIN_DB_PREFIX."c_type_fees as c"; $sql .= " WHERE c.id = ".$type_fees_id; $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $objp_fees = $this->db->fetch_object($resql); $this->line->type_fees_code = $objp_fees->code_type_fees; $this->line->type_fees_libelle = $objp_fees->libelle_type_fees; @@ -2162,8 +2149,7 @@ class ExpenseReport extends CommonObject $this->checkRules(); $result = $this->line->update($user); - if ($result > 0) - { + if ($result > 0) { $this->db->commit(); return 1; } else { @@ -2191,8 +2177,7 @@ class ExpenseReport extends CommonObject dol_syslog(get_class($this)."::deleteline sql=".$sql); $result = $this->db->query($sql); - if (!$result) - { + if (!$result) { $this->error = $this->db->error(); dol_syslog(get_class($this)."::deleteline Error ".$this->error, LOG_ERR); $this->db->rollback(); @@ -2225,27 +2210,30 @@ class ExpenseReport extends CommonObject if ($result) { $num_rows = $this->db->num_rows($result); $i = 0; - if ($num_rows > 0) - { + if ($num_rows > 0) { $date_d_form = $date_debut; $date_f_form = $date_fin; $existe = false; - while ($i < $num_rows) - { + while ($i < $num_rows) { $objp = $this->db->fetch_object($result); $date_d_req = $this->db->jdate($objp->date_debut); // 3 $date_f_req = $this->db->jdate($objp->date_fin); // 4 - if (!($date_f_form < $date_d_req || $date_d_form > $date_f_req)) $existe = true; + if (!($date_f_form < $date_d_req || $date_d_form > $date_f_req)) { + $existe = true; + } $i++; } - if ($existe) return 1; - else return 0; + if ($existe) { + return 1; + } else { + return 0; + } } else { return 0; } @@ -2280,11 +2268,9 @@ class ExpenseReport extends CommonObject dol_syslog(get_class($this)."::fetch_users_approver_expensereport sql=".$sql); $result = $this->db->query($sql); - if ($result) - { + if ($result) { $num_rows = $this->db->num_rows($result); $i = 0; - while ($i < $num_rows) - { + while ($i < $num_rows) { $objp = $this->db->fetch_object($result); array_push($users_validator, $objp->fk_user); $i++; @@ -2348,12 +2334,10 @@ class ExpenseReport extends CommonObject $sql .= " WHERE active = ".$active; dol_syslog(get_class($this)."::listOfTypes", LOG_DEBUG); $result = $this->db->query($sql); - if ($result) - { + if ($result) { $num = $this->db->num_rows($result); $i = 0; - while ($i < $num) - { + while ($i < $num) { $obj = $this->db->fetch_object($result); $ret[$obj->code] = (($langs->transnoentitiesnoconv($obj->code) != $obj->code) ? $langs->transnoentitiesnoconv($obj->code) : $obj->label); $i++; @@ -2381,8 +2365,7 @@ class ExpenseReport extends CommonObject $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as ex"; $sql .= " WHERE ex.fk_statut > 0"; $sql .= " AND ex.entity IN (".getEntity('expensereport').")"; - if (empty($user->rights->expensereport->readall)) - { + if (empty($user->rights->expensereport->readall)) { $userchildids = $user->getAllChildIds(1); $sql .= " AND (ex.fk_user_author IN (".join(',', $userchildids).")"; $sql .= " OR ex.fk_user_validator IN (".join(',', $userchildids)."))"; @@ -2415,30 +2398,32 @@ class ExpenseReport extends CommonObject // phpcs:enable global $conf, $langs; - if ($user->socid) return -1; // protection pour eviter appel par utilisateur externe + if ($user->socid) { + return -1; // protection pour eviter appel par utilisateur externe + } $now = dol_now(); $sql = "SELECT ex.rowid, ex.date_valid"; $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as ex"; - if ($option == 'toapprove') $sql .= " WHERE ex.fk_statut = ".self::STATUS_VALIDATED; - else $sql .= " WHERE ex.fk_statut = ".self::STATUS_APPROVED; + if ($option == 'toapprove') { + $sql .= " WHERE ex.fk_statut = ".self::STATUS_VALIDATED; + } else { + $sql .= " WHERE ex.fk_statut = ".self::STATUS_APPROVED; + } $sql .= " AND ex.entity IN (".getEntity('expensereport').")"; - if (empty($user->rights->expensereport->readall)) - { + if (empty($user->rights->expensereport->readall)) { $userchildids = $user->getAllChildIds(1); $sql .= " AND (ex.fk_user_author IN (".join(',', $userchildids).")"; $sql .= " OR ex.fk_user_validator IN (".join(',', $userchildids)."))"; } $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $langs->load("trips"); $response = new WorkboardResponse(); - if ($option == 'toapprove') - { + if ($option == 'toapprove') { $response->warning_delay = $conf->expensereport->approve->warning_delay / 60 / 60 / 24; $response->label = $langs->trans("ExpenseReportsToApprove"); $response->labelShort = $langs->trans("ToApprove"); @@ -2451,12 +2436,10 @@ class ExpenseReport extends CommonObject } $response->img = img_object('', "trip"); - while ($obj = $this->db->fetch_object($resql)) - { + while ($obj = $this->db->fetch_object($resql)) { $response->nbtodo++; - if ($option == 'toapprove') - { + if ($option == 'toapprove') { if ($this->db->jdate($obj->date_valid) < ($now - $conf->expensereport->approve->warning_delay)) { $response->nbtodolate++; } @@ -2486,8 +2469,12 @@ class ExpenseReport extends CommonObject global $conf; // Only valid expenses reports - if ($option == 'toapprove' && $this->status != 2) return false; - if ($option == 'topay' && $this->status != 5) return false; + if ($option == 'toapprove' && $this->status != 2) { + return false; + } + if ($option == 'topay' && $this->status != 5) { + return false; + } $now = dol_now(); if ($option == 'toapprove') { @@ -2510,11 +2497,9 @@ class ExpenseReport extends CommonObject $sql = " SELECT COUNT(ab.rowid) as nb FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type='".$this->db->escape($type)."' AND ab.fk_doc = ".$this->id; $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $obj = $this->db->fetch_object($resql); - if ($obj) - { + if ($obj) { $alreadydispatched = $obj->nb; } } else { @@ -2522,8 +2507,7 @@ class ExpenseReport extends CommonObject return -1; } - if ($alreadydispatched) - { + if ($alreadydispatched) { return 1; } return 0; @@ -2545,8 +2529,7 @@ class ExpenseReport extends CommonObject dol_syslog(get_class($this)."::getSumPayments", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $obj = $this->db->fetch_object($resql); $this->db->free($resql); return (empty($obj->amount) ? 0 : $obj->amount); @@ -2649,8 +2632,7 @@ class ExpenseReportLine $result = $this->db->query($sql); - if ($result) - { + if ($result) { $objp = $this->db->fetch_object($result); $this->rowid = $objp->rowid; @@ -2700,10 +2682,14 @@ class ExpenseReportLine // Clean parameters $this->comments = trim($this->comments); - if (empty($this->value_unit)) $this->value_unit = 0; + if (empty($this->value_unit)) { + $this->value_unit = 0; + } $this->qty = price2num($this->qty); $this->vatrate = price2num($this->vatrate); - if (empty($this->fk_c_exp_tax_cat)) $this->fk_c_exp_tax_cat = 0; + if (empty($this->fk_c_exp_tax_cat)) { + $this->fk_c_exp_tax_cat = 0; + } $this->db->begin(); @@ -2728,17 +2714,14 @@ class ExpenseReportLine $sql .= ")"; $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'expensereport_det'); - if (!$fromaddline) - { + if (!$fromaddline) { $tmpparent = new ExpenseReport($this->db); $tmpparent->fetch($this->fk_expensereport); $result = $tmpparent->update_price(); - if ($result < 0) - { + if ($result < 0) { $error++; $this->error = $tmpparent->error; $this->errors = $tmpparent->errors; @@ -2748,8 +2731,7 @@ class ExpenseReportLine $error++; } - if (!$error) - { + if (!$error) { $this->db->commit(); return $this->id; } else { @@ -2776,20 +2758,24 @@ class ExpenseReportLine $sql .= ' FROM '.MAIN_DB_PREFIX.'expensereport_det d'; $sql .= ' INNER JOIN '.MAIN_DB_PREFIX.'expensereport e ON (d.fk_expensereport = e.rowid)'; $sql .= ' WHERE e.fk_user_author = '.$fk_user; - if (!empty($this->id)) $sql .= ' AND d.rowid <> '.$this->id; + if (!empty($this->id)) { + $sql .= ' AND d.rowid <> '.$this->id; + } $sql .= ' AND d.fk_c_type_fees = '.$rule->fk_c_type_fees; - if ($mode == 'day' || $mode == 'EX_DAY') $sql .= ' AND d.date = \''.dol_print_date($this->date, '%Y-%m-%d').'\''; - elseif ($mode == 'mon' || $mode == 'EX_MON') $sql .= ' AND DATE_FORMAT(d.date, \'%Y-%m\') = \''.dol_print_date($this->date, '%Y-%m').'\''; // @todo DATE_FORMAT is forbidden - elseif ($mode == 'year' || $mode == 'EX_YEA') $sql .= ' AND DATE_FORMAT(d.date, \'%Y\') = \''.dol_print_date($this->date, '%Y').'\''; // @todo DATE_FORMAT is forbidden + if ($mode == 'day' || $mode == 'EX_DAY') { + $sql .= ' AND d.date = \''.dol_print_date($this->date, '%Y-%m-%d').'\''; + } elseif ($mode == 'mon' || $mode == 'EX_MON') { + $sql .= ' AND DATE_FORMAT(d.date, \'%Y-%m\') = \''.dol_print_date($this->date, '%Y-%m').'\''; // @todo DATE_FORMAT is forbidden + } elseif ($mode == 'year' || $mode == 'EX_YEA') { + $sql .= ' AND DATE_FORMAT(d.date, \'%Y\') = \''.dol_print_date($this->date, '%Y').'\''; // @todo DATE_FORMAT is forbidden + } dol_syslog('ExpenseReportLine::getExpAmount'); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $num = $this->db->num_rows($resql); - if ($num > 0) - { + if ($num > 0) { $obj = $this->db->fetch_object($resql); $amount = (double) $obj->total_amount; } @@ -2816,7 +2802,9 @@ class ExpenseReportLine $this->comments = trim($this->comments); $this->vatrate = price2num($this->vatrate); $this->value_unit = price2num($this->value_unit); - if (empty($this->fk_c_exp_tax_cat)) $this->fk_c_exp_tax_cat = 0; + if (empty($this->fk_c_exp_tax_cat)) { + $this->fk_c_exp_tax_cat = 0; + } $this->db->begin(); @@ -2834,24 +2822,27 @@ class ExpenseReportLine $sql .= ",rule_warning_message='".$this->db->escape($this->rule_warning_message)."'"; $sql .= ",fk_c_exp_tax_cat=".$this->db->escape($this->fk_c_exp_tax_cat); $sql .= ",fk_ecm_files=".($this->fk_ecm_files > 0 ? $this->fk_ecm_files : 'null'); - if ($this->fk_c_type_fees) $sql .= ",fk_c_type_fees=".$this->db->escape($this->fk_c_type_fees); - else $sql .= ",fk_c_type_fees=null"; - if ($this->fk_project > 0) $sql .= ",fk_projet=".$this->db->escape($this->fk_project); - else $sql .= ",fk_projet=null"; + if ($this->fk_c_type_fees) { + $sql .= ",fk_c_type_fees=".$this->db->escape($this->fk_c_type_fees); + } else { + $sql .= ",fk_c_type_fees=null"; + } + if ($this->fk_project > 0) { + $sql .= ",fk_projet=".$this->db->escape($this->fk_project); + } else { + $sql .= ",fk_projet=null"; + } $sql .= " WHERE rowid = ".$this->db->escape($this->rowid ? $this->rowid : $this->id); dol_syslog("ExpenseReportLine::update sql=".$sql); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $tmpparent = new ExpenseReport($this->db); $result = $tmpparent->fetch($this->fk_expensereport); - if ($result > 0) - { + if ($result > 0) { $result = $tmpparent->update_price(); - if ($result < 0) - { + if ($result < 0) { $error++; $this->error = $tmpparent->error; $this->errors = $tmpparent->errors; @@ -2866,8 +2857,7 @@ class ExpenseReportLine dol_print_error($this->db); } - if (!$error) - { + if (!$error) { $this->db->commit(); return 1; } else { diff --git a/htdocs/expensereport/class/expensereport_ik.class.php b/htdocs/expensereport/class/expensereport_ik.class.php index 55af1eb00ed..18a0503cdd7 100644 --- a/htdocs/expensereport/class/expensereport_ik.class.php +++ b/htdocs/expensereport/class/expensereport_ik.class.php @@ -111,15 +111,16 @@ class ExpenseReportIk extends CoreObject $sql = 'SELECT rowid, label, entity, active'; $sql .= ' FROM '.MAIN_DB_PREFIX.'c_exp_tax_cat'; $sql .= ' WHERE entity IN ('.getEntity('c_exp_tax_cat').')'; - if ($mode == 1) $sql .= ' AND active = 1'; - elseif ($mode == 2) $sql .= 'AND active = 0'; + if ($mode == 1) { + $sql .= ' AND active = 1'; + } elseif ($mode == 2) { + $sql .= 'AND active = 0'; + } dol_syslog(get_called_class().'::getTaxCategories sql='.$sql, LOG_DEBUG); $resql = $db->query($sql); - if ($resql) - { - while ($obj = $db->fetch_object($resql)) - { + if ($resql) { + while ($obj = $db->fetch_object($resql)) { $categories[$obj->rowid] = $obj; } } else { @@ -142,8 +143,11 @@ class ExpenseReportIk extends CoreObject $ranges = self::getRangesByCategory($fk_c_exp_tax_cat); // substract 1 because array start from 0 - if (empty($ranges) || !isset($ranges[$default_range - 1])) return false; - else return $ranges[$default_range - 1]; + if (empty($ranges) || !isset($ranges[$default_range - 1])) { + return false; + } else { + return $ranges[$default_range - 1]; + } } /** @@ -160,20 +164,21 @@ class ExpenseReportIk extends CoreObject $ranges = array(); $sql = 'SELECT r.rowid FROM '.MAIN_DB_PREFIX.'c_exp_tax_range r'; - if ($active) $sql .= ' INNER JOIN '.MAIN_DB_PREFIX.'c_exp_tax_cat c ON (r.fk_c_exp_tax_cat = c.rowid)'; + if ($active) { + $sql .= ' INNER JOIN '.MAIN_DB_PREFIX.'c_exp_tax_cat c ON (r.fk_c_exp_tax_cat = c.rowid)'; + } $sql .= ' WHERE r.fk_c_exp_tax_cat = '.$fk_c_exp_tax_cat; - if ($active) $sql .= ' AND r.active = 1 AND c.active = 1'; + if ($active) { + $sql .= ' AND r.active = 1 AND c.active = 1'; + } $sql .= ' ORDER BY r.range_ik'; dol_syslog(get_called_class().'::getRangesByCategory sql='.$sql, LOG_DEBUG); $resql = $db->query($sql); - if ($resql) - { + if ($resql) { $num = $db->num_rows($resql); - if ($num > 0) - { - while ($obj = $db->fetch_object($resql)) - { + if ($num > 0) { + while ($obj = $db->fetch_object($resql)) { $object = new ExpenseReportIk($db); $object->fetch($obj->rowid); @@ -207,15 +212,17 @@ class ExpenseReportIk extends CoreObject dol_syslog(get_called_class().'::getAllRanges sql='.$sql, LOG_DEBUG); $resql = $db->query($sql); - if ($resql) - { - while ($obj = $db->fetch_object($resql)) - { + if ($resql) { + while ($obj = $db->fetch_object($resql)) { $ik = new ExpenseReportIk($db); - if ($obj->fk_expense_ik > 0) $ik->fetch($obj->fk_expense_ik); + if ($obj->fk_expense_ik > 0) { + $ik->fetch($obj->fk_expense_ik); + } $obj->ik = $ik; - if (!isset($ranges[$obj->fk_c_exp_tax_cat])) $ranges[$obj->fk_c_exp_tax_cat] = array('label' => $obj->label, 'active' => $obj->cat_active, 'ranges' => array()); + if (!isset($ranges[$obj->fk_c_exp_tax_cat])) { + $ranges[$obj->fk_c_exp_tax_cat] = array('label' => $obj->label, 'active' => $obj->cat_active, 'ranges' => array()); + } $ranges[$obj->fk_c_exp_tax_cat]['ranges'][] = $obj; } } else { @@ -239,14 +246,15 @@ class ExpenseReportIk extends CoreObject $sql .= ' SELECT COUNT(*) as counted'; $sql .= ' FROM '.MAIN_DB_PREFIX.'c_exp_tax_range r'; $sql .= ' WHERE r.entity IN (0, '.$conf->entity.')'; - if ($default_c_exp_tax_cat > 0) $sql .= ' AND r.fk_c_exp_tax_cat = '.$default_c_exp_tax_cat; + if ($default_c_exp_tax_cat > 0) { + $sql .= ' AND r.fk_c_exp_tax_cat = '.$default_c_exp_tax_cat; + } $sql .= ' GROUP BY r.fk_c_exp_tax_cat'; $sql .= ') as counts'; dol_syslog(get_called_class().'::getMaxRangeNumber sql='.$sql, LOG_DEBUG); $resql = $db->query($sql); - if ($resql) - { + if ($resql) { $obj = $db->fetch_object($resql); return $obj->nbRange; } else { diff --git a/htdocs/expensereport/class/expensereport_rule.class.php b/htdocs/expensereport/class/expensereport_rule.class.php index 9a172cd7563..4e4d1009750 100644 --- a/htdocs/expensereport/class/expensereport_rule.class.php +++ b/htdocs/expensereport/class/expensereport_rule.class.php @@ -156,18 +156,15 @@ class ExpenseReportRule extends CoreObject $sql = 'SELECT er.rowid'; $sql .= ' FROM '.MAIN_DB_PREFIX.'expensereport_rules er'; $sql .= ' WHERE er.entity IN (0,'.getEntity('').')'; - if (!empty($fk_c_type_fees)) - { + if (!empty($fk_c_type_fees)) { $sql .= ' AND er.fk_c_type_fees IN (-1, '.$fk_c_type_fees.')'; } - if (!empty($date)) - { + if (!empty($date)) { $date = dol_print_date($date, '%Y-%m-%d'); $sql .= ' AND er.dates <= \''.$date.'\''; $sql .= ' AND er.datee >= \''.$date.'\''; } - if ($fk_user > 0) - { + if ($fk_user > 0) { $sql .= ' AND (er.is_for_all = 1'; $sql .= ' OR er.fk_user = '.$fk_user; $sql .= ' OR er.fk_usergroup IN (SELECT ugu.fk_usergroup FROM '.MAIN_DB_PREFIX.'usergroup_user ugu WHERE ugu.fk_user = '.$fk_user.') )'; @@ -177,13 +174,14 @@ class ExpenseReportRule extends CoreObject dol_syslog("ExpenseReportRule::getAllRule sql=".$sql); $resql = $db->query($sql); - if ($resql) - { - while ($obj = $db->fetch_object($resql)) - { + if ($resql) { + while ($obj = $db->fetch_object($resql)) { $rule = new ExpenseReportRule($db); - if ($rule->fetch($obj->rowid) > 0) $rules[$rule->id] = $rule; - else dol_print_error($db); + if ($rule->fetch($obj->rowid) > 0) { + $rules[$rule->id] = $rule; + } else { + dol_print_error($db); + } } } else { dol_print_error($db); @@ -201,11 +199,9 @@ class ExpenseReportRule extends CoreObject { include_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php'; - if ($this->fk_usergroup > 0) - { + if ($this->fk_usergroup > 0) { $group = new UserGroup($this->db); - if ($group->fetch($this->fk_usergroup) > 0) - { + if ($group->fetch($this->fk_usergroup) > 0) { return $group->nom; } else { $this->error = $group->error; @@ -225,11 +221,9 @@ class ExpenseReportRule extends CoreObject { include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; - if ($this->fk_user > 0) - { + if ($this->fk_user > 0) { $u = new User($this->db); - if ($u->fetch($this->fk_user) > 0) - { + if ($u->fetch($this->fk_user) > 0) { return dolGetFirstLastname($u->firstname, $u->lastname); } else { $this->error = $u->error; diff --git a/htdocs/expensereport/class/expensereportstats.class.php b/htdocs/expensereport/class/expensereportstats.class.php index c4167e3002f..3d627cbce8d 100644 --- a/htdocs/expensereport/class/expensereportstats.class.php +++ b/htdocs/expensereport/class/expensereportstats.class.php @@ -70,20 +70,20 @@ class ExpenseReportStats extends Stats $this->where .= ' e.entity IN ('.getEntity('expensereport').')'; //$this->where.= " AND entity = ".$conf->entity; - if ($this->socid) - { + if ($this->socid) { $this->where .= " AND e.fk_soc = ".$this->socid; } // Only me and subordinates - if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)) - { + if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)) { $childids = $user->getAllChildIds(); $childids[] = $user->id; $this->where .= " AND e.fk_user_author IN (".(join(',', $childids)).")"; } - if ($this->userid > 0) $this->where .= ' AND e.fk_user_author = '.$this->userid; + if ($this->userid > 0) { + $this->where .= ' AND e.fk_user_author = '.$this->userid; + } } diff --git a/htdocs/expensereport/class/paymentexpensereport.class.php b/htdocs/expensereport/class/paymentexpensereport.class.php index be8693f223e..56525e7b99c 100644 --- a/htdocs/expensereport/class/paymentexpensereport.class.php +++ b/htdocs/expensereport/class/paymentexpensereport.class.php @@ -119,19 +119,36 @@ class PaymentExpenseReport extends CommonObject } // Clean parameters - if (isset($this->fk_expensereport)) $this->fk_expensereport = trim($this->fk_expensereport); - if (isset($this->amount)) $this->amount = trim($this->amount); - if (isset($this->fk_typepayment)) $this->fk_typepayment = trim($this->fk_typepayment); - if (isset($this->num_payment)) $this->num_payment = trim($this->num_payment); - if (isset($this->note)) $this->note = trim($this->note); - if (isset($this->note_public)) $this->note_public = trim($this->note_public); - if (isset($this->fk_bank)) $this->fk_bank = trim($this->fk_bank); - if (isset($this->fk_user_creat)) $this->fk_user_creat = trim($this->fk_user_creat); - if (isset($this->fk_user_modif)) $this->fk_user_modif = trim($this->fk_user_modif); + if (isset($this->fk_expensereport)) { + $this->fk_expensereport = trim($this->fk_expensereport); + } + if (isset($this->amount)) { + $this->amount = trim($this->amount); + } + if (isset($this->fk_typepayment)) { + $this->fk_typepayment = trim($this->fk_typepayment); + } + if (isset($this->num_payment)) { + $this->num_payment = trim($this->num_payment); + } + if (isset($this->note)) { + $this->note = trim($this->note); + } + if (isset($this->note_public)) { + $this->note_public = trim($this->note_public); + } + if (isset($this->fk_bank)) { + $this->fk_bank = trim($this->fk_bank); + } + if (isset($this->fk_user_creat)) { + $this->fk_user_creat = trim($this->fk_user_creat); + } + if (isset($this->fk_user_modif)) { + $this->fk_user_modif = trim($this->fk_user_modif); + } $totalamount = 0; - foreach ($this->amounts as $key => $value) // How payment is dispatch - { + foreach ($this->amounts as $key => $value) { // How payment is dispatch $newvalue = price2num($value, 'MT'); $this->amounts[$key] = $newvalue; $totalamount += $newvalue; @@ -139,13 +156,14 @@ class PaymentExpenseReport extends CommonObject $totalamount = price2num($totalamount); // Check parameters - if ($totalamount == 0) return -1; // On accepte les montants negatifs pour les rejets de prelevement mais pas null + if ($totalamount == 0) { + return -1; // On accepte les montants negatifs pour les rejets de prelevement mais pas null + } $this->db->begin(); - if ($totalamount != 0) - { + if ($totalamount != 0) { $sql = "INSERT INTO ".MAIN_DB_PREFIX."payment_expensereport (fk_expensereport, datec, datep, amount,"; $sql .= " fk_typepayment, num_payment, note, fk_user_creat, fk_bank)"; $sql .= " VALUES ($this->fk_expensereport, '".$this->db->idate($now)."',"; @@ -156,16 +174,14 @@ class PaymentExpenseReport extends CommonObject dol_syslog(get_class($this)."::create", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."payment_expensereport"); } else { $error++; } } - if ($totalamount != 0 && !$error) - { + if ($totalamount != 0 && !$error) { $this->amount = $totalamount; $this->db->commit(); return $this->id; @@ -206,10 +222,8 @@ class PaymentExpenseReport extends CommonObject dol_syslog(get_class($this)."::fetch", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { - if ($this->db->num_rows($resql)) - { + if ($resql) { + if ($this->db->num_rows($resql)) { $obj = $this->db->fetch_object($resql); $this->id = $obj->rowid; @@ -258,14 +272,30 @@ class PaymentExpenseReport extends CommonObject // Clean parameters - if (isset($this->fk_expensereport)) $this->fk_expensereport = trim($this->fk_expensereport); - if (isset($this->amount)) $this->amount = trim($this->amount); - if (isset($this->fk_typepayment)) $this->fk_typepayment = trim($this->fk_typepayment); - if (isset($this->num_payment)) $this->num_payment = trim($this->num_payment); - if (isset($this->note)) $this->note = trim($this->note); - if (isset($this->fk_bank)) $this->fk_bank = trim($this->fk_bank); - if (isset($this->fk_user_creat)) $this->fk_user_creat = trim($this->fk_user_creat); - if (isset($this->fk_user_modif)) $this->fk_user_modif = trim($this->fk_user_modif); + if (isset($this->fk_expensereport)) { + $this->fk_expensereport = trim($this->fk_expensereport); + } + if (isset($this->amount)) { + $this->amount = trim($this->amount); + } + if (isset($this->fk_typepayment)) { + $this->fk_typepayment = trim($this->fk_typepayment); + } + if (isset($this->num_payment)) { + $this->num_payment = trim($this->num_payment); + } + if (isset($this->note)) { + $this->note = trim($this->note); + } + if (isset($this->fk_bank)) { + $this->fk_bank = trim($this->fk_bank); + } + if (isset($this->fk_user_creat)) { + $this->fk_user_creat = trim($this->fk_user_creat); + } + if (isset($this->fk_user_modif)) { + $this->fk_user_modif = trim($this->fk_user_modif); + } // Check parameters @@ -293,13 +323,13 @@ class PaymentExpenseReport extends CommonObject dol_syslog(get_class($this)."::update", LOG_DEBUG); $resql = $this->db->query($sql); - if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } + if (!$resql) { + $error++; $this->errors[] = "Error ".$this->db->lasterror(); + } // Commit or rollback - if ($error) - { - foreach ($this->errors as $errmsg) - { + if ($error) { + foreach ($this->errors as $errmsg) { dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } @@ -327,18 +357,18 @@ class PaymentExpenseReport extends CommonObject $this->db->begin(); - if (!$error) - { + if (!$error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_url"; $sql .= " WHERE type='payment_expensereport' AND url_id=".$this->id; dol_syslog(get_class($this)."::delete", LOG_DEBUG); $resql = $this->db->query($sql); - if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } + if (!$resql) { + $error++; $this->errors[] = "Error ".$this->db->lasterror(); + } } - if (!$error) - { + if (!$error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_expensereport"; $sql .= " WHERE rowid=".$this->id; @@ -351,10 +381,8 @@ class PaymentExpenseReport extends CommonObject } // Commit or rollback - if ($error) - { - foreach ($this->errors as $errmsg) - { + if ($error) { + foreach ($this->errors as $errmsg) { dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } @@ -396,8 +424,7 @@ class PaymentExpenseReport extends CommonObject $result = $object->create($user); // Other options - if ($result < 0) - { + if ($result < 0) { $this->error = $object->error; $error++; } @@ -405,8 +432,7 @@ class PaymentExpenseReport extends CommonObject unset($object->context['createfromclone']); // End - if (!$error) - { + if (!$error) { $this->db->commit(); return $object->id; } else { @@ -487,8 +513,7 @@ class PaymentExpenseReport extends CommonObject $error = 0; - if (!empty($conf->banque->enabled)) - { + if (!empty($conf->banque->enabled)) { include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; $acc = new Account($this->db); @@ -497,7 +522,9 @@ class PaymentExpenseReport extends CommonObject //Fix me field $total = $this->amount; - if ($mode == 'payment_expensereport') $amount = $total; + if ($mode == 'payment_expensereport') { + $amount = $total; + } // Insert payment into llx_bank $bank_line_id = $acc->addline( @@ -514,35 +541,30 @@ class PaymentExpenseReport extends CommonObject // Update fk_bank in llx_paiement. // On connait ainsi le paiement qui a genere l'ecriture bancaire - if ($bank_line_id > 0) - { + if ($bank_line_id > 0) { $result = $this->update_fk_bank($bank_line_id); - if ($result <= 0) - { + if ($result <= 0) { $error++; dol_print_error($this->db); } // Add link 'payment', 'payment_supplier', 'payment_expensereport' in bank_url between payment and bank transaction $url = ''; - if ($mode == 'payment_expensereport') $url = DOL_URL_ROOT.'/expensereport/payment/card.php?rowid='; - if ($url) - { + if ($mode == 'payment_expensereport') { + $url = DOL_URL_ROOT.'/expensereport/payment/card.php?rowid='; + } + if ($url) { $result = $acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode); - if ($result <= 0) - { + if ($result <= 0) { $error++; dol_print_error($this->db); } } // Add link 'user' in bank_url between user and bank transaction - if (!$error) - { - foreach ($this->amounts as $key => $value) // We should have always same user but we loop in case of. - { - if ($mode == 'payment_expensereport') - { + if (!$error) { + foreach ($this->amounts as $key => $value) { // We should have always same user but we loop in case of. + if ($mode == 'payment_expensereport') { $fuser = new User($this->db); $fuser->fetch($key); @@ -553,8 +575,7 @@ class PaymentExpenseReport extends CommonObject $fuser->getFullName($langs), 'user' ); - if ($result <= 0) - { + if ($result <= 0) { $this->error = $this->db->lasterror(); dol_syslog(get_class($this).'::addPaymentToBank '.$this->error); $error++; @@ -568,8 +589,7 @@ class PaymentExpenseReport extends CommonObject } } - if (!$error) - { + if (!$error) { return 1; } else { return -1; @@ -591,8 +611,7 @@ class PaymentExpenseReport extends CommonObject dol_syslog(get_class($this)."::update_fk_bank", LOG_DEBUG); $result = $this->db->query($sql); - if ($result) - { + if ($result) { return 1; } else { $this->error = $this->db->error(); @@ -613,17 +632,24 @@ class PaymentExpenseReport extends CommonObject $result = ''; - if (empty($this->ref)) $this->ref = $this->label; + if (empty($this->ref)) { + $this->ref = $this->label; + } $label = $langs->trans("ShowPayment").': '.$this->ref; - if (!empty($this->id)) - { + if (!empty($this->id)) { $link = ''; $linkend = ''; - if ($withpicto) $result .= ($link.img_object($label, 'payment', 'class="classfortooltip"').$linkend.' '); - if ($withpicto && $withpicto != 2) $result .= ' '; - if ($withpicto != 2) $result .= $link.($maxlen ?dol_trunc($this->ref, $maxlen) : $this->ref).$linkend; + if ($withpicto) { + $result .= ($link.img_object($label, 'payment', 'class="classfortooltip"').$linkend.' '); + } + if ($withpicto && $withpicto != 2) { + $result .= ' '; + } + if ($withpicto != 2) { + $result .= $link.($maxlen ?dol_trunc($this->ref, $maxlen) : $this->ref).$linkend; + } } return $result; @@ -644,20 +670,16 @@ class PaymentExpenseReport extends CommonObject dol_syslog(get_class($this).'::info', LOG_DEBUG); $result = $this->db->query($sql); - if ($result) - { - if ($this->db->num_rows($result)) - { + if ($result) { + if ($this->db->num_rows($result)) { $obj = $this->db->fetch_object($result); $this->id = $obj->rowid; - if ($obj->fk_user_creat) - { + if ($obj->fk_user_creat) { $cuser = new User($this->db); $cuser->fetch($obj->fk_user_creat); $this->user_creation = $cuser; } - if ($obj->fk_user_modif) - { + if ($obj->fk_user_modif) { $muser = new User($this->db); $muser->fetch($obj->fk_user_modif); $this->user_modification = $muser; diff --git a/htdocs/expensereport/document.php b/htdocs/expensereport/document.php index 55799b10589..7713745a0a3 100644 --- a/htdocs/expensereport/document.php +++ b/htdocs/expensereport/document.php @@ -45,7 +45,9 @@ $confirm = GETPOST('confirm', 'alpha'); $childids = $user->getAllChildIds(1); // Security check -if ($user->socid) $socid = $user->socid; +if ($user->socid) { + $socid = $user->socid; +} $result = restrictedArea($user, 'expensereport', $id, 'expensereport'); @@ -54,17 +56,22 @@ $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST('sortfield', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); -if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +if (empty($page) || $page == -1) { + $page = 0; +} // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -if (!$sortorder) $sortorder = "ASC"; -if (!$sortfield) $sortfield = "position_name"; +if (!$sortorder) { + $sortorder = "ASC"; +} +if (!$sortfield) { + $sortfield = "position_name"; +} $object = new ExpenseReport($db); -if (!$object->fetch($id, $ref) > 0) -{ +if (!$object->fetch($id, $ref) > 0) { dol_print_error($db); } @@ -74,14 +81,16 @@ $modulepart = 'trip'; // Load object //include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals -if ($object->id > 0) -{ +if ($object->id > 0) { // Check current user can read this expense report $canread = 0; - if (!empty($user->rights->expensereport->readall)) $canread = 1; - if (!empty($user->rights->expensereport->lire) && in_array($object->fk_user_author, $childids)) $canread = 1; - if (!$canread) - { + if (!empty($user->rights->expensereport->readall)) { + $canread = 1; + } + if (!empty($user->rights->expensereport->lire) && in_array($object->fk_user_author, $childids)) { + $canread = 1; + } + if (!$canread) { accessforbidden(); } } @@ -104,8 +113,7 @@ $title = $langs->trans("ExpenseReport")." - ".$langs->trans("Documents"); $helpurl = "EN:Module_Expense_Reports"; llxHeader("", $title, $helpurl); -if ($object->id) -{ +if ($object->id) { $object->fetch_thirdparty(); $head = expensereport_prepare_head($object); @@ -124,8 +132,7 @@ if ($object->id) // Build file list $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1); $totalsize = 0; - foreach ($filearray as $key => $file) - { + foreach ($filearray as $key => $file) { $totalsize += $file['size']; } diff --git a/htdocs/expensereport/index.php b/htdocs/expensereport/index.php index 046bde4efa1..541c2c0738e 100644 --- a/htdocs/expensereport/index.php +++ b/htdocs/expensereport/index.php @@ -42,19 +42,27 @@ $langs->loadLangs(array('companies', 'users', 'trips')); // Security check $socid = GETPOST('socid', 'int'); -if ($user->socid) $socid = $user->socid; +if ($user->socid) { + $socid = $user->socid; +} $result = restrictedArea($user, 'expensereport', '', ''); $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST("sortfield", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); -if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +if (empty($page) || $page == -1) { + $page = 0; +} // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -if (!$sortorder) $sortorder = "DESC"; -if (!$sortfield) $sortfield = "d.date_create"; +if (!$sortorder) { + $sortorder = "DESC"; +} +if (!$sortfield) { + $sortfield = "d.date_create"; +} $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; @@ -80,8 +88,7 @@ $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as d, ".MAIN_DB_PREFIX."expensere $sql .= " WHERE de.fk_expensereport = d.rowid AND d.entity IN (".getEntity('expensereport').") AND de.fk_c_type_fees = tf.id"; // RESTRICT RIGHTS if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous) - && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->expensereport->writeall_advance))) -{ + && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->expensereport->writeall_advance))) { $childids = $user->getAllChildIds(); $childids[] = $user->id; $sql .= " AND d.fk_user_author IN (".join(',', $childids).")\n"; @@ -90,12 +97,10 @@ if (empty($user->rights->expensereport->readall) && empty($user->rights->expense $sql .= " GROUP BY tf.code, tf.label"; $result = $db->query($sql); -if ($result) -{ +if ($result) { $num = $db->num_rows($result); $i = 0; - while ($i < $num) - { + while ($i < $num) { $objp = $db->fetch_object($result); $somme[$objp->code] = $objp->km; @@ -123,13 +128,11 @@ print ''; print "\n"; $listoftype = $tripandexpense_static->listOfTypes(); -foreach ($listoftype as $code => $label) -{ +foreach ($listoftype as $code => $label) { $dataseries[] = array($label, (isset($somme[$code]) ? (int) $somme[$code] : 0)); } -if ($conf->use_javascript_ajax) -{ +if ($conf->use_javascript_ajax) { print ''; print ''; print ''; - if ($num) - { + if ($num) { $total_ttc = $totalam = $total = 0; $expensereportstatic = new ExpenseReport($db); $userstatic = new User($db); - while ($i < $num && $i < $max) - { + while ($i < $num && $i < $max) { $obj = $db->fetch_object($result); $expensereportstatic->id = $obj->rowid; @@ -241,7 +246,9 @@ if ($result) print ''; } print '
'.$langs->trans('LineNb').''.$langs->trans('Piece').''.$langs->trans('Date').''.$langs->trans('Project').''.$langs->trans('Project').''.$langs->trans('Type').''.$langs->trans('CarCategory').''.$langs->trans('CarCategory').''.$langs->trans('Description').''.$langs->trans('VAT').''.$langs->trans('PriceUHT').''.$langs->trans('PriceUTTC').''.$langs->trans('Qty').''.$langs->trans('AmountHT').''.$langs->trans('AmountTTC').''; print '
'.dol_print_date($db->jdate($line->date), 'day').''; - if ($line->fk_project > 0) - { + if ($line->fk_project > 0) { $projecttmp->id = $line->fk_project; $projecttmp->ref = $line->projet_ref; $projecttmp->title = $line->projet_title; @@ -2079,8 +2048,7 @@ if ($action == 'create') print ''; print dol_getIdFromCode($db, $line->fk_c_exp_tax_cat, 'c_exp_tax_cat', 'rowid', 'label'); print ''.vatrate($line->vatrate, true).''; - if (!empty($line->value_unit_ht)) - { + if (!empty($line->value_unit_ht)) { print price($line->value_unit_ht); } else { $tmpvat = price2num(preg_replace('/\s*\(.*\)/', '', $line->vatrate)); @@ -2106,28 +2073,26 @@ if ($action == 'create') print ''.dol_escape_htmltag($line->qty).''.price($line->total_ht).''.price($line->total_ttc).''; - if ($line->fk_ecm_files > 0) - { + if ($line->fk_ecm_files > 0) { $modulepart = 'expensereport'; $maxheightmini = 32; $result = $ecmfilesstatic->fetch($line->fk_ecm_files); - if ($result > 0) - { + if ($result > 0) { $relativepath = preg_replace('/expensereport\//', '', $ecmfilesstatic->filepath); $fileinfo = pathinfo($ecmfilesstatic->filepath.'/'.$ecmfilesstatic->filename); - if (image_format_supported($fileinfo['basename']) > 0) - { + if (image_format_supported($fileinfo['basename']) > 0) { $minifile = getImageFileNameForSize($fileinfo['basename'], '_mini'); // For new thumbs using same ext (in lower case howerver) than original - if (!dol_is_file($conf->expensereport->dir_output.'/'.$relativepath.'/'.$minifile)) $minifile = getImageFileNameForSize($fileinfo['basename'], '_mini', '.png'); // For backward compatibility of old thumbs that were created with filename in lower case and with .png extension + if (!dol_is_file($conf->expensereport->dir_output.'/'.$relativepath.'/'.$minifile)) { + $minifile = getImageFileNameForSize($fileinfo['basename'], '_mini', '.png'); // For backward compatibility of old thumbs that were created with filename in lower case and with .png extension + } //print $file['path'].'/'.$minifile.'
'; $urlforhref = getAdvancedPreviewUrl($modulepart, $relativepath.'/'.$fileinfo['filename'].'.'.strtolower($fileinfo['extension']), 1, '&entity='.(!empty($object->entity) ? $object->entity : $conf->entity)); if (empty($urlforhref)) { @@ -2141,42 +2106,39 @@ if ($action == 'create') } else { $modulepart = 'expensereport'; $thumbshown = 0; - if (preg_match('/\.pdf$/i', $ecmfilesstatic->filename)) - { + if (preg_match('/\.pdf$/i', $ecmfilesstatic->filename)) { $filepdf = $conf->expensereport->dir_output.'/'.$relativepath.'/'.$ecmfilesstatic->filename; $fileimage = $conf->expensereport->dir_output.'/'.$relativepath.'/'.$ecmfilesstatic->filename.'_preview.png'; $relativepathimage = $relativepath.'/'.$ecmfilesstatic->filename.'_preview.png'; $pdfexists = file_exists($filepdf); - if ($pdfexists) - { + if ($pdfexists) { // Conversion du PDF en image png si fichier png non existant - if (!file_exists($fileimage) || (filemtime($fileimage) < filemtime($filepdf))) - { - if (empty($conf->global->MAIN_DISABLE_PDF_THUMBS)) // If you experience trouble with pdf thumb generation and imagick, you can disable here. - { + if (!file_exists($fileimage) || (filemtime($fileimage) < filemtime($filepdf))) { + if (empty($conf->global->MAIN_DISABLE_PDF_THUMBS)) { // If you experience trouble with pdf thumb generation and imagick, you can disable here. include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $ret = dol_convert_file($filepdf, 'png', $fileimage, '0'); // Convert first page of PDF into a file _preview.png - if ($ret < 0) $error++; + if ($ret < 0) { + $error++; + } } } } - if ($pdfexists && !$error) - { + if ($pdfexists && !$error) { $heightforphotref = 70; - if (!empty($conf->dol_optimize_smallscreen)) $heightforphotref = 60; + if (!empty($conf->dol_optimize_smallscreen)) { + $heightforphotref = 60; + } // If the preview file is found - if (file_exists($fileimage)) - { + if (file_exists($fileimage)) { $thumbshown = 1; print ''; } } } - if (!$thumbshown) - { + if (!$thumbshown) { print img_mime($ecmfilesstatic->filename); } } @@ -2185,8 +2147,7 @@ if ($action == 'create') print '
'; print 'rowid.'">'; @@ -2202,12 +2163,15 @@ if ($action == 'create') print '
'; $formproject->select_projects(-1, $line->fk_project, 'fk_project', 0, 0, 1, 1, 0, 0, 0, '', 0, 0, 'maxwidth300'); print ''; $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); @@ -2341,17 +2299,21 @@ if ($action == 'create') // Add a new line if (($object->status == ExpenseReport::STATUS_DRAFT || $object->status == ExpenseReport::STATUS_REFUSED) && $action != 'editline' - && $user->rights->expensereport->creer) - { + && $user->rights->expensereport->creer) { $colspan = 11; - if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) $colspan++; - if (!empty($conf->projet->enabled)) $colspan++; - if ($action != 'editline') $colspan++; + if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) { + $colspan++; + } + if (!empty($conf->projet->enabled)) { + $colspan++; + } + if ($action != 'editline') { + $colspan++; + } $nbFiles = $nbLinks = 0; $arrayoffiles = array(); - if (empty($conf->global->EXPENSEREPORT_DISABLE_ATTACHMENT_ON_LINES)) - { + if (empty($conf->global->EXPENSEREPORT_DISABLE_ATTACHMENT_ON_LINES)) { require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php'; @@ -2367,8 +2329,7 @@ if ($action == 'create') print ''.$langs->trans("UploadANewFileNow"); print img_picto($langs->trans("UploadANewFileNow"), 'chevron-down', '', false, 0, 0, '', 'marginleftonly'); print ''; - if (empty($conf->global->EXPENSEREPORT_DISABLE_ATTACHMENT_ON_LINES)) - { + if (empty($conf->global->EXPENSEREPORT_DISABLE_ATTACHMENT_ON_LINES)) { print '   -   '.$langs->trans("AttachTheNewLineToTheDocument"); print img_picto($langs->trans("AttachTheNewLineToTheDocument"), 'chevron-down', '', false, 0, 0, '', 'marginleftonly'); print ''; @@ -2386,8 +2347,7 @@ if ($action == 'create') jQuery(".truploadnewfilenow").hide(); return false; });'."\n"; - if (is_array(GETPOST('attachfile', 'array')) && count(GETPOST('attachfile', 'array')) && $action != 'updateline') - { + if (is_array(GETPOST('attachfile', 'array')) && count(GETPOST('attachfile', 'array')) && $action != 'updateline') { print 'jQuery(".trattachnewfilenow").show();'."\n"; } print ' @@ -2431,8 +2391,7 @@ if ($action == 'create') print ''; $formproject->select_projects(-1, $fk_project, 'fk_project', 0, 0, 1, -1, 0, 0, 0, '', 0, 0, 'maxwidth300'); print ''; $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, 0); @@ -2459,7 +2417,9 @@ if ($action == 'create') // Select VAT print ''; $defaultvat = -1; - if (!empty($conf->global->EXPENSEREPORT_NO_DEFAULT_VAT)) $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS = 'none'; + 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 '
'.$langs->trans("Statistics").'
'; include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php'; @@ -168,25 +171,29 @@ $langs->load("boxes"); $sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.login, u.statut as user_status, u.photo, u.email, u.admin,"; $sql .= " d.rowid, d.ref, d.date_debut as dated, d.date_fin as datef, d.date_create as dm, d.total_ht, d.total_ttc, d.fk_statut as status"; $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as d, ".MAIN_DB_PREFIX."user as u"; -if (!$user->rights->societe->client->voir && !$user->socid) $sql .= ", ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."societe_commerciaux as sc"; +if (!$user->rights->societe->client->voir && !$user->socid) { + $sql .= ", ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."societe_commerciaux as sc"; +} $sql .= " WHERE u.rowid = d.fk_user_author"; // RESTRICT RIGHTS if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous) - && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->expensereport->writeall_advance))) -{ + && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->expensereport->writeall_advance))) { $childids = $user->getAllChildIds(); $childids[] = $user->id; $sql .= " AND d.fk_user_author IN (".join(',', $childids).")\n"; } $sql .= ' AND d.entity IN ('.getEntity('expensereport').')'; -if (!$user->rights->societe->client->voir && !$user->socid) $sql .= " AND d.fk_user_author = s.rowid AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; -if ($socid) $sql .= " AND d.fk_user_author = ".$socid; +if (!$user->rights->societe->client->voir && !$user->socid) { + $sql .= " AND d.fk_user_author = s.rowid AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; +} +if ($socid) { + $sql .= " AND d.fk_user_author = ".$socid; +} $sql .= $db->order($sortfield, $sortorder); $sql .= $db->plimit($max, 0); $result = $db->query($sql); -if ($result) -{ +if ($result) { $var = false; $num = $db->num_rows($result); @@ -201,14 +208,12 @@ if ($result) print ''.$langs->trans("DateModificationShort").' 
'.$langs->trans("None").'

'; -} else dol_print_error($db); +} else { + dol_print_error($db); +} print ''; diff --git a/htdocs/expensereport/info.php b/htdocs/expensereport/info.php index 53d1531f4b9..605197d14ac 100644 --- a/htdocs/expensereport/info.php +++ b/htdocs/expensereport/info.php @@ -37,23 +37,26 @@ $ref = GETPOST('ref', 'alpha'); $childids = $user->getAllChildIds(1); // Security check -if ($user->socid) $socid = $user->socid; +if ($user->socid) { + $socid = $user->socid; +} $result = restrictedArea($user, 'expensereport', $id, 'expensereport'); $object = new ExpenseReport($db); -if (!$object->fetch($id, $ref) > 0) -{ +if (!$object->fetch($id, $ref) > 0) { dol_print_error($db); } -if ($object->id > 0) -{ +if ($object->id > 0) { // Check current user can read this expense report $canread = 0; - if (!empty($user->rights->expensereport->readall)) $canread = 1; - if (!empty($user->rights->expensereport->lire) && in_array($object->fk_user_author, $childids)) $canread = 1; - if (!$canread) - { + if (!empty($user->rights->expensereport->readall)) { + $canread = 1; + } + if (!empty($user->rights->expensereport->lire) && in_array($object->fk_user_author, $childids)) { + $canread = 1; + } + if (!$canread) { accessforbidden(); } } @@ -69,8 +72,7 @@ $title = $langs->trans("ExpenseReport")." - ".$langs->trans("Info"); $helpurl = "EN:Module_Expense_Reports"; llxHeader("", $title, $helpurl); -if ($id > 0 || !empty($ref)) -{ +if ($id > 0 || !empty($ref)) { $object = new ExpenseReport($db); $object->fetch($id, $ref); $object->info($object->id); diff --git a/htdocs/expensereport/list.php b/htdocs/expensereport/list.php index 7afb464e4f4..ea3a034e252 100644 --- a/htdocs/expensereport/list.php +++ b/htdocs/expensereport/list.php @@ -54,18 +54,24 @@ $childids = $user->getAllChildIds(1); // Security check $socid = GETPOST('socid', 'int'); -if ($user->socid) $socid = $user->socid; +if ($user->socid) { + $socid = $user->socid; +} $result = restrictedArea($user, 'expensereport', '', ''); $id = GETPOST('id', 'int'); // If we are on the view of a specific user -if ($id > 0) -{ +if ($id > 0) { $canread = 0; - if ($id == $user->id) $canread = 1; - if (!empty($user->rights->expensereport->readall)) $canread = 1; - if (!empty($user->rights->expensereport->lire) && in_array($id, $childids)) $canread = 1; - if (!$canread) - { + if ($id == $user->id) { + $canread = 1; + } + if (!empty($user->rights->expensereport->readall)) { + $canread = 1; + } + if (!empty($user->rights->expensereport->lire) && in_array($id, $childids)) { + $canread = 1; + } + if (!$canread) { accessforbidden(); } } @@ -78,12 +84,18 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST('sortfield', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); -if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +if (empty($page) || $page == -1) { + $page = 0; +} // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -if (!$sortorder) $sortorder = "DESC"; -if (!$sortfield) $sortfield = "d.date_debut"; +if (!$sortorder) { + $sortorder = "DESC"; +} +if (!$sortfield) { + $sortfield = "d.date_debut"; +} $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml')); @@ -101,8 +113,12 @@ $month_end = GETPOST("month_end", "int"); $year_end = GETPOST("year_end", "int"); $optioncss = GETPOST('optioncss', 'alpha'); -if ($search_status == '') $search_status = -1; -if ($search_user == '') $search_user = -1; +if ($search_status == '') { + $search_status = -1; +} +if ($search_user == '') { + $search_user = -1; +} // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $object = new ExpenseReport($db); @@ -123,7 +139,9 @@ $fieldstosearchall = array( 'u.firstname'=>"Firstname", 'u.login'=>"Login", ); -if (empty($user->socid)) $fieldstosearchall["d.note_private"] = "NotePrivate"; +if (empty($user->socid)) { + $fieldstosearchall["d.note_private"] = "NotePrivate"; +} $arrayfields = array( 'd.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1), @@ -151,21 +169,25 @@ $objectuser = new User($db); * Actions */ -if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; } -if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; } +if (GETPOST('cancel', 'alpha')) { + $action = 'list'; $massaction = ''; +} +if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { + $massaction = ''; +} $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'); +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} -if (empty($reshook)) -{ +if (empty($reshook)) { // Selection of new fields include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; // Purge search criteria - if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers - { + if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers $search_ref = ""; $search_user = ""; $search_amount_ht = ""; @@ -181,8 +203,7 @@ if (empty($reshook)) $search_array_options = array(); } if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha') - || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) - { + || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) { $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation } @@ -216,8 +237,7 @@ $min_year = 10; // Get current user id $user_id = $user->id; -if ($id > 0) -{ +if ($id > 0) { // Charge utilisateur edite $fuser->fetch($id, '', '', 1); $fuser->getrights(); @@ -231,35 +251,50 @@ $sql .= " d.date_debut, d.date_fin, d.date_create, d.tms as date_modif, d.date_v $sql .= " u.rowid as id_user, u.firstname, u.lastname, u.login, u.email, u.statut, u.photo"; // Add fields from extrafields if (!empty($extrafields->attributes[$object->table_element]['label'])) { - foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : ''); + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { + $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : ''); + } } // Add fields from hooks $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook $sql .= $hookmanager->resPrint; $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as d"; -if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (d.rowid = ef.fk_object)"; +if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) { + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (d.rowid = ef.fk_object)"; +} $sql .= ", ".MAIN_DB_PREFIX."user as u"; $sql .= " WHERE d.fk_user_author = u.rowid AND d.entity IN (".getEntity('expensereport').")"; // Search all -if (!empty($sall)) $sql .= natural_search(array_keys($fieldstosearchall), $sall); +if (!empty($sall)) { + $sql .= natural_search(array_keys($fieldstosearchall), $sall); +} // Ref -if (!empty($search_ref)) $sql .= natural_search('d.ref', $search_ref); +if (!empty($search_ref)) { + $sql .= natural_search('d.ref', $search_ref); +} // Date Start $sql .= dolSqlDateFilter("d.date_debut", $day_start, $month_start, $year_start); // Date End $sql .= dolSqlDateFilter("d.date_fin", $day_end, $month_end, $year_end); -if ($search_amount_ht != '') $sql .= natural_search('d.total_ht', $search_amount_ht, 1); -if ($search_amount_ttc != '') $sql .= natural_search('d.total_ttc', $search_amount_ttc, 1); +if ($search_amount_ht != '') { + $sql .= natural_search('d.total_ht', $search_amount_ht, 1); +} +if ($search_amount_ttc != '') { + $sql .= natural_search('d.total_ttc', $search_amount_ttc, 1); +} // User -if ($search_user != '' && $search_user >= 0) $sql .= " AND u.rowid = '".$db->escape($search_user)."'"; +if ($search_user != '' && $search_user >= 0) { + $sql .= " AND u.rowid = '".$db->escape($search_user)."'"; +} // Status -if ($search_status != '' && $search_status >= 0) $sql .= " AND d.fk_statut IN (".$db->sanitize($db->escape($search_status)).")"; +if ($search_status != '' && $search_status >= 0) { + $sql .= " AND d.fk_statut IN (".$db->sanitize($db->escape($search_status)).")"; +} // RESTRICT RIGHTS if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous) - && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->expensereport->writeall_advance))) -{ + && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->expensereport->writeall_advance))) { $sql .= " AND d.fk_user_author IN (".join(',', $childids).")\n"; } // Add where from extra fields @@ -273,12 +308,10 @@ $sql .= $db->order($sortfield, $sortorder); // Count total nb of records $nbtotalofrecords = ''; -if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) -{ +if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $result = $db->query($sql); $nbtotalofrecords = $db->num_rows($result); - if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0 - { + if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0 $page = 0; $offset = 0; } @@ -288,22 +321,39 @@ $sql .= $db->plimit($limit + 1, $offset); //print $sql; $resql = $db->query($sql); -if ($resql) -{ +if ($resql) { $num = $db->num_rows($resql); $arrayofselected = is_array($toselect) ? $toselect : array(); $param = ''; - if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage); - if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit); - if ($sall) $param .= "&sall=".urlencode($sall); - if ($search_ref) $param .= "&search_ref=".urlencode($search_ref); - if ($search_user) $param .= "&search_user=".urlencode($search_user); - if ($search_amount_ht) $param .= "&search_amount_ht=".urlencode($search_amount_ht); - if ($search_amount_ttc) $param .= "&search_amount_ttc=".urlencode($search_amount_ttc); - if ($search_status >= 0) $param .= "&search_status=".urlencode($search_status); - if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss); + if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { + $param .= '&contextpage='.urlencode($contextpage); + } + if ($limit > 0 && $limit != $conf->liste_limit) { + $param .= '&limit='.urlencode($limit); + } + if ($sall) { + $param .= "&sall=".urlencode($sall); + } + if ($search_ref) { + $param .= "&search_ref=".urlencode($search_ref); + } + if ($search_user) { + $param .= "&search_user=".urlencode($search_user); + } + if ($search_amount_ht) { + $param .= "&search_amount_ht=".urlencode($search_amount_ht); + } + if ($search_amount_ttc) { + $param .= "&search_amount_ttc=".urlencode($search_amount_ttc); + } + if ($search_status >= 0) { + $param .= "&search_status=".urlencode($search_status); + } + if ($optioncss != '') { + $param .= '&optioncss='.urlencode($optioncss); + } // Add $param from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; @@ -313,23 +363,30 @@ if ($resql) 'builddoc'=>$langs->trans("PDFMerge"), 'presend'=>$langs->trans("SendByMail"), ); - if ($user->rights->expensereport->supprimer) $arrayofmassactions['predelete'] = ''.$langs->trans("Delete"); - if (in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array(); + if ($user->rights->expensereport->supprimer) { + $arrayofmassactions['predelete'] = ''.$langs->trans("Delete"); + } + if (in_array($massaction, array('presend', 'predelete'))) { + $arrayofmassactions = array(); + } $massactionbutton = $form->selectMassAction('', $arrayofmassactions); // Lines of title fields print '
'."\n"; - if ($optioncss != '') print ''; + if ($optioncss != '') { + print ''; + } print ''; print ''; print ''; print ''; print ''; print ''; - if ($id > 0) print ''; + if ($id > 0) { + print ''; + } - if ($id > 0) // For user tab - { + if ($id > 0) { // For user tab $title = $langs->trans("User"); $linkback = ''.$langs->trans("BackToList").''; $head = user_prepare_head($fuser); @@ -340,8 +397,7 @@ if ($resql) print dol_get_fiche_end(); - if ($action != 'edit') - { + if ($action != 'edit') { print '
'; $childids = $user->getAllChildIds(1); @@ -366,7 +422,9 @@ if ($resql) $title = $langs->trans("ListTripsAndExpenses"); $url = DOL_URL_ROOT.'/expensereport/card.php?action=create'; - if (!empty($socid)) $url .= '&socid='.$socid; + if (!empty($socid)) { + $url .= '&socid='.$socid; + } $newcardbutton = dolGetButtonTitle($langs->trans('NewTrip'), '', 'fa fa-plus-circle', $url, '', $user->rights->expensereport->creer); print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'trip', 0, $newcardbutton, '', $limit, 0, 0, 1); @@ -378,9 +436,10 @@ if ($resql) $trackid = 'exp'.$object->id; include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php'; - if ($sall) - { - foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val); + if ($sall) { + foreach ($fieldstosearchall as $key => $val) { + $fieldstosearchall[$key] = $langs->trans($val); + } print '
'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'
'; } @@ -388,11 +447,13 @@ if ($resql) $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook - if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint; - else $moreforfilter = $hookmanager->resPrint; + if (empty($reshook)) { + $moreforfilter .= $hookmanager->resPrint; + } else { + $moreforfilter = $hookmanager->resPrint; + } - if (!empty($moreforfilter)) - { + if (!empty($moreforfilter)) { print '
'; print $moreforfilter; print '
'; @@ -407,17 +468,14 @@ if ($resql) // Filters print ''; - if (!empty($arrayfields['d.ref']['checked'])) - { + if (!empty($arrayfields['d.ref']['checked'])) { print ''; print ''; print ''; } // User - if (!empty($arrayfields['user']['checked'])) - { - if ($user->rights->expensereport->readall || $user->rights->expensereport->lire_tous) - { + if (!empty($arrayfields['user']['checked'])) { + if ($user->rights->expensereport->readall || $user->rights->expensereport->lire_tous) { print ''; print $form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200'); print ''; @@ -426,8 +484,7 @@ if ($resql) } } // Date start - if (!empty($arrayfields['d.date_debut']['checked'])) - { + if (!empty($arrayfields['d.date_debut']['checked'])) { print ''; if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) { print ''; @@ -438,8 +495,7 @@ if ($resql) print ''; } // Date end - if (!empty($arrayfields['d.date_fin']['checked'])) - { + if (!empty($arrayfields['d.date_fin']['checked'])) { print ''; if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) { print ''; @@ -449,33 +505,28 @@ if ($resql) print ''; } // Date valid - if (!empty($arrayfields['d.date_valid']['checked'])) - { + if (!empty($arrayfields['d.date_valid']['checked'])) { print ''; //print ''; //$formother->select_year($year_end,'year_end',1, $min_year, $max_year); print ''; } // Date approve - if (!empty($arrayfields['d.date_approve']['checked'])) - { + if (!empty($arrayfields['d.date_approve']['checked'])) { print ''; //print ''; //$formother->select_year($year_end,'year_end',1, $min_year, $max_year); print ''; } // Amount with no tax - if (!empty($arrayfields['d.total_ht']['checked'])) - { + if (!empty($arrayfields['d.total_ht']['checked'])) { print ''; } - if (!empty($arrayfields['d.total_vat']['checked'])) - { + if (!empty($arrayfields['d.total_vat']['checked'])) { print ''; } // Amount with all taxes - if (!empty($arrayfields['d.total_ttc']['checked'])) - { + if (!empty($arrayfields['d.total_ttc']['checked'])) { print ''; } // Extra fields @@ -486,20 +537,17 @@ if ($resql) $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; // Date creation - if (!empty($arrayfields['d.date_create']['checked'])) - { + if (!empty($arrayfields['d.date_create']['checked'])) { print ''; print ''; } // Date modification - if (!empty($arrayfields['d.tms']['checked'])) - { + if (!empty($arrayfields['d.tms']['checked'])) { print ''; print ''; } // Status - if (!empty($arrayfields['d.fk_statut']['checked'])) - { + if (!empty($arrayfields['d.fk_statut']['checked'])) { print ''; $formexpensereport->selectExpensereportStatus($search_status, 'search_status', 1, 1); print ''; @@ -513,24 +561,48 @@ if ($resql) print "\n"; print ''; - if (!empty($arrayfields['d.ref']['checked'])) print_liste_field_titre($arrayfields['d.ref']['label'], $_SERVER["PHP_SELF"], "d.ref", "", $param, '', $sortfield, $sortorder); - if (!empty($arrayfields['user']['checked'])) print_liste_field_titre($arrayfields['user']['label'], $_SERVER["PHP_SELF"], "u.lastname", "", $param, '', $sortfield, $sortorder); - if (!empty($arrayfields['d.date_debut']['checked'])) print_liste_field_titre($arrayfields['d.date_debut']['label'], $_SERVER["PHP_SELF"], "d.date_debut", "", $param, 'align="center"', $sortfield, $sortorder); - if (!empty($arrayfields['d.date_fin']['checked'])) print_liste_field_titre($arrayfields['d.date_fin']['label'], $_SERVER["PHP_SELF"], "d.date_fin", "", $param, 'align="center"', $sortfield, $sortorder); - if (!empty($arrayfields['d.date_valid']['checked'])) print_liste_field_titre($arrayfields['d.date_valid']['label'], $_SERVER["PHP_SELF"], "d.date_valid", "", $param, 'align="center"', $sortfield, $sortorder); - if (!empty($arrayfields['d.date_approve']['checked'])) print_liste_field_titre($arrayfields['d.date_approve']['label'], $_SERVER["PHP_SELF"], "d.date_approve", "", $param, 'align="center"', $sortfield, $sortorder); - if (!empty($arrayfields['d.total_ht']['checked'])) print_liste_field_titre($arrayfields['d.total_ht']['label'], $_SERVER["PHP_SELF"], "d.total_ht", "", $param, 'align="right"', $sortfield, $sortorder); - if (!empty($arrayfields['d.total_vat']['checked'])) print_liste_field_titre($arrayfields['d.total_vat']['label'], $_SERVER["PHP_SELF"], "d.total_tva", "", $param, 'align="right"', $sortfield, $sortorder); - if (!empty($arrayfields['d.total_ttc']['checked'])) print_liste_field_titre($arrayfields['d.total_ttc']['label'], $_SERVER["PHP_SELF"], "d.total_ttc", "", $param, 'align="right"', $sortfield, $sortorder); + if (!empty($arrayfields['d.ref']['checked'])) { + print_liste_field_titre($arrayfields['d.ref']['label'], $_SERVER["PHP_SELF"], "d.ref", "", $param, '', $sortfield, $sortorder); + } + if (!empty($arrayfields['user']['checked'])) { + print_liste_field_titre($arrayfields['user']['label'], $_SERVER["PHP_SELF"], "u.lastname", "", $param, '', $sortfield, $sortorder); + } + if (!empty($arrayfields['d.date_debut']['checked'])) { + print_liste_field_titre($arrayfields['d.date_debut']['label'], $_SERVER["PHP_SELF"], "d.date_debut", "", $param, 'align="center"', $sortfield, $sortorder); + } + if (!empty($arrayfields['d.date_fin']['checked'])) { + print_liste_field_titre($arrayfields['d.date_fin']['label'], $_SERVER["PHP_SELF"], "d.date_fin", "", $param, 'align="center"', $sortfield, $sortorder); + } + if (!empty($arrayfields['d.date_valid']['checked'])) { + print_liste_field_titre($arrayfields['d.date_valid']['label'], $_SERVER["PHP_SELF"], "d.date_valid", "", $param, 'align="center"', $sortfield, $sortorder); + } + if (!empty($arrayfields['d.date_approve']['checked'])) { + print_liste_field_titre($arrayfields['d.date_approve']['label'], $_SERVER["PHP_SELF"], "d.date_approve", "", $param, 'align="center"', $sortfield, $sortorder); + } + if (!empty($arrayfields['d.total_ht']['checked'])) { + print_liste_field_titre($arrayfields['d.total_ht']['label'], $_SERVER["PHP_SELF"], "d.total_ht", "", $param, 'align="right"', $sortfield, $sortorder); + } + if (!empty($arrayfields['d.total_vat']['checked'])) { + print_liste_field_titre($arrayfields['d.total_vat']['label'], $_SERVER["PHP_SELF"], "d.total_tva", "", $param, 'align="right"', $sortfield, $sortorder); + } + if (!empty($arrayfields['d.total_ttc']['checked'])) { + print_liste_field_titre($arrayfields['d.total_ttc']['label'], $_SERVER["PHP_SELF"], "d.total_ttc", "", $param, 'align="right"', $sortfield, $sortorder); + } // Extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php'; // Hook fields $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder); $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (!empty($arrayfields['d.date_create']['checked'])) print_liste_field_titre($arrayfields['d.date_create']['label'], $_SERVER["PHP_SELF"], "d.date_create", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder); - if (!empty($arrayfields['d.tms']['checked'])) print_liste_field_titre($arrayfields['d.tms']['label'], $_SERVER["PHP_SELF"], "d.tms", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder); - if (!empty($arrayfields['d.fk_statut']['checked'])) print_liste_field_titre($arrayfields['d.fk_statut']['label'], $_SERVER["PHP_SELF"], "d.fk_statut", "", $param, 'align="right"', $sortfield, $sortorder); + if (!empty($arrayfields['d.date_create']['checked'])) { + print_liste_field_titre($arrayfields['d.date_create']['label'], $_SERVER["PHP_SELF"], "d.date_create", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder); + } + if (!empty($arrayfields['d.tms']['checked'])) { + print_liste_field_titre($arrayfields['d.tms']['label'], $_SERVER["PHP_SELF"], "d.tms", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder); + } + if (!empty($arrayfields['d.fk_statut']['checked'])) { + print_liste_field_titre($arrayfields['d.fk_statut']['label'], $_SERVER["PHP_SELF"], "d.fk_statut", "", $param, 'align="right"', $sortfield, $sortorder); + } print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch '); print "\n"; @@ -541,12 +613,10 @@ if ($resql) $expensereportstatic = new ExpenseReport($db); $usertmp = new User($db); - if ($num > 0) - { + if ($num > 0) { $i = 0; $totalarray = array(); - while ($i < min($num, $limit)) - { + while ($i < min($num, $limit)) { $obj = $db->fetch_object($resql); $expensereportstatic->id = $obj->rowid; @@ -572,10 +642,13 @@ if ($resql) print ''; // Warning late icon and note print ''; - if ($expensereportstatic->status == 2 && $expensereportstatic->hasDelay('toappove')) print img_warning($langs->trans("Late")); - if ($expensereportstatic->status == 5 && $expensereportstatic->hasDelay('topay')) print img_warning($langs->trans("Late")); - if (!empty($obj->note_private) || !empty($obj->note_public)) - { + if ($expensereportstatic->status == 2 && $expensereportstatic->hasDelay('toappove')) { + print img_warning($langs->trans("Late")); + } + if ($expensereportstatic->status == 5 && $expensereportstatic->hasDelay('topay')) { + print img_warning($langs->trans("Late")); + } + if (!empty($obj->note_private) || !empty($obj->note_public)) { print ' '; print ''.img_picto($langs->trans("ViewPrivateNote"), 'object_generic').''; print ''; @@ -589,7 +662,9 @@ if ($resql) print ''; print ''; print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // User if (!empty($arrayfields['user']['checked'])) { @@ -603,50 +678,69 @@ if ($resql) $usertmp->email = $obj->email; print $usertmp->getNomUrl(-1); print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Start date if (!empty($arrayfields['d.date_debut']['checked'])) { print ''.($obj->date_debut > 0 ? dol_print_date($db->jdate($obj->date_debut), 'day') : '').''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // End date if (!empty($arrayfields['d.date_fin']['checked'])) { print ''.($obj->date_fin > 0 ? dol_print_date($db->jdate($obj->date_fin), 'day') : '').''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Date validation if (!empty($arrayfields['d.date_valid']['checked'])) { print ''.($obj->date_valid > 0 ? dol_print_date($db->jdate($obj->date_valid), 'day') : '').''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Date approval if (!empty($arrayfields['d.date_approve']['checked'])) { print ''.($obj->date_approve > 0 ? dol_print_date($db->jdate($obj->date_approve), 'day') : '').''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Amount HT - if (!empty($arrayfields['d.total_ht']['checked'])) - { + if (!empty($arrayfields['d.total_ht']['checked'])) { print ''.price($obj->total_ht)."\n"; - if (!$i) $totalarray['nbfield']++; - if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'd.total_ht'; + if (!$i) { + $totalarray['nbfield']++; + } + if (!$i) { + $totalarray['pos'][$totalarray['nbfield']] = 'd.total_ht'; + } $totalarray['val']['d.total_ht'] += $obj->total_ht; } // Amount VAT - if (!empty($arrayfields['d.total_vat']['checked'])) - { + if (!empty($arrayfields['d.total_vat']['checked'])) { print ''.price($obj->total_tva)."\n"; - if (!$i) $totalarray['nbfield']++; - if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'd.total_tva'; + if (!$i) { + $totalarray['nbfield']++; + } + if (!$i) { + $totalarray['pos'][$totalarray['nbfield']] = 'd.total_tva'; + } $totalarray['val']['d.total_tva'] += $obj->total_tva; } // Amount TTC - if (!empty($arrayfields['d.total_ttc']['checked'])) - { + if (!empty($arrayfields['d.total_ttc']['checked'])) { print ''.price($obj->total_ttc)."\n"; - if (!$i) $totalarray['nbfield']++; - if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'd.total_ttc'; + if (!$i) { + $totalarray['nbfield']++; + } + if (!$i) { + $totalarray['pos'][$totalarray['nbfield']] = 'd.total_ttc'; + } $totalarray['val']['d.total_ttc'] += $obj->total_ttc; } @@ -658,37 +752,43 @@ if ($resql) print $hookmanager->resPrint; // Date creation - if (!empty($arrayfields['d.date_create']['checked'])) - { + if (!empty($arrayfields['d.date_create']['checked'])) { print ''; print dol_print_date($db->jdate($obj->date_create), 'dayhour'); print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Date modification - if (!empty($arrayfields['d.tms']['checked'])) - { + if (!empty($arrayfields['d.tms']['checked'])) { print ''; print dol_print_date($db->jdate($obj->date_modif), 'dayhour'); print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Status - if (!empty($arrayfields['d.fk_statut']['checked'])) - { + if (!empty($arrayfields['d.fk_statut']['checked'])) { print ''.$expensereportstatic->getLibStatut(5).''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Action column print ''; - if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined - { + if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined $selected = 0; - if (in_array($obj->rowid, $arrayofselected)) $selected = 1; + if (in_array($obj->rowid, $arrayofselected)) { + $selected = 1; + } print ''; } print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } print "\n"; @@ -700,7 +800,11 @@ if ($resql) } } else { $colspan = 1; - foreach ($arrayfields as $key => $val) { if (!empty($val['checked'])) $colspan++; } + foreach ($arrayfields as $key => $val) { + if (!empty($val['checked'])) { + $colspan++; + } + } print ''.$langs->trans("NoRecordFound").''; } @@ -718,10 +822,11 @@ if ($resql) print ''."\n"; - if (empty($id)) - { + if (empty($id)) { $hidegeneratedfilelistifempty = 1; - if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) $hidegeneratedfilelistifempty = 0; + if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) { + $hidegeneratedfilelistifempty = 0; + } // Show list of available documents $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder; diff --git a/htdocs/expensereport/note.php b/htdocs/expensereport/note.php index ebb66ce42fd..b0156c6a475 100644 --- a/htdocs/expensereport/note.php +++ b/htdocs/expensereport/note.php @@ -41,26 +41,29 @@ $childids = $user->getAllChildIds(1); // Security check $socid = 0; -if ($user->socid) $socid = $user->socid; +if ($user->socid) { + $socid = $user->socid; +} $result = restrictedArea($user, 'expensereport', $id, 'expensereport'); $object = new ExpenseReport($db); -if (!$object->fetch($id, $ref) > 0) -{ +if (!$object->fetch($id, $ref) > 0) { dol_print_error($db); } $permissionnote = $user->rights->expensereport->creer; // Used by the include of actions_setnotes.inc.php -if ($object->id > 0) -{ +if ($object->id > 0) { // Check current user can read this expense report $canread = 0; - if (!empty($user->rights->expensereport->readall)) $canread = 1; - if (!empty($user->rights->expensereport->lire) && in_array($object->fk_user_author, $childids)) $canread = 1; - if (!$canread) - { + if (!empty($user->rights->expensereport->readall)) { + $canread = 1; + } + if (!empty($user->rights->expensereport->lire) && in_array($object->fk_user_author, $childids)) { + $canread = 1; + } + if (!$canread) { accessforbidden(); } } @@ -82,8 +85,7 @@ llxHeader("", $title, $helpurl); $form = new Form($db); -if ($id > 0 || !empty($ref)) -{ +if ($id > 0 || !empty($ref)) { $object = new ExpenseReport($db); $object->fetch($id, $ref); $object->info($object->id); diff --git a/htdocs/expensereport/payment/card.php b/htdocs/expensereport/payment/card.php index 14c95f2d68a..608309ceee0 100644 --- a/htdocs/expensereport/payment/card.php +++ b/htdocs/expensereport/payment/card.php @@ -26,7 +26,9 @@ require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php'; require_once DOL_DOCUMENT_ROOT.'/expensereport/class/paymentexpensereport.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/modules/expensereport/modules_expensereport.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/expensereport.lib.php'; -if (!empty($conf->banque->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; +if (!empty($conf->banque->enabled)) { + require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; +} // Load translation files required by the page $langs->loadLangs(array('bills', 'banks', 'companies', 'trips')); @@ -36,16 +38,19 @@ $action = GETPOST('action', 'aZ09'); $confirm = GETPOST('confirm'); // Security check -if ($user->socid) $socid = $user->socid; +if ($user->socid) { + $socid = $user->socid; +} // TODO Add rule to restrict access payment //$result = restrictedArea($user, 'facture', $id,''); $object = new PaymentExpenseReport($db); -if ($id > 0) -{ +if ($id > 0) { $result = $object->fetch($id); - if (!$result) dol_print_error($db, 'Failed to get payment id '.$id); + if (!$result) { + dol_print_error($db, 'Failed to get payment id '.$id); + } } @@ -54,13 +59,11 @@ if ($id > 0) */ // Delete payment -if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->expensereport->supprimer) -{ +if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->expensereport->supprimer) { $db->begin(); $result = $object->delete($user); - if ($result > 0) - { + if ($result > 0) { $db->commit(); header("Location: ".DOL_URL_ROOT."/expensereport/index.php"); exit; @@ -86,8 +89,7 @@ print dol_get_fiche_head($head, 'payment', $langs->trans("ExpenseReportPayment") /* * Confirm deleting of the payment */ -if ($action == 'delete') -{ +if ($action == 'delete') { print $form->formconfirm('card.php?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete', '', 0, 2); } @@ -118,14 +120,11 @@ print ''.$langs->trans('Note').''.nl2 $disable_delete = 0; // Bank account -if (!empty($conf->banque->enabled)) -{ - if ($object->bank_account) - { +if (!empty($conf->banque->enabled)) { + if ($object->bank_account) { $bankline = new AccountLine($db); $bankline->fetch($object->bank_line); - if ($bankline->rappro) - { + if ($bankline->rappro) { $disable_delete = 1; $title_button = dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemoveConciliatedPayment")); } @@ -167,8 +166,7 @@ $sql .= ' AND per.rowid = '.$id; dol_syslog("expensereport/payment/card.php", LOG_DEBUG); $resql = $db->query($sql); -if ($resql) -{ +if ($resql) { $num = $db->num_rows($resql); $i = 0; @@ -186,10 +184,8 @@ if ($resql) print ''.$langs->trans('Status').''; print "\n"; - if ($num > 0) - { - while ($i < $num) - { + if ($num > 0) { + while ($i < $num) { $objp = $db->fetch_object($resql); print ''; @@ -216,8 +212,7 @@ if ($resql) print "\n"; - if ($objp->paid == 1) // If at least one invoice is paid, disable delete - { + if ($objp->paid == 1) { // If at least one invoice is paid, disable delete $disable_delete = 2; $title_button = $langs->trans("CantRemovePaymentWithOneInvoicePaid"); } @@ -242,12 +237,9 @@ if ($resql) */ print '
'; -if ($action == '') -{ - if ($user->rights->expensereport->supprimer) - { - if (!$disable_delete) - { +if ($action == '') { + if ($user->rights->expensereport->supprimer) { + if (!$disable_delete) { print ''.$langs->trans('Delete').''; } else { print ''.$langs->trans('Delete').''; diff --git a/htdocs/expensereport/payment/payment.php b/htdocs/expensereport/payment/payment.php index b66103f38f5..926559769b4 100644 --- a/htdocs/expensereport/payment/payment.php +++ b/htdocs/expensereport/payment/payment.php @@ -39,8 +39,7 @@ $accountid = GETPOST('accountid', 'int'); // Security check $socid = 0; -if ($user->socid > 0) -{ +if ($user->socid > 0) { $socid = $user->socid; } @@ -49,12 +48,10 @@ if ($user->socid > 0) * Actions */ -if ($action == 'add_payment') -{ +if ($action == 'add_payment') { $error = 0; - if ($_POST["cancel"]) - { + if ($_POST["cancel"]) { $loc = DOL_URL_ROOT.'/expensereport/card.php?id='.$id; header("Location: ".$loc); exit; @@ -62,53 +59,44 @@ if ($action == 'add_payment') $expensereport = new ExpenseReport($db); $result = $expensereport->fetch($id, $ref); - if (!$result) - { + if (!$result) { $error++; setEventMessages($expensereport->error, $expensereport->errors, 'errors'); } $datepaid = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); - if (!($_POST["fk_typepayment"] > 0)) - { + if (!($_POST["fk_typepayment"] > 0)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode")), null, 'errors'); $error++; } - if ($datepaid == '') - { + if ($datepaid == '') { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Date")), null, 'errors'); $error++; } - if (!empty($conf->banque->enabled) && !($accountid > 0)) - { + if (!empty($conf->banque->enabled) && !($accountid > 0)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AccountToDebit")), null, 'errors'); $error++; } - if (!$error) - { + if (!$error) { $paymentid = 0; $total = 0; // Read possible payments - foreach ($_POST as $key => $value) - { - if (substr($key, 0, 7) == 'amount_') - { + foreach ($_POST as $key => $value) { + if (substr($key, 0, 7) == 'amount_') { $amounts[$expensereport->fk_user_author] = price2num($_POST[$key]); $total += price2num($_POST[$key]); } } - if (count($amounts) <= 0) - { + if (count($amounts) <= 0) { $error++; $errmsg = 'ErrorNoPaymentDefined'; } - if (!$error) - { + if (!$error) { $db->begin(); // Create a line of payments @@ -121,21 +109,17 @@ if ($action == 'add_payment') $payment->num_payment = GETPOST("num_payment", 'alphanothtml'); $payment->note_public = GETPOST("note_public", 'restricthtml'); - if (!$error) - { + if (!$error) { $paymentid = $payment->create($user); - if ($paymentid < 0) - { + if ($paymentid < 0) { setEventMessages($payment->error, $payment->errors, 'errors'); $error++; } } - if (!$error) - { + if (!$error) { $result = $payment->addPaymentToBank($user, 'payment_expensereport', '(ExpenseReportPayment)', $accountid, '', ''); - if (!$result > 0) - { + if (!$result > 0) { setEventMessages($payment->error, $payment->errors, 'errors'); $error++; } @@ -152,8 +136,7 @@ if ($action == 'add_payment') } } - if (!$error) - { + if (!$error) { $db->commit(); $loc = DOL_URL_ROOT.'/expensereport/card.php?id='.$id; header('Location: '.$loc); @@ -178,8 +161,7 @@ $form = new Form($db); // Form to create expense report payment -if ($action == 'create' || empty($action)) -{ +if ($action == 'create' || empty($action)) { $expensereport = new ExpenseReport($db); $expensereport->fetch($id, $ref); @@ -226,8 +208,7 @@ if ($action == 'create' || empty($action)) $sql .= " WHERE p.fk_expensereport = e.rowid AND p.fk_expensereport = ".$id; $sql .= ' AND e.entity IN ('.getEntity('expensereport').')'; $resql = $db->query($sql); - if ($resql) - { + if ($resql) { $obj = $db->fetch_object($resql); $sumpaid = $obj->total; $db->free(); @@ -257,8 +238,7 @@ if ($action == 'create' || empty($action)) print "\n"; print ''; - if (!empty($conf->banque->enabled)) - { + if (!empty($conf->banque->enabled)) { print ''; print ''.$langs->trans('AccountToDebit').''; print ''; @@ -299,8 +279,7 @@ if ($action == 'create' || empty($action)) $total = 0; $totalrecu = 0; - while ($i < $num) - { + while ($i < $num) { $objp = $expensereport; print ''; @@ -310,12 +289,12 @@ if ($action == 'create' || empty($action)) print ''.price($sumpaid).""; print ''.price($objp->total_ttc - $sumpaid).""; print ''; - if ($sumpaid < $objp->total_ttc) - { + if ($sumpaid < $objp->total_ttc) { $namef = "amount_".$objp->id; $nameRemain = "remain_".$objp->id; // autofill remainder amount - if (!empty($conf->use_javascript_ajax)) // autofill remainder amount + if (!empty($conf->use_javascript_ajax)) { // autofill remainder amount print img_picto("Auto fill", 'rightarrow', "class='AutoFillAmount' data-rowid='".$namef."' data-value='".($objp->total_ttc - $sumpaid)."'"); // autofill remainder amount + } $remaintopay = $objp->total_ttc - $sumpaid; // autofill remainder amount print ''; // autofill remainder amount print ''; @@ -331,8 +310,7 @@ if ($action == 'create' || empty($action)) $totalrecu += $objp->am; $i++; } - if ($i > 1) - { + if ($i > 1) { // Print total print ''; print ''.$langs->trans("Total").':'; diff --git a/htdocs/expensereport/stats/index.php b/htdocs/expensereport/stats/index.php index f3a3e263fa7..87bac2dde1a 100644 --- a/htdocs/expensereport/stats/index.php +++ b/htdocs/expensereport/stats/index.php @@ -38,16 +38,19 @@ $mode = GETPOSTISSET("mode") ? GETPOST("mode", 'aZ09') : 'customer'; $object_status = GETPOST('object_status', 'intcomma'); $userid = GETPOST('userid', 'int'); -$socid = GETPOST('socid', 'int'); if ($socid < 0) $socid = 0; +$socid = GETPOST('socid', 'int'); if ($socid < 0) { + $socid = 0; +} $id = GETPOST('id', 'int'); // Security check -if ($user->socid > 0) -{ +if ($user->socid > 0) { $action = ''; $socid = $user->socid; } -if ($user->socid) $socid = $user->socid; +if ($user->socid) { + $socid = $user->socid; +} $result = restrictedArea($user, 'expensereport', $id, ''); $nowyear = strftime("%Y", dol_now()); @@ -75,7 +78,9 @@ print load_fiche_titre($title, '', 'trip'); dol_mkdir($dir); $stats = new ExpenseReportStats($db, $socid, $userid); -if ($object_status != '' && $object_status >= -1) $stats->where .= ' AND e.fk_statut IN ('.$db->sanitize($db->escape($object_status)).')'; +if ($object_status != '' && $object_status >= -1) { + $stats->where .= ' AND e.fk_statut IN ('.$db->sanitize($db->escape($object_status)).')'; +} // Build graphic number of object // $data = array(array('Lib',val1,val2,val3),...) @@ -88,12 +93,10 @@ $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=tripsexpensesstats&file $px1 = new DolGraph(); $mesg = $px1->isGraphKo(); -if (!$mesg) -{ +if (!$mesg) { $px1->SetData($data); $i = $startyear; $legend = array(); - while ($i <= $endyear) - { + while ($i <= $endyear) { $legend[] = $i; $i++; } @@ -120,12 +123,10 @@ $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=tripsexpensesstats& $px2 = new DolGraph(); $mesg = $px2->isGraphKo(); -if (!$mesg) -{ +if (!$mesg) { $px2->SetData($data); $i = $startyear; $legend = array(); - while ($i <= $endyear) - { + while ($i <= $endyear) { $legend[] = $i; $i++; } @@ -146,25 +147,30 @@ if (!$mesg) $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear); -if (!$user->rights->societe->client->voir || $user->socid) -{ +if (!$user->rights->societe->client->voir || $user->socid) { $filename_avg = $dir.'/ordersaverage-'.$user->id.'-'.$year.'.png'; - if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.'-'.$year.'.png'; - if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.'-'.$year.'.png'; + if ($mode == 'customer') { + $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.'-'.$year.'.png'; + } + if ($mode == 'supplier') { + $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$user->id.'-'.$year.'.png'; + } } else { $filename_avg = $dir.'/ordersaverage-'.$year.'.png'; - if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.'.png'; - if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.'.png'; + if ($mode == 'customer') { + $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.'.png'; + } + if ($mode == 'supplier') { + $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersaverage-'.$year.'.png'; + } } $px3 = new DolGraph(); $mesg = $px3->isGraphKo(); -if (!$mesg) -{ +if (!$mesg) { $px3->SetData($data); $i = $startyear; $legend = array(); - while ($i <= $endyear) - { + while ($i <= $endyear) { $legend[] = $i; $i++; } @@ -189,7 +195,9 @@ $arrayyears = array(); foreach ($data as $val) { $arrayyears[$val['year']] = $val['year']; } -if (!count($arrayyears)) $arrayyears[$nowyear] = $nowyear; +if (!count($arrayyears)) { + $arrayyears[$nowyear] = $nowyear; +} $h = 0; @@ -223,7 +231,9 @@ print ''; // User print ''.$langs->trans("User").''; $include = ''; -if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)) $include = 'hierarchy'; +if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)) { + $include = 'hierarchy'; +} print $form->select_dolusers($userid, 'userid', 1, '', 0, $include, '', 0, 0, 0, '', 0, '', 'maxwidth300'); print ''; // Status @@ -235,7 +245,9 @@ print ''; print ''; print $form->textwithpicto($langs->trans("Year"), $langs->trans("DateValidation")); print ''; -if (!in_array($year, $arrayyears)) $arrayyears[$year] = $year; +if (!in_array($year, $arrayyears)) { + $arrayyears[$year] = $year; +} arsort($arrayyears); print $form->selectarray('year', $arrayyears, $year, 0); print ''; @@ -254,11 +266,9 @@ print ''.$langs->trans("AmountAverage").''; print ''; $oldyear = 0; -foreach ($data as $val) -{ +foreach ($data as $val) { $year = $val['year']; - while ($year && $oldyear > $year + 1) - { // If we have empty year + while ($year && $oldyear > $year + 1) { // If we have empty year $oldyear--; print ''; @@ -287,7 +297,9 @@ print '
'; // Show graphs print ''; diff --git a/htdocs/expensereport/tpl/expensereport_linktofile.tpl.php b/htdocs/expensereport/tpl/expensereport_linktofile.tpl.php index 04bb2a71990..640f4c17b5d 100644 --- a/htdocs/expensereport/tpl/expensereport_linktofile.tpl.php +++ b/htdocs/expensereport/tpl/expensereport_linktofile.tpl.php @@ -1,7 +1,6 @@ global->EXPENSEREPORT_DISABLE_ATTACHMENT_ON_LINES)) -{ +if (empty($conf->global->EXPENSEREPORT_DISABLE_ATTACHMENT_ON_LINES)) { print ''."\n"; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; @@ -12,23 +11,20 @@ if (empty($conf->global->EXPENSEREPORT_DISABLE_ATTACHMENT_ON_LINES)) $nbFiles = count($arrayoffiles); $nbLinks = Link::count($db, $object->element, $object->id); - if ($nbFiles > 0) - { + if ($nbFiles > 0) { print 'global->MAIN_OPTIMIZEFORTEXTBROWSER) ? ' style="display: none"' : '').'>'; print ' > - - + +
'; -if ($mesg) { print $mesg; } else { +if ($mesg) { + print $mesg; +} else { print $px1->show(); print "
\n"; print $px2->show(); diff --git a/htdocs/expensereport/tpl/expensereport_addfile.tpl.php b/htdocs/expensereport/tpl/expensereport_addfile.tpl.php index 9b2cd49faec..c27136ebd38 100644 --- a/htdocs/expensereport/tpl/expensereport_addfile.tpl.php +++ b/htdocs/expensereport/tpl/expensereport_addfile.tpl.php @@ -9,11 +9,9 @@ $permission = $user->rights->expensereport->creer; // We define var to enable the feature to add prefix of uploaded files $savingdocmask = ''; -if (empty($conf->global->MAIN_DISABLE_SUGGEST_REF_AS_PREFIX)) -{ +if (empty($conf->global->MAIN_DISABLE_SUGGEST_REF_AS_PREFIX)) { //var_dump($modulepart); - if (in_array($modulepart, array('facture_fournisseur', 'commande_fournisseur', 'facture', 'commande', 'propal', 'supplier_proposal', 'ficheinter', 'contract', 'expedition', 'project', 'project_task', 'expensereport', 'tax', 'produit', 'product_batch'))) - { + if (in_array($modulepart, array('facture_fournisseur', 'commande_fournisseur', 'facture', 'commande', 'propal', 'supplier_proposal', 'ficheinter', 'contract', 'expedition', 'project', 'project_task', 'expensereport', 'tax', 'produit', 'product_batch'))) { $savingdocmask = dol_sanitizeFileName($object->ref).'-__file__'; } } @@ -35,6 +33,6 @@ $formfile->form_attach_new_file( 'accept', '', 1 - ); +); print '
'; //print ''.$langs->trans("AttachTheNewLineToTheDocument").'
'; $modulepart = 'expensereport'; $maxheightmini = 48; $relativepath = (!empty($object->ref) ?dol_sanitizeFileName($object->ref) : '').'/'; $filei = 0; - foreach ($arrayoffiles as $file) - { + foreach ($arrayoffiles as $file) { $urlforhref = array(); $filei++; print '
'; $fileinfo = pathinfo($file['fullname']); - if (image_format_supported($file['name']) > 0) - { + if (image_format_supported($file['name']) > 0) { $minifile = getImageFileNameForSize($file['name'], '_mini'); // For new thumbs using same ext (in lower case however) than original //print $file['path'].'/'.$minifile.'
'; $urlforhref = getAdvancedPreviewUrl($modulepart, $relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension']), 1, '&entity='.(!empty($object->entity) ? $object->entity : $conf->entity)); @@ -46,8 +42,7 @@ if (empty($conf->global->EXPENSEREPORT_DISABLE_ATTACHMENT_ON_LINES)) $error = 0; $thumbshown = ''; - if (preg_match('/\.pdf$/i', $file['name'])) - { + if (preg_match('/\.pdf$/i', $file['name'])) { $urlforhref = getAdvancedPreviewUrl($modulepart, $relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension']), 1, '&entity='.(!empty($object->entity) ? $object->entity : $conf->entity)); $filepdf = $conf->expensereport->dir_output.'/'.$relativepath.$file['name']; @@ -56,27 +51,26 @@ if (empty($conf->global->EXPENSEREPORT_DISABLE_ATTACHMENT_ON_LINES)) $pdfexists = file_exists($filepdf); - if ($pdfexists) - { + if ($pdfexists) { // Conversion du PDF en image png si fichier png non existant - if (!file_exists($fileimage) || (filemtime($fileimage) < filemtime($filepdf))) - { - if (empty($conf->global->MAIN_DISABLE_PDF_THUMBS)) // If you experience trouble with pdf thumb generation and imagick, you can disable here. - { + if (!file_exists($fileimage) || (filemtime($fileimage) < filemtime($filepdf))) { + if (empty($conf->global->MAIN_DISABLE_PDF_THUMBS)) { // If you experience trouble with pdf thumb generation and imagick, you can disable here. include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $ret = dol_convert_file($filepdf, 'png', $fileimage, '0'); // Convert first page of PDF into a file _preview.png - if ($ret < 0) $error++; + if ($ret < 0) { + $error++; + } } } } - if ($pdfexists && !$error) - { + if ($pdfexists && !$error) { $heightforphotref = 70; - if (!empty($conf->dol_optimize_smallscreen)) $heightforphotref = 60; + if (!empty($conf->dol_optimize_smallscreen)) { + $heightforphotref = 60; + } // If the preview file is found - if (file_exists($fileimage)) - { + if (file_exists($fileimage)) { $thumbshown = ''; } } @@ -98,10 +92,8 @@ if (empty($conf->global->EXPENSEREPORT_DISABLE_ATTACHMENT_ON_LINES)) //var_dump(GETPOST($file['relativename'])); var_dump($file['relativename']); var_dump($_FILES['userfile']['name']); // If a file was just uploaded, we check to preselect it if (is_array($_FILES['userfile']['name'])) { - foreach ($_FILES['userfile']['name'] as $tmpfile) - { - if ($file['relativename'] == (GETPOST('savingdocmask', 'alpha') ? dol_sanitizeFileName($object->ref.'-') : '').$tmpfile) - { + foreach ($_FILES['userfile']['name'] as $tmpfile) { + if ($file['relativename'] == (GETPOST('savingdocmask', 'alpha') ? dol_sanitizeFileName($object->ref.'-') : '').$tmpfile) { $checked = ' checked'; break; } elseif ($file['relativename'] && in_array($file['relativename'], GETPOST('attachfile', 'array'))) { @@ -111,8 +103,7 @@ if (empty($conf->global->EXPENSEREPORT_DISABLE_ATTACHMENT_ON_LINES)) } } // If we edit a line already linked, then $filenamelinked is defined to the filename (without path) of linked file - if (!empty($filenamelinked) && $filenamelinked == $file['relativename']) - { + if (!empty($filenamelinked) && $filenamelinked == $file['relativename']) { $checked = ' checked'; } print '
'; diff --git a/htdocs/expensereport/tpl/linkedobjectblock.tpl.php b/htdocs/expensereport/tpl/linkedobjectblock.tpl.php index a0ef7c353c6..31c5526903b 100644 --- a/htdocs/expensereport/tpl/linkedobjectblock.tpl.php +++ b/htdocs/expensereport/tpl/linkedobjectblock.tpl.php @@ -18,8 +18,7 @@ */ // Protection to avoid direct call of template -if (empty($conf) || !is_object($conf)) -{ +if (empty($conf) || !is_object($conf)) { print "Error, template page can't be called as URL"; exit; } @@ -35,13 +34,12 @@ $linkedObjectBlock = $GLOBALS['linkedObjectBlock']; $var = true; $total = 0; -foreach ($linkedObjectBlock as $key => $objectlink) -{ +foreach ($linkedObjectBlock as $key => $objectlink) { ?>
trans("ExpenseReport"); ?>getNomUrl(1); ?>getNomUrl(1); ?> date_debut, 'day'); ?> rights->expensereport->lire) {