--- /tmp/dsg/dolibarr/htdocs/expensereport/github_card.php +++ /tmp/dsg/dolibarr/htdocs/expensereport/client_card.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2020 Laurent Destailleur + * Copyright (C) 2004-2019 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2015-2017 Alexandre Spangaro * Copyright (C) 2017 Ferran Marcet @@ -27,11 +27,10 @@ */ require '../main.inc.php'; -require_once DOL_DOCUMENT_ROOT.'/core/class/html.formexpensereport.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; -require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; @@ -61,7 +60,7 @@ $fk_project = GETPOST('fk_project', 'int'); $vatrate = GETPOST('vatrate', 'alpha'); $ref = GETPOST("ref", 'alpha'); -$comments = GETPOST('comments', 'restricthtml'); +$comments = GETPOST('comments', 'none'); $fk_c_type_fees = GETPOST('fk_c_type_fees', 'int'); $socid = GETPOST('socid', 'int') ?GETPOST('socid', 'int') : GETPOST('socid_id', 'int'); @@ -116,14 +115,14 @@ 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) - { - accessforbidden(); - } + // 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) + { + accessforbidden(); + } } @@ -146,260 +145,255 @@ } $action = ''; - $fk_project = ''; - $date_start = ''; - $date_end = ''; - $date = ''; - $comments = ''; - $vatrate = ''; - $value_unit_ht = ''; - $value_unit = ''; - $qty = 1; - $fk_c_type_fees = -1; + $fk_project = ''; + $date_start = ''; + $date_end = ''; + $date = ''; + $comments = ''; + $vatrate = ''; + $value_unit_ht = ''; + $value_unit = ''; + $qty = 1; + $fk_c_type_fees = -1; } 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 ($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 - - include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once - - include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once - - // Action clone object - if ($action == 'confirm_clone' && $confirm == 'yes' && $user->rights->expensereport->creer) - { - if (1 == 0 && !GETPOST('clone_content', 'alpha') && !GETPOST('clone_receivers', 'alpha')) - { - setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors'); - } else { - 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) - { - header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result); - exit; - } else { - setEventMessages($object->error, $object->errors, 'errors'); - $object = $orig; - $action = ''; - } - } - } - } - - 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) - { - header("Location: index.php"); - exit; - } else { - setEventMessages($object->error, $object->errors, 'errors'); - } - } - - if ($action == 'add' && $user->rights->expensereport->creer) - { - $error = 0; - - $object = new ExpenseReport($db); - - $object->date_debut = $date_start; - $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; - - // 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)) - || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->expensereport->creer) && empty($user->rights->expensereport->writeall_advance))) { - $error++; - setEventMessages($langs->trans("NotEnoughPermission"), null, 'errors'); - } - if (!$error) { - if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->expensereport->writeall_advance)) { - if (!in_array($object->fk_user_author, $childids)) { - $error++; - setEventMessages($langs->trans("UserNotInHierachy"), null, 'errors'); - } - } - } - - $fuser = new User($db); - $fuser->fetch($object->fk_user_author); - - $object->status = 1; - $object->fk_c_paiement = GETPOST('fk_c_paiement', 'int'); - $object->fk_user_validator = GETPOST('fk_user_validator', 'int'); - $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) - { - $ret = $extrafields->setOptionalsFromPost(null, $object); - if ($ret < 0) $error++; - } - - 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) - { - $db->begin(); - - $id = $object->create($user); - if ($id <= 0) - { - $error++; - } - - if (!$error) - { - $db->commit(); - Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); - exit; - } else { - setEventMessages($object->error, $object->errors, 'errors'); - $db->rollback(); - $action = 'create'; - } - } - } - - 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) - { - $object->fk_user_validator = GETPOST('fk_user_validator', 'int'); - } - - $object->fk_c_paiement = GETPOST('fk_c_paiement', 'int'); - $object->note_public = GETPOST('note_public', 'restricthtml'); - $object->note_private = GETPOST('note_private', 'restricthtml'); - $object->fk_user_modif = $user->id; - - $result = $object->update($user); - if ($result > 0) - { - header("Location: ".$_SERVER["PHP_SELF"]."?id=".GETPOST('id', 'int')); - exit; - } else { - setEventMessages($object->error, $object->errors, 'errors'); - } - } - - 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 (!$error) - { - // Actions on extra fields - $result = $object->insertExtraFields('EXPENSEREPORT_MODIFY'); + include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once + + include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once + + include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once + + // Action clone object + if ($action == 'confirm_clone' && $confirm == 'yes' && $user->rights->expensereport->creer) + { + if (1 == 0 && !GETPOST('clone_content', 'alpha') && !GETPOST('clone_receivers', 'alpha')) + { + setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors'); + } + else + { + 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) + { + header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result); + exit; + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + $object = $orig; + $action = ''; + } + } + } + } + + 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) + { + header("Location: index.php"); + exit; + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + + if ($action == 'add' && $user->rights->expensereport->creer) + { + $object = new ExpenseReport($db); + + $object->date_debut = $date_start; + $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; + + $fuser = new User($db); + $fuser->fetch($object->fk_user_author); + + $object->fk_statut = 1; + $object->fk_c_paiement = GETPOST('fk_c_paiement', 'int'); + $object->fk_user_validator = GETPOST('fk_user_validator', 'int'); + $object->note_public = GETPOST('note_public', 'none'); + $object->note_private = GETPOST('note_private', 'none'); + // Fill array 'array_options' with data from add form + if (!$error) + { + $ret = $extrafields->setOptionalsFromPost(null, $object); + if ($ret < 0) $error++; + } + + 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) + { + $db->begin(); + + $id = $object->create($user); + if ($id <= 0) + { + $error++; + } + + if (!$error) + { + $db->commit(); + Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); + exit; + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + $db->rollback(); + $action = 'create'; + } + } + } + + 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->fk_statut < 3) + { + $object->fk_user_validator = GETPOST('fk_user_validator', 'int'); + } + + $object->fk_c_paiement = GETPOST('fk_c_paiement', 'int'); + $object->note_public = GETPOST('note_public', 'none'); + $object->note_private = GETPOST('note_private', 'none'); + $object->fk_user_modif = $user->id; + + $result = $object->update($user); + if ($result > 0) + { + header("Location: ".$_SERVER["PHP_SELF"]."?id=".$_POST['id']); + exit; + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + + 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', 'none')); + if ($ret < 0) $error++; + + if (!$error) + { + // Actions on extra fields + $result = $object->insertExtraFields('EXPENSEREPORT_MODIFY'); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); $error++; } - } - - if ($error) - $action = 'edit_extras'; - } - - if ($action == "confirm_validate" && GETPOST("confirm", 'alpha') == "yes" && $id > 0 && $user->rights->expensereport->creer) - { - $error = 0; - - $db->begin(); - - $object = new ExpenseReport($db); - $object->fetch($id); - - $result = $object->setValidate($user); - - if ($result >= 0) - { - // Define output language - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { - $outputlangs = $langs; - $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; - if (!empty($newlang)) { - $outputlangs = new Translate("", $conf); - $outputlangs->setDefaultLang($newlang); - } - $model = $object->model_pdf; - $ret = $object->fetch($id); // Reload to get new records - - $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); - } - } else { - setEventMessages($object->error, $object->errors, 'errors'); - $error++; - } - - if (!$error && $result > 0 && $object->fk_user_validator > 0) - { - $langs->load("mails"); - - // 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 ($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; - - $subject = $societeName." - ".$langs->transnoentities("ExpenseReportWaitingForApproval"); - - // CONTENT - $link = $urlwithroot.'/expensereport/card.php?id='.$object->id; + } + + if ($error) + $action = 'edit_extras'; + } + + if ($action == "confirm_validate" && GETPOST("confirm", 'alpha') == "yes" && $id > 0 && $user->rights->expensereport->creer) + { + $error = 0; + + $db->begin(); + + $object = new ExpenseReport($db); + $object->fetch($id); + + $result = $object->setValidate($user); + + if ($result >= 0) + { + // Define output language + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + $outputlangs = $langs; + $newlang = ''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if (!empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + $model = $object->modelpdf; + $ret = $object->fetch($id); // Reload to get new records + + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + $error++; + } + + if (!$error && $result > 0 && $object->fk_user_validator > 0) + { + $langs->load("mails"); + + // 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 ($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; + + $subject = $societeName." - ".$langs->transnoentities("ExpenseReportWaitingForApproval"); + + // CONTENT + $link = $urlwithroot.'/expensereport/card.php?id='.$object->id; $link = ''.$link.''; - $message = $langs->transnoentities("ExpenseReportWaitingForApprovalMessage", $expediteur->getFullName($langs), get_date_range($object->date_debut, $object->date_fin, '', $langs), $link); - - // Rebuild pdf - /* + $message = $langs->transnoentities("ExpenseReportWaitingForApprovalMessage", $expediteur->getFullName($langs), get_date_range($object->date_debut, $object->date_fin, '', $langs), $link); + + // Rebuild pdf + /* $object->setDocModel($user,""); $resultPDF = expensereport_pdf_create($db,$id,'',"",$langs); @@ -410,78 +404,88 @@ array_push($mimetype,"application/pdf"); */ - // PREPARE SEND - $mailfile = new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, '', '', 0, -1); - - if ($mailfile) - { - // SEND - $result = $mailfile->sendfile(); - if ($result) - { - $mesg = $langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2)); - setEventMessages($mesg, null, 'mesgs'); - } 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 = ''; - } - } + // PREPARE SEND + $mailfile = new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, '', '', 0, -1); + + if ($mailfile) + { + // SEND + $result = $mailfile->sendfile(); + if ($result) + { + $mesg = $langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2)); + setEventMessages($mesg, null, 'mesgs'); + } + 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 = ''; + } + } if (!$error) { $db->commit(); header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); exit; - } else { + } + else + { $db->rollback(); } - } - - 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) - { - // Define output language - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { - $outputlangs = $langs; - $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; - if (!empty($newlang)) { - $outputlangs = new Translate("", $conf); - $outputlangs->setDefaultLang($newlang); - } - $model = $object->model_pdf; - $ret = $object->fetch($id); // Reload to get new records - - $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); - } - } - - if ($result > 0) - { - // Send mail + } + + 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) + { + // Define output language + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + $outputlangs = $langs; + $newlang = ''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if (!empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + $model = $object->modelpdf; + $ret = $object->fetch($id); // Reload to get new records + + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + } + + if ($result > 0) + { + // Send mail // TO $destinataire = new User($db); @@ -495,19 +499,19 @@ 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; - - $subject = $societeName." - ".$langs->transnoentities("ExpenseReportWaitingForReApproval"); - - // CONTENT - $link = $urlwithroot.'/expensereport/card.php?id='.$object->id; + $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; + + $subject = $societeName." - ".$langs->transnoentities("ExpenseReportWaitingForReApproval"); + + // CONTENT + $link = $urlwithroot.'/expensereport/card.php?id='.$object->id; $link = ''.$link.''; $dateRefusEx = explode(" ", $object->date_refuse); - $message = $langs->transnoentities("ExpenseReportWaitingForReApprovalMessage", $dateRefusEx[0], $object->detail_refuse, $expediteur->getFullName($langs), $link); + $message = $langs->transnoentities("ExpenseReportWaitingForReApprovalMessage", $dateRefusEx[0], $object->detail_refuse, $expediteur->getFullName($langs), $link); // Rebuild pdf /* @@ -525,75 +529,85 @@ */ - // PREPARE SEND - $mailfile = new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, '', '', 0, -1); - - if ($mailfile) - { - // SEND - $result = $mailfile->sendfile(); - if ($result) - { - $mesg = $langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2)); - setEventMessages($mesg, null, 'mesgs'); - header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); - exit; - } else { - $langs->load("other"); - if ($mailfile->error) - { - $mesg = ''; - $mesg .= $langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo); - $mesg .= '
'.$mailfile->error; - setEventMessages($mesg, null, 'errors'); - } else { - setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'warnings'); - } - } - } else { - setEventMessages($mailfile->error, $mailfile->errors, 'errors'); - $action = ''; - } - } else { - setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings'); - $action = ''; - } - } else { - setEventMessages($object->error, $object->errors, 'errors'); - } - } - - // 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) - { - // Define output language - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { - $outputlangs = $langs; - $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; - if (!empty($newlang)) { - $outputlangs = new Translate("", $conf); - $outputlangs->setDefaultLang($newlang); - } - $model = $object->model_pdf; - $ret = $object->fetch($id); // Reload to get new records - - $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); - } - } - - if ($result > 0) - { - // Send mail + // PREPARE SEND + $mailfile = new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, '', '', 0, -1); + + if ($mailfile) + { + // SEND + $result = $mailfile->sendfile(); + if ($result) + { + $mesg = $langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2)); + setEventMessages($mesg, null, 'mesgs'); + header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); + exit; + } + else + { + $langs->load("other"); + if ($mailfile->error) + { + $mesg = ''; + $mesg .= $langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo); + $mesg .= '
'.$mailfile->error; + setEventMessages($mesg, null, 'errors'); + } + else + { + setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'warnings'); + } + } + } + else + { + setEventMessages($mailfile->error, $mailfile->errors, 'errors'); + $action = ''; + } + } + else + { + setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings'); + $action = ''; + } + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + + // 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) + { + // Define output language + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + $outputlangs = $langs; + $newlang = ''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if (!empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + $model = $object->modelpdf; + $ret = $object->fetch($id); // Reload to get new records + + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + } + + if ($result > 0) + { + // Send mail // TO $destinataire = new User($db); @@ -602,7 +616,7 @@ // CC $emailCC = $conf->global->NDF_CC_EMAILS; - if (empty($emailTo)) $emailTo = $emailCC; + if (empty($emailTo)) $emailTo = $emailCC; // FROM $expediteur = new User($db); @@ -611,21 +625,21 @@ 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; - - $subject = $societeName." - ".$langs->transnoentities("ExpenseReportApproved"); - - // CONTENT - $link = $urlwithroot.'/expensereport/card.php?id='.$object->id; + $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; + + $subject = $societeName." - ".$langs->transnoentities("ExpenseReportApproved"); + + // CONTENT + $link = $urlwithroot.'/expensereport/card.php?id='.$object->id; $link = ''.$link.''; - $message = $langs->transnoentities("ExpenseReportApprovedMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $link); - - // Rebuilt pdf - /* + $message = $langs->transnoentities("ExpenseReportApprovedMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $link); + + // Rebuilt pdf + /* $object->setDocModel($user,""); $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs); @@ -639,103 +653,113 @@ } */ - $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 { - setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings'); - $action = ''; - } - } else { + $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 + { + setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings'); + $action = ''; + } + } + else + { setEventMessages($langs->trans("FailedtoSetToApprove"), null, 'warnings'); $action = ''; } } - if ($action == "confirm_refuse" && GETPOST('confirm', 'alpha') == "yes" && $id > 0 && $user->rights->expensereport->approve) - { - $object = new ExpenseReport($db); - $object->fetch($id); + 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) - { - // Define output language - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { - $outputlangs = $langs; - $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; - if (!empty($newlang)) { - $outputlangs = new Translate("", $conf); - $outputlangs->setDefaultLang($newlang); - } - $model = $object->model_pdf; - $ret = $object->fetch($id); // Reload to get new records - - $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); - } - } - - if ($result > 0) - { - // Send mail - - // TO - $destinataire = new User($db); - $destinataire->fetch($object->fk_user_author); - $emailTo = $destinataire->email; - - // FROM - $expediteur = new User($db); - $expediteur->fetch($object->fk_user_refuse); - $emailFrom = $expediteur->email; - - 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; - - $subject = $societeName." - ".$langs->transnoentities("ExpenseReportRefused"); - - // CONTENT - $link = $urlwithroot.'/expensereport/card.php?id='.$object->id; + $result = $object->setDeny($user, $detailRefuse); + + if ($result > 0) + { + // Define output language + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + $outputlangs = $langs; + $newlang = ''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if (!empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + $model = $object->modelpdf; + $ret = $object->fetch($id); // Reload to get new records + + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + } + + if ($result > 0) + { + // Send mail + + // TO + $destinataire = new User($db); + $destinataire->fetch($object->fk_user_author); + $emailTo = $destinataire->email; + + // FROM + $expediteur = new User($db); + $expediteur->fetch($object->fk_user_refuse); + $emailFrom = $expediteur->email; + + 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; + + $subject = $societeName." - ".$langs->transnoentities("ExpenseReportRefused"); + + // 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 - /* + $message = $langs->transnoentities("ExpenseReportRefusedMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $detailRefuse, $link); + + // Rebuilt pdf + /* $object->setDocModel($user,""); $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs); @@ -749,111 +773,123 @@ } */ - // PREPARE SEND - $mailfile = new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, '', '', 0, -1); - - if ($mailfile) - { - // SEND - $result = $mailfile->sendfile(); - if ($result) - { - $mesg = $langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2)); - setEventMessages($mesg, null, 'mesgs'); - header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); - exit; - } else { - $langs->load("other"); - if ($mailfile->error) - { - $mesg = ''; - $mesg .= $langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo); - $mesg .= '
'.$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("FailedtoSetToDeny"), null, 'warnings'); - $action = ''; - } - } - - //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')) - { - 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) - { + // PREPARE SEND + $mailfile = new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, '', '', 0, -1); + + if ($mailfile) + { + // SEND + $result = $mailfile->sendfile(); + if ($result) + { + $mesg = $langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2)); + setEventMessages($mesg, null, 'mesgs'); + header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); + exit; + } + else + { + $langs->load("other"); + if ($mailfile->error) + { + $mesg = ''; + $mesg .= $langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo); + $mesg .= '
'.$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("FailedtoSetToDeny"), null, 'warnings'); + $action = ''; + } + } + + //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')) + { + 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) + { $detailCancel = GETPOST('detail_cancel', 'alpha'); - $result = $object->set_cancel($user, $detailCancel); - - if ($result > 0) - { - // Define output language - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { - $outputlangs = $langs; - $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; - if (!empty($newlang)) { - $outputlangs = new Translate("", $conf); - $outputlangs->setDefaultLang($newlang); - } - $model = $object->model_pdf; - $ret = $object->fetch($id); // Reload to get new records - - $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); - } - } - - if ($result > 0) - { - // Send mail - - // TO - $destinataire = new User($db); - $destinataire->fetch($object->fk_user_author); - $emailTo = $destinataire->email; - - // FROM - $expediteur = new User($db); - $expediteur->fetch($object->fk_user_cancel); - $emailFrom = $expediteur->email; - - if ($emailFrom && $emailTo) - { - $filename = array(); $filedir = array(); $mimetype = array(); - - // SUBJECT - $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM; - if (!empty($conf->global->MAIN_APPLICATION_TITLE)) $societeName = $conf->global->MAIN_APPLICATION_TITLE; - - $subject = $societeName." - ".$langs->transnoentities("ExpenseReportCanceled"); - - // CONTENT - $link = $urlwithroot.'/expensereport/card.php?id='.$object->id; + $result = $object->set_cancel($user, $detailCancel); + + if ($result > 0) + { + // Define output language + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + $outputlangs = $langs; + $newlang = ''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if (!empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + $model = $object->modelpdf; + $ret = $object->fetch($id); // Reload to get new records + + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + } + + if ($result > 0) + { + // Send mail + + // TO + $destinataire = new User($db); + $destinataire->fetch($object->fk_user_author); + $emailTo = $destinataire->email; + + // FROM + $expediteur = new User($db); + $expediteur->fetch($object->fk_user_cancel); + $emailFrom = $expediteur->email; + + if ($emailFrom && $emailTo) + { + $filename = array(); $filedir = array(); $mimetype = array(); + + // SUBJECT + $societeName = $conf->global->MAIN_INFO_SOCIETE_NOM; + if (!empty($conf->global->MAIN_APPLICATION_TITLE)) $societeName = $conf->global->MAIN_APPLICATION_TITLE; + + $subject = $societeName." - ".$langs->transnoentities("ExpenseReportCanceled"); + + // CONTENT + $link = $urlwithroot.'/expensereport/card.php?id='.$object->id; $link = ''.$link.''; - $message = $langs->transnoentities("ExpenseReportCanceledMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $detailCancel, $link); - - // Rebuilt pdf - /* + $message = $langs->transnoentities("ExpenseReportCanceledMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $detailCancel, $link); + + // Rebuilt pdf + /* $object->setDocModel($user,""); $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs); @@ -867,290 +903,344 @@ } */ - // PREPARE SEND - $mailfile = new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, '', '', 0, -1); - - if ($mailfile) - { - // SEND - $result = $mailfile->sendfile(); - if ($result) - { - $mesg = $langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2)); - setEventMessages($mesg, null, 'mesgs'); - header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); - exit; - } else { - $langs->load("other"); - if ($mailfile->error) - { - $mesg = ''; - $mesg .= $langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo); - $mesg .= '
'.$mailfile->error; - setEventMessages($mesg, null, 'errors'); - } else { - setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'warnings'); - } - } - } else { - setEventMessages($mailfile->error, $mailfile->errors, 'errors'); - $action = ''; - } - } else { - setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings'); - $action = ''; - } - } else { - setEventMessages($langs->trans("FailedToSetToCancel"), null, 'warnings'); - $action = ''; - } - } else { - setEventMessages($object->error, $object->errors, 'errors'); - } - } - } - - 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) - { - $result = $object->setStatut(0); - - if ($result > 0) - { - // Define output language - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { - $outputlangs = $langs; - $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; - if (!empty($newlang)) { - $outputlangs = new Translate("", $conf); - $outputlangs->setDefaultLang($newlang); - } - $model = $object->model_pdf; - $ret = $object->fetch($id); // Reload to get new records - - $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); - } - } - - if ($result > 0) - { - header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); - exit; - } else { - setEventMessages($object->error, $object->errors, 'errors'); - } - } else { - setEventMessages("NOT_AUTHOR", '', 'errors'); - } - } - - if ($action == 'set_unpaid' && $id > 0 && $user->rights->expensereport->to_paid) - { - $object = new ExpenseReport($db); - $object->fetch($id); - - $result = $object->set_unpaid($user); - - if ($result > 0) - { - // Define output language - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { - $outputlangs = $langs; - $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; - if (!empty($newlang)) { - $outputlangs = new Translate("", $conf); - $outputlangs->setDefaultLang($newlang); - } - $model = $object->model_pdf; - $ret = $object->fetch($id); // Reload to get new records - - $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); - } - } - } - - if ($action == 'set_paid' && $id > 0 && $user->rights->expensereport->to_paid) - { - $object = new ExpenseReport($db); - $object->fetch($id); - - $result = $object->set_paid($id, $user); - - if ($result > 0) - { - // Define output language - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { - $outputlangs = $langs; - $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; - if (!empty($newlang)) { - $outputlangs = new Translate("", $conf); - $outputlangs->setDefaultLang($newlang); - } - $model = $object->model_pdf; - $ret = $object->fetch($id); // Reload to get new records - - $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); - } - } - - if ($result > 0) - { - // Send mail - - // TO - $destinataire = new User($db); - $destinataire->fetch($object->fk_user_author); - $emailTo = $destinataire->email; - - // FROM - $expediteur = new User($db); - $expediteur->fetch($user->id); - $emailFrom = $expediteur->email; - - 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; - - $subject = $societeName." - ".$langs->transnoentities("ExpenseReportPaid"); - - // CONTENT - $link = $urlwithroot.'/expensereport/card.php?id='.$object->id; + // PREPARE SEND + $mailfile = new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, '', '', 0, -1); + + if ($mailfile) + { + // SEND + $result = $mailfile->sendfile(); + if ($result) + { + $mesg = $langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2)); + setEventMessages($mesg, null, 'mesgs'); + header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); + exit; + } + else + { + $langs->load("other"); + if ($mailfile->error) + { + $mesg = ''; + $mesg .= $langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo); + $mesg .= '
'.$mailfile->error; + setEventMessages($mesg, null, 'errors'); + } + else + { + setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'warnings'); + } + } + } + else + { + setEventMessages($mailfile->error, $mailfile->errors, 'errors'); + $action = ''; + } + } + else + { + setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings'); + $action = ''; + } + } + else + { + setEventMessages($langs->trans("FailedToSetToCancel"), null, 'warnings'); + $action = ''; + } + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + } + + 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) + { + $result = $object->setStatut(0); + + if ($result > 0) + { + // Define output language + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + $outputlangs = $langs; + $newlang = ''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if (!empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + $model = $object->modelpdf; + $ret = $object->fetch($id); // Reload to get new records + + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + } + + if ($result > 0) + { + header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); + exit; + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + else + { + setEventMessages("NOT_AUTHOR", '', 'errors'); + } + } + + if ($action == 'set_unpaid' && $id > 0 && $user->rights->expensereport->to_paid) + { + $object = new ExpenseReport($db); + $object->fetch($id); + + $result = $object->set_unpaid($user); + + if ($result > 0) + { + // Define output language + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + $outputlangs = $langs; + $newlang = ''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if (!empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + $model = $object->modelpdf; + $ret = $object->fetch($id); // Reload to get new records + + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + } + } + + if ($action == 'set_unpaid' && $id > 0 && $user->rights->expensereport->to_paid) + { + $object = new ExpenseReport($db); + $object->fetch($id); + + $result = $object->set_unpaid($user); + + if ($result > 0) + { + // Define output language + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + $outputlangs = $langs; + $newlang = ''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if (!empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + $model = $object->modelpdf; + $ret = $object->fetch($id); // Reload to get new records + + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + } + } + + if ($action == 'set_paid' && $id > 0 && $user->rights->expensereport->to_paid) + { + $object = new ExpenseReport($db); + $object->fetch($id); + + $result = $object->set_paid($id, $user); + + if ($result > 0) + { + // Define output language + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + $outputlangs = $langs; + $newlang = ''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if (!empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + $model = $object->modelpdf; + $ret = $object->fetch($id); // Reload to get new records + + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + } + + if ($result > 0) + { + // Send mail + + // TO + $destinataire = new User($db); + $destinataire->fetch($object->fk_user_author); + $emailTo = $destinataire->email; + + // FROM + $expediteur = new User($db); + $expediteur->fetch($user->id); + $emailFrom = $expediteur->email; + + 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; + + $subject = $societeName." - ".$langs->transnoentities("ExpenseReportPaid"); + + // CONTENT + $link = $urlwithroot.'/expensereport/card.php?id='.$object->id; $link = ''.$link.''; - $message = $langs->transnoentities("ExpenseReportPaidMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $link); - - // Generate pdf before attachment - $object->setDocModel($user, ""); - $resultPDF = expensereport_pdf_create($db, $object, '', "", $langs); - - // PREPARE SEND - $mailfile = new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, '', '', 0, -1); - - if ($mailfile) - { - // SEND - $result = $mailfile->sendfile(); - if ($result) - { - $mesg = $langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2)); - setEventMessages($mesg, null, 'mesgs'); - header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); - exit; - } else { - $langs->load("other"); - if ($mailfile->error) - { - $mesg = ''; - $mesg .= $langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo); - $mesg .= '
'.$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("FailedToSetPaid"), null, 'warnings'); - $action = ''; - } - } - - if ($action == "addline" && $user->rights->expensereport->creer) - { - $error = 0; - - // First save uploaded file - $fk_ecm_files = 0; - if (GETPOSTISSET('attachfile')) - { - $arrayoffiles = GETPOST('attachfile', 'array'); - 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); - $ecmfiles->fetch(0, '', $relativepath); - $fk_ecm_files = $ecmfiles->id; - } - } + $message = $langs->transnoentities("ExpenseReportPaidMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $link); + + // Generate pdf before attachment + $object->setDocModel($user, ""); + $resultPDF = expensereport_pdf_create($db, $object, '', "", $langs); + + // PREPARE SEND + $mailfile = new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, '', '', 0, -1); + + if ($mailfile) + { + // SEND + $result = $mailfile->sendfile(); + if ($result) + { + $mesg = $langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2)); + setEventMessages($mesg, null, 'mesgs'); + header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); + exit; + } + else + { + $langs->load("other"); + if ($mailfile->error) + { + $mesg = ''; + $mesg .= $langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo); + $mesg .= '
'.$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("FailedToSetPaid"), null, 'warnings'); + $action = ''; + } + } + + if ($action == "addline" && $user->rights->expensereport->creer) + { + $error = 0; + + // First save uploaded file + $fk_ecm_files = 0; + if (GETPOSTISSET('attachfile')) + { + $arrayoffiles = GETPOST('attachfile', 'array'); + 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); + $ecmfiles->fetch(0, '', $relativepath); + $fk_ecm_files = $ecmfiles->id; + } + } // if VAT is not used in Dolibarr, set VAT rate to 0 because VAT rate is necessary. - if (empty($vatrate)) $vatrate = "0.000"; - $tmpvat = price2num(preg_replace('/\s*\(.*\)/', '', $vatrate)); + 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)) { - $value_unit = price2num($value_unit_ht + ($value_unit_ht * $tmpvat / 100), 'MU'); + $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 (!($fk_c_type_fees > 0)) - { - $error++; - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors'); - $action = ''; - } - - 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 == "--") - { - $error++; - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors'); - } - // Si aucun prix n'est rentré - 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))) - { - $langs->load("errors"); - setEventMessages($langs->trans("WarningDateOfLineMustBeInExpenseReportRange"), null, 'warnings'); - } - - 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 + $qty = GETPOST('qty', 'int'); + if (empty($qty)) $qty = 1; + + if (!($fk_c_type_fees > 0)) + { + $error++; + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors'); + $action = ''; + } + + 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 == "--") + { + $error++; + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors'); + } + // Si aucun prix n'est rentré + 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))) + { + $langs->load("errors"); + setEventMessages($langs->trans("WarningDateOfLineMustBeInExpenseReportRange"), null, 'warnings'); + } + + 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); + $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) { $ret = $object->fetch($object->id); // Reload to get new records @@ -1166,7 +1256,7 @@ $outputlangs->setDefaultLang($newlang); } - $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref); + $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); } unset($qty); @@ -1181,159 +1271,163 @@ } else { setEventMessages($object->error, $object->errors, 'errors'); } - } - - $action = ''; - } - - if ($action == 'confirm_delete_line' && GETPOST("confirm", 'alpha') == "yes" && $user->rights->expensereport->creer) - { - $object = new ExpenseReport($db); - $object->fetch($id); - - $object_ligne = new ExpenseReportLine($db); - $object_ligne->fetch(GETPOST("rowid", 'int')); - $total_ht = $object_ligne->total_ht; - $total_tva = $object_ligne->total_tva; - - $result = $object->deleteline(GETPOST("rowid", 'int'), $user); - if ($result >= 0) - { - if ($result > 0) - { - // Define output language - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { - $outputlangs = $langs; - $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; - if (!empty($newlang)) { - $outputlangs = new Translate("", $conf); - $outputlangs->setDefaultLang($newlang); - } - $model = $object->model_pdf; - $ret = $object->fetch($id); // Reload to get new records - - $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); - } - } - - $object->update_totaux_del($object_ligne->total_ht, $object_ligne->total_tva); - header("Location: ".$_SERVER["PHP_SELF"]."?id=".$_GET['id']); - exit; - } else { - setEventMessages($object->error, $object->errors, 'errors'); - } - } - - 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')) - { - $arrayoffiles = GETPOST('attachfile', 'array'); - 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); - $ecmfiles->fetch(0, '', $relativepath); - $fk_ecm_files = $ecmfiles->id; - } - } - - $rowid = $_POST['rowid']; - $type_fees_id = GETPOST('fk_c_type_fees', 'int'); + } + + $action = ''; + } + + if ($action == 'confirm_delete_line' && GETPOST("confirm", 'alpha') == "yes" && $user->rights->expensereport->creer) + { + $object = new ExpenseReport($db); + $object->fetch($id); + + $object_ligne = new ExpenseReportLine($db); + $object_ligne->fetch(GETPOST("rowid", 'int')); + $total_ht = $object_ligne->total_ht; + $total_tva = $object_ligne->total_tva; + + $result = $object->deleteline(GETPOST("rowid", 'int'), $user); + if ($result >= 0) + { + if ($result > 0) + { + // Define output language + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + $outputlangs = $langs; + $newlang = ''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if (!empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + $model = $object->modelpdf; + $ret = $object->fetch($id); // Reload to get new records + + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + } + + $object->update_totaux_del($object_ligne->total_ht, $object_ligne->total_tva); + header("Location: ".$_SERVER["PHP_SELF"]."?id=".$_GET['id']); + exit; + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + + 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')) + { + $arrayoffiles = GETPOST('attachfile', 'array'); + 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); + $ecmfiles->fetch(0, '', $relativepath); + $fk_ecm_files = $ecmfiles->id; + } + } + + $rowid = $_POST['rowid']; + $type_fees_id = GETPOST('fk_c_type_fees', 'int'); $fk_c_exp_tax_cat = GETPOST('fk_c_exp_tax_cat', 'int'); - $projet_id = $fk_project; - $comments = GETPOST('comments', 'restricthtml'); - $qty = GETPOST('qty', 'int'); - $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"; - $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)) - { - $value_unit = price2num($value_unit_ht + ($value_unit_ht * $tmpvat / 100), 'MU'); - } - - if (!GETPOST('fk_c_type_fees', 'int') > 0) - { - $error++; - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors'); - $action = ''; - } - if ((int) $tmpvat < 0 || $tmpvat == '') - { - $error++; - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Vat")), null, 'errors'); - $action = ''; - } - // Warning if date out of range + $projet_id = $fk_project; + $comments = GETPOST('comments', 'none'); + $qty = GETPOST('qty', 'int'); + $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"; + $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)) + { + $value_unit = price2num($value_unit_ht + ($value_unit_ht * $tmpvat / 100), 'MU'); + } + + if (!GETPOST('fk_c_type_fees', 'int') > 0) + { + $error++; + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors'); + $action = ''; + } + 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))) - { - $langs->load("errors"); - setEventMessages($langs->trans("WarningDateOfLineMustBeInExpenseReportRange"), null, 'warnings'); - } - - 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) - { - // Define output language - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { - $outputlangs = $langs; - $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; - if (!empty($newlang)) { - $outputlangs = new Translate("", $conf); - $outputlangs->setDefaultLang($newlang); - } - $model = $object->model_pdf; - $ret = $object->fetch($id); // Reload to get new records - - $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); - } - } - - $result = $object->recalculer($id); - - //header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); - //exit; - } else { - setEventMessages($object->error, $object->errors, 'errors'); - } - } - } + { + $langs->load("errors"); + setEventMessages($langs->trans("WarningDateOfLineMustBeInExpenseReportRange"), null, 'warnings'); + } + + 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) + { + // Define output language + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + $outputlangs = $langs; + $newlang = ''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if (!empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + $model = $object->modelpdf; + $ret = $object->fetch($id); // Reload to get new records + + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + } + + $result = $object->recalculer($id); + + //header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); + //exit; + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + } // Actions when printing a doc from card - include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php'; - - // Actions to send emails - $triggersendname = 'EXPENSEREPORT_SENTBYMAIL'; - $autocopy = 'MAIN_MAIL_AUTOCOPY_EXPENSEREPORT_TO'; - $trackid = 'exp'.$object->id; - include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; - - // Actions to build doc - $upload_dir = $conf->expensereport->dir_output; - $permissiontoadd = $user->rights->expensereport->creer; - include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; + include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php'; + + // Actions to send emails + $triggersendname = 'EXPENSEREPORT_SENTBYMAIL'; + $autocopy = 'MAIN_MAIL_AUTOCOPY_EXPENSEREPORT_TO'; + $trackid = 'exp'.$object->id; + include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; + + // Actions to build doc + $upload_dir = $conf->expensereport->dir_output; + $permissiontoadd = $user->rights->expensereport->creer; + include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; } @@ -1343,7 +1437,6 @@ $title = $langs->trans("ExpenseReport")." - ".$langs->trans("Card"); $helpurl = "EN:Module_Expense_Reports"; - llxHeader("", $title, $helpurl); $form = new Form($db); @@ -1353,7 +1446,6 @@ $paymentexpensereportstatic = new PaymentExpenseReport($db); $bankaccountstatic = new Account($db); $ecmfilesstatic = new EcmFiles($db); -$formexpensereport = new FormExpenseReport($db); // Create if ($action == 'create') @@ -1364,7 +1456,7 @@ print ''; print ''; - print dol_get_fiche_head(''); + dol_fiche_head(''); print ''; print ''; @@ -1391,8 +1483,8 @@ print ''; @@ -1405,12 +1497,13 @@ $object = new ExpenseReport($db); $include_users = $object->fetch_users_approver_expensereport(); 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'); - $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")); + 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'); + $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")); } print ''; print ''; @@ -1449,24 +1542,27 @@ // Other attributes $parameters = array('colspan' => ' colspan="3"', 'cols' => 3); $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by - print $hookmanager->resPrint; + print $hookmanager->resPrint; if (empty($reshook)) { - print $object->showOptionals($extrafields, 'edit', $parameters); + print $object->showOptionals($extrafields, 'edit', $parameters); } print ''; print '
'; $defaultselectuser = $user->id; 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(); + $include_users = 'hierarchyme'; + 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 '
'; - print dol_get_fiche_end(); + dol_fiche_end(); print '
'; print ''; - print '     '; + print '     '; print '
'; print ''; -} else { - if ($id > 0 || $ref) { +} +else +{ + if ($id > 0 || $ref) + { $result = $object->fetch($id, $ref); $res = $object->fetch_optionals(); @@ -1476,7 +1572,7 @@ 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'); @@ -1485,8 +1581,8 @@ print ''; // End of page - llxFooter(); - $db->close(); + llxFooter(); + $db->close(); exit; } @@ -1494,18 +1590,20 @@ $head = expensereport_prepare_head($object); - if ($action == 'edit' && ($object->status < 3 || $object->status == 99)) + if ($action == 'edit' && ($object->fk_statut < 3 || $object->fk_statut == 99)) { print "
\n"; print ''; print ''; - print dol_get_fiche_head($head, 'card', $langs->trans("ExpenseReport"), 0, 'trip'); - - if ($object->status == 99) + dol_fiche_head($head, 'card', $langs->trans("ExpenseReport"), 0, 'trip'); + + if ($object->fk_statut == 99) { print ''; - } else { + } + else + { print ''; } @@ -1519,15 +1617,15 @@ $userfee = new User($db); if ($object->fk_user_author > 0) { - $userfee->fetch($object->fk_user_author); - print $userfee->getNomUrl(-1); + $userfee->fetch($object->fk_user_author); + print $userfee->getNomUrl(-1); } print ''; - // Ref - print ''.$langs->trans("Ref").''; - print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', ''); - print ''; + // Ref + print ''.$langs->trans("Ref").''; + print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', ''); + print ''; print ''; print ''.$langs->trans("DateStart").''; @@ -1552,7 +1650,7 @@ print ''; } - if ($object->status < 3) + if ($object->fk_statut < 3) { print ''; print ''.$langs->trans("VALIDATOR").''; // Approbator @@ -1562,7 +1660,9 @@ print $form->textwithpicto($s, $langs->trans("AnyOtherInThisListCanValidate")); print ''; print ''; - } else { + } + else + { print ''; print ''.$langs->trans("VALIDOR").''; print ''; @@ -1572,7 +1672,7 @@ print ''; } - if ($object->status == 6) + if ($object->fk_statut == 6) { print ''; print ''.$langs->trans("AUTHORPAIEMENT").''; @@ -1589,28 +1689,30 @@ print ''; - print dol_get_fiche_end(); + dol_fiche_end(); print '
'; print ''; - print '     '; + print '     '; print '
'; print '
'; - } else { - print dol_get_fiche_head($head, 'card', $langs->trans("ExpenseReport"), -1, 'trip'); + } + else + { + dol_fiche_head($head, 'card', $langs->trans("ExpenseReport"), -1, 'trip'); // Clone confirmation if ($action == 'clone') { - // Create an array for form - $criteriaforfilter = 'hierarchyme'; - 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')) - ); - // Paiement incomplet. On demande si motif = escompte ou autre - $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneExpenseReport', $object->ref), 'confirm_clone', $formquestion, 'yes', 1); + // Create an array for form + $criteriaforfilter = 'hierarchyme'; + 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)) + ); + // Paiement incomplet. On demande si motif = escompte ou autre + $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') @@ -1646,7 +1748,7 @@ if ($action == 'setdraft') { - $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("BrouillonnerTrip"), $langs->trans("ConfirmBrouillonnerTrip"), "confirm_setdraft", "", "", 1); + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("BrouillonnerTrip"), $langs->trans("ConfirmBrouillonnerTrip"), "confirm_setdraft", "", "", 1); } if ($action == 'refuse') // Deny @@ -1721,14 +1823,13 @@ print ''; 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); + $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); } print ''; - // Period print ''; print ''.$langs->trans("Period").''; print ''; @@ -1746,14 +1847,14 @@ // Validation date 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")); + print ''.dol_print_date($object->date_valid, 'dayhour'); + if ($object->status == 2 && $object->hasDelay('toapprove')) print ' '.img_warning($langs->trans("Late")); + if ($object->status == 5 && $object->hasDelay('topay')) print ' '.img_warning($langs->trans("Late")); print ''; print ''; // User to inform for approval - if ($object->status <= ExpenseReport::STATUS_VALIDATED) // informed + if ($object->fk_statut <= ExpenseReport::STATUS_VALIDATED) // informed { print ''; print ''.$langs->trans("VALIDATOR").''; // approver @@ -1765,12 +1866,13 @@ 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)); + $langs->load("errors"); + print img_warning($langs->trans("ErrorBadEMail", $userfee->email)); } } print ''; - } elseif ($object->status == ExpenseReport::STATUS_CANCELED) + } + elseif ($object->fk_statut == ExpenseReport::STATUS_CANCELED) { print ''; print ''.$langs->trans("CANCEL_USER").''; @@ -1789,9 +1891,11 @@ print ''; print ''; print ''.$langs->trans("DATE_CANCEL").''; - print ''.dol_print_date($object->date_cancel, 'dayhour', 'tzuser').''; + print ''.dol_print_date($object->date_cancel, 'dayhour').''; print ''; - } else { + } + else + { print ''; print ''.$langs->trans("ApprovedBy").''; print ''; @@ -1805,11 +1909,11 @@ print ''; print ''.$langs->trans("DateApprove").''; - print ''.dol_print_date($object->date_approve, 'dayhour', 'tzuser').''; + print ''.dol_print_date($object->date_approve, 'dayhour').''; print ''; } - if ($object->status == 99 || !empty($object->detail_refuse)) + if ($object->fk_statut == 99 || !empty($object->detail_refuse)) { print ''; print ''.$langs->trans("REFUSEUR").''; @@ -1821,13 +1925,13 @@ print ''; print ''.$langs->trans("DATE_REFUS").''; - print ''.dol_print_date($object->date_refuse, 'dayhour', 'tzuser'); + print ''.dol_print_date($object->date_refuse, 'dayhour'); if ($object->detail_refuse) print ' - '.$object->detail_refuse; print ''; print ''; } - if ($object->status == $object::STATUS_CLOSED) + if ($object->fk_statut == 6) { /* TODO this fields are not yet filled print ''; @@ -1862,11 +1966,11 @@ 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; + if ($object->fk_statut <= ExpenseReport::STATUS_VALIDATED) $rowspan++; + elseif ($object->fk_statut == 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->fk_statut == ExpenseReport::STATUS_REFUSED || !empty($object->detail_refuse)) $rowspan += 2; + if ($object->fk_statut == ExpenseReport::STATUS_CLOSED) $rowspan += 2; print ""; print ''; @@ -1916,25 +2020,26 @@ $resql = $db->query($sql); if ($resql) { - $num = $db->num_rows($resql); - $i = 0; $totalpaid = 0; - while ($i < $num) - { - $objp = $db->fetch_object($resql); - - $paymentexpensereportstatic->id = $objp->rowid; - $paymentexpensereportstatic->datepaye = $db->jdate($objp->dp); - $paymentexpensereportstatic->ref = $objp->rowid; - $paymentexpensereportstatic->num_payment = $objp->num_payment; - $paymentexpensereportstatic->payment_code = $objp->payment_code; - - print ''; - print ''; + $num = $db->num_rows($resql); + $i = 0; $totalpaid = 0; + while ($i < $num) + { + $objp = $db->fetch_object($resql); + + $paymentexpensereportstatic->id = $objp->rowid; + $paymentexpensereportstatic->datepaye = $db->jdate($objp->dp); + $paymentexpensereportstatic->ref = $objp->rowid; + $paymentexpensereportstatic->num_paiement = $objp->num_payment; + $paymentexpensereportstatic->num_payment = $objp->num_payment; + $paymentexpensereportstatic->payment_code = $objp->payment_code; + + print ''; + print ''; print $paymentexpensereportstatic->getNomUrl(1); print ''; - 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"; + 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)) { $bankaccountstatic->id = $objp->baid; @@ -1955,39 +2060,42 @@ print $bankaccountstatic->getNomUrl(1, 'transactions'); print ''; } - print ''.price($objp->amount).""; - print ''; - print ""; - $totalpaid += $objp->amount; - $i++; - } + print ''.price($objp->amount).""; + print ''; + print ""; + $totalpaid += $objp->amount; + $i++; + } if (!is_null($totalpaid)) { - $totalpaid = price2num($totalpaid); // Round $totalpaid to fix floating problem after addition into loop + $totalpaid = price2num($totalpaid); // Round $totalpaid to fix floating problem after addition into loop } - $remaintopay = price2num($object->total_ttc - $totalpaid); - $resteapayeraffiche = $remaintopay; - - $cssforamountpaymentcomplete = 'amountpaymentcomplete'; - - if ($object->status == ExpenseReport::STATUS_REFUSED) - { - $cssforamountpaymentcomplete = 'amountpaymentneutral'; - $resteapayeraffiche = 0; - } elseif ($object->paid == 0) - { - $cssforamountpaymentcomplete = 'amountpaymentneutral'; - } - print ''.$langs->trans("AlreadyPaid").':'.price($totalpaid).''; - print ''.$langs->trans("AmountExpected").':'.price($object->total_ttc).''; - - print ''.$langs->trans("RemainderToPay").':'; - print ''.price($resteapayeraffiche).''; - - $db->free($resql); - } else { - dol_print_error($db); + $remaintopay = price2num($object->total_ttc - $totalpaid); + $resteapayeraffiche = $remaintopay; + + $cssforamountpaymentcomplete = 'amountpaymentcomplete'; + + if ($object->status == ExpenseReport::STATUS_REFUSED) + { + $cssforamountpaymentcomplete = 'amountpaymentneutral'; + $resteapayeraffiche = 0; + } + elseif ($object->paid == 0) + { + $cssforamountpaymentcomplete = 'amountpaymentneutral'; + } + print ''.$langs->trans("AlreadyPaid").':'.price($totalpaid).''; + print ''.$langs->trans("AmountExpected").':'.price($object->total_ttc).''; + + print ''.$langs->trans("RemainderToPay").':'; + print ''.price($resteapayeraffiche).''; + + $db->free($resql); + } + else + { + dol_print_error($db); } print ""; @@ -2000,7 +2108,7 @@ print '
'; $actiontouse = 'updateline'; - if (($object->status == 0 || $object->status == 99) && $action != 'editline') $actiontouse = 'addline'; + if (($object->fk_statut == 0 || $object->fk_statut == 99) && $action != 'editline') $actiontouse = 'addline'; print '
'; print ''; @@ -2020,8 +2128,8 @@ //print ''.$langs->trans('Piece').''; print ''.$langs->trans('Date').''; if (!empty($conf->projet->enabled)) print ''.$langs->trans('Project').''; + if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) print ''.$langs->trans('CarCategory').''; print ''.$langs->trans('Type').''; - if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) print ''.$langs->trans('CarCategory').''; print ''.$langs->trans('Description').''; print ''.$langs->trans('VAT').''; print ''.$langs->trans('PriceUHT').''; @@ -2032,11 +2140,11 @@ print ''.$langs->trans('AmountHT').''; print ''.$langs->trans('AmountTTC').''; } - // Picture + // Picture print ''; print ''; // Ajout des boutons de modification/suppression - if (($object->status < 2 || $object->status == 99) && $user->rights->expensereport->creer) + if (($object->fk_statut < 2 || $object->fk_statut == 99) && $user->rights->expensereport->creer) { print ''; } @@ -2071,13 +2179,6 @@ } print ''; } - - // Type of fee - print ''; - $labeltype = ($langs->trans(($line->type_fees_code)) == $line->type_fees_code ? $line->type_fees_libelle : $langs->trans($line->type_fees_code)); - print $labeltype; - print ''; - // IK if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) { @@ -2085,20 +2186,26 @@ print dol_getIdFromCode($db, $line->fk_c_exp_tax_cat, 'c_exp_tax_cat', 'rowid', 'label'); print ''; } - + // Type of fee + print ''; + $labeltype = ($langs->trans(($line->type_fees_code)) == $line->type_fees_code ? $line->type_fees_libelle : $langs->trans($line->type_fees_code)); + print $labeltype; + print ''; // Comment print ''.dol_nl2br($line->comments).''; // VAT rate print ''.vatrate($line->vatrate, true).''; - // Unit price HT + // Unit price HT print ''; if (!empty($line->value_unit_ht)) { - print price($line->value_unit_ht); - } else { - $tmpvat = price2num(preg_replace('/\s*\(.*\)/', '', $line->vatrate)); - $pricenettoshow = price2num($line->value_unit / (1 + $tmpvat / 100), 'MU'); - print $pricenettoshow; + print price($line->value_unit_ht); + } + else + { + $tmpvat = price2num(preg_replace('/\s*\(.*\)/', '', $line->vatrate)); + $pricenettoshow = price2num($line->value_unit / (1 + $tmpvat / 100), 'MU'); + print $pricenettoshow; } print ''; @@ -2116,83 +2223,85 @@ print ''; if ($line->fk_ecm_files > 0) { - $modulepart = 'expensereport'; - $maxheightmini = 32; - - $result = $ecmfilesstatic->fetch($line->fk_ecm_files); - if ($result > 0) - { - $relativepath = preg_replace('/expensereport\//', '', $ecmfilesstatic->filepath); - $fileinfo = pathinfo($ecmfilesstatic->filepath.'/'.$ecmfilesstatic->filename); - 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 - //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)) { - $urlforhref = DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.(!empty($object->entity) ? $object->entity : $conf->entity).'&file='.urlencode($relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension'])); - print ''; - } else { - print ''; - } - print ''; - print ''; - } else { - $modulepart = 'expensereport'; - $thumbshown = 0; - 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) - { - // 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. - { - 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 ($pdfexists && !$error) - { - $heightforphotref = 70; - if (!empty($conf->dol_optimize_smallscreen)) $heightforphotref = 60; - // If the preview file is found - if (file_exists($fileimage)) - { - $thumbshown = 1; - print ''; - } - } - } - - if (!$thumbshown) - { - print img_mime($ecmfilesstatic->filename); - } - } - } + $modulepart = 'expensereport'; + $maxheightmini = 32; + + $result = $ecmfilesstatic->fetch($line->fk_ecm_files); + if ($result > 0) + { + $relativepath = preg_replace('/expensereport\//', '', $ecmfilesstatic->filepath); + $fileinfo = pathinfo($ecmfilesstatic->filepath.'/'.$ecmfilesstatic->filename); + 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 + //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)) { + $urlforhref = DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.(!empty($object->entity) ? $object->entity : $conf->entity).'&file='.urlencode($relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension'])); + print ''; + } else { + print ''; + } + print ''; + print ''; + } + else + { + $modulepart = 'expensereport'; + $thumbshown = 0; + 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) + { + // 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. + { + 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 ($pdfexists && !$error) + { + $heightforphotref = 70; + if (!empty($conf->dol_optimize_smallscreen)) $heightforphotref = 60; + // If the preview file is found + if (file_exists($fileimage)) + { + $thumbshown = 1; + print ''; + } + } + } + + if (!$thumbshown) + { + print img_mime($ecmfilesstatic->filename); + } + } + } } print ''; // Ajout des boutons de modification/suppression - if (($object->status < ExpenseReport::STATUS_VALIDATED || $object->status == ExpenseReport::STATUS_REFUSED) && $user->rights->expensereport->creer) + if (($object->fk_statut < ExpenseReport::STATUS_VALIDATED || $object->fk_statut == ExpenseReport::STATUS_REFUSED) && $user->rights->expensereport->creer) { print ''; - print 'rowid.'">'; + print 'rowid.'">'; print img_edit(); print '   '; - print 'rowid.'">'; + print 'rowid.'">'; print img_delete(); print ''; @@ -2204,30 +2313,30 @@ 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++; - - print ''; - - print ''; - print $numline; - print ''; - - print ''; - 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)) - { - print '   -   '.$langs->trans("AttachTheNewLineToTheDocument"); - print img_picto($langs->trans("AttachTheNewLineToTheDocument"), 'chevron-down', '', false, 0, 0, '', 'marginleftonly'); - print ''; - } - - print ''."\n"; - print ''; - - $filenamelinked = ''; - if ($line->fk_ecm_files > 0) - { - $result = $ecmfilesstatic->fetch($line->fk_ecm_files); - if ($result > 0) - { - $filenamelinked = $ecmfilesstatic->filename; - } - } - - $tredited = 'tredited'; - include DOL_DOCUMENT_ROOT.'/expensereport/tpl/expensereport_addfile.tpl.php'; - include DOL_DOCUMENT_ROOT.'/expensereport/tpl/expensereport_linktofile.tpl.php'; + print ''."\n"; + print ''; + + $filenamelinked = ''; + if ($line->fk_ecm_files > 0) + { + $result = $ecmfilesstatic->fetch($line->fk_ecm_files); + if ($result > 0) + { + $filenamelinked = $ecmfilesstatic->filename; + } + } + + $tredited = 'tredited'; + include DOL_DOCUMENT_ROOT.'/expensereport/tpl/expensereport_addfile.tpl.php'; + include DOL_DOCUMENT_ROOT.'/expensereport/tpl/expensereport_linktofile.tpl.php'; print ''; @@ -2279,11 +2388,6 @@ print ''; } - // Select type - print ''; - print $formexpensereport->selectTypeExpenseReport($line->fk_c_type_fees, 'fk_c_type_fees'); - print ''; - if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) { print ''; @@ -2292,6 +2396,11 @@ print ''; } + // Select type + print ''; + select_type_fees_id($line->fk_c_type_fees, 'fk_c_type_fees'); + print ''; + // Add comments print ''; print ''; @@ -2327,8 +2436,8 @@ print ''; print ''; - print ''; - print '
'; + print ''; + print '
'; print ''; print ''; @@ -2338,44 +2447,44 @@ } } - // Add a new line - if (($object->status == ExpenseReport::STATUS_DRAFT || $object->status == ExpenseReport::STATUS_REFUSED) - && $action != 'editline' - && $user->rights->expensereport->creer) + // Add a line + if (($object->fk_statut == ExpenseReport::STATUS_DRAFT || $object->fk_statut == ExpenseReport::STATUS_REFUSED) + && $action != 'editline' + && $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++; - - $nbFiles = $nbLinks = 0; - $arrayoffiles = array(); - 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'; - $upload_dir = $conf->expensereport->dir_output."/".dol_sanitizeFileName($object->ref); - $arrayoffiles = dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png|'.preg_quote(dol_sanitizeFileName($object->ref.'.pdf'), '/').')$'); - $nbFiles = count($arrayoffiles); - $nbLinks = Link::count($db, $object->element, $object->id); - } - - // Add line with link to add new file or attach to an existing file - print ''; - print ''; - 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)) - { - print '   -   '.$langs->trans("AttachTheNewLineToTheDocument"); - print img_picto($langs->trans("AttachTheNewLineToTheDocument"), 'chevron-down', '', false, 0, 0, '', 'marginleftonly'); - print ''; - } - - print ''."\n"; - print ''; - - include DOL_DOCUMENT_ROOT.'/expensereport/tpl/expensereport_addfile.tpl.php'; - include DOL_DOCUMENT_ROOT.'/expensereport/tpl/expensereport_linktofile.tpl.php'; + print ''."\n"; + print ''; + + include DOL_DOCUMENT_ROOT.'/expensereport/tpl/expensereport_addfile.tpl.php'; + include DOL_DOCUMENT_ROOT.'/expensereport/tpl/expensereport_linktofile.tpl.php'; print ''; print ''; print ''.$langs->trans('Date').''; - if (!empty($conf->projet->enabled)) { - print ''.$form->textwithpicto($langs->trans('Project'), $langs->trans("ClosedProjectsAreHidden")).''; - } + if (!empty($conf->projet->enabled)) print ''.$form->textwithpicto($langs->trans('Project'), $langs->trans("ClosedProjectsAreHidden")).''; + if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) print ''.$langs->trans('CarCategory').''; print ''.$langs->trans('Type').''; - if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) { - print ''.$langs->trans('CarCategory').''; - } print ''.$langs->trans('Description').''; print ''.$langs->trans('VAT').''; print ''.$langs->trans('PriceUHT').''; @@ -2438,18 +2543,18 @@ print ''; } - // Select type - print ''; - print $formexpensereport->selectTypeExpenseReport($fk_c_type_fees, 'fk_c_type_fees', 1); - print ''; - if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) { 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); + print $form->selectExpenseCategories('', 'fk_c_exp_tax_cat', 1, array(), 'fk_c_type_fees', $userauthor->default_c_exp_tax_cat, $params); print ''; } + + // Select type + print ''; + select_type_fees_id($fk_c_type_fees, 'fk_c_type_fees', 1); + print ''; // Add comments print ''; @@ -2517,10 +2622,11 @@ print '
'; - print dol_get_fiche_end(); + dol_fiche_end(); } // end edit or not edit } // end of if result - else { + else + { dol_print_error($db); } } //fin si id > 0 @@ -2539,7 +2645,7 @@ // Send if (empty($user->socid)) { - if ($object->status > ExpenseReport::STATUS_DRAFT) { + if ($object->fk_statut > ExpenseReport::STATUS_DRAFT) { //if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->expensereport->expensereport_advance->send)) { print ''; //} else @@ -2552,7 +2658,7 @@ * ET fk_user_author == user courant * Afficher : "Enregistrer" / "Modifier" / "Supprimer" */ - if ($user->rights->expensereport->creer && $object->status == ExpenseReport::STATUS_DRAFT) + if ($user->rights->expensereport->creer && $object->fk_statut == ExpenseReport::STATUS_DRAFT) { if (in_array($object->fk_user_author, $user->getAllChildIds(1)) || !empty($user->rights->expensereport->writeall_advance)) { @@ -2572,7 +2678,7 @@ * ET fk_user_author == user courant * Afficher : "Enregistrer" / "Modifier" / "Supprimer" */ - if ($user->rights->expensereport->creer && $object->status == ExpenseReport::STATUS_REFUSED) + if ($user->rights->expensereport->creer && $object->fk_statut == ExpenseReport::STATUS_REFUSED) { if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) { @@ -2586,12 +2692,12 @@ } } - if ($user->rights->expensereport->to_paid && $object->status == ExpenseReport::STATUS_APPROVED) + if ($user->rights->expensereport->to_paid && $object->fk_statut == ExpenseReport::STATUS_APPROVED) { if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) { // setdraft - print ''; + print ''; } } @@ -2600,16 +2706,16 @@ * ET fk_user_validator == user courant * Afficher : "Valider" / "Refuser" / "Supprimer" */ - if ($object->status == ExpenseReport::STATUS_VALIDATED) + if ($object->fk_statut == ExpenseReport::STATUS_VALIDATED) { if (in_array($object->fk_user_author, $user->getAllChildIds(1))) { // set draft - print ''; + print ''; } } - if ($user->rights->expensereport->approve && $object->status == ExpenseReport::STATUS_VALIDATED) + if ($user->rights->expensereport->approve && $object->fk_statut == ExpenseReport::STATUS_VALIDATED) { //if($object->fk_user_validator==$user->id) //{ @@ -2622,7 +2728,7 @@ if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) { // Cancel - print ''; + print ''; } } @@ -2630,66 +2736,69 @@ // If status is Approved // --------------------- - if ($user->rights->expensereport->approve && $object->status == ExpenseReport::STATUS_APPROVED) + if ($user->rights->expensereport->approve && $object->fk_statut == ExpenseReport::STATUS_APPROVED) { - print ''; + 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->fk_statut == ExpenseReport::STATUS_APPROVED) { // Pay if ($remaintopay == 0) { print '
'.$langs->trans('DoPayment').'
'; - } else { + } + else + { print ''; } } // 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->fk_statut == ExpenseReport::STATUS_APPROVED) { //if ((round($remaintopay) == 0 || empty($conf->banque->enabled)) && $object->paid == 0) if ($object->paid == 0) { - print '"; + print '"; } } - if ($user->rights->expensereport->creer && ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) && $object->status == ExpenseReport::STATUS_APPROVED) + if ($user->rights->expensereport->creer && ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) && $object->fk_statut == ExpenseReport::STATUS_APPROVED) { - // Cancel - print ''; + // 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) + // TODO Replace this. It should be SetUnpaid and should go back to status unpaid not canceled. + if (($user->rights->expensereport->approve || $user->rights->expensereport->to_paid) && $object->fk_statut == ExpenseReport::STATUS_CLOSED) { - // Cancel - print ''; + // Cancel + print ''; } - if ($user->rights->expensereport->to_paid && $object->paid && $object->status == ExpenseReport::STATUS_CLOSED) + if ($user->rights->expensereport->to_paid && $object->paid && $object->fk_statut == ExpenseReport::STATUS_CLOSED) { // Set unpaid - print ''; + print ''; } // Clone if ($user->rights->expensereport->creer) { - print ''; + print ''; } /* 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->fk_statut < ExpenseReport::STATUS_APPROVED) { - // Delete - print ''; - } elseif ($user->rights->expensereport->supprimer && $object->status != ExpenseReport::STATUS_CLOSED) + // Delete + print ''; + } + elseif ($user->rights->expensereport->supprimer && $object->fk_statut != ExpenseReport::STATUS_CLOSED) { - // Delete - print ''; + // Delete + print ''; } $parameters = array(); --- /tmp/dsg/dolibarr/htdocs/expensereport/github_document.php +++ /tmp/dsg/dolibarr/htdocs/expensereport/client_document.php @@ -39,10 +39,8 @@ $id = GETPOST('id', 'int'); $ref = GETPOST('ref', 'alpha'); -$action = GETPOST('action', 'aZ09'); +$action = GETPOST('action', 'alpha'); $confirm = GETPOST('confirm', 'alpha'); - -$childids = $user->getAllChildIds(1); // Security check if ($user->socid) $socid = $user->socid; @@ -51,8 +49,8 @@ // Get parameters $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST('sortfield', 'aZ09comma'); -$sortorder = GETPOST('sortorder', 'aZ09comma'); +$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 $offset = $limit * $page; @@ -63,28 +61,13 @@ $object = new ExpenseReport($db); -if (!$object->fetch($id, $ref) > 0) -{ - dol_print_error($db); -} +$object->fetch($id, $ref); $upload_dir = $conf->expensereport->dir_output.'/'.dol_sanitizeFileName($object->ref); $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) -{ - // 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) - { - accessforbidden(); - } -} /* @@ -110,7 +93,7 @@ $head = expensereport_prepare_head($object); - print dol_get_fiche_head($head, 'documents', $langs->trans("ExpenseReport"), -1, 'trip'); + dol_fiche_head($head, 'documents', $langs->trans("ExpenseReport"), -1, 'trip'); $linkback = ''.$langs->trans("BackToList").''; @@ -132,25 +115,27 @@ print '
'; print '
'; - print ''; + print '
'; - $linkback = ''.$langs->trans("BackToList").''; + $linkback = ''.$langs->trans("BackToList").''; - print ''; - print ''; - print '
'.$langs->trans("NbOfAttachedFiles").''.count($filearray).'
'.$langs->trans("TotalSizeOfAttachedFiles").''.dol_print_size($totalsize, 1, 1).'
'; + print ''.$langs->trans("NbOfAttachedFiles").''.count($filearray).''; + print ''.$langs->trans("TotalSizeOfAttachedFiles").''.dol_print_size($totalsize, 1, 1).''; + print ''; - print '
'; + print ''; - print dol_get_fiche_end(); + dol_fiche_end(); - $modulepart = 'expensereport'; - $permission = $user->rights->expensereport->creer; - $permtoedit = $user->rights->expensereport->creer; - $param = '&id='.$object->id; - include_once DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php'; -} else { + $modulepart = 'expensereport'; + $permission = $user->rights->expensereport->creer; + $permtoedit = $user->rights->expensereport->creer; + $param = '&id='.$object->id; + include_once DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php'; +} +else +{ print $langs->trans("ErrorUnknown"); } --- /tmp/dsg/dolibarr/htdocs/expensereport/github_index.php +++ /tmp/dsg/dolibarr/htdocs/expensereport/client_index.php @@ -80,11 +80,11 @@ $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))) -{ - $childids = $user->getAllChildIds(); - $childids[] = $user->id; - $sql .= " AND d.fk_user_author IN (".join(',', $childids).")\n"; + && (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 .= " GROUP BY tf.code, tf.label"; @@ -92,22 +92,22 @@ $result = $db->query($sql); if ($result) { - $num = $db->num_rows($result); - $i = 0; - while ($i < $num) - { - $objp = $db->fetch_object($result); - - $somme[$objp->code] = $objp->km; - $nb[$objp->code] = $objp->nb; - $label[$objp->code] = $objp->label; - $totalnb += $objp->nb; - $totalsum += $objp->km; - $i++; - } - $db->free($result); + $num = $db->num_rows($result); + $i = 0; + while ($i < $num) + { + $objp = $db->fetch_object($result); + + $somme[$objp->code] = $objp->km; + $nb[$objp->code] = $objp->nb; + $label[$objp->code] = $objp->label; + $totalnb += $objp->nb; + $totalsum += $objp->km; + $i++; + } + $db->free($result); } else { - dol_print_error($db); + dol_print_error($db); } @@ -125,26 +125,26 @@ $listoftype = $tripandexpense_static->listOfTypes(); foreach ($listoftype as $code => $label) { - $dataseries[] = array($label, (isset($somme[$code]) ? (int) $somme[$code] : 0)); + $dataseries[] = array($label, (isset($somme[$code]) ? (int) $somme[$code] : 0)); } if ($conf->use_javascript_ajax) { - print ''; - - include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php'; - $dolgraph = new DolGraph(); - $dolgraph->SetData($dataseries); - $dolgraph->setHeight(350); - $dolgraph->combine = empty($conf->global->MAIN_EXPENSEREPORT_COMBINE_GRAPH_STAT) ? 0.05 : $conf->global->MAIN_EXPENSEREPORT_COMBINE_GRAPH_STAT; - $dolgraph->setShowLegend(2); - $dolgraph->setShowPercent(1); - $dolgraph->SetType(array('pie')); - $dolgraph->setHeight('200'); - $dolgraph->draw('idgraphstatus'); - print $dolgraph->show($totalnb ? 0 : 1); - - print ''; + print ''; + + include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php'; + $dolgraph = new DolGraph(); + $dolgraph->SetData($dataseries); + $dolgraph->setHeight(350); + $dolgraph->combine = empty($conf->global->MAIN_EXPENSEREPORT_COMBINE_GRAPH_STAT) ? 0.05 : $conf->global->MAIN_EXPENSEREPORT_COMBINE_GRAPH_STAT; + $dolgraph->setShowLegend(2); + $dolgraph->setShowPercent(1); + $dolgraph->SetType(array('pie')); + $dolgraph->setHeight('200'); + $dolgraph->draw('idgraphstatus'); + print $dolgraph->show($totalnb ? 0 : 1); + + print ''; } print ''; @@ -165,18 +165,18 @@ $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 = "SELECT u.rowid as uid, u.lastname, u.firstname, u.login, u.statut, 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 fk_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"; $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))) -{ - $childids = $user->getAllChildIds(); - $childids[] = $user->id; - $sql .= " AND d.fk_user_author IN (".join(',', $childids).")\n"; + && (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; @@ -187,61 +187,60 @@ $result = $db->query($sql); if ($result) { - $var = false; - $num = $db->num_rows($result); - - $i = 0; + $var = false; + $num = $db->num_rows($result); + + $i = 0; print '
'; print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - if ($num) - { - $total_ttc = $totalam = $total = 0; - - $expensereportstatic = new ExpenseReport($db); - $userstatic = new User($db); - while ($i < $num && $i < $max) - { - $obj = $db->fetch_object($result); - - $expensereportstatic->id = $obj->rowid; - $expensereportstatic->ref = $obj->ref; - $expensereportstatic->status = $obj->status; - - $userstatic->id = $obj->uid; - $userstatic->admin = $obj->admin; - $userstatic->email = $obj->email; - $userstatic->lastname = $obj->lastname; - $userstatic->firstname = $obj->firstname; - $userstatic->login = $obj->login; - $userstatic->statut = $obj->user_status; - $userstatic->photo = $obj->photo; - - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - $i++; - } - } else { - print ''; - } - print '
'.$langs->trans("BoxTitleLastModifiedExpenses", min($max, $num)).''.$langs->trans("AmountHT").''.$langs->trans("AmountTTC").''.$langs->trans("DateModificationShort").' 
'.$expensereportstatic->getNomUrl(1).''.$userstatic->getNomUrl(-1).''.price($obj->total_ht).''.price($obj->total_ttc).''.dol_print_date($db->jdate($obj->dm), 'day').''; - print $expensereportstatic->getLibStatut(3); - print '
'.$langs->trans("None").'

'; -} else dol_print_error($db); + print ''; + print ''.$langs->trans("BoxTitleLastModifiedExpenses", min($max, $num)).''; + print ''.$langs->trans("AmountHT").''; + print ''.$langs->trans("AmountTTC").''; + print ''.$langs->trans("DateModificationShort").''; + print ' '; + print ''; + if ($num) + { + $total_ttc = $totalam = $total = 0; + + $expensereportstatic = new ExpenseReport($db); + $userstatic = new User($db); + while ($i < $num && $i < $max) + { + $obj = $db->fetch_object($result); + $expensereportstatic->id = $obj->rowid; + $expensereportstatic->ref = $obj->ref; + $userstatic->id = $obj->uid; + $userstatic->admin = $obj->admin; + $userstatic->email = $obj->email; + $userstatic->lastname = $obj->lastname; + $userstatic->firstname = $obj->firstname; + $userstatic->login = $obj->login; + $userstatic->statut = $obj->statut; + $userstatic->photo = $obj->photo; + print ''; + print ''.$expensereportstatic->getNomUrl(1).''; + print ''.$userstatic->getNomUrl(-1).''; + print ''.price($obj->total_ht).''; + print ''.price($obj->total_ttc).''; + print ''.dol_print_date($db->jdate($obj->dm), 'day').''; + print ''; + print $expensereportstatic->LibStatut($obj->fk_status, 3); + print ''; + print ''; + + $i++; + } + } + else + { + print ''.$langs->trans("None").''; + } + print '
'; +} +else dol_print_error($db); print ''; --- /tmp/dsg/dolibarr/htdocs/expensereport/github_info.php +++ /tmp/dsg/dolibarr/htdocs/expensereport/client_info.php @@ -31,32 +31,10 @@ // Load translation files required by the page $langs->load("trips"); +// Security check $id = GETPOST('id', 'int'); -$ref = GETPOST('ref', 'alpha'); - -$childids = $user->getAllChildIds(1); - -// Security check if ($user->socid) $socid = $user->socid; $result = restrictedArea($user, 'expensereport', $id, 'expensereport'); - -$object = new ExpenseReport($db); -if (!$object->fetch($id, $ref) > 0) -{ - dol_print_error($db); -} - -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) - { - accessforbidden(); - } -} /* @@ -77,7 +55,7 @@ $head = expensereport_prepare_head($object); - print dol_get_fiche_head($head, 'info', $langs->trans("ExpenseReport"), -1, 'trip'); + dol_fiche_head($head, 'info', $langs->trans("ExpenseReport"), -1, 'trip'); $linkback = ''.$langs->trans("BackToList").''; @@ -98,7 +76,7 @@ print ''; - print dol_get_fiche_end(); + dol_fiche_end(); } // End of page --- /tmp/dsg/dolibarr/htdocs/expensereport/github_list.php +++ /tmp/dsg/dolibarr/htdocs/expensereport/client_list.php @@ -35,7 +35,6 @@ require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; -require_once DOL_DOCUMENT_ROOT.'/core/class/html.formexpensereport.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php'; require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport_ik.class.php'; @@ -60,14 +59,14 @@ // If we are on the view of a specific user 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) - { - accessforbidden(); - } + $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) + { + accessforbidden(); + } } $diroutputmassaction = $conf->expensereport->dir_output.'/temp/massgeneration/'.$user->id; @@ -75,8 +74,8 @@ // Load variable for pagination $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST('sortfield', 'aZ09comma'); -$sortorder = GETPOST('sortorder', 'aZ09comma'); +$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 $offset = $limit * $page; @@ -110,37 +109,44 @@ $extrafields = new ExtraFields($db); // fetch optionals attributes and labels -$extrafields->fetch_name_optionals_label($object->table_element); +$extrafields->fetch_name_optionals_label('expensereport'); $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); // List of fields to search into when doing a "search in all" $fieldstosearchall = array( - 'd.ref'=>'Ref', - 'd.note_public'=>"NotePublic", - 'u.lastname'=>'Lastname', - 'u.firstname'=>"Firstname", - 'u.login'=>"Login", + 'd.ref'=>'Ref', + 'd.note_public'=>"NotePublic", + 'u.lastname'=>'Lastname', + 'u.firstname'=>"Firstname", + 'u.login'=>"Login", ); if (empty($user->socid)) $fieldstosearchall["d.note_private"] = "NotePrivate"; $arrayfields = array( - 'd.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1), - 'user'=>array('label'=>$langs->trans("User"), 'checked'=>1), - 'd.date_debut'=>array('label'=>$langs->trans("DateStart"), 'checked'=>1), - 'd.date_fin'=>array('label'=>$langs->trans("DateEnd"), 'checked'=>1), - 'd.date_valid'=>array('label'=>$langs->trans("DateValidation"), 'checked'=>1), - 'd.date_approve'=>array('label'=>$langs->trans("DateApprove"), 'checked'=>1), - 'd.total_ht'=>array('label'=>$langs->trans("AmountHT"), 'checked'=>1), - 'd.total_vat'=>array('label'=>$langs->trans("AmountVAT"), 'checked'=>1), - 'd.total_ttc'=>array('label'=>$langs->trans("AmountTTC"), 'checked'=>1), - 'd.date_create'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500), - 'd.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500), - 'd.fk_statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000), + 'd.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1), + 'user'=>array('label'=>$langs->trans("User"), 'checked'=>1), + 'd.date_debut'=>array('label'=>$langs->trans("DateStart"), 'checked'=>1), + 'd.date_fin'=>array('label'=>$langs->trans("DateEnd"), 'checked'=>1), + 'd.date_valid'=>array('label'=>$langs->trans("DateValidation"), 'checked'=>1), + 'd.date_approve'=>array('label'=>$langs->trans("DateApprove"), 'checked'=>1), + 'd.total_ht'=>array('label'=>$langs->trans("AmountHT"), 'checked'=>1), + 'd.total_vat'=>array('label'=>$langs->trans("AmountVAT"), 'checked'=>1), + 'd.total_ttc'=>array('label'=>$langs->trans("AmountTTC"), 'checked'=>1), + 'd.date_create'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500), + 'd.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500), + 'd.fk_statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000), ); // Extra fields -include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php'; +if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label']) > 0) +{ + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) + { + if (!empty($extrafields->attributes[$object->table_element]['list'][$key])) + $arrayfields["ef.".$key] = array('label'=>$extrafields->attributes[$object->table_element]['label'][$key], 'checked'=>(($extrafields->attributes[$object->table_element]['list'][$key] < 0) ? 0 : 1), 'position'=>$extrafields->attributes[$object->table_element]['pos'][$key], 'enabled'=>(abs($extrafields->attributes[$object->table_element]['list'][$key]) != 3 && $extrafields->attributes[$object->table_element]['perms'][$key])); + } +} $canedituser = (!empty($user->admin) || $user->rights->user->user->creer); @@ -166,19 +172,19 @@ // 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 { - $search_ref = ""; - $search_user = ""; - $search_amount_ht = ""; - $search_amount_vat = ""; - $search_amount_ttc = ""; - $search_status = ""; - $month_start = ""; - $year_start = ""; - $month_end = ""; - $year_end = ""; - $day_end = ""; - $toselect = ''; - $search_array_options = array(); + $search_ref = ""; + $search_user = ""; + $search_amount_ht = ""; + $search_amount_vat = ""; + $search_amount_ttc = ""; + $search_status = ""; + $month_start = ""; + $year_start = ""; + $month_end = ""; + $year_end = ""; + $day_end = ""; + $toselect = ''; + $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')) @@ -187,12 +193,57 @@ } // Mass actions - $objectclass = 'ExpenseReport'; - $objectlabel = 'ExpenseReport'; - $permissiontoread = $user->rights->expensereport->lire; - $permissiontodelete = $user->rights->expensereport->supprimer; - $uploaddir = $conf->expensereport->dir_output; - include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; + $objectclass = 'ExpenseReport'; + $objectlabel = 'ExpenseReport'; + $permissiontoread = $user->rights->expensereport->lire; + $permissiontodelete = $user->rights->expensereport->supprimer; + $uploaddir = $conf->expensereport->dir_output; + include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; + + if ($action == 'update' && !$cancel) + { + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + + if ($canedituser) // Case we can edit all field + { + $error = 0; + + if (!$error) + { + $objectuser->fetch($id); + + $objectuser->oldcopy = clone $objectuser; + + $db->begin(); + + $objectuser->default_range = GETPOST('default_range'); + $objectuser->default_c_exp_tax_cat = GETPOST('default_c_exp_tax_cat'); + + if (!$error) { + $ret = $objectuser->update($user); + if ($ret < 0) { + $error++; + if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') { + $langs->load("errors"); + setEventMessages($langs->trans("ErrorLoginAlreadyExists", $objectuser->login), null, 'errors'); + } + else + { + setEventMessages($objectuser->error, $objectuser->errors, 'errors'); + } + } + } + + if (!$error && !count($objectuser->errors)) { + setEventMessages($langs->trans("UserModified"), null, 'mesgs'); + $db->commit(); + } + else { + $db->rollback(); + } + } + } + } } @@ -203,7 +254,6 @@ $form = new Form($db); $formother = new FormOther($db); $formfile = new FormFile($db); -$formexpensereport = new FormExpenseReport($db); $fuser = new User($db); @@ -255,10 +305,10 @@ // 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->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"; } @@ -275,13 +325,13 @@ $nbtotalofrecords = ''; 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 - { - $page = 0; - $offset = 0; - } + $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 + { + $page = 0; + $offset = 0; + } } $sql .= $db->plimit($limit + 1, $offset); @@ -295,7 +345,7 @@ $arrayofselected = is_array($toselect) ? $toselect : array(); $param = ''; - if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage); + 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); @@ -310,8 +360,8 @@ // List of mass actions available $arrayofmassactions = array( 'generate_doc'=>$langs->trans("ReGeneratePDF"), - 'builddoc'=>$langs->trans("PDFMerge"), - 'presend'=>$langs->trans("SendByMail"), + '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(); @@ -319,12 +369,12 @@ // Lines of title fields print '
'."\n"; - if ($optioncss != '') print ''; + if ($optioncss != '') print ''; print ''; print ''; print ''; print ''; - print ''; + print ''; print ''; if ($id > 0) print ''; @@ -334,40 +384,97 @@ $linkback = ''.$langs->trans("BackToList").''; $head = user_prepare_head($fuser); - print dol_get_fiche_head($head, 'expensereport', $title, -1, 'user'); + dol_fiche_head($head, 'expensereport', $title, -1, 'user'); dol_banner_tab($fuser, 'id', $linkback, $user->rights->user->user->lire || $user->admin); - print dol_get_fiche_end(); + print '
'; + print '
'; + + if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) + { + print ''; + + if ($action == 'edit') + { + print ''; + print ''; + + print ''; + print ''; + } + else + { + print ''; + print ''; + + print ''; + print ''; + } + + print '
'.$langs->trans("DefaultCategoryCar").''; + print $form->selectExpenseCategories($fuser->default_c_exp_tax_cat, 'default_c_exp_tax_cat', 1); + print '
'.$langs->trans("DefaultRangeNumber").''; + $maxRangeNum = ExpenseReportIk::getMaxRangeNumber($fuser->default_c_exp_tax_cat); + print $form->selectarray('default_range', range(0, $maxRangeNum), $fuser->default_range); + print '
'.$langs->trans("DefaultCategoryCar").''; + print dol_getIdFromCode($db, $fuser->default_c_exp_tax_cat, 'c_exp_tax_cat', 'rowid', 'label'); + print '
'.$langs->trans("DefaultRangeNumber").''; + print $fuser->default_range; + print '
'; + } + + print '
'; + + /*if (empty($conf->global->HOLIDAY_HIDE_BALANCE)) + { + print '
'; + + print '
'; + + showMyBalance($holiday, $user_id); + }*/ + + dol_fiche_end(); if ($action != 'edit') { print '
'; + if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) + { + print ''.$langs->trans("Modify").''; + } + $childids = $user->getAllChildIds(1); $canedit = ((in_array($user_id, $childids) && $user->rights->expensereport->creer) || ($conf->global->MAIN_USE_ADVANCED_PERMS && $user->rights->expensereport->writeall_advance)); // Buttons for actions - if ($canedit) { + if ($canedit) + { print ''.$langs->trans("AddTrip").''; - } else { - print ''.$langs->trans("AddTrip").''; } print '
'; - } else { + } + else + { print '
'; - print ''; + print ''; print '

'; } - } else { + } + else + { $title = $langs->trans("ListTripsAndExpenses"); - $url = DOL_URL_ROOT.'/expensereport/card.php?action=create'; - if (!empty($socid)) $url .= '&socid='.$socid; - $newcardbutton = dolGetButtonTitle($langs->trans('NewTrip'), '', 'fa fa-plus-circle', $url, '', $user->rights->expensereport->creer); + $newcardbutton = ''; + if ($user->rights->expensereport->creer) + { + $newcardbutton .= dolGetButtonTitle($langs->trans('NewTrip'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/expensereport/card.php?action=create'); + } print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'trip', 0, $newcardbutton, '', $limit, 0, 0, 1); } @@ -379,10 +486,10 @@ include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php'; if ($sall) - { - foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val); - print '
'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'
'; - } + { + foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val); + print '
'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'
'; + } $moreforfilter = ''; @@ -393,90 +500,90 @@ if (!empty($moreforfilter)) { - print '
'; - print $moreforfilter; - print '
'; + print '
'; + print $moreforfilter; + print '
'; } $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage; $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : ''); - print '
'; + print '
'; print ''."\n"; // Filters print ''; if (!empty($arrayfields['d.ref']['checked'])) { - print ''; + print ''; } // User if (!empty($arrayfields['user']['checked'])) { - if ($user->rights->expensereport->readall || $user->rights->expensereport->lire_tous) - { - print ''; - } else { - print ''; - } + if ($user->rights->expensereport->readall || $user->rights->expensereport->lire_tous) + { + print ''; + } else { + print ''; + } } // Date start if (!empty($arrayfields['d.date_debut']['checked'])) { - print ''; + print ''; } // Date end if (!empty($arrayfields['d.date_fin']['checked'])) { - print ''; - } + $formother->select_year($year_end, 'year_end', 1, $min_year, $max_year); + print ''; + } // Date valid if (!empty($arrayfields['d.date_valid']['checked'])) { - print ''; - } + print ''; + } // Date approve if (!empty($arrayfields['d.date_approve']['checked'])) { - print ''; - } - // Amount with no tax + print ''; + } + // Amount with no tax if (!empty($arrayfields['d.total_ht']['checked'])) { - print ''; + print ''; } if (!empty($arrayfields['d.total_vat']['checked'])) { - print ''; + print ''; } // Amount with all taxes if (!empty($arrayfields['d.total_ttc']['checked'])) { - print ''; + print ''; } // Extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php'; @@ -488,21 +595,21 @@ // Date creation if (!empty($arrayfields['d.date_create']['checked'])) { - print ''; + print ''; } // Date modification if (!empty($arrayfields['d.tms']['checked'])) { - print ''; + print ''; } // Status if (!empty($arrayfields['d.fk_statut']['checked'])) { - print ''; + print ''; } // Action column print ''; // Ref if (!empty($arrayfields['d.ref']['checked'])) { - print ''; - if (!$i) $totalarray['nbfield']++; + print ''; + if (!$i) $totalarray['nbfield']++; } // User if (!empty($arrayfields['user']['checked'])) { - print ''; - if (!$i) $totalarray['nbfield']++; + print ''; + if (!$i) $totalarray['nbfield']++; } // Start date if (!empty($arrayfields['d.date_debut']['checked'])) { - print ''; - if (!$i) $totalarray['nbfield']++; - } - // End date + print ''; + if (!$i) $totalarray['nbfield']++; + } + // End date if (!empty($arrayfields['d.date_fin']['checked'])) { - print ''; - if (!$i) $totalarray['nbfield']++; + print ''; + if (!$i) $totalarray['nbfield']++; } // Date validation if (!empty($arrayfields['d.date_valid']['checked'])) { - print ''; - if (!$i) $totalarray['nbfield']++; + print ''; + if (!$i) $totalarray['nbfield']++; } // Date approval if (!empty($arrayfields['d.date_approve']['checked'])) { - print ''; - if (!$i) $totalarray['nbfield']++; + print ''; + if (!$i) $totalarray['nbfield']++; } // Amount HT - if (!empty($arrayfields['d.total_ht']['checked'])) - { - print '\n"; - 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'])) - { - print '\n"; - 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'])) - { - print '\n"; - if (!$i) $totalarray['nbfield']++; - if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'd.total_ttc'; - $totalarray['val']['d.total_ttc'] += $obj->total_ttc; - } - - // Extra fields - include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php'; - // Fields from hook - $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray); - $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook - print $hookmanager->resPrint; - - // Date creation - if (!empty($arrayfields['d.date_create']['checked'])) - { - print ''; - if (!$i) $totalarray['nbfield']++; - } - // Date modification - if (!empty($arrayfields['d.tms']['checked'])) - { - print ''; - if (!$i) $totalarray['nbfield']++; - } - // Status - if (!empty($arrayfields['d.fk_statut']['checked'])) - { - print ''; - if (!$i) $totalarray['nbfield']++; - } - // Action column - print ''; - if (!$i) $totalarray['nbfield']++; + if (!empty($arrayfields['d.total_ht']['checked'])) + { + print '\n"; + 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'])) + { + print '\n"; + 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'])) + { + print '\n"; + if (!$i) $totalarray['nbfield']++; + if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'd.total_ttc'; + $totalarray['val']['d.total_ttc'] += $obj->total_ttc; + } + + // Extra fields + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php'; + // Fields from hook + $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray); + $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + + // Date creation + if (!empty($arrayfields['d.date_create']['checked'])) + { + print ''; + if (!$i) $totalarray['nbfield']++; + } + // Date modification + if (!empty($arrayfields['d.tms']['checked'])) + { + print ''; + if (!$i) $totalarray['nbfield']++; + } + // Status + if (!empty($arrayfields['d.fk_statut']['checked'])) + { + print ''; + if (!$i) $totalarray['nbfield']++; + } + // Action column + print ''; + if (!$i) $totalarray['nbfield']++; print "\n"; @@ -698,7 +805,9 @@ $i++; } - } else { + } + else + { $colspan = 1; foreach ($arrayfields as $key => $val) { if (!empty($val['checked'])) $colspan++; } print ''; @@ -714,7 +823,7 @@ print $hookmanager->resPrint; print '
'; - print ''; - print ''; + print ''; + print ''; - print $form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200'); - print ' '; + print $form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200'); + print ' '; - if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) { - print ''; - } - - print ''; - $formother->select_year($year_start, 'year_start', 1, $min_year, $max_year); - print ''; + if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) { + print ''; + } + + print ''; + $formother->select_year($year_start, 'year_start', 1, $min_year, $max_year); + print ''; + print ''; if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) { print ''; } print ''; - $formother->select_year($year_end, 'year_end', 1, $min_year, $max_year); - print ''; - //print ''; - //$formother->select_year($year_end,'year_end',1, $min_year, $max_year); - print ''; + //print ''; + //$formother->select_year($year_end,'year_end',1, $min_year, $max_year); + print ''; - //print ''; - //$formother->select_year($year_end,'year_end',1, $min_year, $max_year); - print ''; + //print ''; + //$formother->select_year($year_end,'year_end',1, $min_year, $max_year); + print ''; - print ''; + print ''; - print ''; + print ''; - $formexpensereport->selectExpensereportStatus($search_status, 'search_status', 1, 1); - print ''; + select_expensereport_statut($search_status, 'search_status', 1, 1); + print ''; @@ -543,9 +650,9 @@ if ($num > 0) { - $i = 0; - $totalarray = array(); - while ($i < min($num, $limit)) + $i = 0; + $totalarray = array(); + while ($i < min($num, $limit)) { $obj = $db->fetch_object($resql); @@ -565,130 +672,130 @@ print '
'; - print ''; - print ''; - // Warning late icon and note - print ''; - print ''; - print '
'; - print $expensereportstatic->getNomUrl(1); - 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)) - { - print ' '; - print ''.img_picto($langs->trans("ViewPrivateNote"), 'object_generic').''; - print ''; - } - print ''; - $filename = dol_sanitizeFileName($obj->ref); - $filedir = $conf->expensereport->dir_output.'/'.dol_sanitizeFileName($obj->ref); - $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid; - print $formfile->getDocumentsLink($expensereportstatic->element, $filename, $filedir); - print '
'; - print '
'; + print ''; + print ''; + // Warning late icon and note + print ''; + print ''; + print '
'; + print $expensereportstatic->getNomUrl(1); + 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)) + { + print ' '; + print ''.img_picto($langs->trans("ViewPrivateNote"), 'object_generic').''; + print ''; + } + print ''; + $filename = dol_sanitizeFileName($obj->ref); + $filedir = $conf->expensereport->dir_output.'/'.dol_sanitizeFileName($obj->ref); + $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid; + print $formfile->getDocumentsLink($expensereportstatic->element, $filename, $filedir); + print '
'; + print '
'; - $usertmp->id = $obj->id_user; - $usertmp->lastname = $obj->lastname; - $usertmp->firstname = $obj->firstname; - $usertmp->login = $obj->login; - $usertmp->statut = $obj->statut; - $usertmp->photo = $obj->photo; - $usertmp->email = $obj->email; - print $usertmp->getNomUrl(-1); - print ''; + $usertmp->id = $obj->id_user; + $usertmp->lastname = $obj->lastname; + $usertmp->firstname = $obj->firstname; + $usertmp->login = $obj->login; + $usertmp->statut = $obj->statut; + $usertmp->photo = $obj->photo; + $usertmp->email = $obj->email; + print $usertmp->getNomUrl(-1); + print ''.($obj->date_debut > 0 ? dol_print_date($db->jdate($obj->date_debut), 'day') : '').''.($obj->date_debut > 0 ? dol_print_date($db->jdate($obj->date_debut), 'day') : '').''.($obj->date_fin > 0 ? dol_print_date($db->jdate($obj->date_fin), 'day') : '').''.($obj->date_fin > 0 ? dol_print_date($db->jdate($obj->date_fin), 'day') : '').''.($obj->date_valid > 0 ? dol_print_date($db->jdate($obj->date_valid), 'day') : '').''.($obj->date_valid > 0 ? dol_print_date($db->jdate($obj->date_valid), 'day') : '').''.($obj->date_approve > 0 ? dol_print_date($db->jdate($obj->date_approve), 'day') : '').''.($obj->date_approve > 0 ? dol_print_date($db->jdate($obj->date_approve), 'day') : '').''.price($obj->total_ht)."'.price($obj->total_tva)."'.price($obj->total_ttc)."'; - print dol_print_date($db->jdate($obj->date_create), 'dayhour'); - print ''; - print dol_print_date($db->jdate($obj->date_modif), 'dayhour'); - print ''.$expensereportstatic->getLibStatut(5).''; - 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; - print ''; - } - print ''.price($obj->total_ht)."'.price($obj->total_tva)."'.price($obj->total_ttc)."'; + print dol_print_date($db->jdate($obj->date_create), 'dayhour'); + print ''; + print dol_print_date($db->jdate($obj->date_modif), 'dayhour'); + print ''.$expensereportstatic->getLibStatut(5).''; + 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; + print ''; + } + print '
'.$langs->trans("NoRecordFound").'
'."\n"; - print '
'; + print '
'; print '
'."\n"; @@ -733,7 +842,9 @@ print $formfile->showdocuments('massfilesarea_expensereport', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty); } -} else { +} +else +{ dol_print_error($db); } --- /tmp/dsg/dolibarr/htdocs/expensereport/github_note.php +++ /tmp/dsg/dolibarr/htdocs/expensereport/client_note.php @@ -35,9 +35,7 @@ $id = GETPOST('id', 'int'); $ref = GETPOST('ref', 'alpha'); $socid = GETPOST('socid', 'int'); -$action = GETPOST('action', 'aZ09'); - -$childids = $user->getAllChildIds(1); +$action = GETPOST('action', 'alpha'); // Security check $socid = 0; @@ -52,18 +50,6 @@ } $permissionnote = $user->rights->expensereport->creer; // Used by the include of actions_setnotes.inc.php - -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) - { - accessforbidden(); - } -} /* @@ -90,7 +76,7 @@ $head = expensereport_prepare_head($object); - print dol_get_fiche_head($head, 'note', $langs->trans("ExpenseReport"), -1, 'trip'); + dol_fiche_head($head, 'note', $langs->trans("ExpenseReport"), -1, 'trip'); $linkback = ''.$langs->trans("BackToList").''; @@ -108,7 +94,7 @@ print ''; - print dol_get_fiche_end(); + dol_fiche_end(); } // End of page