card.php 142 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334
  1. <?php
  2. /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2003 Brian Fraval <brian@fraval.org>
  4. * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
  6. * Copyright (C) 2005-2017 Regis Houssin <regis.houssin@inodbox.com>
  7. * Copyright (C) 2008 Patrick Raguin <patrick.raguin@auguria.net>
  8. * Copyright (C) 2010-2020 Juanjo Menent <jmenent@2byte.es>
  9. * Copyright (C) 2011-2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
  10. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  11. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  12. * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  13. * Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
  14. * Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es.com>
  15. * Copyright (C) 2018-2022 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/societe/card.php
  32. * \ingroup societe
  33. * \brief Third party card page
  34. */
  35. // Load Dolibarr environment
  36. require '../main.inc.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  40. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
  41. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  42. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  43. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  44. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  45. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  46. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  47. if (isModEnabled('adherent')) {
  48. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  49. }
  50. if (isModEnabled('accounting')) {
  51. require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
  52. }
  53. if (isModEnabled('accounting')) {
  54. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
  55. }
  56. if (isModEnabled('accounting')) {
  57. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
  58. }
  59. if (isModEnabled('eventorganization')) {
  60. require_once DOL_DOCUMENT_ROOT.'/eventorganization/class/conferenceorboothattendee.class.php';
  61. }
  62. // Load translation files required by the page
  63. $langs->loadLangs(array("companies", "commercial", "bills", "banks", "users"));
  64. if (isModEnabled('adherent')) {
  65. $langs->load("members");
  66. }
  67. if (isModEnabled('categorie')) {
  68. $langs->load("categories");
  69. }
  70. if (isModEnabled('incoterm')) {
  71. $langs->load("incoterm");
  72. }
  73. if (isModEnabled('notification')) {
  74. $langs->load("mails");
  75. }
  76. if (isModEnabled('accounting')) {
  77. $langs->load("products");
  78. }
  79. $error = 0; $errors = array();
  80. // Get parameters
  81. $action = (GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view');
  82. $cancel = GETPOST('cancel', 'alpha');
  83. $backtopage = GETPOST('backtopage', 'alpha');
  84. $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
  85. $backtopagejsfields = GETPOST('backtopagejsfields', 'alpha');
  86. $dol_openinpopup = GETPOST('dol_openinpopup', 'aZ09');
  87. $confirm = GETPOST('confirm', 'alpha');
  88. $socid = GETPOST('socid', 'int') ?GETPOST('socid', 'int') : GETPOST('id', 'int');
  89. if ($user->socid) {
  90. $socid = $user->socid;
  91. }
  92. if (empty($socid) && $action == 'view') {
  93. $action = 'create';
  94. }
  95. $id = $socid;
  96. $object = new Societe($db);
  97. $extrafields = new ExtraFields($db);
  98. // fetch optionals attributes and labels
  99. $extrafields->fetch_name_optionals_label($object->table_element);
  100. $socialnetworks = getArrayOfSocialNetworks();
  101. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  102. $hookmanager->initHooks(array('thirdpartycard', 'globalcard'));
  103. if ($socid > 0) {
  104. $object->fetch($socid);
  105. }
  106. if (!($object->id > 0) && $action == 'view') {
  107. $langs->load("errors");
  108. print($langs->trans('ErrorRecordNotFound'));
  109. exit;
  110. }
  111. // Get object canvas (By default, this is not defined, so standard usage of dolibarr)
  112. $canvas = $object->canvas ? $object->canvas : GETPOST("canvas");
  113. $objcanvas = null;
  114. if (!empty($canvas)) {
  115. require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
  116. $objcanvas = new Canvas($db, $action);
  117. $objcanvas->getCanvas('thirdparty', 'card', $canvas);
  118. }
  119. // Permissions
  120. $permissiontoread = $user->hasRight('societe', 'lire');
  121. $permissiontoadd = $user->hasRight('societe', 'creer'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
  122. $permissiontodelete = $user->hasRight('societe', 'supprimer') || ($permissiontoadd && isset($object->status) && $object->status == 0);
  123. $permissionnote = $user->hasRight('societe', 'creer'); // Used by the include of actions_setnotes.inc.php
  124. $permissiondellink = $user->hasRight('societe', 'creer'); // Used by the include of actions_dellink.inc.php
  125. $upload_dir = $conf->societe->multidir_output[isset($object->entity) ? $object->entity : 1];
  126. // Security check
  127. $result = restrictedArea($user, 'societe', $socid, '&societe', '', 'fk_soc', 'rowid', 0);
  128. /*
  129. * Actions
  130. */
  131. $parameters = array('id'=>$socid, 'objcanvas'=>$objcanvas);
  132. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  133. if ($reshook < 0) {
  134. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  135. }
  136. if (empty($reshook)) {
  137. $backurlforlist = DOL_URL_ROOT.'/societe/list.php';
  138. if (empty($backtopage) || ($cancel && empty($id))) {
  139. if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
  140. if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
  141. $backtopage = $backurlforlist;
  142. } else {
  143. $backtopage = DOL_URL_ROOT.'/societe/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
  144. }
  145. }
  146. }
  147. if ($cancel) {
  148. if (!empty($backtopageforcancel)) {
  149. header("Location: ".$backtopageforcancel);
  150. exit;
  151. } elseif (!empty($backtopage)) {
  152. header("Location: ".$backtopage);
  153. exit;
  154. }
  155. $action = '';
  156. }
  157. if ($action == 'confirm_merge' && $confirm == 'yes' && $user->rights->societe->creer) {
  158. $error = 0;
  159. $soc_origin_id = GETPOST('soc_origin', 'int');
  160. $soc_origin = new Societe($db);
  161. if ($soc_origin_id <= 0) {
  162. $langs->load('errors');
  163. setEventMessages($langs->trans('ErrorThirdPartyIdIsMandatory', $langs->transnoentitiesnoconv('MergeOriginThirdparty')), null, 'errors');
  164. } else {
  165. if (!$error && $soc_origin->fetch($soc_origin_id) < 1) {
  166. setEventMessages($langs->trans('ErrorRecordNotFound'), null, 'errors');
  167. $error++;
  168. }
  169. if (!$error) {
  170. // TODO Move the merge function into class of object.
  171. $db->begin();
  172. // Recopy some data
  173. $object->client = $object->client | $soc_origin->client;
  174. $object->fournisseur = $object->fournisseur | $soc_origin->fournisseur;
  175. $listofproperties = array(
  176. 'address', 'zip', 'town', 'state_id', 'country_id', 'phone', 'phone_pro', 'fax', 'email', 'socialnetworks', 'url', 'barcode',
  177. 'idprof1', 'idprof2', 'idprof3', 'idprof4', 'idprof5', 'idprof6',
  178. 'tva_intra', 'effectif_id', 'forme_juridique', 'remise_percent', 'remise_supplier_percent', 'mode_reglement_supplier_id', 'cond_reglement_supplier_id', 'name_bis',
  179. 'stcomm_id', 'outstanding_limit', 'price_level', 'parent', 'default_lang', 'ref', 'ref_ext', 'import_key', 'fk_incoterms', 'fk_multicurrency',
  180. 'code_client', 'code_fournisseur', 'code_compta', 'code_compta_fournisseur',
  181. 'model_pdf', 'fk_projet'
  182. );
  183. foreach ($listofproperties as $property) {
  184. if (empty($object->$property)) {
  185. $object->$property = $soc_origin->$property;
  186. }
  187. }
  188. // Concat some data
  189. $listofproperties = array(
  190. 'note_public', 'note_private'
  191. );
  192. foreach ($listofproperties as $property) {
  193. $object->$property = dol_concatdesc($object->$property, $soc_origin->$property);
  194. }
  195. // Merge extrafields
  196. if (is_array($soc_origin->array_options)) {
  197. foreach ($soc_origin->array_options as $key => $val) {
  198. if (empty($object->array_options[$key])) {
  199. $object->array_options[$key] = $val;
  200. }
  201. }
  202. }
  203. // Merge categories
  204. $static_cat = new Categorie($db);
  205. $custcats_ori = $static_cat->containing($soc_origin->id, 'customer', 'id');
  206. $custcats = $static_cat->containing($object->id, 'customer', 'id');
  207. $custcats = array_merge($custcats, $custcats_ori);
  208. $object->setCategories($custcats, 'customer');
  209. $suppcats_ori = $static_cat->containing($soc_origin->id, 'supplier', 'id');
  210. $suppcats = $static_cat->containing($object->id, 'supplier', 'id');
  211. $suppcats = array_merge($suppcats, $suppcats_ori);
  212. $object->setCategories($suppcats, 'supplier');
  213. // If thirdparty has a new code that is same than origin, we clean origin code to avoid duplicate key from database unique keys.
  214. if ($soc_origin->code_client == $object->code_client
  215. || $soc_origin->code_fournisseur == $object->code_fournisseur
  216. || $soc_origin->barcode == $object->barcode) {
  217. dol_syslog("We clean customer and supplier code so we will be able to make the update of target");
  218. $soc_origin->code_client = '';
  219. $soc_origin->code_fournisseur = '';
  220. $soc_origin->barcode = '';
  221. $soc_origin->update($soc_origin->id, $user, 0, 1, 1, 'merge');
  222. }
  223. // Update
  224. $result = $object->update($object->id, $user, 0, 1, 1, 'merge');
  225. if ($result < 0) {
  226. setEventMessages($object->error, $object->errors, 'errors');
  227. $error++;
  228. }
  229. // Move links
  230. if (!$error) {
  231. // This list is also into the api_thirdparties.class.php
  232. // TODO Mutualise the list into object societe.class.php
  233. $objects = array(
  234. 'Adherent' => '/adherents/class/adherent.class.php',
  235. 'Don' => '/don/class/don.class.php',
  236. 'Societe' => '/societe/class/societe.class.php',
  237. //'Categorie' => '/categories/class/categorie.class.php',
  238. 'ActionComm' => '/comm/action/class/actioncomm.class.php',
  239. 'Propal' => '/comm/propal/class/propal.class.php',
  240. 'Commande' => '/commande/class/commande.class.php',
  241. 'Facture' => '/compta/facture/class/facture.class.php',
  242. 'FactureRec' => '/compta/facture/class/facture-rec.class.php',
  243. 'LignePrelevement' => '/compta/prelevement/class/ligneprelevement.class.php',
  244. 'Mo' => '/mrp/class/mo.class.php',
  245. 'Contact' => '/contact/class/contact.class.php',
  246. 'Contrat' => '/contrat/class/contrat.class.php',
  247. 'Expedition' => '/expedition/class/expedition.class.php',
  248. 'Fichinter' => '/fichinter/class/fichinter.class.php',
  249. 'CommandeFournisseur' => '/fourn/class/fournisseur.commande.class.php',
  250. 'FactureFournisseur' => '/fourn/class/fournisseur.facture.class.php',
  251. 'SupplierProposal' => '/supplier_proposal/class/supplier_proposal.class.php',
  252. 'ProductFournisseur' => '/fourn/class/fournisseur.product.class.php',
  253. 'Delivery' => '/delivery/class/delivery.class.php',
  254. 'Product' => '/product/class/product.class.php',
  255. 'Project' => '/projet/class/project.class.php',
  256. 'Ticket' => '/ticket/class/ticket.class.php',
  257. 'User' => '/user/class/user.class.php',
  258. 'Account' => '/compta/bank/class/account.class.php',
  259. 'ConferenceOrBoothAttendee' => '/eventorganization/class/conferenceorboothattendee.class.php'
  260. );
  261. //First, all core objects must update their tables
  262. foreach ($objects as $object_name => $object_file) {
  263. require_once DOL_DOCUMENT_ROOT.$object_file;
  264. if (!$error && !$object_name::replaceThirdparty($db, $soc_origin->id, $object->id)) {
  265. $error++;
  266. setEventMessages($db->lasterror(), null, 'errors');
  267. break;
  268. }
  269. }
  270. }
  271. // External modules should update their ones too
  272. if (!$error) {
  273. $reshook = $hookmanager->executeHooks('replaceThirdparty', array(
  274. 'soc_origin' => $soc_origin->id,
  275. 'soc_dest' => $object->id
  276. ), $object, $action);
  277. if ($reshook < 0) {
  278. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  279. $error++;
  280. }
  281. }
  282. if (!$error) {
  283. $object->context = array('merge'=>1, 'mergefromid'=>$soc_origin->id);
  284. // Call trigger
  285. $result = $object->call_trigger('COMPANY_MODIFY', $user);
  286. if ($result < 0) {
  287. setEventMessages($object->error, $object->errors, 'errors');
  288. $error++;
  289. }
  290. // End call triggers
  291. }
  292. if (!$error) {
  293. //We finally remove the old thirdparty
  294. if ($soc_origin->delete($soc_origin->id, $user) < 1) {
  295. setEventMessages($soc_origin->error, $soc_origin->errors, 'errors');
  296. $error++;
  297. }
  298. }
  299. if (!$error) {
  300. setEventMessages($langs->trans('ThirdpartiesMergeSuccess'), null, 'mesgs');
  301. $db->commit();
  302. } else {
  303. $langs->load("errors");
  304. setEventMessages($langs->trans('ErrorsThirdpartyMerge'), null, 'errors');
  305. $db->rollback();
  306. }
  307. }
  308. }
  309. }
  310. if (GETPOST('getcustomercode')) {
  311. // We defined value code_client
  312. $_POST["customer_code"] = "Acompleter";
  313. }
  314. if (GETPOST('getsuppliercode')) {
  315. // We defined value code_fournisseur
  316. $_POST["supplier_code"] = "Acompleter";
  317. }
  318. if ($action == 'set_localtax1') {
  319. //obtidre selected del combobox
  320. $value = GETPOST('lt1');
  321. $object->fetch($socid);
  322. $res = $object->setValueFrom('localtax1_value', $value, '', null, 'text', '', $user, 'COMPANY_MODIFY');
  323. }
  324. if ($action == 'set_localtax2') {
  325. //obtidre selected del combobox
  326. $value = GETPOST('lt2');
  327. $object->fetch($socid);
  328. $res = $object->setValueFrom('localtax2_value', $value, '', null, 'text', '', $user, 'COMPANY_MODIFY');
  329. }
  330. if ($action == 'update_extras') {
  331. $object->fetch($socid);
  332. $object->oldcopy = dol_clone($object);
  333. // Fill array 'array_options' with data from update form
  334. $extrafields->fetch_name_optionals_label($object->table_element);
  335. $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml'));
  336. if ($ret < 0) {
  337. $error++;
  338. }
  339. if (!$error) {
  340. $result = $object->insertExtraFields('COMPANY_MODIFY');
  341. if ($result < 0) {
  342. setEventMessages($object->error, $object->errors, 'errors');
  343. $error++;
  344. }
  345. }
  346. if ($error) {
  347. $action = 'edit_extras';
  348. }
  349. }
  350. // Add new or update third party
  351. if ((!GETPOST('getcustomercode') && !GETPOST('getsuppliercode'))
  352. && ($action == 'add' || $action == 'update') && $user->rights->societe->creer) {
  353. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  354. if (!GETPOST('name')) {
  355. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ThirdPartyName")), null, 'errors');
  356. $error++;
  357. }
  358. if (GETPOST('client', 'int') && GETPOST('client', 'int') < 0) {
  359. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ProspectCustomer")), null, 'errors');
  360. $error++;
  361. }
  362. if (GETPOSTISSET('fournisseur') && GETPOST('fournisseur', 'int') < 0) {
  363. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Supplier")), null, 'errors');
  364. $error++;
  365. }
  366. if (isModEnabled('mailing') && !empty($conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS) && $conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS == 2 && GETPOST('contact_no_email', 'int')==-1 && !empty(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL))) {
  367. $error++;
  368. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("No_Email")), null, 'errors');
  369. }
  370. if (isModEnabled('mailing') && GETPOST("private", 'int') == 1 && !empty($conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS) && $conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS == 2 && GETPOST('contact_no_email', 'int')==-1 && !empty(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL))) {
  371. $error++;
  372. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("No_Email")), null, 'errors');
  373. }
  374. if (!$error) {
  375. if ($action == 'update') {
  376. $ret = $object->fetch($socid);
  377. $object->oldcopy = clone $object;
  378. } else {
  379. $object->canvas = $canvas;
  380. }
  381. if (GETPOST("private", 'int') == 1) { // Ask to create a contact
  382. $object->particulier = GETPOST("private", 'int');
  383. $object->name = dolGetFirstLastname(GETPOST('firstname', 'alphanohtml'), GETPOST('name', 'alphanohtml'));
  384. $object->civility_id = GETPOST('civility_id', 'alphanohtml'); // Note: civility id is a code, not an int
  385. // Add non official properties
  386. $object->name_bis = GETPOST('name', 'alphanohtml');
  387. $object->firstname = GETPOST('firstname', 'alphanohtml');
  388. } else {
  389. $object->name = GETPOST('name', 'alphanohtml');
  390. }
  391. $object->entity = (GETPOSTISSET('entity') ? GETPOST('entity', 'int') : $conf->entity);
  392. $object->name_alias = GETPOST('name_alias', 'alphanohtml');
  393. $object->parent = GETPOST('parent_company_id', 'int');
  394. $object->address = GETPOST('address', 'alphanohtml');
  395. $object->zip = GETPOST('zipcode', 'alphanohtml');
  396. $object->town = GETPOST('town', 'alphanohtml');
  397. $object->country_id = GETPOST('country_id', 'int');
  398. $object->state_id = GETPOST('state_id', 'int');
  399. $object->socialnetworks = array();
  400. if (isModEnabled('socialnetworks')) {
  401. foreach ($socialnetworks as $key => $value) {
  402. if (GETPOSTISSET($key) && GETPOST($key, 'alphanohtml') != '') {
  403. $object->socialnetworks[$key] = GETPOST($key, 'alphanohtml');
  404. }
  405. }
  406. }
  407. $object->phone = GETPOST('phone', 'alpha');
  408. $object->fax = GETPOST('fax', 'alpha');
  409. $object->email = trim(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL));
  410. $object->no_email = GETPOST("no_email", "int");
  411. $object->url = trim(GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL));
  412. $object->idprof1 = trim(GETPOST('idprof1', 'alphanohtml'));
  413. $object->idprof2 = trim(GETPOST('idprof2', 'alphanohtml'));
  414. $object->idprof3 = trim(GETPOST('idprof3', 'alphanohtml'));
  415. $object->idprof4 = trim(GETPOST('idprof4', 'alphanohtml'));
  416. $object->idprof5 = trim(GETPOST('idprof5', 'alphanohtml'));
  417. $object->idprof6 = trim(GETPOST('idprof6', 'alphanohtml'));
  418. $object->prefix_comm = GETPOST('prefix_comm', 'alphanohtml');
  419. $object->code_client = GETPOSTISSET('customer_code') ?GETPOST('customer_code', 'alpha') : GETPOST('code_client', 'alpha');
  420. $object->code_fournisseur = GETPOSTISSET('supplier_code') ?GETPOST('supplier_code', 'alpha') : GETPOST('code_fournisseur', 'alpha');
  421. $object->capital = GETPOST('capital', 'alphanohtml');
  422. $object->barcode = GETPOST('barcode', 'alphanohtml');
  423. $object->tva_intra = GETPOST('tva_intra', 'alphanohtml');
  424. $object->tva_assuj = GETPOST('assujtva_value', 'alpha');
  425. $object->status = GETPOST('status', 'alpha');
  426. // Local Taxes
  427. $object->localtax1_assuj = GETPOST('localtax1assuj_value', 'alpha');
  428. $object->localtax2_assuj = GETPOST('localtax2assuj_value', 'alpha');
  429. $object->localtax1_value = GETPOST('lt1', 'alpha');
  430. $object->localtax2_value = GETPOST('lt2', 'alpha');
  431. $object->forme_juridique_code = GETPOST('forme_juridique_code', 'int');
  432. $object->effectif_id = GETPOST('effectif_id', 'int');
  433. $object->typent_id = GETPOST('typent_id', 'int');
  434. $object->typent_code = dol_getIdFromCode($db, $object->typent_id, 'c_typent', 'id', 'code'); // Force typent_code too so check in verify() will be done on new type
  435. $object->client = GETPOST('client', 'int');
  436. $object->fournisseur = GETPOST('fournisseur', 'int');
  437. $object->commercial_id = GETPOST('commercial_id', 'int');
  438. $object->default_lang = GETPOST('default_lang');
  439. // Webservices url/key
  440. $object->webservices_url = GETPOST('webservices_url', 'custom', 0, FILTER_SANITIZE_URL);
  441. $object->webservices_key = GETPOST('webservices_key', 'san_alpha');
  442. if (GETPOSTISSET('accountancy_code_sell')) {
  443. $accountancy_code_sell = GETPOST('accountancy_code_sell', 'alpha');
  444. if (empty($accountancy_code_sell) || $accountancy_code_sell == '-1') {
  445. $object->accountancy_code_sell = '';
  446. } else {
  447. $object->accountancy_code_sell = $accountancy_code_sell;
  448. }
  449. }
  450. if (GETPOSTISSET('accountancy_code_buy')) {
  451. $accountancy_code_buy = GETPOST('accountancy_code_buy', 'alpha');
  452. if (empty($accountancy_code_buy) || $accountancy_code_buy == '-1') {
  453. $object->accountancy_code_buy = '';
  454. } else {
  455. $object->accountancy_code_buy = $accountancy_code_buy;
  456. }
  457. }
  458. // Incoterms
  459. if (isModEnabled('incoterm')) {
  460. $object->fk_incoterms = GETPOST('incoterm_id', 'int');
  461. $object->location_incoterms = GETPOST('location_incoterms', 'alpha');
  462. }
  463. // Multicurrency
  464. if (isModEnabled("multicurrency")) {
  465. $object->multicurrency_code = GETPOST('multicurrency_code', 'alpha');
  466. }
  467. // Fill array 'array_options' with data from add form
  468. $ret = $extrafields->setOptionalsFromPost(null, $object);
  469. if ($ret < 0) {
  470. $error++;
  471. }
  472. // Fill array 'array_languages' with data from add form
  473. $ret = $object->setValuesForExtraLanguages();
  474. if ($ret < 0) {
  475. $error++;
  476. }
  477. //var_dump($object->array_languages);exit;
  478. if (!empty($_FILES['photo']['name'])) {
  479. $current_logo = $object->logo;
  480. $object->logo = dol_sanitizeFileName($_FILES['photo']['name']);
  481. }
  482. // Check parameters
  483. if (!GETPOST('cancel', 'alpha')) {
  484. if (!empty($object->email) && !isValidEMail($object->email)) {
  485. $langs->load("errors");
  486. $error++;
  487. setEventMessages($langs->trans("ErrorBadEMail", $object->email), null, 'errors');
  488. }
  489. if (!empty($object->url) && !isValidUrl($object->url)) {
  490. $langs->load("errors");
  491. setEventMessages($langs->trans("ErrorBadUrl", $object->url), null, 'errors');
  492. }
  493. if (!empty($object->webservices_url)) {
  494. //Check if has transport, without any the soap client will give error
  495. if (strpos($object->webservices_url, "http") === false) {
  496. $object->webservices_url = "http://".$object->webservices_url;
  497. }
  498. if (!isValidUrl($object->webservices_url)) {
  499. $langs->load("errors");
  500. $error++; $errors[] = $langs->trans("ErrorBadUrl", $object->webservices_url);
  501. }
  502. }
  503. // We set country_id, country_code and country for the selected country
  504. $object->country_id = GETPOST('country_id', 'int') != '' ? GETPOST('country_id', 'int') : $mysoc->country_id;
  505. if ($object->country_id) {
  506. $tmparray = getCountry($object->country_id, 'all');
  507. $object->country_code = $tmparray['code'];
  508. $object->country = $tmparray['label'];
  509. }
  510. }
  511. }
  512. if (!$error) {
  513. if ($action == 'add') {
  514. $error = 0;
  515. $db->begin();
  516. if (empty($object->client)) {
  517. $object->code_client = '';
  518. }
  519. if (empty($object->fournisseur)) {
  520. $object->code_fournisseur = '';
  521. }
  522. $result = $object->create($user);
  523. if (empty($error) && !empty($conf->mailing->enabled) && !empty($object->email) && $object->no_email == 1) {
  524. // Add mass emailing flag into table mailing_unsubscribe
  525. $result = $object->setNoEmail($object->no_email);
  526. if ($result < 0) {
  527. $error++;
  528. $errors = array_merge($errors, ($object->error ? array($object->error) : $object->errors));
  529. $action = 'create';
  530. }
  531. }
  532. if ($result >= 0) {
  533. if ($object->particulier) {
  534. dol_syslog("We ask to create a contact/address too", LOG_DEBUG);
  535. $contcats = GETPOST('contcats', 'array');
  536. $no_email = GETPOST('contact_no_email', 'int');
  537. $result = $object->create_individual($user, $no_email, $contcats);
  538. if ($result < 0) {
  539. setEventMessages($object->error, $object->errors, 'errors');
  540. $error++;
  541. }
  542. }
  543. // Links with users
  544. $salesreps = GETPOST('commercial', 'array');
  545. $result = $object->setSalesRep($salesreps, true);
  546. if ($result < 0) {
  547. $error++;
  548. setEventMessages($object->error, $object->errors, 'errors');
  549. }
  550. // Customer categories association
  551. $custcats = GETPOST('custcats', 'array');
  552. $result = $object->setCategories($custcats, 'customer');
  553. if ($result < 0) {
  554. $error++;
  555. setEventMessages($object->error, $object->errors, 'errors');
  556. }
  557. // Supplier categories association
  558. $suppcats = GETPOST('suppcats', 'array');
  559. $result = $object->setCategories($suppcats, 'supplier');
  560. if ($result < 0) {
  561. $error++;
  562. setEventMessages($object->error, $object->errors, 'errors');
  563. }
  564. // Logo/Photo save
  565. $dir = $conf->societe->multidir_output[$conf->entity]."/".$object->id."/logos/";
  566. $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
  567. if ($file_OK) {
  568. if (image_format_supported($_FILES['photo']['name'])) {
  569. dol_mkdir($dir);
  570. if (@is_dir($dir)) {
  571. $newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
  572. $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
  573. if (!($result > 0)) {
  574. $errors[] = "ErrorFailedToSaveFile";
  575. } else {
  576. // Create thumbs
  577. $object->addThumbs($newfile);
  578. }
  579. }
  580. }
  581. } else {
  582. switch ($_FILES['photo']['error']) {
  583. case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
  584. case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
  585. $errors[] = "ErrorFileSizeTooLarge";
  586. break;
  587. case 3: //uploaded file was only partially uploaded
  588. $errors[] = "ErrorFilePartiallyUploaded";
  589. break;
  590. }
  591. }
  592. } else {
  593. if ($result == -3 && in_array('ErrorCustomerCodeAlreadyUsed', $object->errors)) {
  594. $duplicate_code_error = true;
  595. $object->code_client = null;
  596. }
  597. if ($result == -3 && in_array('ErrorSupplierCodeAlreadyUsed', $object->errors)) {
  598. $duplicate_code_error = true;
  599. $object->code_fournisseur = null;
  600. }
  601. if ($db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') { // TODO Sometime errors on duplicate on profid and not on code, so we must manage this case
  602. $duplicate_code_error = true;
  603. }
  604. setEventMessages($object->error, $object->errors, 'errors');
  605. $error++;
  606. }
  607. if ($result >= 0 && !$error) {
  608. $db->commit();
  609. if ($backtopagejsfields) {
  610. llxHeader('', '', '');
  611. $tmpbacktopagejsfields = explode(':', $backtopagejsfields);
  612. $dol_openinpopup = $tmpbacktopagejsfields[0];
  613. $retstring = '<script>';
  614. $retstring .= 'jQuery(document).ready(function() {
  615. console.log(\'We execute action to create. We save id and go back - '.$dol_openinpopup.'\');
  616. console.log(\'id = '.$object->id.'\');
  617. $(\'#varforreturndialogid'.$dol_openinpopup.'\', window.parent.document).text(\''.$object->id.'\');
  618. $(\'#varforreturndialoglabel'.$dol_openinpopup.'\', window.parent.document).text(\''.$object->name.'\');
  619. window.parent.jQuery(\'#idfordialog'.$dol_openinpopup.'\').dialog(\'close\');
  620. });';
  621. $retstring .= '</script>';
  622. print $retstring;
  623. llxFooter();
  624. exit;
  625. }
  626. if (!empty($backtopage)) {
  627. $backtopage = preg_replace('/--IDFORBACKTOPAGE--/', $object->id, $backtopage); // New method to autoselect project after a New on another form object creation
  628. if (preg_match('/\?/', $backtopage)) {
  629. $backtopage .= '&socid='.$object->id; // Old method
  630. }
  631. header("Location: ".$backtopage);
  632. exit;
  633. } else {
  634. $url = $_SERVER["PHP_SELF"]."?socid=".$object->id; // Old method
  635. if (($object->client == 1 || $object->client == 3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
  636. $url = DOL_URL_ROOT."/comm/card.php?socid=".$object->id;
  637. } elseif ($object->fournisseur == 1) {
  638. $url = DOL_URL_ROOT."/fourn/card.php?socid=".$object->id;
  639. }
  640. header("Location: ".$url);
  641. exit;
  642. }
  643. } else {
  644. $db->rollback();
  645. $action = 'create';
  646. }
  647. }
  648. if ($action == 'update') {
  649. $error = 0;
  650. if (GETPOST('cancel', 'alpha')) {
  651. if (!empty($backtopage)) {
  652. header("Location: ".$backtopage);
  653. exit;
  654. } else {
  655. header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid);
  656. exit;
  657. }
  658. }
  659. // To not set code if third party is not concerned. But if it had values, we keep them.
  660. if (empty($object->client) && empty($object->oldcopy->code_client)) {
  661. $object->code_client = '';
  662. }
  663. if (empty($object->fournisseur) && empty($object->oldcopy->code_fournisseur)) {
  664. $object->code_fournisseur = '';
  665. }
  666. //var_dump($object);exit;
  667. $result = $object->update($socid, $user, 1, $object->oldcopy->codeclient_modifiable(), $object->oldcopy->codefournisseur_modifiable(), 'update', 0);
  668. if ($result > 0) {
  669. // Update mass emailing flag into table mailing_unsubscribe
  670. if (GETPOSTISSET('no_email') && $object->email) {
  671. $no_email = GETPOST('no_email', 'int');
  672. $result = $object->setNoEmail($no_email);
  673. if ($result < 0) {
  674. setEventMessages($object->error, $object->errors, 'errors');
  675. $action = 'edit';
  676. }
  677. }
  678. $action = 'view';
  679. } else {
  680. setEventMessages($object->error, $object->errors, 'errors');
  681. $action = 'edit';
  682. }
  683. if ($result <= 0) {
  684. setEventMessages($object->error, $object->errors, 'errors');
  685. $error++;
  686. }
  687. // Links with users
  688. $salesreps = GETPOST('commercial', 'array');
  689. $result = $object->setSalesRep($salesreps);
  690. if ($result < 0) {
  691. $error++;
  692. setEventMessages($object->error, $object->errors, 'errors');
  693. }
  694. // Prevent thirdparty's emptying if a user hasn't rights $user->rights->categorie->lire (in such a case, post of 'custcats' is not defined)
  695. if (!$error && !empty($user->rights->categorie->lire)) {
  696. // Customer categories association
  697. $categories = GETPOST('custcats', 'array');
  698. $result = $object->setCategories($categories, 'customer');
  699. if ($result < 0) {
  700. $error++;
  701. setEventMessages($object->error, $object->errors, 'errors');
  702. }
  703. // Supplier categories association
  704. $categories = GETPOST('suppcats', 'array');
  705. $result = $object->setCategories($categories, 'supplier');
  706. if ($result < 0) {
  707. $error++;
  708. setEventMessages($object->error, $object->errors, 'errors');
  709. }
  710. }
  711. // Logo/Photo save
  712. $dir = $conf->societe->multidir_output[$object->entity]."/".$object->id."/logos";
  713. $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
  714. if (GETPOST('deletephoto') && $object->logo) {
  715. $fileimg = $dir.'/'.$object->logo;
  716. $dirthumbs = $dir.'/thumbs';
  717. dol_delete_file($fileimg);
  718. dol_delete_dir_recursive($dirthumbs);
  719. }
  720. if ($file_OK) {
  721. if (image_format_supported($_FILES['photo']['name']) > 0) {
  722. if ($current_logo != $object->logo) {
  723. $fileimg = $dir.'/'.$current_logo;
  724. $dirthumbs = $dir.'/thumbs';
  725. dol_delete_file($fileimg);
  726. dol_delete_dir_recursive($dirthumbs);
  727. }
  728. dol_mkdir($dir);
  729. if (@is_dir($dir)) {
  730. $newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
  731. $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
  732. if (!($result > 0)) {
  733. $errors[] = "ErrorFailedToSaveFile";
  734. } else {
  735. // Create thumbs
  736. $object->addThumbs($newfile);
  737. // Index file in database
  738. if (!empty($conf->global->THIRDPARTY_LOGO_ALLOW_EXTERNAL_DOWNLOAD)) {
  739. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  740. // the dir dirname($newfile) is directory of logo, so we should have only one file at once into index, so we delete indexes for the dir
  741. deleteFilesIntoDatabaseIndex(dirname($newfile), '', '');
  742. // now we index the uploaded logo file
  743. addFileIntoDatabaseIndex(dirname($newfile), basename($newfile), '', 'uploaded', 1);
  744. }
  745. }
  746. }
  747. } else {
  748. $errors[] = "ErrorBadImageFormat";
  749. }
  750. } else {
  751. switch ($_FILES['photo']['error']) {
  752. case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
  753. case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
  754. $errors[] = "ErrorFileSizeTooLarge";
  755. break;
  756. case 3: //uploaded file was only partially uploaded
  757. $errors[] = "ErrorFilePartiallyUploaded";
  758. break;
  759. }
  760. }
  761. // Gestion du logo de la société
  762. // Update linked member
  763. if (!$error && $object->fk_soc > 0) {
  764. $sql = "UPDATE ".MAIN_DB_PREFIX."adherent";
  765. $sql .= " SET fk_soc = NULL WHERE fk_soc = ".((int) $socid);
  766. if (!$object->db->query($sql)) {
  767. $error++;
  768. $object->error .= $object->db->lasterror();
  769. setEventMessages($object->error, $object->errors, 'errors');
  770. }
  771. }
  772. if (!$error && !count($errors)) {
  773. if (!empty($backtopage)) {
  774. header("Location: ".$backtopage);
  775. exit;
  776. } else {
  777. header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid);
  778. exit;
  779. }
  780. } else {
  781. $object->id = $socid;
  782. $action = "edit";
  783. }
  784. }
  785. } else {
  786. $action = ($action == 'add' ? 'create' : 'edit');
  787. }
  788. }
  789. // Delete third party
  790. if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('societe', 'supprimer')) {
  791. $object->fetch($socid);
  792. $object->oldcopy = clone $object;
  793. $result = $object->delete($socid, $user);
  794. if ($result > 0) {
  795. header("Location: ".DOL_URL_ROOT."/societe/list.php?restore_lastsearch_values=1&delsoc=".urlencode($object->name));
  796. exit;
  797. } else {
  798. $langs->load("errors");
  799. setEventMessages($object->error, $object->errors, 'errors');
  800. $error++;
  801. $action = '';
  802. }
  803. }
  804. // Set third-party type
  805. if ($action == 'set_thirdpartytype' && $user->rights->societe->creer) {
  806. $object->fetch($socid);
  807. $result = $object->setThirdpartyType(GETPOST('typent_id', 'int'));
  808. }
  809. // Set incoterm
  810. if ($action == 'set_incoterms' && $user->rights->societe->creer && isModEnabled('incoterm')) {
  811. $object->fetch($socid);
  812. $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha'));
  813. }
  814. // Set parent company
  815. if ($action == 'set_thirdparty' && $user->rights->societe->creer) {
  816. $object->fetch($socid);
  817. $result = $object->setParent(GETPOST('parent_id', 'int'));
  818. }
  819. // Set sales representatives
  820. if ($action == 'set_salesrepresentatives' && $user->rights->societe->creer) {
  821. $object->fetch($socid);
  822. $result = $object->setSalesRep(GETPOST('commercial', 'array'));
  823. }
  824. // warehouse
  825. if ($action == 'setwarehouse' && $user->rights->societe->creer) {
  826. $result = $object->setWarehouse(GETPOST('fk_warehouse', 'int'));
  827. }
  828. $id = $socid;
  829. $object->fetch($socid);
  830. // Selection of new fields
  831. if (!empty($conf->global->MAIN_DUPLICATE_CONTACTS_TAB_ON_MAIN_CARD) && (empty($conf->global->SOCIETE_DISABLE_CONTACTS) || !empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT))) {
  832. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  833. }
  834. // Actions to send emails
  835. $triggersendname = 'COMPANY_SENTBYMAIL';
  836. $paramname = 'socid';
  837. $mode = 'emailfromthirdparty';
  838. $trackid = 'thi'.$object->id;
  839. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  840. // Actions to build doc
  841. $id = $socid;
  842. $upload_dir = !empty($conf->societe->multidir_output[$object->entity])?$conf->societe->multidir_output[$object->entity]:$conf->societe->dir_output;
  843. $permissiontoadd = $user->hasRight('societe', 'creer');
  844. include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
  845. }
  846. /*
  847. * View
  848. */
  849. $form = new Form($db);
  850. $formfile = new FormFile($db);
  851. $formadmin = new FormAdmin($db);
  852. $formcompany = new FormCompany($db);
  853. if (isModEnabled('accounting')) {
  854. $formaccounting = new FormAccounting($db);
  855. }
  856. if ($socid > 0 && empty($object->id)) {
  857. $result = $object->fetch($socid);
  858. if ($result <= 0) {
  859. dol_print_error('', $object->error);
  860. exit(-1);
  861. }
  862. }
  863. $title = $langs->trans("ThirdParty");
  864. if ($action == 'create') {
  865. $title = $langs->trans("NewThirdParty");
  866. }
  867. if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) {
  868. $title = $object->name." - ".$langs->trans('Card');
  869. }
  870. $help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas|DE:Modul_Geschäftspartner';
  871. llxHeader('', $title, $help_url);
  872. $countrynotdefined = $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
  873. if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
  874. // -----------------------------------------
  875. // When used with CANVAS
  876. // -----------------------------------------
  877. $objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates
  878. $objcanvas->display_canvas($action); // Show template
  879. } else {
  880. // -----------------------------------------
  881. // When used in standard mode
  882. // -----------------------------------------
  883. if ($action == 'create') {
  884. /*
  885. * Creation
  886. */
  887. $private = GETPOST("private", "int");
  888. if (!empty($conf->global->THIRDPARTY_DEFAULT_CREATE_CONTACT) && !GETPOSTISSET('private')) {
  889. $private = 1;
  890. }
  891. if (empty($private)) {
  892. $private = 0;
  893. }
  894. // Load object modCodeTiers
  895. $module = (!empty($conf->global->SOCIETE_CODECLIENT_ADDON) ? $conf->global->SOCIETE_CODECLIENT_ADDON : 'mod_codeclient_leopard');
  896. if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') {
  897. $module = substr($module, 0, dol_strlen($module) - 4);
  898. }
  899. $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
  900. foreach ($dirsociete as $dirroot) {
  901. $res = dol_include_once($dirroot.$module.'.php');
  902. if ($res) {
  903. break;
  904. }
  905. }
  906. $modCodeClient = new $module;
  907. // Load object modCodeFournisseur
  908. $module = (!empty($conf->global->SOCIETE_CODECLIENT_ADDON) ? $conf->global->SOCIETE_CODECLIENT_ADDON : 'mod_codeclient_leopard');
  909. if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') {
  910. $module = substr($module, 0, dol_strlen($module) - 4);
  911. }
  912. $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
  913. foreach ($dirsociete as $dirroot) {
  914. $res = dol_include_once($dirroot.$module.'.php');
  915. if ($res) {
  916. break;
  917. }
  918. }
  919. $modCodeFournisseur = new $module;
  920. // Define if customer/prospect or supplier status is set or not
  921. if (GETPOST("type", 'aZ') != 'f') {
  922. $object->client = -1;
  923. if (!empty($conf->global->THIRDPARTY_CUSTOMERPROSPECT_BY_DEFAULT)) {
  924. $object->client = 3;
  925. }
  926. }
  927. // Prospect / Customer
  928. if (GETPOST("type", 'aZ') == 'c') {
  929. if (!empty($conf->global->THIRDPARTY_CUSTOMERTYPE_BY_DEFAULT)) {
  930. $object->client = $conf->global->THIRDPARTY_CUSTOMERTYPE_BY_DEFAULT;
  931. } else {
  932. $object->client = 3;
  933. }
  934. }
  935. if (GETPOST("type", 'aZ') == 'p') {
  936. $object->client = 2;
  937. }
  938. if (!empty($conf->global->SOCIETE_DISABLE_PROSPECTSCUSTOMERS) && $object->client == 3) {
  939. $object->client = 1;
  940. }
  941. if (((isModEnabled("fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) && (GETPOST("type") == 'f' || (GETPOST("type") == '' && !empty($conf->global->THIRDPARTY_SUPPLIER_BY_DEFAULT)))) {
  942. $object->fournisseur = 1;
  943. }
  944. $object->name = GETPOST('name', 'alphanohtml');
  945. $object->name_alias = GETPOST('name_alias', 'alphanohtml');
  946. $object->firstname = GETPOST('firstname', 'alphanohtml');
  947. $object->particulier = $private;
  948. $object->prefix_comm = GETPOST('prefix_comm', 'alphanohtml');
  949. $object->client = GETPOST('client', 'int') ?GETPOST('client', 'int') : $object->client;
  950. if (empty($duplicate_code_error)) {
  951. $object->code_client = GETPOST('customer_code', 'alpha');
  952. $object->fournisseur = GETPOST('fournisseur') ? GETPOST('fournisseur', 'int') : $object->fournisseur;
  953. $object->code_fournisseur = GETPOST('supplier_code', 'alpha');
  954. } else {
  955. setEventMessages($langs->trans('NewCustomerSupplierCodeProposed'), '', 'warnings');
  956. }
  957. $object->address = GETPOST('address', 'alphanohtml');
  958. $object->zip = GETPOST('zipcode', 'alphanohtml');
  959. $object->town = GETPOST('town', 'alphanohtml');
  960. $object->state_id = GETPOST('state_id', 'int');
  961. $object->socialnetworks = array();
  962. if (isModEnabled('socialnetworks')) {
  963. foreach ($socialnetworks as $key => $value) {
  964. if (GETPOSTISSET($key) && GETPOST($key, 'alphanohtml') != '') {
  965. $object->socialnetworks[$key] = GETPOST($key, 'alphanohtml');
  966. }
  967. }
  968. }
  969. $object->phone = GETPOST('phone', 'alpha');
  970. $object->fax = GETPOST('fax', 'alpha');
  971. $object->email = GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL);
  972. $object->url = GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL);
  973. $object->capital = GETPOST('capital', 'alphanohtml');
  974. $object->barcode = GETPOST('barcode', 'alphanohtml');
  975. $object->idprof1 = GETPOST('idprof1', 'alphanohtml');
  976. $object->idprof2 = GETPOST('idprof2', 'alphanohtml');
  977. $object->idprof3 = GETPOST('idprof3', 'alphanohtml');
  978. $object->idprof4 = GETPOST('idprof4', 'alphanohtml');
  979. $object->idprof5 = GETPOST('idprof5', 'alphanohtml');
  980. $object->idprof6 = GETPOST('idprof6', 'alphanohtml');
  981. $object->typent_id = GETPOST('typent_id', 'int');
  982. $object->effectif_id = GETPOST('effectif_id', 'int');
  983. $object->civility_id = GETPOST('civility_id', 'alpha');
  984. $object->tva_assuj = GETPOST('assujtva_value', 'int');
  985. $object->status = GETPOST('status', 'int');
  986. //Local Taxes
  987. $object->localtax1_assuj = GETPOST('localtax1assuj_value', 'int');
  988. $object->localtax2_assuj = GETPOST('localtax2assuj_value', 'int');
  989. $object->localtax1_value = GETPOST('lt1', 'int');
  990. $object->localtax2_value = GETPOST('lt2', 'int');
  991. $object->tva_intra = GETPOST('tva_intra', 'alphanohtml');
  992. $object->commercial_id = GETPOST('commercial_id', 'int');
  993. $object->default_lang = GETPOST('default_lang');
  994. if (GETPOSTISSET('accountancy_code_sell')) {
  995. $accountancy_code_sell = GETPOST('accountancy_code_sell', 'alpha');
  996. if (empty($accountancy_code_sell) || $accountancy_code_sell == '-1') {
  997. $object->accountancy_code_sell = '';
  998. } else {
  999. $object->accountancy_code_sell = $accountancy_code_sell;
  1000. }
  1001. }
  1002. if (GETPOSTISSET('accountancy_code_buy')) {
  1003. $accountancy_code_buy = GETPOST('accountancy_code_buy', 'alpha');
  1004. if (empty($accountancy_code_buy) || $accountancy_code_buy == '-1') {
  1005. $object->accountancy_code_buy = '';
  1006. } else {
  1007. $object->accountancy_code_buy = $accountancy_code_buy;
  1008. }
  1009. }
  1010. $object->logo = (isset($_FILES['photo']) ?dol_sanitizeFileName($_FILES['photo']['name']) : '');
  1011. // Gestion du logo de la société
  1012. $dir = $conf->societe->multidir_output[$conf->entity]."/".$object->id."/logos";
  1013. $file_OK = (isset($_FILES['photo']) ?is_uploaded_file($_FILES['photo']['tmp_name']) : false);
  1014. if ($file_OK) {
  1015. if (image_format_supported($_FILES['photo']['name'])) {
  1016. dol_mkdir($dir);
  1017. if (@is_dir($dir)) {
  1018. $newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
  1019. $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
  1020. if (!($result > 0)) {
  1021. $errors[] = "ErrorFailedToSaveFile";
  1022. } else {
  1023. // Create thumbs
  1024. $object->addThumbs($newfile);
  1025. }
  1026. }
  1027. }
  1028. }
  1029. // We set country_id, country_code and country for the selected country
  1030. $object->country_id = GETPOST('country_id') ?GETPOST('country_id') : $mysoc->country_id;
  1031. if ($object->country_id) {
  1032. $tmparray = getCountry($object->country_id, 'all');
  1033. $object->country_code = $tmparray['code'];
  1034. $object->country = $tmparray['label'];
  1035. }
  1036. $object->forme_juridique_code = GETPOST('forme_juridique_code');
  1037. // We set multicurrency_code if enabled
  1038. if (isModEnabled("multicurrency")) {
  1039. $object->multicurrency_code = GETPOST('multicurrency_code') ? GETPOST('multicurrency_code') : $conf->currency;
  1040. }
  1041. /* Show create form */
  1042. $linkback = "";
  1043. print load_fiche_titre($langs->trans("NewThirdParty"), $linkback, 'building');
  1044. if (!empty($conf->use_javascript_ajax)) {
  1045. if (!empty($conf->global->THIRDPARTY_SUGGEST_ALSO_ADDRESS_CREATION)) {
  1046. print "\n".'<script type="text/javascript">';
  1047. print '$(document).ready(function () {
  1048. id_te_private=8;
  1049. id_ef15=1;
  1050. is_private=' . $private.';
  1051. if (is_private) {
  1052. $(".individualline").show();
  1053. } else {
  1054. $(".individualline").hide();
  1055. }
  1056. $("#radiocompany").click(function() {
  1057. $(".individualline").hide();
  1058. $("#typent_id").val(0);
  1059. $("#typent_id").change();
  1060. $("#effectif_id").val(0);
  1061. $("#effectif_id").change();
  1062. $("#TypeName").html(document.formsoc.ThirdPartyName.value);
  1063. document.formsoc.private.value=0;
  1064. });
  1065. $("#radioprivate").click(function() {
  1066. $(".individualline").show();
  1067. $("#typent_id").val(id_te_private);
  1068. $("#typent_id").change();
  1069. $("#effectif_id").val(id_ef15);
  1070. $("#effectif_id").change();
  1071. /* Force to recompute the width of a select2 field when it was hidden and then shown programatically */
  1072. if ($("#civility_id").data("select2")) {
  1073. $("#civility_id").select2({width: "resolve"});
  1074. }
  1075. $("#TypeName").html(document.formsoc.LastName.value);
  1076. document.formsoc.private.value=1;
  1077. });
  1078. var canHaveCategoryIfNotCustomerProspectSupplier = ' . (empty($conf->global->THIRDPARTY_CAN_HAVE_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT) ? '0' : '1') . ';
  1079. init_customer_categ();
  1080. $("#customerprospect").change(function() {
  1081. init_customer_categ();
  1082. });
  1083. function init_customer_categ() {
  1084. console.log("is customer or prospect = "+jQuery("#customerprospect").val());
  1085. if (jQuery("#customerprospect").val() == 0 && !canHaveCategoryIfNotCustomerProspectSupplier)
  1086. {
  1087. jQuery(".visibleifcustomer").hide();
  1088. }
  1089. else
  1090. {
  1091. jQuery(".visibleifcustomer").show();
  1092. }
  1093. }
  1094. init_supplier_categ();
  1095. $("#fournisseur").change(function() {
  1096. init_supplier_categ();
  1097. });
  1098. function init_supplier_categ() {
  1099. console.log("is supplier = "+jQuery("#fournisseur").val());
  1100. if (jQuery("#fournisseur").val() == 0)
  1101. {
  1102. jQuery(".visibleifsupplier").hide();
  1103. }
  1104. else
  1105. {
  1106. jQuery(".visibleifsupplier").show();
  1107. }
  1108. }
  1109. $("#selectcountry_id").change(function() {
  1110. document.formsoc.action.value="create";
  1111. document.formsoc.submit();
  1112. });';
  1113. if ($conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS == 2) {
  1114. print '
  1115. function init_check_no_email(input) {
  1116. if (input.val()!="") {
  1117. $(".noemail").addClass("fieldrequired");
  1118. } else {
  1119. $(".noemail").removeClass("fieldrequired");
  1120. }
  1121. }
  1122. $("#email").keyup(function() {
  1123. init_check_no_email($(this));
  1124. });
  1125. init_check_no_email($("#email"));';
  1126. }
  1127. print '});';
  1128. print '</script>'."\n";
  1129. print '<div id="selectthirdpartytype">';
  1130. print '<div class="hideonsmartphone float">';
  1131. print $langs->trans("ThirdPartyType").': &nbsp; &nbsp; ';
  1132. print '</div>';
  1133. print '<label for="radiocompany" class="radiocompany">';
  1134. print '<input type="radio" id="radiocompany" class="flat" name="private" value="0"'.($private ? '' : ' checked').'>';
  1135. print '&nbsp;';
  1136. print $langs->trans("CreateThirdPartyOnly");
  1137. print '</label>';
  1138. print ' &nbsp; &nbsp; ';
  1139. print '<label for="radioprivate" class="radioprivate">';
  1140. $text = '<input type="radio" id="radioprivate" class="flat" name="private" value="1"'.($private ? ' checked' : '').'>';
  1141. $text .= '&nbsp;';
  1142. $text .= $langs->trans("CreateThirdPartyAndContact");
  1143. $htmltext = $langs->trans("ToCreateContactWithSameName");
  1144. print $form->textwithpicto($text, $htmltext, 1, 'help', '', 0, 3);
  1145. print '</label>';
  1146. print '</div>';
  1147. print "<br>\n";
  1148. } else {
  1149. print '<script type="text/javascript">';
  1150. print '$(document).ready(function () {
  1151. $("#selectcountry_id").change(function() {
  1152. document.formsoc.action.value="create";
  1153. document.formsoc.submit();
  1154. });
  1155. });';
  1156. print '</script>'."\n";
  1157. }
  1158. }
  1159. dol_htmloutput_mesg(is_numeric($error) ? '' : $error, $errors, 'error');
  1160. print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'" method="post" name="formsoc" autocomplete="off">'; // Chrome ignor autocomplete
  1161. print '<input type="hidden" name="action" value="add">';
  1162. print '<input type="hidden" name="token" value="'.newToken().'">';
  1163. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  1164. print '<input type="hidden" name="backtopagejsfields" value="'.$backtopagejsfields.'">';
  1165. print '<input type="hidden" name="dol_openinpopup" value="'.$dol_openinpopup.'">';
  1166. print '<input type="hidden" name="private" value='.$object->particulier.'>';
  1167. print '<input type="hidden" name="type" value='.GETPOST("type", 'alpha').'>';
  1168. print '<input type="hidden" name="LastName" value="'.$langs->trans('ThirdPartyName').' / '.$langs->trans('LastName').'">';
  1169. print '<input type="hidden" name="ThirdPartyName" value="'.$langs->trans('ThirdPartyName').'">';
  1170. if ($modCodeClient->code_auto || $modCodeFournisseur->code_auto) {
  1171. print '<input type="hidden" name="code_auto" value="1">';
  1172. }
  1173. print dol_get_fiche_head(null, 'card', '', 0, '');
  1174. print '<table class="border centpercent">';
  1175. // Name, firstname
  1176. print '<tr class="tr-field-thirdparty-name"><td class="titlefieldcreate">';
  1177. if ($object->particulier || $private) {
  1178. print '<span id="TypeName" class="fieldrequired">'.$langs->trans('ThirdPartyName').' / '.$langs->trans('LastName', 'name').'</span>';
  1179. } else {
  1180. print '<span id="TypeName" class="fieldrequired">'.$form->editfieldkey('ThirdPartyName', 'name', '', $object, 0).'</span>';
  1181. }
  1182. print '</td><td'.(empty($conf->global->SOCIETE_USEPREFIX) ? ' colspan="3"' : '').'>';
  1183. print '<input type="text" class="minwidth300" maxlength="128" name="name" id="name" value="'.dol_escape_htmltag($object->name).'" autofocus="autofocus">';
  1184. print $form->widgetForTranslation("name", $object, $permissiontoadd, 'string', 'alpahnohtml', 'minwidth300');
  1185. /* Disabled. Must be implenteted by keeping the input text but calling ajax on a keydown of the input and output
  1186. data of duplicate into a div under the input. We need to keep the widgetForTranslation also for some countries.
  1187. */
  1188. /*
  1189. print '<select class="name" name="name" id="name" style="min-width:500px"></select>';
  1190. print "\n".'<script type="text/javascript">';
  1191. print '$(document).ready(function () {
  1192. $("#name").select2({
  1193. ajax: {
  1194. url: "' . DOL_URL_ROOT . '/core/ajax/ajaxcompanies.php",
  1195. dataType: "json",
  1196. delay: 250,
  1197. data: function (params) {
  1198. return {
  1199. newcompany: params.term // search term
  1200. };
  1201. },
  1202. processResults: function (data, params) {
  1203. return {
  1204. results: data
  1205. };
  1206. },
  1207. cache: true
  1208. },
  1209. placeholder: "' . $langs->trans('Name of the new third party. In the meantime we check if it already exists...') . '",
  1210. allowClear: true,
  1211. minimumInputLength: 3,
  1212. language: select2arrayoflanguage,
  1213. containerCssClass: ":all:",
  1214. selectionCssClass: ":all:",
  1215. tags: true,
  1216. templateResult: formatCustomer,
  1217. templateSelection: formatCustomerSelection
  1218. });
  1219. function formatCustomer (Customer) {
  1220. if(Customer.label === undefined) {
  1221. return Customer.text;
  1222. }
  1223. if(Customer.logo !== null ) {
  1224. logo = \'<img src="\';
  1225. logo += \'' . DOL_URL_ROOT . '/viewimage.php?modulepart=societe&amp;entity=1&amp;file=\' + Customer.key + "%2Flogos%2Fthumbs%2F" + Customer.logo.replace(".", "_mini.") + "&amp;cache=0";
  1226. logo += \'" /></div>\';
  1227. } else {
  1228. logo = \'<div class="floatleft inline-block valigntop photowithmargin" style="padding:0 10px"><div class="photosociete photoref" alt="No photo"><span class="fas fa-building" style="color: #6c6aa8;"></span></div></div>\';
  1229. }
  1230. var $container = $("<div class=\'select2-result-repository clearfix\'>" +
  1231. "<div class=\'select2-result-repository__avatar floatleft inline-block valigntop\'>" + logo +
  1232. "<div class=\'select2-result-repository__meta floatleft inline-block valigntop\'>" +
  1233. "<div class=\'select2-result-repository__title\'></div>" +
  1234. "<div class=\'select2-result-repository__name_alias\'></div>" +
  1235. "<div class=\'select2-result-repository__code_client\'></div>" +
  1236. "<div class=\'select2-result-repository__code_fournisseur\'></div>" +
  1237. "<div class=\'select2-result-repository__companies_info\'>" +
  1238. "<div class=\'select2-result-repository__email\'><i class=\'fa fa-at\'></i> </div>" +
  1239. "<div class=\'select2-result-repository__address\'><i class=\'fa fa-flag\'></i> </div>" +
  1240. "<div class=\'select2-result-repository__zip\'><i class=\'fa fa-circle-o\'></i> </div>" +
  1241. "<div class=\'select2-result-repository__country\'><i class=\'fa fa-globe-americas\'></i> </div>" +
  1242. "<div class=\'select2-result-repository__departement\'><i class=\'fa fa-circle-o\'></i> </div>" +
  1243. "<div class=\'select2-result-repository__town\'><i class=\'fa fa-circle-o\'></i> </div>" +
  1244. "<div class=\'select2-result-repository__siren\'><i class=\'fa fa-circle-o\'></i> </div>" +
  1245. "<div class=\'select2-result-repository__datec\'><i class=\'fa fa-calendar\'></i> </div>" +
  1246. "</div>" +
  1247. "</div>" +
  1248. "</div>"
  1249. );
  1250. $container.find(".select2-result-repository__title").text(Customer.label);
  1251. $container.find(".select2-result-repository__name_alias").text(Customer.name_alias ? Customer.name_alias : "");
  1252. $container.find(".select2-result-repository__code_client").text(Customer.code_client ? Customer.code_client : "");
  1253. $container.find(".select2-result-repository__code_fournisseur").text((Customer.code_fournisseur!==null) ? Customer.code_fournisseur : "");
  1254. $container.find(".select2-result-repository__email").append("' . $langs->trans('EMail') . ': " + (Customer.email !== null ? Customer.email : ""));
  1255. $container.find(".select2-result-repository__address").append("' . $langs->trans('Address') . ': " + (Customer.address !== null ? Customer.address : ""));
  1256. $container.find(".select2-result-repository__country").append("' . $langs->trans('Country') . ': " + (Customer.country !== null ? Customer.country : ""));
  1257. $container.find(".select2-result-repository__departement").append("' . $langs->trans('Region-State') . ': " + (Customer.departement !== null ? Customer.departement : ""));
  1258. $container.find(".select2-result-repository__zip").append("' . $langs->trans('Zip') . ': " + (Customer.zip !== null ? Customer.zip : ""));
  1259. $container.find(".select2-result-repository__town").append("' . $langs->trans('Town') . ': " + (Customer.town !== null ? Customer.town : ""));
  1260. $container.find(".select2-result-repository__siren").append("' . $langs->trans('Siren') . ': " + (Customer.siren !== null ? Customer.siren : ""));
  1261. $container.find(".select2-result-repository__datec").append("' . $langs->trans('Created') . ': " + (Customer.datec !== null ? Customer.datec : ""));
  1262. return $container;
  1263. }
  1264. function formatCustomerSelection (selection) {
  1265. return selection.label || selection.text;
  1266. }
  1267. });
  1268. </script>
  1269. ';
  1270. */
  1271. print '</td>';
  1272. if (!empty($conf->global->SOCIETE_USEPREFIX)) { // Old not used prefix field
  1273. print '<td>'.$langs->trans('Prefix').'</td><td><input type="text" size="5" maxlength="5" name="prefix_comm" value="'.dol_escape_htmltag($object->prefix_comm).'"></td>';
  1274. }
  1275. print '</tr>';
  1276. // If javascript on, we show option individual
  1277. if ($conf->use_javascript_ajax) {
  1278. if (!empty($conf->global->THIRDPARTY_SUGGEST_ALSO_ADDRESS_CREATION)) {
  1279. // Firstname
  1280. print '<tr class="individualline"><td>'.$form->editfieldkey('FirstName', 'firstname', '', $object, 0).'</td>';
  1281. print '<td colspan="3"><input type="text" class="minwidth300" maxlength="128" name="firstname" id="firstname" value="'.dol_escape_htmltag($object->firstname).'"></td>';
  1282. print '</tr>';
  1283. // Title
  1284. print '<tr class="individualline"><td>'.$form->editfieldkey('UserTitle', 'civility_id', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">';
  1285. print $formcompany->select_civility($object->civility_id, 'civility_id', 'maxwidth100').'</td>';
  1286. print '</tr>';
  1287. }
  1288. }
  1289. // Alias names (commercial, trademark or alias names)
  1290. print '<tr id="name_alias"><td><label for="name_alias_input">'.$langs->trans('AliasNames').'</label></td>';
  1291. print '<td colspan="3"><input type="text" class="minwidth300" name="name_alias" id="name_alias_input" value="'.dol_escape_htmltag($object->name_alias).'"></td></tr>';
  1292. // Prospect/Customer
  1293. print '<tr><td class="titlefieldcreate">'.$form->editfieldkey('ProspectCustomer', 'customerprospect', '', $object, 0, 'string', '', 1).'</td>';
  1294. print '<td class="maxwidthonsmartphone">';
  1295. $selected = (GETPOSTISSET('client') ?GETPOST('client', 'int') : $object->client);
  1296. print $formcompany->selectProspectCustomerType($selected);
  1297. print '</td>';
  1298. if ($conf->browser->layout == 'phone') {
  1299. print '</tr><tr>';
  1300. }
  1301. print '<td>'.$form->editfieldkey('CustomerCode', 'customer_code', '', $object, 0).'</td><td>';
  1302. print '<table class="nobordernopadding"><tr><td>';
  1303. $tmpcode = $object->code_client;
  1304. if (empty($tmpcode) && !empty($modCodeClient->code_auto)) {
  1305. $tmpcode = $modCodeClient->getNextValue($object, 0);
  1306. }
  1307. print '<input type="text" name="customer_code" id="customer_code" class="maxwidthonsmartphone" value="'.dol_escape_htmltag($tmpcode).'" maxlength="24">';
  1308. print '</td><td>';
  1309. $s = $modCodeClient->getToolTip($langs, $object, 0);
  1310. print $form->textwithpicto('', $s, 1);
  1311. print '</td></tr></table>';
  1312. print '</td></tr>';
  1313. if ((isModEnabled("fournisseur") && !empty($user->rights->fournisseur->lire) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || (isModEnabled("supplier_order") && !empty($user->rights->supplier_order->lire)) || (isModEnabled("supplier_invoice") && !empty($user->rights->supplier_invoice->lire))
  1314. || (isModEnabled('supplier_proposal') && !empty($user->rights->supplier_proposal->lire))) {
  1315. // Supplier
  1316. print '<tr>';
  1317. print '<td>'.$form->editfieldkey('Vendor', 'fournisseur', '', $object, 0, 'string', '', 1).'</td><td>';
  1318. $default = -1;
  1319. if (!empty($conf->global->THIRDPARTY_SUPPLIER_BY_DEFAULT)) {
  1320. $default = 1;
  1321. }
  1322. print $form->selectyesno("fournisseur", (GETPOST('fournisseur', 'int') != '' ? GETPOST('fournisseur', 'int') : (GETPOST("type", 'alpha') == '' ? $default : $object->fournisseur)), 1, 0, (GETPOST("type", 'alpha') == '' ? 1 : 0), 1);
  1323. print '</td>';
  1324. if ($conf->browser->layout == 'phone') {
  1325. print '</tr><tr>';
  1326. }
  1327. print '<td>';
  1328. if ((isModEnabled("fournisseur") && !empty($user->rights->fournisseur->lire) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || (isModEnabled("supplier_order") && !empty($user->rights->supplier_order->lire)) || (isModEnabled("supplier_invoice") && !empty($user->rights->supplier_invoice->lire))) {
  1329. print $form->editfieldkey('SupplierCode', 'supplier_code', '', $object, 0);
  1330. }
  1331. print '</td><td>';
  1332. if ((isModEnabled("fournisseur") && !empty($user->rights->fournisseur->lire) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || (isModEnabled("supplier_order") && !empty($user->rights->supplier_order->lire)) || (isModEnabled("supplier_invoice") && !empty($user->rights->supplier_invoice->lire))) {
  1333. print '<table class="nobordernopadding"><tr><td>';
  1334. $tmpcode = $object->code_fournisseur;
  1335. if (empty($tmpcode) && !empty($modCodeFournisseur->code_auto)) {
  1336. $tmpcode = $modCodeFournisseur->getNextValue($object, 1);
  1337. }
  1338. print '<input type="text" name="supplier_code" id="supplier_code" class="maxwidthonsmartphone" value="'.dol_escape_htmltag($tmpcode).'" maxlength="24">';
  1339. print '</td><td>';
  1340. $s = $modCodeFournisseur->getToolTip($langs, $object, 1);
  1341. print $form->textwithpicto('', $s, 1);
  1342. print '</td></tr></table>';
  1343. }
  1344. print '</td></tr>';
  1345. }
  1346. // Status
  1347. print '<tr><td>'.$form->editfieldkey('Status', 'status', '', $object, 0).'</td><td colspan="3">';
  1348. print $form->selectarray('status', array('0'=>$langs->trans('ActivityCeased'), '1'=>$langs->trans('InActivity')), 1, 0, 0, 0, '', 0, 0, 0, '', 'minwidth100', 1);
  1349. print '</td></tr>';
  1350. // Barcode
  1351. if (isModEnabled('barcode')) {
  1352. print '<tr><td>'.$form->editfieldkey('Gencod', 'barcode', '', $object, 0).'</td>';
  1353. print '<td colspan="3">';
  1354. print img_picto('', 'barcode', 'class="pictofixedwidth"');
  1355. print '<input type="text" name="barcode" id="barcode" value="'.dol_escape_htmltag($object->barcode).'">';
  1356. print '</td></tr>';
  1357. }
  1358. // Address
  1359. print '<tr><td class="tdtop">';
  1360. print $form->editfieldkey('Address', 'address', '', $object, 0);
  1361. print '</td>';
  1362. print '<td colspan="3">';
  1363. print '<textarea name="address" id="address" class="quatrevingtpercent" rows="'.ROWS_2.'" wrap="soft">';
  1364. print dol_escape_htmltag($object->address, 0, 1);
  1365. print '</textarea>';
  1366. print $form->widgetForTranslation("address", $object, $permissiontoadd, 'textarea', 'alphanohtml', 'quatrevingtpercent');
  1367. print '</td></tr>';
  1368. // Zip / Town
  1369. print '<tr><td>'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).'</td><td>';
  1370. print $formcompany->select_ziptown($object->zip, 'zipcode', array('town', 'selectcountry_id', 'state_id'), 0, 0, '', 'maxwidth100');
  1371. print '</td>';
  1372. if ($conf->browser->layout == 'phone') {
  1373. print '</tr><tr>';
  1374. }
  1375. print '<td class="tdtop">'.$form->editfieldkey('Town', 'town', '', $object, 0).'</td><td>';
  1376. print $formcompany->select_ziptown($object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id'), 0, 0, '', 'maxwidth150 quatrevingtpercent');
  1377. print $form->widgetForTranslation("town", $object, $permissiontoadd, 'string', 'alphanohtml', 'maxwidth100 quatrevingtpercent');
  1378. print '</td></tr>';
  1379. // Country
  1380. print '<tr><td>'.$form->editfieldkey('Country', 'selectcountry_id', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">';
  1381. print img_picto('', 'country', 'class="pictofixedwidth"');
  1382. print $form->select_country((GETPOSTISSET('country_id') ? GETPOST('country_id') : $object->country_id), 'country_id', '', 0, 'minwidth300 maxwidth500 widthcentpercentminusx');
  1383. if ($user->admin) {
  1384. print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  1385. }
  1386. print '</td></tr>';
  1387. // State
  1388. if (empty($conf->global->SOCIETE_DISABLE_STATE)) {
  1389. if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && ($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 || $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 2)) {
  1390. print '<tr><td>'.$form->editfieldkey('Region-State', 'state_id', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">';
  1391. } else {
  1392. print '<tr><td>'.$form->editfieldkey('State', 'state_id', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">';
  1393. }
  1394. if ($object->country_id) {
  1395. print img_picto('', 'state', 'class="pictofixedwidth"');
  1396. print $formcompany->select_state($object->state_id, $object->country_code);
  1397. } else {
  1398. print $countrynotdefined;
  1399. }
  1400. print '</td></tr>';
  1401. }
  1402. // Phone / Fax
  1403. print '<tr><td>'.$form->editfieldkey('Phone', 'phone', '', $object, 0).'</td>';
  1404. print '<td'.($conf->browser->layout == 'phone' ? ' colspan="3"' : '').'>'.img_picto('', 'object_phoning', 'class="pictofixedwidth"').' <input type="text" name="phone" id="phone" class="maxwidth200 widthcentpercentminusx" value="'.(GETPOSTISSET('phone') ?GETPOST('phone', 'alpha') : $object->phone).'"></td>';
  1405. if ($conf->browser->layout == 'phone') {
  1406. print '</tr><tr>';
  1407. }
  1408. print '<td>'.$form->editfieldkey('Fax', 'fax', '', $object, 0).'</td>';
  1409. print '<td'.($conf->browser->layout == 'phone' ? ' colspan="3"' : '').'>'.img_picto('', 'object_phoning_fax', 'class="pictofixedwidth"').' <input type="text" name="fax" id="fax" class="maxwidth200 widthcentpercentminusx" value="'.(GETPOSTISSET('fax') ?GETPOST('fax', 'alpha') : $object->fax).'"></td></tr>';
  1410. // Email / Web
  1411. print '<tr><td>'.$form->editfieldkey('EMail', 'email', '', $object, 0, 'string', '', empty($conf->global->SOCIETE_EMAIL_MANDATORY) ? '' : $conf->global->SOCIETE_EMAIL_MANDATORY).'</td>';
  1412. print '<td'.(($conf->browser->layout == 'phone') || !isModEnabled('mailing') ? ' colspan="3"' : '').'>'.img_picto('', 'object_email', 'class="pictofixedwidth"').' <input type="text" class="maxwidth200 widthcentpercentminusx" name="email" id="email" value="'.$object->email.'"></td>';
  1413. if (isModEnabled('mailing') && !empty($conf->global->THIRDPARTY_SUGGEST_ALSO_ADDRESS_CREATION)) {
  1414. if ($conf->browser->layout == 'phone') {
  1415. print '</tr><tr>';
  1416. }
  1417. print '<td class="individualline noemail">'.$form->editfieldkey($langs->trans('No_Email') .' ('.$langs->trans('Contact').')', 'contact_no_email', '', $object, 0).'</td>';
  1418. print '<td class="individualline" '.(($conf->browser->layout == 'phone') || !isModEnabled('mailing') ? ' colspan="3"' : '').'>'.$form->selectyesno('contact_no_email', (GETPOSTISSET("contact_no_email") ? GETPOST("contact_no_email", 'alpha') : (empty($object->no_email) ? 0 : 1)), 1, false, 1).'</td>';
  1419. }
  1420. print '</tr>';
  1421. print '<tr><td>'.$form->editfieldkey('Web', 'url', '', $object, 0).'</td>';
  1422. print '<td colspan="3">'.img_picto('', 'globe', 'class="pictofixedwidth"').' <input type="text" class="maxwidth500 widthcentpercentminusx" name="url" id="url" value="'.$object->url.'"></td></tr>';
  1423. // Unsubscribe
  1424. if (!empty($conf->mailing->enabled)) {
  1425. if ($conf->use_javascript_ajax && $conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS == 2) {
  1426. print "\n".'<script type="text/javascript">'."\n";
  1427. print '$(document).ready(function () {
  1428. $("#email").keyup(function() {
  1429. if ($(this).val()!="") {
  1430. $(".noemail").addClass("fieldrequired");
  1431. } else {
  1432. $(".noemail").removeClass("fieldrequired");
  1433. }
  1434. });
  1435. })'."\n";
  1436. print '</script>'."\n";
  1437. }
  1438. if (!GETPOSTISSET("no_email") && !empty($object->email)) {
  1439. $result = $object->getNoEmail();
  1440. if ($result < 0) {
  1441. setEventMessages($object->error, $object->errors, 'errors');
  1442. }
  1443. }
  1444. print '<tr>';
  1445. print '<td class="noemail"><label for="no_email">'.$langs->trans("No_Email").'</label></td>';
  1446. print '<td>';
  1447. print $form->selectyesno('no_email', (GETPOSTISSET("no_email") ? GETPOST("no_email", 'int') : $conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS), 1, false, ($conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS == 2));
  1448. print '</td>';
  1449. print '</tr>';
  1450. }
  1451. // Social networks
  1452. if (isModEnabled('socialnetworks')) {
  1453. foreach ($socialnetworks as $key => $value) {
  1454. if ($value['active']) {
  1455. print '<tr>';
  1456. print '<td><label for="'.$value['label'].'">'.$form->editfieldkey($value['label'], $key, '', $object, 0).'</label></td>';
  1457. print '<td colspan="3">';
  1458. if (!empty($value['icon'])) {
  1459. print '<span class="fa '.$value['icon'].' pictofixedwidth"></span>';
  1460. }
  1461. print '<input type="text" name="'.$key.'" id="'.$key.'" class="minwidth100 maxwidth300 widthcentpercentminusx" maxlength="80" value="'.dol_escape_htmltag(GETPOSTISSET($key) ? GETPOST($key, 'alphanohtml') : (empty($object->socialnetworks[$key]) ? '' : $object->socialnetworks[$key])).'">';
  1462. print '</td>';
  1463. print '</tr>';
  1464. } elseif (!empty($object->socialnetworks[$key])) {
  1465. print '<input type="hidden" name="'.$key.'" value="'.$object->socialnetworks[$key].'">';
  1466. }
  1467. }
  1468. }
  1469. // Prof ids
  1470. $i = 1; $j = 0; $NBCOLS = ($conf->browser->layout == 'phone' ? 1 : 2);
  1471. while ($i <= 6) {
  1472. $idprof = $langs->transcountry('ProfId'.$i, $object->country_code);
  1473. if ($idprof != '-') {
  1474. $key = 'idprof'.$i;
  1475. if (($j % $NBCOLS) == 0) {
  1476. print '<tr>';
  1477. }
  1478. $idprof_mandatory = 'SOCIETE_IDPROF'.($i).'_MANDATORY';
  1479. print '<td>'.$form->editfieldkey($idprof, $key, '', $object, 0, 'string', '', (empty($conf->global->$idprof_mandatory) ? 0 : 1)).'</td><td>';
  1480. print $formcompany->get_input_id_prof($i, $key, $object->$key, $object->country_code);
  1481. print '</td>';
  1482. if (($j % $NBCOLS) == ($NBCOLS - 1)) {
  1483. print '</tr>';
  1484. }
  1485. $j++;
  1486. }
  1487. $i++;
  1488. }
  1489. if ($NBCOLS > 1 && ($j % 2 == 1)) {
  1490. print '<td colspan="2"></td></tr>';
  1491. }
  1492. // Vat is used
  1493. print '<tr><td>'.$form->editfieldkey('VATIsUsed', 'assujtva_value', '', $object, 0).'</td>';
  1494. print '<td>';
  1495. print $form->selectyesno('assujtva_value', GETPOSTISSET('assujtva_value') ?GETPOST('assujtva_value', 'int') : 1, 1); // Assujeti par defaut en creation
  1496. print '</td>';
  1497. if ($conf->browser->layout == 'phone') {
  1498. print '</tr><tr>';
  1499. }
  1500. print '<td class="nowrap">'.$form->editfieldkey('VATIntra', 'intra_vat', '', $object, 0).'</td>';
  1501. print '<td class="nowrap">';
  1502. $s = '<input type="text" class="flat maxwidthonsmartphone" name="tva_intra" id="intra_vat" maxlength="20" value="'.$object->tva_intra.'">';
  1503. if (empty($conf->global->MAIN_DISABLEVATCHECK) && isInEEC($object)) {
  1504. $s .= ' ';
  1505. if (!empty($conf->use_javascript_ajax)) {
  1506. $widthpopup = 600;
  1507. if (!empty($conf->dol_use_jmobile)) {
  1508. $widthpopup = 350;
  1509. }
  1510. $heightpopup = 400;
  1511. print "\n";
  1512. print '<script type="text/javascript">';
  1513. print "function CheckVAT(a) {\n";
  1514. print "newpopup('".DOL_URL_ROOT."/societe/checkvat/checkVatPopup.php?vatNumber='+a, '".dol_escape_js($langs->trans("VATIntraCheckableOnEUSite"))."', ".$widthpopup.", ".$heightpopup.");\n";
  1515. print "}\n";
  1516. print '</script>';
  1517. print "\n";
  1518. $s .= '<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>';
  1519. $s = $form->textwithpicto($s, $langs->trans("VATIntraCheckDesc", $langs->transnoentitiesnoconv("VATIntraCheck")), 1);
  1520. } else {
  1521. $s .= '<a href="'.$langs->transcountry("VATIntraCheckURL", $object->country_id).'" target="_blank" rel="noopener noreferrer">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"), 'help').'</a>';
  1522. }
  1523. }
  1524. print $s;
  1525. print '</td>';
  1526. print '</tr>';
  1527. // Local Taxes
  1528. //TODO: Place into a function to control showing by country or study better option
  1529. if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1") {
  1530. print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>';
  1531. print $form->selectyesno('localtax1assuj_value', (isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1) ? $conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1 : 0), 1);
  1532. print '</td>';
  1533. if ($conf->browser->layout == 'phone') {
  1534. print '</tr><tr>';
  1535. }
  1536. print '<td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>';
  1537. print $form->selectyesno('localtax2assuj_value', (isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2) ? $conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2 : 0), 1);
  1538. print '</td></tr>';
  1539. } elseif ($mysoc->localtax1_assuj == "1") {
  1540. print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td colspan="3">';
  1541. print $form->selectyesno('localtax1assuj_value', (isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1) ? $conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1 : 0), 1);
  1542. print '</td></tr>';
  1543. } elseif ($mysoc->localtax2_assuj == "1") {
  1544. print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td colspan="3">';
  1545. print $form->selectyesno('localtax2assuj_value', (isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2) ? $conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2 : 0), 1);
  1546. print '</td></tr>';
  1547. }
  1548. // Type - Workforce/Staff
  1549. print '<tr><td>'.$form->editfieldkey('ThirdPartyType', 'typent_id', '', $object, 0).'</td><td class="maxwidthonsmartphone"'.( ($conf->browser->layout == 'phone' || !empty($conf->global->SOCIETE_DISABLE_WORKFORCE)) ? ' colspan="3"' : '').'>'."\n";
  1550. $sortparam = (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT); // NONE means we keep sort of original array, so we sort on position. ASC, means next function will sort on label.
  1551. print $form->selectarray("typent_id", $formcompany->typent_array(0), $object->typent_id, 1, 0, 0, '', 0, 0, 0, $sortparam, '', 1);
  1552. if ($user->admin) {
  1553. print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  1554. }
  1555. if (empty($conf->global->SOCIETE_DISABLE_WORKFORCE)) {
  1556. print '</td>';
  1557. if ($conf->browser->layout == 'phone') {
  1558. print '</tr><tr>';
  1559. }
  1560. print '<td>'.$form->editfieldkey('Workforce', 'effectif_id', '', $object, 0).'</td><td class="maxwidthonsmartphone"'.($conf->browser->layout == 'phone' ? ' colspan="3"' : '').'>';
  1561. print $form->selectarray("effectif_id", $formcompany->effectif_array(0), $object->effectif_id, 0, 0, 0, '', 0, 0, 0, '', '', 1);
  1562. if ($user->admin) {
  1563. print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  1564. }
  1565. } else {
  1566. print '<input type="hidden" name="effectif_id" id="effectif_id" value="'.$object->effectif_id.'">';
  1567. }
  1568. print '</td></tr>';
  1569. // Legal Form
  1570. print '<tr><td>'.$form->editfieldkey('JuridicalStatus', 'forme_juridique_code', '', $object, 0).'</td>';
  1571. print '<td colspan="3" class="maxwidthonsmartphone">';
  1572. if ($object->country_id) {
  1573. print $formcompany->select_juridicalstatus($object->forme_juridique_code, $object->country_code, '', 'forme_juridique_code');
  1574. } else {
  1575. print $countrynotdefined;
  1576. }
  1577. print '</td></tr>';
  1578. // Capital
  1579. print '<tr><td>'.$form->editfieldkey('Capital', 'capital', '', $object, 0).'</td>';
  1580. print '<td colspan="3"><input type="text" name="capital" id="capital" class="maxwidth100" value="'.$object->capital.'"> ';
  1581. if (isModEnabled("multicurrency")) {
  1582. print '<span class="hideonsmartphone">'.$langs->trans("Currency".$object->multicurrency_code).'</span></td></tr>';
  1583. } else {
  1584. print '<span class="hideonsmartphone">'.$langs->trans("Currency".$conf->currency).'</span></td></tr>';
  1585. }
  1586. if (getDolGlobalInt('MAIN_MULTILANGS')) {
  1587. print '<tr><td>'.$form->editfieldkey('DefaultLang', 'default_lang', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">'."\n";
  1588. print img_picto('', 'language', 'class="pictofixedwidth"').$formadmin->select_language(GETPOST('default_lang', 'alpha') ? GETPOST('default_lang', 'alpha') : ($object->default_lang ? $object->default_lang : ''), 'default_lang', 0, 0, 1, 0, 0, 'maxwidth200onsmartphone');
  1589. print '</td>';
  1590. print '</tr>';
  1591. }
  1592. // Incoterms
  1593. if (isModEnabled('incoterm')) {
  1594. print '<tr>';
  1595. print '<td>'.$form->editfieldkey('IncotermLabel', 'incoterm_id', '', $object, 0).'</td>';
  1596. print '<td colspan="3" class="maxwidthonsmartphone">';
  1597. print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''));
  1598. print '</td></tr>';
  1599. }
  1600. // Categories
  1601. if (isModEnabled('categorie') && !empty($user->rights->categorie->lire)) {
  1602. $langs->load('categories');
  1603. // Customer
  1604. print '<tr class="visibleifcustomer"><td class="toptd">'.$form->editfieldkey('CustomersProspectsCategoriesShort', 'custcats', '', $object, 0).'</td><td colspan="3">';
  1605. $cate_arbo = $form->select_all_categories(Categorie::TYPE_CUSTOMER, null, 'parent', null, null, 1);
  1606. print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('custcats', $cate_arbo, GETPOST('custcats', 'array'), null, null, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
  1607. print "</td></tr>";
  1608. if (!empty($conf->global->THIRDPARTY_SUGGEST_ALSO_ADDRESS_CREATION)) {
  1609. print '<tr class="individualline"><td class="toptd">'.$form->editfieldkey('ContactCategoriesShort', 'contcats', '', $object, 0).'</td><td colspan="3">';
  1610. $cate_arbo = $form->select_all_categories(Categorie::TYPE_CONTACT, null, 'parent', null, null, 1);
  1611. print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('contcats', $cate_arbo, GETPOST('contcats', 'array'), null, null, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
  1612. print "</td></tr>";
  1613. }
  1614. // Supplier
  1615. if ((isModEnabled("fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) {
  1616. print '<tr class="visibleifsupplier"><td class="toptd">'.$form->editfieldkey('SuppliersCategoriesShort', 'suppcats', '', $object, 0).'</td><td colspan="3">';
  1617. $cate_arbo = $form->select_all_categories(Categorie::TYPE_SUPPLIER, null, 'parent', null, null, 1);
  1618. print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('suppcats', $cate_arbo, GETPOST('suppcats', 'array'), null, null, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
  1619. print "</td></tr>";
  1620. }
  1621. }
  1622. // Multicurrency
  1623. if (isModEnabled("multicurrency")) {
  1624. print '<tr>';
  1625. print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
  1626. print '<td colspan="3" class="maxwidthonsmartphone">';
  1627. print img_picto('', 'currency', 'class="pictofixedwidth"');
  1628. print $form->selectMultiCurrency((GETPOSTISSET('multicurrency_code') ? GETPOST('multicurrency_code') : ($object->multicurrency_code ? $object->multicurrency_code : $conf->currency)), 'multicurrency_code', 1, '', false, 'maxwidth150 widthcentpercentminusx');
  1629. print '</td></tr>';
  1630. }
  1631. // Other attributes
  1632. $parameters = array('socid'=>$socid, 'colspan' => ' colspan="3"', 'colspanvalue' => '3');
  1633. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
  1634. // Parent company
  1635. if (empty($conf->global->SOCIETE_DISABLE_PARENTCOMPANY)) {
  1636. print '<tr>';
  1637. print '<td>'.$langs->trans('ParentCompany').'</td>';
  1638. print '<td colspan="3" class="maxwidthonsmartphone">';
  1639. print img_picto('', 'company', 'class="paddingrightonly"');
  1640. print $form->select_company(GETPOST('parent_company_id'), 'parent_company_id', '', 'SelectThirdParty', 0, 0, null, 0, 'minwidth300 maxwidth500 widthcentpercentminusxx');
  1641. print '</td></tr>';
  1642. }
  1643. // Assign a sale representative
  1644. print '<tr>';
  1645. print '<td>'.$form->editfieldkey('AllocateCommercial', 'commercial_id', '', $object, 0).'</td>';
  1646. print '<td colspan="3" class="maxwidthonsmartphone">';
  1647. $userlist = $form->select_dolusers('', '', 0, null, 0, '', '', 0, 0, 0, 'AND u.statut = 1', 0, '', '', 0, 1);
  1648. // Note: If user has no right to "see all thirdparties", we force selection of sale representative to him, so after creation he can see the record.
  1649. $selected = (count(GETPOST('commercial', 'array')) > 0 ? GETPOST('commercial', 'array') : (GETPOST('commercial', 'int') > 0 ? array(GETPOST('commercial', 'int')) : (empty($user->rights->societe->client->voir) ? array($user->id) : array())));
  1650. print img_picto('', 'user').$form->multiselectarray('commercial', $userlist, $selected, null, null, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
  1651. print '</td></tr>';
  1652. // Add logo
  1653. print '<tr class="hideonsmartphone">';
  1654. print '<td>'.$form->editfieldkey('Logo', 'photoinput', '', $object, 0).'</td>';
  1655. print '<td colspan="3">';
  1656. print '<input class="flat" type="file" name="photo" id="photoinput" />';
  1657. print '</td>';
  1658. print '</tr>';
  1659. print '</table>'."\n";
  1660. // Accountancy codes
  1661. if (!empty($conf->global->ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY)) {
  1662. print '<table class="border centpercent">';
  1663. if (isModEnabled('accounting')) {
  1664. // Accountancy_code_sell
  1665. print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellCode").'</td>';
  1666. print '<td>';
  1667. $accountancy_code_sell = GETPOST('accountancy_code_sell', 'alpha');
  1668. print $formaccounting->select_account($accountancy_code_sell, 'accountancy_code_sell', 1, null, 1, 1, '');
  1669. print '</td></tr>';
  1670. // Accountancy_code_buy
  1671. print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyCode").'</td>';
  1672. print '<td>';
  1673. $accountancy_code_buy = GETPOST('accountancy_code_buy', 'alpha');
  1674. print $formaccounting->select_account($accountancy_code_buy, 'accountancy_code_buy', 1, null, 1, 1, '');
  1675. print '</td></tr>';
  1676. } else { // For external software
  1677. // Accountancy_code_sell
  1678. print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellCode").'</td>';
  1679. print '<td class="maxwidthonsmartphone"><input class="minwidth100" name="accountancy_code_sell" value="'.$object->accountancy_code_sell.'">';
  1680. print '</td></tr>';
  1681. // Accountancy_code_buy
  1682. print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyCode").'</td>';
  1683. print '<td class="maxwidthonsmartphone"><input class="minwidth100" name="accountancy_code_buy" value="'.$object->accountancy_code_buy.'">';
  1684. print '</td></tr>';
  1685. }
  1686. print '</table>';
  1687. }
  1688. print dol_get_fiche_end();
  1689. print $form->buttonsSaveCancel("AddThirdParty", 'Cancel', null, 0, '', $dol_openinpopup);
  1690. print '</form>'."\n";
  1691. } elseif ($action == 'edit') {
  1692. //print load_fiche_titre($langs->trans("EditCompany"));
  1693. if ($socid) {
  1694. $res = $object->fetch_optionals();
  1695. //if ($res < 0) { dol_print_error($db); exit; }
  1696. $head = societe_prepare_head($object);
  1697. // Load object modCodeTiers
  1698. $module = (!empty($conf->global->SOCIETE_CODECLIENT_ADDON) ? $conf->global->SOCIETE_CODECLIENT_ADDON : 'mod_codeclient_leopard');
  1699. if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') {
  1700. $module = substr($module, 0, dol_strlen($module) - 4);
  1701. }
  1702. $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
  1703. foreach ($dirsociete as $dirroot) {
  1704. $res = dol_include_once($dirroot.$module.'.php');
  1705. if ($res) {
  1706. break;
  1707. }
  1708. }
  1709. $modCodeClient = new $module($db);
  1710. // We verified if the tag prefix is used
  1711. if ($modCodeClient->code_auto) {
  1712. $prefixCustomerIsUsed = $modCodeClient->verif_prefixIsUsed();
  1713. }
  1714. $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
  1715. if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') {
  1716. $module = substr($module, 0, dol_strlen($module) - 4);
  1717. }
  1718. $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
  1719. foreach ($dirsociete as $dirroot) {
  1720. $res = dol_include_once($dirroot.$module.'.php');
  1721. if ($res) {
  1722. break;
  1723. }
  1724. }
  1725. $modCodeFournisseur = new $module($db);
  1726. // On verifie si la balise prefix est utilisee
  1727. if ($modCodeFournisseur->code_auto) {
  1728. $prefixSupplierIsUsed = $modCodeFournisseur->verif_prefixIsUsed();
  1729. }
  1730. $object->oldcopy = clone $object;
  1731. if (GETPOSTISSET('name')) {
  1732. // We overwrite with values if posted
  1733. $object->name = GETPOST('name', 'alphanohtml');
  1734. $object->name_alias = GETPOST('name_alias', 'alphanohtml');
  1735. $object->prefix_comm = GETPOST('prefix_comm', 'alphanohtml');
  1736. $object->client = GETPOST('client', 'int');
  1737. $object->code_client = GETPOST('customer_code', 'alpha');
  1738. $object->fournisseur = GETPOST('fournisseur', 'int');
  1739. $object->code_fournisseur = GETPOST('supplier_code', 'alpha');
  1740. $object->address = GETPOST('address', 'alphanohtml');
  1741. $object->zip = GETPOST('zipcode', 'alphanohtml');
  1742. $object->town = GETPOST('town', 'alphanohtml');
  1743. $object->country_id = GETPOST('country_id') ?GETPOST('country_id', 'int') : $mysoc->country_id;
  1744. $object->state_id = GETPOST('state_id', 'int');
  1745. $object->parent = GETPOST('parent_company_id', 'int');
  1746. $object->socialnetworks = array();
  1747. if (isModEnabled('socialnetworks')) {
  1748. foreach ($socialnetworks as $key => $value) {
  1749. if (GETPOSTISSET($key) && GETPOST($key, 'alphanohtml') != '') {
  1750. $object->socialnetworks[$key] = GETPOST($key, 'alphanohtml');
  1751. }
  1752. }
  1753. }
  1754. $object->phone = GETPOST('phone', 'alpha');
  1755. $object->fax = GETPOST('fax', 'alpha');
  1756. $object->email = GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL);
  1757. $object->no_email = GETPOST("no_email", "int");
  1758. $object->url = GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL);
  1759. $object->capital = GETPOST('capital', 'alphanohtml');
  1760. $object->idprof1 = GETPOST('idprof1', 'alphanohtml');
  1761. $object->idprof2 = GETPOST('idprof2', 'alphanohtml');
  1762. $object->idprof3 = GETPOST('idprof3', 'alphanohtml');
  1763. $object->idprof4 = GETPOST('idprof4', 'alphanohtml');
  1764. $object->idprof5 = GETPOST('idprof5', 'alphanohtml');
  1765. $object->idprof6 = GETPOST('idprof6', 'alphanohtml');
  1766. $object->typent_id = GETPOST('typent_id', 'int');
  1767. $object->effectif_id = GETPOST('effectif_id', 'int');
  1768. $object->barcode = GETPOST('barcode', 'alphanohtml');
  1769. $object->forme_juridique_code = GETPOST('forme_juridique_code', 'int');
  1770. $object->default_lang = GETPOST('default_lang', 'alpha');
  1771. $object->tva_assuj = GETPOST('assujtva_value', 'int');
  1772. $object->tva_intra = GETPOST('tva_intra', 'alphanohtml');
  1773. $object->status = GETPOST('status', 'int');
  1774. // Webservices url/key
  1775. $object->webservices_url = GETPOST('webservices_url', 'custom', 0, FILTER_SANITIZE_URL);
  1776. $object->webservices_key = GETPOST('webservices_key', 'san_alpha');
  1777. if (GETPOSTISSET('accountancy_code_sell')) {
  1778. $accountancy_code_sell = GETPOST('accountancy_code_sell', 'alpha');
  1779. if (empty($accountancy_code_sell) || $accountancy_code_sell == '-1') {
  1780. $object->accountancy_code_sell = '';
  1781. } else {
  1782. $object->accountancy_code_sell = $accountancy_code_sell;
  1783. }
  1784. }
  1785. if (GETPOSTISSET('accountancy_code_buy')) {
  1786. $accountancy_code_buy = GETPOST('accountancy_code_buy', 'alpha');
  1787. if (empty($accountancy_code_buy) || $accountancy_code_buy == '-1') {
  1788. $object->accountancy_code_buy = '';
  1789. } else {
  1790. $object->accountancy_code_buy = $accountancy_code_buy;
  1791. }
  1792. }
  1793. //Incoterms
  1794. if (isModEnabled('incoterm')) {
  1795. $object->fk_incoterms = GETPOST('incoterm_id', 'int');
  1796. $object->location_incoterms = GETPOST('lcoation_incoterms', 'alpha');
  1797. }
  1798. //Local Taxes
  1799. $object->localtax1_assuj = GETPOST('localtax1assuj_value');
  1800. $object->localtax2_assuj = GETPOST('localtax2assuj_value');
  1801. $object->localtax1_value = GETPOST('lt1');
  1802. $object->localtax2_value = GETPOST('lt2');
  1803. // We set country_id, and country_code label of the chosen country
  1804. if ($object->country_id > 0) {
  1805. $tmparray = getCountry($object->country_id, 'all');
  1806. $object->country_code = $tmparray['code'];
  1807. $object->country = $tmparray['label'];
  1808. }
  1809. // We set multicurrency_code if enabled
  1810. if (isModEnabled("multicurrency")) {
  1811. $object->multicurrency_code = GETPOST('multicurrency_code') ? GETPOST('multicurrency_code') : $object->multicurrency_code;
  1812. }
  1813. }
  1814. if ($object->localtax1_assuj == 0) {
  1815. $sub = 0;
  1816. } else {
  1817. $sub = 1;
  1818. }
  1819. if ($object->localtax2_assuj == 0) {
  1820. $sub2 = 0;
  1821. } else {
  1822. $sub2 = 1;
  1823. }
  1824. if (!empty($conf->use_javascript_ajax)) {
  1825. print "\n".'<script type="text/javascript">';
  1826. print '$(document).ready(function () {
  1827. var val='.$sub.';
  1828. var val2='.$sub2.';
  1829. if("#localtax1assuj_value".value==undefined){
  1830. if(val==1){
  1831. $(".cblt1").show();
  1832. }else{
  1833. $(".cblt1").hide();
  1834. }
  1835. }
  1836. if("#localtax2assuj_value".value==undefined){
  1837. if(val2==1){
  1838. $(".cblt2").show();
  1839. }else{
  1840. $(".cblt2").hide();
  1841. }
  1842. }
  1843. $("#localtax1assuj_value").change(function() {
  1844. var value=document.getElementById("localtax1assuj_value").value;
  1845. if(value==1){
  1846. $(".cblt1").show();
  1847. }else{
  1848. $(".cblt1").hide();
  1849. }
  1850. });
  1851. $("#localtax2assuj_value").change(function() {
  1852. var value=document.getElementById("localtax2assuj_value").value;
  1853. if(value==1){
  1854. $(".cblt2").show();
  1855. }else{
  1856. $(".cblt2").hide();
  1857. }
  1858. });
  1859. var canHaveCategoryIfNotCustomerProspectSupplier = ' . (empty($conf->global->THIRDPARTY_CAN_HAVE_CUSTOMER_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT) ? '0' : '1') . ';
  1860. init_customer_categ();
  1861. $("#customerprospect").change(function() {
  1862. init_customer_categ();
  1863. });
  1864. function init_customer_categ() {
  1865. console.log("is customer or prospect = "+jQuery("#customerprospect").val());
  1866. if (jQuery("#customerprospect").val() == 0 && !canHaveCategoryIfNotCustomerProspectSupplier)
  1867. {
  1868. jQuery(".visibleifcustomer").hide();
  1869. }
  1870. else
  1871. {
  1872. jQuery(".visibleifcustomer").show();
  1873. }
  1874. }
  1875. init_supplier_categ();
  1876. $("#fournisseur").change(function() {
  1877. init_supplier_categ();
  1878. });
  1879. function init_supplier_categ() {
  1880. console.log("is supplier = "+jQuery("#fournisseur").val());
  1881. if (jQuery("#fournisseur").val() == 0)
  1882. {
  1883. jQuery(".visibleifsupplier").hide();
  1884. }
  1885. else
  1886. {
  1887. jQuery(".visibleifsupplier").show();
  1888. }
  1889. };
  1890. $("#selectcountry_id").change(function() {
  1891. document.formsoc.action.value="edit";
  1892. document.formsoc.submit();
  1893. });
  1894. })';
  1895. print '</script>'."\n";
  1896. }
  1897. print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'" method="post" name="formsoc">';
  1898. print '<input type="hidden" name="action" value="update">';
  1899. print '<input type="hidden" name="token" value="'.newToken().'">';
  1900. print '<input type="hidden" name="socid" value="'.$object->id.'">';
  1901. print '<input type="hidden" name="entity" value="'.$object->entity.'">';
  1902. if ($modCodeClient->code_auto || $modCodeFournisseur->code_auto) {
  1903. print '<input type="hidden" name="code_auto" value="1">';
  1904. }
  1905. print dol_get_fiche_head($head, 'card', $langs->trans("ThirdParty"), 0, 'company');
  1906. print '<div class="fichecenter2">';
  1907. print '<table class="border centpercent">';
  1908. // Ref/ID
  1909. if (!empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) {
  1910. print '<tr><td class="titlefieldcreate">'.$langs->trans("ID").'</td><td colspan="3">';
  1911. print $object->ref;
  1912. print '</td></tr>';
  1913. }
  1914. // Name
  1915. print '<tr><td class="titlefieldcreate">'.$form->editfieldkey('ThirdPartyName', 'name', '', $object, 0, 'string', '', 1).'</td>';
  1916. print '<td colspan="3"><input type="text" class="minwidth300" maxlength="128" name="name" id="name" value="'.dol_escape_htmltag($object->name).'" autofocus="autofocus">';
  1917. print $form->widgetForTranslation("name", $object, $permissiontoadd, 'string', 'alpahnohtml', 'minwidth300');
  1918. print '</td></tr>';
  1919. // Alias names (commercial, trademark or alias names)
  1920. print '<tr id="name_alias"><td><label for="name_alias_input">'.$langs->trans('AliasNames').'</label></td>';
  1921. print '<td colspan="3"><input type="text" class="minwidth300" name="name_alias" id="name_alias_input" value="'.dol_escape_htmltag($object->name_alias).'"></td></tr>';
  1922. // Prefix
  1923. if (!empty($conf->global->SOCIETE_USEPREFIX)) { // Old not used prefix field
  1924. print '<tr><td>'.$form->editfieldkey('Prefix', 'prefix', '', $object, 0).'</td><td colspan="3">';
  1925. // It does not change the prefix mode using the auto numbering prefix
  1926. if (($prefixCustomerIsUsed || $prefixSupplierIsUsed) && $object->prefix_comm) {
  1927. print '<input type="hidden" name="prefix_comm" value="'.dol_escape_htmltag($object->prefix_comm).'">';
  1928. print $object->prefix_comm;
  1929. } else {
  1930. print '<input type="text" size="5" maxlength="5" name="prefix_comm" id="prefix" value="'.dol_escape_htmltag($object->prefix_comm).'">';
  1931. }
  1932. print '</td>';
  1933. }
  1934. // Prospect/Customer
  1935. print '<tr><td>'.$form->editfieldkey('ProspectCustomer', 'customerprospect', '', $object, 0, 'string', '', 1).'</td>';
  1936. print '<td class="maxwidthonsmartphone">';
  1937. print $formcompany->selectProspectCustomerType($object->client);
  1938. print '</td>';
  1939. if ($conf->browser->layout == 'phone') {
  1940. print '</tr><tr>';
  1941. }
  1942. print '<td>'.$form->editfieldkey('CustomerCode', 'customer_code', '', $object, 0).'</td><td>';
  1943. print '<table class="nobordernopadding"><tr><td>';
  1944. if ((!$object->code_client || $object->code_client == -1) && $modCodeClient->code_auto) {
  1945. $tmpcode = $object->code_client;
  1946. if (empty($tmpcode) && !empty($object->oldcopy->code_client)) {
  1947. $tmpcode = $object->oldcopy->code_client; // When there is an error to update a thirdparty, the number for supplier and customer code is kept to old value.
  1948. }
  1949. if (empty($tmpcode) && !empty($modCodeClient->code_auto)) {
  1950. $tmpcode = $modCodeClient->getNextValue($object, 0);
  1951. }
  1952. print '<input type="text" name="customer_code" id="customer_code" size="16" value="'.dol_escape_htmltag($tmpcode).'" maxlength="24">';
  1953. } elseif ($object->codeclient_modifiable()) {
  1954. print '<input type="text" name="customer_code" id="customer_code" size="16" value="'.dol_escape_htmltag($object->code_client).'" maxlength="24">';
  1955. } else {
  1956. print $object->code_client;
  1957. print '<input type="hidden" name="customer_code" value="'.dol_escape_htmltag($object->code_client).'">';
  1958. }
  1959. print '</td><td>';
  1960. $s = $modCodeClient->getToolTip($langs, $object, 0);
  1961. print $form->textwithpicto('', $s, 1);
  1962. print '</td></tr></table>';
  1963. print '</td></tr>';
  1964. // Supplier
  1965. if (((isModEnabled("fournisseur") && !empty($user->rights->fournisseur->lire) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || (isModEnabled("supplier_order") && !empty($user->rights->supplier_order->lire)) || (isModEnabled("supplier_invoice") && !empty($user->rights->supplier_invoice->lire)))
  1966. || (isModEnabled('supplier_proposal') && !empty($user->rights->supplier_proposal->lire))) {
  1967. print '<tr>';
  1968. print '<td>'.$form->editfieldkey('Supplier', 'fournisseur', '', $object, 0, 'string', '', 1).'</td>';
  1969. print '<td class="maxwidthonsmartphone">';
  1970. print $form->selectyesno("fournisseur", $object->fournisseur, 1, false, 0, 1);
  1971. print '</td>';
  1972. if ($conf->browser->layout == 'phone') {
  1973. print '</tr><tr>';
  1974. }
  1975. print '<td>';
  1976. if ((isModEnabled("fournisseur") && !empty($user->rights->fournisseur->lire) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || (isModEnabled("supplier_order") && !empty($user->rights->supplier_order->lire)) || (isModEnabled("supplier_invoice") && !empty($user->rights->supplier_invoice->lire))) {
  1977. print $form->editfieldkey('SupplierCode', 'supplier_code', '', $object, 0);
  1978. }
  1979. print '</td>';
  1980. print '<td>';
  1981. print '<table class="nobordernopadding"><tr><td>';
  1982. if ((!$object->code_fournisseur || $object->code_fournisseur == -1) && $modCodeFournisseur->code_auto) {
  1983. $tmpcode = $object->code_fournisseur;
  1984. if (empty($tmpcode) && !empty($object->oldcopy->code_fournisseur)) {
  1985. $tmpcode = $object->oldcopy->code_fournisseur; // When there is an error to update a thirdparty, the number for supplier and customer code is kept to old value.
  1986. }
  1987. if (empty($tmpcode) && !empty($modCodeFournisseur->code_auto)) {
  1988. $tmpcode = $modCodeFournisseur->getNextValue($object, 1);
  1989. }
  1990. print '<input type="text" name="supplier_code" id="supplier_code" size="16" value="'.dol_escape_htmltag($tmpcode).'" maxlength="24">';
  1991. } elseif ($object->codefournisseur_modifiable()) {
  1992. print '<input type="text" name="supplier_code" id="supplier_code" size="16" value="'.dol_escape_htmltag($object->code_fournisseur).'" maxlength="24">';
  1993. } else {
  1994. print $object->code_fournisseur;
  1995. print '<input type="hidden" name="supplier_code" value="'.$object->code_fournisseur.'">';
  1996. }
  1997. print '</td><td>';
  1998. $s = $modCodeFournisseur->getToolTip($langs, $object, 1);
  1999. print $form->textwithpicto('', $s, 1);
  2000. print '</td></tr></table>';
  2001. print '</td></tr>';
  2002. }
  2003. // Barcode
  2004. if (isModEnabled('barcode')) {
  2005. print '<tr><td class="tdtop">'.$form->editfieldkey('Gencod', 'barcode', '', $object, 0).'</td>';
  2006. print '<td colspan="3">';
  2007. print img_picto('', 'barcode');
  2008. print '<input type="text" name="barcode" id="barcode" value="'.dol_escape_htmltag($object->barcode).'">';
  2009. print '</td></tr>';
  2010. }
  2011. // Status
  2012. print '<tr><td>'.$form->editfieldkey('Status', 'status', '', $object, 0).'</td><td colspan="3">';
  2013. print $form->selectarray('status', array('0'=>$langs->trans('ActivityCeased'), '1'=>$langs->trans('InActivity')), $object->status, 0, 0, 0, '', 0, 0, 0, '', 'minwidth100', 1);
  2014. print '</td></tr>';
  2015. // Address
  2016. print '<tr><td class="tdtop">'.$form->editfieldkey('Address', 'address', '', $object, 0).'</td>';
  2017. print '<td colspan="3"><textarea name="address" id="address" class="quatrevingtpercent" rows="3" wrap="soft">';
  2018. print dol_escape_htmltag($object->address, 0, 1);
  2019. print '</textarea>';
  2020. print $form->widgetForTranslation("address", $object, $permissiontoadd, 'textarea', 'alphanohtml', 'quatrevingtpercent');
  2021. print '</td></tr>';
  2022. // Zip / Town
  2023. print '<tr><td>'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).'</td><td'.($conf->browser->layout == 'phone' ? ' colspan="3"': '').'>';
  2024. print $formcompany->select_ziptown($object->zip, 'zipcode', array('town', 'selectcountry_id', 'state_id'), 0, 0, '', 'maxwidth100');
  2025. print '</td>';
  2026. if ($conf->browser->layout == 'phone') {
  2027. print '</tr><tr>';
  2028. }
  2029. print '<td>'.$form->editfieldkey('Town', 'town', '', $object, 0).'</td><td'.($conf->browser->layout == 'phone' ? ' colspan="3"': '').'>';
  2030. print $formcompany->select_ziptown($object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id'));
  2031. print $form->widgetForTranslation("town", $object, $permissiontoadd, 'string', 'alphanohtml', 'maxwidth100 quatrevingtpercent');
  2032. print '</td></tr>';
  2033. // Country
  2034. print '<tr><td>'.$form->editfieldkey('Country', 'selectcounty_id', '', $object, 0).'</td><td colspan="3">';
  2035. print img_picto('', 'globe-americas', 'class="paddingrightonly"');
  2036. print $form->select_country((GETPOSTISSET('country_id') ? GETPOST('country_id') : $object->country_id), 'country_id', '', 0, 'minwidth300 maxwidth500 widthcentpercentminusx');
  2037. if ($user->admin) {
  2038. print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  2039. }
  2040. print '</td></tr>';
  2041. // State
  2042. if (empty($conf->global->SOCIETE_DISABLE_STATE)) {
  2043. if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && ($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 || $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 2)) {
  2044. print '<tr><td>'.$form->editfieldkey('Region-State', 'state_id', '', $object, 0).'</td><td colspan="3">';
  2045. } else {
  2046. print '<tr><td>'.$form->editfieldkey('State', 'state_id', '', $object, 0).'</td><td colspan="3">';
  2047. }
  2048. print img_picto('', 'state', 'class="pictofixedwidth"');
  2049. print $formcompany->select_state($object->state_id, $object->country_code);
  2050. print '</td></tr>';
  2051. }
  2052. // Phone / Fax
  2053. print '<tr><td>'.$form->editfieldkey('Phone', 'phone', GETPOST('phone', 'alpha'), $object, 0).'</td>';
  2054. print '<td'.($conf->browser->layout == 'phone' ? ' colspan="3"': '').'>'.img_picto('', 'object_phoning', 'class="pictofixedwidth"').' <input type="text" name="phone" id="phone" class="maxwidth200 widthcentpercentminusx" value="'.(GETPOSTISSET('phone') ? GETPOST('phone', 'alpha') : $object->phone).'"></td>';
  2055. if ($conf->browser->layout == 'phone') {
  2056. print '</tr><tr>';
  2057. }
  2058. print '<td>'.$form->editfieldkey('Fax', 'fax', GETPOST('fax', 'alpha'), $object, 0).'</td>';
  2059. print '<td'.($conf->browser->layout == 'phone' ? ' colspan="3"': '').'>'.img_picto('', 'object_phoning_fax', 'class="pictofixedwidth"').' <input type="text" name="fax" id="fax" class="maxwidth200 widthcentpercentminusx" value="'.(GETPOSTISSET('fax') ? GETPOST('fax', 'alpha') : $object->fax).'"></td>';
  2060. print '</tr>';
  2061. // Web
  2062. print '<tr><td>'.$form->editfieldkey('Web', 'url', GETPOST('url', 'alpha'), $object, 0).'</td>';
  2063. print '<td colspan="3">'.img_picto('', 'globe', 'class="pictofixedwidth"').' <input type="text" name="url" id="url" class="maxwidth200onsmartphone maxwidth300 widthcentpercentminusx " value="'.(GETPOSTISSET('url') ?GETPOST('url', 'alpha') : $object->url).'"></td></tr>';
  2064. // EMail
  2065. print '<tr><td>'.$form->editfieldkey('EMail', 'email', GETPOST('email', 'alpha'), $object, 0, 'string', '', (!empty($conf->global->SOCIETE_EMAIL_MANDATORY))).'</td>';
  2066. print '<td colspan="3">';
  2067. print img_picto('', 'object_email', 'class="pictofixedwidth"');
  2068. print '<input type="text" name="email" id="email" class="maxwidth500 widthcentpercentminusx" value="'.(GETPOSTISSET('email') ?GETPOST('email', 'alpha') : $object->email).'">';
  2069. print '</td></tr>';
  2070. // Unsubscribe
  2071. if (!empty($conf->mailing->enabled)) {
  2072. if ($conf->use_javascript_ajax && isset($conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS) && $conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS == 2) {
  2073. print "\n".'<script type="text/javascript">'."\n";
  2074. print '
  2075. jQuery(document).ready(function () {
  2076. function init_check_no_email(input) {
  2077. if (input.val()!="") {
  2078. $(".noemail").addClass("fieldrequired");
  2079. } else {
  2080. $(".noemail").removeClass("fieldrequired");
  2081. }
  2082. }
  2083. $("#email").keyup(function() {
  2084. init_check_no_email($(this));
  2085. });
  2086. init_check_no_email($("#email"));
  2087. })'."\n";
  2088. print '</script>'."\n";
  2089. }
  2090. if (!GETPOSTISSET("no_email") && !empty($object->email)) {
  2091. $result = $object->getNoEmail();
  2092. if ($result < 0) {
  2093. setEventMessages($object->error, $object->errors, 'errors');
  2094. }
  2095. }
  2096. print '<tr>';
  2097. print '<td class="noemail"><label for="no_email">'.$langs->trans("No_Email").'</label></td>';
  2098. print '<td>';
  2099. $useempty = (isset($conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS) && ($conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS == 2));
  2100. print $form->selectyesno('no_email', (GETPOSTISSET("no_email") ? GETPOST("no_email", 'int') : $object->no_email), 1, false, $useempty);
  2101. print '</td>';
  2102. print '</tr>';
  2103. }
  2104. // Social network
  2105. if (isModEnabled('socialnetworks')) {
  2106. foreach ($socialnetworks as $key => $value) {
  2107. if ($value['active']) {
  2108. print '<tr>';
  2109. print '<td><label for="'.$value['label'].'">'.$form->editfieldkey($value['label'], $key, '', $object, 0).'</label></td>';
  2110. print '<td colspan="3">';
  2111. if (!empty($value['icon'])) {
  2112. print '<span class="fa '.$value['icon'].' pictofixedwidth"></span>';
  2113. }
  2114. print '<input type="text" name="'.$key.'" id="'.$key.'" class="minwidth100 maxwidth500 widthcentpercentminusx" maxlength="80" value="'.(empty($object->socialnetworks[$key]) ? '' : $object->socialnetworks[$key]).'">';
  2115. print '</td>';
  2116. print '</tr>';
  2117. } elseif (!empty($object->socialnetworks[$key])) {
  2118. print '<input type="hidden" name="'.$key.'" value="'.$object->socialnetworks[$key].'">';
  2119. }
  2120. }
  2121. }
  2122. // Prof ids
  2123. $i = 1;
  2124. $j = 0;
  2125. $NBCOLS = ($conf->browser->layout == 'phone' ? 1 : 2);
  2126. while ($i <= 6) {
  2127. $idprof = $langs->transcountry('ProfId'.$i, $object->country_code);
  2128. if ($idprof != '-') {
  2129. $key = 'idprof'.$i;
  2130. if (($j % $NBCOLS) == 0) {
  2131. print '<tr>';
  2132. }
  2133. $idprof_mandatory = 'SOCIETE_IDPROF'.($i).'_MANDATORY';
  2134. print '<td>'.$form->editfieldkey($idprof, $key, '', $object, 0, 'string', '', !(empty($conf->global->$idprof_mandatory) || !$object->isACompany())).'</td><td>';
  2135. print $formcompany->get_input_id_prof($i, $key, $object->$key, $object->country_code);
  2136. print '</td>';
  2137. if (($j % $NBCOLS) == ($NBCOLS - 1)) {
  2138. print '</tr>';
  2139. }
  2140. $j++;
  2141. }
  2142. $i++;
  2143. }
  2144. if ($NBCOLS > 0 && $j % 2 == 1) {
  2145. print '<td colspan="2"></td></tr>';
  2146. }
  2147. // VAT is used
  2148. print '<tr><td>'.$form->editfieldkey('VATIsUsed', 'assujtva_value', '', $object, 0).'</td><td colspan="3">';
  2149. print $form->selectyesno('assujtva_value', $object->tva_assuj, 1);
  2150. print '</td></tr>';
  2151. // Local Taxes
  2152. //TODO: Place into a function to control showing by country or study better option
  2153. if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1") {
  2154. print '<tr><td>'.$form->editfieldkey($langs->transcountry("LocalTax1IsUsed", $mysoc->country_code), 'localtax1assuj_value', '', $object, 0).'</td><td>';
  2155. print $form->selectyesno('localtax1assuj_value', $object->localtax1_assuj, 1);
  2156. if (!isOnlyOneLocalTax(1)) {
  2157. print '<span class="cblt1"> '.$langs->transcountry("Type", $mysoc->country_code).': ';
  2158. $formcompany->select_localtax(1, $object->localtax1_value, "lt1");
  2159. print '</span>';
  2160. }
  2161. print '</td>';
  2162. print '</tr><tr>';
  2163. print '<td>'.$form->editfieldkey($langs->transcountry("LocalTax2IsUsed", $mysoc->country_code), 'localtax2assuj_value', '', $object, 0).'</td><td>';
  2164. print $form->selectyesno('localtax2assuj_value', $object->localtax2_assuj, 1);
  2165. if (!isOnlyOneLocalTax(2)) {
  2166. print '<span class="cblt2"> '.$langs->transcountry("Type", $mysoc->country_code).': ';
  2167. $formcompany->select_localtax(2, $object->localtax2_value, "lt2");
  2168. print '</span>';
  2169. }
  2170. print '</td></tr>';
  2171. } elseif ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj != "1") {
  2172. print '<tr><td>'.$form->editfieldkey($langs->transcountry("LocalTax1IsUsed", $mysoc->country_code), 'localtax1assuj_value', '', $object, 0).'</td><td colspan="3">';
  2173. print $form->selectyesno('localtax1assuj_value', $object->localtax1_assuj, 1);
  2174. if (!isOnlyOneLocalTax(1)) {
  2175. print '<span class="cblt1"> '.$langs->transcountry("Type", $mysoc->country_code).': ';
  2176. $formcompany->select_localtax(1, $object->localtax1_value, "lt1");
  2177. print '</span>';
  2178. }
  2179. print '</td></tr>';
  2180. } elseif ($mysoc->localtax2_assuj == "1" && $mysoc->localtax1_assuj != "1") {
  2181. print '<tr><td>'.$form->editfieldkey($langs->transcountry("LocalTax2IsUsed", $mysoc->country_code), 'localtax2assuj_value', '', $object, 0).'</td><td colspan="3">';
  2182. print $form->selectyesno('localtax2assuj_value', $object->localtax2_assuj, 1);
  2183. if (!isOnlyOneLocalTax(2)) {
  2184. print '<span class="cblt2"> '.$langs->transcountry("Type", $mysoc->country_code).': ';
  2185. $formcompany->select_localtax(2, $object->localtax2_value, "lt2");
  2186. print '</span>';
  2187. }
  2188. print '</td></tr>';
  2189. }
  2190. // VAT Code
  2191. print '<tr><td>'.$form->editfieldkey('VATIntra', 'intra_vat', '', $object, 0).'</td>';
  2192. print '<td colspan="3">';
  2193. $s = '<input type="text" class="flat maxwidthonsmartphone" name="tva_intra" id="intra_vat" maxlength="20" value="'.$object->tva_intra.'">';
  2194. if (empty($conf->global->MAIN_DISABLEVATCHECK) && isInEEC($object)) {
  2195. $s .= ' &nbsp; ';
  2196. if ($conf->use_javascript_ajax) {
  2197. $widthpopup = 600;
  2198. if (!empty($conf->dol_use_jmobile)) {
  2199. $widthpopup = 350;
  2200. }
  2201. $heightpopup = 400;
  2202. print "\n";
  2203. print '<script type="text/javascript">';
  2204. print "function CheckVAT(a) {\n";
  2205. print "newpopup('".DOL_URL_ROOT."/societe/checkvat/checkVatPopup.php?vatNumber='+a,'".dol_escape_js($langs->trans("VATIntraCheckableOnEUSite"))."', ".$widthpopup.", ".$heightpopup.");\n";
  2206. print "}\n";
  2207. print '</script>';
  2208. print "\n";
  2209. $s .= '<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>';
  2210. $s = $form->textwithpicto($s, $langs->trans("VATIntraCheckDesc", $langs->transnoentitiesnoconv("VATIntraCheck")), 1);
  2211. } else {
  2212. $s .= '<a href="'.$langs->transcountry("VATIntraCheckURL", $object->country_id).'" class="hideonsmartphone" target="_blank" rel="noopener noreferrer">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"), 'help').'</a>';
  2213. }
  2214. }
  2215. print $s;
  2216. print '</td>';
  2217. print '</tr>';
  2218. // Type - Workforce/Staff
  2219. print '<tr><td>'.$form->editfieldkey('ThirdPartyType', 'typent_id', '', $object, 0).'</td><td class="maxwidthonsmartphone"'.( ($conf->browser->layout == 'phone' || !empty($conf->global->SOCIETE_DISABLE_WORKFORCE)) ? ' colspan="3"' : '').'>';
  2220. print $form->selectarray("typent_id", $formcompany->typent_array(0), $object->typent_id, 1, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT), '', 1);
  2221. if ($user->admin) {
  2222. print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  2223. }
  2224. if (empty($conf->global->SOCIETE_DISABLE_WORKFORCE)) {
  2225. print '</td>';
  2226. if ($conf->browser->layout == 'phone') {
  2227. print '</tr><tr>';
  2228. }
  2229. print '<td>'.$form->editfieldkey('Workforce', 'effectif_id', '', $object, 0).'</td><td class="maxwidthonsmartphone">';
  2230. print $form->selectarray("effectif_id", $formcompany->effectif_array(0), $object->effectif_id, 0, 0, 0, '', 0, 0, 0, '', '', 1);
  2231. if ($user->admin) {
  2232. print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  2233. }
  2234. } else {
  2235. print '<input type="hidden" name="effectif_id" id="effectif_id" value="'.$object->effectif_id.'">';
  2236. }
  2237. print '</td></tr>';
  2238. // Juridical type
  2239. print '<tr><td>'.$form->editfieldkey('JuridicalStatus', 'forme_juridique_code', '', $object, 0).'</td><td class="maxwidthonsmartphone" colspan="3">';
  2240. print $formcompany->select_juridicalstatus($object->forme_juridique_code, $object->country_code, '', 'forme_juridique_code');
  2241. print '</td></tr>';
  2242. // Capital
  2243. print '<tr><td>'.$form->editfieldkey('Capital', 'capital', '', $object, 0).'</td>';
  2244. print '<td colspan="3"><input type="text" name="capital" id="capital" size="10" value="';
  2245. print $object->capital != '' ? dol_escape_htmltag(price($object->capital)) : '';
  2246. if (isModEnabled("multicurrency")) {
  2247. print '"> <span class="hideonsmartphone">'.$langs->trans("Currency".$object->multicurrency_code).'</span></td></tr>';
  2248. } else {
  2249. print '"> <span class="hideonsmartphone">'.$langs->trans("Currency".$conf->currency).'</span></td></tr>';
  2250. }
  2251. // Default language
  2252. if (getDolGlobalInt('MAIN_MULTILANGS')) {
  2253. print '<tr><td>'.$form->editfieldkey('DefaultLang', 'default_lang', '', $object, 0).'</td><td colspan="3">'."\n";
  2254. print img_picto('', 'language', 'class="pictofixedwidth"').$formadmin->select_language($object->default_lang, 'default_lang', 0, null, '1', 0, 0, 'maxwidth300 widthcentpercentminusx');
  2255. print '</td>';
  2256. print '</tr>';
  2257. }
  2258. // Incoterms
  2259. if (isModEnabled('incoterm')) {
  2260. print '<tr>';
  2261. print '<td>'.$form->editfieldkey('IncotermLabel', 'incoterm_id', '', $object, 0).'</td>';
  2262. print '<td colspan="3" class="maxwidthonsmartphone">';
  2263. print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''));
  2264. print '</td></tr>';
  2265. }
  2266. // Categories
  2267. if (isModEnabled('categorie') && !empty($user->rights->categorie->lire)) {
  2268. // Customer
  2269. print '<tr class="visibleifcustomer"><td>'.$form->editfieldkey('CustomersCategoriesShort', 'custcats', '', $object, 0).'</td>';
  2270. print '<td colspan="3">';
  2271. $cate_arbo = $form->select_all_categories(Categorie::TYPE_CUSTOMER, null, null, null, null, 1);
  2272. $c = new Categorie($db);
  2273. $cats = $c->containing($object->id, Categorie::TYPE_CUSTOMER);
  2274. $arrayselected = array();
  2275. foreach ($cats as $cat) {
  2276. $arrayselected[] = $cat->id;
  2277. }
  2278. print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('custcats', $cate_arbo, $arrayselected, 0, 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
  2279. print "</td></tr>";
  2280. // Supplier
  2281. if ((isModEnabled("fournisseur") && !empty($user->rights->fournisseur->lire) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || (isModEnabled("supplier_order") && !empty($user->rights->supplier_order->lire)) || (isModEnabled("supplier_invoice") && !empty($user->rights->supplier_invoice->lire))) {
  2282. print '<tr class="visibleifsupplier"><td>'.$form->editfieldkey('SuppliersCategoriesShort', 'suppcats', '', $object, 0).'</td>';
  2283. print '<td colspan="3">';
  2284. $cate_arbo = $form->select_all_categories(Categorie::TYPE_SUPPLIER, null, null, null, null, 1);
  2285. $c = new Categorie($db);
  2286. $cats = $c->containing($object->id, Categorie::TYPE_SUPPLIER);
  2287. $arrayselected = array();
  2288. foreach ($cats as $cat) {
  2289. $arrayselected[] = $cat->id;
  2290. }
  2291. print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('suppcats', $cate_arbo, $arrayselected, 0, 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
  2292. print "</td></tr>";
  2293. }
  2294. }
  2295. // Multicurrency
  2296. if (isModEnabled("multicurrency")) {
  2297. print '<tr>';
  2298. print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
  2299. print '<td colspan="3" class="maxwidthonsmartphone">';
  2300. print img_picto('', 'currency', 'class="pictofixedwidth"');
  2301. print $form->selectMultiCurrency((GETPOSTISSET('multicurrency_code') ? GETPOST('multicurrency_code') : ($object->multicurrency_code ? $object->multicurrency_code : $conf->currency)), 'multicurrency_code', 1, '', false, 'maxwidth150 widthcentpercentminusx');
  2302. print '</td></tr>';
  2303. }
  2304. // Other attributes
  2305. $parameters = array('socid'=>$socid, 'colspan' => ' colspan="3"', 'colspanvalue' => '3');
  2306. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
  2307. // Parent company
  2308. if (empty($conf->global->SOCIETE_DISABLE_PARENTCOMPANY)) {
  2309. print '<tr>';
  2310. print '<td>'.$langs->trans('ParentCompany').'</td>';
  2311. print '<td colspan="3" class="maxwidthonsmartphone">';
  2312. print img_picto('', 'company', 'class="pictofixedwidth"');
  2313. print $form->select_company(GETPOST('parent_company_id') ? GETPOST('parent_company_id') : $object->parent, 'parent_company_id', '', 'SelectThirdParty', 0, 0, null, 0, 'minwidth300 maxwidth500 widthcentpercentminusxx');
  2314. print '</td></tr>';
  2315. }
  2316. // Webservices url/key
  2317. if (!empty($conf->syncsupplierwebservices->enabled)) {
  2318. print '<tr><td>'.$form->editfieldkey('WebServiceURL', 'webservices_url', '', $object, 0).'</td>';
  2319. print '<td><input type="text" name="webservices_url" id="webservices_url" size="32" value="'.$object->webservices_url.'"></td>';
  2320. print '<td>'.$form->editfieldkey('WebServiceKey', 'webservices_key', '', $object, 0).'</td>';
  2321. print '<td><input type="text" name="webservices_key" id="webservices_key" size="32" value="'.$object->webservices_key.'"></td></tr>';
  2322. }
  2323. // Logo
  2324. print '<tr class="hideonsmartphone">';
  2325. print '<td>'.$form->editfieldkey('Logo', 'photoinput', '', $object, 0).'</td>';
  2326. print '<td colspan="3">';
  2327. if ($object->logo) {
  2328. print $form->showphoto('societe', $object);
  2329. }
  2330. $caneditfield = 1;
  2331. if ($caneditfield) {
  2332. if ($object->logo) {
  2333. print "<br>\n";
  2334. }
  2335. print '<table class="nobordernopadding">';
  2336. if ($object->logo) {
  2337. print '<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> '.$langs->trans("Delete").'<br><br></td></tr>';
  2338. }
  2339. //print '<tr><td>'.$langs->trans("PhotoFile").'</td></tr>';
  2340. print '<tr><td>';
  2341. $maxfilesizearray = getMaxFileSizeArray();
  2342. $maxmin = $maxfilesizearray['maxmin'];
  2343. if ($maxmin > 0) {
  2344. print '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
  2345. }
  2346. print '<input type="file" class="flat" name="photo" id="photoinput">';
  2347. print '</td></tr>';
  2348. print '</table>';
  2349. }
  2350. print '</td>';
  2351. print '</tr>';
  2352. // Assign sale representative
  2353. print '<tr>';
  2354. print '<td>'.$form->editfieldkey('AllocateCommercial', 'commercial_id', '', $object, 0).'</td>';
  2355. print '<td colspan="3" class="maxwidthonsmartphone">';
  2356. $userlist = $form->select_dolusers('', '', 0, null, 0, '', '', 0, 0, 0, 'AND u.statut = 1', 0, '', '', 0, 1);
  2357. $arrayselected = GETPOST('commercial', 'array');
  2358. if (empty($arrayselected)) {
  2359. $arrayselected = $object->getSalesRepresentatives($user, 1);
  2360. }
  2361. print img_picto('', 'user', 'class="pictofixedwidth"').$form->multiselectarray('commercial', $userlist, $arrayselected, 0, 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0, '', '', '', 1);
  2362. print '</td></tr>';
  2363. print '</table>';
  2364. if (!empty($conf->global->ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY)) {
  2365. print '<br>';
  2366. print '<table class="border centpercent">';
  2367. if (isModEnabled('accounting')) {
  2368. // Accountancy_code_sell
  2369. print '<tr><td class="titlefield">'.$langs->trans("ProductAccountancySellCode").'</td>';
  2370. print '<td>';
  2371. print $formaccounting->select_account($object->accountancy_code_sell, 'accountancy_code_sell', 1, '', 1, 1);
  2372. print '</td></tr>';
  2373. // Accountancy_code_buy
  2374. print '<tr><td>'.$langs->trans("ProductAccountancyBuyCode").'</td>';
  2375. print '<td>';
  2376. print $formaccounting->select_account($object->accountancy_code_buy, 'accountancy_code_buy', 1, '', 1, 1);
  2377. print '</td></tr>';
  2378. } else { // For external software
  2379. // Accountancy_code_sell
  2380. print '<tr><td class="titlefield">'.$langs->trans("ProductAccountancySellCode").'</td>';
  2381. print '<td><input name="accountancy_code_sell" class="maxwidth200" value="'.$object->accountancy_code_sell.'">';
  2382. print '</td></tr>';
  2383. // Accountancy_code_buy
  2384. print '<tr><td>'.$langs->trans("ProductAccountancyBuyCode").'</td>';
  2385. print '<td><input name="accountancy_code_buy" class="maxwidth200" value="'.$object->accountancy_code_buy.'">';
  2386. print '</td></tr>';
  2387. }
  2388. print '</table>';
  2389. }
  2390. print '</div>';
  2391. print dol_get_fiche_end();
  2392. print $form->buttonsSaveCancel();
  2393. print '</form>';
  2394. }
  2395. } else {
  2396. /*
  2397. * View
  2398. */
  2399. if (!empty($object->id)) {
  2400. $res = $object->fetch_optionals();
  2401. }
  2402. //if ($res < 0) { dol_print_error($db); exit; }
  2403. $head = societe_prepare_head($object);
  2404. print dol_get_fiche_head($head, 'card', $langs->trans("ThirdParty"), -1, 'company');
  2405. $formconfirm = '';
  2406. // Confirm delete third party
  2407. if ($action == 'delete' || ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile))) {
  2408. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id, $langs->trans("DeleteACompany"), $langs->trans("ConfirmDeleteCompany"), "confirm_delete", '', 0, "action-delete");
  2409. }
  2410. if ($action == 'merge') {
  2411. $formquestion = array(
  2412. array(
  2413. 'name' => 'soc_origin',
  2414. 'label' => $langs->trans('MergeOriginThirdparty'),
  2415. 'type' => 'other',
  2416. 'value' => $form->select_company('', 'soc_origin', '', 'SelectThirdParty', 0, 0, array(), 0, 'minwidth200', '', '', 1, null, false, array($object->id))
  2417. )
  2418. );
  2419. $formconfirm .= $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id, $langs->trans("MergeThirdparties"), $langs->trans("ConfirmMergeThirdparties"), "confirm_merge", $formquestion, 'no', 1, 250);
  2420. }
  2421. // Call Hook formConfirm
  2422. $parameters = array('formConfirm' => $formconfirm);
  2423. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  2424. if (empty($reshook)) {
  2425. $formconfirm .= $hookmanager->resPrint;
  2426. } elseif ($reshook > 0) {
  2427. $formconfirm = $hookmanager->resPrint;
  2428. }
  2429. // Print form confirm
  2430. print $formconfirm;
  2431. dol_htmloutput_mesg(is_numeric($error) ? '' : $error, $errors, 'error');
  2432. $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  2433. dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
  2434. print '<div class="fichecenter">';
  2435. print '<div class="fichehalfleft">';
  2436. print '<div class="underbanner clearboth"></div>';
  2437. print '<table class="border tableforfield centpercent">';
  2438. // Type Prospect/Customer/Supplier
  2439. print '<tr><td class="titlefield">'.$langs->trans('NatureOfThirdParty').'</td><td>';
  2440. print $object->getTypeUrl(1);
  2441. print '</td></tr>';
  2442. // Prefix
  2443. if (!empty($conf->global->SOCIETE_USEPREFIX)) { // Old not used prefix field
  2444. print '<tr><td>'.$langs->trans('Prefix').'</td><td>'.dol_escape_htmltag($object->prefix_comm).'</td>';
  2445. print '</tr>';
  2446. }
  2447. // Customer code
  2448. if ($object->client) {
  2449. print '<tr><td>';
  2450. print $langs->trans('CustomerCode');
  2451. print '</td>';
  2452. print '<td>';
  2453. print showValueWithClipboardCPButton(dol_escape_htmltag($object->code_client));
  2454. $tmpcheck = $object->check_codeclient();
  2455. if ($tmpcheck != 0 && $tmpcheck != -5) {
  2456. print ' <span class="error">('.$langs->trans("WrongCustomerCode").')</span>';
  2457. }
  2458. print '</td>';
  2459. print '</tr>';
  2460. }
  2461. // Supplier code
  2462. if (((isModEnabled("fournisseur") && !empty($user->rights->fournisseur->lire) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || (isModEnabled("supplier_order") && !empty($user->rights->supplier_order->lire)) || (isModEnabled("supplier_invoice") && !empty($user->rights->supplier_invoice->lire))) && $object->fournisseur) {
  2463. print '<tr><td>';
  2464. print $langs->trans('SupplierCode').'</td><td>';
  2465. print showValueWithClipboardCPButton(dol_escape_htmltag($object->code_fournisseur));
  2466. $tmpcheck = $object->check_codefournisseur();
  2467. if ($tmpcheck != 0 && $tmpcheck != -5) {
  2468. print ' <span class="error">('.$langs->trans("WrongSupplierCode").')</span>';
  2469. }
  2470. print '</td>';
  2471. print '</tr>';
  2472. }
  2473. // Barcode
  2474. if (isModEnabled('barcode')) {
  2475. print '<tr><td>';
  2476. print $langs->trans('Gencod').'</td><td>'.showValueWithClipboardCPButton(dol_escape_htmltag($object->barcode));
  2477. print '</td>';
  2478. print '</tr>';
  2479. }
  2480. // Prof ids
  2481. $i = 1; $j = 0;
  2482. while ($i <= 6) {
  2483. $idprof = $langs->transcountry('ProfId'.$i, $object->country_code);
  2484. if ($idprof != '-') {
  2485. //if (($j % 2) == 0) print '<tr>';
  2486. print '<tr>';
  2487. print '<td>'.$idprof.'</td><td>';
  2488. $key = 'idprof'.$i;
  2489. print dol_print_profids($object->$key, 'ProfId'.$i, $object->country_code, 1);
  2490. if ($object->$key) {
  2491. if ($object->id_prof_check($i, $object) > 0) {
  2492. if (!empty($object->id_prof_url($i, $object))) {
  2493. print ' &nbsp; '.$object->id_prof_url($i, $object);
  2494. }
  2495. } else {
  2496. print ' <span class="error">('.$langs->trans("ErrorWrongValue").')</span>';
  2497. }
  2498. }
  2499. print '</td>';
  2500. //if (($j % 2) == 1) print '</tr>';
  2501. print '</tr>';
  2502. $j++;
  2503. }
  2504. $i++;
  2505. }
  2506. //if ($j % 2 == 1) print '<td colspan="2"></td></tr>';
  2507. // This fields are used to know VAT to include in an invoice when the thirdparty is making a sale, so when it is a supplier.
  2508. // We don't need them into customer profile.
  2509. // Except for spain and localtax where localtax depends on buyer and not seller
  2510. if ($object->fournisseur) {
  2511. // VAT is used
  2512. print '<tr><td>';
  2513. print $form->textwithpicto($langs->trans('VATIsUsed'), $langs->trans('VATIsUsedWhenSelling'));
  2514. print '</td><td>';
  2515. print yn($object->tva_assuj);
  2516. print '</td>';
  2517. print '</tr>';
  2518. }
  2519. // Local Taxes
  2520. if ($object->fournisseur || $mysoc->country_code == 'ES') {
  2521. if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1") {
  2522. print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>';
  2523. print yn($object->localtax1_assuj);
  2524. print '</td></tr><tr><td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>';
  2525. print yn($object->localtax2_assuj);
  2526. print '</td></tr>';
  2527. if ($object->localtax1_assuj == "1" && (!isOnlyOneLocalTax(1))) {
  2528. print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
  2529. print '<input type="hidden" name="action" value="set_localtax1">';
  2530. print '<input type="hidden" name="token" value="'.newToken().'">';
  2531. print '<tr><td>'.$langs->transcountry("Localtax1", $mysoc->country_code).' <a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editRE&token='.newToken().'&socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</td>';
  2532. if ($action == 'editRE') {
  2533. print '<td class="left">';
  2534. $formcompany->select_localtax(1, $object->localtax1_value, "lt1");
  2535. print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'"></td>';
  2536. } else {
  2537. print '<td>'.$object->localtax1_value.'</td>';
  2538. }
  2539. print '</tr></form>';
  2540. }
  2541. if ($object->localtax2_assuj == "1" && (!isOnlyOneLocalTax(2))) {
  2542. print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
  2543. print '<input type="hidden" name="action" value="set_localtax2">';
  2544. print '<input type="hidden" name="token" value="'.newToken().'">';
  2545. print '<tr><td>'.$langs->transcountry("Localtax2", $mysoc->country_code).'<a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editIRPF&token='.newToken().'&socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</td>';
  2546. if ($action == 'editIRPF') {
  2547. print '<td class="left">';
  2548. $formcompany->select_localtax(2, $object->localtax2_value, "lt2");
  2549. print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'"></td>';
  2550. } else {
  2551. print '<td>'.$object->localtax2_value.'</td>';
  2552. }
  2553. print '</tr></form>';
  2554. }
  2555. } elseif ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj != "1") {
  2556. print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>';
  2557. print yn($object->localtax1_assuj);
  2558. print '</td></tr>';
  2559. if ($object->localtax1_assuj == "1" && (!isOnlyOneLocalTax(1))) {
  2560. print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
  2561. print '<input type="hidden" name="action" value="set_localtax1">';
  2562. print '<input type="hidden" name="token" value="'.newToken().'">';
  2563. print '<tr><td> '.$langs->transcountry("Localtax1", $mysoc->country_code).'<a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editRE&token='.newToken().'&socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</td>';
  2564. if ($action == 'editRE') {
  2565. print '<td class="left">';
  2566. $formcompany->select_localtax(1, $object->localtax1_value, "lt1");
  2567. print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'"></td>';
  2568. } else {
  2569. print '<td>'.$object->localtax1_value.'</td>';
  2570. }
  2571. print '</tr></form>';
  2572. }
  2573. } elseif ($mysoc->localtax2_assuj == "1" && $mysoc->localtax1_assuj != "1") {
  2574. print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>';
  2575. print yn($object->localtax2_assuj);
  2576. print '</td></tr>';
  2577. if ($object->localtax2_assuj == "1" && (!isOnlyOneLocalTax(2))) {
  2578. print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
  2579. print '<input type="hidden" name="action" value="set_localtax2">';
  2580. print '<input type="hidden" name="token" value="'.newToken().'">';
  2581. print '<tr><td> '.$langs->transcountry("Localtax2", $mysoc->country_code).' <a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editIRPF&token='.newToken().'&socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</td>';
  2582. if ($action == 'editIRPF') {
  2583. print '<td class="left">';
  2584. $formcompany->select_localtax(2, $object->localtax2_value, "lt2");
  2585. print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'"></td>';
  2586. } else {
  2587. print '<td>'.$object->localtax2_value.'</td>';
  2588. }
  2589. print '</tr></form>';
  2590. }
  2591. }
  2592. }
  2593. // Sale tax code (VAT code)
  2594. print '<tr>';
  2595. print '<td class="nowrap">'.$langs->trans('VATIntra').'</td><td>';
  2596. if ($object->tva_intra) {
  2597. $s = '';
  2598. $s .= dol_print_profids($object->tva_intra, 'VAT', $object->country_code, 1);
  2599. $s .= '<input type="hidden" id="tva_intra" name="tva_intra" maxlength="20" value="'.$object->tva_intra.'">';
  2600. if (empty($conf->global->MAIN_DISABLEVATCHECK) && isInEEC($object)) {
  2601. $s .= ' &nbsp; ';
  2602. if ($conf->use_javascript_ajax) {
  2603. $widthpopup = 600;
  2604. if (!empty($conf->dol_use_jmobile)) {
  2605. $widthpopup = 350;
  2606. }
  2607. $heightpopup = 400;
  2608. print "\n";
  2609. print '<script type="text/javascript">';
  2610. print "function CheckVAT(a) {\n";
  2611. print "newpopup('".DOL_URL_ROOT."/societe/checkvat/checkVatPopup.php?vatNumber='+a, '".dol_escape_js($langs->trans("VATIntraCheckableOnEUSite"))."', ".$widthpopup.", ".$heightpopup.");\n";
  2612. print "}\n";
  2613. print '</script>';
  2614. print "\n";
  2615. $s .= '<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT( $(\'#tva_intra\').val() );">'.$langs->trans("VATIntraCheck").'</a>';
  2616. $s = $form->textwithpicto($s, $langs->trans("VATIntraCheckDesc", $langs->transnoentitiesnoconv("VATIntraCheck")), 1);
  2617. } else {
  2618. $s .= '<a href="'.$langs->transcountry("VATIntraCheckURL", $object->country_id).'" class="hideonsmartphone" target="_blank" rel="noopener noreferrer">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"), 'help').'</a>';
  2619. }
  2620. }
  2621. print $s;
  2622. } else {
  2623. print '&nbsp;';
  2624. }
  2625. print '</td></tr>';
  2626. // Warehouse
  2627. if (isModEnabled('stock') && !empty($conf->global->SOCIETE_ASK_FOR_WAREHOUSE)) {
  2628. $langs->load('stocks');
  2629. require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
  2630. $formproduct = new FormProduct($db);
  2631. print '<tr class="nowrap">';
  2632. print '<td>';
  2633. print $form->editfieldkey("Warehouse", 'warehouse', '', $object, $user->rights->societe->creer);
  2634. print '</td><td>';
  2635. if ($action == 'editwarehouse') {
  2636. $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_warehouse, 'fk_warehouse', 1);
  2637. } else {
  2638. if ($object->fk_warehouse > 0) {
  2639. print img_picto('', 'stock', 'class="paddingrightonly"');
  2640. }
  2641. $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_warehouse, 'none');
  2642. }
  2643. print '</td>';
  2644. print '</tr>';
  2645. }
  2646. print '</table>';
  2647. print '</div>';
  2648. print '<div class="fichehalfright">';
  2649. print '<div class="underbanner clearboth"></div>';
  2650. print '<table class="border tableforfield centpercent">';
  2651. // Tags / categories
  2652. if (isModEnabled('categorie') && !empty($user->rights->categorie->lire)) {
  2653. // Customer
  2654. if ($object->prospect || $object->client || !empty($conf->global->THIRDPARTY_CAN_HAVE_CUSTOMER_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT)) {
  2655. print '<tr><td>'.$langs->trans("CustomersCategoriesShort").'</td>';
  2656. print '<td>';
  2657. print $form->showCategories($object->id, Categorie::TYPE_CUSTOMER, 1);
  2658. print "</td></tr>";
  2659. }
  2660. // Supplier
  2661. if (((isModEnabled("fournisseur") && !empty($user->rights->fournisseur->lire) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || (isModEnabled("supplier_order") && !empty($user->rights->supplier_order->lire)) || (isModEnabled("supplier_invoice") && !empty($user->rights->supplier_invoice->lire))) && $object->fournisseur) {
  2662. print '<tr><td>'.$langs->trans("SuppliersCategoriesShort").'</td>';
  2663. print '<td>';
  2664. print $form->showCategories($object->id, Categorie::TYPE_SUPPLIER, 1);
  2665. print "</td></tr>";
  2666. }
  2667. }
  2668. // Third-Party Type
  2669. print '<tr><td>';
  2670. print '<table class="nobordernopadding" width="100%"><tr><td>'.$langs->trans('ThirdPartyType').'</td>';
  2671. if ($action != 'editthirdpartytype' && $user->hasRight('societe', 'creer')) {
  2672. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editthirdpartytype&token='.newToken().'&socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</a></td>';
  2673. }
  2674. print '</tr></table>';
  2675. print '</td><td>';
  2676. $html_name = ($action == 'editthirdpartytype') ? 'typent_id' : 'none';
  2677. $formcompany->formThirdpartyType($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->typent_id, $html_name, '');
  2678. print '</td></tr>';
  2679. // Workforce/Staff
  2680. if (empty($conf->global->SOCIETE_DISABLE_WORKFORCE)) {
  2681. print '<tr><td>'.$langs->trans("Workforce").'</td><td>'.$object->effectif.'</td></tr>';
  2682. }
  2683. // Legal
  2684. print '<tr><td class="titlefield">'.$langs->trans('JuridicalStatus').'</td><td>'.$object->forme_juridique.'</td></tr>';
  2685. // Capital
  2686. print '<tr><td>'.$langs->trans('Capital').'</td><td>';
  2687. if ($object->capital) {
  2688. if (isModEnabled("multicurrency") && !empty($object->multicurrency_code)) {
  2689. print price($object->capital, '', $langs, 0, -1, -1, $object->multicurrency_code);
  2690. } else {
  2691. print price($object->capital, '', $langs, 0, -1, -1, $conf->currency);
  2692. }
  2693. } else {
  2694. print '&nbsp;';
  2695. }
  2696. print '</td></tr>';
  2697. // Unsubscribe opt-out
  2698. if (!empty($conf->mailing->enabled)) {
  2699. $result = $object->getNoEmail();
  2700. if ($result < 0) {
  2701. setEventMessages($object->error, $object->errors, 'errors');
  2702. }
  2703. print '<tr><td>'.$langs->trans("No_Email").'</td><td>';
  2704. if ($object->email) {
  2705. print yn($object->no_email);
  2706. } else {
  2707. print '<span class="opacitymedium">'.$langs->trans("EMailNotDefined").'</span>';
  2708. }
  2709. $langs->load("mails");
  2710. print ' &nbsp; <span class="badge badge-secondary" title="'.dol_escape_htmltag($langs->trans("NbOfEMailingsSend")).'">'.$object->getNbOfEMailings().'</span>';
  2711. print '</td></tr>';
  2712. }
  2713. // Default language
  2714. if (getDolGlobalInt('MAIN_MULTILANGS')) {
  2715. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  2716. print '<tr><td>'.$langs->trans("DefaultLang").'</td><td>';
  2717. //$s=picto_from_langcode($object->default_lang);
  2718. //print ($s?$s.' ':'');
  2719. $langs->load("languages");
  2720. $labellang = ($object->default_lang ? $langs->trans('Language_'.$object->default_lang) : '');
  2721. print picto_from_langcode($object->default_lang, 'class="paddingrightonly saturatemedium opacitylow"');
  2722. print $labellang;
  2723. print '</td></tr>';
  2724. }
  2725. // Incoterms
  2726. if (isModEnabled('incoterm')) {
  2727. print '<tr><td>';
  2728. print '<table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans('IncotermLabel').'</td>';
  2729. if ($action != 'editincoterm' && $user->hasRight('societe', 'creer')) {
  2730. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&action=editincoterm&token='.newToken().'">'.img_edit('', 1).'</a></td>';
  2731. }
  2732. print '</tr></table>';
  2733. print '</td><td colspan="3">';
  2734. if ($action != 'editincoterm') {
  2735. print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
  2736. } else {
  2737. print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?socid='.$object->id);
  2738. }
  2739. print '</td></tr>';
  2740. }
  2741. // Multicurrency
  2742. if (isModEnabled("multicurrency")) {
  2743. print '<tr>';
  2744. print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
  2745. print '<td>';
  2746. print !empty($object->multicurrency_code) ? currency_name($object->multicurrency_code, 1) : '';
  2747. print '</td></tr>';
  2748. }
  2749. if (!empty($conf->global->ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY)) {
  2750. // Accountancy sell code
  2751. print '<tr><td class="nowrap">';
  2752. print $langs->trans("ProductAccountancySellCode");
  2753. print '</td><td colspan="2">';
  2754. if (isModEnabled('accounting')) {
  2755. if (!empty($object->accountancy_code_sell)) {
  2756. $accountingaccount = new AccountingAccount($db);
  2757. $accountingaccount->fetch('', $object->accountancy_code_sell, 1);
  2758. print $accountingaccount->getNomUrl(0, 1, 1, '', 1);
  2759. }
  2760. } else {
  2761. print $object->accountancy_code_sell;
  2762. }
  2763. print '</td></tr>';
  2764. // Accountancy buy code
  2765. print '<tr><td class="nowrap">';
  2766. print $langs->trans("ProductAccountancyBuyCode");
  2767. print '</td><td colspan="2">';
  2768. if (isModEnabled('accounting')) {
  2769. if (!empty($object->accountancy_code_buy)) {
  2770. $accountingaccount2 = new AccountingAccount($db);
  2771. $accountingaccount2->fetch('', $object->accountancy_code_buy, 1);
  2772. print $accountingaccount2->getNomUrl(0, 1, 1, '', 1);
  2773. }
  2774. } else {
  2775. print $object->accountancy_code_buy;
  2776. }
  2777. print '</td></tr>';
  2778. }
  2779. // Other attributes
  2780. $parameters = array('socid'=>$socid, 'colspan' => ' colspan="3"', 'colspanvalue' => '3');
  2781. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  2782. // Parent company
  2783. if (empty($conf->global->SOCIETE_DISABLE_PARENTCOMPANY)) {
  2784. print '<tr><td>';
  2785. print '<table class="nobordernopadding" width="100%"><tr><td>'.$langs->trans('ParentCompany').'</td>';
  2786. if ($action != 'editparentcompany' && $user->hasRight('societe', 'creer')) {
  2787. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editparentcompany&token='.newToken().'&socid='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</a></td>';
  2788. }
  2789. print '</tr></table>';
  2790. print '</td><td>';
  2791. $html_name = ($action == 'editparentcompany') ? 'parent_id' : 'none';
  2792. $form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->parent, $html_name, '', 1, 0, 0, null, 0, array($object->id));
  2793. print '</td></tr>';
  2794. }
  2795. // Sales representative
  2796. include DOL_DOCUMENT_ROOT.'/societe/tpl/linesalesrepresentative.tpl.php';
  2797. // Module Adherent
  2798. if (isModEnabled('adherent')) {
  2799. $langs->load("members");
  2800. print '<tr><td>'.$langs->trans("LinkedToDolibarrMember").'</td>';
  2801. print '<td>';
  2802. $adh = new Adherent($db);
  2803. $result = $adh->fetch('', '', $object->id);
  2804. if ($result > 0) {
  2805. $adh->ref = $adh->getFullName($langs);
  2806. print $adh->getNomUrl(-1);
  2807. } else {
  2808. print '<span class="opacitymedium">'.$langs->trans("ThirdpartyNotLinkedToMember").'</span>';
  2809. }
  2810. print "</td></tr>\n";
  2811. }
  2812. // Link user (you must create a contact to get a user)
  2813. /*
  2814. print '<tr><td>'.$langs->trans("DolibarrLogin").'</td><td colspan="3">';
  2815. if ($object->user_id) {
  2816. $dolibarr_user = new User($db);
  2817. $result = $dolibarr_user->fetch($object->user_id);
  2818. print $dolibarr_user->getLoginUrl(-1);
  2819. } else {
  2820. //print '<span class="opacitymedium">'.$langs->trans("NoDolibarrAccess").'</span>';
  2821. if (!$object->user_id && $user->rights->user->user->creer) {
  2822. print '<a class="aaa" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=create_user&token='.newToken().'">'.img_picto($langs->trans("CreateDolibarrLogin"), 'add').' '.$langs->trans("CreateDolibarrLogin").'</a>';
  2823. }
  2824. }
  2825. print '</td></tr>';
  2826. */
  2827. // Webservices url/key
  2828. if (!empty($conf->syncsupplierwebservices->enabled)) {
  2829. print '<tr><td>'.$langs->trans("WebServiceURL").'</td><td>'.dol_print_url($object->webservices_url).'</td>';
  2830. print '<td class="nowrap">'.$langs->trans('WebServiceKey').'</td><td>'.$object->webservices_key.'</td></tr>';
  2831. }
  2832. print '</table>';
  2833. print '</div>';
  2834. print '</div>';
  2835. print '<div style="clear:both"></div>';
  2836. print dol_get_fiche_end();
  2837. /*
  2838. * Actions
  2839. */
  2840. if ($action != 'presend') {
  2841. print '<div class="tabsAction">'."\n";
  2842. $parameters = array();
  2843. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  2844. if (empty($reshook)) {
  2845. $at_least_one_email_contact = false;
  2846. $TContact = $object->contact_array_objects();
  2847. foreach ($TContact as &$contact) {
  2848. if (!empty($contact->email)) {
  2849. $at_least_one_email_contact = true;
  2850. break;
  2851. }
  2852. }
  2853. if (empty($user->socid)) {
  2854. $langs->load("mails");
  2855. $title = '';
  2856. if (empty($object->email) && !$at_least_one_email_contact) { $title = $langs->trans('NoEMail'); }
  2857. print dolGetButtonAction($title, $langs->trans('SendMail'), 'default', $_SERVER['PHP_SELF'].'?socid='.$object->id.'&action=presend&mode=init#formmailbeforetitle', 'btn-send-mail', !empty($object->email) || $at_least_one_email_contact);
  2858. }
  2859. print dolGetButtonAction('', $langs->trans('Modify'), 'default', $_SERVER["PHP_SELF"].'?socid='.$object->id.'&action=edit&token='.newToken(), '', $permissiontoadd);
  2860. if (isModEnabled('adherent')) {
  2861. $adh = new Adherent($db);
  2862. $result = $adh->fetch('', '', $object->id);
  2863. if ($result == 0 && ($object->client == 1 || $object->client == 3) && !empty($conf->global->MEMBER_CAN_CONVERT_CUSTOMERS_TO_MEMBERS)) {
  2864. print '<a class="butAction" href="'.DOL_URL_ROOT.'/adherents/card.php?&action=create&socid='.$object->id.'" title="'.dol_escape_htmltag($langs->trans("NewMember")).'">'.$langs->trans("NewMember").'</a>'."\n";
  2865. }
  2866. }
  2867. print dolGetButtonAction($langs->trans('MergeThirdparties'), $langs->trans('Merge'), 'danger', $_SERVER["PHP_SELF"].'?socid='.$object->id.'&action=merge&token='.newToken(), '', $permissiontodelete);
  2868. if ($user->hasRight('societe', 'supprimer')) {
  2869. $deleteUrl = $_SERVER["PHP_SELF"].'?socid='.$object->id.'&action=delete&token='.newToken();
  2870. $buttonId = 'action-delete-no-ajax';
  2871. if ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile)) { // We can't use preloaded confirm form with jmobile
  2872. $deleteUrl = '';
  2873. $buttonId = 'action-delete';
  2874. }
  2875. print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $deleteUrl, $buttonId, $permissiontodelete);
  2876. }
  2877. }
  2878. print '</div>'."\n";
  2879. }
  2880. //Select mail models is same action as presend
  2881. if (GETPOST('modelselected')) {
  2882. $action = 'presend';
  2883. }
  2884. if ($action != 'presend') {
  2885. print '<div class="fichecenter"><div class="fichehalfleft">';
  2886. if (empty($conf->global->SOCIETE_DISABLE_BUILDDOC)) {
  2887. print '<a name="builddoc"></a>'; // ancre
  2888. /*
  2889. * Generated documents
  2890. */
  2891. $filedir = $conf->societe->multidir_output[$object->entity].'/'.$object->id;
  2892. $urlsource = $_SERVER["PHP_SELF"]."?socid=".$object->id;
  2893. $genallowed = $user->hasRight('societe', 'lire');
  2894. $delallowed = $user->hasRight('societe', 'creer');
  2895. print $formfile->showdocuments('company', $object->id, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 0, 0, 0, 28, 0, 'entity='.$object->entity, 0, '', $object->default_lang);
  2896. }
  2897. // Subsidiaries list
  2898. if (empty($conf->global->SOCIETE_DISABLE_PARENTCOMPANY) && empty($conf->global->SOCIETE_DISABLE_SHOW_SUBSIDIARIES)) {
  2899. $result = show_subsidiaries($conf, $langs, $db, $object);
  2900. }
  2901. print '</div><div class="fichehalfright">';
  2902. $MAXEVENT = 10;
  2903. $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id);
  2904. // List of actions on element
  2905. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  2906. $formactions = new FormActions($db);
  2907. $somethingshown = $formactions->showactions($object, '', $socid, 1, '', $MAXEVENT, '', $morehtmlcenter); // Show all action for thirdparty
  2908. print '</div></div>';
  2909. if (!empty($conf->global->MAIN_DUPLICATE_CONTACTS_TAB_ON_MAIN_CARD)) {
  2910. // Contacts list
  2911. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
  2912. $result = show_contacts($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id);
  2913. }
  2914. // Addresses list
  2915. if (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT)) {
  2916. $result = show_addresses($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id);
  2917. }
  2918. }
  2919. }
  2920. // Presend form
  2921. $modelmail = 'thirdparty';
  2922. $defaulttopic = 'Information';
  2923. $diroutput = $conf->societe->multidir_output[$object->entity];
  2924. $trackid = 'thi'.$object->id;
  2925. include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
  2926. }
  2927. }
  2928. // End of page
  2929. llxFooter();
  2930. $db->close();