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

/htdocs/societe/canvas/actions_card_common.class.php

https://bitbucket.org/speedealing/speedealing
PHP | 717 lines | 535 code | 82 blank | 100 comment | 122 complexity | ef74e8ec0a09381630f30567462aa364 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@capnetworks.com>
  3. * Copyright (C) 2011-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/societe/canvas/actions_card_common.class.php
  20. * \ingroup thirdparty
  21. * \brief Fichier de la classe Thirdparty card controller (common)
  22. */
  23. /**
  24. * \class ActionsCardCommon
  25. * \brief Classe permettant la gestion des tiers par defaut
  26. */
  27. abstract class ActionsCardCommon
  28. {
  29. var $db;
  30. var $dirmodule;
  31. var $targetmodule;
  32. var $canvas;
  33. var $card;
  34. //! Template container
  35. var $tpl = array();
  36. //! Object container
  37. var $object;
  38. //! Error string
  39. var $error;
  40. //! Error array
  41. var $errors=array();
  42. /**
  43. * Instantiation of DAO class
  44. * TODO This method is useless
  45. *
  46. * @return void
  47. */
  48. protected function getInstanceDao()
  49. {
  50. if (! is_object($this->object))
  51. {
  52. $modelclassfile = dol_buildpath('/'.$this->dirmodule.'/canvas/'.$this->canvas.'/dao_'.$this->targetmodule.'_'.$this->canvas.'.class.php');
  53. if (file_exists($modelclassfile))
  54. {
  55. // Include dataservice class (model)
  56. $ret = require_once $modelclassfile;
  57. if ($ret)
  58. {
  59. // Instantiate dataservice class (model)
  60. $modelclassname = 'Dao'.ucfirst($this->targetmodule).ucfirst($this->canvas);
  61. $this->object = new $modelclassname($this->db);
  62. }
  63. }
  64. }
  65. }
  66. /**
  67. * Get object from id or ref and save it into this->object
  68. *
  69. * @param int $id Object id
  70. * @param ref $ref Object ref
  71. * @return object Object loaded
  72. */
  73. protected function getObject($id,$ref='')
  74. {
  75. $ret = $this->getInstanceDao();
  76. $object = new Societe($this->db);
  77. if (! empty($id) || ! empty($ref)) $object->fetch($id,$ref);
  78. $this->object = $object;
  79. }
  80. /**
  81. * Load data control
  82. *
  83. * @param int &$action Action code
  84. * @return void
  85. */
  86. function doActions(&$action)
  87. {
  88. global $conf, $user, $langs;
  89. if ($_POST["getcustomercode"])
  90. {
  91. // We defined value code_client
  92. $_POST["code_client"]="Acompleter";
  93. }
  94. if ($_POST["getsuppliercode"])
  95. {
  96. // We defined value code_fournisseur
  97. $_POST["code_fournisseur"]="Acompleter";
  98. }
  99. // Add new third party
  100. if ((! $_POST["getcustomercode"] && ! $_POST["getsuppliercode"])
  101. && ($action == 'add' || $action == 'update'))
  102. {
  103. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  104. $error=0;
  105. if (GETPOST("private") == 1)
  106. {
  107. $this->object->particulier = GETPOST("private");
  108. $this->object->name = empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION)?trim($_POST["prenom"].' '.$_POST["nom"]):trim($_POST["nom"].' '.$_POST["prenom"]);
  109. $this->object->civilite_id = $_POST["civilite_id"];
  110. // Add non official properties
  111. $this->object->name_bis = $_POST["nom"];
  112. $this->object->firstname = $_POST["prenom"];
  113. }
  114. else
  115. {
  116. $this->object->name = $_POST["nom"];
  117. }
  118. $this->object->address = $_POST["adresse"];
  119. $this->object->zip = $_POST["zipcode"];
  120. $this->object->town = $_POST["town"];
  121. $this->object->country_id = $_POST["pays_id"];
  122. $this->object->state_id = $_POST["departement_id"];
  123. $this->object->tel = $_POST["tel"];
  124. $this->object->fax = $_POST["fax"];
  125. $this->object->email = trim($_POST["email"]);
  126. $this->object->url = $_POST["url"];
  127. $this->object->idprof1 = $_POST["idprof1"];
  128. $this->object->idprof2 = $_POST["idprof2"];
  129. $this->object->idprof3 = $_POST["idprof3"];
  130. $this->object->idprof4 = $_POST["idprof4"];
  131. $this->object->prefix_comm = $_POST["prefix_comm"];
  132. $this->object->code_client = $_POST["code_client"];
  133. $this->object->code_fournisseur = $_POST["code_fournisseur"];
  134. $this->object->capital = $_POST["capital"];
  135. $this->object->barcode = $_POST["barcode"];
  136. $this->object->canvas = GETPOST("canvas");
  137. $this->object->tva_assuj = $_POST["assujtva_value"];
  138. // Local Taxes
  139. $this->object->localtax1_assuj = $_POST["localtax1assuj_value"];
  140. $this->object->localtax2_assuj = $_POST["localtax2assuj_value"];
  141. $this->object->tva_intra = $_POST["tva_intra"];
  142. $this->object->forme_juridique_code = $_POST["forme_juridique_code"];
  143. $this->object->effectif_id = $_POST["effectif_id"];
  144. if (GETPOST("private") == 1)
  145. {
  146. $this->object->typent_id = 8; // TODO predict another method if the field "special" change of rowid
  147. }
  148. else
  149. {
  150. $this->object->typent_id = $_POST["typent_id"];
  151. }
  152. $this->object->client = $_POST["client"];
  153. $this->object->fournisseur = $_POST["fournisseur"];
  154. $this->object->fournisseur_categorie = $_POST["fournisseur_categorie"];
  155. $this->object->commercial_id = $_POST["commercial_id"];
  156. $this->object->default_lang = $_POST["default_lang"];
  157. // Check parameters
  158. if (empty($_POST["cancel"]))
  159. {
  160. if (! empty($this->object->email) && ! isValidEMail($this->object->email))
  161. {
  162. $error = 1;
  163. $langs->load("errors");
  164. $this->error = $langs->trans("ErrorBadEMail",$this->object->email);
  165. $action = ($action == 'add' ? 'create' : 'edit');
  166. }
  167. if (! empty($this->object->url) && ! isValidUrl($this->object->url))
  168. {
  169. $error = 1;
  170. $langs->load("errors");
  171. $this->error = $langs->trans("ErrorBadUrl",$this->object->url);
  172. $action = ($action == 'add' ? 'create' : 'edit');
  173. }
  174. if ($this->object->fournisseur && ! $conf->fournisseur->enabled)
  175. {
  176. $error = 1;
  177. $langs->load("errors");
  178. $this->error = $langs->trans("ErrorSupplierModuleNotEnabled");
  179. $action = ($action == 'add' ? 'create' : 'edit');
  180. }
  181. }
  182. if (! $error)
  183. {
  184. if ($action == 'add')
  185. {
  186. $this->db->begin();
  187. if (empty($this->object->client)) $this->object->code_client='';
  188. if (empty($this->object->fournisseur)) $this->object->code_fournisseur='';
  189. $result = $this->object->create($user);
  190. if ($result >= 0)
  191. {
  192. if ($this->object->particulier)
  193. {
  194. dol_syslog(get_class($this)."::doActions This thirdparty is a personal people",LOG_DEBUG);
  195. $contact=new Contact($this->db);
  196. $contact->civilite_id = $this->object->civilite_id;
  197. $contact->name = $this->object->name_bis;
  198. $contact->firstname = $this->object->firstname;
  199. $contact->address = $this->object->address;
  200. $contact->zip = $this->object->zip;
  201. $contact->town = $this->object->town;
  202. $contact->country_id = $this->object->country_id;
  203. $contact->socid = $this->object->id; // fk_soc
  204. $contact->status = 1;
  205. $contact->email = $this->object->email;
  206. $contact->priv = 0;
  207. $result=$contact->create($user);
  208. }
  209. }
  210. else
  211. {
  212. $this->errors=$this->object->errors;
  213. }
  214. if ($result >= 0)
  215. {
  216. $this->db->commit();
  217. if ( $this->object->client == 1 )
  218. {
  219. header("Location: ".DOL_URL_ROOT."/comm/fiche.php?socid=".$this->object->id);
  220. return;
  221. }
  222. else
  223. {
  224. if ( $this->object->fournisseur == 1 )
  225. {
  226. header("Location: ".DOL_URL_ROOT."/fourn/fiche.php?socid=".$this->object->id);
  227. return;
  228. }
  229. else
  230. {
  231. header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$this->object->id);
  232. return;
  233. }
  234. }
  235. exit;
  236. }
  237. else
  238. {
  239. $this->db->rollback();
  240. $this->errors=$this->object->errors;
  241. $action = 'create';
  242. }
  243. }
  244. if ($action == 'update')
  245. {
  246. if ($_POST["cancel"])
  247. {
  248. header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$this->object->id);
  249. exit;
  250. }
  251. $oldsoccanvas = dol_clone($this->object);
  252. // To avoid setting code if third party is not concerned. But if it had values, we keep them.
  253. if (empty($this->object->client) && empty($oldsoccanvas->code_client)) $this->object->code_client='';
  254. if (empty($this->object->fournisseur) && empty($oldsoccanvas->code_fournisseur)) $this->object->code_fournisseur='';
  255. $result = $this->object->update($this->object->id, $user, 1, $oldsoccanvas->codeclient_modifiable(), $oldsoccanvas->codefournisseur_modifiable());
  256. if ($result >= 0)
  257. {
  258. header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$this->object->id);
  259. exit;
  260. }
  261. else
  262. {
  263. $this->object->id = $this->object->id;
  264. $reload = 0;
  265. $this->errors = $this->object->errors;
  266. $action = "edit";
  267. }
  268. }
  269. }
  270. }
  271. if ($action == 'confirm_delete' && GETPOST("confirm") == 'yes')
  272. {
  273. $result = $this->object->delete($this->object->id);
  274. if ($result >= 0)
  275. {
  276. header("Location: ".DOL_URL_ROOT."/societe/societe.php?delsoc=".$this->object->nom."");
  277. exit;
  278. }
  279. else
  280. {
  281. $reload = 0;
  282. $this->errors=$this->object->errors;
  283. $action = '';
  284. }
  285. }
  286. /*
  287. * Generate document
  288. */
  289. if ($action == 'builddoc') // En get ou en post
  290. {
  291. if (is_numeric(GETPOST('model')))
  292. {
  293. $this->error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Model"));
  294. }
  295. else
  296. {
  297. require_once DOL_DOCUMENT_ROOT.'/core/models/modules_societe.class.php';
  298. $this->object->fetch_thirdparty();
  299. // Define output language
  300. $outputlangs = $langs;
  301. $newlang='';
  302. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id') ) $newlang=GETPOST('lang_id');
  303. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$this->object->default_lang;
  304. if (! empty($newlang))
  305. {
  306. $outputlangs = new Translate();
  307. $outputlangs->setDefaultLang($newlang);
  308. }
  309. $result=thirdparty_doc_create($this->db, $this->object->id, '', GETPOST('model'), $outputlangs);
  310. if ($result <= 0)
  311. {
  312. dol_print_error($this->db,$result);
  313. exit;
  314. }
  315. else
  316. {
  317. header('Location: '.$_SERVER["PHP_SELF"].'?socid='.$this->object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc'));
  318. exit;
  319. }
  320. }
  321. }
  322. }
  323. /**
  324. * Assign custom values for canvas (for example into this->tpl to be used by templates)
  325. *
  326. * @param string &$action Type of action
  327. * @param string $id Id of object
  328. * @param string $ref Ref of object
  329. * @return void
  330. */
  331. function assign_values(&$action, $id=0, $ref='')
  332. {
  333. global $conf, $langs, $user, $mysoc, $canvas;
  334. global $form, $formadmin, $formcompany;
  335. if ($action == 'add' || $action == 'update') $this->assign_post($action);
  336. if ($_GET["type"]=='f') { $this->object->fournisseur=1; }
  337. if ($_GET["type"]=='c') { $this->object->client=1; }
  338. if ($_GET["type"]=='p') { $this->object->client=2; }
  339. if ($_GET["type"]=='cp') { $this->object->client=3; }
  340. if ($_REQUEST["private"]==1) { $this->object->particulier=1; }
  341. foreach($this->object as $key => $value)
  342. {
  343. $this->tpl[$key] = $value;
  344. }
  345. $this->tpl['error'] = get_htmloutput_errors($this->object->error,$this->object->errors);
  346. if (is_array($GLOBALS['errors'])) $this->tpl['error'] = get_htmloutput_mesg('',$GLOBALS['errors'],'error');
  347. if ($action == 'create')
  348. {
  349. if ($conf->use_javascript_ajax)
  350. {
  351. $this->tpl['ajax_selecttype'] = "\n".'<script type="text/javascript" language="javascript">
  352. $(document).ready(function () {
  353. $("#radiocompany").click(function() {
  354. document.formsoc.action.value="create";
  355. document.formsoc.canvas.value="company";
  356. document.formsoc.private.value=0;
  357. document.formsoc.submit();
  358. });
  359. $("#radioprivate").click(function() {
  360. document.formsoc.action.value="create";
  361. document.formsoc.canvas.value="individual";
  362. document.formsoc.private.value=1;
  363. document.formsoc.submit();
  364. });
  365. });
  366. </script>'."\n";
  367. }
  368. }
  369. if ($action == 'create' || $action == 'edit')
  370. {
  371. if ($conf->use_javascript_ajax)
  372. {
  373. $this->tpl['ajax_selectcountry'] = "\n".'<script type="text/javascript" language="javascript">
  374. $(document).ready(function () {
  375. $("#selectcountry_id").change(function() {
  376. document.formsoc.action.value="'.$action.'";
  377. document.formsoc.canvas.value="'.$canvas.'";
  378. document.formsoc.submit();
  379. });
  380. })
  381. </script>'."\n";
  382. }
  383. // Load object modCodeClient
  384. $module=(! empty($conf->global->SOCIETE_CODECLIENT_ADDON)?$conf->global->SOCIETE_CODECLIENT_ADDON:'mod_codeclient_leopard');
  385. if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php')
  386. {
  387. $module = substr($module, 0, dol_strlen($module)-4);
  388. }
  389. $dirsociete=array_merge(array('/societe/core/models/'),$conf->societe_modules);
  390. foreach ($dirsociete as $dirroot)
  391. {
  392. $res=dol_include_once($dirroot.$module.'.php');
  393. if ($res) break;
  394. }
  395. $modCodeClient = new $module($db);
  396. $this->tpl['auto_customercode'] = $modCodeClient->code_auto;
  397. // We verified if the tag prefix is used
  398. if ($modCodeClient->code_auto) $this->tpl['prefix_customercode'] = $modCodeClient->verif_prefixIsUsed();
  399. // TODO create a function
  400. $this->tpl['select_customertype'] = '<select class="flat" name="client">';
  401. $this->tpl['select_customertype'].= '<option value="2"'.($this->object->client==2?' selected="selected"':'').'>'.$langs->trans('Prospect').'</option>';
  402. $this->tpl['select_customertype'].= '<option value="3"'.($this->object->client==3?' selected="selected"':'').'>'.$langs->trans('ProspectCustomer').'</option>';
  403. $this->tpl['select_customertype'].= '<option value="1"'.($this->object->client==1?' selected="selected"':'').'>'.$langs->trans('Customer').'</option>';
  404. $this->tpl['select_customertype'].= '<option value="0"'.($this->object->client==0?' selected="selected"':'').'>'.$langs->trans('NorProspectNorCustomer').'</option>';
  405. $this->tpl['select_customertype'].= '</select>';
  406. // Customer
  407. $this->tpl['customercode'] = $this->object->code_client;
  408. if ((!$this->object->code_client || $this->object->code_client == -1) && $modCodeClient->code_auto) $this->tpl['customercode'] = $modCodeClient->getNextValue($this->object,0);
  409. $this->tpl['ismodifiable_customercode'] = $this->object->codeclient_modifiable();
  410. $s=$modCodeClient->getToolTip($langs,$this->object,0);
  411. $this->tpl['help_customercode'] = $form->textwithpicto('',$s,1);
  412. if (! empty($conf->fournisseur->enabled))
  413. {
  414. $this->tpl['supplier_enabled'] = 1;
  415. // Load object modCodeFournisseur
  416. $module=$conf->global->SOCIETE_CODEFOURNISSEUR_ADDON;
  417. if (! $module) $module=$conf->global->SOCIETE_CODECLIENT_ADDON;
  418. if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php')
  419. {
  420. $module = substr($module, 0, dol_strlen($module)-4);
  421. }
  422. $dirsociete=array_merge(array('/societe/core/models/'),$conf->societe_modules);
  423. foreach ($dirsociete as $dirroot)
  424. {
  425. $res=dol_include_once($dirroot.$module.'.php');
  426. if ($res) break;
  427. }
  428. $modCodeFournisseur = new $module;
  429. $this->tpl['auto_suppliercode'] = $modCodeFournisseur->code_auto;
  430. // We verified if the tag prefix is used
  431. if ($modCodeFournisseur->code_auto) $this->tpl['prefix_suppliercode'] = $modCodeFournisseur->verif_prefixIsUsed();
  432. // Supplier
  433. $this->tpl['yn_supplier'] = $form->selectyesno("fournisseur",$this->object->fournisseur,1);
  434. $this->tpl['suppliercode'] = $this->object->code_fournisseur;
  435. if ((!$this->object->code_fournisseur || $this->object->code_fournisseur == -1) && $modCodeFournisseur->code_auto) $this->tpl['suppliercode'] = $modCodeFournisseur->getNextValue($this->object,1);
  436. $this->tpl['ismodifiable_suppliercode'] = $this->object->codefournisseur_modifiable();
  437. $s=$modCodeFournisseur->getToolTip($langs,$this->object,1);
  438. $this->tpl['help_suppliercode'] = $form->textwithpicto('',$s,1);
  439. $this->object->LoadSupplierCateg();
  440. $this->tpl['suppliercategory'] = $this->object->SupplierCategories;
  441. $this->tpl['select_suppliercategory'] = $form->selectarray("fournisseur_categorie",$this->object->SupplierCategories,$_POST["fournisseur_categorie"],1);
  442. }
  443. // Zip
  444. $this->tpl['select_zip'] = $formcompany->select_ziptown($this->object->zip,'zipcode',array('town','selectcountry_id','departement_id'),6);
  445. // Town
  446. $this->tpl['select_town'] = $formcompany->select_ziptown($this->object->town,'town',array('zipcode','selectcountry_id','departement_id'));
  447. // Country
  448. $this->object->country_id = ($this->object->country_id ? $this->object->country_id : $mysoc->country_id);
  449. $this->object->country_code = ($this->object->country_code ? $this->object->country_code : $mysoc->country_code);
  450. $this->tpl['select_country'] = $form->select_country($this->object->country_id,'country_id');
  451. $countrynotdefined = $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
  452. if ($user->admin) $this->tpl['info_admin'] = info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
  453. // State
  454. if ($this->object->country_id) $this->tpl['select_state'] = $formcompany->select_state($this->object->state_id,$this->object->country_code);
  455. else $this->tpl['select_state'] = $countrynotdefined;
  456. // Language
  457. if (! empty($conf->global->MAIN_MULTILANGS)) $this->tpl['select_lang'] = $formadmin->select_language(($this->object->default_lang?$this->object->default_lang:$conf->global->MAIN_LANG_DEFAULT),'default_lang',0,0,1);
  458. // VAT
  459. $this->tpl['yn_assujtva'] = $form->selectyesno('assujtva_value',$this->tpl['tva_assuj'],1); // Assujeti par defaut en creation
  460. // Select users
  461. $this->tpl['select_users'] = $form->select_dolusers($this->object->commercial_id,'commercial_id',1);
  462. // Local Tax
  463. // TODO mettre dans une classe propre au pays
  464. if($mysoc->country_code=='ES')
  465. {
  466. $this->tpl['localtax'] = '';
  467. if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1")
  468. {
  469. $this->tpl['localtax'].= '<tr><td>'.$langs->trans("LocalTax1IsUsedES").'</td><td>';
  470. $this->tpl['localtax'].= $form->selectyesno('localtax1assuj_value',$this->object->localtax1_assuj,1);
  471. $this->tpl['localtax'].= '</td><td>'.$langs->trans("LocalTax2IsUsedES").'</td><td>';
  472. $this->tpl['localtax'].= $form->selectyesno('localtax2assuj_value',$this->object->localtax1_assuj,1);
  473. $this->tpl['localtax'].= '</td></tr>';
  474. }
  475. elseif($mysoc->localtax1_assuj=="1")
  476. {
  477. $this->tpl['localtax'].= '<tr><td>'.$langs->trans("LocalTax1IsUsedES").'</td><td colspan="3">';
  478. $this->tpl['localtax'].= $form->selectyesno('localtax1assuj_value',$this->object->localtax1_assuj,1);
  479. $this->tpl['localtax'].= '</td><tr>';
  480. }
  481. elseif($mysoc->localtax2_assuj=="1")
  482. {
  483. $this->tpl['localtax'].= '<tr><td>'.$langs->trans("LocalTax2IsUsedES").'</td><td colspan="3">';
  484. $this->tpl['localtax'].= $form->selectyesno('localtax2assuj_value',$this->object->localtax1_assuj,1);
  485. $this->tpl['localtax'].= '</td><tr>';
  486. }
  487. }
  488. }
  489. else
  490. {
  491. $head = societe_prepare_head($this->object);
  492. $this->tpl['showhead']=dol_get_fiche_head($head, 'card', '', 0, 'company');
  493. $this->tpl['showend']=dol_get_fiche_end();
  494. $this->tpl['showrefnav'] = $form->showrefnav($this->object,'socid','',($user->societe_id?0:1),'rowid','nom');
  495. $this->tpl['checkcustomercode'] = $this->object->check_codeclient();
  496. $this->tpl['checksuppliercode'] = $this->object->check_codefournisseur();
  497. $this->tpl['address'] = dol_nl2br($this->object->address);
  498. $img=picto_from_langcode($this->object->pays_code);
  499. if ($this->object->isInEEC()) $this->tpl['country'] = $form->textwithpicto(($img?$img.' ':'').$this->object->country,$langs->trans("CountryIsInEEC"),1,0);
  500. $this->tpl['country'] = ($img?$img.' ':'').$this->object->country;
  501. $this->tpl['phone'] = dol_print_phone($this->object->tel,$this->object->country_code,0,$this->object->id,'AC_TEL');
  502. $this->tpl['fax'] = dol_print_phone($this->object->fax,$this->object->country_code,0,$this->object->id,'AC_FAX');
  503. $this->tpl['email'] = dol_print_email($this->object->email,0,$this->object->id,'AC_EMAIL');
  504. $this->tpl['url'] = dol_print_url($this->object->url);
  505. $this->tpl['tva_assuj'] = yn($this->object->tva_assuj);
  506. // Third party type
  507. $arr = $formcompany->typent_array(1);
  508. $this->tpl['typent'] = $arr[$this->object->typent_code];
  509. if (! empty($conf->global->MAIN_MULTILANGS))
  510. {
  511. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  512. //$s=picto_from_langcode($this->default_lang);
  513. //print ($s?$s.' ':'');
  514. $langs->load("languages");
  515. $this->tpl['default_lang'] = ($this->default_lang?$langs->trans('Language_'.$this->object->default_lang):'');
  516. }
  517. $this->tpl['image_edit'] = img_edit();
  518. $this->tpl['display_rib'] = $this->object->display_rib();
  519. // Sales representatives
  520. $this->tpl['sales_representatives'] = '';
  521. $listsalesrepresentatives=$this->object->getSalesRepresentatives($user);
  522. $nbofsalesrepresentative=count($listsalesrepresentatives);
  523. if ($nbofsalesrepresentative > 3) // We print only number
  524. {
  525. $this->tpl['sales_representatives'].= '<a href="'.DOL_URL_ROOT.'/societe/commerciaux.php?socid='.$this->object->id.'">';
  526. $this->tpl['sales_representatives'].= $nbofsalesrepresentative;
  527. $this->tpl['sales_representatives'].= '</a>';
  528. }
  529. else if ($nbofsalesrepresentative > 0)
  530. {
  531. $userstatic=new User($this->db);
  532. $i=0;
  533. foreach($listsalesrepresentatives as $val)
  534. {
  535. $userstatic->id=$val['id'];
  536. $userstatic->lastname=$val['name'];
  537. $userstatic->firstname=$val['firstname'];
  538. $this->tpl['sales_representatives'].= $userstatic->getNomUrl(1);
  539. $i++;
  540. if ($i < $nbofsalesrepresentative) $this->tpl['sales_representatives'].= ', ';
  541. }
  542. }
  543. else $this->tpl['sales_representatives'].= $langs->trans("NoSalesRepresentativeAffected");
  544. // Linked member
  545. if (! empty($conf->adherent->enabled))
  546. {
  547. $langs->load("members");
  548. $adh=new Adherent($this->db);
  549. $result=$adh->fetch('','',$this->object->id);
  550. if ($result > 0)
  551. {
  552. $adh->ref=$adh->getFullName($langs);
  553. $this->tpl['linked_member'] = $adh->getNomUrl(1);
  554. }
  555. else
  556. {
  557. $this->tpl['linked_member'] = $langs->trans("UserNotLinkedToMember");
  558. }
  559. }
  560. // Local Tax
  561. // TODO mettre dans une classe propre au pays
  562. if($mysoc->country_code=='ES')
  563. {
  564. $this->tpl['localtax'] = '';
  565. if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1")
  566. {
  567. $this->tpl['localtax'].= '<tr><td>'.$langs->trans("LocalTax1IsUsedES").'</td>';
  568. $this->tpl['localtax'].= '<td>'.yn($this->object->localtax1_assuj).'</td>';
  569. $this->tpl['localtax'].= '<td>'.$langs->trans("LocalTax2IsUsedES").'</td>';
  570. $this->tpl['localtax'].= '<td>'.yn($this->object->localtax2_assuj).'</td></tr>';
  571. }
  572. elseif($mysoc->localtax1_assuj=="1")
  573. {
  574. $this->tpl['localtax'].= '<tr><td>'.$langs->trans("LocalTax1IsUsedES").'</td>';
  575. $this->tpl['localtax'].= '<td colspan="3">'.yn($this->object->localtax1_assuj).'</td></tr>';
  576. }
  577. elseif($mysoc->localtax2_assuj=="1")
  578. {
  579. $this->tpl['localtax'].= '<tr><td>'.$langs->trans("LocalTax2IsUsedES").'</td>';
  580. $this->tpl['localtax'].= '<td colspan="3">'.yn($this->object->localtax2_assuj).'</td></tr>';
  581. }
  582. }
  583. }
  584. }
  585. /**
  586. * Assign POST values into object
  587. *
  588. * @param string $action Action string
  589. * @return string HTML output
  590. */
  591. private function assign_post($action)
  592. {
  593. global $langs, $mysoc;
  594. $this->object->id = $_POST["socid"];
  595. $this->object->name = $_POST["nom"];
  596. $this->object->prefix_comm = $_POST["prefix_comm"];
  597. $this->object->client = $_POST["client"];
  598. $this->object->code_client = $_POST["code_client"];
  599. $this->object->fournisseur = $_POST["fournisseur"];
  600. $this->object->code_fournisseur = $_POST["code_fournisseur"];
  601. $this->object->address = $_POST["adresse"];
  602. $this->object->zip = $_POST["zipcode"];
  603. $this->object->town = $_POST["town"];
  604. $this->object->country_id = $_POST["country_id"]?$_POST["country_id"]:$mysoc->country_id;
  605. $this->object->state_id = $_POST["departement_id"];
  606. $this->object->tel = $_POST["tel"];
  607. $this->object->fax = $_POST["fax"];
  608. $this->object->email = $_POST["email"];
  609. $this->object->url = $_POST["url"];
  610. $this->object->capital = $_POST["capital"];
  611. $this->object->idprof1 = $_POST["idprof1"];
  612. $this->object->idprof2 = $_POST["idprof2"];
  613. $this->object->idprof3 = $_POST["idprof3"];
  614. $this->object->idprof4 = $_POST["idprof4"];
  615. $this->object->typent_id = $_POST["typent_id"];
  616. $this->object->effectif_id = $_POST["effectif_id"];
  617. $this->object->barcode = $_POST["barcode"];
  618. $this->object->forme_juridique_code = $_POST["forme_juridique_code"];
  619. $this->object->default_lang = $_POST["default_lang"];
  620. $this->object->commercial_id = $_POST["commercial_id"];
  621. $this->object->tva_assuj = $_POST["assujtva_value"]?$_POST["assujtva_value"]:1;
  622. $this->object->tva_intra = $_POST["tva_intra"];
  623. //Local Taxes
  624. $this->object->localtax1_assuj = $_POST["localtax1assuj_value"];
  625. $this->object->localtax2_assuj = $_POST["localtax2assuj_value"];
  626. // We set pays_id, and pays_code label of the chosen country
  627. if ($this->object->country_id)
  628. {
  629. $tmparray=getCountry($this->object->country_id,'all',$this->db,$langs,0);
  630. $this->object->country_code = $tmparray['code'];
  631. $this->object->country_label= $tmparray['label'];
  632. }
  633. }
  634. }
  635. ?>