card.php 109 KB

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