card.php 128 KB

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