card.php 142 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335
  1. <?php
  2. /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2003 Brian Fraval <brian@fraval.org>
  4. * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
  6. * Copyright (C) 2005-2017 Regis Houssin <regis.houssin@inodbox.com>
  7. * Copyright (C) 2008 Patrick Raguin <patrick.raguin@auguria.net>
  8. * Copyright (C) 2010-2020 Juanjo Menent <jmenent@2byte.es>
  9. * Copyright (C) 2011-2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
  10. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  11. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  12. * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  13. * Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
  14. * Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es.com>
  15. * Copyright (C) 2018-2022 Frédéric France <frederic.france@netlogic.fr>
  16. *
  17. * This program is free software; you can redistribute it and/or modify
  18. * it under the terms of the GNU General Public License as published by
  19. * the Free Software Foundation; either version 3 of the License, or
  20. * (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License
  28. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  29. */
  30. /**
  31. * \file htdocs/societe/card.php
  32. * \ingroup societe
  33. * \brief Third party card page
  34. */
  35. // Load Dolibarr environment
  36. require '../main.inc.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  40. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
  41. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  42. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  43. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  44. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  45. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  46. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  47. if (isModEnabled('adherent')) {
  48. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  49. }
  50. if (isModEnabled('accounting')) {
  51. require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
  52. }
  53. if (isModEnabled('accounting')) {
  54. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
  55. }
  56. if (isModEnabled('accounting')) {
  57. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
  58. }
  59. if (isModEnabled('eventorganization')) {
  60. require_once DOL_DOCUMENT_ROOT.'/eventorganization/class/conferenceorboothattendee.class.php';
  61. }
  62. // Load translation files required by the page
  63. $langs->loadLangs(array("companies", "commercial", "bills", "banks", "users"));
  64. if (isModEnabled('adherent')) {
  65. $langs->load("members");
  66. }
  67. if (isModEnabled('categorie')) {
  68. $langs->load("categories");
  69. }
  70. if (isModEnabled('incoterm')) {
  71. $langs->load("incoterm");
  72. }
  73. if (isModEnabled('notification')) {
  74. $langs->load("mails");
  75. }
  76. if (isModEnabled('accounting')) {
  77. $langs->load("products");
  78. }
  79. $error = 0; $errors = array();
  80. // Get parameters
  81. $action = (GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view');
  82. $cancel = GETPOST('cancel', 'alpha');
  83. $backtopage = GETPOST('backtopage', 'alpha');
  84. $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
  85. $backtopagejsfields = GETPOST('backtopagejsfields', 'alpha');
  86. $confirm = GETPOST('confirm', 'alpha');
  87. if (!empty($backtopagejsfields)) {
  88. $tmpbacktopagejsfields = explode(':', $backtopagejsfields);
  89. $dol_openinpopup = $tmpbacktopagejsfields[0];
  90. }
  91. $socid = GETPOST('socid', 'int') ?GETPOST('socid', 'int') : GETPOST('id', 'int');
  92. if ($user->socid) {
  93. $socid = $user->socid;
  94. }
  95. if (empty($socid) && $action == 'view') {
  96. $action = 'create';
  97. }
  98. $id = $socid;
  99. $object = new Societe($db);
  100. $extrafields = new ExtraFields($db);
  101. // fetch optionals attributes and labels
  102. $extrafields->fetch_name_optionals_label($object->table_element);
  103. $socialnetworks = getArrayOfSocialNetworks();
  104. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  105. $hookmanager->initHooks(array('thirdpartycard', 'globalcard'));
  106. if ($socid > 0) {
  107. $object->fetch($socid);
  108. }
  109. if (!($object->id > 0) && $action == 'view') {
  110. $langs->load("errors");
  111. print($langs->trans('ErrorRecordNotFound'));
  112. exit;
  113. }
  114. // Get object canvas (By default, this is not defined, so standard usage of dolibarr)
  115. $canvas = $object->canvas ? $object->canvas : GETPOST("canvas");
  116. $objcanvas = null;
  117. if (!empty($canvas)) {
  118. require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
  119. $objcanvas = new Canvas($db, $action);
  120. $objcanvas->getCanvas('thirdparty', 'card', $canvas);
  121. }
  122. // Permissions
  123. $permissiontoread = $user->hasRight('societe', 'lire');
  124. $permissiontoadd = $user->hasRight('societe', 'creer'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
  125. $permissiontodelete = $user->hasRight('societe', 'supprimer') || ($permissiontoadd && isset($object->status) && $object->status == 0);
  126. $permissionnote = $user->hasRight('societe', 'creer'); // Used by the include of actions_setnotes.inc.php
  127. $permissiondellink = $user->hasRight('societe', 'creer'); // Used by the include of actions_dellink.inc.php
  128. $upload_dir = $conf->societe->multidir_output[isset($object->entity) ? $object->entity : 1];
  129. // Security check
  130. $result = restrictedArea($user, 'societe', $socid, '&societe', '', 'fk_soc', 'rowid', 0);
  131. /*
  132. * Actions
  133. */
  134. $parameters = array('id'=>$socid, 'objcanvas'=>$objcanvas);
  135. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  136. if ($reshook < 0) {
  137. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  138. }
  139. if (empty($reshook)) {
  140. $backurlforlist = DOL_URL_ROOT.'/societe/list.php';
  141. if (empty($backtopage) || ($cancel && empty($id))) {
  142. if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
  143. if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
  144. $backtopage = $backurlforlist;
  145. } else {
  146. $backtopage = DOL_URL_ROOT.'/societe/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
  147. }
  148. }
  149. }
  150. if ($cancel) {
  151. if (!empty($backtopageforcancel)) {
  152. header("Location: ".$backtopageforcancel);
  153. exit;
  154. } elseif (!empty($backtopage)) {
  155. header("Location: ".$backtopage);
  156. exit;
  157. }
  158. $action = '';
  159. }
  160. if ($action == 'confirm_merge' && $confirm == 'yes' && $user->rights->societe->creer) {
  161. $error = 0;
  162. $soc_origin_id = GETPOST('soc_origin', 'int');
  163. $soc_origin = new Societe($db);
  164. if ($soc_origin_id <= 0) {
  165. $langs->load('errors');
  166. setEventMessages($langs->trans('ErrorThirdPartyIdIsMandatory', $langs->transnoentitiesnoconv('MergeOriginThirdparty')), null, 'errors');
  167. } else {
  168. if (!$error && $soc_origin->fetch($soc_origin_id) < 1) {
  169. setEventMessages($langs->trans('ErrorRecordNotFound'), null, 'errors');
  170. $error++;
  171. }
  172. if (!$error) {
  173. // TODO Move the merge function into class of object.
  174. $db->begin();
  175. // Recopy some data
  176. $object->client = $object->client | $soc_origin->client;
  177. $object->fournisseur = $object->fournisseur | $soc_origin->fournisseur;
  178. $listofproperties = array(
  179. 'address', 'zip', 'town', 'state_id', 'country_id', 'phone', 'phone_pro', 'fax', 'email', 'socialnetworks', 'url', 'barcode',
  180. 'idprof1', 'idprof2', 'idprof3', 'idprof4', 'idprof5', 'idprof6',
  181. 'tva_intra', 'effectif_id', 'forme_juridique', 'remise_percent', 'remise_supplier_percent', 'mode_reglement_supplier_id', 'cond_reglement_supplier_id', 'name_bis',
  182. 'stcomm_id', 'outstanding_limit', 'price_level', 'parent', 'default_lang', 'ref', 'ref_ext', 'import_key', 'fk_incoterms', 'fk_multicurrency',
  183. 'code_client', 'code_fournisseur', 'code_compta', 'code_compta_fournisseur',
  184. 'model_pdf', 'fk_projet'
  185. );
  186. foreach ($listofproperties as $property) {
  187. if (empty($object->$property)) {
  188. $object->$property = $soc_origin->$property;
  189. }
  190. }
  191. // Concat some data
  192. $listofproperties = array(
  193. 'note_public', 'note_private'
  194. );
  195. foreach ($listofproperties as $property) {
  196. $object->$property = dol_concatdesc($object->$property, $soc_origin->$property);
  197. }
  198. // Merge extrafields
  199. if (is_array($soc_origin->array_options)) {
  200. foreach ($soc_origin->array_options as $key => $val) {
  201. if (empty($object->array_options[$key])) {
  202. $object->array_options[$key] = $val;
  203. }
  204. }
  205. }
  206. // Merge categories
  207. $static_cat = new Categorie($db);
  208. $custcats_ori = $static_cat->containing($soc_origin->id, 'customer', 'id');
  209. $custcats = $static_cat->containing($object->id, 'customer', 'id');
  210. $custcats = array_merge($custcats, $custcats_ori);
  211. $object->setCategories($custcats, 'customer');
  212. $suppcats_ori = $static_cat->containing($soc_origin->id, 'supplier', 'id');
  213. $suppcats = $static_cat->containing($object->id, 'supplier', 'id');
  214. $suppcats = array_merge($suppcats, $suppcats_ori);
  215. $object->setCategories($suppcats, 'supplier');
  216. // If thirdparty has a new code that is same than origin, we clean origin code to avoid duplicate key from database unique keys.
  217. if ($soc_origin->code_client == $object->code_client
  218. || $soc_origin->code_fournisseur == $object->code_fournisseur
  219. || $soc_origin->barcode == $object->barcode) {
  220. dol_syslog("We clean customer and supplier code so we will be able to make the update of target");
  221. $soc_origin->code_client = '';
  222. $soc_origin->code_fournisseur = '';
  223. $soc_origin->barcode = '';
  224. $soc_origin->update($soc_origin->id, $user, 0, 1, 1, 'merge');
  225. }
  226. // Update
  227. $result = $object->update($object->id, $user, 0, 1, 1, 'merge');
  228. if ($result < 0) {
  229. setEventMessages($object->error, $object->errors, 'errors');
  230. $error++;
  231. }
  232. // Move links
  233. if (!$error) {
  234. // This list is also into the api_thirdparties.class.php
  235. // TODO Mutualise the list into object societe.class.php
  236. $objects = array(
  237. 'Adherent' => '/adherents/class/adherent.class.php',
  238. 'Don' => '/don/class/don.class.php',
  239. 'Societe' => '/societe/class/societe.class.php',
  240. //'Categorie' => '/categories/class/categorie.class.php',
  241. 'ActionComm' => '/comm/action/class/actioncomm.class.php',
  242. 'Propal' => '/comm/propal/class/propal.class.php',
  243. 'Commande' => '/commande/class/commande.class.php',
  244. 'Facture' => '/compta/facture/class/facture.class.php',
  245. 'FactureRec' => '/compta/facture/class/facture-rec.class.php',
  246. 'LignePrelevement' => '/compta/prelevement/class/ligneprelevement.class.php',
  247. 'Mo' => '/mrp/class/mo.class.php',
  248. 'Contact' => '/contact/class/contact.class.php',
  249. 'Contrat' => '/contrat/class/contrat.class.php',
  250. 'Expedition' => '/expedition/class/expedition.class.php',
  251. 'Fichinter' => '/fichinter/class/fichinter.class.php',
  252. 'CommandeFournisseur' => '/fourn/class/fournisseur.commande.class.php',
  253. 'FactureFournisseur' => '/fourn/class/fournisseur.facture.class.php',
  254. 'SupplierProposal' => '/supplier_proposal/class/supplier_proposal.class.php',
  255. 'ProductFournisseur' => '/fourn/class/fournisseur.product.class.php',
  256. 'Delivery' => '/delivery/class/delivery.class.php',
  257. 'Product' => '/product/class/product.class.php',
  258. 'Project' => '/projet/class/project.class.php',
  259. 'Ticket' => '/ticket/class/ticket.class.php',
  260. 'User' => '/user/class/user.class.php',
  261. 'Account' => '/compta/bank/class/account.class.php',
  262. 'ConferenceOrBoothAttendee' => '/eventorganization/class/conferenceorboothattendee.class.php'
  263. );
  264. //First, all core objects must update their tables
  265. foreach ($objects as $object_name => $object_file) {
  266. require_once DOL_DOCUMENT_ROOT.$object_file;
  267. if (!$error && !$object_name::replaceThirdparty($db, $soc_origin->id, $object->id)) {
  268. $error++;
  269. setEventMessages($db->lasterror(), null, 'errors');
  270. break;
  271. }
  272. }
  273. }
  274. // External modules should update their ones too
  275. if (!$error) {
  276. $reshook = $hookmanager->executeHooks('replaceThirdparty', array(
  277. 'soc_origin' => $soc_origin->id,
  278. 'soc_dest' => $object->id
  279. ), $object, $action);
  280. if ($reshook < 0) {
  281. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  282. $error++;
  283. }
  284. }
  285. if (!$error) {
  286. $object->context = array('merge'=>1, 'mergefromid'=>$soc_origin->id);
  287. // Call trigger
  288. $result = $object->call_trigger('COMPANY_MODIFY', $user);
  289. if ($result < 0) {
  290. setEventMessages($object->error, $object->errors, 'errors');
  291. $error++;
  292. }
  293. // End call triggers
  294. }
  295. if (!$error) {
  296. //We finally remove the old thirdparty
  297. if ($soc_origin->delete($soc_origin->id, $user) < 1) {
  298. setEventMessages($soc_origin->error, $soc_origin->errors, 'errors');
  299. $error++;
  300. }
  301. }
  302. if (!$error) {
  303. setEventMessages($langs->trans('ThirdpartiesMergeSuccess'), null, 'mesgs');
  304. $db->commit();
  305. } else {
  306. $langs->load("errors");
  307. setEventMessages($langs->trans('ErrorsThirdpartyMerge'), null, 'errors');
  308. $db->rollback();
  309. }
  310. }
  311. }
  312. }
  313. if (GETPOST('getcustomercode')) {
  314. // We defined value code_client
  315. $_POST["customer_code"] = "Acompleter";
  316. }
  317. if (GETPOST('getsuppliercode')) {
  318. // We defined value code_fournisseur
  319. $_POST["supplier_code"] = "Acompleter";
  320. }
  321. if ($action == 'set_localtax1') {
  322. //obtidre selected del combobox
  323. $value = GETPOST('lt1');
  324. $object->fetch($socid);
  325. $res = $object->setValueFrom('localtax1_value', $value, '', null, 'text', '', $user, 'COMPANY_MODIFY');
  326. }
  327. if ($action == 'set_localtax2') {
  328. //obtidre selected del combobox
  329. $value = GETPOST('lt2');
  330. $object->fetch($socid);
  331. $res = $object->setValueFrom('localtax2_value', $value, '', null, 'text', '', $user, 'COMPANY_MODIFY');
  332. }
  333. if ($action == 'update_extras') {
  334. $object->fetch($socid);
  335. $object->oldcopy = dol_clone($object);
  336. // Fill array 'array_options' with data from update form
  337. $extrafields->fetch_name_optionals_label($object->table_element);
  338. $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml'));
  339. if ($ret < 0) {
  340. $error++;
  341. }
  342. if (!$error) {
  343. $result = $object->insertExtraFields('COMPANY_MODIFY');
  344. if ($result < 0) {
  345. setEventMessages($object->error, $object->errors, 'errors');
  346. $error++;
  347. }
  348. }
  349. if ($error) {
  350. $action = 'edit_extras';
  351. }
  352. }
  353. // Add new or update third party
  354. if ((!GETPOST('getcustomercode') && !GETPOST('getsuppliercode'))
  355. && ($action == 'add' || $action == 'update') && $user->rights->societe->creer) {
  356. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  357. if (!GETPOST('name')) {
  358. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ThirdPartyName")), null, 'errors');
  359. $error++;
  360. }
  361. if (GETPOST('client', 'int') && GETPOST('client', 'int') < 0) {
  362. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ProspectCustomer")), null, 'errors');
  363. $error++;
  364. }
  365. if (GETPOSTISSET('fournisseur') && GETPOST('fournisseur', 'int') < 0) {
  366. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Supplier")), null, 'errors');
  367. $error++;
  368. }
  369. 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))) {
  370. $error++;
  371. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("No_Email")), null, 'errors');
  372. }
  373. 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))) {
  374. $error++;
  375. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("No_Email")), null, 'errors');
  376. }
  377. if (!$error) {
  378. if ($action == 'update') {
  379. $ret = $object->fetch($socid);
  380. $object->oldcopy = clone $object;
  381. } else {
  382. $object->canvas = $canvas;
  383. }
  384. if (GETPOST("private", 'int') == 1) { // Ask to create a contact
  385. $object->particulier = GETPOST("private", 'int');
  386. $object->name = dolGetFirstLastname(GETPOST('firstname', 'alphanohtml'), GETPOST('name', 'alphanohtml'));
  387. $object->civility_id = GETPOST('civility_id', 'alphanohtml'); // Note: civility id is a code, not an int
  388. // Add non official properties
  389. $object->name_bis = GETPOST('name', 'alphanohtml');
  390. $object->firstname = GETPOST('firstname', 'alphanohtml');
  391. } else {
  392. $object->name = GETPOST('name', 'alphanohtml');
  393. }
  394. $object->entity = (GETPOSTISSET('entity') ? GETPOST('entity', 'int') : $conf->entity);
  395. $object->name_alias = GETPOST('name_alias', 'alphanohtml');
  396. $object->parent = GETPOST('parent_company_id', 'int');
  397. $object->address = GETPOST('address', 'alphanohtml');
  398. $object->zip = GETPOST('zipcode', 'alphanohtml');
  399. $object->town = GETPOST('town', 'alphanohtml');
  400. $object->country_id = GETPOST('country_id', 'int');
  401. $object->state_id = GETPOST('state_id', 'int');
  402. $object->socialnetworks = array();
  403. if (isModEnabled('socialnetworks')) {
  404. foreach ($socialnetworks as $key => $value) {
  405. if (GETPOSTISSET($key) && GETPOST($key, 'alphanohtml') != '') {
  406. $object->socialnetworks[$key] = GETPOST($key, 'alphanohtml');
  407. }
  408. }
  409. }
  410. $object->phone = GETPOST('phone', 'alpha');
  411. $object->fax = GETPOST('fax', 'alpha');
  412. $object->email = trim(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL));
  413. $object->no_email = GETPOST("no_email", "int");
  414. $object->url = trim(GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL));
  415. $object->idprof1 = trim(GETPOST('idprof1', 'alphanohtml'));
  416. $object->idprof2 = trim(GETPOST('idprof2', 'alphanohtml'));
  417. $object->idprof3 = trim(GETPOST('idprof3', 'alphanohtml'));
  418. $object->idprof4 = trim(GETPOST('idprof4', 'alphanohtml'));
  419. $object->idprof5 = trim(GETPOST('idprof5', 'alphanohtml'));
  420. $object->idprof6 = trim(GETPOST('idprof6', 'alphanohtml'));
  421. $object->prefix_comm = GETPOST('prefix_comm', 'alphanohtml');
  422. $object->code_client = GETPOSTISSET('customer_code') ?GETPOST('customer_code', 'alpha') : GETPOST('code_client', 'alpha');
  423. $object->code_fournisseur = GETPOSTISSET('supplier_code') ?GETPOST('supplier_code', 'alpha') : GETPOST('code_fournisseur', 'alpha');
  424. $object->capital = GETPOST('capital', 'alphanohtml');
  425. $object->barcode = GETPOST('barcode', 'alphanohtml');
  426. $object->tva_intra = GETPOST('tva_intra', 'alphanohtml');
  427. $object->tva_assuj = GETPOST('assujtva_value', 'alpha');
  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) && !empty($conf->mailing->enabled) && !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 && !empty($user->rights->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->rights->societe->creer) {
  807. $object->fetch($socid);
  808. $result = $object->setThirdpartyType(GETPOST('typent_id', 'int'));
  809. }
  810. // Set incoterm
  811. if ($action == 'set_incoterms' && $user->rights->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->rights->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->rights->societe->creer) {
  822. $object->fetch($socid);
  823. $result = $object->setSalesRep(GETPOST('commercial', 'array'));
  824. }
  825. // warehouse
  826. if ($action == 'setwarehouse' && $user->rights->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("fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) && (GETPOST("type") == 'f' || (GETPOST("type") == '' && !empty($conf->global->THIRDPARTY_SUPPLIER_BY_DEFAULT)))) {
  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->status = GETPOST('status', 'int');
  987. //Local Taxes
  988. $object->localtax1_assuj = GETPOST('localtax1assuj_value', 'int');
  989. $object->localtax2_assuj = GETPOST('localtax2assuj_value', 'int');
  990. $object->localtax1_value = GETPOST('lt1', 'int');
  991. $object->localtax2_value = GETPOST('lt2', 'int');
  992. $object->tva_intra = GETPOST('tva_intra', 'alphanohtml');
  993. $object->commercial_id = GETPOST('commercial_id', 'int');
  994. $object->default_lang = GETPOST('default_lang');
  995. if (GETPOSTISSET('accountancy_code_sell')) {
  996. $accountancy_code_sell = GETPOST('accountancy_code_sell', 'alpha');
  997. if (empty($accountancy_code_sell) || $accountancy_code_sell == '-1') {
  998. $object->accountancy_code_sell = '';
  999. } else {
  1000. $object->accountancy_code_sell = $accountancy_code_sell;
  1001. }
  1002. }
  1003. if (GETPOSTISSET('accountancy_code_buy')) {
  1004. $accountancy_code_buy = GETPOST('accountancy_code_buy', 'alpha');
  1005. if (empty($accountancy_code_buy) || $accountancy_code_buy == '-1') {
  1006. $object->accountancy_code_buy = '';
  1007. } else {
  1008. $object->accountancy_code_buy = $accountancy_code_buy;
  1009. }
  1010. }
  1011. $object->logo = (isset($_FILES['photo']) ?dol_sanitizeFileName($_FILES['photo']['name']) : '');
  1012. // Gestion du logo de la société
  1013. $dir = $conf->societe->multidir_output[$conf->entity]."/".$object->id."/logos";
  1014. $file_OK = (isset($_FILES['photo']) ?is_uploaded_file($_FILES['photo']['tmp_name']) : false);
  1015. if ($file_OK) {
  1016. if (image_format_supported($_FILES['photo']['name'])) {
  1017. dol_mkdir($dir);
  1018. if (@is_dir($dir)) {
  1019. $newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
  1020. $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
  1021. if (!($result > 0)) {
  1022. $errors[] = "ErrorFailedToSaveFile";
  1023. } else {
  1024. // Create thumbs
  1025. $object->addThumbs($newfile);
  1026. }
  1027. }
  1028. }
  1029. }
  1030. // We set country_id, country_code and country for the selected country
  1031. $object->country_id = GETPOST('country_id') ?GETPOST('country_id') : $mysoc->country_id;
  1032. if ($object->country_id) {
  1033. $tmparray = getCountry($object->country_id, 'all');
  1034. $object->country_code = $tmparray['code'];
  1035. $object->country = $tmparray['label'];
  1036. }
  1037. $object->forme_juridique_code = GETPOST('forme_juridique_code');
  1038. // We set multicurrency_code if enabled
  1039. if (isModEnabled("multicurrency")) {
  1040. $object->multicurrency_code = GETPOST('multicurrency_code') ? GETPOST('multicurrency_code') : $conf->currency;
  1041. }
  1042. /* Show create form */
  1043. $linkback = "";
  1044. print load_fiche_titre($langs->trans("NewThirdParty"), $linkback, 'building');
  1045. if (!empty($conf->use_javascript_ajax)) {
  1046. if (!empty($conf->global->THIRDPARTY_SUGGEST_ALSO_ADDRESS_CREATION)) {
  1047. print "\n".'<script type="text/javascript">';
  1048. print '$(document).ready(function () {
  1049. id_te_private=8;
  1050. id_ef15=1;
  1051. is_private=' . $private.';
  1052. if (is_private) {
  1053. $(".individualline").show();
  1054. } else {
  1055. $(".individualline").hide();
  1056. }
  1057. $("#radiocompany").click(function() {
  1058. $(".individualline").hide();
  1059. $("#typent_id").val(0);
  1060. $("#typent_id").change();
  1061. $("#effectif_id").val(0);
  1062. $("#effectif_id").change();
  1063. $("#TypeName").html(document.formsoc.ThirdPartyName.value);
  1064. document.formsoc.private.value=0;
  1065. });
  1066. $("#radioprivate").click(function() {
  1067. $(".individualline").show();
  1068. $("#typent_id").val(id_te_private);
  1069. $("#typent_id").change();
  1070. $("#effectif_id").val(id_ef15);
  1071. $("#effectif_id").change();
  1072. /* Force to recompute the width of a select2 field when it was hidden and then shown programatically */
  1073. if ($("#civility_id").data("select2")) {
  1074. $("#civility_id").select2({width: "resolve"});
  1075. }
  1076. $("#TypeName").html(document.formsoc.LastName.value);
  1077. document.formsoc.private.value=1;
  1078. });
  1079. var canHaveCategoryIfNotCustomerProspectSupplier = ' . (empty($conf->global->THIRDPARTY_CAN_HAVE_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT) ? '0' : '1') . ';
  1080. init_customer_categ();
  1081. $("#customerprospect").change(function() {
  1082. init_customer_categ();
  1083. });
  1084. function init_customer_categ() {
  1085. console.log("is customer or prospect = "+jQuery("#customerprospect").val());
  1086. if (jQuery("#customerprospect").val() == 0 && !canHaveCategoryIfNotCustomerProspectSupplier)
  1087. {
  1088. jQuery(".visibleifcustomer").hide();
  1089. }
  1090. else
  1091. {
  1092. jQuery(".visibleifcustomer").show();
  1093. }
  1094. }
  1095. init_supplier_categ();
  1096. $("#fournisseur").change(function() {
  1097. init_supplier_categ();
  1098. });
  1099. function init_supplier_categ() {
  1100. console.log("is supplier = "+jQuery("#fournisseur").val());
  1101. if (jQuery("#fournisseur").val() == 0)
  1102. {
  1103. jQuery(".visibleifsupplier").hide();
  1104. }
  1105. else
  1106. {
  1107. jQuery(".visibleifsupplier").show();
  1108. }
  1109. }
  1110. $("#selectcountry_id").change(function() {
  1111. document.formsoc.action.value="create";
  1112. document.formsoc.submit();
  1113. });';
  1114. if ($conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS == 2) {
  1115. print '
  1116. function init_check_no_email(input) {
  1117. if (input.val()!="") {
  1118. $(".noemail").addClass("fieldrequired");
  1119. } else {
  1120. $(".noemail").removeClass("fieldrequired");
  1121. }
  1122. }
  1123. $("#email").keyup(function() {
  1124. init_check_no_email($(this));
  1125. });
  1126. init_check_no_email($("#email"));';
  1127. }
  1128. print '});';
  1129. print '</script>'."\n";
  1130. print '<div id="selectthirdpartytype">';
  1131. print '<div class="hideonsmartphone float">';
  1132. print $langs->trans("ThirdPartyType").': &nbsp; &nbsp; ';
  1133. print '</div>';
  1134. print '<label for="radiocompany" class="radiocompany">';
  1135. print '<input type="radio" id="radiocompany" class="flat" name="private" value="0"'.($private ? '' : ' checked').'>';
  1136. print '&nbsp;';
  1137. print $langs->trans("CreateThirdPartyOnly");
  1138. print '</label>';
  1139. print ' &nbsp; &nbsp; ';
  1140. print '<label for="radioprivate" class="radioprivate">';
  1141. $text = '<input type="radio" id="radioprivate" class="flat" name="private" value="1"'.($private ? ' checked' : '').'>';
  1142. $text .= '&nbsp;';
  1143. $text .= $langs->trans("CreateThirdPartyAndContact");
  1144. $htmltext = $langs->trans("ToCreateContactWithSameName");
  1145. print $form->textwithpicto($text, $htmltext, 1, 'help', '', 0, 3);
  1146. print '</label>';
  1147. print '</div>';
  1148. print "<br>\n";
  1149. } else {
  1150. print '<script type="text/javascript">';
  1151. print '$(document).ready(function () {
  1152. $("#selectcountry_id").change(function() {
  1153. document.formsoc.action.value="create";
  1154. document.formsoc.submit();
  1155. });
  1156. });';
  1157. print '</script>'."\n";
  1158. }
  1159. }
  1160. dol_htmloutput_mesg(is_numeric($error) ? '' : $error, $errors, 'error');
  1161. print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'" method="post" name="formsoc" autocomplete="off">'; // Chrome ignor autocomplete
  1162. print '<input type="hidden" name="action" value="add">';
  1163. print '<input type="hidden" name="token" value="'.newToken().'">';
  1164. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  1165. print '<input type="hidden" name="backtopagejsfields" value="'.$backtopagejsfields.'">';
  1166. print '<input type="hidden" name="dol_openinpopup" value="'.$dol_openinpopup.'">';
  1167. print '<input type="hidden" name="private" value='.$object->particulier.'>';
  1168. print '<input type="hidden" name="type" value='.GETPOST("type", 'alpha').'>';
  1169. print '<input type="hidden" name="LastName" value="'.$langs->trans('ThirdPartyName').' / '.$langs->trans('LastName').'">';
  1170. print '<input type="hidden" name="ThirdPartyName" value="'.$langs->trans('ThirdPartyName').'">';
  1171. if ($modCodeClient->code_auto || $modCodeFournisseur->code_auto) {
  1172. print '<input type="hidden" name="code_auto" value="1">';
  1173. }
  1174. print dol_get_fiche_head(null, 'card', '', 0, '');
  1175. print '<table class="border centpercent">';
  1176. // Name, firstname
  1177. print '<tr class="tr-field-thirdparty-name"><td class="titlefieldcreate">';
  1178. if ($object->particulier || $private) {
  1179. print '<span id="TypeName" class="fieldrequired">'.$langs->trans('ThirdPartyName').' / '.$langs->trans('LastName', 'name').'</span>';
  1180. } else {
  1181. print '<span id="TypeName" class="fieldrequired">'.$form->editfieldkey('ThirdPartyName', 'name', '', $object, 0).'</span>';
  1182. }
  1183. print '</td><td'.(empty($conf->global->SOCIETE_USEPREFIX) ? ' colspan="3"' : '').'>';
  1184. print '<input type="text" class="minwidth300" maxlength="128" name="name" id="name" value="'.dol_escape_htmltag($object->name).'" autofocus="autofocus">';
  1185. print $form->widgetForTranslation("name", $object, $permissiontoadd, 'string', 'alpahnohtml', 'minwidth300');
  1186. /* Disabled. Must be implenteted by keeping the input text but calling ajax on a keydown of the input and output
  1187. data of duplicate into a div under the input. We need to keep the widgetForTranslation also for some countries.
  1188. */
  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 (!empty($conf->mailing->enabled)) {
  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. foreach ($socialnetworks as $key => $value) {
  1455. if ($value['active']) {
  1456. print '<tr>';
  1457. print '<td><label for="'.$value['label'].'">'.$form->editfieldkey($value['label'], $key, '', $object, 0).'</label></td>';
  1458. print '<td colspan="3">';
  1459. if (!empty($value['icon'])) {
  1460. print '<span class="fa '.$value['icon'].' pictofixedwidth"></span>';
  1461. }
  1462. print '<input type="text" name="'.$key.'" id="'.$key.'" class="minwidth100 maxwidth300 widthcentpercentminusx" maxlength="80" value="'.dol_escape_htmltag(GETPOSTISSET($key) ? GETPOST($key, 'alphanohtml') : (empty($object->socialnetworks[$key]) ? '' : $object->socialnetworks[$key])).'">';
  1463. print '</td>';
  1464. print '</tr>';
  1465. } elseif (!empty($object->socialnetworks[$key])) {
  1466. print '<input type="hidden" name="'.$key.'" value="'.$object->socialnetworks[$key].'">';
  1467. }
  1468. }
  1469. }
  1470. // Prof ids
  1471. $i = 1; $j = 0; $NBCOLS = ($conf->browser->layout == 'phone' ? 1 : 2);
  1472. while ($i <= 6) {
  1473. $idprof = $langs->transcountry('ProfId'.$i, $object->country_code);
  1474. if ($idprof != '-') {
  1475. $key = 'idprof'.$i;
  1476. if (($j % $NBCOLS) == 0) {
  1477. print '<tr>';
  1478. }
  1479. $idprof_mandatory = 'SOCIETE_IDPROF'.($i).'_MANDATORY';
  1480. print '<td>'.$form->editfieldkey($idprof, $key, '', $object, 0, 'string', '', (empty($conf->global->$idprof_mandatory) ? 0 : 1)).'</td><td>';
  1481. print $formcompany->get_input_id_prof($i, $key, $object->$key, $object->country_code);
  1482. print '</td>';
  1483. if (($j % $NBCOLS) == ($NBCOLS - 1)) {
  1484. print '</tr>';
  1485. }
  1486. $j++;
  1487. }
  1488. $i++;
  1489. }
  1490. if ($NBCOLS > 1 && ($j % 2 == 1)) {
  1491. print '<td colspan="2"></td></tr>';
  1492. }
  1493. // Vat is used
  1494. print '<tr><td>'.$form->editfieldkey('VATIsUsed', 'assujtva_value', '', $object, 0).'</td>';
  1495. print '<td>';
  1496. print $form->selectyesno('assujtva_value', GETPOSTISSET('assujtva_value') ?GETPOST('assujtva_value', 'int') : 1, 1); // Assujeti par defaut en creation
  1497. print '</td>';
  1498. if ($conf->browser->layout == 'phone') {
  1499. print '</tr><tr>';
  1500. }
  1501. print '<td class="nowrap">'.$form->editfieldkey('VATIntra', 'intra_vat', '', $object, 0).'</td>';
  1502. print '<td class="nowrap">';
  1503. $s = '<input type="text" class="flat maxwidthonsmartphone" name="tva_intra" id="intra_vat" maxlength="20" value="'.$object->tva_intra.'">';
  1504. if (empty($conf->global->MAIN_DISABLEVATCHECK) && isInEEC($object)) {
  1505. $s .= ' ';
  1506. if (!empty($conf->use_javascript_ajax)) {
  1507. $widthpopup = 600;
  1508. if (!empty($conf->dol_use_jmobile)) {
  1509. $widthpopup = 350;
  1510. }
  1511. $heightpopup = 400;
  1512. print "\n";
  1513. print '<script type="text/javascript">';
  1514. print "function CheckVAT(a) {\n";
  1515. print "newpopup('".DOL_URL_ROOT."/societe/checkvat/checkVatPopup.php?vatNumber='+a, '".dol_escape_js($langs->trans("VATIntraCheckableOnEUSite"))."', ".$widthpopup.", ".$heightpopup.");\n";
  1516. print "}\n";
  1517. print '</script>';
  1518. print "\n";
  1519. $s .= '<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>';
  1520. $s = $form->textwithpicto($s, $langs->trans("VATIntraCheckDesc", $langs->transnoentitiesnoconv("VATIntraCheck")), 1);
  1521. } else {
  1522. $s .= '<a href="'.$langs->transcountry("VATIntraCheckURL", $object->country_id).'" target="_blank" rel="noopener noreferrer">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"), 'help').'</a>';
  1523. }
  1524. }
  1525. print $s;
  1526. print '</td>';
  1527. print '</tr>';
  1528. // Local Taxes
  1529. //TODO: Place into a function to control showing by country or study better option
  1530. if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1") {
  1531. print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>';
  1532. print $form->selectyesno('localtax1assuj_value', (isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1) ? $conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1 : 0), 1);
  1533. print '</td>';
  1534. if ($conf->browser->layout == 'phone') {
  1535. print '</tr><tr>';
  1536. }
  1537. print '<td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>';
  1538. print $form->selectyesno('localtax2assuj_value', (isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2) ? $conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2 : 0), 1);
  1539. print '</td></tr>';
  1540. } elseif ($mysoc->localtax1_assuj == "1") {
  1541. print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td colspan="3">';
  1542. print $form->selectyesno('localtax1assuj_value', (isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1) ? $conf->global->THIRDPARTY_DEFAULT_USELOCALTAX1 : 0), 1);
  1543. print '</td></tr>';
  1544. } elseif ($mysoc->localtax2_assuj == "1") {
  1545. print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td colspan="3">';
  1546. print $form->selectyesno('localtax2assuj_value', (isset($conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2) ? $conf->global->THIRDPARTY_DEFAULT_USELOCALTAX2 : 0), 1);
  1547. print '</td></tr>';
  1548. }
  1549. // Type - Workforce/Staff
  1550. 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";
  1551. $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.
  1552. print $form->selectarray("typent_id", $formcompany->typent_array(0), $object->typent_id, 1, 0, 0, '', 0, 0, 0, $sortparam, '', 1);
  1553. if ($user->admin) {
  1554. print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  1555. }
  1556. if (empty($conf->global->SOCIETE_DISABLE_WORKFORCE)) {
  1557. print '</td>';
  1558. if ($conf->browser->layout == 'phone') {
  1559. print '</tr><tr>';
  1560. }
  1561. print '<td>'.$form->editfieldkey('Workforce', 'effectif_id', '', $object, 0).'</td><td class="maxwidthonsmartphone"'.($conf->browser->layout == 'phone' ? ' colspan="3"' : '').'>';
  1562. print $form->selectarray("effectif_id", $formcompany->effectif_array(0), $object->effectif_id, 0, 0, 0, '', 0, 0, 0, '', '', 1);
  1563. if ($user->admin) {
  1564. print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  1565. }
  1566. } else {
  1567. print '<input type="hidden" name="effectif_id" id="effectif_id" value="'.$object->effectif_id.'">';
  1568. }
  1569. print '</td></tr>';
  1570. // Legal Form
  1571. print '<tr><td>'.$form->editfieldkey('JuridicalStatus', 'forme_juridique_code', '', $object, 0).'</td>';
  1572. print '<td colspan="3" class="maxwidthonsmartphone">';
  1573. if ($object->country_id) {
  1574. print $formcompany->select_juridicalstatus($object->forme_juridique_code, $object->country_code, '', 'forme_juridique_code');
  1575. } else {
  1576. print $countrynotdefined;
  1577. }
  1578. print '</td></tr>';
  1579. // Capital
  1580. print '<tr><td>'.$form->editfieldkey('Capital', 'capital', '', $object, 0).'</td>';
  1581. print '<td colspan="3"><input type="text" name="capital" id="capital" class="maxwidth100" value="'.$object->capital.'"> ';
  1582. if (isModEnabled("multicurrency")) {
  1583. print '<span class="hideonsmartphone">'.$langs->trans("Currency".$object->multicurrency_code).'</span></td></tr>';
  1584. } else {
  1585. print '<span class="hideonsmartphone">'.$langs->trans("Currency".$conf->currency).'</span></td></tr>';
  1586. }
  1587. if (getDolGlobalInt('MAIN_MULTILANGS')) {
  1588. print '<tr><td>'.$form->editfieldkey('DefaultLang', 'default_lang', '', $object, 0).'</td><td colspan="3" class="maxwidthonsmartphone">'."\n";
  1589. 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');
  1590. print '</td>';
  1591. print '</tr>';
  1592. }
  1593. // Incoterms
  1594. if (isModEnabled('incoterm')) {
  1595. print '<tr>';
  1596. print '<td>'.$form->editfieldkey('IncotermLabel', 'incoterm_id', '', $object, 0).'</td>';
  1597. print '<td colspan="3" class="maxwidthonsmartphone">';
  1598. print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''));
  1599. print '</td></tr>';
  1600. }
  1601. // Categories
  1602. if (isModEnabled('categorie') && !empty($user->rights->categorie->lire)) {
  1603. $langs->load('categories');
  1604. // Customer
  1605. print '<tr class="visibleifcustomer"><td class="toptd">'.$form->editfieldkey('CustomersProspectsCategoriesShort', 'custcats', '', $object, 0).'</td><td colspan="3">';
  1606. $cate_arbo = $form->select_all_categories(Categorie::TYPE_CUSTOMER, null, 'parent', null, null, 1);
  1607. print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('custcats', $cate_arbo, GETPOST('custcats', 'array'), null, null, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
  1608. print "</td></tr>";
  1609. if (!empty($conf->global->THIRDPARTY_SUGGEST_ALSO_ADDRESS_CREATION)) {
  1610. print '<tr class="individualline"><td class="toptd">'.$form->editfieldkey('ContactCategoriesShort', 'contcats', '', $object, 0).'</td><td colspan="3">';
  1611. $cate_arbo = $form->select_all_categories(Categorie::TYPE_CONTACT, null, 'parent', null, null, 1);
  1612. print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('contcats', $cate_arbo, GETPOST('contcats', 'array'), null, null, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
  1613. print "</td></tr>";
  1614. }
  1615. // Supplier
  1616. if ((isModEnabled("fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) {
  1617. print '<tr class="visibleifsupplier"><td class="toptd">'.$form->editfieldkey('SuppliersCategoriesShort', 'suppcats', '', $object, 0).'</td><td colspan="3">';
  1618. $cate_arbo = $form->select_all_categories(Categorie::TYPE_SUPPLIER, null, 'parent', null, null, 1);
  1619. print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('suppcats', $cate_arbo, GETPOST('suppcats', 'array'), null, null, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
  1620. print "</td></tr>";
  1621. }
  1622. }
  1623. // Multicurrency
  1624. if (isModEnabled("multicurrency")) {
  1625. print '<tr>';
  1626. print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
  1627. print '<td colspan="3" class="maxwidthonsmartphone">';
  1628. print img_picto('', 'currency', 'class="pictofixedwidth"');
  1629. print $form->selectMultiCurrency((GETPOSTISSET('multicurrency_code') ? GETPOST('multicurrency_code') : ($object->multicurrency_code ? $object->multicurrency_code : $conf->currency)), 'multicurrency_code', 1, '', false, 'maxwidth150 widthcentpercentminusx');
  1630. print '</td></tr>';
  1631. }
  1632. // Other attributes
  1633. $parameters = array('socid'=>$socid, 'colspan' => ' colspan="3"', 'colspanvalue' => '3');
  1634. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
  1635. // Parent company
  1636. if (empty($conf->global->SOCIETE_DISABLE_PARENTCOMPANY)) {
  1637. print '<tr>';
  1638. print '<td>'.$langs->trans('ParentCompany').'</td>';
  1639. print '<td colspan="3" class="maxwidthonsmartphone">';
  1640. print img_picto('', 'company', 'class="paddingrightonly"');
  1641. print $form->select_company(GETPOST('parent_company_id'), 'parent_company_id', '', 'SelectThirdParty', 0, 0, null, 0, 'minwidth300 maxwidth500 widthcentpercentminusxx');
  1642. print '</td></tr>';
  1643. }
  1644. // Assign a sale representative
  1645. print '<tr>';
  1646. print '<td>'.$form->editfieldkey('AllocateCommercial', 'commercial_id', '', $object, 0).'</td>';
  1647. print '<td colspan="3" class="maxwidthonsmartphone">';
  1648. $userlist = $form->select_dolusers('', '', 0, null, 0, '', '', 0, 0, 0, 'AND u.statut = 1', 0, '', '', 0, 1);
  1649. // 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.
  1650. $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())));
  1651. print img_picto('', 'user').$form->multiselectarray('commercial', $userlist, $selected, null, null, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
  1652. print '</td></tr>';
  1653. // Add logo
  1654. print '<tr class="hideonsmartphone">';
  1655. print '<td>'.$form->editfieldkey('Logo', 'photoinput', '', $object, 0).'</td>';
  1656. print '<td colspan="3">';
  1657. print '<input class="flat" type="file" name="photo" id="photoinput" />';
  1658. print '</td>';
  1659. print '</tr>';
  1660. print '</table>'."\n";
  1661. // Accountancy codes
  1662. if (!empty($conf->global->ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY)) {
  1663. print '<table class="border centpercent">';
  1664. if (isModEnabled('accounting')) {
  1665. // Accountancy_code_sell
  1666. print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellCode").'</td>';
  1667. print '<td>';
  1668. $accountancy_code_sell = GETPOST('accountancy_code_sell', 'alpha');
  1669. print $formaccounting->select_account($accountancy_code_sell, 'accountancy_code_sell', 1, null, 1, 1, '');
  1670. print '</td></tr>';
  1671. // Accountancy_code_buy
  1672. print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyCode").'</td>';
  1673. print '<td>';
  1674. $accountancy_code_buy = GETPOST('accountancy_code_buy', 'alpha');
  1675. print $formaccounting->select_account($accountancy_code_buy, 'accountancy_code_buy', 1, null, 1, 1, '');
  1676. print '</td></tr>';
  1677. } else { // For external software
  1678. // Accountancy_code_sell
  1679. print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellCode").'</td>';
  1680. print '<td class="maxwidthonsmartphone"><input class="minwidth100" name="accountancy_code_sell" value="'.$object->accountancy_code_sell.'">';
  1681. print '</td></tr>';
  1682. // Accountancy_code_buy
  1683. print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancyBuyCode").'</td>';
  1684. print '<td class="maxwidthonsmartphone"><input class="minwidth100" name="accountancy_code_buy" value="'.$object->accountancy_code_buy.'">';
  1685. print '</td></tr>';
  1686. }
  1687. print '</table>';
  1688. }
  1689. print dol_get_fiche_end();
  1690. print $form->buttonsSaveCancel("AddThirdParty", 'Cancel', null, 0, '', $dol_openinpopup);
  1691. print '</form>'."\n";
  1692. } elseif ($action == 'edit') {
  1693. //print load_fiche_titre($langs->trans("EditCompany"));
  1694. if ($socid) {
  1695. $res = $object->fetch_optionals();
  1696. //if ($res < 0) { dol_print_error($db); exit; }
  1697. $head = societe_prepare_head($object);
  1698. // Load object modCodeTiers
  1699. $module = (!empty($conf->global->SOCIETE_CODECLIENT_ADDON) ? $conf->global->SOCIETE_CODECLIENT_ADDON : 'mod_codeclient_leopard');
  1700. if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') {
  1701. $module = substr($module, 0, dol_strlen($module) - 4);
  1702. }
  1703. $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
  1704. foreach ($dirsociete as $dirroot) {
  1705. $res = dol_include_once($dirroot.$module.'.php');
  1706. if ($res) {
  1707. break;
  1708. }
  1709. }
  1710. $modCodeClient = new $module($db);
  1711. // We verified if the tag prefix is used
  1712. if ($modCodeClient->code_auto) {
  1713. $prefixCustomerIsUsed = $modCodeClient->verif_prefixIsUsed();
  1714. }
  1715. $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
  1716. if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') {
  1717. $module = substr($module, 0, dol_strlen($module) - 4);
  1718. }
  1719. $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
  1720. foreach ($dirsociete as $dirroot) {
  1721. $res = dol_include_once($dirroot.$module.'.php');
  1722. if ($res) {
  1723. break;
  1724. }
  1725. }
  1726. $modCodeFournisseur = new $module($db);
  1727. // On verifie si la balise prefix est utilisee
  1728. if ($modCodeFournisseur->code_auto) {
  1729. $prefixSupplierIsUsed = $modCodeFournisseur->verif_prefixIsUsed();
  1730. }
  1731. $object->oldcopy = clone $object;
  1732. if (GETPOSTISSET('name')) {
  1733. // We overwrite with values if posted
  1734. $object->name = GETPOST('name', 'alphanohtml');
  1735. $object->name_alias = GETPOST('name_alias', 'alphanohtml');
  1736. $object->prefix_comm = GETPOST('prefix_comm', 'alphanohtml');
  1737. $object->client = GETPOST('client', 'int');
  1738. $object->code_client = GETPOST('customer_code', 'alpha');
  1739. $object->fournisseur = GETPOST('fournisseur', 'int');
  1740. $object->code_fournisseur = GETPOST('supplier_code', 'alpha');
  1741. $object->address = GETPOST('address', 'alphanohtml');
  1742. $object->zip = GETPOST('zipcode', 'alphanohtml');
  1743. $object->town = GETPOST('town', 'alphanohtml');
  1744. $object->country_id = GETPOST('country_id') ?GETPOST('country_id', 'int') : $mysoc->country_id;
  1745. $object->state_id = GETPOST('state_id', 'int');
  1746. $object->parent = GETPOST('parent_company_id', 'int');
  1747. $object->socialnetworks = array();
  1748. if (isModEnabled('socialnetworks')) {
  1749. foreach ($socialnetworks as $key => $value) {
  1750. if (GETPOSTISSET($key) && GETPOST($key, 'alphanohtml') != '') {
  1751. $object->socialnetworks[$key] = GETPOST($key, 'alphanohtml');
  1752. }
  1753. }
  1754. }
  1755. $object->phone = GETPOST('phone', 'alpha');
  1756. $object->fax = GETPOST('fax', 'alpha');
  1757. $object->email = GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL);
  1758. $object->no_email = GETPOST("no_email", "int");
  1759. $object->url = GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL);
  1760. $object->capital = GETPOST('capital', 'alphanohtml');
  1761. $object->idprof1 = GETPOST('idprof1', 'alphanohtml');
  1762. $object->idprof2 = GETPOST('idprof2', 'alphanohtml');
  1763. $object->idprof3 = GETPOST('idprof3', 'alphanohtml');
  1764. $object->idprof4 = GETPOST('idprof4', 'alphanohtml');
  1765. $object->idprof5 = GETPOST('idprof5', 'alphanohtml');
  1766. $object->idprof6 = GETPOST('idprof6', 'alphanohtml');
  1767. $object->typent_id = GETPOST('typent_id', 'int');
  1768. $object->effectif_id = GETPOST('effectif_id', 'int');
  1769. $object->barcode = GETPOST('barcode', 'alphanohtml');
  1770. $object->forme_juridique_code = GETPOST('forme_juridique_code', 'int');
  1771. $object->default_lang = GETPOST('default_lang', 'alpha');
  1772. $object->tva_assuj = GETPOST('assujtva_value', 'int');
  1773. $object->tva_intra = GETPOST('tva_intra', 'alphanohtml');
  1774. $object->status = GETPOST('status', 'int');
  1775. // Webservices url/key
  1776. $object->webservices_url = GETPOST('webservices_url', 'custom', 0, FILTER_SANITIZE_URL);
  1777. $object->webservices_key = GETPOST('webservices_key', 'san_alpha');
  1778. if (GETPOSTISSET('accountancy_code_sell')) {
  1779. $accountancy_code_sell = GETPOST('accountancy_code_sell', 'alpha');
  1780. if (empty($accountancy_code_sell) || $accountancy_code_sell == '-1') {
  1781. $object->accountancy_code_sell = '';
  1782. } else {
  1783. $object->accountancy_code_sell = $accountancy_code_sell;
  1784. }
  1785. }
  1786. if (GETPOSTISSET('accountancy_code_buy')) {
  1787. $accountancy_code_buy = GETPOST('accountancy_code_buy', 'alpha');
  1788. if (empty($accountancy_code_buy) || $accountancy_code_buy == '-1') {
  1789. $object->accountancy_code_buy = '';
  1790. } else {
  1791. $object->accountancy_code_buy = $accountancy_code_buy;
  1792. }
  1793. }
  1794. //Incoterms
  1795. if (isModEnabled('incoterm')) {
  1796. $object->fk_incoterms = GETPOST('incoterm_id', 'int');
  1797. $object->location_incoterms = GETPOST('lcoation_incoterms', 'alpha');
  1798. }
  1799. //Local Taxes
  1800. $object->localtax1_assuj = GETPOST('localtax1assuj_value');
  1801. $object->localtax2_assuj = GETPOST('localtax2assuj_value');
  1802. $object->localtax1_value = GETPOST('lt1');
  1803. $object->localtax2_value = GETPOST('lt2');
  1804. // We set country_id, and country_code label of the chosen country
  1805. if ($object->country_id > 0) {
  1806. $tmparray = getCountry($object->country_id, 'all');
  1807. $object->country_code = $tmparray['code'];
  1808. $object->country = $tmparray['label'];
  1809. }
  1810. // We set multicurrency_code if enabled
  1811. if (isModEnabled("multicurrency")) {
  1812. $object->multicurrency_code = GETPOST('multicurrency_code') ? GETPOST('multicurrency_code') : $object->multicurrency_code;
  1813. }
  1814. }
  1815. if ($object->localtax1_assuj == 0) {
  1816. $sub = 0;
  1817. } else {
  1818. $sub = 1;
  1819. }
  1820. if ($object->localtax2_assuj == 0) {
  1821. $sub2 = 0;
  1822. } else {
  1823. $sub2 = 1;
  1824. }
  1825. if (!empty($conf->use_javascript_ajax)) {
  1826. print "\n".'<script type="text/javascript">';
  1827. print '$(document).ready(function () {
  1828. var val='.$sub.';
  1829. var val2='.$sub2.';
  1830. if("#localtax1assuj_value".value==undefined){
  1831. if(val==1){
  1832. $(".cblt1").show();
  1833. }else{
  1834. $(".cblt1").hide();
  1835. }
  1836. }
  1837. if("#localtax2assuj_value".value==undefined){
  1838. if(val2==1){
  1839. $(".cblt2").show();
  1840. }else{
  1841. $(".cblt2").hide();
  1842. }
  1843. }
  1844. $("#localtax1assuj_value").change(function() {
  1845. var value=document.getElementById("localtax1assuj_value").value;
  1846. if(value==1){
  1847. $(".cblt1").show();
  1848. }else{
  1849. $(".cblt1").hide();
  1850. }
  1851. });
  1852. $("#localtax2assuj_value").change(function() {
  1853. var value=document.getElementById("localtax2assuj_value").value;
  1854. if(value==1){
  1855. $(".cblt2").show();
  1856. }else{
  1857. $(".cblt2").hide();
  1858. }
  1859. });
  1860. var canHaveCategoryIfNotCustomerProspectSupplier = ' . (empty($conf->global->THIRDPARTY_CAN_HAVE_CUSTOMER_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT) ? '0' : '1') . ';
  1861. init_customer_categ();
  1862. $("#customerprospect").change(function() {
  1863. init_customer_categ();
  1864. });
  1865. function init_customer_categ() {
  1866. console.log("is customer or prospect = "+jQuery("#customerprospect").val());
  1867. if (jQuery("#customerprospect").val() == 0 && !canHaveCategoryIfNotCustomerProspectSupplier)
  1868. {
  1869. jQuery(".visibleifcustomer").hide();
  1870. }
  1871. else
  1872. {
  1873. jQuery(".visibleifcustomer").show();
  1874. }
  1875. }
  1876. init_supplier_categ();
  1877. $("#fournisseur").change(function() {
  1878. init_supplier_categ();
  1879. });
  1880. function init_supplier_categ() {
  1881. console.log("is supplier = "+jQuery("#fournisseur").val());
  1882. if (jQuery("#fournisseur").val() == 0)
  1883. {
  1884. jQuery(".visibleifsupplier").hide();
  1885. }
  1886. else
  1887. {
  1888. jQuery(".visibleifsupplier").show();
  1889. }
  1890. };
  1891. $("#selectcountry_id").change(function() {
  1892. document.formsoc.action.value="edit";
  1893. document.formsoc.submit();
  1894. });
  1895. })';
  1896. print '</script>'."\n";
  1897. }
  1898. print '<form enctype="multipart/form-data" action="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'" method="post" name="formsoc">';
  1899. print '<input type="hidden" name="action" value="update">';
  1900. print '<input type="hidden" name="token" value="'.newToken().'">';
  1901. print '<input type="hidden" name="socid" value="'.$object->id.'">';
  1902. print '<input type="hidden" name="entity" value="'.$object->entity.'">';
  1903. if ($modCodeClient->code_auto || $modCodeFournisseur->code_auto) {
  1904. print '<input type="hidden" name="code_auto" value="1">';
  1905. }
  1906. print dol_get_fiche_head($head, 'card', $langs->trans("ThirdParty"), 0, 'company');
  1907. print '<div class="fichecenter2">';
  1908. print '<table class="border centpercent">';
  1909. // Ref/ID
  1910. if (!empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) {
  1911. print '<tr><td class="titlefieldcreate">'.$langs->trans("ID").'</td><td colspan="3">';
  1912. print $object->ref;
  1913. print '</td></tr>';
  1914. }
  1915. // Name
  1916. print '<tr><td class="titlefieldcreate">'.$form->editfieldkey('ThirdPartyName', 'name', '', $object, 0, 'string', '', 1).'</td>';
  1917. print '<td colspan="3"><input type="text" class="minwidth300" maxlength="128" name="name" id="name" value="'.dol_escape_htmltag($object->name).'" autofocus="autofocus">';
  1918. print $form->widgetForTranslation("name", $object, $permissiontoadd, 'string', 'alpahnohtml', 'minwidth300');
  1919. print '</td></tr>';
  1920. // Alias names (commercial, trademark or alias names)
  1921. print '<tr id="name_alias"><td><label for="name_alias_input">'.$langs->trans('AliasNames').'</label></td>';
  1922. 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>';
  1923. // Prefix
  1924. if (!empty($conf->global->SOCIETE_USEPREFIX)) { // Old not used prefix field
  1925. print '<tr><td>'.$form->editfieldkey('Prefix', 'prefix', '', $object, 0).'</td><td colspan="3">';
  1926. // It does not change the prefix mode using the auto numbering prefix
  1927. if (($prefixCustomerIsUsed || $prefixSupplierIsUsed) && $object->prefix_comm) {
  1928. print '<input type="hidden" name="prefix_comm" value="'.dol_escape_htmltag($object->prefix_comm).'">';
  1929. print $object->prefix_comm;
  1930. } else {
  1931. print '<input type="text" size="5" maxlength="5" name="prefix_comm" id="prefix" value="'.dol_escape_htmltag($object->prefix_comm).'">';
  1932. }
  1933. print '</td>';
  1934. }
  1935. // Prospect/Customer
  1936. print '<tr><td>'.$form->editfieldkey('ProspectCustomer', 'customerprospect', '', $object, 0, 'string', '', 1).'</td>';
  1937. print '<td class="maxwidthonsmartphone">';
  1938. print $formcompany->selectProspectCustomerType($object->client);
  1939. print '</td>';
  1940. if ($conf->browser->layout == 'phone') {
  1941. print '</tr><tr>';
  1942. }
  1943. print '<td>'.$form->editfieldkey('CustomerCode', 'customer_code', '', $object, 0).'</td><td>';
  1944. print '<table class="nobordernopadding"><tr><td>';
  1945. if ((!$object->code_client || $object->code_client == -1) && $modCodeClient->code_auto) {
  1946. $tmpcode = $object->code_client;
  1947. if (empty($tmpcode) && !empty($object->oldcopy->code_client)) {
  1948. $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.
  1949. }
  1950. if (empty($tmpcode) && !empty($modCodeClient->code_auto)) {
  1951. $tmpcode = $modCodeClient->getNextValue($object, 0);
  1952. }
  1953. print '<input type="text" name="customer_code" id="customer_code" size="16" value="'.dol_escape_htmltag($tmpcode).'" maxlength="24">';
  1954. } elseif ($object->codeclient_modifiable()) {
  1955. print '<input type="text" name="customer_code" id="customer_code" size="16" value="'.dol_escape_htmltag($object->code_client).'" maxlength="24">';
  1956. } else {
  1957. print $object->code_client;
  1958. print '<input type="hidden" name="customer_code" value="'.dol_escape_htmltag($object->code_client).'">';
  1959. }
  1960. print '</td><td>';
  1961. $s = $modCodeClient->getToolTip($langs, $object, 0);
  1962. print $form->textwithpicto('', $s, 1);
  1963. print '</td></tr></table>';
  1964. print '</td></tr>';
  1965. // Supplier
  1966. 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)))
  1967. || (isModEnabled('supplier_proposal') && !empty($user->rights->supplier_proposal->lire))) {
  1968. print '<tr>';
  1969. print '<td>'.$form->editfieldkey('Supplier', 'fournisseur', '', $object, 0, 'string', '', 1).'</td>';
  1970. print '<td class="maxwidthonsmartphone">';
  1971. print $form->selectyesno("fournisseur", $object->fournisseur, 1, false, 0, 1);
  1972. print '</td>';
  1973. if ($conf->browser->layout == 'phone') {
  1974. print '</tr><tr>';
  1975. }
  1976. print '<td>';
  1977. 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))) {
  1978. print $form->editfieldkey('SupplierCode', 'supplier_code', '', $object, 0);
  1979. }
  1980. print '</td>';
  1981. print '<td>';
  1982. print '<table class="nobordernopadding"><tr><td>';
  1983. if ((!$object->code_fournisseur || $object->code_fournisseur == -1) && $modCodeFournisseur->code_auto) {
  1984. $tmpcode = $object->code_fournisseur;
  1985. if (empty($tmpcode) && !empty($object->oldcopy->code_fournisseur)) {
  1986. $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.
  1987. }
  1988. if (empty($tmpcode) && !empty($modCodeFournisseur->code_auto)) {
  1989. $tmpcode = $modCodeFournisseur->getNextValue($object, 1);
  1990. }
  1991. print '<input type="text" name="supplier_code" id="supplier_code" size="16" value="'.dol_escape_htmltag($tmpcode).'" maxlength="24">';
  1992. } elseif ($object->codefournisseur_modifiable()) {
  1993. print '<input type="text" name="supplier_code" id="supplier_code" size="16" value="'.dol_escape_htmltag($object->code_fournisseur).'" maxlength="24">';
  1994. } else {
  1995. print $object->code_fournisseur;
  1996. print '<input type="hidden" name="supplier_code" value="'.$object->code_fournisseur.'">';
  1997. }
  1998. print '</td><td>';
  1999. $s = $modCodeFournisseur->getToolTip($langs, $object, 1);
  2000. print $form->textwithpicto('', $s, 1);
  2001. print '</td></tr></table>';
  2002. print '</td></tr>';
  2003. }
  2004. // Barcode
  2005. if (isModEnabled('barcode')) {
  2006. print '<tr><td class="tdtop">'.$form->editfieldkey('Gencod', 'barcode', '', $object, 0).'</td>';
  2007. print '<td colspan="3">';
  2008. print img_picto('', 'barcode');
  2009. print '<input type="text" name="barcode" id="barcode" value="'.dol_escape_htmltag($object->barcode).'">';
  2010. print '</td></tr>';
  2011. }
  2012. // Status
  2013. print '<tr><td>'.$form->editfieldkey('Status', 'status', '', $object, 0).'</td><td colspan="3">';
  2014. print $form->selectarray('status', array('0'=>$langs->trans('ActivityCeased'), '1'=>$langs->trans('InActivity')), $object->status, 0, 0, 0, '', 0, 0, 0, '', 'minwidth100', 1);
  2015. print '</td></tr>';
  2016. // Address
  2017. print '<tr><td class="tdtop">'.$form->editfieldkey('Address', 'address', '', $object, 0).'</td>';
  2018. print '<td colspan="3"><textarea name="address" id="address" class="quatrevingtpercent" rows="3" wrap="soft">';
  2019. print dol_escape_htmltag($object->address, 0, 1);
  2020. print '</textarea>';
  2021. print $form->widgetForTranslation("address", $object, $permissiontoadd, 'textarea', 'alphanohtml', 'quatrevingtpercent');
  2022. print '</td></tr>';
  2023. // Zip / Town
  2024. print '<tr><td>'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).'</td><td'.($conf->browser->layout == 'phone' ? ' colspan="3"': '').'>';
  2025. print $formcompany->select_ziptown($object->zip, 'zipcode', array('town', 'selectcountry_id', 'state_id'), 0, 0, '', 'maxwidth100');
  2026. print '</td>';
  2027. if ($conf->browser->layout == 'phone') {
  2028. print '</tr><tr>';
  2029. }
  2030. print '<td>'.$form->editfieldkey('Town', 'town', '', $object, 0).'</td><td'.($conf->browser->layout == 'phone' ? ' colspan="3"': '').'>';
  2031. print $formcompany->select_ziptown($object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id'));
  2032. print $form->widgetForTranslation("town", $object, $permissiontoadd, 'string', 'alphanohtml', 'maxwidth100 quatrevingtpercent');
  2033. print '</td></tr>';
  2034. // Country
  2035. print '<tr><td>'.$form->editfieldkey('Country', 'selectcounty_id', '', $object, 0).'</td><td colspan="3">';
  2036. print img_picto('', 'globe-americas', 'class="paddingrightonly"');
  2037. print $form->select_country((GETPOSTISSET('country_id') ? GETPOST('country_id') : $object->country_id), 'country_id', '', 0, 'minwidth300 maxwidth500 widthcentpercentminusx');
  2038. if ($user->admin) {
  2039. print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  2040. }
  2041. print '</td></tr>';
  2042. // State
  2043. if (empty($conf->global->SOCIETE_DISABLE_STATE)) {
  2044. 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)) {
  2045. print '<tr><td>'.$form->editfieldkey('Region-State', 'state_id', '', $object, 0).'</td><td colspan="3">';
  2046. } else {
  2047. print '<tr><td>'.$form->editfieldkey('State', 'state_id', '', $object, 0).'</td><td colspan="3">';
  2048. }
  2049. print img_picto('', 'state', 'class="pictofixedwidth"');
  2050. print $formcompany->select_state($object->state_id, $object->country_code);
  2051. print '</td></tr>';
  2052. }
  2053. // Phone / Fax
  2054. print '<tr><td>'.$form->editfieldkey('Phone', 'phone', GETPOST('phone', 'alpha'), $object, 0).'</td>';
  2055. 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>';
  2056. if ($conf->browser->layout == 'phone') {
  2057. print '</tr><tr>';
  2058. }
  2059. print '<td>'.$form->editfieldkey('Fax', 'fax', GETPOST('fax', 'alpha'), $object, 0).'</td>';
  2060. 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>';
  2061. print '</tr>';
  2062. // Web
  2063. print '<tr><td>'.$form->editfieldkey('Web', 'url', GETPOST('url', 'alpha'), $object, 0).'</td>';
  2064. 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>';
  2065. // EMail
  2066. print '<tr><td>'.$form->editfieldkey('EMail', 'email', GETPOST('email', 'alpha'), $object, 0, 'string', '', (!empty($conf->global->SOCIETE_EMAIL_MANDATORY))).'</td>';
  2067. print '<td colspan="3">';
  2068. print img_picto('', 'object_email', 'class="pictofixedwidth"');
  2069. print '<input type="text" name="email" id="email" class="maxwidth500 widthcentpercentminusx" value="'.(GETPOSTISSET('email') ?GETPOST('email', 'alpha') : $object->email).'">';
  2070. print '</td></tr>';
  2071. // Unsubscribe
  2072. if (!empty($conf->mailing->enabled)) {
  2073. if ($conf->use_javascript_ajax && isset($conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS) && $conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS == 2) {
  2074. print "\n".'<script type="text/javascript">'."\n";
  2075. print '
  2076. jQuery(document).ready(function () {
  2077. function init_check_no_email(input) {
  2078. if (input.val()!="") {
  2079. $(".noemail").addClass("fieldrequired");
  2080. } else {
  2081. $(".noemail").removeClass("fieldrequired");
  2082. }
  2083. }
  2084. $("#email").keyup(function() {
  2085. init_check_no_email($(this));
  2086. });
  2087. init_check_no_email($("#email"));
  2088. })'."\n";
  2089. print '</script>'."\n";
  2090. }
  2091. if (!GETPOSTISSET("no_email") && !empty($object->email)) {
  2092. $result = $object->getNoEmail();
  2093. if ($result < 0) {
  2094. setEventMessages($object->error, $object->errors, 'errors');
  2095. }
  2096. }
  2097. print '<tr>';
  2098. print '<td class="noemail"><label for="no_email">'.$langs->trans("No_Email").'</label></td>';
  2099. print '<td>';
  2100. $useempty = (isset($conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS) && ($conf->global->MAILING_CONTACT_DEFAULT_BULK_STATUS == 2));
  2101. print $form->selectyesno('no_email', (GETPOSTISSET("no_email") ? GETPOST("no_email", 'int') : $object->no_email), 1, false, $useempty);
  2102. print '</td>';
  2103. print '</tr>';
  2104. }
  2105. // Social network
  2106. if (isModEnabled('socialnetworks')) {
  2107. foreach ($socialnetworks as $key => $value) {
  2108. if ($value['active']) {
  2109. print '<tr>';
  2110. print '<td><label for="'.$value['label'].'">'.$form->editfieldkey($value['label'], $key, '', $object, 0).'</label></td>';
  2111. print '<td colspan="3">';
  2112. if (!empty($value['icon'])) {
  2113. print '<span class="fa '.$value['icon'].' pictofixedwidth"></span>';
  2114. }
  2115. print '<input type="text" name="'.$key.'" id="'.$key.'" class="minwidth100 maxwidth500 widthcentpercentminusx" maxlength="80" value="'.(empty($object->socialnetworks[$key]) ? '' : $object->socialnetworks[$key]).'">';
  2116. print '</td>';
  2117. print '</tr>';
  2118. } elseif (!empty($object->socialnetworks[$key])) {
  2119. print '<input type="hidden" name="'.$key.'" value="'.$object->socialnetworks[$key].'">';
  2120. }
  2121. }
  2122. }
  2123. // Prof ids
  2124. $i = 1;
  2125. $j = 0;
  2126. $NBCOLS = ($conf->browser->layout == 'phone' ? 1 : 2);
  2127. while ($i <= 6) {
  2128. $idprof = $langs->transcountry('ProfId'.$i, $object->country_code);
  2129. if ($idprof != '-') {
  2130. $key = 'idprof'.$i;
  2131. if (($j % $NBCOLS) == 0) {
  2132. print '<tr>';
  2133. }
  2134. $idprof_mandatory = 'SOCIETE_IDPROF'.($i).'_MANDATORY';
  2135. print '<td>'.$form->editfieldkey($idprof, $key, '', $object, 0, 'string', '', !(empty($conf->global->$idprof_mandatory) || !$object->isACompany())).'</td><td>';
  2136. print $formcompany->get_input_id_prof($i, $key, $object->$key, $object->country_code);
  2137. print '</td>';
  2138. if (($j % $NBCOLS) == ($NBCOLS - 1)) {
  2139. print '</tr>';
  2140. }
  2141. $j++;
  2142. }
  2143. $i++;
  2144. }
  2145. if ($NBCOLS > 0 && $j % 2 == 1) {
  2146. print '<td colspan="2"></td></tr>';
  2147. }
  2148. // VAT is used
  2149. print '<tr><td>'.$form->editfieldkey('VATIsUsed', 'assujtva_value', '', $object, 0).'</td><td colspan="3">';
  2150. print $form->selectyesno('assujtva_value', $object->tva_assuj, 1);
  2151. print '</td></tr>';
  2152. // Local Taxes
  2153. //TODO: Place into a function to control showing by country or study better option
  2154. if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1") {
  2155. print '<tr><td>'.$form->editfieldkey($langs->transcountry("LocalTax1IsUsed", $mysoc->country_code), 'localtax1assuj_value', '', $object, 0).'</td><td>';
  2156. print $form->selectyesno('localtax1assuj_value', $object->localtax1_assuj, 1);
  2157. if (!isOnlyOneLocalTax(1)) {
  2158. print '<span class="cblt1"> '.$langs->transcountry("Type", $mysoc->country_code).': ';
  2159. $formcompany->select_localtax(1, $object->localtax1_value, "lt1");
  2160. print '</span>';
  2161. }
  2162. print '</td>';
  2163. print '</tr><tr>';
  2164. print '<td>'.$form->editfieldkey($langs->transcountry("LocalTax2IsUsed", $mysoc->country_code), 'localtax2assuj_value', '', $object, 0).'</td><td>';
  2165. print $form->selectyesno('localtax2assuj_value', $object->localtax2_assuj, 1);
  2166. if (!isOnlyOneLocalTax(2)) {
  2167. print '<span class="cblt2"> '.$langs->transcountry("Type", $mysoc->country_code).': ';
  2168. $formcompany->select_localtax(2, $object->localtax2_value, "lt2");
  2169. print '</span>';
  2170. }
  2171. print '</td></tr>';
  2172. } elseif ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj != "1") {
  2173. print '<tr><td>'.$form->editfieldkey($langs->transcountry("LocalTax1IsUsed", $mysoc->country_code), 'localtax1assuj_value', '', $object, 0).'</td><td colspan="3">';
  2174. print $form->selectyesno('localtax1assuj_value', $object->localtax1_assuj, 1);
  2175. if (!isOnlyOneLocalTax(1)) {
  2176. print '<span class="cblt1"> '.$langs->transcountry("Type", $mysoc->country_code).': ';
  2177. $formcompany->select_localtax(1, $object->localtax1_value, "lt1");
  2178. print '</span>';
  2179. }
  2180. print '</td></tr>';
  2181. } elseif ($mysoc->localtax2_assuj == "1" && $mysoc->localtax1_assuj != "1") {
  2182. print '<tr><td>'.$form->editfieldkey($langs->transcountry("LocalTax2IsUsed", $mysoc->country_code), 'localtax2assuj_value', '', $object, 0).'</td><td colspan="3">';
  2183. print $form->selectyesno('localtax2assuj_value', $object->localtax2_assuj, 1);
  2184. if (!isOnlyOneLocalTax(2)) {
  2185. print '<span class="cblt2"> '.$langs->transcountry("Type", $mysoc->country_code).': ';
  2186. $formcompany->select_localtax(2, $object->localtax2_value, "lt2");
  2187. print '</span>';
  2188. }
  2189. print '</td></tr>';
  2190. }
  2191. // VAT Code
  2192. print '<tr><td>'.$form->editfieldkey('VATIntra', 'intra_vat', '', $object, 0).'</td>';
  2193. print '<td colspan="3">';
  2194. $s = '<input type="text" class="flat maxwidthonsmartphone" name="tva_intra" id="intra_vat" maxlength="20" value="'.$object->tva_intra.'">';
  2195. if (empty($conf->global->MAIN_DISABLEVATCHECK) && isInEEC($object)) {
  2196. $s .= ' &nbsp; ';
  2197. if ($conf->use_javascript_ajax) {
  2198. $widthpopup = 600;
  2199. if (!empty($conf->dol_use_jmobile)) {
  2200. $widthpopup = 350;
  2201. }
  2202. $heightpopup = 400;
  2203. print "\n";
  2204. print '<script type="text/javascript">';
  2205. print "function CheckVAT(a) {\n";
  2206. print "newpopup('".DOL_URL_ROOT."/societe/checkvat/checkVatPopup.php?vatNumber='+a,'".dol_escape_js($langs->trans("VATIntraCheckableOnEUSite"))."', ".$widthpopup.", ".$heightpopup.");\n";
  2207. print "}\n";
  2208. print '</script>';
  2209. print "\n";
  2210. $s .= '<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>';
  2211. $s = $form->textwithpicto($s, $langs->trans("VATIntraCheckDesc", $langs->transnoentitiesnoconv("VATIntraCheck")), 1);
  2212. } else {
  2213. $s .= '<a href="'.$langs->transcountry("VATIntraCheckURL", $object->country_id).'" class="hideonsmartphone" target="_blank" rel="noopener noreferrer">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"), 'help').'</a>';
  2214. }
  2215. }
  2216. print $s;
  2217. print '</td>';
  2218. print '</tr>';
  2219. // Type - Workforce/Staff
  2220. 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"' : '').'>';
  2221. 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);
  2222. if ($user->admin) {
  2223. print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  2224. }
  2225. if (empty($conf->global->SOCIETE_DISABLE_WORKFORCE)) {
  2226. print '</td>';
  2227. if ($conf->browser->layout == 'phone') {
  2228. print '</tr><tr>';
  2229. }
  2230. print '<td>'.$form->editfieldkey('Workforce', 'effectif_id', '', $object, 0).'</td><td class="maxwidthonsmartphone">';
  2231. print $form->selectarray("effectif_id", $formcompany->effectif_array(0), $object->effectif_id, 0, 0, 0, '', 0, 0, 0, '', '', 1);
  2232. if ($user->admin) {
  2233. print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  2234. }
  2235. } else {
  2236. print '<input type="hidden" name="effectif_id" id="effectif_id" value="'.$object->effectif_id.'">';
  2237. }
  2238. print '</td></tr>';
  2239. // Juridical type
  2240. print '<tr><td>'.$form->editfieldkey('JuridicalStatus', 'forme_juridique_code', '', $object, 0).'</td><td class="maxwidthonsmartphone" colspan="3">';
  2241. print $formcompany->select_juridicalstatus($object->forme_juridique_code, $object->country_code, '', 'forme_juridique_code');
  2242. print '</td></tr>';
  2243. // Capital
  2244. print '<tr><td>'.$form->editfieldkey('Capital', 'capital', '', $object, 0).'</td>';
  2245. print '<td colspan="3"><input type="text" name="capital" id="capital" size="10" value="';
  2246. print $object->capital != '' ? dol_escape_htmltag(price($object->capital)) : '';
  2247. if (isModEnabled("multicurrency")) {
  2248. print '"> <span class="hideonsmartphone">'.$langs->trans("Currency".$object->multicurrency_code).'</span></td></tr>';
  2249. } else {
  2250. print '"> <span class="hideonsmartphone">'.$langs->trans("Currency".$conf->currency).'</span></td></tr>';
  2251. }
  2252. // Default language
  2253. if (getDolGlobalInt('MAIN_MULTILANGS')) {
  2254. print '<tr><td>'.$form->editfieldkey('DefaultLang', 'default_lang', '', $object, 0).'</td><td colspan="3">'."\n";
  2255. print img_picto('', 'language', 'class="pictofixedwidth"').$formadmin->select_language($object->default_lang, 'default_lang', 0, null, '1', 0, 0, 'maxwidth300 widthcentpercentminusx');
  2256. print '</td>';
  2257. print '</tr>';
  2258. }
  2259. // Incoterms
  2260. if (isModEnabled('incoterm')) {
  2261. print '<tr>';
  2262. print '<td>'.$form->editfieldkey('IncotermLabel', 'incoterm_id', '', $object, 0).'</td>';
  2263. print '<td colspan="3" class="maxwidthonsmartphone">';
  2264. print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''));
  2265. print '</td></tr>';
  2266. }
  2267. // Categories
  2268. if (isModEnabled('categorie') && !empty($user->rights->categorie->lire)) {
  2269. // Customer
  2270. print '<tr class="visibleifcustomer"><td>'.$form->editfieldkey('CustomersCategoriesShort', 'custcats', '', $object, 0).'</td>';
  2271. print '<td colspan="3">';
  2272. $cate_arbo = $form->select_all_categories(Categorie::TYPE_CUSTOMER, null, null, null, null, 1);
  2273. $c = new Categorie($db);
  2274. $cats = $c->containing($object->id, Categorie::TYPE_CUSTOMER);
  2275. $arrayselected = array();
  2276. foreach ($cats as $cat) {
  2277. $arrayselected[] = $cat->id;
  2278. }
  2279. print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('custcats', $cate_arbo, $arrayselected, 0, 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
  2280. print "</td></tr>";
  2281. // Supplier
  2282. 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))) {
  2283. print '<tr class="visibleifsupplier"><td>'.$form->editfieldkey('SuppliersCategoriesShort', 'suppcats', '', $object, 0).'</td>';
  2284. print '<td colspan="3">';
  2285. $cate_arbo = $form->select_all_categories(Categorie::TYPE_SUPPLIER, null, null, null, null, 1);
  2286. $c = new Categorie($db);
  2287. $cats = $c->containing($object->id, Categorie::TYPE_SUPPLIER);
  2288. $arrayselected = array();
  2289. foreach ($cats as $cat) {
  2290. $arrayselected[] = $cat->id;
  2291. }
  2292. print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('suppcats', $cate_arbo, $arrayselected, 0, 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
  2293. print "</td></tr>";
  2294. }
  2295. }
  2296. // Multicurrency
  2297. if (isModEnabled("multicurrency")) {
  2298. print '<tr>';
  2299. print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
  2300. print '<td colspan="3" class="maxwidthonsmartphone">';
  2301. print img_picto('', 'currency', 'class="pictofixedwidth"');
  2302. print $form->selectMultiCurrency((GETPOSTISSET('multicurrency_code') ? GETPOST('multicurrency_code') : ($object->multicurrency_code ? $object->multicurrency_code : $conf->currency)), 'multicurrency_code', 1, '', false, 'maxwidth150 widthcentpercentminusx');
  2303. print '</td></tr>';
  2304. }
  2305. // Other attributes
  2306. $parameters = array('socid'=>$socid, 'colspan' => ' colspan="3"', 'colspanvalue' => '3');
  2307. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
  2308. // Parent company
  2309. if (empty($conf->global->SOCIETE_DISABLE_PARENTCOMPANY)) {
  2310. print '<tr>';
  2311. print '<td>'.$langs->trans('ParentCompany').'</td>';
  2312. print '<td colspan="3" class="maxwidthonsmartphone">';
  2313. print img_picto('', 'company', 'class="pictofixedwidth"');
  2314. 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');
  2315. print '</td></tr>';
  2316. }
  2317. // Webservices url/key
  2318. if (!empty($conf->syncsupplierwebservices->enabled)) {
  2319. print '<tr><td>'.$form->editfieldkey('WebServiceURL', 'webservices_url', '', $object, 0).'</td>';
  2320. print '<td><input type="text" name="webservices_url" id="webservices_url" size="32" value="'.$object->webservices_url.'"></td>';
  2321. print '<td>'.$form->editfieldkey('WebServiceKey', 'webservices_key', '', $object, 0).'</td>';
  2322. print '<td><input type="text" name="webservices_key" id="webservices_key" size="32" value="'.$object->webservices_key.'"></td></tr>';
  2323. }
  2324. // Logo
  2325. print '<tr class="hideonsmartphone">';
  2326. print '<td>'.$form->editfieldkey('Logo', 'photoinput', '', $object, 0).'</td>';
  2327. print '<td colspan="3">';
  2328. if ($object->logo) {
  2329. print $form->showphoto('societe', $object);
  2330. }
  2331. $caneditfield = 1;
  2332. if ($caneditfield) {
  2333. if ($object->logo) {
  2334. print "<br>\n";
  2335. }
  2336. print '<table class="nobordernopadding">';
  2337. if ($object->logo) {
  2338. print '<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> '.$langs->trans("Delete").'<br><br></td></tr>';
  2339. }
  2340. //print '<tr><td>'.$langs->trans("PhotoFile").'</td></tr>';
  2341. print '<tr><td>';
  2342. $maxfilesizearray = getMaxFileSizeArray();
  2343. $maxmin = $maxfilesizearray['maxmin'];
  2344. if ($maxmin > 0) {
  2345. print '<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).'">'; // MAX_FILE_SIZE must precede the field type=file
  2346. }
  2347. print '<input type="file" class="flat" name="photo" id="photoinput">';
  2348. print '</td></tr>';
  2349. print '</table>';
  2350. }
  2351. print '</td>';
  2352. print '</tr>';
  2353. // Assign sale representative
  2354. print '<tr>';
  2355. print '<td>'.$form->editfieldkey('AllocateCommercial', 'commercial_id', '', $object, 0).'</td>';
  2356. print '<td colspan="3" class="maxwidthonsmartphone">';
  2357. $userlist = $form->select_dolusers('', '', 0, null, 0, '', '', 0, 0, 0, 'AND u.statut = 1', 0, '', '', 0, 1);
  2358. $arrayselected = GETPOST('commercial', 'array');
  2359. if (empty($arrayselected)) {
  2360. $arrayselected = $object->getSalesRepresentatives($user, 1);
  2361. }
  2362. print img_picto('', 'user', 'class="pictofixedwidth"').$form->multiselectarray('commercial', $userlist, $arrayselected, 0, 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0, '', '', '', 1);
  2363. print '</td></tr>';
  2364. print '</table>';
  2365. if (!empty($conf->global->ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY)) {
  2366. print '<br>';
  2367. print '<table class="border centpercent">';
  2368. if (isModEnabled('accounting')) {
  2369. // Accountancy_code_sell
  2370. print '<tr><td class="titlefield">'.$langs->trans("ProductAccountancySellCode").'</td>';
  2371. print '<td>';
  2372. print $formaccounting->select_account($object->accountancy_code_sell, 'accountancy_code_sell', 1, '', 1, 1);
  2373. print '</td></tr>';
  2374. // Accountancy_code_buy
  2375. print '<tr><td>'.$langs->trans("ProductAccountancyBuyCode").'</td>';
  2376. print '<td>';
  2377. print $formaccounting->select_account($object->accountancy_code_buy, 'accountancy_code_buy', 1, '', 1, 1);
  2378. print '</td></tr>';
  2379. } else { // For external software
  2380. // Accountancy_code_sell
  2381. print '<tr><td class="titlefield">'.$langs->trans("ProductAccountancySellCode").'</td>';
  2382. print '<td><input name="accountancy_code_sell" class="maxwidth200" value="'.$object->accountancy_code_sell.'">';
  2383. print '</td></tr>';
  2384. // Accountancy_code_buy
  2385. print '<tr><td>'.$langs->trans("ProductAccountancyBuyCode").'</td>';
  2386. print '<td><input name="accountancy_code_buy" class="maxwidth200" value="'.$object->accountancy_code_buy.'">';
  2387. print '</td></tr>';
  2388. }
  2389. print '</table>';
  2390. }
  2391. print '</div>';
  2392. print dol_get_fiche_end();
  2393. print $form->buttonsSaveCancel();
  2394. print '</form>';
  2395. }
  2396. } else {
  2397. /*
  2398. * View
  2399. */
  2400. if (!empty($object->id)) {
  2401. $res = $object->fetch_optionals();
  2402. }
  2403. //if ($res < 0) { dol_print_error($db); exit; }
  2404. $head = societe_prepare_head($object);
  2405. print dol_get_fiche_head($head, 'card', $langs->trans("ThirdParty"), -1, 'company');
  2406. $formconfirm = '';
  2407. // Confirm delete third party
  2408. if ($action == 'delete' || ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile))) {
  2409. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id, $langs->trans("DeleteACompany"), $langs->trans("ConfirmDeleteCompany"), "confirm_delete", '', 0, "action-delete");
  2410. }
  2411. if ($action == 'merge') {
  2412. $formquestion = array(
  2413. array(
  2414. 'name' => 'soc_origin',
  2415. 'label' => $langs->trans('MergeOriginThirdparty'),
  2416. 'type' => 'other',
  2417. 'value' => $form->select_company('', 'soc_origin', '', 'SelectThirdParty', 0, 0, array(), 0, 'minwidth200', '', '', 1, null, false, array($object->id))
  2418. )
  2419. );
  2420. $formconfirm .= $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$object->id, $langs->trans("MergeThirdparties"), $langs->trans("ConfirmMergeThirdparties"), "confirm_merge", $formquestion, 'no', 1, 250);
  2421. }
  2422. // Call Hook formConfirm
  2423. $parameters = array('formConfirm' => $formconfirm);
  2424. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  2425. if (empty($reshook)) {
  2426. $formconfirm .= $hookmanager->resPrint;
  2427. } elseif ($reshook > 0) {
  2428. $formconfirm = $hookmanager->resPrint;
  2429. }
  2430. // Print form confirm
  2431. print $formconfirm;
  2432. dol_htmloutput_mesg(is_numeric($error) ? '' : $error, $errors, 'error');
  2433. $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  2434. dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
  2435. print '<div class="fichecenter">';
  2436. print '<div class="fichehalfleft">';
  2437. print '<div class="underbanner clearboth"></div>';
  2438. print '<table class="border tableforfield centpercent">';
  2439. // Type Prospect/Customer/Supplier
  2440. print '<tr><td class="titlefield">'.$langs->trans('NatureOfThirdParty').'</td><td>';
  2441. print $object->getTypeUrl(1);
  2442. print '</td></tr>';
  2443. // Prefix
  2444. if (!empty($conf->global->SOCIETE_USEPREFIX)) { // Old not used prefix field
  2445. print '<tr><td>'.$langs->trans('Prefix').'</td><td>'.dol_escape_htmltag($object->prefix_comm).'</td>';
  2446. print '</tr>';
  2447. }
  2448. // Customer code
  2449. if ($object->client) {
  2450. print '<tr><td>';
  2451. print $langs->trans('CustomerCode');
  2452. print '</td>';
  2453. print '<td>';
  2454. print showValueWithClipboardCPButton(dol_escape_htmltag($object->code_client));
  2455. $tmpcheck = $object->check_codeclient();
  2456. if ($tmpcheck != 0 && $tmpcheck != -5) {
  2457. print ' <span class="error">('.$langs->trans("WrongCustomerCode").')</span>';
  2458. }
  2459. print '</td>';
  2460. print '</tr>';
  2461. }
  2462. // Supplier code
  2463. 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) {
  2464. print '<tr><td>';
  2465. print $langs->trans('SupplierCode').'</td><td>';
  2466. print showValueWithClipboardCPButton(dol_escape_htmltag($object->code_fournisseur));
  2467. $tmpcheck = $object->check_codefournisseur();
  2468. if ($tmpcheck != 0 && $tmpcheck != -5) {
  2469. print ' <span class="error">('.$langs->trans("WrongSupplierCode").')</span>';
  2470. }
  2471. print '</td>';
  2472. print '</tr>';
  2473. }
  2474. // Barcode
  2475. if (isModEnabled('barcode')) {
  2476. print '<tr><td>';
  2477. print $langs->trans('Gencod').'</td><td>'.showValueWithClipboardCPButton(dol_escape_htmltag($object->barcode));
  2478. print '</td>';
  2479. print '</tr>';
  2480. }
  2481. // Prof ids
  2482. $i = 1; $j = 0;
  2483. while ($i <= 6) {
  2484. $idprof = $langs->transcountry('ProfId'.$i, $object->country_code);
  2485. if ($idprof != '-') {
  2486. //if (($j % 2) == 0) print '<tr>';
  2487. print '<tr>';
  2488. print '<td>'.$idprof.'</td><td>';
  2489. $key = 'idprof'.$i;
  2490. print dol_print_profids($object->$key, 'ProfId'.$i, $object->country_code, 1);
  2491. if ($object->$key) {
  2492. if ($object->id_prof_check($i, $object) > 0) {
  2493. if (!empty($object->id_prof_url($i, $object))) {
  2494. print ' &nbsp; '.$object->id_prof_url($i, $object);
  2495. }
  2496. } else {
  2497. print ' <span class="error">('.$langs->trans("ErrorWrongValue").')</span>';
  2498. }
  2499. }
  2500. print '</td>';
  2501. //if (($j % 2) == 1) print '</tr>';
  2502. print '</tr>';
  2503. $j++;
  2504. }
  2505. $i++;
  2506. }
  2507. //if ($j % 2 == 1) print '<td colspan="2"></td></tr>';
  2508. // 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.
  2509. // We don't need them into customer profile.
  2510. // Except for spain and localtax where localtax depends on buyer and not seller
  2511. if ($object->fournisseur) {
  2512. // VAT is used
  2513. print '<tr><td>';
  2514. print $form->textwithpicto($langs->trans('VATIsUsed'), $langs->trans('VATIsUsedWhenSelling'));
  2515. print '</td><td>';
  2516. print yn($object->tva_assuj);
  2517. print '</td>';
  2518. print '</tr>';
  2519. }
  2520. // Local Taxes
  2521. if ($object->fournisseur || $mysoc->country_code == 'ES') {
  2522. if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1") {
  2523. print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>';
  2524. print yn($object->localtax1_assuj);
  2525. print '</td></tr><tr><td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>';
  2526. print yn($object->localtax2_assuj);
  2527. print '</td></tr>';
  2528. if ($object->localtax1_assuj == "1" && (!isOnlyOneLocalTax(1))) {
  2529. print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
  2530. print '<input type="hidden" name="action" value="set_localtax1">';
  2531. print '<input type="hidden" name="token" value="'.newToken().'">';
  2532. 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>';
  2533. if ($action == 'editRE') {
  2534. print '<td class="left">';
  2535. $formcompany->select_localtax(1, $object->localtax1_value, "lt1");
  2536. print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'"></td>';
  2537. } else {
  2538. print '<td>'.$object->localtax1_value.'</td>';
  2539. }
  2540. print '</tr></form>';
  2541. }
  2542. if ($object->localtax2_assuj == "1" && (!isOnlyOneLocalTax(2))) {
  2543. print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
  2544. print '<input type="hidden" name="action" value="set_localtax2">';
  2545. print '<input type="hidden" name="token" value="'.newToken().'">';
  2546. 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>';
  2547. if ($action == 'editIRPF') {
  2548. print '<td class="left">';
  2549. $formcompany->select_localtax(2, $object->localtax2_value, "lt2");
  2550. print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'"></td>';
  2551. } else {
  2552. print '<td>'.$object->localtax2_value.'</td>';
  2553. }
  2554. print '</tr></form>';
  2555. }
  2556. } elseif ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj != "1") {
  2557. print '<tr><td>'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>';
  2558. print yn($object->localtax1_assuj);
  2559. print '</td></tr>';
  2560. if ($object->localtax1_assuj == "1" && (!isOnlyOneLocalTax(1))) {
  2561. print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
  2562. print '<input type="hidden" name="action" value="set_localtax1">';
  2563. print '<input type="hidden" name="token" value="'.newToken().'">';
  2564. 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>';
  2565. if ($action == 'editRE') {
  2566. print '<td class="left">';
  2567. $formcompany->select_localtax(1, $object->localtax1_value, "lt1");
  2568. print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'"></td>';
  2569. } else {
  2570. print '<td>'.$object->localtax1_value.'</td>';
  2571. }
  2572. print '</tr></form>';
  2573. }
  2574. } elseif ($mysoc->localtax2_assuj == "1" && $mysoc->localtax1_assuj != "1") {
  2575. print '<tr><td>'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>';
  2576. print yn($object->localtax2_assuj);
  2577. print '</td></tr>';
  2578. if ($object->localtax2_assuj == "1" && (!isOnlyOneLocalTax(2))) {
  2579. print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?socid='.$object->id.'">';
  2580. print '<input type="hidden" name="action" value="set_localtax2">';
  2581. print '<input type="hidden" name="token" value="'.newToken().'">';
  2582. 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>';
  2583. if ($action == 'editIRPF') {
  2584. print '<td class="left">';
  2585. $formcompany->select_localtax(2, $object->localtax2_value, "lt2");
  2586. print '<input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'"></td>';
  2587. } else {
  2588. print '<td>'.$object->localtax2_value.'</td>';
  2589. }
  2590. print '</tr></form>';
  2591. }
  2592. }
  2593. }
  2594. // Sale tax code (VAT code)
  2595. print '<tr>';
  2596. print '<td class="nowrap">'.$langs->trans('VATIntra').'</td><td>';
  2597. if ($object->tva_intra) {
  2598. $s = '';
  2599. $s .= dol_print_profids($object->tva_intra, 'VAT', $object->country_code, 1);
  2600. $s .= '<input type="hidden" id="tva_intra" name="tva_intra" maxlength="20" value="'.$object->tva_intra.'">';
  2601. if (empty($conf->global->MAIN_DISABLEVATCHECK) && isInEEC($object)) {
  2602. $s .= ' &nbsp; ';
  2603. if ($conf->use_javascript_ajax) {
  2604. $widthpopup = 600;
  2605. if (!empty($conf->dol_use_jmobile)) {
  2606. $widthpopup = 350;
  2607. }
  2608. $heightpopup = 400;
  2609. print "\n";
  2610. print '<script type="text/javascript">';
  2611. print "function CheckVAT(a) {\n";
  2612. print "newpopup('".DOL_URL_ROOT."/societe/checkvat/checkVatPopup.php?vatNumber='+a, '".dol_escape_js($langs->trans("VATIntraCheckableOnEUSite"))."', ".$widthpopup.", ".$heightpopup.");\n";
  2613. print "}\n";
  2614. print '</script>';
  2615. print "\n";
  2616. $s .= '<a href="#" class="hideonsmartphone" onclick="javascript: CheckVAT( $(\'#tva_intra\').val() );">'.$langs->trans("VATIntraCheck").'</a>';
  2617. $s = $form->textwithpicto($s, $langs->trans("VATIntraCheckDesc", $langs->transnoentitiesnoconv("VATIntraCheck")), 1);
  2618. } else {
  2619. $s .= '<a href="'.$langs->transcountry("VATIntraCheckURL", $object->country_id).'" class="hideonsmartphone" target="_blank" rel="noopener noreferrer">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"), 'help').'</a>';
  2620. }
  2621. }
  2622. print $s;
  2623. } else {
  2624. print '&nbsp;';
  2625. }
  2626. print '</td></tr>';
  2627. // Warehouse
  2628. if (isModEnabled('stock') && !empty($conf->global->SOCIETE_ASK_FOR_WAREHOUSE)) {
  2629. $langs->load('stocks');
  2630. require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
  2631. $formproduct = new FormProduct($db);
  2632. print '<tr class="nowrap">';
  2633. print '<td>';
  2634. print $form->editfieldkey("Warehouse", 'warehouse', '', $object, $user->rights->societe->creer);
  2635. print '</td><td>';
  2636. if ($action == 'editwarehouse') {
  2637. $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_warehouse, 'fk_warehouse', 1);
  2638. } else {
  2639. if ($object->fk_warehouse > 0) {
  2640. print img_picto('', 'stock', 'class="paddingrightonly"');
  2641. }
  2642. $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_warehouse, 'none');
  2643. }
  2644. print '</td>';
  2645. print '</tr>';
  2646. }
  2647. print '</table>';
  2648. print '</div>';
  2649. print '<div class="fichehalfright">';
  2650. print '<div class="underbanner clearboth"></div>';
  2651. print '<table class="border tableforfield centpercent">';
  2652. // Tags / categories
  2653. if (isModEnabled('categorie') && !empty($user->rights->categorie->lire)) {
  2654. // Customer
  2655. if ($object->prospect || $object->client || !empty($conf->global->THIRDPARTY_CAN_HAVE_CUSTOMER_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT)) {
  2656. print '<tr><td>'.$langs->trans("CustomersCategoriesShort").'</td>';
  2657. print '<td>';
  2658. print $form->showCategories($object->id, Categorie::TYPE_CUSTOMER, 1);
  2659. print "</td></tr>";
  2660. }
  2661. // Supplier
  2662. 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) {
  2663. print '<tr><td>'.$langs->trans("SuppliersCategoriesShort").'</td>';
  2664. print '<td>';
  2665. print $form->showCategories($object->id, Categorie::TYPE_SUPPLIER, 1);
  2666. print "</td></tr>";
  2667. }
  2668. }
  2669. // Third-Party Type
  2670. print '<tr><td>';
  2671. print '<table class="nobordernopadding" width="100%"><tr><td>'.$langs->trans('ThirdPartyType').'</td>';
  2672. if ($action != 'editthirdpartytype' && $user->hasRight('societe', 'creer')) {
  2673. 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>';
  2674. }
  2675. print '</tr></table>';
  2676. print '</td><td>';
  2677. $html_name = ($action == 'editthirdpartytype') ? 'typent_id' : 'none';
  2678. $formcompany->formThirdpartyType($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->typent_id, $html_name, '');
  2679. print '</td></tr>';
  2680. // Workforce/Staff
  2681. if (empty($conf->global->SOCIETE_DISABLE_WORKFORCE)) {
  2682. print '<tr><td>'.$langs->trans("Workforce").'</td><td>'.$object->effectif.'</td></tr>';
  2683. }
  2684. // Legal
  2685. print '<tr><td class="titlefield">'.$langs->trans('JuridicalStatus').'</td><td>'.$object->forme_juridique.'</td></tr>';
  2686. // Capital
  2687. print '<tr><td>'.$langs->trans('Capital').'</td><td>';
  2688. if ($object->capital) {
  2689. if (isModEnabled("multicurrency") && !empty($object->multicurrency_code)) {
  2690. print price($object->capital, '', $langs, 0, -1, -1, $object->multicurrency_code);
  2691. } else {
  2692. print price($object->capital, '', $langs, 0, -1, -1, $conf->currency);
  2693. }
  2694. } else {
  2695. print '&nbsp;';
  2696. }
  2697. print '</td></tr>';
  2698. // Unsubscribe opt-out
  2699. if (!empty($conf->mailing->enabled)) {
  2700. $result = $object->getNoEmail();
  2701. if ($result < 0) {
  2702. setEventMessages($object->error, $object->errors, 'errors');
  2703. }
  2704. print '<tr><td>'.$langs->trans("No_Email").'</td><td>';
  2705. if ($object->email) {
  2706. print yn($object->no_email);
  2707. } else {
  2708. print '<span class="opacitymedium">'.$langs->trans("EMailNotDefined").'</span>';
  2709. }
  2710. $langs->load("mails");
  2711. print ' &nbsp; <span class="badge badge-secondary" title="'.dol_escape_htmltag($langs->trans("NbOfEMailingsSend")).'">'.$object->getNbOfEMailings().'</span>';
  2712. print '</td></tr>';
  2713. }
  2714. // Default language
  2715. if (getDolGlobalInt('MAIN_MULTILANGS')) {
  2716. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  2717. print '<tr><td>'.$langs->trans("DefaultLang").'</td><td>';
  2718. //$s=picto_from_langcode($object->default_lang);
  2719. //print ($s?$s.' ':'');
  2720. $langs->load("languages");
  2721. $labellang = ($object->default_lang ? $langs->trans('Language_'.$object->default_lang) : '');
  2722. print picto_from_langcode($object->default_lang, 'class="paddingrightonly saturatemedium opacitylow"');
  2723. print $labellang;
  2724. print '</td></tr>';
  2725. }
  2726. // Incoterms
  2727. if (isModEnabled('incoterm')) {
  2728. print '<tr><td>';
  2729. print '<table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans('IncotermLabel').'</td>';
  2730. if ($action != 'editincoterm' && $user->hasRight('societe', 'creer')) {
  2731. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&action=editincoterm&token='.newToken().'">'.img_edit('', 1).'</a></td>';
  2732. }
  2733. print '</tr></table>';
  2734. print '</td><td colspan="3">';
  2735. if ($action != 'editincoterm') {
  2736. print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
  2737. } else {
  2738. print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?socid='.$object->id);
  2739. }
  2740. print '</td></tr>';
  2741. }
  2742. // Multicurrency
  2743. if (isModEnabled("multicurrency")) {
  2744. print '<tr>';
  2745. print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
  2746. print '<td>';
  2747. print !empty($object->multicurrency_code) ? currency_name($object->multicurrency_code, 1) : '';
  2748. print '</td></tr>';
  2749. }
  2750. if (!empty($conf->global->ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY)) {
  2751. // Accountancy sell code
  2752. print '<tr><td class="nowrap">';
  2753. print $langs->trans("ProductAccountancySellCode");
  2754. print '</td><td colspan="2">';
  2755. if (isModEnabled('accounting')) {
  2756. if (!empty($object->accountancy_code_sell)) {
  2757. $accountingaccount = new AccountingAccount($db);
  2758. $accountingaccount->fetch('', $object->accountancy_code_sell, 1);
  2759. print $accountingaccount->getNomUrl(0, 1, 1, '', 1);
  2760. }
  2761. } else {
  2762. print $object->accountancy_code_sell;
  2763. }
  2764. print '</td></tr>';
  2765. // Accountancy buy code
  2766. print '<tr><td class="nowrap">';
  2767. print $langs->trans("ProductAccountancyBuyCode");
  2768. print '</td><td colspan="2">';
  2769. if (isModEnabled('accounting')) {
  2770. if (!empty($object->accountancy_code_buy)) {
  2771. $accountingaccount2 = new AccountingAccount($db);
  2772. $accountingaccount2->fetch('', $object->accountancy_code_buy, 1);
  2773. print $accountingaccount2->getNomUrl(0, 1, 1, '', 1);
  2774. }
  2775. } else {
  2776. print $object->accountancy_code_buy;
  2777. }
  2778. print '</td></tr>';
  2779. }
  2780. // Other attributes
  2781. $parameters = array('socid'=>$socid, 'colspan' => ' colspan="3"', 'colspanvalue' => '3');
  2782. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  2783. // Parent company
  2784. if (empty($conf->global->SOCIETE_DISABLE_PARENTCOMPANY)) {
  2785. print '<tr><td>';
  2786. print '<table class="nobordernopadding" width="100%"><tr><td>'.$langs->trans('ParentCompany').'</td>';
  2787. if ($action != 'editparentcompany' && $user->hasRight('societe', 'creer')) {
  2788. 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>';
  2789. }
  2790. print '</tr></table>';
  2791. print '</td><td>';
  2792. $html_name = ($action == 'editparentcompany') ? 'parent_id' : 'none';
  2793. $form->form_thirdparty($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->parent, $html_name, '', 1, 0, 0, null, 0, array($object->id));
  2794. print '</td></tr>';
  2795. }
  2796. // Sales representative
  2797. include DOL_DOCUMENT_ROOT.'/societe/tpl/linesalesrepresentative.tpl.php';
  2798. // Module Adherent
  2799. if (isModEnabled('adherent')) {
  2800. $langs->load("members");
  2801. print '<tr><td>'.$langs->trans("LinkedToDolibarrMember").'</td>';
  2802. print '<td>';
  2803. $adh = new Adherent($db);
  2804. $result = $adh->fetch('', '', $object->id);
  2805. if ($result > 0) {
  2806. $adh->ref = $adh->getFullName($langs);
  2807. print $adh->getNomUrl(-1);
  2808. } else {
  2809. print '<span class="opacitymedium">'.$langs->trans("ThirdpartyNotLinkedToMember").'</span>';
  2810. }
  2811. print "</td></tr>\n";
  2812. }
  2813. // Link user (you must create a contact to get a user)
  2814. /*
  2815. print '<tr><td>'.$langs->trans("DolibarrLogin").'</td><td colspan="3">';
  2816. if ($object->user_id) {
  2817. $dolibarr_user = new User($db);
  2818. $result = $dolibarr_user->fetch($object->user_id);
  2819. print $dolibarr_user->getLoginUrl(-1);
  2820. } else {
  2821. //print '<span class="opacitymedium">'.$langs->trans("NoDolibarrAccess").'</span>';
  2822. if (!$object->user_id && $user->rights->user->user->creer) {
  2823. 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>';
  2824. }
  2825. }
  2826. print '</td></tr>';
  2827. */
  2828. // Webservices url/key
  2829. if (!empty($conf->syncsupplierwebservices->enabled)) {
  2830. print '<tr><td>'.$langs->trans("WebServiceURL").'</td><td>'.dol_print_url($object->webservices_url).'</td>';
  2831. print '<td class="nowrap">'.$langs->trans('WebServiceKey').'</td><td>'.$object->webservices_key.'</td></tr>';
  2832. }
  2833. print '</table>';
  2834. print '</div>';
  2835. print '</div>';
  2836. print '<div style="clear:both"></div>';
  2837. print dol_get_fiche_end();
  2838. /*
  2839. * Actions
  2840. */
  2841. if ($action != 'presend') {
  2842. print '<div class="tabsAction">'."\n";
  2843. $parameters = array();
  2844. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  2845. if (empty($reshook)) {
  2846. $at_least_one_email_contact = false;
  2847. $TContact = $object->contact_array_objects();
  2848. foreach ($TContact as &$contact) {
  2849. if (!empty($contact->email)) {
  2850. $at_least_one_email_contact = true;
  2851. break;
  2852. }
  2853. }
  2854. if (empty($user->socid)) {
  2855. $langs->load("mails");
  2856. $title = '';
  2857. if (empty($object->email) && !$at_least_one_email_contact) { $title = $langs->trans('NoEMail'); }
  2858. 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);
  2859. }
  2860. print dolGetButtonAction('', $langs->trans('Modify'), 'default', $_SERVER["PHP_SELF"].'?socid='.$object->id.'&action=edit&token='.newToken(), '', $permissiontoadd);
  2861. if (isModEnabled('adherent')) {
  2862. $adh = new Adherent($db);
  2863. $result = $adh->fetch('', '', $object->id);
  2864. if ($result == 0 && ($object->client == 1 || $object->client == 3) && !empty($conf->global->MEMBER_CAN_CONVERT_CUSTOMERS_TO_MEMBERS)) {
  2865. 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";
  2866. }
  2867. }
  2868. print dolGetButtonAction($langs->trans('MergeThirdparties'), $langs->trans('Merge'), 'danger', $_SERVER["PHP_SELF"].'?socid='.$object->id.'&action=merge&token='.newToken(), '', $permissiontodelete);
  2869. if ($user->hasRight('societe', 'supprimer')) {
  2870. $deleteUrl = $_SERVER["PHP_SELF"].'?socid='.$object->id.'&action=delete&token='.newToken();
  2871. $buttonId = 'action-delete-no-ajax';
  2872. if ($conf->use_javascript_ajax && empty($conf->dol_use_jmobile)) { // We can't use preloaded confirm form with jmobile
  2873. $deleteUrl = '';
  2874. $buttonId = 'action-delete';
  2875. }
  2876. print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $deleteUrl, $buttonId, $permissiontodelete);
  2877. }
  2878. }
  2879. print '</div>'."\n";
  2880. }
  2881. //Select mail models is same action as presend
  2882. if (GETPOST('modelselected')) {
  2883. $action = 'presend';
  2884. }
  2885. if ($action != 'presend') {
  2886. print '<div class="fichecenter"><div class="fichehalfleft">';
  2887. if (empty($conf->global->SOCIETE_DISABLE_BUILDDOC)) {
  2888. print '<a name="builddoc"></a>'; // ancre
  2889. /*
  2890. * Generated documents
  2891. */
  2892. $filedir = $conf->societe->multidir_output[$object->entity].'/'.$object->id;
  2893. $urlsource = $_SERVER["PHP_SELF"]."?socid=".$object->id;
  2894. $genallowed = $user->hasRight('societe', 'lire');
  2895. $delallowed = $user->hasRight('societe', 'creer');
  2896. 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);
  2897. }
  2898. // Subsidiaries list
  2899. if (empty($conf->global->SOCIETE_DISABLE_PARENTCOMPANY) && empty($conf->global->SOCIETE_DISABLE_SHOW_SUBSIDIARIES)) {
  2900. $result = show_subsidiaries($conf, $langs, $db, $object);
  2901. }
  2902. print '</div><div class="fichehalfright">';
  2903. $MAXEVENT = 10;
  2904. $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id);
  2905. // List of actions on element
  2906. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  2907. $formactions = new FormActions($db);
  2908. $somethingshown = $formactions->showactions($object, '', $socid, 1, '', $MAXEVENT, '', $morehtmlcenter); // Show all action for thirdparty
  2909. print '</div></div>';
  2910. if (!empty($conf->global->MAIN_DUPLICATE_CONTACTS_TAB_ON_MAIN_CARD)) {
  2911. // Contacts list
  2912. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
  2913. $result = show_contacts($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id);
  2914. }
  2915. // Addresses list
  2916. if (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT)) {
  2917. $result = show_addresses($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id);
  2918. }
  2919. }
  2920. }
  2921. // Presend form
  2922. $modelmail = 'thirdparty';
  2923. $defaulttopic = 'Information';
  2924. $diroutput = $conf->societe->multidir_output[$object->entity];
  2925. $trackid = 'thi'.$object->id;
  2926. include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
  2927. }
  2928. }
  2929. // End of page
  2930. llxFooter();
  2931. $db->close();