card.php 128 KB

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