card.php 134 KB

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