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