card.php 141 KB

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