card.php 126 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023
  1. <?php
  2. /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2022 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
  5. * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
  6. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  7. * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
  8. * Copyright (C) 2010-2023 Juanjo Menent <jmenent@2byte.es>
  9. * Copyright (C) 2010-2022 Philippe Grand <philippe.grand@atoo-net.com>
  10. * Copyright (C) 2012-2013 Christophe Battarel <christophe.battarel@altairis.fr>
  11. * Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
  12. * Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro>
  13. * Copyright (C) 2014 Ferran Marcet <fmarcet@2byte.es>
  14. * Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
  15. * Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.fr>
  16. * Copyright (C) 2020 Nicolas ZABOURI <info@inovea-conseil.com>
  17. * Copyright (C) 2022 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
  18. *
  19. * This program is free software; you can redistribute it and/or modify
  20. * it under the terms of the GNU General Public License as published by
  21. * the Free Software Foundation; either version 3 of the License, or
  22. * (at your option) any later version.
  23. *
  24. * This program is distributed in the hope that it will be useful,
  25. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. * GNU General Public License for more details.
  28. *
  29. * You should have received a copy of the GNU General Public License
  30. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  31. */
  32. /**
  33. * \file htdocs/comm/propal/card.php
  34. * \ingroup propale
  35. * \brief Page of commercial proposals card and list
  36. */
  37. // Load Dolibarr environment
  38. require '../../main.inc.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  40. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  41. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formpropal.class.php';
  42. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmargin.class.php';
  43. require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  44. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  45. require_once DOL_DOCUMENT_ROOT.'/core/modules/propale/modules_propale.php';
  46. require_once DOL_DOCUMENT_ROOT.'/core/lib/propal.lib.php';
  47. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  48. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  49. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  50. if (isModEnabled('project')) {
  51. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  52. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  53. }
  54. if (isModEnabled('variants')) {
  55. require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductCombination.class.php';
  56. }
  57. // Load translation files required by the page
  58. $langs->loadLangs(array('companies', 'propal', 'compta', 'bills', 'orders', 'products', 'deliveries', 'sendings', 'other'));
  59. if (isModEnabled('incoterm')) {
  60. $langs->load('incoterm');
  61. }
  62. if (isModEnabled('margin')) {
  63. $langs->load('margins');
  64. }
  65. $error = 0;
  66. $id = GETPOST('id', 'int');
  67. $ref = GETPOST('ref', 'alpha');
  68. $socid = GETPOST('socid', 'int');
  69. $action = GETPOST('action', 'aZ09');
  70. $cancel = GETPOST('cancel', 'alpha');
  71. $origin = GETPOST('origin', 'alpha');
  72. $originid = GETPOST('originid', 'int');
  73. $confirm = GETPOST('confirm', 'alpha');
  74. $lineid = GETPOST('lineid', 'int');
  75. $contactid = GETPOST('contactid', 'int');
  76. $projectid = GETPOST('projectid', 'int');
  77. $rank = (GETPOST('rank', 'int') > 0) ? GETPOST('rank', 'int') : -1;
  78. // PDF
  79. $hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
  80. $hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
  81. $hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
  82. $object = new Propal($db);
  83. $extrafields = new ExtraFields($db);
  84. // fetch optionals attributes and labels
  85. $extrafields->fetch_name_optionals_label($object->table_element);
  86. // Load object
  87. if ($id > 0 || !empty($ref)) {
  88. $ret = $object->fetch($id, $ref);
  89. if ($ret > 0) {
  90. $ret = $object->fetch_thirdparty();
  91. }
  92. if ($ret <= 0) {
  93. setEventMessages($object->error, $object->errors, 'errors');
  94. $action = '';
  95. }
  96. }
  97. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  98. $hookmanager->initHooks(array('propalcard', 'globalcard'));
  99. $usercanread = $user->hasRight("propal", "lire");
  100. $usercancreate = $user->hasRight("propal", "creer");
  101. $usercandelete = $user->hasRight("propal", "supprimer");
  102. $usercanclose = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->propal->propal_advance->close)));
  103. $usercanvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->propal->propal_advance->validate)));
  104. $usercansend = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->propal->propal_advance->send)));
  105. $usermustrespectpricemin = ((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS));
  106. $usercancreateorder = $user->hasRight('commande', 'creer');
  107. $usercancreateinvoice = $user->hasRight('facture', 'creer');
  108. $usercancreatecontract = $user->hasRight('contrat', 'creer');
  109. $usercancreateintervention = $user->hasRight('ficheinter', 'creer');
  110. $usercancreatepurchaseorder = ($user->hasRight('fournisseur', 'commande', 'creer') || $user->hasRight('supplier_order', 'creer'));
  111. $permissionnote = $usercancreate; // Used by the include of actions_setnotes.inc.php
  112. $permissiondellink = $usercancreate; // Used by the include of actions_dellink.inc.php
  113. $permissiontoedit = $usercancreate; // Used by the include of actions_lineupdown.inc.php
  114. // Security check
  115. if (!empty($user->socid)) {
  116. $socid = $user->socid;
  117. }
  118. restrictedArea($user, 'propal', $object->id);
  119. /*
  120. * Actions
  121. */
  122. $parameters = array('socid' => $socid);
  123. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  124. if ($reshook < 0) {
  125. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  126. }
  127. if (empty($reshook)) {
  128. $backurlforlist = DOL_URL_ROOT.'/comm/propal/list.php';
  129. if (empty($backtopage) || ($cancel && empty($id))) {
  130. if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
  131. if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
  132. $backtopage = $backurlforlist;
  133. } else {
  134. $backtopage = DOL_URL_ROOT.'/comm/propal/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
  135. }
  136. }
  137. }
  138. if ($cancel) {
  139. if (!empty($backtopageforcancel)) {
  140. header("Location: ".$backtopageforcancel);
  141. exit;
  142. } elseif (!empty($backtopage)) {
  143. header("Location: ".$backtopage);
  144. exit;
  145. }
  146. $action = '';
  147. }
  148. include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once
  149. include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once
  150. include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once
  151. // Action clone object
  152. if ($action == 'confirm_clone' && $confirm == 'yes' && $usercancreate) {
  153. if (!GETPOST('socid', 3)) {
  154. setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors');
  155. } else {
  156. if ($object->id > 0) {
  157. if (!empty($conf->global->PROPAL_CLONE_DATE_DELIVERY)) {
  158. //Get difference between old and new delivery date and change lines according to difference
  159. $date_delivery = dol_mktime(
  160. 12,
  161. 0,
  162. 0,
  163. GETPOST('date_deliverymonth', 'int'),
  164. GETPOST('date_deliveryday', 'int'),
  165. GETPOST('date_deliveryyear', 'int')
  166. );
  167. $date_delivery_old = (empty($object->delivery_date) ? $object->date_livraison : $object->delivery_date);
  168. if (!empty($date_delivery_old) && !empty($date_delivery)) {
  169. //Attempt to get the date without possible hour rounding errors
  170. $old_date_delivery = dol_mktime(
  171. 12,
  172. 0,
  173. 0,
  174. dol_print_date($date_delivery_old, '%m'),
  175. dol_print_date($date_delivery_old, '%d'),
  176. dol_print_date($date_delivery_old, '%Y')
  177. );
  178. //Calculate the difference and apply if necessary
  179. $difference = $date_delivery - $old_date_delivery;
  180. if ($difference != 0) {
  181. $object->date_livraison = $date_delivery;
  182. $object->delivery_date = $date_delivery;
  183. foreach ($object->lines as $line) {
  184. if (isset($line->date_start)) {
  185. $line->date_start = $line->date_start + $difference;
  186. }
  187. if (isset($line->date_end)) {
  188. $line->date_end = $line->date_end + $difference;
  189. }
  190. }
  191. }
  192. }
  193. }
  194. $result = $object->createFromClone($user, $socid, (GETPOSTISSET('entity') ? GETPOST('entity', 'int') : null), (GETPOST('update_prices', 'aZ') ? true : false));
  195. if ($result > 0) {
  196. header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
  197. exit();
  198. } else {
  199. if (count($object->errors) > 0) {
  200. setEventMessages($object->error, $object->errors, 'errors');
  201. }
  202. $action = '';
  203. }
  204. }
  205. }
  206. } elseif ($action == 'confirm_delete' && $confirm == 'yes' && $usercandelete) {
  207. // Delete proposal
  208. $result = $object->delete($user);
  209. if ($result > 0) {
  210. header('Location: '.DOL_URL_ROOT.'/comm/propal/list.php?restore_lastsearch_values=1');
  211. exit();
  212. } else {
  213. $langs->load("errors");
  214. setEventMessages($object->error, $object->errors, 'errors');
  215. }
  216. } elseif ($action == 'confirm_deleteline' && $confirm == 'yes' && $usercancreate) {
  217. // Remove line
  218. $result = $object->deleteline($lineid);
  219. // reorder lines
  220. if ($result > 0) {
  221. $object->line_order(true);
  222. } else {
  223. $langs->load("errors");
  224. setEventMessages($object->error, $object->errors, 'errors');
  225. }
  226. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  227. // Define output language
  228. $outputlangs = $langs;
  229. if (getDolGlobalInt('MAIN_MULTILANGS')) {
  230. $outputlangs = new Translate("", $conf);
  231. $newlang = (GETPOST('lang_id', 'aZ09') ? GETPOST('lang_id', 'aZ09') : $object->thirdparty->default_lang);
  232. $outputlangs->setDefaultLang($newlang);
  233. }
  234. $ret = $object->fetch($id); // Reload to get new records
  235. if ($ret > 0) {
  236. $object->fetch_thirdparty();
  237. }
  238. $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  239. }
  240. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  241. exit();
  242. } elseif ($action == 'confirm_validate' && $confirm == 'yes' && $usercanvalidate) {
  243. // Validation
  244. $idwarehouse = GETPOST('idwarehouse', 'int');
  245. $result = $object->valid($user);
  246. if ( $result > 0 && ! empty($conf->global->PROPAL_SKIP_ACCEPT_REFUSE) ) {
  247. $result = $object->closeProposal($user, $object::STATUS_SIGNED);
  248. }
  249. if ($result >= 0) {
  250. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  251. $outputlangs = $langs;
  252. $newlang = '';
  253. if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
  254. $newlang = GETPOST('lang_id', 'aZ09');
  255. }
  256. if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
  257. $newlang = $object->thirdparty->default_lang;
  258. }
  259. if (!empty($newlang)) {
  260. $outputlangs = new Translate("", $conf);
  261. $outputlangs->setDefaultLang($newlang);
  262. }
  263. $model = $object->model_pdf;
  264. $ret = $object->fetch($id); // Reload to get new records
  265. if ($ret > 0) {
  266. $object->fetch_thirdparty();
  267. }
  268. $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
  269. }
  270. } else {
  271. $langs->load("errors");
  272. if (count($object->errors) > 0) {
  273. setEventMessages($object->error, $object->errors, 'errors');
  274. } else {
  275. setEventMessages($langs->trans($object->error), null, 'errors');
  276. }
  277. }
  278. } elseif ($action == 'setdate' && $usercancreate) {
  279. $datep = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
  280. if (empty($datep)) {
  281. $error++;
  282. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
  283. }
  284. if (!$error) {
  285. $result = $object->set_date($user, $datep);
  286. if ($result > 0 && !empty($object->duree_validite) && !empty($object->fin_validite)) {
  287. $datev = $datep + ($object->duree_validite * 24 * 3600);
  288. $result = $object->set_echeance($user, $datev, 1);
  289. }
  290. if ($result < 0) {
  291. dol_print_error($db, $object->error);
  292. } elseif (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  293. $outputlangs = $langs;
  294. $newlang = '';
  295. if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
  296. if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) $newlang = $object->thirdparty->default_lang;
  297. if (!empty($newlang)) {
  298. $outputlangs = new Translate("", $conf);
  299. $outputlangs->setDefaultLang($newlang);
  300. }
  301. $model = $object->model_pdf;
  302. $ret = $object->fetch($id); // Reload to get new records
  303. if ($ret > 0) {
  304. $object->fetch_thirdparty();
  305. }
  306. $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
  307. }
  308. }
  309. } elseif ($action == 'setecheance' && $usercancreate) {
  310. $result = $object->set_echeance($user, dol_mktime(12, 0, 0, GETPOST('echmonth', 'int'), GETPOST('echday', 'int'), GETPOST('echyear', 'int')));
  311. if ($result >= 0) {
  312. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  313. $outputlangs = $langs;
  314. $newlang = '';
  315. if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
  316. if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) $newlang = $object->thirdparty->default_lang;
  317. if (!empty($newlang)) {
  318. $outputlangs = new Translate("", $conf);
  319. $outputlangs->setDefaultLang($newlang);
  320. }
  321. $model = $object->model_pdf;
  322. $ret = $object->fetch($id); // Reload to get new records
  323. if ($ret > 0) {
  324. $object->fetch_thirdparty();
  325. }
  326. $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
  327. }
  328. } else {
  329. setEventMessages($object->error, $object->errors, 'errors');
  330. }
  331. } elseif ($action == 'setdate_livraison' && $usercancreate) {
  332. $result = $object->setDeliveryDate($user, dol_mktime(12, 0, 0, GETPOST('date_livraisonmonth', 'int'), GETPOST('date_livraisonday', 'int'), GETPOST('date_livraisonyear', 'int')));
  333. if ($result < 0) {
  334. dol_print_error($db, $object->error);
  335. }
  336. } elseif ($action == 'setref_client' && $usercancreate) {
  337. // Positionne ref client
  338. $result = $object->set_ref_client($user, GETPOST('ref_client'));
  339. if ($result < 0) {
  340. setEventMessages($object->error, $object->errors, 'errors');
  341. }
  342. } elseif ($action == 'set_incoterms' && isModEnabled('incoterm') && $usercancreate) {
  343. // Set incoterm
  344. $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha'));
  345. } elseif ($action == 'add' && $usercancreate) {
  346. // Create proposal
  347. $object->socid = $socid;
  348. $object->fetch_thirdparty();
  349. $datep = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
  350. $date_delivery = dol_mktime(12, 0, 0, GETPOST('date_livraisonmonth'), GETPOST('date_livraisonday'), GETPOST('date_livraisonyear'));
  351. $duration = GETPOST('duree_validite', 'int');
  352. if (empty($datep)) {
  353. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DatePropal")), null, 'errors');
  354. $action = 'create';
  355. $error++;
  356. }
  357. if (empty($duration)) {
  358. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ValidityDuration")), null, 'errors');
  359. $action = 'create';
  360. $error++;
  361. }
  362. if ($socid < 1) {
  363. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Customer")), null, 'errors');
  364. $action = 'create';
  365. $error++;
  366. }
  367. if (!$error) {
  368. $db->begin();
  369. // If we select proposal to clone during creation (when option PROPAL_CLONE_ON_CREATE_PAGE is on)
  370. if (GETPOST('createmode') == 'copy' && GETPOST('copie_propal')) {
  371. if ($object->fetch(GETPOST('copie_propal', 'int')) > 0) {
  372. $object->ref = GETPOST('ref');
  373. $object->datep = $datep;
  374. $object->date = $datep;
  375. $object->date_livraison = $date_delivery; // deprecated
  376. $object->delivery_date = $date_delivery;
  377. $object->availability_id = GETPOST('availability_id');
  378. $object->demand_reason_id = GETPOST('demand_reason_id');
  379. $object->fk_delivery_address = GETPOST('fk_address', 'int');
  380. $object->shipping_method_id = GETPOST('shipping_method_id', 'int');
  381. $object->warehouse_id = GETPOST('warehouse_id', 'int');
  382. $object->duree_validite = $duration;
  383. $object->cond_reglement_id = GETPOST('cond_reglement_id');
  384. $object->deposit_percent = GETPOST('cond_reglement_id_deposit_percent', 'alpha');
  385. $object->mode_reglement_id = GETPOST('mode_reglement_id');
  386. $object->fk_account = GETPOST('fk_account', 'int');
  387. $object->remise_absolue = price2num(GETPOST('remise_absolue'), 'MU', 2); // deprecated
  388. $object->remise_percent = price2num(GETPOST('remise_percent'), '', 2);
  389. $object->socid = GETPOST('socid', 'int');
  390. $object->contact_id = GETPOST('contactid', 'int');
  391. $object->fk_project = GETPOST('projectid', 'int');
  392. $object->model_pdf = GETPOST('model', 'alphanohtml');
  393. $object->author = $user->id; // deprecated
  394. $object->user_author_id = $user->id;
  395. $object->note_private = GETPOST('note_private', 'restricthtml');
  396. $object->note_public = GETPOST('note_public', 'restricthtml');
  397. $object->statut = Propal::STATUS_DRAFT;
  398. $object->fk_incoterms = GETPOST('incoterm_id', 'int');
  399. $object->location_incoterms = GETPOST('location_incoterms', 'alpha');
  400. } else {
  401. setEventMessages($langs->trans("ErrorFailedToCopyProposal", GETPOST('copie_propal')), null, 'errors');
  402. }
  403. } else {
  404. $object->ref = GETPOST('ref');
  405. $object->ref_client = GETPOST('ref_client');
  406. $object->datep = $datep;
  407. $object->date = $datep;
  408. $object->date_livraison = $date_delivery;
  409. $object->delivery_date = $date_delivery;
  410. $object->availability_id = GETPOST('availability_id', 'int');
  411. $object->demand_reason_id = GETPOST('demand_reason_id', 'int');
  412. $object->fk_delivery_address = GETPOST('fk_address', 'int');
  413. $object->shipping_method_id = GETPOST('shipping_method_id', 'int');
  414. $object->warehouse_id = GETPOST('warehouse_id', 'int');
  415. $object->duree_validite = price2num(GETPOST('duree_validite', 'alpha'));
  416. $object->cond_reglement_id = GETPOST('cond_reglement_id', 'int');
  417. $object->deposit_percent = GETPOST('cond_reglement_id_deposit_percent', 'alpha');
  418. $object->mode_reglement_id = GETPOST('mode_reglement_id', 'int');
  419. $object->fk_account = GETPOST('fk_account', 'int');
  420. $object->contact_id = GETPOST('contactid', 'int');
  421. $object->fk_project = GETPOST('projectid', 'int');
  422. $object->model_pdf = GETPOST('model');
  423. $object->author = $user->id; // deprecated
  424. $object->note_private = GETPOST('note_private', 'restricthtml');
  425. $object->note_public = GETPOST('note_public', 'restricthtml');
  426. $object->fk_incoterms = GETPOST('incoterm_id', 'int');
  427. $object->location_incoterms = GETPOST('location_incoterms', 'alpha');
  428. $object->origin = GETPOST('origin');
  429. $object->origin_id = GETPOST('originid');
  430. // Multicurrency
  431. if (isModEnabled("multicurrency")) {
  432. $object->multicurrency_code = GETPOST('multicurrency_code', 'alpha');
  433. }
  434. // Fill array 'array_options' with data from add form
  435. $ret = $extrafields->setOptionalsFromPost(null, $object);
  436. if ($ret < 0) {
  437. $error++;
  438. $action = 'create';
  439. }
  440. }
  441. if (!$error) {
  442. if ($origin && $originid) {
  443. // Parse element/subelement (ex: project_task)
  444. $element = $subelement = $origin;
  445. if (preg_match('/^([^_]+)_([^_]+)/i', $origin, $regs)) {
  446. $element = $regs [1];
  447. $subelement = $regs [2];
  448. }
  449. // For compatibility
  450. if ($element == 'order') {
  451. $element = $subelement = 'commande';
  452. }
  453. if ($element == 'propal') {
  454. $element = 'comm/propal';
  455. $subelement = 'propal';
  456. }
  457. if ($element == 'contract') {
  458. $element = $subelement = 'contrat';
  459. }
  460. if ($element == 'inter') {
  461. $element = $subelement = 'ficheinter';
  462. }
  463. if ($element == 'shipping') {
  464. $element = $subelement = 'expedition';
  465. }
  466. $object->origin = $origin;
  467. $object->origin_id = $originid;
  468. // Possibility to add external linked objects with hooks
  469. $object->linked_objects [$object->origin] = $object->origin_id;
  470. if (is_array($_POST['other_linked_objects']) && !empty($_POST['other_linked_objects'])) {
  471. $object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']);
  472. }
  473. $id = $object->create($user);
  474. if ($id > 0) {
  475. dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
  476. $classname = ucfirst($subelement);
  477. $srcobject = new $classname($db);
  478. dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add lines");
  479. $result = $srcobject->fetch($object->origin_id);
  480. if ($result > 0) {
  481. $lines = $srcobject->lines;
  482. if (empty($lines) && method_exists($srcobject, 'fetch_lines')) {
  483. $srcobject->fetch_lines();
  484. $lines = $srcobject->lines;
  485. }
  486. $fk_parent_line = 0;
  487. $num = count($lines);
  488. for ($i = 0; $i < $num; $i++) {
  489. $label = (!empty($lines[$i]->label) ? $lines[$i]->label : '');
  490. $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc : $lines[$i]->libelle);
  491. // Positive line
  492. $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
  493. // Date start
  494. $date_start = false;
  495. if ($lines[$i]->date_debut_prevue) {
  496. $date_start = $lines[$i]->date_debut_prevue;
  497. }
  498. if ($lines[$i]->date_debut_reel) {
  499. $date_start = $lines[$i]->date_debut_reel;
  500. }
  501. if ($lines[$i]->date_start) {
  502. $date_start = $lines[$i]->date_start;
  503. }
  504. // Date end
  505. $date_end = false;
  506. if ($lines[$i]->date_fin_prevue) {
  507. $date_end = $lines[$i]->date_fin_prevue;
  508. }
  509. if ($lines[$i]->date_fin_reel) {
  510. $date_end = $lines[$i]->date_fin_reel;
  511. }
  512. if ($lines[$i]->date_end) {
  513. $date_end = $lines[$i]->date_end;
  514. }
  515. // Reset fk_parent_line for no child products and special product
  516. if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
  517. $fk_parent_line = 0;
  518. }
  519. // Extrafields
  520. if (method_exists($lines[$i], 'fetch_optionals')) {
  521. $lines[$i]->fetch_optionals();
  522. $array_options = $lines[$i]->array_options;
  523. }
  524. $tva_tx = $lines[$i]->tva_tx;
  525. if (!empty($lines[$i]->vat_src_code) && !preg_match('/\(/', $tva_tx)) {
  526. $tva_tx .= ' ('.$lines[$i]->vat_src_code.')';
  527. }
  528. $result = $object->addline($desc, $lines[$i]->subprice, $lines[$i]->qty, $tva_tx, $lines[$i]->localtax1_tx, $lines[$i]->localtax2_tx, $lines[$i]->fk_product, $lines[$i]->remise_percent, 'HT', 0, $lines[$i]->info_bits, $product_type, $lines[$i]->rang, $lines[$i]->special_code, $fk_parent_line, $lines[$i]->fk_fournprice, $lines[$i]->pa_ht, $label, $date_start, $date_end, $array_options, $lines[$i]->fk_unit);
  529. if ($result > 0) {
  530. $lineid = $result;
  531. } else {
  532. $lineid = 0;
  533. $error++;
  534. break;
  535. }
  536. // Defined the new fk_parent_line
  537. if ($result > 0 && $lines[$i]->product_type == 9) {
  538. $fk_parent_line = $result;
  539. }
  540. }
  541. // Hooks
  542. $parameters = array('objFrom' => $srcobject);
  543. $reshook = $hookmanager->executeHooks('createFrom', $parameters, $object, $action); // Note that $action and $object may have been
  544. // modified by hook
  545. if ($reshook < 0) {
  546. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  547. $error++;
  548. }
  549. } else {
  550. setEventMessages($srcobject->error, $srcobject->errors, 'errors');
  551. $error++;
  552. }
  553. } else {
  554. setEventMessages($object->error, $object->errors, 'errors');
  555. $error++;
  556. }
  557. } else {
  558. // Standard creation
  559. $id = $object->create($user);
  560. }
  561. if ($id > 0) {
  562. // Insert default contacts if defined
  563. if (GETPOST('contactid') > 0) {
  564. $result = $object->add_contact(GETPOST('contactid'), 'CUSTOMER', 'external');
  565. if ($result < 0) {
  566. $error++;
  567. setEventMessages($langs->trans("ErrorFailedToAddContact"), null, 'errors');
  568. }
  569. }
  570. if (!empty($conf->global->PROPOSAL_AUTO_ADD_AUTHOR_AS_CONTACT)) {
  571. $result = $object->add_contact($user->id, 'SALESREPFOLL', 'internal');
  572. if ($result < 0) {
  573. $error++;
  574. setEventMessages($langs->trans("ErrorFailedToAddUserAsContact"), null, 'errors');
  575. }
  576. }
  577. if (!$error) {
  578. $db->commit();
  579. // Define output language
  580. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  581. $outputlangs = $langs;
  582. $newlang = '';
  583. if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
  584. $newlang = GETPOST('lang_id', 'aZ09');
  585. }
  586. if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
  587. $newlang = $object->thirdparty->default_lang;
  588. }
  589. if (!empty($newlang)) {
  590. $outputlangs = new Translate("", $conf);
  591. $outputlangs->setDefaultLang($newlang);
  592. }
  593. $model = $object->model_pdf;
  594. $ret = $object->fetch($id); // Reload to get new records
  595. $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
  596. if ($result < 0) {
  597. dol_print_error($db, $result);
  598. }
  599. }
  600. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
  601. exit();
  602. } else {
  603. $db->rollback();
  604. $action = 'create';
  605. }
  606. } else {
  607. setEventMessages($object->error, $object->errors, 'errors');
  608. $db->rollback();
  609. $action = 'create';
  610. }
  611. }
  612. }
  613. } elseif ($action == 'classifybilled' && $usercanclose) {
  614. // Classify billed
  615. $db->begin();
  616. $result = $object->classifyBilled($user, 0, '');
  617. if ($result < 0) {
  618. setEventMessages($object->error, $object->errors, 'errors');
  619. $error++;
  620. }
  621. if (!$error) {
  622. $db->commit();
  623. } else {
  624. $db->rollback();
  625. }
  626. } elseif ($action == 'confirm_closeas' && $usercanclose && !GETPOST('cancel', 'alpha')) {
  627. // Close proposal
  628. if (!(GETPOST('statut', 'int') > 0)) {
  629. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CloseAs")), null, 'errors');
  630. $action = 'closeas';
  631. } elseif (GETPOST('statut', 'int') == $object::STATUS_SIGNED || GETPOST('statut', 'int') == $object::STATUS_NOTSIGNED) {
  632. // prevent browser refresh from closing proposal several times
  633. if ($object->statut == $object::STATUS_VALIDATED || ( ! empty($conf->global->PROPAL_SKIP_ACCEPT_REFUSE) && $object->statut == $object::STATUS_DRAFT)) {
  634. $db->begin();
  635. $result = $object->closeProposal($user, GETPOST('statut', 'int'), GETPOST('note_private', 'restricthtml'));
  636. if ($result < 0) {
  637. setEventMessages($object->error, $object->errors, 'errors');
  638. $error++;
  639. }
  640. $deposit = null;
  641. $locationTarget = '';
  642. $deposit_percent_from_payment_terms = getDictionaryValue('c_payment_term', 'deposit_percent', $object->cond_reglement_id);
  643. if (
  644. !$error && GETPOST('statut', 'int') == $object::STATUS_SIGNED && GETPOST('generate_deposit', 'alpha') == 'on'
  645. && !empty($deposit_percent_from_payment_terms) && isModEnabled('facture') && !empty($user->rights->facture->creer)
  646. ) {
  647. require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
  648. $date = dol_mktime(0, 0, 0, GETPOST('datefmonth', 'int'), GETPOST('datefday', 'int'), GETPOST('datefyear', 'int'));
  649. $forceFields = array();
  650. if (GETPOSTISSET('date_pointoftax')) {
  651. $forceFields['date_pointoftax'] = dol_mktime(0, 0, 0, GETPOST('date_pointoftaxmonth', 'int'), GETPOST('date_pointoftaxday', 'int'), GETPOST('date_pointoftaxyear', 'int'));
  652. }
  653. $deposit = Facture::createDepositFromOrigin($object, $date, GETPOST('cond_reglement_id', 'int'), $user, 0, GETPOST('validate_generated_deposit', 'alpha') == 'on', $forceFields);
  654. if ($deposit) {
  655. setEventMessage('DepositGenerated');
  656. $locationTarget = DOL_URL_ROOT . '/compta/facture/card.php?id=' . $deposit->id;
  657. } else {
  658. $error++;
  659. setEventMessages($object->error, $object->errors, 'errors');
  660. }
  661. }
  662. if (!$error) {
  663. $db->commit();
  664. if ($deposit && empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  665. $ret = $deposit->fetch($deposit->id); // Reload to get new records
  666. $outputlangs = $langs;
  667. if (getDolGlobalInt('MAIN_MULTILANGS')) {
  668. $outputlangs = new Translate('', $conf);
  669. $outputlangs->setDefaultLang($deposit->thirdparty->default_lang);
  670. $outputlangs->load('products');
  671. }
  672. $result = $deposit->generateDocument($deposit->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  673. if ($result < 0) {
  674. setEventMessages($deposit->error, $deposit->errors, 'errors');
  675. }
  676. }
  677. if ($locationTarget) {
  678. header('Location: ' . $locationTarget);
  679. exit;
  680. }
  681. } else {
  682. $db->rollback();
  683. $action = '';
  684. }
  685. }
  686. }
  687. } elseif ($action == 'confirm_reopen' && $usercanclose && !GETPOST('cancel', 'alpha')) {
  688. // Reopen proposal
  689. // prevent browser refresh from reopening proposal several times
  690. if ($object->statut == Propal::STATUS_SIGNED || $object->statut == Propal::STATUS_NOTSIGNED || $object->statut == Propal::STATUS_BILLED) {
  691. $db->begin();
  692. $result = $object->reopen($user, empty($conf->global->PROPAL_SKIP_ACCEPT_REFUSE));
  693. if ($result < 0) {
  694. setEventMessages($object->error, $object->errors, 'errors');
  695. $error++;
  696. }
  697. if (!$error) {
  698. $db->commit();
  699. } else {
  700. $db->rollback();
  701. }
  702. }
  703. } elseif ($action == 'import_lines_from_object'
  704. && $user->rights->propal->creer
  705. && $object->statut == Propal::STATUS_DRAFT
  706. ) {
  707. // add lines from objectlinked
  708. $fromElement = GETPOST('fromelement');
  709. $fromElementid = GETPOST('fromelementid');
  710. $importLines = GETPOST('line_checkbox');
  711. if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) {
  712. if ($fromElement == 'commande') {
  713. dol_include_once('/'.$fromElement.'/class/'.$fromElement.'.class.php');
  714. $lineClassName = 'OrderLine';
  715. } elseif ($fromElement == 'propal') {
  716. dol_include_once('/comm/'.$fromElement.'/class/'.$fromElement.'.class.php');
  717. $lineClassName = 'PropaleLigne';
  718. }
  719. $nextRang = count($object->lines) + 1;
  720. $importCount = 0;
  721. $error = 0;
  722. foreach ($importLines as $lineId) {
  723. $lineId = intval($lineId);
  724. $originLine = new $lineClassName($db);
  725. if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) {
  726. $originLine->fetch_optionals();
  727. $desc = $originLine->desc;
  728. $pu_ht = $originLine->subprice;
  729. $qty = $originLine->qty;
  730. $txtva = $originLine->tva_tx;
  731. $txlocaltax1 = $originLine->localtax1_tx;
  732. $txlocaltax2 = $originLine->localtax2_tx;
  733. $fk_product = $originLine->fk_product;
  734. $remise_percent = $originLine->remise_percent;
  735. $date_start = $originLine->date_start;
  736. $date_end = $originLine->date_end;
  737. $ventil = 0;
  738. $info_bits = $originLine->info_bits;
  739. $fk_remise_except = $originLine->fk_remise_except;
  740. $price_base_type = 'HT';
  741. $pu_ttc = 0;
  742. $type = $originLine->product_type;
  743. $rang = $nextRang++;
  744. $special_code = $originLine->special_code;
  745. $origin = $originLine->element;
  746. $origin_id = $originLine->id;
  747. $fk_parent_line = 0;
  748. $fk_fournprice = $originLine->fk_fournprice;
  749. $pa_ht = $originLine->pa_ht;
  750. $label = $originLine->label;
  751. $array_options = $originLine->array_options;
  752. $situation_percent = 100;
  753. $fk_prev_id = '';
  754. $fk_unit = $originLine->fk_unit;
  755. $pu_ht_devise = $originLine->multicurrency_subprice;
  756. $res = $object->addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1, $txlocaltax2, $fk_product, $remise_percent, $price_base_type, $pu_ttc, $info_bits, $type, $rang, $special_code, $fk_parent_line, $fk_fournprice, $pa_ht, $label, $date_start, $date_end, $array_options, $fk_unit, $origin, $origin_id, $pu_ht_devise, $fk_remise_except);
  757. if ($res > 0) {
  758. $importCount++;
  759. } else {
  760. $error++;
  761. }
  762. } else {
  763. $error++;
  764. }
  765. }
  766. if ($error) {
  767. setEventMessages($langs->trans('ErrorsOnXLines', $error), null, 'errors');
  768. }
  769. }
  770. }
  771. include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
  772. // Actions to send emails
  773. $actiontypecode = 'AC_OTH_AUTO';
  774. $triggersendname = 'PROPAL_SENTBYMAIL';
  775. $autocopy = 'MAIN_MAIL_AUTOCOPY_PROPOSAL_TO';
  776. $trackid = 'pro'.$object->id;
  777. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  778. // Go back to draft
  779. if ($action == 'modif' && $usercancreate) {
  780. $object->setDraft($user);
  781. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  782. // Define output language
  783. $outputlangs = $langs;
  784. if (getDolGlobalInt('MAIN_MULTILANGS')) {
  785. $outputlangs = new Translate("", $conf);
  786. $newlang = (GETPOST('lang_id', 'aZ09') ? GETPOST('lang_id', 'aZ09') : $object->thirdparty->default_lang);
  787. $outputlangs->setDefaultLang($newlang);
  788. }
  789. $ret = $object->fetch($id); // Reload to get new records
  790. if ($ret > 0) {
  791. $object->fetch_thirdparty();
  792. }
  793. $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  794. }
  795. } elseif ($action == "setabsolutediscount" && $usercancreate) {
  796. if (GETPOST("remise_id", "int")) {
  797. if ($object->id > 0) {
  798. $result = $object->insert_discount(GETPOST("remise_id", "int"));
  799. if ($result < 0) {
  800. setEventMessages($object->error, $object->errors, 'errors');
  801. }
  802. }
  803. }
  804. } elseif ($action == 'addline' && GETPOST('submitforalllines', 'alpha') && GETPOST('vatforalllines', 'alpha') !== '' && $usercancreate) {
  805. // Define a vat_rate for all lines
  806. $vat_rate = (GETPOST('vatforalllines') ? GETPOST('vatforalllines') : 0);
  807. $vat_rate = str_replace('*', '', $vat_rate);
  808. $localtax1_rate = get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
  809. $localtax2_rate = get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
  810. foreach ($object->lines as $line) {
  811. $result = $object->updateline($line->id, $line->subprice, $line->qty, $line->remise_percent, $vat_rate, $localtax1_rate, $localtax2_rate, $line->desc, 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice);
  812. }
  813. } elseif ($action == 'addline' && GETPOST('submitforalllines', 'alpha') && GETPOST('remiseforalllines', 'alpha') !== '' && $usercancreate) {
  814. // Define a discount for all lines
  815. $remise_percent = (GETPOST('remiseforalllines') ? GETPOST('remiseforalllines') : 0);
  816. $remise_percent = str_replace('*', '', $remise_percent);
  817. foreach ($object->lines as $line) {
  818. $result = $object->updateline($line->id, $line->subprice, $line->qty, $remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line->desc, 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice);
  819. }
  820. } elseif ($action == 'addline' && $usercancreate) { // Add line
  821. // Set if we used free entry or predefined product
  822. $predef = '';
  823. $product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : '');
  824. $price_ht = '';
  825. $price_ht_devise = '';
  826. $price_ttc = '';
  827. $price_ttc_devise = '';
  828. // TODO Implement if (getDolGlobalInt('MAIN_UNIT_PRICE_WITH_TAX_IS_FOR_ALL_TAXES'))
  829. if (GETPOST('price_ht') !== '') {
  830. $price_ht = price2num(GETPOST('price_ht'), 'MU', 2);
  831. }
  832. if (GETPOST('multicurrency_price_ht') !== '') {
  833. $price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CU', 2);
  834. }
  835. if (GETPOST('price_ttc') !== '') {
  836. $price_ttc = price2num(GETPOST('price_ttc'), 'MU', 2);
  837. }
  838. if (GETPOST('multicurrency_price_ttc') !== '') {
  839. $price_ttc_devise = price2num(GETPOST('multicurrency_price_ttc'), 'CU', 2);
  840. }
  841. $prod_entry_mode = GETPOST('prod_entry_mode', 'aZ09');
  842. if ($prod_entry_mode == 'free') {
  843. $idprod = 0;
  844. $tva_tx = (GETPOSTISSET('tva_tx') ? GETPOST('tva_tx', 'alpha') : 0);
  845. } else {
  846. $idprod = GETPOST('idprod', 'int');
  847. $tva_tx = '';
  848. }
  849. $qty = price2num(GETPOST('qty'.$predef, 'alpha'), 'MS', 2);
  850. $remise_percent = (GETPOSTISSET('remise_percent'.$predef) ? price2num(GETPOST('remise_percent'.$predef, 'alpha'), '', 2) : 0);
  851. if (empty($remise_percent)) {
  852. $remise_percent = 0;
  853. }
  854. // Extrafields
  855. $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
  856. $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
  857. // Unset extrafield
  858. if (is_array($extralabelsline)) {
  859. // Get extra fields
  860. foreach ($extralabelsline as $key => $value) {
  861. unset($_POST["options_".$key]);
  862. }
  863. }
  864. if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && GETPOST('type') < 0) {
  865. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
  866. $error++;
  867. }
  868. if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && $price_ht === '' && $price_ht_devise === '' && $price_ttc === '' && $price_ttc_devise === '') { // Unit price can be 0 but not ''. Also price can be negative for proposal.
  869. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("UnitPriceHT")), null, 'errors');
  870. $error++;
  871. }
  872. if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && empty($product_desc)) {
  873. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Description")), null, 'errors');
  874. $error++;
  875. }
  876. if (!$error && isModEnabled('variants') && $prod_entry_mode != 'free') {
  877. if ($combinations = GETPOST('combinations', 'array')) {
  878. //Check if there is a product with the given combination
  879. $prodcomb = new ProductCombination($db);
  880. if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
  881. $idprod = $res->fk_product_child;
  882. } else {
  883. setEventMessages($langs->trans('ErrorProductCombinationNotFound'), null, 'errors');
  884. $error++;
  885. }
  886. }
  887. }
  888. if (!$error && ($qty >= 0) && (!empty($product_desc) || (!empty($idprod) && $idprod > 0))) {
  889. $pu_ht = 0;
  890. $pu_ttc = 0;
  891. $price_min = 0;
  892. $price_min_ttc = 0;
  893. $price_base_type = (GETPOST('price_base_type', 'alpha') ? GETPOST('price_base_type', 'alpha') : 'HT');
  894. $db->begin();
  895. // $tva_tx can be 'x.x (XXX)'
  896. // Ecrase $pu par celui du produit
  897. // Ecrase $desc par celui du produit
  898. // Ecrase $tva_tx par celui du produit
  899. // Replaces $fk_unit with the product unit
  900. if (!empty($idprod) && $idprod > 0) {
  901. $prod = new Product($db);
  902. $prod->fetch($idprod);
  903. $label = ((GETPOST('product_label') && GETPOST('product_label') != $prod->label) ? GETPOST('product_label') : '');
  904. // Update if prices fields are defined
  905. $tva_tx = get_default_tva($mysoc, $object->thirdparty, $prod->id);
  906. $tva_npr = get_default_npr($mysoc, $object->thirdparty, $prod->id);
  907. if (empty($tva_tx)) {
  908. $tva_npr = 0;
  909. }
  910. // Price unique per product
  911. $pu_ht = $prod->price;
  912. $pu_ttc = $prod->price_ttc;
  913. $price_min = $prod->price_min;
  914. $price_min_ttc = $prod->price_min_ttc;
  915. $price_base_type = $prod->price_base_type;
  916. // If price per segment
  917. if (!empty($conf->global->PRODUIT_MULTIPRICES) && $object->thirdparty->price_level) {
  918. $pu_ht = $prod->multiprices[$object->thirdparty->price_level];
  919. $pu_ttc = $prod->multiprices_ttc[$object->thirdparty->price_level];
  920. $price_min = $prod->multiprices_min[$object->thirdparty->price_level];
  921. $price_min_ttc = $prod->multiprices_min_ttc[$object->thirdparty->price_level];
  922. $price_base_type = $prod->multiprices_base_type[$object->thirdparty->price_level];
  923. if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) { // using this option is a bug. kept for backward compatibility
  924. if (isset($prod->multiprices_tva_tx[$object->thirdparty->price_level])) {
  925. $tva_tx = $prod->multiprices_tva_tx[$object->thirdparty->price_level];
  926. }
  927. if (isset($prod->multiprices_recuperableonly[$object->thirdparty->price_level])) {
  928. $tva_npr = $prod->multiprices_recuperableonly[$object->thirdparty->price_level];
  929. }
  930. }
  931. } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
  932. // If price per customer
  933. require_once DOL_DOCUMENT_ROOT.'/product/class/productcustomerprice.class.php';
  934. $prodcustprice = new Productcustomerprice($db);
  935. $filter = array('t.fk_product' => $prod->id, 't.fk_soc' => $object->thirdparty->id);
  936. $result = $prodcustprice->fetchAll('', '', 0, 0, $filter);
  937. if ($result) {
  938. // If there is some prices specific to the customer
  939. if (count($prodcustprice->lines) > 0) {
  940. $pu_ht = price($prodcustprice->lines[0]->price);
  941. $pu_ttc = price($prodcustprice->lines[0]->price_ttc);
  942. $price_min = price($prodcustprice->lines[0]->price_min);
  943. $price_min_ttc = price($prodcustprice->lines[0]->price_min_ttc);
  944. $price_base_type = $prodcustprice->lines[0]->price_base_type;
  945. $tva_tx = ($prodcustprice->lines[0]->default_vat_code ? $prodcustprice->lines[0]->tva_tx.' ('.$prodcustprice->lines[0]->default_vat_code.' )' : $prodcustprice->lines[0]->tva_tx);
  946. if ($prodcustprice->lines[0]->default_vat_code && !preg_match('/\(.*\)/', $tva_tx)) {
  947. $tva_tx .= ' ('.$prodcustprice->lines[0]->default_vat_code.')';
  948. }
  949. $tva_npr = $prodcustprice->lines[0]->recuperableonly;
  950. if (empty($tva_tx)) {
  951. $tva_npr = 0;
  952. }
  953. }
  954. }
  955. } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) {
  956. // If price per quantity
  957. if ($prod->prices_by_qty[0]) { // yes, this product has some prices per quantity
  958. // Search the correct price into loaded array product_price_by_qty using id of array retrieved into POST['pqp'].
  959. $pqp = GETPOST('pbq', 'int');
  960. // Search price into product_price_by_qty from $prod->id
  961. foreach ($prod->prices_by_qty_list[0] as $priceforthequantityarray) {
  962. if ($priceforthequantityarray['rowid'] != $pqp) {
  963. continue;
  964. }
  965. // We found the price
  966. if ($priceforthequantityarray['price_base_type'] == 'HT') {
  967. $pu_ht = $priceforthequantityarray['unitprice'];
  968. } else {
  969. $pu_ttc = $priceforthequantityarray['unitprice'];
  970. }
  971. // Note: the remise_percent or price by qty is used to set data on form, so we will use value from POST.
  972. break;
  973. }
  974. }
  975. } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
  976. // If price per quantity and customer
  977. if ($prod->prices_by_qty[$object->thirdparty->price_level]) { // yes, this product has some prices per quantity
  978. // Search the correct price into loaded array product_price_by_qty using id of array retrieved into POST['pqp'].
  979. $pqp = GETPOST('pbq', 'int');
  980. // Search price into product_price_by_qty from $prod->id
  981. foreach ($prod->prices_by_qty_list[$object->thirdparty->price_level] as $priceforthequantityarray) {
  982. if ($priceforthequantityarray['rowid'] != $pqp) {
  983. continue;
  984. }
  985. // We found the price
  986. if ($priceforthequantityarray['price_base_type'] == 'HT') {
  987. $pu_ht = $priceforthequantityarray['unitprice'];
  988. } else {
  989. $pu_ttc = $priceforthequantityarray['unitprice'];
  990. }
  991. // Note: the remise_percent or price by qty is used to set data on form, so we will use value from POST.
  992. break;
  993. }
  994. }
  995. }
  996. $tmpvat = price2num(preg_replace('/\s*\(.*\)/', '', $tva_tx));
  997. $tmpprodvat = price2num(preg_replace('/\s*\(.*\)/', '', $prod->tva_tx));
  998. // Set unit price to use
  999. if (!empty($price_ht) || $price_ht === '0') {
  1000. $pu_ht = price2num($price_ht, 'MU');
  1001. $pu_ttc = price2num($pu_ht * (1 + ($tmpvat / 100)), 'MU');
  1002. } elseif (!empty($price_ttc) || $price_ttc === '0') {
  1003. $pu_ttc = price2num($price_ttc, 'MU');
  1004. $pu_ht = price2num($pu_ttc / (1 + ($tmpvat / 100)), 'MU');
  1005. } elseif ($tmpvat != $tmpprodvat) {
  1006. // Is this still used ?
  1007. if ($price_base_type != 'HT') {
  1008. $pu_ht = price2num($pu_ttc / (1 + ($tmpvat / 100)), 'MU');
  1009. } else {
  1010. $pu_ttc = price2num($pu_ht * (1 + ($tmpvat / 100)), 'MU');
  1011. }
  1012. }
  1013. $desc = '';
  1014. // Define output language
  1015. if (getDolGlobalInt('MAIN_MULTILANGS') && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
  1016. $outputlangs = $langs;
  1017. $newlang = '';
  1018. if (empty($newlang) && GETPOST('lang_id', 'aZ09')) {
  1019. $newlang = GETPOST('lang_id', 'aZ09');
  1020. }
  1021. if (empty($newlang)) {
  1022. $newlang = $object->thirdparty->default_lang;
  1023. }
  1024. if (!empty($newlang)) {
  1025. $outputlangs = new Translate("", $conf);
  1026. $outputlangs->setDefaultLang($newlang);
  1027. }
  1028. $desc = (!empty($prod->multilangs[$outputlangs->defaultlang]["description"])) ? $prod->multilangs[$outputlangs->defaultlang]["description"] : $prod->description;
  1029. } else {
  1030. $desc = $prod->description;
  1031. }
  1032. //If text set in desc is the same as product description (as now it's preloaded) whe add it only one time
  1033. if ($product_desc==$desc && !empty($conf->global->PRODUIT_AUTOFILL_DESC)) {
  1034. $product_desc='';
  1035. }
  1036. if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) {
  1037. $desc = $product_desc;
  1038. } else {
  1039. $desc = dol_concatdesc($desc, $product_desc, '', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
  1040. }
  1041. // Add custom code and origin country into description
  1042. if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (!empty($prod->customcode) || !empty($prod->country_code))) {
  1043. $tmptxt = '(';
  1044. // Define output language
  1045. if (getDolGlobalInt('MAIN_MULTILANGS') && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
  1046. $outputlangs = $langs;
  1047. $newlang = '';
  1048. if (empty($newlang) && GETPOST('lang_id', 'alpha')) {
  1049. $newlang = GETPOST('lang_id', 'alpha');
  1050. }
  1051. if (empty($newlang)) {
  1052. $newlang = $object->thirdparty->default_lang;
  1053. }
  1054. if (!empty($newlang)) {
  1055. $outputlangs = new Translate("", $conf);
  1056. $outputlangs->setDefaultLang($newlang);
  1057. $outputlangs->load('products');
  1058. }
  1059. if (!empty($prod->customcode)) {
  1060. $tmptxt .= $outputlangs->transnoentitiesnoconv("CustomCode").': '.$prod->customcode;
  1061. }
  1062. if (!empty($prod->customcode) && !empty($prod->country_code)) {
  1063. $tmptxt .= ' - ';
  1064. }
  1065. if (!empty($prod->country_code)) {
  1066. $tmptxt .= $outputlangs->transnoentitiesnoconv("CountryOrigin").': '.getCountry($prod->country_code, 0, $db, $outputlangs, 0);
  1067. }
  1068. } else {
  1069. if (!empty($prod->customcode)) {
  1070. $tmptxt .= $langs->transnoentitiesnoconv("CustomCode").': '.$prod->customcode;
  1071. }
  1072. if (!empty($prod->customcode) && !empty($prod->country_code)) {
  1073. $tmptxt .= ' - ';
  1074. }
  1075. if (!empty($prod->country_code)) {
  1076. $tmptxt .= $langs->transnoentitiesnoconv("CountryOrigin").': '.getCountry($prod->country_code, 0, $db, $langs, 0);
  1077. }
  1078. }
  1079. $tmptxt .= ')';
  1080. $desc = dol_concatdesc($desc, $tmptxt);
  1081. }
  1082. $type = $prod->type;
  1083. $fk_unit = $prod->fk_unit;
  1084. } else {
  1085. $pu_ht = price2num($price_ht, 'MU');
  1086. $pu_ttc = price2num($price_ttc, 'MU');
  1087. $tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0);
  1088. if (empty($tva_tx)) {
  1089. $tva_npr = 0;
  1090. }
  1091. $tva_tx = str_replace('*', '', $tva_tx);
  1092. $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
  1093. $desc = $product_desc;
  1094. $type = GETPOST('type');
  1095. $fk_unit = GETPOST('units', 'alpha');
  1096. $pu_ht_devise = price2num($price_ht_devise, 'MU');
  1097. $pu_ttc_devise = price2num($price_ttc_devise, 'MU');
  1098. if ($pu_ttc && !$pu_ht) {
  1099. $price_base_type = 'TTC';
  1100. }
  1101. }
  1102. // Margin
  1103. $fournprice = price2num(GETPOST('fournprice'.$predef) ? GETPOST('fournprice'.$predef) : '');
  1104. $buyingprice = price2num(GETPOST('buying_price'.$predef) != '' ? GETPOST('buying_price'.$predef) : ''); // If buying_price is '0', we muste keep this value
  1105. $date_start = dol_mktime(GETPOST('date_start'.$predef.'hour'), GETPOST('date_start'.$predef.'min'), GETPOST('date_start'.$predef.'sec'), GETPOST('date_start'.$predef.'month'), GETPOST('date_start'.$predef.'day'), GETPOST('date_start'.$predef.'year'));
  1106. $date_end = dol_mktime(GETPOST('date_end'.$predef.'hour'), GETPOST('date_end'.$predef.'min'), GETPOST('date_end'.$predef.'sec'), GETPOST('date_end'.$predef.'month'), GETPOST('date_end'.$predef.'day'), GETPOST('date_end'.$predef.'year'));
  1107. // Prepare a price equivalent for minimum price check
  1108. $pu_equivalent = $pu_ht;
  1109. $pu_equivalent_ttc = $pu_ttc;
  1110. $currency_tx = $object->multicurrency_tx;
  1111. // Check if we have a foreing currency
  1112. // If so, we update the pu_equiv as the equivalent price in base currency
  1113. if ($pu_ht == '' && $pu_ht_devise != '' && $currency_tx != '') {
  1114. $pu_equivalent = $pu_ht_devise * $currency_tx;
  1115. }
  1116. if ($pu_ttc == '' && $pu_ttc_devise != '' && $currency_tx != '') {
  1117. $pu_equivalent_ttc = $pu_ttc_devise * $currency_tx;
  1118. }
  1119. // Local Taxes
  1120. $localtax1_tx = get_localtax($tva_tx, 1, $object->thirdparty, $tva_npr);
  1121. $localtax2_tx = get_localtax($tva_tx, 2, $object->thirdparty, $tva_npr);
  1122. $info_bits = 0;
  1123. if ($tva_npr) {
  1124. $info_bits |= 0x01;
  1125. }
  1126. //var_dump(price2num($price_min)); var_dump(price2num($pu_ht)); var_dump($remise_percent);
  1127. //var_dump(price2num($price_min_ttc)); var_dump(price2num($pu_ttc)); var_dump($remise_percent);exit;
  1128. if ($usermustrespectpricemin) {
  1129. if ($pu_equivalent && $price_min && ((price2num($pu_equivalent) * (1 - $remise_percent / 100)) < price2num($price_min))) {
  1130. $mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency));
  1131. setEventMessages($mesg, null, 'errors');
  1132. $error++;
  1133. } elseif ($pu_equivalent_ttc && $price_min_ttc && ((price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) < price2num($price_min_ttc))) {
  1134. $mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min_ttc, 'MU'), 0, $langs, 0, 0, -1, $conf->currency));
  1135. setEventMessages($mesg, null, 'errors');
  1136. $error++;
  1137. }
  1138. }
  1139. if (!$error) {
  1140. // Insert line
  1141. $result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $price_base_type, $pu_ttc, $info_bits, $type, min($rank, count($object->lines) + 1), 0, GETPOST('fk_parent_line'), $fournprice, $buyingprice, $label, $date_start, $date_end, $array_options, $fk_unit, '', 0, $pu_ht_devise);
  1142. if ($result > 0) {
  1143. $db->commit();
  1144. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  1145. // Define output language
  1146. $outputlangs = $langs;
  1147. if (getDolGlobalInt('MAIN_MULTILANGS')) {
  1148. $outputlangs = new Translate("", $conf);
  1149. $newlang = (GETPOST('lang_id', 'aZ09') ? GETPOST('lang_id', 'aZ09') : $object->thirdparty->default_lang);
  1150. $outputlangs->setDefaultLang($newlang);
  1151. }
  1152. $ret = $object->fetch($id); // Reload to get new records
  1153. if ($ret > 0) {
  1154. $object->fetch_thirdparty();
  1155. }
  1156. $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  1157. }
  1158. unset($_POST['prod_entry_mode']);
  1159. unset($_POST['qty']);
  1160. unset($_POST['type']);
  1161. unset($_POST['remise_percent']);
  1162. unset($_POST['price_ht']);
  1163. unset($_POST['multicurrency_price_ht']);
  1164. unset($_POST['price_ttc']);
  1165. unset($_POST['tva_tx']);
  1166. unset($_POST['product_ref']);
  1167. unset($_POST['product_label']);
  1168. unset($_POST['product_desc']);
  1169. unset($_POST['fournprice']);
  1170. unset($_POST['buying_price']);
  1171. unset($_POST['np_marginRate']);
  1172. unset($_POST['np_markRate']);
  1173. unset($_POST['dp_desc']);
  1174. unset($_POST['idprod']);
  1175. unset($_POST['units']);
  1176. unset($_POST['date_starthour']);
  1177. unset($_POST['date_startmin']);
  1178. unset($_POST['date_startsec']);
  1179. unset($_POST['date_startday']);
  1180. unset($_POST['date_startmonth']);
  1181. unset($_POST['date_startyear']);
  1182. unset($_POST['date_endhour']);
  1183. unset($_POST['date_endmin']);
  1184. unset($_POST['date_endsec']);
  1185. unset($_POST['date_endday']);
  1186. unset($_POST['date_endmonth']);
  1187. unset($_POST['date_endyear']);
  1188. } else {
  1189. $db->rollback();
  1190. setEventMessages($object->error, $object->errors, 'errors');
  1191. }
  1192. }
  1193. }
  1194. } elseif ($action == 'updateline' && $usercancreate && GETPOST('save')) {
  1195. // Update a line within proposal
  1196. // Define info_bits
  1197. $info_bits = 0;
  1198. if (preg_match('/\*/', GETPOST('tva_tx'))) {
  1199. $info_bits |= 0x01;
  1200. }
  1201. // Clean parameters
  1202. $description = dol_htmlcleanlastbr(GETPOST('product_desc', 'restricthtml'));
  1203. // Define vat_rate
  1204. $vat_rate = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0);
  1205. $vat_rate = str_replace('*', '', $vat_rate);
  1206. $localtax1_rate = get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
  1207. $localtax2_rate = get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
  1208. $pu_ht = price2num(GETPOST('price_ht'), '', 2);
  1209. $pu_ttc = price2num(GETPOST('price_ttc'), '', 2);
  1210. // Add buying price
  1211. $fournprice = price2num(GETPOST('fournprice') ? GETPOST('fournprice') : '');
  1212. $buyingprice = price2num(GETPOST('buying_price') != '' ? GETPOST('buying_price') : ''); // If buying_price is '0', we muste keep this value
  1213. $pu_ht_devise = price2num(GETPOST('multicurrency_subprice'), '', 2);
  1214. $pu_ttc_devise = price2num(GETPOST('multicurrency_subprice_ttc'), '', 2);
  1215. $date_start = dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), GETPOST('date_startsec'), GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear'));
  1216. $date_end = dol_mktime(GETPOST('date_endhour'), GETPOST('date_endmin'), GETPOST('date_endsec'), GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear'));
  1217. $remise_percent = price2num(GETPOST('remise_percent'), '', 2);
  1218. if (empty($remise_percent)) {
  1219. $remise_percent = 0;
  1220. }
  1221. // Prepare a price equivalent for minimum price check
  1222. $pu_equivalent = $pu_ht;
  1223. $pu_equivalent_ttc = $pu_ttc;
  1224. $currency_tx = $object->multicurrency_tx;
  1225. // Check if we have a foreing currency
  1226. // If so, we update the pu_equiv as the equivalent price in base currency
  1227. if ($pu_ht == '' && $pu_ht_devise != '' && $currency_tx != '') {
  1228. $pu_equivalent = $pu_ht_devise * $currency_tx;
  1229. }
  1230. if ($pu_ttc == '' && $pu_ttc_devise != '' && $currency_tx != '') {
  1231. $pu_equivalent_ttc = $pu_ttc_devise * $currency_tx;
  1232. }
  1233. // Extrafields
  1234. $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
  1235. $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
  1236. // Unset extrafield
  1237. if (is_array($extralabelsline)) {
  1238. // Get extra fields
  1239. foreach ($extralabelsline as $key => $value) {
  1240. unset($_POST["options_".$key]);
  1241. }
  1242. }
  1243. // Define special_code for special lines
  1244. $special_code = GETPOST('special_code', 'int');
  1245. if (!GETPOST('qty')) {
  1246. $special_code = 3;
  1247. }
  1248. // Check minimum price
  1249. $productid = GETPOST('productid', 'int');
  1250. if (!empty($productid)) {
  1251. $product = new Product($db);
  1252. $res = $product->fetch($productid);
  1253. $type = $product->type;
  1254. $label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : '');
  1255. $price_min = $product->price_min;
  1256. if (!empty($conf->global->PRODUIT_MULTIPRICES) && !empty($object->thirdparty->price_level)) {
  1257. $price_min = $product->multiprices_min[$object->thirdparty->price_level];
  1258. }
  1259. $price_min_ttc = $product->price_min_ttc;
  1260. if (!empty($conf->global->PRODUIT_MULTIPRICES) && !empty($object->thirdparty->price_level)) {
  1261. $price_min_ttc = $product->multiprices_min_ttc[$object->thirdparty->price_level];
  1262. }
  1263. //var_dump(price2num($price_min)); var_dump(price2num($pu_ht)); var_dump($remise_percent);
  1264. //var_dump(price2num($price_min_ttc)); var_dump(price2num($pu_ttc)); var_dump($remise_percent);exit;
  1265. if ($usermustrespectpricemin) {
  1266. if ($pu_equivalent && $price_min && ((price2num($pu_equivalent) * (1 - $remise_percent / 100)) < price2num($price_min))) {
  1267. $mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency));
  1268. setEventMessages($mesg, null, 'errors');
  1269. $error++;
  1270. $action = 'editline';
  1271. } elseif ($pu_equivalent_ttc && $price_min_ttc && ((price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) < price2num($price_min_ttc))) {
  1272. $mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min_ttc, 'MU'), 0, $langs, 0, 0, -1, $conf->currency));
  1273. setEventMessages($mesg, null, 'errors');
  1274. $error++;
  1275. $action = 'editline';
  1276. }
  1277. }
  1278. } else {
  1279. $type = GETPOST('type');
  1280. $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
  1281. // Check parameters
  1282. if (GETPOST('type') < 0) {
  1283. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
  1284. $error++;
  1285. }
  1286. }
  1287. if (!$error) {
  1288. $db->begin();
  1289. if (empty($user->rights->margins->creer)) {
  1290. foreach ($object->lines as &$line) {
  1291. if ($line->id == GETPOST('lineid', 'int')) {
  1292. $fournprice = $line->fk_fournprice;
  1293. $buyingprice = $line->pa_ht;
  1294. break;
  1295. }
  1296. }
  1297. }
  1298. $qty = price2num(GETPOST('qty', 'alpha'), 'MS');
  1299. $pu = $pu_ht;
  1300. $price_base_type = 'HT';
  1301. if (empty($pu) && !empty($pu_ttc)) {
  1302. $pu = $pu_ttc;
  1303. $price_base_type = 'TTC';
  1304. }
  1305. $result = $object->updateline(GETPOST('lineid', 'int'), $pu, $qty, $remise_percent, $vat_rate, $localtax1_rate, $localtax2_rate, $description, $price_base_type, $info_bits, $special_code, GETPOST('fk_parent_line'), 0, $fournprice, $buyingprice, $label, $type, $date_start, $date_end, $array_options, GETPOST("units"), $pu_ht_devise);
  1306. if ($result >= 0) {
  1307. $db->commit();
  1308. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  1309. // Define output language
  1310. $outputlangs = $langs;
  1311. if (getDolGlobalInt('MAIN_MULTILANGS')) {
  1312. $outputlangs = new Translate("", $conf);
  1313. $newlang = (GETPOST('lang_id', 'aZ09') ? GETPOST('lang_id', 'aZ09') : $object->thirdparty->default_lang);
  1314. $outputlangs->setDefaultLang($newlang);
  1315. }
  1316. $ret = $object->fetch($id); // Reload to get new records
  1317. if ($ret > 0) {
  1318. $object->fetch_thirdparty();
  1319. }
  1320. $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
  1321. }
  1322. unset($_POST['qty']);
  1323. unset($_POST['type']);
  1324. unset($_POST['productid']);
  1325. unset($_POST['remise_percent']);
  1326. unset($_POST['price_ht']);
  1327. unset($_POST['multicurrency_price_ht']);
  1328. unset($_POST['price_ttc']);
  1329. unset($_POST['tva_tx']);
  1330. unset($_POST['product_ref']);
  1331. unset($_POST['product_label']);
  1332. unset($_POST['product_desc']);
  1333. unset($_POST['fournprice']);
  1334. unset($_POST['buying_price']);
  1335. unset($_POST['date_starthour']);
  1336. unset($_POST['date_startmin']);
  1337. unset($_POST['date_startsec']);
  1338. unset($_POST['date_startday']);
  1339. unset($_POST['date_startmonth']);
  1340. unset($_POST['date_startyear']);
  1341. unset($_POST['date_endhour']);
  1342. unset($_POST['date_endmin']);
  1343. unset($_POST['date_endsec']);
  1344. unset($_POST['date_endday']);
  1345. unset($_POST['date_endmonth']);
  1346. unset($_POST['date_endyear']);
  1347. } else {
  1348. $db->rollback();
  1349. setEventMessages($object->error, $object->errors, 'errors');
  1350. }
  1351. }
  1352. } elseif ($action == 'updateline' && $usercancreate && GETPOST('cancel', 'alpha')) {
  1353. header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id); // Pour reaffichage de la fiche en cours d'edition
  1354. exit();
  1355. } elseif ($action == 'classin' && $usercancreate) {
  1356. // Set project
  1357. $object->setProject(GETPOST('projectid', 'int'));
  1358. } elseif ($action == 'setavailability' && $usercancreate) {
  1359. // Delivery time
  1360. $result = $object->set_availability($user, GETPOST('availability_id', 'int'));
  1361. } elseif ($action == 'setdemandreason' && $usercancreate) {
  1362. // Origin of the commercial proposal
  1363. $result = $object->set_demand_reason($user, GETPOST('demand_reason_id', 'int'));
  1364. } elseif ($action == 'setconditions' && $usercancreate) {
  1365. // Terms of payment
  1366. $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int'), GETPOST('cond_reglement_id_deposit_percent', 'alpha'));
  1367. } elseif ($action == 'setremisepercent' && $usercancreate) {
  1368. $result = $object->set_remise_percent($user, price2num(GETPOST('remise_percent'), '', 2));
  1369. } elseif ($action == 'setremiseabsolue' && $usercancreate) {
  1370. $result = $object->set_remise_absolue($user, price2num(GETPOST('remise_absolue'), 'MU', 2));
  1371. } elseif ($action == 'setmode' && $usercancreate) {
  1372. // Payment choice
  1373. $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int'));
  1374. } elseif ($action == 'setmulticurrencycode' && $usercancreate) {
  1375. // Multicurrency Code
  1376. $result = $object->setMulticurrencyCode(GETPOST('multicurrency_code', 'alpha'));
  1377. } elseif ($action == 'setmulticurrencyrate' && $usercancreate) {
  1378. // Multicurrency rate
  1379. $result = $object->setMulticurrencyRate(price2num(GETPOST('multicurrency_tx')), GETPOST('calculation_mode', 'int'));
  1380. } elseif ($action == 'setbankaccount' && $usercancreate) {
  1381. // bank account
  1382. $result = $object->setBankAccount(GETPOST('fk_account', 'int'));
  1383. } elseif ($action == 'setshippingmethod' && $usercancreate) {
  1384. // shipping method
  1385. $result = $object->setShippingMethod(GETPOST('shipping_method_id', 'int'));
  1386. } elseif ($action == 'setwarehouse' && $usercancreate) {
  1387. // warehouse
  1388. $result = $object->setWarehouse(GETPOST('warehouse_id', 'int'));
  1389. } elseif ($action == 'update_extras') {
  1390. $object->oldcopy = dol_clone($object);
  1391. // Fill array 'array_options' with data from update form
  1392. $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml'));
  1393. if ($ret < 0) {
  1394. $error++;
  1395. }
  1396. if (!$error) {
  1397. $result = $object->insertExtraFields('PROPAL_MODIFY');
  1398. if ($result < 0) {
  1399. setEventMessages($object->error, $object->errors, 'errors');
  1400. $error++;
  1401. }
  1402. }
  1403. if ($error) {
  1404. $action = 'edit_extras';
  1405. }
  1406. }
  1407. if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $usercancreate) {
  1408. if ($action == 'addcontact') {
  1409. if ($object->id > 0) {
  1410. $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
  1411. $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
  1412. $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
  1413. }
  1414. if ($result >= 0) {
  1415. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  1416. exit();
  1417. } else {
  1418. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  1419. $langs->load("errors");
  1420. setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
  1421. } else {
  1422. setEventMessages($object->error, $object->errors, 'errors');
  1423. }
  1424. }
  1425. } elseif ($action == 'swapstatut') {
  1426. // Toggle the status of a contact
  1427. if ($object->fetch($id) > 0) {
  1428. $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
  1429. } else {
  1430. dol_print_error($db);
  1431. }
  1432. } elseif ($action == 'deletecontact') {
  1433. // Delete a contact
  1434. $object->fetch($id);
  1435. $result = $object->delete_contact($lineid);
  1436. if ($result >= 0) {
  1437. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  1438. exit();
  1439. } else {
  1440. dol_print_error($db);
  1441. }
  1442. }
  1443. }
  1444. // Actions to build doc
  1445. $upload_dir = !empty($conf->propal->multidir_output[$object->entity])?$conf->propal->multidir_output[$object->entity]:$conf->propal->dir_output;
  1446. $permissiontoadd = $usercancreate;
  1447. include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
  1448. }
  1449. /*
  1450. * View
  1451. */
  1452. $form = new Form($db);
  1453. $formfile = new FormFile($db);
  1454. $formpropal = new FormPropal($db);
  1455. $formmargin = new FormMargin($db);
  1456. if (isModEnabled('project')) {
  1457. $formproject = new FormProjets($db);
  1458. }
  1459. $title = $object->ref." - ".$langs->trans('Card');
  1460. if ($action == 'create') {
  1461. $title = $langs->trans("NewPropal");
  1462. }
  1463. $help_url = 'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos|DE:Modul_Angebote';
  1464. llxHeader('', $title, $help_url);
  1465. $now = dol_now();
  1466. // Add new proposal
  1467. if ($action == 'create') {
  1468. $currency_code = $conf->currency;
  1469. print load_fiche_titre($langs->trans("NewProp"), '', 'propal');
  1470. $soc = new Societe($db);
  1471. if ($socid > 0) {
  1472. $res = $soc->fetch($socid);
  1473. }
  1474. // Load objectsrc
  1475. if (!empty($origin) && !empty($originid)) {
  1476. // Parse element/subelement (ex: project_task)
  1477. $element = $subelement = $origin;
  1478. $regs = array();
  1479. if (preg_match('/^([^_]+)_([^_]+)/i', $origin, $regs)) {
  1480. $element = $regs[1];
  1481. $subelement = $regs[2];
  1482. }
  1483. if ($element == 'project') {
  1484. $projectid = $originid;
  1485. } else {
  1486. // For compatibility
  1487. if ($element == 'order' || $element == 'commande') {
  1488. $element = $subelement = 'commande';
  1489. }
  1490. if ($element == 'propal') {
  1491. $element = 'comm/propal';
  1492. $subelement = 'propal';
  1493. }
  1494. if ($element == 'contract') {
  1495. $element = $subelement = 'contrat';
  1496. }
  1497. if ($element == 'shipping') {
  1498. $element = $subelement = 'expedition';
  1499. }
  1500. dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
  1501. $classname = ucfirst($subelement);
  1502. $objectsrc = new $classname($db);
  1503. $objectsrc->fetch($originid);
  1504. if (empty($objectsrc->lines) && method_exists($objectsrc, 'fetch_lines')) {
  1505. $objectsrc->fetch_lines();
  1506. }
  1507. $objectsrc->fetch_thirdparty();
  1508. $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project : 0);
  1509. $ref_client = (!empty($objectsrc->ref_client) ? $objectsrc->ref_client : '');
  1510. $soc = $objectsrc->thirdparty;
  1511. $cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0)); // TODO maybe add default value option
  1512. $mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
  1513. $remise_absolue = (!empty($objectsrc->remise_absolue) ? $objectsrc->remise_absolue : (!empty($soc->remise_absolue) ? $soc->remise_absolue : 0)); // deprecated
  1514. $remise_percent = (!empty($objectsrc->remise_percent) ? $objectsrc->remise_percent : (!empty($soc->remise_percent) ? $soc->remise_percent : 0));
  1515. $warehouse_id = (!empty($objectsrc->warehouse_id) ? $objectsrc->warehouse_id : (!empty($soc->warehouse_id) ? $soc->warehouse_id : 0));
  1516. $dateinvoice = (empty($dateinvoice) ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 : '') : $dateinvoice);
  1517. // Replicate extrafields
  1518. $objectsrc->fetch_optionals();
  1519. $object->array_options = $objectsrc->array_options;
  1520. if (isModEnabled("multicurrency")) {
  1521. if (!empty($objectsrc->multicurrency_code)) {
  1522. $currency_code = $objectsrc->multicurrency_code;
  1523. }
  1524. if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) {
  1525. $currency_tx = $objectsrc->multicurrency_tx;
  1526. }
  1527. }
  1528. }
  1529. } else {
  1530. if (isModEnabled("multicurrency") && !empty($soc->multicurrency_code)) {
  1531. $currency_code = $soc->multicurrency_code;
  1532. }
  1533. }
  1534. //Warehouse default if null
  1535. if ($soc->fk_warehouse > 0) {
  1536. $warehouse_id = $soc->fk_warehouse;
  1537. }
  1538. if (isModEnabled('stock') && empty($warehouse_id) && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) {
  1539. if (empty($object->warehouse_id) && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE)) {
  1540. $warehouse_id = $conf->global->MAIN_DEFAULT_WAREHOUSE;
  1541. }
  1542. if (empty($object->warehouse_id) && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER)) {
  1543. $warehouse_id = $user->fk_warehouse;
  1544. }
  1545. }
  1546. print '<form name="addprop" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  1547. print '<input type="hidden" name="token" value="'.newToken().'">';
  1548. print '<input type="hidden" name="action" value="add">';
  1549. if ($origin != 'project' && $originid) {
  1550. print '<input type="hidden" name="origin" value="'.$origin.'">';
  1551. print '<input type="hidden" name="originid" value="'.$originid.'">';
  1552. } elseif ($origin == 'project' && !empty($projectid)) {
  1553. print '<input type="hidden" name="projectid" value="'.$projectid.'">';
  1554. }
  1555. print dol_get_fiche_head();
  1556. print '<table class="border centpercent">';
  1557. // Reference
  1558. print '<tr class="field_ref"><td class="titlefieldcreate fieldrequired">'.$langs->trans('Ref').'</td><td class="valuefieldcreate">'.$langs->trans("Draft").'</td></tr>';
  1559. // Ref customer
  1560. print '<tr class="field_ref_client"><td class="titlefieldcreate">'.$langs->trans('RefCustomer').'</td><td class="valuefieldcreate">';
  1561. print '<input type="text" name="ref_client" value="'.(!empty($ref_client)?$ref_client:GETPOST('ref_client')).'"></td>';
  1562. print '</tr>';
  1563. // Third party
  1564. print '<tr class="field_socid">';
  1565. print '<td class="titlefieldcreate fieldrequired">'.$langs->trans('Customer').'</td>';
  1566. $shipping_method_id = 0;
  1567. if ($socid > 0) {
  1568. print '<td class="valuefieldcreate">';
  1569. print $soc->getNomUrl(1, 'customer');
  1570. print '<input type="hidden" name="socid" value="'.$soc->id.'">';
  1571. print '</td>';
  1572. if (!empty($conf->global->SOCIETE_ASK_FOR_SHIPPING_METHOD) && !empty($soc->shipping_method_id)) {
  1573. $shipping_method_id = $soc->shipping_method_id;
  1574. }
  1575. //$warehouse_id = $soc->warehouse_id;
  1576. } else {
  1577. print '<td class="valuefieldcreate">';
  1578. print img_picto('', 'company').$form->select_company('', 'socid', '((s.client = 1 OR s.client = 2 OR s.client = 3) AND status=1)', 'SelectThirdParty', 1, 0, null, 0, 'minwidth300 maxwidth500 widthcentpercentminusxx');
  1579. // reload page to retrieve customer informations
  1580. if (empty($conf->global->RELOAD_PAGE_ON_CUSTOMER_CHANGE_DISABLED)) {
  1581. print '<script type="text/javascript">
  1582. $(document).ready(function() {
  1583. $("#socid").change(function() {
  1584. console.log("We have changed the company - Reload page");
  1585. var socid = $(this).val();
  1586. // reload page
  1587. $("input[name=action]").val("create");
  1588. $("form[name=addprop]").submit();
  1589. });
  1590. });
  1591. </script>';
  1592. }
  1593. print ' <a href="'.DOL_URL_ROOT.'/societe/card.php?action=create&client=3&fournisseur=0&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create').'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddThirdParty").'"></span></a>';
  1594. print '</td>';
  1595. }
  1596. print '</tr>'."\n";
  1597. if ($socid > 0) {
  1598. // Contacts (ask contact only if thirdparty already defined).
  1599. print '<tr class="field_contactid"><td class="titlefieldcreate">'.$langs->trans("DefaultContact").'</td><td class="valuefieldcreate">';
  1600. print img_picto('', 'contact');
  1601. print $form->selectcontacts($soc->id, $contactid, 'contactid', 1, '', '', 0, 'minwidth300');
  1602. print '</td></tr>';
  1603. // Third party discounts info line
  1604. print '<tr class="field_discount_info"><td class="titlefieldcreate">'.$langs->trans('Discounts').'</td><td class="valuefieldcreate">';
  1605. $absolute_discount = $soc->getAvailableDiscounts();
  1606. $thirdparty = $soc;
  1607. $discount_type = 0;
  1608. $backtopage = urlencode($_SERVER["PHP_SELF"].'?socid='.$thirdparty->id.'&action='.$action.'&origin='.GETPOST('origin').'&originid='.GETPOST('originid'));
  1609. include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
  1610. print '</td></tr>';
  1611. }
  1612. // Date
  1613. print '<tr class="field_addprop"><td class="titlefieldcreate fieldrequired">'.$langs->trans('DatePropal').'</td><td class="valuefieldcreate">';
  1614. print $form->selectDate('', '', '', '', '', "addprop", 1, 1);
  1615. print '</td></tr>';
  1616. // Validaty duration
  1617. print '<tr class="field_duree_validitee"><td class="titlefieldcreate fieldrequired">'.$langs->trans("ValidityDuration").'</td><td class="valuefieldcreate">'.img_picto('', 'clock', 'class="paddingright"').'<input name="duree_validite" class="width50" value="'.(GETPOSTISSET('duree_validite') ? GETPOST('duree_validite', 'alphanohtml') : $conf->global->PROPALE_VALIDITY_DURATION).'"> '.$langs->trans("days").'</td></tr>';
  1618. // Terms of payment
  1619. print '<tr class="field_cond_reglement_id"><td class="nowrap">'.$langs->trans('PaymentConditionsShort').'</td><td>';
  1620. print img_picto('', 'paiment');
  1621. print $form->getSelectConditionsPaiements((GETPOSTISSET('cond_reglement_id') && GETPOST('cond_reglement_id', 'int') != 0) ? GETPOST('cond_reglement_id', 'int') : $soc->cond_reglement_id, 'cond_reglement_id', 1, 1, 0, '', (GETPOSTISSET('cond_reglement_id_deposit_percent') ? GETPOST('cond_reglement_id_deposit_percent', 'alpha') : $soc->deposit_percent));
  1622. print '</td></tr>';
  1623. // Mode of payment
  1624. print '<tr class="field_mode_reglement_id"><td class="titlefieldcreate">'.$langs->trans('PaymentMode').'</td><td class="valuefieldcreate">';
  1625. print img_picto('', 'bank', 'class="pictofixedwidth"');
  1626. print $form->select_types_paiements((GETPOSTISSET('mode_reglement_id') && GETPOST('mode_reglement_id', 'int') != 0) ? GETPOST('mode_reglement_id', 'int') : $soc->mode_reglement_id, 'mode_reglement_id', 'CRDT', 0, 1, 0, 0, 1, 'maxwidth200 widthcentpercentminusx', 1);
  1627. print '</td></tr>';
  1628. // Bank Account
  1629. if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_PROPOSAL) && isModEnabled("banque")) {
  1630. print '<tr class="field_fk_account"><td class="titlefieldcreate">'.$langs->trans('BankAccount').'</td><td class="valuefieldcreate">';
  1631. print img_picto('', 'bank_account', 'class="pictofixedwidth"').$form->select_comptes($soc->fk_account, 'fk_account', 0, '', 1, '', 0, 'maxwidth200 widthcentpercentminusx', 1);
  1632. print '</td></tr>';
  1633. }
  1634. // Source / Channel - What trigger creation
  1635. print '<tr class="field_demand_reason_id"><td class="titlefieldcreate">'.$langs->trans('Source').'</td><td class="valuefieldcreate">';
  1636. print img_picto('', 'question', 'class="pictofixedwidth"');
  1637. $form->selectInputReason('', 'demand_reason_id', "SRC_PROP", 1, 'maxwidth200 widthcentpercentminusx');
  1638. print '</td></tr>';
  1639. // Delivery delay
  1640. print '<tr class="field_availability_id"><td class="titlefieldcreate">'.$langs->trans('AvailabilityPeriod');
  1641. if (isModEnabled('commande')) {
  1642. print ' ('.$langs->trans('AfterOrder').')';
  1643. }
  1644. print '</td><td class="valuefieldcreate">';
  1645. print img_picto('', 'clock', 'class="pictofixedwidth"');
  1646. $form->selectAvailabilityDelay('', 'availability_id', '', 1, 'maxwidth200 widthcentpercentminusx');
  1647. print '</td></tr>';
  1648. // Shipping Method
  1649. if (isModEnabled("expedition")) {
  1650. if (!empty($conf->global->SOCIETE_ASK_FOR_SHIPPING_METHOD) && !empty($soc->shipping_method_id)) {
  1651. $shipping_method_id = $soc->shipping_method_id;
  1652. }
  1653. print '<tr class="field_shipping_method_id"><td class="titlefieldcreate">'.$langs->trans('SendingMethod').'</td><td class="valuefieldcreate">';
  1654. print img_picto('', 'object_dollyrevert', 'class="pictofixedwidth"');
  1655. $form->selectShippingMethod($shipping_method_id, 'shipping_method_id', '', 1, '', 0, 'maxwidth200 widthcentpercentminusx');
  1656. print '</td></tr>';
  1657. }
  1658. // Warehouse
  1659. if (isModEnabled('stock') && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_PROPAL)) {
  1660. require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
  1661. $formproduct = new FormProduct($db);
  1662. print '<tr class="field_warehouse_id"><td class="titlefieldcreate">'.$langs->trans('Warehouse').'</td><td class="valuefieldcreate">';
  1663. print img_picto('', 'stock', 'class="pictofixedwidth"').$formproduct->selectWarehouses($warehouse_id, 'warehouse_id', '', 1, 0, 0, '', 0, 0, array(), 'maxwidth500 widthcentpercentminusxx');
  1664. print '</td></tr>';
  1665. }
  1666. // Delivery date (or manufacturing)
  1667. print '<tr class="field_date_livraison"><td class="titlefieldcreate">'.$langs->trans("DeliveryDate").'</td>';
  1668. print '<td class="valuefieldcreate">';
  1669. if (isset($conf->global->DATE_LIVRAISON_WEEK_DELAY) && is_numeric($conf->global->DATE_LIVRAISON_WEEK_DELAY)) {
  1670. $tmpdte = time() + ((7 * $conf->global->DATE_LIVRAISON_WEEK_DELAY) * 24 * 60 * 60);
  1671. $syear = date("Y", $tmpdte);
  1672. $smonth = date("m", $tmpdte);
  1673. $sday = date("d", $tmpdte);
  1674. print $form->selectDate($syear."-".$smonth."-".$sday, 'date_livraison', '', '', '', "addprop");
  1675. } else {
  1676. print $form->selectDate(-1, 'date_livraison', '', '', '', "addprop", 1, 1);
  1677. }
  1678. print '</td></tr>';
  1679. // Project
  1680. if (isModEnabled('project')) {
  1681. $langs->load("projects");
  1682. print '<tr class="field_projectid">';
  1683. print '<td class="titlefieldcreate">'.$langs->trans("Project").'</td><td class="valuefieldcreate">';
  1684. print img_picto('', 'project', 'class="pictofixedwidth"').$formproject->select_projects(($soc->id > 0 ? $soc->id : -1), $projectid, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 1, 0, 'maxwidth500 widthcentpercentminusxx');
  1685. print ' <a href="'.DOL_URL_ROOT.'/projet/card.php?socid='.$soc->id.'&action=create&status=1&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create&socid='.$soc->id).'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddProject").'"></span></a>';
  1686. print '</td>';
  1687. print '</tr>';
  1688. }
  1689. // Incoterms
  1690. if (isModEnabled('incoterm')) {
  1691. print '<tr class="field_incoterm_id">';
  1692. print '<td class="titlefieldcreate"><label for="incoterm_id">'.$form->textwithpicto($langs->trans("IncotermLabel"), $soc->label_incoterms, 1).'</label></td>';
  1693. print '<td class="valuefieldcreate maxwidthonsmartphone">';
  1694. print $form->select_incoterms((!empty($soc->fk_incoterms) ? $soc->fk_incoterms : ''), (!empty($soc->location_incoterms) ? $soc->location_incoterms : ''));
  1695. print '</td></tr>';
  1696. }
  1697. // Template to use by default
  1698. print '<tr class="field_model">';
  1699. print '<td class="titlefieldcreate">'.$langs->trans("DefaultModel").'</td>';
  1700. print '<td class="valuefieldcreate">';
  1701. print img_picto('', 'pdf', 'class="pictofixedwidth"');
  1702. $liste = ModelePDFPropales::liste_modeles($db);
  1703. $preselected = (!empty($conf->global->PROPALE_ADDON_PDF_ODT_DEFAULT) ? $conf->global->PROPALE_ADDON_PDF_ODT_DEFAULT : getDolGlobalString("PROPALE_ADDON_PDF"));
  1704. print $form->selectarray('model', $liste, $preselected, 0, 0, 0, '', 0, 0, 0, '', 'maxwidth200 widthcentpercentminusx', 1);
  1705. print "</td></tr>";
  1706. // Multicurrency
  1707. if (isModEnabled("multicurrency")) {
  1708. print '<tr class="field_currency">';
  1709. print '<td class="titlefieldcreate">'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
  1710. print '<td class="valuefieldcreate maxwidthonsmartphone">';
  1711. print img_picto('', 'currency', 'class="pictofixedwidth"').$form->selectMultiCurrency($currency_code, 'multicurrency_code', 0);
  1712. print '</td></tr>';
  1713. }
  1714. // Public note
  1715. print '<tr class="field_note_public">';
  1716. print '<td class="titlefieldcreate tdtop">'.$langs->trans('NotePublic').'</td>';
  1717. print '<td class="valuefieldcreate">';
  1718. $note_public = $object->getDefaultCreateValueFor('note_public', (!empty($objectsrc) ? $objectsrc->note_public : null));
  1719. $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PUBLIC) ? 0 : 1, ROWS_3, '90%');
  1720. print $doleditor->Create(1);
  1721. // Private note
  1722. if (empty($user->socid)) {
  1723. print '<tr class="field_note_private">';
  1724. print '<td class="titlefieldcreate tdtop">'.$langs->trans('NotePrivate').'</td>';
  1725. print '<td class="valuefieldcreate">';
  1726. $note_private = $object->getDefaultCreateValueFor('note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc)) ? $objectsrc->note_private : null));
  1727. $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PRIVATE) ? 0 : 1, ROWS_3, '90%');
  1728. print $doleditor->Create(1);
  1729. // print '<textarea name="note_private" wrap="soft" cols="70" rows="'.ROWS_3.'">'.$note_private.'.</textarea>
  1730. print '</td></tr>';
  1731. }
  1732. // Other attributes
  1733. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
  1734. // Lines from source
  1735. if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
  1736. // TODO for compatibility
  1737. if ($origin == 'contrat') {
  1738. // Calcul contrat->price (HT), contrat->total (TTC), contrat->tva
  1739. $objectsrc->remise_absolue = $remise_absolue; // deprecated
  1740. $objectsrc->remise_percent = $remise_percent;
  1741. $objectsrc->update_price(1, 'auto', 1);
  1742. }
  1743. print "\n<!-- ".$classname." info -->";
  1744. print "\n";
  1745. print '<input type="hidden" name="amount" value="'.$objectsrc->total_ht.'">'."\n";
  1746. print '<input type="hidden" name="total" value="'.$objectsrc->total_ttc.'">'."\n";
  1747. print '<input type="hidden" name="tva" value="'.$objectsrc->total_tva.'">'."\n";
  1748. print '<input type="hidden" name="origin" value="'.$objectsrc->element.'">';
  1749. print '<input type="hidden" name="originid" value="'.$objectsrc->id.'">';
  1750. $newclassname = $classname;
  1751. if ($newclassname == 'Propal') {
  1752. $newclassname = 'CommercialProposal';
  1753. } elseif ($newclassname == 'Commande') {
  1754. $newclassname = 'Order';
  1755. } elseif ($newclassname == 'Expedition') {
  1756. $newclassname = 'Sending';
  1757. } elseif ($newclassname == 'Fichinter') {
  1758. $newclassname = 'Intervention';
  1759. }
  1760. print '<tr><td>'.$langs->trans($newclassname).'</td><td>'.$objectsrc->getNomUrl(1).'</td></tr>';
  1761. print '<tr><td>'.$langs->trans('AmountHT').'</td><td>'.price($objectsrc->total_ht, 0, $langs, 1, -1, -1, $conf->currency).'</td></tr>';
  1762. print '<tr><td>'.$langs->trans('AmountVAT').'</td><td>'.price($objectsrc->total_tva, 0, $langs, 1, -1, -1, $conf->currency)."</td></tr>";
  1763. if ($mysoc->localtax1_assuj == "1" || $objectsrc->total_localtax1 != 0) { // Localtax1
  1764. print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td><td>'.price($objectsrc->total_localtax1, 0, $langs, 1, -1, -1, $conf->currency)."</td></tr>";
  1765. }
  1766. if ($mysoc->localtax2_assuj == "1" || $objectsrc->total_localtax2 != 0) { // Localtax2
  1767. print '<tr><td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td><td>'.price($objectsrc->total_localtax2, 0, $langs, 1, -1, -1, $conf->currency)."</td></tr>";
  1768. }
  1769. print '<tr><td>'.$langs->trans('AmountTTC').'</td><td>'.price($objectsrc->total_ttc, 0, $langs, 1, -1, -1, $conf->currency)."</td></tr>";
  1770. if (isModEnabled("multicurrency")) {
  1771. print '<tr><td>'.$langs->trans('MulticurrencyAmountHT').'</td><td>'.price($objectsrc->multicurrency_total_ht).'</td></tr>';
  1772. print '<tr><td>'.$langs->trans('MulticurrencyAmountVAT').'</td><td>'.price($objectsrc->multicurrency_total_tva)."</td></tr>";
  1773. print '<tr><td>'.$langs->trans('MulticurrencyAmountTTC').'</td><td>'.price($objectsrc->multicurrency_total_ttc)."</td></tr>";
  1774. }
  1775. }
  1776. print "</table>\n";
  1777. /*
  1778. * Combobox for copy function
  1779. */
  1780. if (empty($conf->global->PROPAL_CLONE_ON_CREATE_PAGE)) {
  1781. print '<input type="hidden" name="createmode" value="empty">';
  1782. }
  1783. if (!empty($conf->global->PROPAL_CLONE_ON_CREATE_PAGE)) {
  1784. print '<br><table>';
  1785. // For backward compatibility
  1786. print '<tr>';
  1787. print '<td><input type="radio" name="createmode" value="copy"></td>';
  1788. print '<td>'.$langs->trans("CopyPropalFrom").' </td>';
  1789. print '<td>';
  1790. $liste_propal = array();
  1791. $liste_propal [0] = '';
  1792. $sql = "SELECT p.rowid as id, p.ref, s.nom";
  1793. $sql .= " FROM ".MAIN_DB_PREFIX."propal p";
  1794. $sql .= ", ".MAIN_DB_PREFIX."societe s";
  1795. $sql .= " WHERE s.rowid = p.fk_soc";
  1796. $sql .= " AND p.entity IN (".getEntity('propal').")";
  1797. $sql .= " AND p.fk_statut <> 0";
  1798. $sql .= " ORDER BY Id";
  1799. $resql = $db->query($sql);
  1800. if ($resql) {
  1801. $num = $db->num_rows($resql);
  1802. $i = 0;
  1803. while ($i < $num) {
  1804. $row = $db->fetch_row($resql);
  1805. $propalRefAndSocName = $row[1]." - ".$row[2];
  1806. $liste_propal[$row[0]] = $propalRefAndSocName;
  1807. $i++;
  1808. }
  1809. print $form->selectarray("copie_propal", $liste_propal, 0);
  1810. } else {
  1811. dol_print_error($db);
  1812. }
  1813. print '</td></tr>';
  1814. print '<tr><td class="tdtop"><input type="radio" name="createmode" value="empty" checked></td>';
  1815. print '<td valign="top" colspan="2">'.$langs->trans("CreateEmptyPropal").'</td></tr>';
  1816. print '</table>';
  1817. }
  1818. print dol_get_fiche_end();
  1819. $langs->load("bills");
  1820. print $form->buttonsSaveCancel("CreateDraft");
  1821. print "</form>";
  1822. // Show origin lines
  1823. if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
  1824. print '<br>';
  1825. $title = $langs->trans('ProductsAndServices');
  1826. print load_fiche_titre($title);
  1827. print '<div class="div-table-responsive-no-min">';
  1828. print '<table class="noborder centpercent">';
  1829. $objectsrc->printOriginLinesList();
  1830. print '</table>';
  1831. print '</div>';
  1832. }
  1833. } elseif ($object->id > 0) {
  1834. /*
  1835. * Show object in view mode
  1836. */
  1837. $soc = new Societe($db);
  1838. $soc->fetch($object->socid);
  1839. $head = propal_prepare_head($object);
  1840. print dol_get_fiche_head($head, 'comm', $langs->trans('Proposal'), -1, 'propal');
  1841. $formconfirm = '';
  1842. // Clone confirmation
  1843. if ($action == 'clone') {
  1844. // Create an array for form
  1845. $formquestion = array(
  1846. // 'text' => $langs->trans("ConfirmClone"),
  1847. // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
  1848. array('type' => 'other', 'name' => 'socid', 'label' => $langs->trans("SelectThirdParty"), 'value' => $form->select_company(GETPOST('socid', 'int'), 'socid', '(s.client=1 OR s.client=2 OR s.client=3)', '', 0, 0, null, 0, 'maxwidth300')),
  1849. array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans('PuttingPricesUpToDate'), 'value' => (!empty($conf->global->PROPOSAL_CLONE_UPDATE_PRICES) ? 1 : 0)),
  1850. );
  1851. if (!empty($conf->global->PROPAL_CLONE_DATE_DELIVERY) && !empty($object->delivery_date)) {
  1852. $formquestion[] = array('type' => 'date', 'name' => 'date_delivery', 'label' => $langs->trans("DeliveryDate"), 'value' => $object->delivery_date);
  1853. }
  1854. // Incomplete payment. We ask if reason = discount or other
  1855. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmClonePropal', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
  1856. }
  1857. if ($action == 'closeas') {
  1858. //Form to close proposal (signed or not)
  1859. $formquestion = array();
  1860. if (empty($conf->global->PROPAL_SKIP_ACCEPT_REFUSE)) {
  1861. $formquestion[] = array('type' => 'select', 'name' => 'statut', 'label' => '<span class="fieldrequired">'.$langs->trans("CloseAs").'</span>', 'values' => array($object::STATUS_SIGNED => $object->LibStatut($object::STATUS_SIGNED), $object::STATUS_NOTSIGNED => $object->LibStatut($object::STATUS_NOTSIGNED)));
  1862. }
  1863. $formquestion[] = array('type' => 'text', 'name' => 'note_private', 'label' => $langs->trans("Note"), 'value' => ''); // Field to complete private note (not replace)
  1864. if (getDolGlobalInt('PROPOSAL_SUGGEST_DOWN_PAYMENT_INVOICE_CREATION')) {
  1865. // This is a hidden option:
  1866. // Suggestion to create invoice during proposal signature is not enabled by default.
  1867. // Such choice should be managed by the workflow module and trigger. This option generates conflicts with some setup.
  1868. // It may also break step of creating an order when invoicing must be done from orders and not from proposal
  1869. $deposit_percent_from_payment_terms = getDictionaryValue('c_payment_term', 'deposit_percent', $object->cond_reglement_id);
  1870. if (!empty($deposit_percent_from_payment_terms) && isModEnabled('facture') && !empty($user->rights->facture->creer)) {
  1871. require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
  1872. $object->fetchObjectLinked();
  1873. $eligibleForDepositGeneration = true;
  1874. if (array_key_exists('facture', $object->linkedObjects)) {
  1875. foreach ($object->linkedObjects['facture'] as $invoice) {
  1876. if ($invoice->type == Facture::TYPE_DEPOSIT) {
  1877. $eligibleForDepositGeneration = false;
  1878. break;
  1879. }
  1880. }
  1881. }
  1882. if ($eligibleForDepositGeneration && array_key_exists('commande', $object->linkedObjects)) {
  1883. foreach ($object->linkedObjects['commande'] as $order) {
  1884. $order->fetchObjectLinked();
  1885. if (array_key_exists('facture', $order->linkedObjects)) {
  1886. foreach ($order->linkedObjects['facture'] as $invoice) {
  1887. if ($invoice->type == Facture::TYPE_DEPOSIT) {
  1888. $eligibleForDepositGeneration = false;
  1889. break 2;
  1890. }
  1891. }
  1892. }
  1893. }
  1894. }
  1895. if ($eligibleForDepositGeneration) {
  1896. $formquestion[] = array(
  1897. 'type' => 'checkbox',
  1898. 'tdclass' => 'showonlyifsigned',
  1899. 'name' => 'generate_deposit',
  1900. 'morecss' => 'margintoponly marginbottomonly',
  1901. 'label' => $form->textwithpicto($langs->trans('GenerateDeposit', $object->deposit_percent), $langs->trans('DepositGenerationPermittedByThePaymentTermsSelected'))
  1902. );
  1903. $formquestion[] = array(
  1904. 'type' => 'date',
  1905. 'tdclass' => 'fieldrequired showonlyifgeneratedeposit',
  1906. 'name' => 'datef',
  1907. 'label' => $langs->trans('DateInvoice'),
  1908. 'value' => dol_now(),
  1909. 'datenow' => true
  1910. );
  1911. if (!empty($conf->global->INVOICE_POINTOFTAX_DATE)) {
  1912. $formquestion[] = array(
  1913. 'type' => 'date',
  1914. 'tdclass' => 'fieldrequired showonlyifgeneratedeposit',
  1915. 'name' => 'date_pointoftax',
  1916. 'label' => $langs->trans('DatePointOfTax'),
  1917. 'value' => dol_now(),
  1918. 'datenow' => true
  1919. );
  1920. }
  1921. $paymentTermsSelect = $form->getSelectConditionsPaiements(0, 'cond_reglement_id', -1, 0, 1, 'minwidth200');
  1922. $formquestion[] = array(
  1923. 'type' => 'other',
  1924. 'tdclass' => 'fieldrequired showonlyifgeneratedeposit',
  1925. 'name' => 'cond_reglement_id',
  1926. 'label' => $langs->trans('PaymentTerm'),
  1927. 'value' => $paymentTermsSelect
  1928. );
  1929. $formquestion[] = array(
  1930. 'type' => 'checkbox',
  1931. 'tdclass' => 'showonlyifgeneratedeposit',
  1932. 'name' => 'validate_generated_deposit',
  1933. 'morecss' => 'margintoponly marginbottomonly',
  1934. 'label' => $langs->trans('ValidateGeneratedDeposit')
  1935. );
  1936. $formquestion[] = array(
  1937. 'type' => 'onecolumn',
  1938. 'value' => '
  1939. <script>
  1940. let signedValue = ' . $object::STATUS_SIGNED . ';
  1941. $(document).ready(function() {
  1942. $("[name=generate_deposit]").change(function () {
  1943. let $self = $(this);
  1944. let $target = $(".showonlyifgeneratedeposit").parent(".tagtr");
  1945. if (! $self.parents(".tagtr").is(":hidden") && $self.is(":checked")) {
  1946. $target.show();
  1947. } else {
  1948. $target.hide();
  1949. }
  1950. return true;
  1951. });
  1952. $("#statut").change(function() {
  1953. let $target = $(".showonlyifsigned").parent(".tagtr");
  1954. if ($(this).val() == signedValue) {
  1955. $target.show();
  1956. } else {
  1957. $target.hide();
  1958. }
  1959. $("[name=generate_deposit]").trigger("change");
  1960. return true;
  1961. });
  1962. $("#statut").trigger("change");
  1963. });
  1964. </script>
  1965. '
  1966. );
  1967. }
  1968. }
  1969. }
  1970. if (isModEnabled('notification')) {
  1971. require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
  1972. $notify = new Notify($db);
  1973. $formquestion = array_merge($formquestion, array(
  1974. array('type' => 'onecolumn', 'value' => $notify->confirmMessage('PROPAL_CLOSE_SIGNED', $object->socid, $object)),
  1975. ));
  1976. }
  1977. if (empty($conf->global->PROPAL_SKIP_ACCEPT_REFUSE)) {
  1978. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('SetAcceptedRefused'), $text, 'confirm_closeas', $formquestion, '', 1, 250);
  1979. } else {
  1980. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?statut=3&id=' . $object->id, $langs->trans('Close'), $text, 'confirm_closeas', $formquestion, '', 1, 250);
  1981. }
  1982. } elseif ($action == 'delete') {
  1983. // Confirm delete
  1984. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteProp'), $langs->trans('ConfirmDeleteProp', $object->ref), 'confirm_delete', '', 0, 1);
  1985. } elseif ($action == 'reopen') {
  1986. // Confirm reopen
  1987. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ReOpen'), $langs->trans('ConfirmReOpenProp', $object->ref), 'confirm_reopen', '', 0, 1);
  1988. } elseif ($action == 'ask_deleteline') {
  1989. // Confirmation delete product/service line
  1990. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline', '', 0, 1);
  1991. } elseif ($action == 'validate') {
  1992. // Confirm validate proposal
  1993. $error = 0;
  1994. // We verify whether the object is provisionally numbering
  1995. $ref = substr($object->ref, 1, 4);
  1996. if ($ref == 'PROV' || $ref == '') {
  1997. $numref = $object->getNextNumRef($soc);
  1998. if (empty($numref)) {
  1999. $error++;
  2000. setEventMessages($object->error, $object->errors, 'errors');
  2001. }
  2002. } else {
  2003. $numref = $object->ref;
  2004. }
  2005. $text = $langs->trans('ConfirmValidateProp', $numref);
  2006. if (isModEnabled('notification')) {
  2007. require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
  2008. $notify = new Notify($db);
  2009. $text .= '<br>';
  2010. $text .= $notify->confirmMessage('PROPAL_VALIDATE', $object->socid, $object);
  2011. }
  2012. // mandatoryPeriod
  2013. $nbMandated = 0;
  2014. foreach ($object->lines as $line) {
  2015. $res = $line->fetch_product();
  2016. if ($res > 0 ) {
  2017. if ($line->product->isService() && $line->product->isMandatoryPeriod() && (empty($line->date_start) || empty($line->date_end) )) {
  2018. $nbMandated++;
  2019. break;
  2020. }
  2021. }
  2022. }
  2023. if ($nbMandated > 0) {
  2024. $text .= '<div><span class="clearboth nowraponall warning">'.$langs->trans("mandatoryPeriodNeedTobeSetMsgValidate").'</span></div>';
  2025. }
  2026. if (!$error) {
  2027. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateProp'), $text, 'confirm_validate', '', 0, 1);
  2028. }
  2029. }
  2030. // Call Hook formConfirm
  2031. $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
  2032. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  2033. if (empty($reshook)) {
  2034. $formconfirm .= $hookmanager->resPrint;
  2035. } elseif ($reshook > 0) {
  2036. $formconfirm = $hookmanager->resPrint;
  2037. }
  2038. // Print form confirm
  2039. print $formconfirm;
  2040. // Proposal card
  2041. $linkback = '<a href="'.DOL_URL_ROOT.'/comm/propal/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  2042. $morehtmlref = '<div class="refidno">';
  2043. // Ref customer
  2044. $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $usercancreate, 'string', '', 0, 1);
  2045. $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $usercancreate, 'string'.(isset($conf->global->THIRDPARTY_REF_INPUT_SIZE) ? ':'.$conf->global->THIRDPARTY_REF_INPUT_SIZE : ''), '', null, null, '', 1);
  2046. // Thirdparty
  2047. $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1, 'customer');
  2048. if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
  2049. $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/comm/propal/list.php?socid='.$object->thirdparty->id.'&search_societe='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherProposals").'</a>)';
  2050. }
  2051. // Project
  2052. if (isModEnabled('project')) {
  2053. $langs->load("projects");
  2054. $morehtmlref .= '<br>';
  2055. if ($usercancreate) {
  2056. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  2057. if ($action != 'classify') {
  2058. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  2059. }
  2060. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  2061. } else {
  2062. if (!empty($object->fk_project)) {
  2063. $proj = new Project($db);
  2064. $proj->fetch($object->fk_project);
  2065. $morehtmlref .= $proj->getNomUrl(1);
  2066. if ($proj->title) {
  2067. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  2068. }
  2069. }
  2070. }
  2071. }
  2072. $morehtmlref .= '</div>';
  2073. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  2074. print '<div class="fichecenter">';
  2075. print '<div class="fichehalfleft">';
  2076. print '<div class="underbanner clearboth"></div>';
  2077. print '<table class="border tableforfield centpercent">';
  2078. // Link for thirdparty discounts
  2079. if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
  2080. $filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
  2081. $filtercreditnote = "fk_facture_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
  2082. } else {
  2083. $filterabsolutediscount = "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";
  2084. $filtercreditnote = "fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";
  2085. }
  2086. print '<tr><td class="titlefield">'.$langs->trans('Discounts').'</td><td>';
  2087. $absolute_discount = $soc->getAvailableDiscounts('', $filterabsolutediscount);
  2088. $absolute_creditnote = $soc->getAvailableDiscounts('', $filtercreditnote);
  2089. $absolute_discount = price2num($absolute_discount, 'MT');
  2090. $absolute_creditnote = price2num($absolute_creditnote, 'MT');
  2091. $caneditfield = ($object->statut != Propal::STATUS_SIGNED && $object->statut != Propal::STATUS_BILLED);
  2092. $thirdparty = $soc;
  2093. $discount_type = 0;
  2094. $backtopage = urlencode($_SERVER["PHP_SELF"].'?id='.$object->id);
  2095. include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
  2096. print '</td></tr>';
  2097. // Date of proposal
  2098. print '<tr>';
  2099. print '<td>';
  2100. // print '<table class="nobordernopadding" width="100%"><tr><td>';
  2101. // print $langs->trans('DatePropal');
  2102. // print '</td>';
  2103. // if ($action != 'editdate' && $usercancreate && $caneditfield) {
  2104. // print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editdate&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetDate'), 1).'</a></td>';
  2105. // }
  2106. // print '</tr></table>';
  2107. $editenable = $usercancreate && $caneditfield && $object->statut == Propal::STATUS_DRAFT;
  2108. print $form->editfieldkey("DatePropal", 'date', '', $object, $editenable);
  2109. print '</td><td class="valuefield">';
  2110. if ($action == 'editdate' && $usercancreate && $caneditfield) {
  2111. print '<form name="editdate" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
  2112. print '<input type="hidden" name="token" value="'.newToken().'">';
  2113. print '<input type="hidden" name="action" value="setdate">';
  2114. print $form->selectDate($object->date, 're', '', '', 0, "editdate");
  2115. print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
  2116. print '</form>';
  2117. } else {
  2118. if ($object->date) {
  2119. print dol_print_date($object->date, 'day');
  2120. } else {
  2121. print '&nbsp;';
  2122. }
  2123. }
  2124. print '</td>';
  2125. // Date end proposal
  2126. print '<tr>';
  2127. print '<td>';
  2128. print '<table class="nobordernopadding centpercent"><tr><td>';
  2129. print $langs->trans('DateEndPropal');
  2130. print '</td>';
  2131. if ($action != 'editecheance' && $usercancreate && $caneditfield) {
  2132. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editecheance&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetConditions'), 1).'</a></td>';
  2133. }
  2134. print '</tr></table>';
  2135. print '</td><td class="valuefield">';
  2136. if ($action == 'editecheance' && $usercancreate && $caneditfield) {
  2137. print '<form name="editecheance" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
  2138. print '<input type="hidden" name="token" value="'.newToken().'">';
  2139. print '<input type="hidden" name="action" value="setecheance">';
  2140. print $form->selectDate($object->fin_validite, 'ech', '', '', '', "editecheance");
  2141. print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
  2142. print '</form>';
  2143. } else {
  2144. if (!empty($object->fin_validite)) {
  2145. print dol_print_date($object->fin_validite, 'day');
  2146. if ($object->statut == Propal::STATUS_VALIDATED && $object->fin_validite < ($now - $conf->propal->cloture->warning_delay)) {
  2147. print img_warning($langs->trans("Late"));
  2148. }
  2149. } else {
  2150. print '&nbsp;';
  2151. }
  2152. }
  2153. print '</td>';
  2154. print '</tr>';
  2155. // Payment term
  2156. print '<tr><td>';
  2157. print '<table class="nobordernopadding" width="100%"><tr><td>';
  2158. print $langs->trans('PaymentConditionsShort');
  2159. print '</td>';
  2160. if ($action != 'editconditions' && $usercancreate && $caneditfield) {
  2161. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editconditions&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetConditions'), 1).'</a></td>';
  2162. }
  2163. print '</tr></table>';
  2164. print '</td><td class="valuefield">';
  2165. if ($action == 'editconditions' && $usercancreate && $caneditfield) {
  2166. $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'cond_reglement_id', 0, '', 1, $object->deposit_percent);
  2167. } else {
  2168. $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'none', 0, '', 1, $object->deposit_percent);
  2169. }
  2170. print '</td>';
  2171. print '</tr>';
  2172. // Payment mode
  2173. print '<tr class="field_mode_reglement_id">';
  2174. print '<td class="titlefieldcreate">';
  2175. print '<table class="nobordernopadding centpercent"><tr><td>';
  2176. print $langs->trans('PaymentMode');
  2177. print '</td>';
  2178. if ($action != 'editmode' && $usercancreate && $caneditfield) {
  2179. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmode&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetMode'), 1).'</a></td>';
  2180. }
  2181. print '</tr></table>';
  2182. print '</td><td class="valuefieldcreate">';
  2183. if ($action == 'editmode' && $usercancreate && $caneditfield) {
  2184. $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'mode_reglement_id', 'CRDT', 1, 1);
  2185. } else {
  2186. $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'none');
  2187. }
  2188. print '</td></tr>';
  2189. // Delivery date
  2190. $langs->load('deliveries');
  2191. print '<tr><td>';
  2192. print $form->editfieldkey($langs->trans('DeliveryDate'), 'date_livraison', $object->delivery_date, $object, $usercancreate && $caneditfield, 'datepicker');
  2193. print '</td><td class="valuefieldedit">';
  2194. print $form->editfieldval($langs->trans('DeliveryDate'), 'date_livraison', $object->delivery_date, $object, $usercancreate && $caneditfield, 'datepicker');
  2195. print '</td>';
  2196. print '</tr>';
  2197. // Delivery delay
  2198. print '<tr class="fielddeliverydelay"><td>';
  2199. print '<table class="nobordernopadding" width="100%"><tr><td>';
  2200. if (isModEnabled('commande')) {
  2201. print $form->textwithpicto($langs->trans('AvailabilityPeriod'), $langs->trans('AvailabilityPeriod').' ('.$langs->trans('AfterOrder').')');
  2202. } else {
  2203. print $langs->trans('AvailabilityPeriod');
  2204. }
  2205. print '</td>';
  2206. if ($action != 'editavailability' && $usercancreate && $caneditfield) {
  2207. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editavailability&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetAvailability'), 1).'</a></td>';
  2208. }
  2209. print '</tr></table>';
  2210. print '</td><td class="valuefield">';
  2211. if ($action == 'editavailability' && $usercancreate && $caneditfield) {
  2212. $form->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id, $object->availability_id, 'availability_id', 1);
  2213. } else {
  2214. $form->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id, $object->availability_id, 'none', 1);
  2215. }
  2216. print '</td>';
  2217. print '</tr>';
  2218. // Shipping Method
  2219. if (isModEnabled("expedition")) {
  2220. print '<tr><td>';
  2221. print '<table class="nobordernopadding centpercent"><tr><td>';
  2222. print $langs->trans('SendingMethod');
  2223. print '</td>';
  2224. if ($action != 'editshippingmethod' && $usercancreate && $caneditfield) {
  2225. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editshippingmethod&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetShippingMode'), 1).'</a></td>';
  2226. }
  2227. print '</tr></table>';
  2228. print '</td><td class="valuefield">';
  2229. if ($action == 'editshippingmethod' && $usercancreate && $caneditfield) {
  2230. $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'shipping_method_id', 1);
  2231. } else {
  2232. $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'none');
  2233. }
  2234. print '</td>';
  2235. print '</tr>';
  2236. }
  2237. // Warehouse
  2238. if (isModEnabled('stock') && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_PROPAL)) {
  2239. $langs->load('stocks');
  2240. require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
  2241. $formproduct = new FormProduct($db);
  2242. print '<tr class="field_warehouse_id"><td class="titlefieldcreate">';
  2243. $editenable = $usercancreate;
  2244. print $form->editfieldkey("Warehouse", 'warehouse', '', $object, $editenable);
  2245. print '</td><td class="valuefieldcreate">';
  2246. if ($action == 'editwarehouse') {
  2247. $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->warehouse_id, 'warehouse_id', 1);
  2248. } else {
  2249. $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->warehouse_id, 'none');
  2250. }
  2251. print '</td>';
  2252. print '</tr>';
  2253. }
  2254. // Origin of demand
  2255. print '<tr><td>';
  2256. print '<table class="nobordernopadding centpercent"><tr><td>';
  2257. print $langs->trans('Source');
  2258. print '</td>';
  2259. if ($action != 'editdemandreason' && $usercancreate) {
  2260. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editdemandreason&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetDemandReason'), 1).'</a></td>';
  2261. }
  2262. print '</tr></table>';
  2263. print '</td><td class="valuefield">';
  2264. if ($action == 'editdemandreason' && $usercancreate) {
  2265. $form->formInputReason($_SERVER['PHP_SELF'].'?id='.$object->id, $object->demand_reason_id, 'demand_reason_id', 1);
  2266. } else {
  2267. $form->formInputReason($_SERVER['PHP_SELF'].'?id='.$object->id, $object->demand_reason_id, 'none');
  2268. }
  2269. print '</td>';
  2270. print '</tr>';
  2271. // Multicurrency
  2272. if (isModEnabled("multicurrency")) {
  2273. // Multicurrency code
  2274. print '<tr>';
  2275. print '<td>';
  2276. print '<table class="nobordernopadding" width="100%"><tr><td>';
  2277. print $form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0);
  2278. print '</td>';
  2279. if ($action != 'editmulticurrencycode' && $object->statut == $object::STATUS_DRAFT && $usercancreate) {
  2280. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmulticurrencycode&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1).'</a></td>';
  2281. }
  2282. print '</tr></table>';
  2283. print '</td><td class="valuefield">';
  2284. if ($object->statut == $object::STATUS_DRAFT && $action == 'editmulticurrencycode' && $usercancreate) {
  2285. $form->form_multicurrency_code($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_code, 'multicurrency_code');
  2286. } else {
  2287. $form->form_multicurrency_code($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_code, 'none');
  2288. }
  2289. print '</td></tr>';
  2290. // Multicurrency rate
  2291. if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
  2292. print '<tr>';
  2293. print '<td>';
  2294. print '<table class="nobordernopadding" width="100%"><tr>';
  2295. print '<td>';
  2296. print $form->editfieldkey('CurrencyRate', 'multicurrency_tx', '', $object, 0);
  2297. print '</td>';
  2298. if ($action != 'editmulticurrencyrate' && $object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency && $usercancreate) {
  2299. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmulticurrencyrate&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1).'</a></td>';
  2300. }
  2301. print '</tr></table>';
  2302. print '</td><td class="valuefield">';
  2303. if ($object->statut == $object::STATUS_DRAFT && ($action == 'editmulticurrencyrate' || $action == 'actualizemulticurrencyrate') && $usercancreate) {
  2304. if ($action == 'actualizemulticurrencyrate') {
  2305. list($object->fk_multicurrency, $object->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($object->db, $object->multicurrency_code);
  2306. }
  2307. $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, 'multicurrency_tx', $object->multicurrency_code);
  2308. } else {
  2309. $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, 'none', $object->multicurrency_code);
  2310. if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
  2311. print '<div class="inline-block"> &nbsp; &nbsp; &nbsp; &nbsp; ';
  2312. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=actualizemulticurrencyrate">'.$langs->trans("ActualizeCurrency").'</a>';
  2313. print '</div>';
  2314. }
  2315. }
  2316. print '</td></tr>';
  2317. }
  2318. }
  2319. if ($soc->outstanding_limit) {
  2320. // Outstanding Bill
  2321. print '<tr><td>';
  2322. print $langs->trans('OutstandingBill');
  2323. print '</td><td class="valuefield">';
  2324. $arrayoutstandingbills = $soc->getOutstandingBills();
  2325. print ($arrayoutstandingbills['opened'] > $soc->outstanding_limit ? img_warning() : '');
  2326. print price($arrayoutstandingbills['opened']).' / ';
  2327. print price($soc->outstanding_limit, 0, $langs, 1, - 1, - 1, $conf->currency);
  2328. print '</td>';
  2329. print '</tr>';
  2330. }
  2331. if (!empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_PROPOSAL) && isModEnabled("banque")) {
  2332. // Bank Account
  2333. print '<tr><td>';
  2334. print '<table width="100%" class="nobordernopadding"><tr><td>';
  2335. print $langs->trans('BankAccount');
  2336. print '</td>';
  2337. if ($action != 'editbankaccount' && $usercancreate) {
  2338. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editbankaccount&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetBankAccount'), 1).'</a></td>';
  2339. }
  2340. print '</tr></table>';
  2341. print '</td><td class="valuefield">';
  2342. if ($action == 'editbankaccount') {
  2343. $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1);
  2344. } else {
  2345. $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
  2346. }
  2347. print '</td>';
  2348. print '</tr>';
  2349. }
  2350. $tmparray = $object->getTotalWeightVolume();
  2351. $totalWeight = $tmparray['weight'];
  2352. $totalVolume = $tmparray['volume'];
  2353. if ($totalWeight) {
  2354. print '<tr><td>'.$langs->trans("CalculatedWeight").'</td>';
  2355. print '<td class="valuefield">';
  2356. print showDimensionInBestUnit($totalWeight, 0, "weight", $langs, isset($conf->global->MAIN_WEIGHT_DEFAULT_ROUND) ? $conf->global->MAIN_WEIGHT_DEFAULT_ROUND : -1, isset($conf->global->MAIN_WEIGHT_DEFAULT_UNIT) ? $conf->global->MAIN_WEIGHT_DEFAULT_UNIT : 'no', 0);
  2357. print '</td></tr>';
  2358. }
  2359. if ($totalVolume) {
  2360. print '<tr><td>'.$langs->trans("CalculatedVolume").'</td>';
  2361. print '<td class="valuefield">';
  2362. print showDimensionInBestUnit($totalVolume, 0, "volume", $langs, isset($conf->global->MAIN_VOLUME_DEFAULT_ROUND) ? $conf->global->MAIN_VOLUME_DEFAULT_ROUND : -1, isset($conf->global->MAIN_VOLUME_DEFAULT_UNIT) ? $conf->global->MAIN_VOLUME_DEFAULT_UNIT : 'no', 0);
  2363. print '</td></tr>';
  2364. }
  2365. // Incoterms
  2366. if (isModEnabled('incoterm')) {
  2367. print '<tr><td>';
  2368. print '<table width="100%" class="nobordernopadding"><tr><td>';
  2369. print $langs->trans('IncotermLabel');
  2370. print '<td><td class="right">';
  2371. if ($action != 'editincoterm' && $usercancreate && $caneditfield) {
  2372. print '<a class="editfielda" href="'.DOL_URL_ROOT.'/comm/propal/card.php?id='.$object->id.'&action=editincoterm&token='.newToken().'">'.img_edit().'</a>';
  2373. } else {
  2374. print '&nbsp;';
  2375. }
  2376. print '</td></tr></table>';
  2377. print '</td>';
  2378. print '<td class="valuefield">';
  2379. if ($action == 'editincoterm' && $usercancreate && $caneditfield) {
  2380. print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?id='.$object->id);
  2381. } else {
  2382. print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
  2383. }
  2384. print '</td></tr>';
  2385. }
  2386. // Other attributes
  2387. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  2388. print '</table>';
  2389. print '</div>';
  2390. print '<div class="fichehalfright">';
  2391. print '<div class="underbanner clearboth"></div>';
  2392. print '<table class="border tableforfield centpercent">';
  2393. if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
  2394. // Multicurrency Amount HT
  2395. print '<tr><td class="titlefieldmiddle">'.$form->editfieldkey('MulticurrencyAmountHT', 'multicurrency_total_ht', '', $object, 0).'</td>';
  2396. print '<td class="nowrap right amountcard">'.price($object->multicurrency_total_ht, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'</td>';
  2397. print '</tr>';
  2398. // Multicurrency Amount VAT
  2399. print '<tr><td>'.$form->editfieldkey('MulticurrencyAmountVAT', 'multicurrency_total_tva', '', $object, 0).'</td>';
  2400. print '<td class="nowrap right amountcard">'.price($object->multicurrency_total_tva, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'</td>';
  2401. print '</tr>';
  2402. // Multicurrency Amount TTC
  2403. print '<tr><td>'.$form->editfieldkey('MulticurrencyAmountTTC', 'multicurrency_total_ttc', '', $object, 0).'</td>';
  2404. print '<td class="nowrap right amountcard">'.price($object->multicurrency_total_ttc, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'</td>';
  2405. print '</tr>';
  2406. }
  2407. // Amount HT
  2408. print '<tr><td class="titlefieldmiddle">'.$langs->trans('AmountHT').'</td>';
  2409. print '<td class="nowrap right amountcard">'.price($object->total_ht, '', $langs, 0, - 1, - 1, $conf->currency).'</td>';
  2410. print '</tr>';
  2411. // Amount VAT
  2412. print '<tr><td>'.$langs->trans('AmountVAT').'</td>';
  2413. print '<td class="nowrap right amountcard">'.price($object->total_tva, '', $langs, 0, - 1, - 1, $conf->currency).'</td>';
  2414. print '</tr>';
  2415. // Amount Local Taxes
  2416. if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) { // Localtax1
  2417. print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td>';
  2418. print '<td class="nowrap right amountcard">'.price($object->total_localtax1, '', $langs, 0, - 1, - 1, $conf->currency).'</td>';
  2419. print '</tr>';
  2420. }
  2421. if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) { // Localtax2
  2422. print '<tr><td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td>';
  2423. print '<td class="nowrap right amountcard">'.price($object->total_localtax2, '', $langs, 0, - 1, - 1, $conf->currency).'</td>';
  2424. print '</tr>';
  2425. }
  2426. // Amount TTC
  2427. print '<tr><td>'.$langs->trans('AmountTTC').'</td>';
  2428. print '<td class="nowrap right amountcard">'.price($object->total_ttc, '', $langs, 0, - 1, - 1, $conf->currency).'</td>';
  2429. print '</tr>';
  2430. // Statut
  2431. //print '<tr><td height="10">' . $langs->trans('Status') . '</td><td class="left" colspan="2">' . $object->getLibStatut(4) . '</td></tr>';
  2432. print '</table>';
  2433. // Margin Infos
  2434. if (isModEnabled('margin')) {
  2435. $formmargin->displayMarginInfos($object);
  2436. }
  2437. print '</div>';
  2438. print '</div>';
  2439. print '<div class="clearboth"></div><br>';
  2440. if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
  2441. $blocname = 'contacts';
  2442. $title = $langs->trans('ContactsAddresses');
  2443. include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
  2444. }
  2445. if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
  2446. $blocname = 'notes';
  2447. $title = $langs->trans('Notes');
  2448. include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
  2449. }
  2450. /*
  2451. * Lines
  2452. */
  2453. // Get object lines
  2454. $result = $object->getLinesArray();
  2455. // Add products/services form
  2456. //$forceall = 1;
  2457. global $inputalsopricewithtax;
  2458. $inputalsopricewithtax = 1;
  2459. print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">
  2460. <input type="hidden" name="token" value="' . newToken().'">
  2461. <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline').'">
  2462. <input type="hidden" name="mode" value="">
  2463. <input type="hidden" name="page_y" value="">
  2464. <input type="hidden" name="id" value="' . $object->id.'">
  2465. ';
  2466. if (!empty($conf->use_javascript_ajax) && $object->statut == Propal::STATUS_DRAFT) {
  2467. include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
  2468. }
  2469. print '<div class="div-table-responsive-no-min">';
  2470. if (!empty($object->lines) || ($object->statut == Propal::STATUS_DRAFT && $usercancreate && $action != 'selectlines' && $action != 'editline')) {
  2471. print '<table id="tablelines" class="noborder noshadow" width="100%">';
  2472. }
  2473. if (!empty($object->lines)) {
  2474. $object->printObjectLines($action, $mysoc, $soc, $lineid, 1);
  2475. }
  2476. // Form to add new line
  2477. if ($object->statut == Propal::STATUS_DRAFT && $usercancreate && $action != 'selectlines') {
  2478. if ($action != 'editline') {
  2479. $parameters = array();
  2480. $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  2481. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  2482. if (empty($reshook))
  2483. $object->formAddObjectLine(1, $mysoc, $soc);
  2484. } else {
  2485. $parameters = array();
  2486. $reshook = $hookmanager->executeHooks('formEditObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  2487. }
  2488. }
  2489. if (!empty($object->lines) || ($object->statut == Propal::STATUS_DRAFT && $usercancreate && $action != 'selectlines' && $action != 'editline')) {
  2490. print '</table>';
  2491. }
  2492. print '</div>';
  2493. print "</form>\n";
  2494. print dol_get_fiche_end();
  2495. /*
  2496. * Button Actions
  2497. */
  2498. if ($action != 'presend') {
  2499. print '<div class="tabsAction">';
  2500. $parameters = array();
  2501. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
  2502. // modified by hook
  2503. if (empty($reshook)) {
  2504. if ($action != 'editline') {
  2505. // Validate
  2506. if (($object->statut == Propal::STATUS_DRAFT && $object->total_ttc >= 0 && count($object->lines) > 0)
  2507. || ($object->statut == Propal::STATUS_DRAFT && !empty($conf->global->PROPAL_ENABLE_NEGATIVE) && count($object->lines) > 0)) {
  2508. if ($usercanvalidate) {
  2509. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=validate&token='.newToken().'">'.(empty($conf->global->PROPAL_SKIP_ACCEPT_REFUSE) ? $langs->trans('Validate') : $langs->trans('ValidateAndSign')).'</a>';
  2510. } else {
  2511. print '<a class="butActionRefused classfortooltip" href="#">'.$langs->trans('Validate').'</a>';
  2512. }
  2513. }
  2514. // Create event
  2515. /*if ($conf->agenda->enabled && !empty($conf->global->MAIN_ADD_EVENT_ON_ELEMENT_CARD)) // Add hidden condition because this is not a "workflow" action so should appears somewhere else on page.
  2516. {
  2517. print '<a class="butAction" href="' . DOL_URL_ROOT . '/comm/action/card.php?action=create&amp;origin=' . $object->element . '&amp;originid=' . $object->id . '&amp;socid=' . $object->socid . '">' . $langs->trans("AddAction") . '</a></div>';
  2518. }*/
  2519. // Edit
  2520. if ($object->statut == Propal::STATUS_VALIDATED && $usercancreate) {
  2521. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=modif&token='.newToken().'">'.$langs->trans('Modify').'</a>';
  2522. }
  2523. // ReOpen
  2524. if ( (( !empty($conf->global->PROPAL_REOPEN_UNSIGNED_ONLY) && $object->statut == Propal::STATUS_NOTSIGNED) || (empty($conf->global->PROPAL_REOPEN_UNSIGNED_ONLY) && ($object->statut == Propal::STATUS_SIGNED || $object->statut == Propal::STATUS_NOTSIGNED || $object->statut == Propal::STATUS_BILLED))) && $usercanclose) {
  2525. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=reopen&token='.newToken().(empty($conf->global->MAIN_JUMP_TAG) ? '' : '#reopen').'"';
  2526. print '>'.$langs->trans('ReOpen').'</a>';
  2527. }
  2528. // Send
  2529. if (empty($user->socid)) {
  2530. if ($object->statut == Propal::STATUS_VALIDATED || $object->statut == Propal::STATUS_SIGNED || !empty($conf->global->PROPOSAL_SENDBYEMAIL_FOR_ALL_STATUS)) {
  2531. print dolGetButtonAction('', $langs->trans('SendMail'), 'default', $_SERVER["PHP_SELF"].'?action=presend&token='.newToken().'&id='.$object->id.'&mode=init#formmailbeforetitle', '', $usercansend);
  2532. }
  2533. }
  2534. // Create a sale order
  2535. if (isModEnabled('commande') && $object->statut == Propal::STATUS_SIGNED) {
  2536. if ($usercancreateorder) {
  2537. print '<a class="butAction" href="'.DOL_URL_ROOT.'/commande/card.php?action=create&origin='.$object->element.'&originid='.$object->id.'&socid='.$object->socid.'">'.$langs->trans("AddOrder").'</a>';
  2538. }
  2539. }
  2540. // Create a purchase order
  2541. if (!empty($conf->global->WORKFLOW_CAN_CREATE_PURCHASE_ORDER_FROM_PROPOSAL)) {
  2542. if ($object->statut == Propal::STATUS_SIGNED && ((isModEnabled("fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || isModEnabled("supplier_order"))) {
  2543. if ($usercancreatepurchaseorder) {
  2544. print '<a class="butAction" href="'.DOL_URL_ROOT.'/fourn/commande/card.php?action=create&origin='.$object->element.'&originid='.$object->id.'&socid='.$object->socid.'">'.$langs->trans("AddPurchaseOrder").'</a>';
  2545. }
  2546. }
  2547. }
  2548. // Create an intervention
  2549. if (isModEnabled("service") && isModEnabled('ficheinter') && $object->statut == Propal::STATUS_SIGNED) {
  2550. if ($usercancreateintervention) {
  2551. $langs->load("interventions");
  2552. print '<a class="butAction" href="'.DOL_URL_ROOT.'/fichinter/card.php?action=create&origin='.$object->element.'&originid='.$object->id.'&socid='.$object->socid.'">'.$langs->trans("AddIntervention").'</a>';
  2553. }
  2554. }
  2555. // Create contract
  2556. if (isModEnabled('contrat') && $object->statut == Propal::STATUS_SIGNED) {
  2557. $langs->load("contracts");
  2558. if ($usercancreatecontract) {
  2559. print '<a class="butAction" href="'.DOL_URL_ROOT.'/contrat/card.php?action=create&origin='.$object->element.'&originid='.$object->id.'&socid='.$object->socid.'">'.$langs->trans('AddContract').'</a>';
  2560. }
  2561. }
  2562. // Create an invoice and classify billed
  2563. if ($object->statut == Propal::STATUS_SIGNED && empty($conf->global->PROPOSAL_ARE_NOT_BILLABLE)) {
  2564. if (isModEnabled('facture') && $usercancreateinvoice) {
  2565. print '<a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture/card.php?action=create&origin='.$object->element.'&originid='.$object->id.'&socid='.$object->socid.'">'.$langs->trans("CreateBill").'</a>';
  2566. }
  2567. $arrayofinvoiceforpropal = $object->getInvoiceArrayList();
  2568. if ((is_array($arrayofinvoiceforpropal) && count($arrayofinvoiceforpropal) > 0) || empty($conf->global->WORKFLOW_PROPAL_NEED_INVOICE_TO_BE_CLASSIFIED_BILLED)) {
  2569. if ($usercanclose) {
  2570. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=classifybilled&token='.newToken().'&socid='.$object->socid.'">'.$langs->trans("ClassifyBilled").'</a>';
  2571. } else {
  2572. print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans("ClassifyBilled").'</a>';
  2573. }
  2574. }
  2575. }
  2576. if (empty($conf->global->PROPAL_SKIP_ACCEPT_REFUSE)) {
  2577. // Close as accepted/refused
  2578. if ($object->statut == Propal::STATUS_VALIDATED) {
  2579. if ($usercanclose) {
  2580. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=closeas&token='.newToken().(empty($conf->global->MAIN_JUMP_TAG) ? '' : '#close').'"';
  2581. print '>'.$langs->trans('SetAcceptedRefused').'</a>';
  2582. } else {
  2583. print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'"';
  2584. print '>'.$langs->trans('SetAcceptedRefused').'</a>';
  2585. }
  2586. }
  2587. } else {
  2588. // Set not signed (close)
  2589. if ($object->statut == Propal::STATUS_DRAFT && $usercanclose) {
  2590. print '<a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&token='.newToken().'&action=closeas&token='.newToken() . (empty($conf->global->MAIN_JUMP_TAG) ? '' : '#close') . '"';
  2591. print '>' . $langs->trans('SetRefusedAndClose') . '</a>';
  2592. }
  2593. }
  2594. // Clone
  2595. if ($usercancreate) {
  2596. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&socid='.$object->socid.'&action=clone&token='.newToken().'&object='.$object->element.'">'.$langs->trans("ToClone").'</a>';
  2597. }
  2598. // Delete
  2599. print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $usercandelete);
  2600. }
  2601. }
  2602. print '</div>';
  2603. }
  2604. //Select mail models is same action as presend
  2605. if (GETPOST('modelselected')) {
  2606. $action = 'presend';
  2607. }
  2608. if ($action != 'presend') {
  2609. print '<div class="fichecenter"><div class="fichehalfleft">';
  2610. print '<a name="builddoc"></a>'; // ancre
  2611. /*
  2612. * Generated documents
  2613. */
  2614. $objref = dol_sanitizeFileName($object->ref);
  2615. $filedir = $conf->propal->multidir_output[$object->entity]."/".dol_sanitizeFileName($object->ref);
  2616. $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
  2617. $genallowed = $usercanread;
  2618. $delallowed = $usercancreate;
  2619. print $formfile->showdocuments('propal', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', 0, '', $soc->default_lang, '', $object);
  2620. // Show links to link elements
  2621. $linktoelem = $form->showLinkToObjectBlock($object, null, array('propal'));
  2622. $compatibleImportElementsList = false;
  2623. if ($user->rights->propal->creer && $object->statut == Propal::STATUS_DRAFT) {
  2624. $compatibleImportElementsList = array('commande', 'propal'); // import from linked elements
  2625. }
  2626. $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem, $compatibleImportElementsList);
  2627. // Show online signature link
  2628. $useonlinesignature = 1;
  2629. if ($object->statut != Propal::STATUS_DRAFT && $useonlinesignature) {
  2630. print '<br><!-- Link to sign -->';
  2631. require_once DOL_DOCUMENT_ROOT.'/core/lib/signature.lib.php';
  2632. print showOnlineSignatureUrl('proposal', $object->ref).'<br>';
  2633. }
  2634. print '</div><div class="fichehalfright">';
  2635. // List of actions on element
  2636. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  2637. $formactions = new FormActions($db);
  2638. $somethingshown = $formactions->showactions($object, 'propal', $socid, 1);
  2639. print '</div></div>';
  2640. }
  2641. // Presend form
  2642. $modelmail = 'propal_send';
  2643. $defaulttopic = 'SendPropalRef';
  2644. $diroutput = $conf->propal->multidir_output[$object->entity];
  2645. $trackid = 'pro'.$object->id;
  2646. include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
  2647. }
  2648. // End of page
  2649. llxFooter();
  2650. $db->close();