card.php 141 KB

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