12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405 |
- <?php
- /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
- * Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
- * Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
- * Copyright (C) 2015-2017 Alexandre Spangaro <aspangaro@zendsi.com>
- * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- /**
- * \file htdocs/expensereport/card.php
- * \ingroup expensereport
- * \brief Page for trip and expense report card
- */
- $res=0;
- require '../main.inc.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 . '/projet/class/project.class.php';
- require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php';
- require_once DOL_DOCUMENT_ROOT . '/core/lib/expensereport.lib.php';
- require_once DOL_DOCUMENT_ROOT . '/core/lib/price.lib.php';
- require_once DOL_DOCUMENT_ROOT . '/core/modules/expensereport/modules_expensereport.php';
- require_once DOL_DOCUMENT_ROOT . '/expensereport/class/expensereport.class.php';
- require_once DOL_DOCUMENT_ROOT . '/expensereport/class/paymentexpensereport.class.php';
- require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
- require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
- if (! empty($conf->accounting->enabled)) {
- require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php';
- }
- $langs->load("trips");
- $langs->load("bills");
- $langs->load("mails");
- $action=GETPOST('action','aZ09');
- $cancel=GETPOST('cancel');
- $confirm = GETPOST('confirm', 'alpha');
- $date_start = dol_mktime(0, 0, 0, GETPOST('date_debutmonth'), GETPOST('date_debutday'), GETPOST('date_debutyear'));
- $date_end = dol_mktime(0, 0, 0, GETPOST('date_finmonth'), GETPOST('date_finday'), GETPOST('date_finyear'));
- $date = dol_mktime(0, 0, 0, GETPOST('datemonth'), GETPOST('dateday'), GETPOST('dateyear'));
- $fk_projet=GETPOST('fk_projet');
- $vatrate=GETPOST('vatrate');
- $ref=GETPOST("ref",'alpha');
- $comments=GETPOST('comments');
- $fk_c_type_fees=GETPOST('fk_c_type_fees','int');
- // If socid provided by ajax company selector
- if (! empty($_REQUEST['socid_id']))
- {
- $_GET['socid'] = $_GET['socid_id'];
- $_POST['socid'] = $_POST['socid_id'];
- $_REQUEST['socid'] = $_REQUEST['socid_id'];
- }
- // Security check
- $id=GETPOST("id",'int');
- if ($user->societe_id) $socid=$user->societe_id;
- $result = restrictedArea($user, 'expensereport', 0, 'expensereport');
- // Hack to use expensereport dir
- $rootfordata = DOL_DATA_ROOT;
- $rootforuser = DOL_DATA_ROOT;
- // If multicompany module is enabled, we redefine the root of data
- if (! empty($conf->multicompany->enabled) && ! empty($conf->entity) && $conf->entity > 1)
- {
- $rootfordata.='/'.$conf->entity;
- }
- $conf->expensereport->dir_output = $rootfordata.'/expensereport';
- // Define $urlwithroot
- $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
- $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
- //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
- // PDF
- $hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
- $hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
- $hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
- $object=new ExpenseReport($db);
- $extrafields = new ExtraFields($db);
- // fetch optionals attributes and labels
- $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
- // Load object
- include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once
- // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
- $hookmanager->initHooks(array('expensereportcard','globalcard'));
- $permissionnote = $user->rights->expensereport->creer; // Used by the include of actions_setnotes.inc.php
- $permissiondellink = $user->rights->expensereport->creer; // Used by the include of actions_dellink.inc.php
- $permissionedit = $user->rights->expensereport->creer; // Used by the include of actions_lineupdown.inc.php
- /*
- * Actions
- */
- $parameters = array('socid' => $socid);
- $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
- if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
- if (empty($reshook))
- {
- if ($cancel)
- {
- $action='';
- $fk_projet='';
- $date_start='';
- $date_end='';
- $date='';
- $comments='';
- $vatrate='';
- $value_unit='';
- $qty=1;
- $fk_c_type_fees=-1;
- }
- 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') && ! GETPOST('clone_receivers'))
- {
- 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(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") == "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');
- $object->note_private = GETPOST('note_private');
- // Fill array 'array_options' with data from add form
- if (! $error)
- {
- $ret = $extrafields->setOptionalsFromPost($extralabels, $object);
- if ($ret < 0) $error++;
- }
-
- if ($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)
- {
- $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');
- $object->note_private = GETPOST('note_private');
- $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')
- {
- // Fill array 'array_options' with data from update form
- $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
- $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute'));
- if ($ret < 0) $error++;
-
- if (! $error)
- {
- // Actions on extra fields (by external module or standard code)
- $hookmanager->initHooks(array('expensereportdao'));
- $parameters = array('id' => $object->id);
- $reshook = $hookmanager->executeHooks('insertExtraFields', $parameters, $object, $action); // Note that $action and $object may have been modified by
- // some hooks
- if (empty($reshook)) {
- $result = $object->insertExtraFields();
- if ($result < 0) {
- $error++;
- }
- } else if ($reshook < 0)
- $error++;
- }
-
- if ($error)
- $action = 'edit_extras';
- }
-
- if ($action == "confirm_validate" && GETPOST("confirm") == "yes" && $id > 0 && $user->rights->expensereport->creer)
- {
- $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')) $newlang = GETPOST('lang_id','alpha');
- 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 && $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
- $subject = $langs->transnoentities("ExpenseReportWaitingForApproval");
-
- // CONTENT
- $link = $urlwithroot.'/expensereport/card.php?id='.$object->id;
- $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);
-
- if($resultPDF):
- // ATTACHMENT
- array_push($filename,dol_sanitizeFileName($object->ref).".pdf");
- array_push($filedir,$conf->expensereport->dir_output . "/" . dol_sanitizeFileName($object->ref) . "/" . dol_sanitizeFileName($object->ref).".pdf");
- array_push($mimetype,"application/pdf");
- */
-
- // PREPARE SEND
- $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename);
-
- if ($mailfile)
- {
- // SEND
- $result=$mailfile->sendfile();
- if ($result)
- {
- $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($emailFrom,2),$mailfile->getValidAddress($emailTo,2));
- setEventMessages($mesg, null, 'mesgs');
- header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
- exit;
- }
- else
- {
- $langs->load("other");
- if ($mailfile->error)
- {
- $mesg='';
- $mesg.=$langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo);
- $mesg.='<br>'.$mailfile->error;
- setEventMessages($mesg, null, 'errors');
- }
- else
- {
- setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'warnings');
- }
- }
- }
- else
- {
- setEventMessages($mailfile->error,$mailfile->errors,'errors');
- $action='';
- }
- }
- else
- {
- setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings');
- $action='';
- }
- }
- else
- {
- setEventMessages($object->error, $object->errors, 'errors');
- }
- }
-
- if ($action == "confirm_save_from_refuse" && GETPOST("confirm") == "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')) $newlang = GETPOST('lang_id','alpha');
- 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_validator);
- $emailTo = $destinataire->email;
-
- // FROM
- $expediteur = new User($db);
- $expediteur->fetch($object->fk_user_author);
- $emailFrom = $expediteur->email;
- if ($emailFrom && $emailTo)
- {
- $filename=array(); $filedir=array(); $mimetype=array();
-
- // SUBJECT
- $subject = $langs->transnoentities("ExpenseReportWaitingForReApproval");
-
- // CONTENT
- $link = $urlwithroot.'/expensereport/card.php?id='.$object->id;
- $dateRefusEx = explode(" ",$object->date_refuse);
- $message = $langs->transnoentities("ExpenseReportWaitingForReApprovalMessage", $dateRefusEx[0], $object->detail_refuse, $expediteur->getFullName($langs), $link);
- // Rebuild pdf
- /*
- $object->setDocModel($user,"");
- $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs);
- if($resultPDF)
- {
- // ATTACHMENT
- $filename=array(); $filedir=array(); $mimetype=array();
- array_push($filename,dol_sanitizeFileName($object->ref).".pdf");
- array_push($filedir,$conf->expensereport->dir_output . "/" . dol_sanitizeFileName($object->ref) . "/" . dol_sanitizeFileName($object->ref_number).".pdf");
- array_push($mimetype,"application/pdf");
- }
- */
- // PREPARE SEND
- $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename);
-
- if ($mailfile)
- {
- // SEND
- $result=$mailfile->sendfile();
- if ($result)
- {
- $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($emailFrom,2),$mailfile->getValidAddress($emailTo,2));
- setEventMessages($mesg, null, 'mesgs');
- header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
- exit;
- }
- else
- {
- $langs->load("other");
- if ($mailfile->error)
- {
- $mesg='';
- $mesg.=$langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo);
- $mesg.='<br>'.$mailfile->error;
- setEventMessages($mesg, null, 'errors');
- }
- else
- {
- setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'warnings');
- }
- }
- }
- else
- {
- setEventMessages($mailfile->error,$mailfile->errors,'errors');
- $action='';
- }
- }
- else
- {
- setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings');
- $action='';
- }
- }
- else
- {
- setEventMessages($object->error, $object->errors, 'errors');
- }
- }
-
- // Approve
- if ($action == "confirm_approve" && GETPOST("confirm") == "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')) $newlang = GETPOST('lang_id','alpha');
- 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;
- // CC
- $emailCC = $conf->global->NDF_CC_EMAILS;
- if (empty($emailTo)) $emailTo=$emailCC;
- // FROM
- $expediteur = new User($db);
- $expediteur->fetch($object->fk_user_valid);
- $emailFrom = $expediteur->email;
- if ($emailFrom && $emailTo)
- {
- $filename=array(); $filedir=array(); $mimetype=array();
-
- // SUBJECT
- $subject = $langs->transnoentities("ExpenseReportApproved");
-
- // CONTENT
- $link = $urlwithroot.'/expensereport/card.php?id='.$object->id;
- $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);
-
- if($resultPDF
- {
- // ATTACHMENT
- $filename=array(); $filedir=array(); $mimetype=array();
- array_push($filename,dol_sanitizeFileName($object->ref).".pdf");
- array_push($filedir, $conf->expensereport->dir_output."/".dol_sanitizeFileName($object->ref)."/".dol_sanitizeFileName($object->ref).".pdf");
- array_push($mimetype,"application/pdf");
- }
- */
- $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename);
-
- if ($mailfile)
- {
- // SEND
- $result=$mailfile->sendfile();
- if ($result)
- {
- $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($emailFrom,2),$mailfile->getValidAddress($emailTo,2));
- setEventMessages($mesg, null, 'mesgs');
- header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
- exit;
- }
- else
- {
- $langs->load("other");
- if ($mailfile->error)
- {
- $mesg='';
- $mesg.=$langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo);
- $mesg.='<br>'.$mailfile->error;
- setEventMessages($mesg, null, 'errors');
- }
- else
- {
- setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'warnings');
- }
- }
- }
- else
- {
- setEventMessages($mailfile->error,$mailfile->errors,'errors');
- $action='';
- }
- }
- else
- {
- setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings');
- $action='';
- }
- }
- else
- {
- setEventMessages($langs->trans("FailedtoSetToApprove"), null, 'warnings');
- $action='';
- }
- }
- else
- {
- setEventMessages($object->error, $object->errors, 'errors');
- }
- if ($action == "confirm_refuse" && GETPOST('confirm')=="yes" && $id > 0 && $user->rights->expensereport->approve)
- {
- $object = new ExpenseReport($db);
- $object->fetch($id);
- $result = $object->setDeny($user,GETPOST('detail_refuse'));
- 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')) $newlang = GETPOST('lang_id','alpha');
- 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
- $subject = $langs->transnoentities("ExpenseReportRefused");
-
- // CONTENT
- $link = $urlwithroot.'/expensereport/card.php?id='.$object->id;
- $message = $langs->transnoentities("ExpenseReportRefusedMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $_POST['detail_refuse'], $link);
-
- // Rebuilt pdf
- /*
- $object->setDocModel($user,"");
- $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs);
-
- if($resultPDF
- {
- // ATTACHMENT
- $filename=array(); $filedir=array(); $mimetype=array();
- array_push($filename,dol_sanitizeFileName($object->ref).".pdf");
- array_push($filedir, $conf->expensereport->dir_output."/".dol_sanitizeFileName($object->ref)."/".dol_sanitizeFileName($object->ref).".pdf");
- array_push($mimetype,"application/pdf");
- }
- */
- // PREPARE SEND
- $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename);
- if ($mailfile)
- {
- // SEND
- $result=$mailfile->sendfile();
- if ($result)
- {
- $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($emailFrom,2),$mailfile->getValidAddress($emailTo,2));
- setEventMessages($mesg, null, 'mesgs');
- header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
- exit;
- }
- else
- {
- $langs->load("other");
- if ($mailfile->error)
- {
- $mesg='';
- $mesg.=$langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo);
- $mesg.='<br>'.$mailfile->error;
- setEventMessages($mesg, null, 'errors');
- }
- else
- {
- setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'warnings');
- }
- }
- }
- else
- {
- setEventMessages($mailfile->error,$mailfile->errors,'errors');
- $action='';
- }
- }
- else
- {
- setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings');
- $action='';
- }
- }
- else
- {
- setEventMessages($langs->trans("FailedtoSetToDeny"), null, 'warnings');
- $action='';
- }
- }
- else
- {
- setEventMessages($object->error, $object->errors, 'errors');
- }
- //var_dump($user->id == $object->fk_user_validator);exit;
- if ($action == "confirm_cancel" && GETPOST('confirm')=="yes" && GETPOST('detail_cancel') && $id > 0 && $user->rights->expensereport->creer)
- {
- $object = new ExpenseReport($db);
- $object->fetch($id);
- if ($user->id == $object->fk_user_valid || $user->id == $object->fk_user_author)
- {
- $result = $object->set_cancel($user,GETPOST('detail_cancel'));
- 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')) $newlang = GETPOST('lang_id','alpha');
- 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
- $subject = $langs->transnoentities("ExpenseReportCanceled");
-
- // CONTENT
- $link = $urlwithroot.'/expensereport/card.php?id='.$object->id;
- $message = $langs->transnoentities("ExpenseReportCanceledMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $_POST['detail_cancel'], $link);
-
- // Rebuilt pdf
- /*
- $object->setDocModel($user,"");
- $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs);
-
- if($resultPDF
- {
- // ATTACHMENT
- $filename=array(); $filedir=array(); $mimetype=array();
- array_push($filename,dol_sanitizeFileName($object->ref).".pdf");
- array_push($filedir, $conf->expensereport->dir_output."/".dol_sanitizeFileName($object->ref)."/".dol_sanitizeFileName($object->ref).".pdf");
- array_push($mimetype,"application/pdf");
- }
- */
-
- // PREPARE SEND
- $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename);
-
- if ($mailfile)
- {
- // SEND
- $result=$mailfile->sendfile();
- if ($result)
- {
- $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($emailFrom,2),$mailfile->getValidAddress($emailTo,2));
- setEventMessages($mesg, null, 'mesgs');
- header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
- exit;
- }
- else
- {
- $langs->load("other");
- if ($mailfile->error)
- {
- $mesg='';
- $mesg.=$langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo);
- $mesg.='<br>'.$mailfile->error;
- setEventMessages($mesg, null, 'errors');
- }
- else
- {
- setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'warnings');
- }
- }
- }
- else
- {
- setEventMessages($mailfile->error,$mailfile->errors,'errors');
- $action='';
- }
- }
- else
- {
- setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings');
- $action='';
- }
- }
- else
- {
- setEventMessages($langs->trans("FailedToSetToCancel"), null, 'warnings');
- $action='';
- }
- }
- else
- {
- setEventMessages($object->error, $object->errors, 'errors');
- }
- }
- if ($action == "confirm_brouillonner" && GETPOST('confirm')=="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')) $newlang = GETPOST('lang_id','alpha');
- 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_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')) $newlang = GETPOST('lang_id','alpha');
- 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
- $subject = $langs->transnoentities("ExpenseReportPaid");
- // CONTENT
- $link = $urlwithroot.'/expensereport/card.php?id='.$object->id;
- $message = $langs->transnoentities("ExpenseReportPaidMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $link);
- // CONTENT
- $message = "Bonjour {$destinataire->firstname},\n\n";
- $message.= "Votre note de frais \"{$object->ref}\" vient d'être payée.\n";
- $message.= "- Payeur : {$expediteur->firstname} {$expediteur->lastname}\n";
- $message.= "- Lien : {$dolibarr_main_url_root}/expensereport/card.php?id={$object->id}\n\n";
- $message.= "Bien cordialement,\n' SI";
- // 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);
- if ($mailfile)
- {
- // SEND
- $result=$mailfile->sendfile();
- if ($result)
- {
- $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($emailFrom,2),$mailfile->getValidAddress($emailTo,2));
- setEventMessages($mesg, null, 'mesgs');
- header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
- exit;
- }
- else
- {
- $langs->load("other");
- if ($mailfile->error)
- {
- $mesg='';
- $mesg.=$langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo);
- $mesg.='<br>'.$mailfile->error;
- setEventMessages($mesg, null, 'errors');
- }
- else
- {
- setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'warnings');
- }
- }
- }
- else
- {
- setEventMessages($mailfile->error,$mailfile->errors,'errors');
- $action='';
- }
- }
- else
- {
- setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings');
- $action='';
- }
- }
- else
- {
- setEventMessages($langs->trans("FailedToSetPaid"), null, 'warnings');
- $action='';
- }
- }
- else
- {
- setEventMessages($object->error, $object->errors, 'errors');
- }
- if ($action == "addline" && $user->rights->expensereport->creer)
- {
- $error = 0;
- $db->begin();
- $object_ligne = new ExpenseReportLine($db);
- $vatrate = GETPOST('vatrate');
- $object_ligne->comments = GETPOST('comments');
- $qty = GETPOST('qty','int');
- if (empty($qty)) $qty=1;
- $object_ligne->qty = $qty;
- $up=price2num(GETPOST('value_unit'),'MU');
- $object_ligne->value_unit = $up;
- $object_ligne->date = $date;
- $object_ligne->fk_c_type_fees = GETPOST('fk_c_type_fees');
- // if VAT is not used in Dolibarr, set VAT rate to 0 because VAT rate is necessary.
- if (empty($vatrate)) $vatrate = "0.000";
- $object_ligne->vatrate = price2num($vatrate);
- $object_ligne->fk_projet = $fk_projet;
- if (! GETPOST('fk_c_type_fees') > 0)
- {
- $error++;
- setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
- $action='';
- }
- if ($vatrate < 0 || $vatrate == '')
- {
- $error++;
- setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("VAT")), null, 'errors');
- $action='';
- }
- /* Projects are never required. To force them, check module forceproject
- if ($conf->projet->enabled)
- {
- if (empty($object_ligne->fk_projet) || $object_ligne->fk_projet==-1)
- {
- $error++;
- setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Project")), null, 'errors');
- }
- }*/
- // Si aucune date n'est rentrée
- if (empty($object_ligne->date) || $object_ligne->date=="--")
- {
- $error++;
- setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
- }
- // Si aucun prix n'est rentré
- if($object_ligne->value_unit==0)
- {
- $error++;
- setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PriceUTTC")), null, 'errors');
- }
- // S'il y'a eu au moins une erreur
- if (! $error)
- {
- $object_ligne->fk_expensereport = $_POST['fk_expensereport'];
- $type = 0; // TODO What if service ?
- $seller = ''; // seller is unknown
- $tmp = calcul_price_total($qty, $up, 0, $vatrate, 0, 0, 0, 'TTC', 0, $type, $seller);
- $object_ligne->vatrate = price2num($vatrate);
- $object_ligne->total_ttc = $tmp[2];
- $object_ligne->total_ht = $tmp[0];
- $object_ligne->total_tva = $tmp[1];
- $result = $object_ligne->insert();
- if ($result > 0)
- {
- $db->commit();
- header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
- exit;
- }
- else
- {
- dol_print_error($db,$object->error);
- $db->rollback();
- }
- }
- $action='';
- }
- if ($action == 'confirm_delete_line' && GETPOST("confirm") == "yes" && $user->rights->expensereport->creer)
- {
- $object = new ExpenseReport($db);
- $object->fetch($id);
-
- $object_ligne = new ExpenseReportLine($db);
- $object_ligne->fetch(GETPOST("rowid"));
- $total_ht = $object_ligne->total_ht;
- $total_tva = $object_ligne->total_tva;
- $result=$object->deleteline(GETPOST("rowid"), $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')) $newlang = GETPOST('lang_id','alpha');
- 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 == "updateligne" && $user->rights->expensereport->creer)
- {
- $object = new ExpenseReport($db);
- $object->fetch($id);
- $rowid = $_POST['rowid'];
- $type_fees_id = GETPOST('fk_c_type_fees');
- $projet_id = $fk_projet;
- $comments = GETPOST('comments');
- $qty = GETPOST('qty');
- $value_unit = GETPOST('value_unit');
- $vatrate = GETPOST('vatrate');
- // if VAT is not used in Dolibarr, set VAT rate to 0 because VAT rate is necessary.
- if (empty($vatrate)) $vatrate = "0.000";
- $vatrate = price2num($vatrate);
- if (! GETPOST('fk_c_type_fees') > 0)
- {
- $error++;
- setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
- $action='';
- }
- if ((int) $vatrate < 0 || $vatrate == '')
- {
- $error++;
- setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Vat")), null, 'errors');
- $action='';
- }
- if (! $error)
- {
- // TODO Use update method of ExpenseReportLine
- $result = $object->updateline($rowid, $type_fees_id, $projet_id, $vatrate, $comments, $qty, $value_unit, $date, $id);
- 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')) $newlang = GETPOST('lang_id','alpha');
- 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 to build doc
- $upload_dir = $conf->expensereport->dir_output;
- $permissioncreate = $user->rights->expensereport->creer;
- include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
- }
- /*
- * View
- */
- $title=$langs->trans("ExpenseReport") . " - " . $langs->trans("Card");
- $helpurl="EN:Module_Expense_Reports";
- llxHeader("",$title,$helpurl);
- $form = new Form($db);
- $formfile = new FormFile($db);
- $formproject = new FormProjets($db);
- $projecttmp = new Project($db);
- $paymentexpensereportstatic=new PaymentExpenseReport($db);
- $bankaccountstatic = new Account($db);
- // Create
- if ($action == 'create')
- {
- print load_fiche_titre($langs->trans("NewTrip"));
- print '<form action="'.$_SERVER['PHP_SELF'].'" method="post" name="create">';
- print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
- print '<input type="hidden" name="action" value="add">';
- dol_fiche_head('');
- print '<table class="border" width="100%">';
- print '<tbody>';
-
- // Date start
- print '<tr>';
- print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("DateStart").'</td>';
- print '<td>';
- $form->select_date($date_start?$date_start:-1,'date_debut',0,0,0,'',1,1);
- print '</td>';
- print '</tr>';
-
- // Date end
- print '<tr>';
- print '<td class="fieldrequired">'.$langs->trans("DateEnd").'</td>';
- print '<td>';
- $form->select_date($date_end?$date_end:-1,'date_fin',0,0,0,'',1,1);
- print '</td>';
- print '</tr>';
-
- print '<tr>';
- print '<td class="fieldrequired">'.$langs->trans("User").'</td>';
- print '<td>';
- $defaultselectuser=$user->id;
- if (GETPOST('fk_user_author') > 0) $defaultselectuser=GETPOST('fk_user_author');
- $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);
- print $s;
- print '</td>';
- print '</tr>';
- print '<tr>';
- print '<td>'.$langs->trans("VALIDATOR").'</td>';
- print '<td>';
- $object = new ExpenseReport($db);
- $include_users = $object->fetch_users_approver_expensereport();
- if (empty($include_users)) print img_warning().' '.$langs->trans("NobodyHasPermissionToValidateExpenseReport");
- else
- {
- $defaultselectuser=$user->fk_user; // Will work only if supervisor has permission to approve so is inside include_users
- if (! empty($conf->global->EXPENSEREPORT_DEFAULT_VALIDATOR)) $defaultselectuser=$conf->global->EXPENSEREPORT_DEFAULT_VALIDATOR; // Can force default approver
- if (GETPOST('fk_user_validator') > 0) $defaultselectuser=GETPOST('fk_user_validator');
- $s=$form->select_dolusers($defaultselectuser, "fk_user_validator", 1, "", 0, $include_users);
- print $form->textwithpicto($s, $langs->trans("AnyOtherInThisListCanValidate"));
- }
- print '</td>';
- print '</tr>';
-
- // Payment mode
- if (! empty($conf->global->EXPENSEREPORT_ASK_PAYMENTMODE_ON_CREATION))
- {
- print '<tr>';
- print '<td>'.$langs->trans("ModePaiement").'</td>';
- print '<td>';
- $form->select_types_paiements(2,'fk_c_paiement');
- print '</td>';
- print '</tr>';
- }
- // Public note
- print '<tr>';
- print '<td class="tdtop">' . $langs->trans('NotePublic') . '</td>';
- print '<td>';
- $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');
- print $doleditor->Create(1);
- print '</td></tr>';
- // Private note
- if (empty($user->societe_id)) {
- print '<tr>';
- print '<td class="tdtop">' . $langs->trans('NotePrivate') . '</td>';
- print '<td>';
- $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');
- print $doleditor->Create(1);
- print '</td></tr>';
- }
- // Other attributes
- $parameters = array('colspan' => ' colspan="3"');
- $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by
- // hook
- if (empty($reshook) && ! empty($extrafields->attribute_label)) {
- print $object->showOptionals($extrafields, 'edit');
- }
- print '<tbody>';
- print '</table>';
- dol_fiche_end();
- print '<div class="center">';
- print '<input type="submit" value="'.$langs->trans("AddTrip").'" name="bouton" class="button" />';
- print ' <input type="button" value="'.$langs->trans("Cancel").'" class="button" onclick="history.go(-1)" />';
- print '</div>';
- print '</form>';
- }
- else
- {
- if($id > 0 || $ref)
- {
- $result = $object->fetch($id, $ref);
- $res = $object->fetch_optionals($object->id, $extralabels);
-
- if ($result > 0)
- {
- if (! in_array($object->fk_user_author, $user->getAllChildIds(1)))
- {
- if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)
- && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->expensereport->writeall_advance)))
- {
- print load_fiche_titre($langs->trans('TripCard'));
- print '<div class="tabBar">';
- print $langs->trans('NotUserRightToView');
- print '</div>';
- llxFooter();
- $db->close();
- exit;
- }
- }
- $head = expensereport_prepare_head($object);
- if ($action == 'edit' && ($object->fk_statut < 3 || $object->fk_statut==99))
- {
- print "<form name='update' action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">\n";
- print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
- print '<input type="hidden" name="id" value="'.$id.'">';
- dol_fiche_head($head, 'card', $langs->trans("ExpenseReport"), 0, 'trip');
- if($object->fk_statut==99)
- {
- print '<input type="hidden" name="action" value="updateFromRefuse">';
- }
- else
- {
- print '<input type="hidden" name="action" value="update">';
- }
- $linkback = '<a href="'.DOL_URL_ROOT.'/expensereport/list.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
- print '<table class="border" style="width:100%;">';
- print '<tr>';
- print '<td>'.$langs->trans("User").'</td>';
- print '<td>';
- $userfee=new User($db);
- if ($object->fk_user_author > 0)
- {
- $userfee->fetch($object->fk_user_author);
- print $userfee->getNomUrl(-1);
- }
- print '</td></tr>';
- // Ref
- print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td><td>';
- print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', '');
- print '</td></tr>';
- print '<tr>';
- print '<td>'.$langs->trans("DateStart").'</td>';
- print '<td>';
- $form->select_date($object->date_debut,'date_debut');
- print '</td>';
- print '</tr>';
- print '<tr>';
- print '<td>'.$langs->trans("DateEnd").'</td>';
- print '<td>';
- $form->select_date($object->date_fin,'date_fin');
- print '</td>';
- print '</tr>';
- if (! empty($conf->global->EXPENSEREPORT_ASK_PAYMENTMODE_ON_CREATION))
- {
- print '<tr>';
- print '<td>'.$langs->trans("ModePaiement").'</td>';
- print '<td>';
- $form->select_types_paiements($object->fk_c_paiement,'fk_c_paiement');
- print '</td>';
- print '</tr>';
- }
- if($object->fk_statut<3)
- {
- print '<tr>';
- print '<td>'.$langs->trans("VALIDATOR").'</td>'; // Approbator
- print '<td>';
- $include_users = $object->fetch_users_approver_expensereport();
- $s=$form->select_dolusers($object->fk_user_validator,"fk_user_validator",1,"",0,$include_users);
- print $form->textwithpicto($s, $langs->trans("AnyOtherInThisListCanValidate"));
- print '</td>';
- print '</tr>';
- }
- else
- {
- print '<tr>';
- print '<td>'.$langs->trans("VALIDOR").'</td>';
- print '<td>';
- $userfee=new User($db);
- $userfee->fetch($object->fk_user_valid);
- print $userfee->getNomUrl(-1);
- print '</td></tr>';
- }
- if ($object->fk_statut==6)
- {
- print '<tr>';
- print '<td>'.$langs->trans("AUTHORPAIEMENT").'</td>';
- print '<td>';
- $userfee=new User($db);
- $userfee->fetch($user->id);
- print $userfee->getNomUrl(-1);
- print '</td></tr>';
- }
- // Other attributes
- //$cols = 3;
- //include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_edit.tpl.php';
- print '</table>';
- dol_fiche_end();
- print '<div class="center">';
- print '<input type="submit" value="'.$langs->trans("Modify").'" name="bouton" class="button">';
- print ' <input type="button" value="'.$langs->trans("Cancel").'" class="button" onclick="history.go(-1)" />';
- print '</div>';
- print '</form>';
- }
- 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))
- );
- // Paiement incomplet. On demande si motif = escompte ou autre
- $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('CloneExpenseReport'), $langs->trans('ConfirmCloneExpenseReport', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
- }
- if ($action == 'save')
- {
- $formconfirm=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$id,$langs->trans("SaveTrip"),$langs->trans("ConfirmSaveTrip"),"confirm_validate","","",1);
- }
- if ($action == 'save_from_refuse')
- {
- $formconfirm=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$id,$langs->trans("SaveTrip"),$langs->trans("ConfirmSaveTrip"),"confirm_save_from_refuse","","",1);
- }
- if ($action == 'delete')
- {
- $formconfirm=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$id,$langs->trans("DeleteTrip"),$langs->trans("ConfirmDeleteTrip"),"confirm_delete","","",1);
- }
- if ($action == 'validate')
- {
- $formconfirm=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$id,$langs->trans("ValideTrip"),$langs->trans("ConfirmValideTrip"),"confirm_approve","","",1);
- }
- if ($action == 'paid')
- {
- $formconfirm=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$id,$langs->trans("PaidTrip"),$langs->trans("ConfirmPaidTrip"),"confirm_paid","","",1);
- }
- if ($action == 'cancel')
- {
- $array_input = array('text'=>$langs->trans("ConfirmCancelTrip"), array('type'=>"text",'label'=>$langs->trans("Comment"),'name'=>"detail_cancel",'size'=>"50",'value'=>""));
- $formconfirm=$form->form_confirm($_SEVER["PHP_SELF"]."?id=".$id,$langs->trans("Cancel"),"","confirm_cancel",$array_input,"",1);
- }
- if ($action == 'brouillonner')
- {
- $formconfirm=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$id,$langs->trans("BrouillonnerTrip"),$langs->trans("ConfirmBrouillonnerTrip"),"confirm_brouillonner","","",1);
- }
- if ($action == 'refuse') // Deny
- {
- $array_input = array('text'=>$langs->trans("ConfirmRefuseTrip"), array('type'=>"text",'label'=>$langs->trans("Comment"),'name'=>"detail_refuse",'size'=>"50",'value'=>""));
- $formconfirm=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$id,$langs->trans("Deny"),'',"confirm_refuse",$array_input,"yes",1);
- }
- if ($action == 'delete_line')
- {
- $formconfirm=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$id."&rowid=".GETPOST('rowid'),$langs->trans("DeleteLine"),$langs->trans("ConfirmDeleteLine"),"confirm_delete_line",'','yes',1);
- }
- // Print form confirm
- print $formconfirm;
- // Expense report card
- $linkback = '<a href="'.DOL_URL_ROOT.'/expensereport/list.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
- $morehtmlref='<div class="refidno">';
- /*
- // Ref customer
- $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->commande->creer, 'string', '', 0, 1);
- $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->commande->creer, 'string', '', null, null, '', 1);
- // Thirdparty
- $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $soc->getNomUrl(1);
- // Project
- if (! empty($conf->projet->enabled))
- {
- $langs->load("projects");
- $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
- if ($user->rights->commande->creer)
- {
- if ($action != 'classify')
- $morehtmlref.='<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
- if ($action == 'classify') {
- //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
- $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
- $morehtmlref.='<input type="hidden" name="action" value="classin">';
- $morehtmlref.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
- $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
- $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
- $morehtmlref.='</form>';
- } else {
- $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
- }
- } else {
- if (! empty($object->fk_project)) {
- $proj = new Project($db);
- $proj->fetch($object->fk_project);
- $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
- $morehtmlref.=$proj->ref;
- $morehtmlref.='</a>';
- } else {
- $morehtmlref.='';
- }
- }
- }*/
- $morehtmlref.='</div>';
- dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
- print '<div class="fichecenter">';
- print '<div class="fichehalfleft">';
- print '<div class="underbanner clearboth"></div>';
- print '<table class="border centpercent">';
- // Author
- print '<tr>';
- print '<td class="titlefield">'.$langs->trans("User").'</td>';
- print '<td>';
- if ($object->fk_user_author > 0)
- {
- $userauthor=new User($db);
- $result=$userauthor->fetch($object->fk_user_author);
- if ($result < 0) dol_print_error('',$userauthor->error);
- elseif ($result > 0) print $userauthor->getNomUrl(-1);
- }
- print '</td></tr>';
- print '<tr>';
- print '<td class="titlefield">'.$langs->trans("Period").'</td>';
- print '<td>';
- print get_date_range($object->date_debut,$object->date_fin,'day',$langs,0);
- print '</td>';
- print '</tr>';
- if (! empty($conf->global->EXPENSEREPORT_ASK_PAYMENTMODE_ON_CREATION))
- {
- print '<tr>';
- print '<td>'.$langs->trans("ModePaiement").'</td>';
- print '<td>'.$object->libelle_paiement.'</td>';
- print '</tr>';
- }
- // Validation date
- print '<tr>';
- print '<td>'.$langs->trans("DATE_SAVE").'</td>';
- print '<td>'.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 '</td></tr>';
- print '</tr>';
- // User to inform for approval
- if ($object->fk_statut < 3) // informed
- {
- print '<tr>';
- print '<td>'.$langs->trans("VALIDATOR").'</td>'; // approver
- print '<td>';
- if ($object->fk_user_validator > 0)
- {
- $userfee=new User($db);
- $result = $userfee->fetch($object->fk_user_validator);
- if ($result > 0) print $userfee->getNomUrl(-1);
- if (empty($userfee->email) || ! isValidEmail($userfee->email))
- {
- $langs->load("errors");
- print img_warning($langs->trans("ErrorBadEMail", $userfee->email));
- }
- }
- print '</td></tr>';
- }
- elseif($object->fk_statut == 4)
- {
- print '<tr>';
- print '<td>'.$langs->trans("CANCEL_USER").'</span></td>';
- print '<td>';
- if ($object->fk_user_cancel > 0)
- {
- $userfee=new User($db);
- $result = $userfee->fetch($object->fk_user_cancel);
- if ($result > 0) print $userfee->getNomUrl(-1);
- }
- print '</td></tr>';
- print '<tr>';
- print '<td>'.$langs->trans("MOTIF_CANCEL").'</td>';
- print '<td>'.$object->detail_cancel.'</td></tr>';
- print '</tr>';
- print '<tr>';
- print '<td>'.$langs->trans("DATE_CANCEL").'</td>';
- print '<td>'.dol_print_date($object->date_cancel,'dayhour').'</td></tr>';
- print '</tr>';
- }
- else
- {
- print '<tr>';
- print '<td>'.$langs->trans("ApprovedBy").'</td>';
- print '<td>';
- if ($object->fk_user_approve > 0)
- {
- $userapp=new User($db);
- $result = $userapp->fetch($object->fk_user_approve);
- if ($result > 0) print $userapp->getNomUrl(-1);
- }
- print '</td></tr>';
- print '<tr>';
- print '<td>'.$langs->trans("DateApprove").'</td>';
- print '<td>'.dol_print_date($object->date_approve,'dayhour').'</td></tr>';
- print '</tr>';
- }
- if ($object->fk_statut==99 || !empty($object->detail_refuse))
- {
- print '<tr>';
- print '<td>'.$langs->trans("REFUSEUR").'</td>';
- print '<td>';
- $userfee=new User($db);
- $result = $userfee->fetch($object->fk_user_refuse);
- if ($result > 0) print $userfee->getNomUrl(-1);
- print '</td></tr>';
- print '<tr>';
- print '<td>'.$langs->trans("DATE_REFUS").'</td>';
- print '<td>'.dol_print_date($object->date_refuse,'dayhour');
- if ($object->detail_refuse) print ' - '.$object->detail_refuse;
- print '</td>';
- print '</tr>';
- }
- if($object->fk_statut==6)
- {
- /* TODO this fields are not yet filled
- print '<tr>';
- print '<td>'.$langs->trans("AUTHORPAIEMENT").'</td>';
- print '<td>';
- $userfee=new User($db);
- $userfee->fetch($object->fk_user_paid);
- print $userfee->getNomUrl(-1);
- print '</td></tr>';
- print '<tr>';
- print '<td>'.$langs->trans("DATE_PAIEMENT").'</td>';
- print '<td>'.$object->date_paiement.'</td></tr>';
- print '</tr>';
- */
- }
- // Other attributes
- $cols = 2;
- include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
- print '</table>';
- print '</div>';
- print '<div class="fichehalfright">';
- print '<div class="ficheaddleft">';
- print '<div class="underbanner clearboth"></div>';
- print '<table class="border centpercent">';
- // Amount
- print '<tr>';
- print '<td class="titlefieldmiddle">'.$langs->trans("AmountHT").'</td>';
- print '<td class="nowrap amountcard">'.price($object->total_ht, 1, '', 1, - 1, - 1, $conf->currency).'</td>';
- $rowspan = 5;
- if ($object->fk_statut < 3) $rowspan++;
- elseif($object->fk_statut == 4) $rowspan+=2;
- else $rowspan+=2;
- if ($object->fk_statut==99 || !empty($object->detail_refuse)) $rowspan+=2;
- if($object->fk_statut==6) $rowspan+=2;
- print "</td>";
- print '</tr>';
- print '<tr>';
- print '<td>'.$langs->trans("AmountVAT").'</td>';
- print '<td class="nowrap amountcard">'.price($object->total_tva, 1, '', 1, - 1, - 1, $conf->currency).'</td>';
- print '</tr>';
- print '<tr>';
- print '<td>'.$langs->trans("AmountTTC").'</td>';
- print '<td class="nowrap amountcard">'.price($object->total_ttc, 1, '', 1, - 1, - 1, $conf->currency).'</td>';
- print '</tr>';
- // List of payments already done
- $nbcols = 3;
- if (! empty($conf->banque->enabled)) {
- $nbrows ++;
- $nbcols ++;
- }
- print '<table class="noborder paymenttable" width="100%">';
- print '<tr class="liste_titre">';
- print '<td class="liste_titre">' . $langs->trans('Payments') . '</td>';
- print '<td class="liste_titre">' . $langs->trans('Date') . '</td>';
- print '<td class="liste_titre">' . $langs->trans('Type') . '</td>';
- if (! empty($conf->banque->enabled)) {
- print '<td class="liste_titre" align="right">' . $langs->trans('BankAccount') . '</td>';
- }
- print '<td class="liste_titre" align="right">' . $langs->trans('Amount') . '</td>';
- print '<td class="liste_titre" width="18"> </td>';
- print '</tr>';
- // Payments already done (from payment on this expensereport)
- $sql = "SELECT p.rowid, p.num_payment, p.datep as dp, p.amount, p.fk_bank,";
- $sql.= "c.code as p_code, c.libelle as payment_type,";
- $sql.= "ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal";
- $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as e";
- $sql.= ", ".MAIN_DB_PREFIX."c_paiement as c ";
- $sql.= ", ".MAIN_DB_PREFIX."payment_expensereport as p";
- $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank as b ON p.fk_bank = b.rowid';
- $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank_account as ba ON b.fk_account = ba.rowid';
- $sql.= " WHERE e.rowid = '".$id."'";
- $sql.= " AND p.fk_expensereport = e.rowid";
- $sql.= " AND e.entity = ".$conf->entity;
- $sql.= " AND p.fk_typepayment = c.id";
- $sql.= " ORDER BY dp";
- $resql = $db->query($sql);
- if ($resql)
- {
- $num = $db->num_rows($resql);
- $i = 0; $total = 0;
- while ($i < $num)
- {
- $objp = $db->fetch_object($resql);
- print '<tr class="oddseven"><td>';
- $paymentexpensereportstatic->id = $objp->rowid;
- $paymentexpensereportstatic->datepaye = $db->jdate($objp->dp);
- $paymentexpensereportstatic->ref = $objp->rowid;
- $paymentexpensereportstatic->num_paiement = $objp->num_paiement;
- $paymentexpensereportstatic->payment_code = $objp->payment_code;
- print $paymentexpensereportstatic->getNomUrl(1);
- print '</td>';
- print '<td>'.dol_print_date($db->jdate($objp->dp),'day')."</td>\n";
- $labeltype=$langs->trans("PaymentType".$objp->p_code)!=("PaymentType".$objp->p_code)?$langs->trans("PaymentType".$objp->p_code):$objp->fk_typepayment;
- print "<td>".$labeltype.' '.$objp->num_payment."</td>\n";
- if (! empty($conf->banque->enabled)) {
- $bankaccountstatic->id = $objp->baid;
- $bankaccountstatic->ref = $objp->baref;
- $bankaccountstatic->label = $objp->baref;
- $bankaccountstatic->number = $objp->banumber;
- if (! empty($conf->accounting->enabled)) {
- $bankaccountstatic->account_number = $objp->account_number;
- $accountingjournal = new AccountingJournal($db);
- $accountingjournal->fetch($objp->fk_accountancy_journal);
- $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0,1,1,'',1);
- }
- print '<td align="right">';
- if ($bankaccountstatic->id)
- print $bankaccountstatic->getNomUrl(1, 'transactions');
- print '</td>';
- }
- print '<td align="right">'.price($objp->amount)."</td>";
- print "</tr>";
- $totalpaid += $objp->amount;
- $i++;
- }
- if ($object->paid == 0)
- {
- print '<tr><td colspan="' . $nbcols . '" align="right">'.$langs->trans("AlreadyPaid").':</td><td align="right">'.price($totalpaid).'</td></tr>';
- print '<tr><td colspan="' . $nbcols . '" align="right">'.$langs->trans("AmountExpected").':</td><td align="right">'.price($object->total_ttc).'</td></tr>';
-
- $remaintopay = $object->total_ttc - $totalpaid;
-
- print '<tr><td colspan="' . $nbcols . '" align="right">'.$langs->trans("RemainderToPay").':</td>';
- print '<td align="right"'.($remaintopay?' class="amountremaintopay"':'').'>'.price($remaintopay).'</td></tr>';
- }
- print "</table>";
- $db->free($resql);
- }
- else
- {
- dol_print_error($db);
- }
- print '</div>';
- print '</div>';
- print '</div>';
- print '<div class="clearboth"></div><br>';
- // Fetch Lines of current expense report
- $sql = 'SELECT fde.rowid, fde.fk_expensereport, fde.fk_c_type_fees, fde.fk_projet, fde.date,';
- $sql.= ' fde.tva_tx as vatrate, fde.comments, fde.qty, fde.value_unit, fde.total_ht, fde.total_tva, fde.total_ttc,';
- $sql.= ' ctf.code as type_fees_code, ctf.label as type_fees_libelle,';
- $sql.= ' pjt.rowid as projet_id, pjt.title as projet_title, pjt.ref as projet_ref';
- $sql.= ' FROM '.MAIN_DB_PREFIX.'expensereport_det as fde';
- $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_type_fees as ctf ON fde.fk_c_type_fees=ctf.id';
- $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pjt ON fde.fk_projet=pjt.rowid';
- $sql.= ' WHERE fde.fk_expensereport = '.$object->id;
- $sql.= ' ORDER BY fde.date ASC';
- print '<div style="clear: both;"></div>';
- $actiontouse='updateligne';
- if (($object->fk_statut==0 || $object->fk_statut==99) && $action != 'editline') $actiontouse='addline';
- print '<form name="expensereport" action="'.$_SERVER["PHP_SELF"].'" method="post">';
- print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
- print '<input type="hidden" name="action" value="'.$actiontouse.'">';
- print '<input type="hidden" name="id" value="'.$object->id.'">';
- print '<input type="hidden" name="fk_expensereport" value="'.$object->id.'" />';
- print '<div class="div-table-responsive">';
- print '<table id="tablelines" class="noborder" width="100%">';
- $resql = $db->query($sql);
- if ($resql)
- {
- $num_lignes = $db->num_rows($resql);
- $i = 0;$total = 0;
- if ($num_lignes)
- {
- print '<tr class="liste_titre">';
- print '<td style="text-align:center;">'.$langs->trans('Piece').'</td>';
- print '<td style="text-align:center;">'.$langs->trans('Date').'</td>';
- if (! empty($conf->projet->enabled)) print '<td class="minwidth100imp">'.$langs->trans('Project').'</td>';
- print '<td style="text-align:center;">'.$langs->trans('Type').'</td>';
- print '<td style="text-align:left;">'.$langs->trans('Description').'</td>';
- print '<td style="text-align:right;">'.$langs->trans('VAT').'</td>';
- print '<td style="text-align:right;">'.$langs->trans('PriceUTTC').'</td>';
- print '<td style="text-align:right;">'.$langs->trans('Qty').'</td>';
- if ($action != 'editline')
- {
- print '<td style="text-align:right;">'.$langs->trans('AmountHT').'</td>';
- print '<td style="text-align:right;">'.$langs->trans('AmountTTC').'</td>';
- }
- // Ajout des boutons de modification/suppression
- if (($object->fk_statut < 2 || $object->fk_statut == 99) && $user->rights->expensereport->creer)
- {
- print '<td style="text-align:right;"></td>';
- }
- print '</tr>';
- while ($i < $num_lignes)
- {
- $piece_comptable = $i + 1;
- $objp = $db->fetch_object($resql);
- if ($action != 'editline' || $objp->rowid != GETPOST('rowid'))
- {
- print '<tr class="oddeven">';
-
- print '<td style="text-align:center;">';
- print img_picto($langs->trans("Document"), "object_generic");
- print ' <span>'.$piece_comptable.'</span></td>';
- print '<td style="text-align:center;">'.dol_print_date($db->jdate($objp->date), 'day').'</td>';
- if (! empty($conf->projet->enabled))
- {
- print '<td>';
- if ($objp->projet_id > 0)
- {
- $projecttmp->id=$objp->projet_id;
- $projecttmp->ref=$objp->projet_ref;
- print $projecttmp->getNomUrl(1);
- }
- print '</td>';
- }
- // print '<td style="text-align:center;">'.$langs->trans("TF_".strtoupper(empty($objp->type_fees_libelle)?'OTHER':$objp->type_fees_libelle)).'</td>';
- print '<td style="text-align:center;">'.($langs->trans(($objp->type_fees_code)) == $objp->type_fees_code ? $objp->type_fees_libelle : $langs->trans(($objp->type_fees_code))).'</td>';
- print '<td style="text-align:left;">'.$objp->comments.'</td>';
- print '<td style="text-align:right;">'.vatrate($objp->vatrate,true).'</td>';
- print '<td style="text-align:right;">'.price($objp->value_unit).'</td>';
- print '<td style="text-align:right;">'.$objp->qty.'</td>';
-
- if ($action != 'editline')
- {
- print '<td style="text-align:right;">'.price($objp->total_ht).'</td>';
- print '<td style="text-align:right;">'.price($objp->total_ttc).'</td>';
- }
- // Ajout des boutons de modification/suppression
- if (($object->fk_statut < 2 || $object->fk_statut == 99) && $user->rights->expensereport->creer)
- {
- print '<td style="text-align:right;" class="nowrap">';
- print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=editline&rowid='.$objp->rowid.'#'.$objp->rowid.'">';
- print img_edit();
- print '</a> ';
- print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete_line&rowid='.$objp->rowid.'">';
- print img_delete();
- print '</a>';
- print '</td>';
- }
- print '</tr>';
- }
- if ($action == 'editline' && $objp->rowid == GETPOST('rowid'))
- {
- print '<tr class="oddeven">';
-
- print '<td></td>';
- // Select date
- print '<td class="center">';
- $form->select_date($objp->date,'date');
- print '</td>';
- // Select project
- if (! empty($conf->projet->enabled))
- {
- print '<td>';
- $formproject->select_projects(-1, $objp->fk_projet,'fk_projet', 0, 0, 1, 1);
- print '</td>';
- }
-
- // Select type
- print '<td class="center">';
- select_type_fees_id($objp->type_fees_code,'fk_c_type_fees');
- print '</td>';
- // Add comments
- print '<td>';
- print '<textarea name="comments" class="flat_ndf centpercent">'.$objp->comments.'</textarea>';
- print '</td>';
- // VAT
- print '<td style="text-align:right;">';
- print $form->load_tva('vatrate', (isset($_POST["vatrate"])?$_POST["vatrate"]:$objp->vatrate), $mysoc, '');
- print '</td>';
- // Unit price
- print '<td style="text-align:right;">';
- print '<input type="text" min="0" class="maxwidth100" name="value_unit" value="'.$objp->value_unit.'" />';
- print '</td>';
- // Quantity
- print '<td style="text-align:right;">';
- print '<input type="number" min="0" class="maxwidth100" name="qty" value="'.$objp->qty.'" />';
- print '</td>';
- if ($action != 'editline')
- {
- print '<td style="text-align:right;">'.$langs->trans('AmountHT').'</td>';
- print '<td style="text-align:right;">'.$langs->trans('AmountTTC').'</td>';
- }
- print '<td style="text-align:center;">';
- print '<input type="hidden" name="rowid" value="'.$objp->rowid.'">';
- print '<input type="submit" class="button" name="save" value="'.$langs->trans('Save').'">';
- print '<br /><input type="submit" class="button" name="cancel" value="'.$langs->trans('Cancel').'">';
- print '</td>';
- }
- $i++;
- }
- $db->free($resql);
- }
- else
- {
- /* print '<table width="100%">';
- print '<tr><td><div class="error" style="display:block;">'.$langs->trans("AucuneLigne").'</div></td></tr>';
- print '</table>';*/
- }
- //print '</div>';
- // Add a line
- if (($object->fk_statut==0 || $object->fk_statut==99) && $action != 'editline' && $user->rights->expensereport->creer)
- {
- print '<tr class="liste_titre">';
- print '<td></td>';
- print '<td align="center">'.$langs->trans('Date').'</td>';
- if (! empty($conf->projet->enabled)) print '<td class="minwidth100imp">'.$langs->trans('Project').'</td>';
- print '<td align="center">'.$langs->trans('Type').'</td>';
- print '<td>'.$langs->trans('Description').'</td>';
- print '<td align="right">'.$langs->trans('VAT').'</td>';
- print '<td align="right">'.$langs->trans('PriceUTTC').'</td>';
- print '<td align="right">'.$langs->trans('Qty').'</td>';
- print '<td colspan="3"></td>';
- print '</tr>';
- print '<tr '.$bc[true].'>';
- print '<td></td>';
- // Select date
- print '<td align="center">';
- $form->select_date($date?$date:-1,'date');
- print '</td>';
- // Select project
- if (! empty($conf->projet->enabled))
- {
- print '<td>';
- $formproject->select_projects(-1, $fk_projet, 'fk_projet', 0, 0, 1, 1);
- print '</td>';
- }
- // Select type
- print '<td align="center">';
- select_type_fees_id($fk_c_type_fees,'fk_c_type_fees',1);
- print '</td>';
- // Add comments
- print '<td>';
- print '<textarea class="flat_ndf centpercent" name="comments">'.$comments.'</textarea>';
- print '</td>';
- // Select VAT
- print '<td align="right">';
- $defaultvat=-1;
- if (! empty($conf->global->EXPENSEREPORT_NO_DEFAULT_VAT)) $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS = 'none';
- print $form->load_tva('vatrate', ($vatrate!=''?$vatrate:$defaultvat), $mysoc, '', 0, 0, '', false);
- print '</td>';
- // Unit price
- print '<td align="right">';
- print '<input type="text" class="right maxwidth50" name="value_unit" value="'.$value_unit.'">';
- print '</td>';
- // Quantity
- print '<td align="right">';
- print '<input type="number" min="0" class="right maxwidth50" name="qty" value="'.($qty?$qty:1).'">';
- print '</td>';
- if ($action != 'editline')
- {
- print '<td align="right"></td>';
- print '<td align="right"></td>';
- }
- print '<td align="center"><input type="submit" value="'.$langs->trans("Add").'" name="bouton" class="button"></td>';
-
- print '</tr>';
- } // Fin si c'est payé/validé
- print '</table>';
- print '</div>';
-
- print '</form>';
- }
- else
- {
- dol_print_error($db);
- }
- dol_fiche_end();
- } // end edit or not edit
- } // end of if result
- else
- {
- dol_print_error($db);
- }
- } //fin si id > 0
- }
- /*
- * Barre d'actions
- */
- print '<div class="tabsAction">';
- if ($action != 'create' && $action != 'edit')
- {
- $object = new ExpenseReport($db);
- $object->fetch($id, $ref);
- /* Si l'état est "Brouillon"
- * ET user à droit "creer/supprimer"
- * ET fk_user_author == user courant
- * Afficher : "Enregistrer" / "Modifier" / "Supprimer"
- */
- if ($user->rights->expensereport->creer && $object->fk_statut==0)
- {
- if (in_array($object->fk_user_author, $user->getAllChildIds(1)) || !empty($user->rights->expensereport->writeall_advance))
- {
- // Modify
- print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&id='.$object->id.'">'.$langs->trans('Modify').'</a></div>';
- // Validate
- if (count($object->lines) > 0)
- {
- print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=save&id='.$object->id.'">'.$langs->trans('ValidateAndSubmit').'</a></div>';
- }
- }
- }
- /* Si l'état est "Refusée"
- * ET user à droit "creer/supprimer"
- * ET fk_user_author == user courant
- * Afficher : "Enregistrer" / "Modifier" / "Supprimer"
- */
- if($user->rights->expensereport->creer && $object->fk_statut==99)
- {
- if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid)
- {
- // Modify
- print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&id='.$object->id.'">'.$langs->trans('Modify').'</a></div>';
- // Brouillonner (le statut refusée est identique à brouillon)
- //print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=brouillonner&id='.$id.'">'.$langs->trans('BROUILLONNER').'</a>';
- // Enregistrer depuis le statut "Refusée"
- print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=save_from_refuse&id='.$object->id.'">'.$langs->trans('ValidateAndSubmit').'</a></div>';
- }
- }
- if ($user->rights->expensereport->to_paid && $object->fk_statut==5)
- {
- if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid)
- {
- // Brouillonner
- print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=brouillonner&id='.$object->id.'">'.$langs->trans('SetToDraft').'</a></div>';
- }
- }
- /* Si l'état est "En attente d'approbation"
- * ET user à droit de "approve"
- * ET fk_user_validator == user courant
- * Afficher : "Valider" / "Refuser" / "Supprimer"
- */
- if ($object->fk_statut == 2)
- {
- if (in_array($object->fk_user_author, $user->getAllChildIds(1)))
- {
- // Brouillonner
- print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=brouillonner&id='.$object->id.'">'.$langs->trans('SetToDraft').'</a></div>';
- }
- }
- if ($user->rights->expensereport->approve && $object->fk_statut == 2)
- {
- //if($object->fk_user_validator==$user->id)
- //{
- // Validate
- print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=validate&id='.$object->id.'">'.$langs->trans('Approve').'</a></div>';
- // Deny
- print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=refuse&id='.$object->id.'">'.$langs->trans('Deny').'</a></div>';
- //}
- if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid)
- {
- // Cancel
- print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=cancel&id='.$object->id.'">'.$langs->trans('Cancel').'</a></div>';
- }
- }
- // If status is Appoved
- // --------------------
-
- if ($user->rights->expensereport->approve && $object->fk_statut == 5)
- {
- print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=refuse&id='.$object->id.'">'.$langs->trans('Deny').'</a></div>';
- }
- // If bank module is used
- if ($user->rights->expensereport->to_paid && ! empty($conf->banque->enabled) && $object->fk_statut == 5)
- {
- // Pay
- if ($remaintopay == 0)
- {
- print '<div class="inline-block divButAction"><span class="butActionRefused" title="' . $langs->trans("DisabledBecauseRemainderToPayIsZero") . '">' . $langs->trans('DoPayment') . '</span></div>';
- }
- else
- {
- print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/expensereport/payment/payment.php?id=' . $object->id . '&action=create">' . $langs->trans('DoPayment') . '</a></div>';
- }
- }
-
- // If bank module is not used
- if (($user->rights->expensereport->to_paid || empty($conf->banque->enabled)) && $object->fk_statut == 5)
- {
- //if ((round($remaintopay) == 0 || empty($conf->banque->enabled)) && $object->paid == 0)
- if ($object->paid == 0)
- {
- print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id='.$object->id.'&action=set_paid">'.$langs->trans("ClassifyPaid")."</a></div>";
- }
- }
-
- if ($user->rights->expensereport->creer && ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) && $object->fk_statut == 5)
- {
- // Cancel
- print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=cancel&id='.$object->id.'">'.$langs->trans('Cancel').'</a></div>';
- }
-
- // TODO Replace this. It should be SetUnpaid and should go back to status unpaid not canceled.
- if (($user->rights->expensereport->approve || $user->rights->expensereport->to_paid) && $object->fk_statut == 6)
- {
- // Cancel
- print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=cancel&id='.$object->id.'">'.$langs->trans('Cancel').'</a></div>';
- }
-
- // Clone
- if ($user->rights->expensereport->creer) {
- print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=clone">' . $langs->trans("ToClone") . '</a></div>';
- }
-
- /* 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->fk_statut <= 4)
- {
- // Delete
- print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?action=delete&id='.$object->id.'">'.$langs->trans('Delete').'</a></div>';
- }
- else if($user->rights->expensereport->supprimer && $object->fk_statut != 6)
- {
- // Delete
- print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?action=delete&id='.$object->id.'">'.$langs->trans('Delete').'</a></div>';
- }
- }
- print '</div>';
- //$conf->global->DOL_URL_ROOT_DOCUMENT_PHP=dol_buildpath('/expensereport/documentwrapper.php',1);
- print '<div class="fichehalfleft">';
- /*
- * Generate documents
- */
- if($user->rights->expensereport->export && $action != 'create' && $action != 'edit')
- {
- $filename = dol_sanitizeFileName($object->ref);
- $filedir = $conf->expensereport->dir_output . "/" . dol_sanitizeFileName($object->ref);
- $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
- $genallowed = 1;
- $delallowed = 1;
- $var = true;
- print $formfile->showdocuments('expensereport',$filename,$filedir,$urlsource,$genallowed,$delallowed);
- $somethingshown = $formfile->numoffiles;
- }
- print '</div>';
- if ($action != 'create' && $action != 'edit' && ($id || $ref))
- {
- $permissiondellink=$user->rights->facture->creer; // Used by the include of actions_dellink.inc.php
- include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once
- // Link invoice to intervention
- if (GETPOST('LinkedFichinter')) {
- $object->fetch($id);
- $object->fetch_thirdparty();
- $result = $object->add_object_linked('fichinter', GETPOST('LinkedFichinter'));
- }
-
- // Show links to link elements
- $linktoelements=array();
- if (! empty($conf->global->EXPENSES_LINK_TO_INTERVENTION))
- {
- $linktoelements[]='fichinter';
- $linktoelem = $form->showLinkToObjectBlock($object, $linktoelements, array('expensereport'));
- $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
- }
- }
- llxFooter();
- $db->close();
|