soc.php 108 KB

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