card.php 129 KB

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