PageRenderTime 31ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/societe/view.php

https://bitbucket.org/speedealing/speedealing
PHP | 1367 lines | 989 code | 158 blank | 220 comment | 254 complexity | 39905976478614665c8978b8bbf2a7e4 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT

Large files files are truncated, but you can click here to view the full file

  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-2011 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-2011 Juanjo Menent <jmenent@2byte.es>
  9. * Copyright (C) 2010-2012 Herve Prot <herve.prot@symeos.com>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. */
  24. if (!defined('NOTOKENRENEWAL'))
  25. define('NOTOKENRENEWAL', '1'); // Disables token renewal
  26. if (!defined('NOREQUIREMENU'))
  27. define('NOREQUIREMENU', '1');
  28. if (!defined('NOHEADER'))
  29. define('NOHEADER', '1');
  30. //if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
  31. //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
  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/class/html.formadmin.class.php");
  37. require_once(DOL_DOCUMENT_ROOT . "/core/class/html.formcompany.class.php");
  38. require_once(DOL_DOCUMENT_ROOT . "/core/class/html.formfile.class.php");
  39. require_once(DOL_DOCUMENT_ROOT . "/core/class/extrafields.class.php");
  40. require_once(DOL_DOCUMENT_ROOT . "/contact/class/contact.class.php");
  41. if ($conf->adherent->enabled)
  42. require_once(DOL_DOCUMENT_ROOT . "/adherents/class/adherent.class.php");
  43. if ($conf->highcharts->enabled)
  44. dol_include_once("/highCharts/class/highCharts.class.php");
  45. $langs->load("companies");
  46. $langs->load("commercial");
  47. $langs->load("bills");
  48. $langs->load("banks");
  49. $langs->load("users");
  50. if ($conf->notification->enabled)
  51. $langs->load("mails");
  52. $mesg = '';
  53. $error = 0;
  54. $errors = array();
  55. $action = (GETPOST('action', 'alpha') ? GETPOST('action', 'alpha') : 'view');
  56. $confirm = GETPOST('confirm', 'alpha');
  57. $cancel = GETPOST('cancel', 'alpha');
  58. $socid = GETPOST('id', 'alpha');
  59. if ($user->societe_id)
  60. $socid = $user->societe_id;
  61. // Security check
  62. $result = restrictedArea($user, 'societe', $socid, '&societe', '', 'fk_soc', 'rowid', $objcanvas);
  63. /*
  64. * Actions
  65. */
  66. if (empty($reshook)) {
  67. if ($_POST["getcustomercode"]) {
  68. // We defined value code_client
  69. $_POST["code_client"] = "Acompleter";
  70. }
  71. if ($_POST["getsuppliercode"]) {
  72. // We defined value code_fournisseur
  73. $_POST["code_fournisseur"] = "Acompleter";
  74. }
  75. // Add new third party
  76. if ((!$_POST["getcustomercode"] && !$_POST["getsuppliercode"])
  77. && ($action == 'add' || $action == 'update') && empty($cancel) && $user->rights->societe->creer) {
  78. require_once(DOL_DOCUMENT_ROOT . "/core/lib/functions2.lib.php");
  79. if ($action == 'update')
  80. $object = $couchdb->getDoc($socid);
  81. else
  82. $object->canvas = $canvas;
  83. if (GETPOST("private") == 1) {
  84. $object->particulier = GETPOST("private");
  85. $object->name = empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION) ? trim($_POST["prenom"] . ' ' . $_POST["nom"]) : trim($_POST["nom"] . ' ' . $_POST["prenom"]);
  86. $object->civilite_id = (int) $_POST["civilite_id"];
  87. // Add non official properties
  88. $object->name_bis = $_POST["nom"];
  89. $object->firstname = $_POST["prenom"];
  90. } else {
  91. $object->name = ucwords($_POST["nom"]);
  92. }
  93. $object->Address = $_POST["Address"];
  94. $object->Zip = $_POST["Zip"];
  95. $object->Town = $_POST["Town"];
  96. $object->Country = $_POST["Country"];
  97. $object->State = $_POST["State"];
  98. $tel = preg_replace("/\s/", "", $_POST["Phone"]);
  99. $tel = preg_replace("/\./", "", $tel);
  100. $fax = preg_replace("/\s/", "", $_POST["Fax"]);
  101. $fax = preg_replace("/\./", "", $fax);
  102. if ($tel) {
  103. $object->AddressBook->Phone->value = $tel;
  104. $object->AddressBook->Phone->type = "AC_TEL";
  105. }
  106. if ($fax) {
  107. $object->AddressBook->Fax->value = $fax;
  108. $object->AddressBook->Fax->type = "AC_FAX";
  109. }
  110. $email = $_POST["email"];
  111. if ($email) {
  112. $object->AddressBook->EMail->value = $email;
  113. $object->AddressBook->EMail->type = "AC_EMAIL";
  114. }
  115. $object->Url->Web = clean_url(trim($_POST["Web"]), 0);
  116. if (!empty($_POST['Deal'])) {
  117. foreach ($_POST['Deal'] as $key => $aRow) {
  118. $object->Deal->$key = $aRow;
  119. /* $object->idprof["idprof2"] = $_POST["idprof2"];
  120. $object->idprof["idprof3"] = $_POST["idprof3"];
  121. $object->idprof["idprof4"] = $_POST["idprof4"]; */
  122. }
  123. }
  124. $object->prefix_comm = $_POST["prefix_comm"];
  125. $object->Accounting->CustomerCode = $_POST["code_client"];
  126. $object->Accounting->SupplierCode = $_POST["code_fournisseur"];
  127. $object->Accounting->VATIsUsed = (bool) $_POST["assujtva_value"];
  128. $object->Accounting->VATIntra = dol_sanitizeFileName($_POST["tva_intra"], '');
  129. $object->Accounting->localtax1_assuj = (int) $_POST["localtax1assuj_value"];
  130. $object->Accounting->localtax2_assuj = (int) $_POST["localtax2assuj_value"];
  131. $object->Deal->JuridicalStatus = $_POST["forme_juridique_code"];
  132. $object->Deal->Capital = price2num(trim($_POST["capital"]), 'MT') . " " . $langs->trans("Currency" . $conf->currency);
  133. $object->Deal->Staff = $_POST["effectif_id"];
  134. $object->barcode = $_POST["barcode"];
  135. $object->status = (int) $_POST["status"];
  136. $object->tms = dol_now();
  137. if (GETPOST("private") == 1) {
  138. $object->typent_id = 8; // TODO predict another method if the field "special" change of rowid
  139. } else {
  140. $object->typent_id = $_POST["typent_id"];
  141. }
  142. $object->client = (int) $_POST["client"];
  143. $object->fournisseur = (int) $_POST["fournisseur"];
  144. $object->fournisseur_categorie = $_POST["fournisseur_categorie"];
  145. $object->commercial_id = $_POST["commercial_id"];
  146. $object->default_lang = $_POST["default_lang"];
  147. if ($conf->map->enabled) {
  148. //Retire le CEDEX de la ville :
  149. $town = $_POST["town"];
  150. $town = strtolower($town);
  151. $find = "cedex";
  152. $pos = strpos($town, $find);
  153. if ($pos != false) {
  154. $town = substr($town, 0, $pos);
  155. }
  156. $apiUrl = "http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=" . urlencode($_POST["adresse"] . "," . $_POST["zipcode"] . "," . $town);
  157. $c = curl_init();
  158. curl_setopt($c, CURLOPT_URL, $apiUrl);
  159. curl_setopt($c, CURLOPT_HEADER, false);
  160. curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
  161. // make the call
  162. $json = curl_exec($c);
  163. $response = json_decode($json);
  164. curl_close($c);
  165. if ($response->status == "OK") {
  166. $object->gps = array($response->results[0]->geometry->location->lat, $response->results[0]->geometry->location->lng);
  167. } else {
  168. $object->gps = array(0, 0);
  169. }
  170. }
  171. if (GETPOST('deletephoto'))
  172. $object->logo = '';
  173. else if (!empty($_FILES['photo']['name']))
  174. $object->logo = dol_sanitizeFileName($_FILES['photo']['name']);
  175. // Check parameters
  176. if (empty($_POST["cancel"])) {
  177. if (!empty($object->url->Web) && !isValidUrl($object->url->Web)) {
  178. $langs->load("errors");
  179. $error++;
  180. $errors[] = $langs->trans("ErrorBadUrl", $object->url->Web);
  181. $action = ($action == 'add' ? 'create' : 'edit');
  182. }
  183. if ($object->fournisseur && !$conf->fournisseur->enabled) {
  184. $langs->load("errors");
  185. $error++;
  186. $errors[] = $langs->trans("ErrorSupplierModuleNotEnabled");
  187. $action = ($action == 'add' ? 'create' : 'edit');
  188. }
  189. /* for ($i = 1; $i < 3; $i++)
  190. {
  191. $slabel="idprof".$i;
  192. if (($_POST[$slabel] && $object->id_prof_verifiable($i)))
  193. {
  194. if($object->id_prof_exists($i,$_POST["$slabel"],$object->id))
  195. {
  196. $langs->load("errors");
  197. $error++; $errors[] = $langs->transcountry('ProfId'.$i, $object->country_id)." ".$langs->trans("ErrorProdIdAlreadyExist", $_POST[$slabel]);
  198. $action = ($action=='add'?'create':'edit');
  199. }
  200. }
  201. } */
  202. }
  203. if (!$error) {
  204. if ($action == 'add') {
  205. if (!empty($conf->global->MAIN_FIRST_TO_UPPER))
  206. $object->name = ucwords($object->name);
  207. dol_syslog(get_class($object) . "::create " . $object->name);
  208. // Check parameters
  209. if (!empty($conf->global->SOCIETE_MAIL_REQUIRED) && !isValidEMail($object->email)) {
  210. $langs->load("errors");
  211. $message = $langs->trans("ErrorBadEMail", $object->email);
  212. return -1;
  213. }
  214. $object->tms = dol_now();
  215. // For automatic creation during create action (not used by Dolibarr GUI, can be used by scripts)
  216. if ($object->Accounting->CustomCode == -1)
  217. $compta->setCode("CustomerCode", $object->get_codeclient($object->prefix_comm, 0));
  218. if ($object->Accounting->SupplierCode == -1)
  219. $compta->setCode("SupplierCode", $object->get_codefournisseur($object->prefix_comm, 1));
  220. if (!$message) {
  221. try {
  222. $object->record();
  223. Header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $object->id);
  224. exit;
  225. } catch (Exception $e) {
  226. $message = "Something weird happened: " . $e->getMessage() . " (errcode=" . $e->getCode() . ")\n";
  227. dol_syslog("Ego::Create " . $message, LOG_ERR);
  228. }
  229. }
  230. $message = '<div class="error">' . $message . '</div>';
  231. $action = "create";
  232. $result = 0; // TODO go next
  233. if ($result >= 0) {
  234. if ($object->particulier) {
  235. dol_syslog("This thirdparty is a personal people", LOG_DEBUG);
  236. $contact = new Contact($db);
  237. $contact->civilite_id = $object->civilite_id;
  238. $contact->name = $object->name_bis;
  239. $contact->firstname = $object->firstname;
  240. $contact->address = $object->address;
  241. $contact->zip = $object->zip;
  242. $contact->town = $object->town;
  243. $contact->state_id = $object->state_id;
  244. $contact->country_id = $object->country_id;
  245. $contact->socid = $object->id; // fk_soc
  246. $contact->status = 1;
  247. $contact->email = $object->email;
  248. $contact->phone_pro = $object->tel;
  249. $contact->fax = $object->fax;
  250. $contact->priv = 0;
  251. $result = $contact->create($user);
  252. if (!$result >= 0) {
  253. $error = $contact->error;
  254. $errors = $contact->errors;
  255. }
  256. }
  257. // Gestion du logo de la société
  258. $dir = $conf->societe->multidir_output[$conf->entity] . "/" . $object->id . "/logos/";
  259. $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
  260. if ($file_OK) {
  261. if (image_format_supported($_FILES['photo']['name'])) {
  262. dol_mkdir($dir);
  263. if (@is_dir($dir)) {
  264. $newfile = $dir . '/' . dol_sanitizeFileName($_FILES['photo']['name']);
  265. $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
  266. if (!$result > 0) {
  267. $errors[] = "ErrorFailedToSaveFile";
  268. } else {
  269. // Create small thumbs for company (Ratio is near 16/9)
  270. // Used on logon for example
  271. $imgThumbSmall = vignette($newfile, $maxwidthsmall, $maxheightsmall, '_small', $quality);
  272. // Create mini thumbs for company (Ratio is near 16/9)
  273. // Used on menu or for setup page for example
  274. $imgThumbMini = vignette($newfile, $maxwidthmini, $maxheightmini, '_mini', $quality);
  275. }
  276. }
  277. }
  278. }
  279. // Gestion du logo de la société
  280. } else {
  281. $error = $object->error;
  282. $errors = $object->errors;
  283. }
  284. if ($result >= 0) {
  285. $db->commit();
  286. $url = $_SERVER["PHP_SELF"] . "?id=" . $object->id;
  287. if (($object->client == 1 || $object->client == 3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS))
  288. $url = DOL_URL_ROOT . "/comm/fiche.php?socid=" . $object->id;
  289. else if ($object->fournisseur == 1)
  290. $url = DOL_URL_ROOT . "/fourn/fiche.php?socid=" . $object->id;
  291. Header("Location: " . $url);
  292. exit;
  293. }
  294. else {
  295. $db->rollback();
  296. $action = 'create';
  297. }
  298. }
  299. if ($action == 'update') {
  300. if ($_POST["cancel"]) {
  301. Header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $socid);
  302. exit;
  303. }
  304. $backtopage = '';
  305. if (!empty($_POST["backtopage"]))
  306. $backtopage = $_POST["backtopage"];
  307. $oldcopy = dol_clone($object);
  308. ### Calcul des coordonnées GPS
  309. if ($conf->map->enabled) {
  310. //Retire le CEDEX de la ville :
  311. $town = $_POST["town"];
  312. $town = strtolower($town);
  313. $find = "cedex";
  314. $pos = strpos($town, $find);
  315. if ($pos != false) {
  316. $town = substr($town, 0, $pos);
  317. //print $town;exit;
  318. }
  319. $apiUrl = "http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=" . urlencode($_POST["adresse"] . "," . $_POST["zipcode"] . "," . $_POST["town"]);
  320. $c = curl_init();
  321. curl_setopt($c, CURLOPT_URL, $apiUrl);
  322. curl_setopt($c, CURLOPT_HEADER, false);
  323. curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
  324. // make the call
  325. $json = curl_exec($c);
  326. $response = json_decode($json);
  327. curl_close($c);
  328. if ($response->status == "OK") {
  329. $object->gps = array($response->results[0]->geometry->location->lat, $response->results[0]->geometry->location->lng);
  330. } else {
  331. $object->gps = array(0, 0);
  332. }
  333. }
  334. // To not set code if third party is not concerned. But if it had values, we keep them.
  335. if (empty($object->client) && empty($oldcopy->code_client))
  336. $object->code_client = '';
  337. if (empty($object->fournisseur) && empty($oldcopy->code_fournisseur))
  338. $object->code_fournisseur = '';
  339. //var_dump($object);exit;
  340. $soc = new Societe($db);
  341. // For automatic creation during create action (not used by Dolibarr GUI, can be used by scripts)
  342. if ($object->Accounting->CustomCode == -1)
  343. $object->Accounting->CustomCode = $soc->get_codeclient($object->prefix_comm, 0);
  344. if ($object->Accounting->SupplierCode == -1)
  345. $object->Accounting->SupplierCode = $soc->get_codefournisseur($object->prefix_comm, 1);
  346. //$object->update($socid,$user,1,$oldcopy->codeclient_modifiable(),$oldcopy->codefournisseur_modifiable());
  347. try {
  348. $couchdb->clean($object);
  349. $couchdb->storeDoc($object);
  350. $result = 1;
  351. } catch (Exception $e) {
  352. $error = "Something weird happened: " . $e->getMessage() . " (errcode=" . $e->getCode() . ")\n";
  353. print $error;
  354. exit;
  355. }
  356. if ($result <= 0) {
  357. $error = $object->error;
  358. $errors = $object->errors;
  359. }
  360. // Gestion du logo de la société
  361. $dir = $conf->societe->multidir_output[$object->entity] . "/" . $object->_id . "/logos";
  362. $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
  363. if ($file_OK) {
  364. if (GETPOST('deletephoto')) {
  365. $fileimg = $dir . '/' . $object->logo;
  366. $dirthumbs = $dir . '/thumbs';
  367. dol_delete_file($fileimg);
  368. dol_delete_dir_recursive($dirthumbs);
  369. }
  370. if (image_format_supported($_FILES['photo']['name']) > 0) {
  371. dol_mkdir($dir);
  372. if (@is_dir($dir)) {
  373. $newfile = $dir . '/' . dol_sanitizeFileName($_FILES['photo']['name']);
  374. $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
  375. if (!$result > 0) {
  376. $errors[] = "ErrorFailedToSaveFile";
  377. } else {
  378. // Create small thumbs for company (Ratio is near 16/9)
  379. // Used on logon for example
  380. $imgThumbSmall = vignette($newfile, $maxwidthsmall, $maxheightsmall, '_small', $quality);
  381. // Create mini thumbs for company (Ratio is near 16/9)
  382. // Used on menu or for setup page for example
  383. $imgThumbMini = vignette($newfile, $maxwidthmini, $maxheightmini, '_mini', $quality);
  384. }
  385. }
  386. } else {
  387. $errors[] = "ErrorBadImageFormat";
  388. }
  389. }
  390. // Gestion du logo de la société
  391. if (!$error && !count($errors)) {
  392. Header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $socid);
  393. exit;
  394. } else {
  395. //$object->id = $socid;
  396. $action = "edit";
  397. }
  398. }
  399. }
  400. }
  401. // Delete third party
  402. if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->societe->supprimer) {
  403. $object = new Societe($db);
  404. $object->load($socid);
  405. $result = $object->delete();
  406. if ($result > 0) {
  407. Header("Location: " . DOL_URL_ROOT . "/comm/list.php");
  408. exit;
  409. } else {
  410. $langs->load("errors");
  411. $error = $langs->trans($object->error);
  412. $errors = $object->errors;
  413. $action = '';
  414. }
  415. }
  416. /*
  417. * Generate document
  418. */
  419. if ($action == 'builddoc') { // En get ou en post
  420. if (is_numeric(GETPOST('model'))) {
  421. $error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Model"));
  422. } else {
  423. require_once(DOL_DOCUMENT_ROOT . '/core/models/modules_societe.class.php');
  424. $object = new Societe($db);
  425. $object->load($socid);
  426. $object->fetch_thirdparty();
  427. // Define output language
  428. $outputlangs = $langs;
  429. $newlang = '';
  430. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && !empty($_REQUEST['lang_id']))
  431. $newlang = $_REQUEST['lang_id'];
  432. if ($conf->global->MAIN_MULTILANGS && empty($newlang))
  433. $newlang = $fac->client->default_lang;
  434. if (!empty($newlang)) {
  435. $outputlangs = new Translate();
  436. $outputlangs->setDefaultLang($newlang);
  437. }
  438. $result = thirdparty_doc_create($db, $object->id, '', $_REQUEST['model'], $outputlangs);
  439. if ($result <= 0) {
  440. dol_print_error($db, $result);
  441. exit;
  442. } else {
  443. Header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . (empty($conf->global->MAIN_JUMP_TAG) ? '' : '#builddoc'));
  444. exit;
  445. }
  446. }
  447. }
  448. }
  449. /*
  450. * View
  451. */
  452. llxHeader('', $langs->trans("ThirdParty"));
  453. $form = new Form($db);
  454. $formfile = new FormFile($db);
  455. $formadmin = new FormAdmin($db);
  456. $formcompany = new FormCompany($db);
  457. $countrynotdefined = $langs->trans("ErrorSetACountryFirst") . ' (' . $langs->trans("SeeAbove") . ')';
  458. if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
  459. // -----------------------------------------
  460. // When used with CANVAS
  461. // -----------------------------------------
  462. if (!$objcanvas->hasActions() && $socid) {
  463. $object = new Societe($db);
  464. $object->load($socid); // For use with "pure canvas" (canvas that contains templates only)
  465. }
  466. $objcanvas->assign_values($action, $socid); // Set value for templates
  467. $objcanvas->display_canvas($action); // Show template
  468. } else {
  469. // -----------------------------------------
  470. // When used in standard mode
  471. // -----------------------------------------
  472. if ($action == 'create') {
  473. /*
  474. * Creation
  475. */
  476. // Load object modCodeTiers
  477. $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
  478. if (!$module)
  479. dolibarr_error('', $langs->trans("ErrorModuleThirdPartyCodeInCompanyModuleNotDefined"));
  480. if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') {
  481. $module = substr($module, 0, dol_strlen($module) - 4);
  482. }
  483. $dirsociete = array_merge(array('/societe/core/models/'), $conf->societe_modules);
  484. foreach ($dirsociete as $dirroot) {
  485. $res = dol_include_once($dirroot . $module . ".php");
  486. if ($res)
  487. break;
  488. }
  489. $modCodeClient = new $module;
  490. $module = $conf->global->SOCIETE_CODEFOURNISSEUR_ADDON;
  491. if (!$module)
  492. $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
  493. if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') {
  494. $module = substr($module, 0, dol_strlen($module) - 4);
  495. }
  496. $dirsociete = array_merge(array('/societe/core/models/'), $conf->societe_modules);
  497. foreach ($dirsociete as $dirroot) {
  498. $res = dol_include_once($dirroot . $module . ".php");
  499. if ($res)
  500. break;
  501. }
  502. $modCodeFournisseur = new $module;
  503. //if ($_GET["type"]=='cp') { $object->client=3; }
  504. if (GETPOST("type") != 'f') {
  505. $object->client = 3;
  506. }
  507. if (GETPOST("type") == 'c') {
  508. $object->client = 1;
  509. }
  510. if (GETPOST("type") == 'p') {
  511. $object->client = 2;
  512. }
  513. if ($conf->fournisseur->enabled && (GETPOST("type") == 'f' || GETPOST("type") == '')) {
  514. $object->fournisseur = 1;
  515. }
  516. if (GETPOST("private") == 1) {
  517. $object->particulier = 1;
  518. }
  519. $object->name = $_POST["nom"];
  520. $object->firstname = $_POST["prenom"];
  521. $object->particulier = GETPOST('private', 'int');
  522. $object->prefix_comm = $_POST["prefix_comm"];
  523. $object->client = $_POST["client"] ? $_POST["client"] : $object->client;
  524. $object->code_client = $_POST["code_client"];
  525. $object->fournisseur = $_POST["fournisseur"] ? $_POST["fournisseur"] : $object->fournisseur;
  526. $object->code_fournisseur = $_POST["code_fournisseur"];
  527. $object->address = $_POST["adresse"];
  528. $object->zip = $_POST["zipcode"];
  529. $object->town = $_POST["town"];
  530. $object->state_id = $_POST["departement_id"];
  531. $object->tel = $_POST["tel"];
  532. $object->fax = $_POST["fax"];
  533. $object->email = $_POST["email"];
  534. $object->url = $_POST["url"];
  535. $object->capital = $_POST["capital"];
  536. $object->barcode = $_POST["barcode"];
  537. $object->idprof1 = $_POST["idprof1"];
  538. $object->idprof2 = $_POST["idprof2"];
  539. $object->idprof3 = $_POST["idprof3"];
  540. $object->idprof4 = $_POST["idprof4"];
  541. $object->typent_id = $_POST["typent_id"];
  542. $object->effectif_id = $_POST["effectif_id"];
  543. $object->civility_id = $_POST["civilite_id"];
  544. $object->tva_assuj = $_POST["assujtva_value"];
  545. $object->status = $_POST["status"];
  546. //Local Taxes
  547. $object->localtax1_assuj = $_POST["localtax1assuj_value"];
  548. $object->localtax2_assuj = $_POST["localtax2assuj_value"];
  549. $object->tva_intra = $_POST["tva_intra"];
  550. $object->commercial_id = $_POST["commercial_id"];
  551. $object->default_lang = $_POST["default_lang"];
  552. $object->logo = dol_sanitizeFileName($_FILES['photo']['name']);
  553. // Gestion du logo de la société
  554. $dir = $conf->societe->multidir_output[$object->entity] . "/" . $object->id . "/logos";
  555. $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
  556. if ($file_OK) {
  557. if (image_format_supported($_FILES['photo']['name'])) {
  558. dol_mkdir($dir);
  559. if (@is_dir($dir)) {
  560. $newfile = $dir . '/' . dol_sanitizeFileName($_FILES['photo']['name']);
  561. $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
  562. if (!$result > 0) {
  563. $errors[] = "ErrorFailedToSaveFile";
  564. } else {
  565. // Create small thumbs for company (Ratio is near 16/9)
  566. // Used on logon for example
  567. $imgThumbSmall = vignette($newfile, $maxwidthsmall, $maxheightsmall, '_small', $quality);
  568. // Create mini thumbs for company (Ratio is near 16/9)
  569. // Used on menu or for setup page for example
  570. $imgThumbMini = vignette($newfile, $maxwidthmini, $maxheightmini, '_mini', $quality);
  571. }
  572. }
  573. }
  574. }
  575. // We set country_id, country_id and country for the selected country
  576. $object->country_id = $_POST["country_id"] ? $_POST["country_id"] : $mysoc->country_id;
  577. if ($object->country_id) {
  578. $tmparray = getCountry($object->country_id, 'all');
  579. $object->country_id = $tmparray['code'];
  580. $object->country = $tmparray['label'];
  581. }
  582. $object->forme_juridique_code = $_POST['forme_juridique_code'];
  583. /* Show create form */
  584. print_fiche_titre($langs->trans("NewCompany"));
  585. if ($conf->use_javascript_ajax) {
  586. print "\n" . '<script type="text/javascript">';
  587. print '$(document).ready(function () {
  588. id_te_private=8;
  589. id_ef15=1;
  590. is_private=' . (GETPOST("private") ? GETPOST("private") : 0) . ';
  591. if (is_private) {
  592. $(".individualline").show();
  593. } else {
  594. $(".individualline").hide();
  595. }
  596. $("#radiocompany").click(function() {
  597. $(".individualline").hide();
  598. $("#typent_id").val(0);
  599. $("#effectif_id").val(0);
  600. $("#TypeName").html(document.formsoc.ThirdPartyName.value);
  601. document.formsoc.private.value=0;
  602. });
  603. $("#radioprivate").click(function() {
  604. $(".individualline").show();
  605. $("#typent_id").val(id_te_private);
  606. $("#effectif_id").val(id_ef15);
  607. $("#TypeName").html(document.formsoc.LastName.value);
  608. document.formsoc.private.value=1;
  609. });
  610. $("#selectcountry_id").change(function() {
  611. document.formsoc.action.value="create";
  612. document.formsoc.submit();
  613. });
  614. });';
  615. print '</script>' . "\n";
  616. print "<br>\n";
  617. print $langs->trans("ThirdPartyType") . ': &nbsp; ';
  618. print '<input type="radio" id="radiocompany" class="flat" name="private" value="0"' . (!GETPOST("private") ? ' checked="checked"' : '');
  619. print '> ' . $langs->trans("Company/Fundation");
  620. print ' &nbsp; &nbsp; ';
  621. print '<input type="radio" id="radioprivate" class="flat" name="private" value="1"' . (!GETPOST("private") ? '' : ' checked="checked"');
  622. print '> ' . $langs->trans("Individual");
  623. print ' (' . $langs->trans("ToCreateContactWithSameName") . ')';
  624. print "<br>\n";
  625. print "<br>\n";
  626. }
  627. dol_htmloutput_errors($error, $errors);
  628. print '<form enctype="multipart/form-data" action="' . $_SERVER["PHP_SELF"] . '" method="post" name="formsoc">';
  629. print '<input type="hidden" name="action" value="add">';
  630. print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
  631. print '<input type="hidden" name="private" value=' . $object->particulier . '>';
  632. print '<input type="hidden" name="type" value=' . GETPOST("type") . '>';
  633. print '<input type="hidden" name="LastName" value="' . $langs->trans('LastName') . '">';
  634. print '<input type="hidden" name="ThirdPartyName" value="' . $langs->trans('ThirdPartyName') . '">';
  635. if ($modCodeClient->code_auto || $modCodeFournisseur->code_auto)
  636. print '<input type="hidden" name="code_auto" value="1">';
  637. print '<table class="border" width="100%">';
  638. // Name, firstname
  639. if ($object->particulier || GETPOST("private")) {
  640. print '<tr><td><span id="TypeName" class="fieldrequired">' . $langs->trans('LastName') . '</span></td><td' . (empty($conf->global->SOCIETE_USEPREFIX) ? ' colspan="3"' : '') . '><input type="text" size="30" maxlength="60" name="nom" value="' . $object->name . '"></td>';
  641. if (!empty($conf->global->SOCIETE_USEPREFIX)) { // Old not used prefix field
  642. print '<td>' . $langs->trans('Prefix') . '</td><td><input type="text" size="5" maxlength="5" name="prefix_comm" value="' . $object->prefix_comm . '"></td>';
  643. }
  644. print '</tr>';
  645. } else {
  646. print '<tr><td><span span id="TypeName" class="fieldrequired">' . $langs->trans('ThirdPartyName') . '</span></td><td' . (empty($conf->global->SOCIETE_USEPREFIX) ? ' colspan="3"' : '') . '><input type="text" size="30" maxlength="60" name="nom" value="' . $object->name . '"></td>';
  647. if (!empty($conf->global->SOCIETE_USEPREFIX)) { // Old not used prefix field
  648. print '<td>' . $langs->trans('Prefix') . '</td><td><input type="text" size="5" maxlength="5" name="prefix_comm" value="' . $object->prefix_comm . '"></td>';
  649. }
  650. print '</tr>';
  651. }
  652. // If javascript on, we show option individual
  653. if ($conf->use_javascript_ajax) {
  654. print '<tr class="individualline"><td>' . $langs->trans('FirstName') . '</td><td><input type="text" size="30" name="prenom" value="' . $object->firstname . '"></td>';
  655. print '<td colspan=2>&nbsp;</td></tr>';
  656. print '<tr class="individualline"><td>' . $langs->trans("UserTitle") . '</td><td>';
  657. print $formcompany->select_civility($object->civility_id) . '</td>';
  658. print '<td colspan=2>&nbsp;</td></tr>';
  659. }
  660. // Prospect/Customer
  661. print '<tr><td width="25%"><span class="fieldrequired">' . $langs->trans('ProspectCustomer') . '</span></td><td width="25%"><select class="flat" name="client">';
  662. $selected = isset($_POST['client']) ? GETPOST('client') : $object->client;
  663. if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS))
  664. print '<option value="2"' . ($selected == 2 ? ' selected="selected"' : '') . '>' . $langs->trans('Prospect') . '</option>';
  665. if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS))
  666. print '<option value="3"' . ($selected == 3 ? ' selected="selected"' : '') . '>' . $langs->trans('ProspectCustomer') . '</option>';
  667. print '<option value="1"' . ($selected == 1 ? ' selected="selected"' : '') . '>' . $langs->trans('Customer') . '</option>';
  668. print '<option value="0"' . ($selected == 0 ? ' selected="selected"' : '') . '>' . $langs->trans('NorProspectNorCustomer') . '</option>';
  669. print '</select></td>';
  670. print '<td width="25%">' . $langs->trans('CustomerCode') . '</td><td width="25%">';
  671. print '<table class="nobordernopadding"><tr><td>';
  672. $tmpcode = $object->code_client;
  673. if ($modCodeClient->code_auto)
  674. $tmpcode = $modCodeClient->getNextValue($object, 0);
  675. print '<input type="text" name="code_client" size="16" value="' . $tmpcode . '" maxlength="15">';
  676. print '</td><td>';
  677. $s = $modCodeClient->getToolTip($langs, $object, 0);
  678. print $form->textwithpicto('', $s, 1);
  679. print '</td></tr></table>';
  680. print '</td></tr>';
  681. if ($conf->fournisseur->enabled && !empty($user->rights->fournisseur->lire)) {
  682. // Supplier
  683. print '<tr>';
  684. print '<td><span class="fieldrequired">' . $langs->trans('Supplier') . '</span></td><td>';
  685. print $form->selectyesno("fournisseur", (isset($_POST['fournisseur']) ? GETPOST('fournisseur') : $object->fournisseur), 1);
  686. print '</td>';
  687. print '<td>' . $langs->trans('SupplierCode') . '</td><td>';
  688. print '<table class="nobordernopadding"><tr><td>';
  689. $tmpcode = $object->code_fournisseur;
  690. if ($modCodeFournisseur->code_auto)
  691. $tmpcode = $modCodeFournisseur->getNextValue($object, 1);
  692. print '<input type="text" name="code_fournisseur" size="16" value="' . $tmpcode . '" maxlength="15">';
  693. print '</td><td>';
  694. $s = $modCodeFournisseur->getToolTip($langs, $object, 1);
  695. print $form->textwithpicto('', $s, 1);
  696. print '</td></tr></table>';
  697. print '</td></tr>';
  698. // Category
  699. /* if ($object->fournisseur)
  700. {
  701. $load = $object->LoadSupplierCateg();
  702. if ( $load == 0)
  703. {
  704. if (count($object->SupplierCategories) > 0)
  705. {
  706. print '<tr>';
  707. print '<td>'.$langs->trans('SupplierCategory').'</td><td colspan="3">';
  708. print $form->selectarray("fournisseur_categorie",$object->SupplierCategories,$_POST["fournisseur_categorie"],1);
  709. print '</td></tr>';
  710. }
  711. }
  712. } */
  713. }
  714. // Status
  715. print '<tr><td>' . $langs->trans('Status') . '</td><td colspan="3">';
  716. print $form->selectarray('status', array('0' => $langs->trans('ActivityCeased'), '1' => $langs->trans('InActivity')), 1);
  717. print '</td></tr>';
  718. // Barcode
  719. if ($conf->global->MAIN_MODULE_BARCODE) {
  720. print '<tr><td>' . $langs->trans('Gencod') . '</td><td colspan="3"><input type="text" name="barcode" value="' . $object->barcode . '">';
  721. print '</td></tr>';
  722. }
  723. // Address
  724. print '<tr><td valign="top">' . $langs->trans('Address') . '</td><td colspan="3"><textarea name="adresse" cols="40" rows="3" wrap="soft">';
  725. print $object->address;
  726. print '</textarea></td></tr>';
  727. // Zip / Town
  728. print '<tr><td>' . $langs->trans('Zip') . '</td><td>';
  729. print $formcompany->select_ziptown($object->zip, 'zipcode', array('town', 'selectcountry_id', 'departement_id'), 6);
  730. print '</td><td>' . $langs->trans('Town') . '</td><td>';
  731. print $formcompany->select_ziptown($object->town, 'town', array('zipcode', 'selectcountry_id', 'departement_id'));
  732. print '</td></tr>';
  733. // Country
  734. print '<tr><td width="25%">' . $langs->trans('Country') . '</td><td colspan="3">';
  735. print $form->select_country($object->country_id, 'country_id');
  736. if ($user->admin)
  737. print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"), 1);
  738. print '</td></tr>';
  739. // State
  740. if (empty($conf->global->SOCIETE_DISABLE_STATE)) {
  741. print '<tr><td>' . $langs->trans('State') . '</td><td colspan="3">';
  742. if ($object->country_id)
  743. print $formcompany->select_state($object->state_id, $object->country_id, 'departement_id');
  744. else
  745. print $countrynotdefined;
  746. print '</td></tr>';
  747. }
  748. // Phone / Fax
  749. print '<tr><td>' . $langs->trans('Phone') . '</td><td><input type="text" name="tel" value="' . $object->tel . '"></td>';
  750. print '<td>' . $langs->trans('Fax') . '</td><td><input type="text" name="fax" value="' . $object->fax . '"></td></tr>';
  751. print '<tr><td>' . $langs->trans('EMail') . ($conf->global->SOCIETE_MAIL_REQUIRED ? '*' : '') . '</td><td><input type="text" name="email" size="32" value="' . $object->email . '"></td>';
  752. print '<td>' . $langs->trans('Web') . '</td><td><input type="text" name="url" size="32" value="' . $object->url . '"></td></tr>';
  753. // Prof ids
  754. $i = 1;
  755. $j = 0;
  756. while ($i <= 6) {
  757. $idprof = $langs->transcountry('ProfId' . $i, $object->country_id);
  758. if ($idprof != '-') {
  759. if (($j % 2) == 0)
  760. print '<tr>';
  761. print '<td>' . $idprof . '</td><td>';
  762. $key = 'idprof' . $i;
  763. print $formcompany->get_input_id_prof($i, 'idprof' . $i, $object->$key, $object->country_id);
  764. print '</td>';
  765. if (($j % 2) == 1)
  766. print '</tr>';
  767. $j++;
  768. }
  769. $i++;
  770. }
  771. if ($j % 2 == 1)
  772. print '<td colspan="2"></td></tr>';
  773. // Assujeti TVA
  774. $form = new Form($db);
  775. print '<tr><td>' . $langs->trans('VATIsUsed') . '</td>';
  776. print '<td>';
  777. print $form->selectyesno('assujtva_value', 1, 1); // Assujeti par defaut en creation
  778. print '</td>';
  779. print '<td nowrap="nowrap">' . $langs->trans('VATIntra') . '</td>';
  780. print '<td nowrap="nowrap">';
  781. $s = '<input type="text" class="flat" name="tva_intra" size="12" maxlength="20" value="' . $object->tva_intra . '">';
  782. if (empty($conf->global->MAIN_DISABLEVATCHECK)) {
  783. $s.=' ';
  784. if ($conf->use_javascript_ajax) {
  785. print "\n";
  786. print '<script language="JavaScript" type="text/javascript">';
  787. print "function CheckVAT(a) {\n";
  788. print "newpopup('" . DOL_URL_ROOT . "/societe/checkvat/checkVatPopup.php?vatNumber='+a,'" . dol_escape_js($langs->trans("VATIntraCheckableOnEUSite")) . "',500,230);\n";
  789. print "}\n";
  790. print '</script>';
  791. print "\n";
  792. $s.='<a href="#" onclick="javascript: CheckVAT(document.formsoc.tva_intra.value);">' . $langs->trans("VATIntraCheck") . '</a>';
  793. $s = $form->textwithpicto($s, $langs->trans("VATIntraCheckDesc", $langs->trans("VATIntraCheck")), 1);
  794. } else {
  795. $s.='<a href="' . $langs->transcountry("VATIntraCheckURL", $object->id_pays) . '" target="_blank">' . img_picto($langs->trans("VATIntraCheckableOnEUSite"), 'help') . '</a>';
  796. }
  797. }
  798. print $s;
  799. print '</td>';
  800. print '</tr>';
  801. // Type - Size
  802. print '<tr><td>' . $langs->trans("ThirdPartyType") . '</td><td>' . "\n";
  803. print $form->selectarray("typent_id", $formcompany->typent_array(0), $object->typent_id);
  804. if ($user->admin)
  805. print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"), 1);
  806. print '</td>';
  807. print '<td>' . $langs->trans("Staff") . '</td><td>';
  808. print $form->selectarray("effectif_id", $formcompany->effectif_array(0), $object->effectif_id);
  809. if ($user->admin)
  810. print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"), 1);
  811. print '</td></tr>';
  812. // Legal Form
  813. print '<tr><td>' . $langs->trans('JuridicalStatus') . '</td>';
  814. print '<td colspan="3">';
  815. if ($object->country_id) {
  816. $formcompany->select_forme_juridique($object->forme_juridique_code, $object->country_id);
  817. } else {
  818. print $countrynotdefined;
  819. }
  820. print '</td></tr>';
  821. // Capital
  822. print '<tr><td>' . $langs->trans('Capital') . '</td><td colspan="3"><input type="text" name="capital" size="10" value="' . $object->capital . '"> ' . $langs->trans("Currency" . $conf->currency) . '</td></tr>';
  823. // Local Taxes
  824. // TODO add specific function by country
  825. if ($mysoc->country_id == 'ES') {
  826. if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1") {
  827. print '<tr><td>' . $langs->trans("LocalTax1IsUsedES") . '</td><td>';
  828. print $form->selectyesno('localtax1assuj_value', 0, 1);
  829. print '</td><td>' . $langs->trans("LocalTax2IsUsedES") . '</td><td>';
  830. print $form->selectyesno('localtax2assuj_value', 0, 1);
  831. print '</td></tr>';
  832. } elseif ($mysoc->localtax1_assuj == "1") {
  833. print '<tr><td>' . $langs->trans("LocalTax1IsUsedES") . '</td><td colspan="3">';
  834. print $form->selectyesno('localtax1assuj_value', 0, 1);
  835. print '</td><tr>';
  836. } elseif ($mysoc->localtax2_assuj == "1") {
  837. print '<tr><td>' . $langs->trans("LocalTax2IsUsedES") . '</td><td colspan="3">';
  838. print $form->selectyesno('localtax2assuj_value', 0, 1);
  839. print '</td><tr>';
  840. }
  841. }
  842. if ($conf->global->MAIN_MULTILANGS) {
  843. print '<tr><td>' . $langs->trans("DefaultLang") . '</td><td colspan="3">' . "\n";
  844. print $formadmin->select_language(($object->default_lang ? $object->default_lang : $conf->global->MAIN_LANG_DEFAULT), 'default_lang', 0, 0, 1);
  845. print '</td>';
  846. print '</tr>';
  847. }
  848. if ($user->rights->societe->client->voir) {
  849. // Assign a Name
  850. print '<tr>';
  851. print '<td>' . $langs->trans("AllocateCommercial") . '</td>';
  852. print '<td colspan="3">';
  853. $form->select_users($object->commercial_id, 'commercial_id', 1);
  854. print '</td></tr>';
  855. }
  856. // Ajout du logo
  857. print '<tr>';
  858. print '<td>' . $langs->trans("Logo") . '</td>';
  859. print '<td colspan="3">';
  860. print '<input class="flat" type="file" name="photo" id="photoinput" />';
  861. print '</td>';
  862. print '</tr>';
  863. print '</table>' . "\n";
  864. print '<br><center>';
  865. print '<input type="submit" class="button" value="' . $langs->trans('AddThirdParty') . '">';
  866. print '</center>' . "\n";
  867. print '</form>' . "\n";
  868. } elseif ($action == 'edit') {
  869. /*
  870. * Edition
  871. */
  872. $object = new Societe($db);
  873. try {
  874. $object->load($socid);
  875. } catch (Exception $e) {
  876. $error = "Something weird happened: " . $e->getMessage() . " (errcode=" . $e->getCode() . ")\n";
  877. print $error;
  878. exit;
  879. }
  880. // Load object modCodeTiers
  881. $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
  882. if (!$module)
  883. dolibarr_error('', $langs->trans("ErrorModuleThirdPartyCodeInCompanyModuleNotDefined"));
  884. if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') {
  885. $module = substr($module, 0, dol_strlen($module) - 4);
  886. }
  887. $dirsociete = array_merge(array('/societe/core/models/'), $conf->societe_modules);
  888. foreach ($dirsociete as $dirroot) {
  889. $res = dol_include_once($dirroot . $module . ".php");
  890. if ($res)
  891. break;
  892. }
  893. $modCodeClient = new $module;
  894. $module = $conf->global->SOCIETE_CODEFOURNISSEUR_ADDON;
  895. if (!$module)
  896. $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
  897. if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') {
  898. $module = substr($module, 0, dol_strlen($module) - 4);
  899. }
  900. $dirsociete = array_merge(array('/societe/core/models/'), $conf->societe_modules);
  901. foreach ($dirsociete as $dirroot) {
  902. $res = dol_include_once($dirroot . $module . ".php");
  903. if ($res)
  904. break;
  905. }
  906. $modCodeFournisseur = new $module;
  907. if (!empty($_POST["ThirdPartyName"])) {
  908. // We overwrite with values if posted
  909. $object->ThirdPartyName = $_POST["ThirdPartyName"];
  910. $object->prefix_comm = $_POST["prefix_comm"];
  911. $object->client = $_POST["client"];
  912. $object->code_client = $_POST["code_client"];
  913. $object->fournisseur = $_POST["fournisseur"];
  914. $object->code_fournisseur = $_POST["code_fournisseur"];
  915. $object->address = $_POST["adresse"];
  916. $object->zip = $_POST["zipcode"];
  917. $object->town = $_POST["town"];
  918. $object->country_id = $_POST["country_id"] ? $_POST["country_id"] : $mysoc->country_id;
  919. $object->Country = $_POST["Country"] ? $_POST["Country"] : $mysoc->country_code;
  920. $object->state_id = $_POST["departement_id"];
  921. $object->tel = $_POST["tel"];
  922. $object->fax = $_POST["fax"];
  923. $object->email = $_POST["email"];
  924. $object->url = $_POST["url"];
  925. $object->capital = $_POST["capital"];
  926. $object->idprof1 = $_POST["idprof1"];
  927. $object->idprof2 = $_POST["idprof2"];
  928. $object->idprof3 = $_POST["idprof3"];
  929. $object->idprof4 = $_POST["idprof4"];
  930. $object->typent_id = $_POST["typent_id"];
  931. $object->effectif_id = $_POST["effectif_id"];
  932. $object->barcode = $_POST["barcode"];
  933. $object->forme_juridique_code = $_POST["forme_juridique_code"];
  934. $object->default_lang = $_POST["default_lang"];
  935. $object->tva_assuj = $_POST["assujtva_value"];
  936. $object->tva_intra = $_POST["tva_intra"];
  937. $object->status = $_POST["status"];
  938. //Local Taxes
  939. $object->localtax1_assuj = $_POST["localtax1assuj_value"];
  940. $object->localtax2_assuj = $_POST["localtax2assuj_value"];
  941. // We set country_id, and pays_code label of the chosen country
  942. // TODO move to DAO class
  943. if ($object->values->Country) {
  944. $sql = "SELECT code, libelle from " . MAIN_DB_PREFIX . "c_pays where code = '" . $object->values->Country . "'";
  945. $resql = $db->query($sql);
  946. if ($resql) {
  947. $obj = $db->fetch_object($resql);
  948. } else {
  949. dol_print_error($db);
  950. }
  951. $object->countryname = $langs->trans("Country" . $object->values->Country);
  952. }
  953. }
  954. dol_htmloutput_errors($error, $errors);
  955. // Assign values for template
  956. /* $tpl->assign('id', $object->id);
  957. $tpl->assign('customer_code_auto', $modCodeClient->code_auto);
  958. $tpl->assign('customer_code_changed', $object->codeclient_modifiable());
  959. $tpl->assign('customer_code_tooltip', $modCodeClient->getToolTip($langs, $object, 0));
  960. $tpl->assign('supplier_code_auto', $modCodeFournisseur->code_auto);
  961. $tpl->assign('supplier_code_auto', $object->codefournisseur_modifiable());
  962. $tpl->assign('supplier_code_tooltip', $modCodeFournisseur->getToolTip($langs, $object, 1));
  963. if ($user->admin) {
  964. $tpl->assign('info_admin', info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"), 1));
  965. }
  966. // Assign blocks and fields
  967. for ($i = 0; $i < count($object->fk_extrafields->block); $i++) {
  968. $blockfields = array();
  969. foreach ($object->fk_extrafields->fields as $key => $params) {
  970. $blockfields[$key]['trans'] = $langs->trans($key);
  971. $blockfields[$key]['value'] = $object->values->$key;
  972. if (is_object($params) && !empty($params)) {
  973. foreach ($params as $param => $value) {
  974. $blockfields[$key][$param] = $value;
  975. }
  976. }
  977. }
  978. $tpl->assign($object->fk_extrafields->block[$i], $blockfields);
  979. }
  980. // Assign specific functions
  981. if ($object->fk_extrafields->fields->Zip->enable) {
  982. $tpl->assign('select_zip', $formcompany->select_ziptown($object->values->Zip, 'Zip', array('Town', 'selectCountry', 'State'), $object->fk_extrafields->fields->Zip->length));
  983. }
  984. if ($object->fk_extrafields->fields->Town->enable) {
  985. $tpl->assign('select_town', $formcompany->select_ziptown($object->values->Town, 'Town', array('Zip', 'selectCountry', 'State'), $object->fk_extrafields->fields->Town->length));
  986. }
  987. if ($object->fk_extrafields->fields->Country->enable) {
  988. $tpl->assign('select_country', $form->select_country($object->values->Country, 'Country'));
  989. }
  990. if ($object->fk_extrafields->fields->State->enable) {
  991. $tpl->assign('select_state', $formcompany->select_state($object->values->State, $object->values->Country, 'State'));
  992. }
  993. if ($object->fk_extrafields->fields->Status->enable) {
  994. // TODO add function select
  995. $value = (!empty($object->values->Status) ? $object->values->Status : $object->fk_extrafields->fields->Status->default);
  996. $out = '<select name="Status" id="Status">';
  997. foreach ($object->fk_status->values as $key => $aRow) {
  998. if ($aRow->enable) {
  999. if ($key == $value)
  1000. $out.= '<option selected="selected"';
  1001. else
  1002. $out.= '<option';
  1003. $out.= ' value="' . $key . '">' . $langs->trans($key) . '</option>\n';
  1004. }
  1005. }
  1006. $out.= '<select>';
  1007. //$tpl->assign('select_status', $out);
  1008. } */
  1009. ?>
  1010. <!-- BEGIN PHP TEMPLATE thirdparty update card -->
  1011. <script type="text/javascript">
  1012. $(document).ready(function () {
  1013. $("#selectCountry").change(function() {
  1014. document.formsoc.action.value="edit";
  1015. document.formsoc.submit();
  1016. });
  1017. })
  1018. </script>
  1019. <form id="simple_wizard" class="stepy-wizzard nice" enctype="multipart/form-data" action="<?php echo $_SERVER["PHP_SELF"] . '?id=' . $object->id; ?>" method="POST" name="formsoc">
  1020. <input type="hidden" name="action" value="update">
  1021. <input type="hidden" name="token" value="<?php echo $_SESSION['newtoken']; ?>">
  1022. <input type="hidden" name="id" value="<?php echo $object->id; ?>">
  1023. <?php if ($auto_customer_code->auto || $auto_supplier_code->auto): ?>
  1024. <input type="hidden" name="code_auto" value="1">
  1025. <?php endif; ?>
  1026. <?php for ($i = 0; $i < count($object->fk_extrafields->place); $i++): ?>
  1027. <fieldset title="Personal info">
  1028. <legend>Lorem ipsum dolor&hellip;</legend>
  1029. <div class="row">
  1030. <div class="two columns">
  1031. <div class="form_legend">
  1032. <h4>Personal details</h4>
  1033. <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent pharetra metus non nisi feugiat porta&hellip;</p>
  1034. </div>
  1035. </div>
  1036. <div class="ten columns">
  1037. <div class="form_content"><!-- forms columns -->
  1038. <div class="eight columns"><!-- center form -->
  1039. <?php
  1040. foreach ($object->fk_extrafields->place[$i][0] as $key) {
  1041. $aRow = $object->fk_extrafields->fields->$key;
  1042. print $object->form($aRow, $key, "large");
  1043. }
  1044. ?> </div><!-- end center form -->
  1045. <div class="four columns"><!-- right form -->
  1046. <?php
  1047. foreach ($object->fk_extrafields->place[$i][1] as $key) {
  1048. $aRow = $object->fk_extrafields->fields->$key;
  1049. print $object->form($aRow, $key, "small");
  1050. }
  1051. ?>
  1052. </div><!-- end right form -->
  1053. </div><!-- end forms columns -->
  1054. </div><!-- end ten columns -->
  1055. </div><!-- end row -->
  1056. </fieldset>
  1057. <?php endfor; ?>
  1058. <button type="submit" class="finish gh_button icon approve primary"><?php echo $langs->trans("Save"); ?></button>
  1059. <script>
  1060. $(document).ready(function() {
  1061. $('#simple_wizard').stepy({
  1062. titleClick : true
  1063. });
  1064. $('.stepy-titles').each(function(){
  1065. $(this).children('li').each(function(index){
  1066. var myIndex = index + 1
  1067. $(this).append('<span class="stepNb">'+myIndex+'</span>');
  1068. })
  1069. })
  1070. });
  1071. </script>
  1072. <?php
  1073. // Display template
  1074. //$tpl->display("./tpl/update_card.tpl.php");
  1075. print '<table class="border" width="100%">';
  1076. // VAT payers
  1077. print '<tr><td>' . $langs->trans('VATIsUsed') . '</td><td>';
  1078. print $form->selectyesno('assujtva_value', $object->tva_assuj, 1);
  1079. print '</td>';
  1080. // VAT Code
  1081. print '<td nowrap="nowrap">' . $langs->trans('VATIntra') . '</td>';
  1082. print '<td nowrap="nowrap">';
  1083. $s = '<input type="text" class="flat" name="tva_intra" size="12" maxlength="20" value="' . $object->tva_intra . '">';
  1084. if (empty($conf->global->MAIN_DISABLEVATCHECK)) {
  1085. $s.=' &nbsp; ';
  1086. if ($conf->use_javascript_ajax) {
  1087. print "\n";
  1088. print '<script language="JavaScript" type="text/javascript">';
  1089. print "function CheckVAT(a) {\n";
  1090. print "newpopup('" . DOL_URL_ROOT . "/societe/checkvat/checkVatPopup.php?vatNumber='+a,'" . dol_escape_js($langs->trans("VATIntraCheckableOnEUSite")) . "',500,285);\n";
  1091. print "}\n";
  1092. print '</script>';
  1093. print "\n";
  1094. $s.='<a href="#" onclick="javascript: CheckVAT(document.formsoc.tva_intra.value);">' . $langs->trans("VATIntraCheck") . '</a>';
  1095. $s = $form->textwithpicto($s, $langs->trans("VATIntraCheckDesc", $langs->trans("VATIntraCheck")), 1);
  1096. } else {
  1097. $s.='<a href="' . $langs->transcountry("VATIntraCheckURL", $object->id_pays) . '" target="_blank">' . img_picto($langs->trans("VATIntraCheckableOnEUSite"), 'help') . '</a>';
  1098. }
  1099. }
  1100. print $s;
  1101. print '</td>';
  1102. print '</tr>';
  1103. // Local Taxes
  1104. // TODO add specific function by country
  1105. if ($mysoc->country_id == 'ES') {
  1106. if ($mysoc->localtax1_assuj == "1" && $mysoc->localtax2_assuj == "1") {
  1107. print '<tr><td>' . $langs->trans("LocalTax1IsUsedES") . '</td><td>';
  1108. print $form->selectyesno('localtax1assuj_value', $object->localtax1_assuj, 1);
  1109. print '</td><td>' . $langs->trans("LocalTax2IsUsedES") . '</td><td>';
  1110. print $form->selectyesno('localtax2assuj_value', $object->localtax2_assuj, 1);
  1111. print '</td></tr>';
  1112. } elseif ($mysoc->localtax1_assuj == "1") {
  1113. print '<tr><td>' . $langs->trans("LocalTax1IsUsedES") . '</td><td colspan="3">';
  1114. print $form->selectyesno('localtax1assuj_value', $object->localtax1_assuj, 1);
  1115. print '</td></tr>';
  1116. } elseif ($mysoc->localtax2_assuj == "1") {
  1117. print '<tr><td>' . $langs->trans("LocalTax2IsUsedES") . '</td><td colspan="3">';
  1118. print $form->selectyesno('localtax2assuj_value', $object->localtax2_assuj, 1);
  1119. print '</td></tr>';
  1120. }
  1121. }
  1122. // Type - Size
  1123. print '<tr><td>' . $langs->trans("ThirdPartyType") . '</td><td>';
  1124. print $form->selectarray("typent_id", $formcompany->typent_array(1), $object->typent_id);
  1125. if ($user->admin)
  1126. print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"), 1);
  1127. print '</td>';
  1128. print '<td>' . $langs->trans("Staff") . '</td><td>';
  1129. print $form->selectarray("effectif_id", $formcompany->effectif_array(1), $object->effectif_id);
  1130. if ($user->admin)
  1131. print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"), 1);
  1132. print '</td></tr>';
  1133. print '<tr><td>' . $langs->trans('JuridicalStatus') . '</td><td colspan="3">';
  1134. //print $form->selectarray("forme_juridique_code",$formcompany->forme_juridique_array(1), $object…

Large files files are truncated, but you can click here to view the full file