card.php 118 KB

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