card.php 121 KB

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