card.php 142 KB

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