card.php 112 KB

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