card.php 109 KB

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