card.php 142 KB

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