actions_card_company.class.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <?php
  2. /* Copyright (C) 2010-2011 Regis Houssin <regis.houssin@inodbox.com>
  3. * Copyright (C) 2011 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 <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/societe/canvas/company/actions_card_company.class.php
  20. * \ingroup thirdparty
  21. * \brief File of Thirdparty card controller (default canvas)
  22. */
  23. include_once DOL_DOCUMENT_ROOT.'/societe/canvas/actions_card_common.class.php';
  24. /**
  25. * ActionsCardCompany
  26. *
  27. * Class with controller methods for thirdparty canvas
  28. */
  29. class ActionsCardCompany extends ActionsCardCommon
  30. {
  31. /**
  32. * Constructor
  33. *
  34. * @param DoliDB $db Handler acces base de donnees
  35. * @param string $dirmodule Name of directory of module
  36. * @param string $targetmodule Name of directory of module where canvas is stored
  37. * @param string $canvas Name of canvas
  38. * @param string $card Name of tab (sub-canvas)
  39. */
  40. public function __construct($db, $dirmodule, $targetmodule, $canvas, $card)
  41. {
  42. $this->db = $db;
  43. $this->dirmodule = $dirmodule;
  44. $this->targetmodule = $targetmodule;
  45. $this->canvas = $canvas;
  46. $this->card = $card;
  47. }
  48. /**
  49. * Return the title of card
  50. *
  51. * @param string $action Action code
  52. * @return string Title
  53. */
  54. private function getTitle($action)
  55. {
  56. global $langs;
  57. $out = '';
  58. if ($action == 'view') {
  59. $out .= $langs->trans("ThirdParty");
  60. }
  61. if ($action == 'edit') {
  62. $out .= $langs->trans("EditCompany");
  63. }
  64. if ($action == 'create') {
  65. $out .= $langs->trans("NewCompany");
  66. }
  67. return $out;
  68. }
  69. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  70. /**
  71. * Assign custom values for canvas (for example into this->tpl to be used by templates)
  72. *
  73. * @param string $action Type of action
  74. * @param integer $id Id of object
  75. * @param string $ref Ref of object
  76. * @return void
  77. */
  78. public function assign_values(&$action, $id = 0, $ref = '')
  79. {
  80. // phpcs:enable
  81. global $conf, $langs, $user, $mysoc;
  82. global $form, $formcompany;
  83. $ret = $this->getObject($id, $ref);
  84. parent::assign_values($action);
  85. $this->tpl['title'] = load_fiche_titre($this->getTitle($action));
  86. $this->tpl['profid1'] = $this->object->idprof1;
  87. $this->tpl['profid2'] = $this->object->idprof2;
  88. $this->tpl['profid3'] = $this->object->idprof3;
  89. $this->tpl['profid4'] = $this->object->idprof4;
  90. if ($conf->use_javascript_ajax && !getDolGlobalString('MAIN_DISABLEVATCHECK')) {
  91. $js = "\n";
  92. $js .= '<script type="text/javascript">';
  93. $js .= "function CheckVAT(a) {\n";
  94. $js .= "newpopup('".DOL_URL_ROOT."/societe/checkvat/checkVatPopup.php?vatNumber='+a,'".dol_escape_js($langs->trans("VATIntraCheckableOnEUSite"))."',500,230);\n";
  95. $js .= "}\n";
  96. $js .= '</script>';
  97. $js .= "\n";
  98. $this->tpl['js_checkVatPopup'] = $js;
  99. }
  100. if ($action == 'create' || $action == 'edit') {
  101. for ($i = 1; $i <= 4; $i++) {
  102. $this->tpl['langprofid'.$i] = $langs->transcountry('ProfId'.$i, $this->object->country_code);
  103. $this->tpl['showprofid'.$i] = $formcompany->get_input_id_prof($i, 'idprof'.$i, $this->tpl['profid'.$i], $this->object->country_code);
  104. }
  105. // Type
  106. $this->tpl['select_companytype'] = $form->selectarray("typent_id", $formcompany->typent_array(0), $this->object->typent_id);
  107. // Juridical Status
  108. $this->tpl['select_juridicalstatus'] = $formcompany->select_juridicalstatus($this->object->forme_juridique_code, $this->object->country_code);
  109. // Workforce
  110. $this->tpl['select_workforce'] = $form->selectarray("effectif_id", $formcompany->effectif_array(0), $this->object->effectif_id);
  111. // VAT intra
  112. $s = '<input type="text" class="flat" name="tva_intra" size="12" maxlength="20" value="'.$this->object->tva_intra.'">';
  113. if (!getDolGlobalString('MAIN_DISABLEVATCHECK')) {
  114. $s .= ' ';
  115. if ($conf->use_javascript_ajax) {
  116. $s .= '<a href="#" onclick="CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>';
  117. $this->tpl['tva_intra'] = $form->textwithpicto($s, $langs->trans("VATIntraCheckDesc", $langs->transnoentitiesnoconv("VATIntraCheck")), 1);
  118. } else {
  119. $this->tpl['tva_intra'] = $s.'<a href="'.$langs->transcountry("VATIntraCheckURL", $this->object->country_id).'" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"), 'help').'</a>';
  120. }
  121. } else {
  122. $this->tpl['tva_intra'] = $s;
  123. }
  124. } else {
  125. // Confirm delete third party
  126. if ($action == 'delete') {
  127. $this->tpl['action_delete'] = $form->formconfirm($_SERVER["PHP_SELF"]."?socid=".$this->object->id, $langs->trans("DeleteACompany"), $langs->trans("ConfirmDeleteCompany"), "confirm_delete", '', 0, "1,action-delete");
  128. }
  129. for ($i = 1; $i <= 4; $i++) {
  130. $this->tpl['langprofid'.$i] = $langs->transcountry('ProfId'.$i, $this->object->country_code);
  131. $this->tpl['checkprofid'.$i] = $this->object->id_prof_check($i, $this->object);
  132. $this->tpl['urlprofid'.$i] = $this->object->id_prof_url($i, $this->object);
  133. }
  134. // TVA intra
  135. if ($this->object->tva_intra) {
  136. $s = $this->object->tva_intra;
  137. $s .= '<input type="hidden" name="tva_intra" size="12" maxlength="20" value="'.$this->object->tva_intra.'">';
  138. if (!getDolGlobalString('MAIN_DISABLEVATCHECK')) {
  139. $s .= ' &nbsp; ';
  140. if ($conf->use_javascript_ajax) {
  141. $s .= '<a href="#" onclick="CheckVAT(document.formsoc.tva_intra.value);">'.$langs->trans("VATIntraCheck").'</a>';
  142. $this->tpl['tva_intra'] = $form->textwithpicto($s, $langs->trans("VATIntraCheckDesc", $langs->transnoentitiesnoconv("VATIntraCheck")), 1);
  143. } else {
  144. $this->tpl['tva_intra'] = $s.'<a href="'.$langs->transcountry("VATIntraCheckURL", $this->object->country_id).'" target="_blank">'.img_picto($langs->trans("VATIntraCheckableOnEUSite"), 'help').'</a>';
  145. }
  146. } else {
  147. $this->tpl['tva_intra'] = $s;
  148. }
  149. } else {
  150. $this->tpl['tva_intra'] = '&nbsp;';
  151. }
  152. // Parent company
  153. if ($this->object->parent) {
  154. $socm = new Societe($this->db);
  155. $socm->fetch($this->object->parent);
  156. $this->tpl['parent_company'] = $socm->getNomUrl(1).' '.($socm->code_client ? "(".$socm->code_client.")" : "");
  157. $this->tpl['parent_company'] .= ($socm->town ? ' - '.$socm->town : '');
  158. } else {
  159. $this->tpl['parent_company'] = $langs->trans("NoParentCompany");
  160. }
  161. }
  162. }
  163. /**
  164. * Check permissions of a user to show a page and an object. Check read permission
  165. * If $_REQUEST['action'] defined, we also check write permission.
  166. *
  167. * @param User $user User to check
  168. * @param string $features Features to check (in most cases, it's module name)
  169. * @param int $objectid Object ID if we want to check permission on a particular record (optional)
  170. * @param string $dbtablename Table name where object is stored. Not used if objectid is null (optional)
  171. * @param string $feature2 Feature to check (second level of permission)
  172. * @param string $dbt_keyfield Field name for socid foreign key if not fk_soc. (optional)
  173. * @param string $dbt_select Field name for select if not rowid. (optional)
  174. * @return int 1
  175. */
  176. public function restrictedArea($user, $features = 'societe', $objectid = 0, $dbtablename = '', $feature2 = '', $dbt_keyfield = 'fk_soc', $dbt_select = 'rowid')
  177. {
  178. return restrictedArea($user, $features, $objectid, $dbtablename, $feature2, $dbt_keyfield, $dbt_select);
  179. }
  180. }