card.php 134 KB

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