PageRenderTime 26ms CodeModel.GetById 95ms RepoModel.GetById 75ms app.codeStats 0ms

/crm/Setup.class.php

https://github.com/bgerp/bgerp
PHP | 312 lines | 139 code | 74 blank | 99 comment | 5 complexity | 3e108e58ae0434f4a9d177560204be86 MD5 | raw file
  1. <?php
  2. /**
  3. * Име на собствената компания (тази за която ще работи bgERP)
  4. */
  5. defIfNot('BGERP_OWN_COMPANY_NAME', 'Моята Фирма ООД');
  6. /**
  7. * Държавата на собствената компания (тази за която ще работи bgERP)
  8. */
  9. defIfNot('BGERP_OWN_COMPANY_COUNTRY', 'Bulgaria');
  10. /**
  11. * ID на нашата фирма
  12. */
  13. defIfNot('BGERP_OWN_COMPANY_ID', 1);
  14. /**
  15. * Да се показва ли полето Класификация на икономическите дейности (НКИД)
  16. */
  17. defIfNot('CRM_VISIBLE_NKID', 'none');
  18. /**
  19. * Използване на регистър VIES за търсене на фирми
  20. */
  21. defIfNot('CRM_REGISTRY_USE_VIES', 'yes');
  22. /**
  23. * Използване на Търговския регистър за търсене на фирми
  24. */
  25. defIfNot('CRM_REGISTRY_USE_BRRA', 'yes');
  26. /**
  27. * Вид на визитника
  28. */
  29. defIfNot('CRM_ALPHABET_FILTER', 'standart');
  30. /**
  31. * "Свързани" фирми
  32. */
  33. defIfNot('CRM_CONNECTED_COMPANIES', '');
  34. /**
  35. * Клас 'crm_Setup' -
  36. *
  37. *
  38. * @category bgerp
  39. * @package crm
  40. *
  41. * @author Milen Georgiev <milen@download.bg>
  42. * @copyright 2006 - 2021 Experta OOD
  43. * @license GPL 3
  44. *
  45. * @since v 0.1
  46. */
  47. class crm_Setup extends core_ProtoSetup
  48. {
  49. /**
  50. * ID на нашата фирма
  51. */
  52. const BGERP_OWN_COMPANY_ID = BGERP_OWN_COMPANY_ID;
  53. /**
  54. * Версия на пакета
  55. */
  56. public $version = '0.1';
  57. /**
  58. * Мениджър - входна точка в пакета
  59. */
  60. public $startCtr = 'crm_Companies';
  61. /**
  62. * Екшън - входна точка в пакета
  63. */
  64. public $startAct = 'default';
  65. /**
  66. * Необходими пакети
  67. */
  68. public $depends = 'drdata=0.1, callcenter=0.1';
  69. /**
  70. * Описание на модула
  71. */
  72. public $info = 'Визитник и управление на контактите';
  73. /**
  74. * Описание на конфигурационните константи
  75. */
  76. public $configDescription = array(
  77. 'CRM_VISIBLE_NKID' => array('enum(none=Не показвай, yes=Покажи)', 'caption=Класификация на икономическите дейности->НКИД'),
  78. 'CRM_REGISTRY_USE_BRRA' => array('enum(yes=Включено,ne=Изключено)', 'caption=Извличане и попълване на данни->Търговски регистър'),
  79. 'CRM_REGISTRY_USE_VIES' => array('enum(yes=Включено,ne=Изключено)', 'caption=Извличане и попълване на данни->VIES'),
  80. 'CRM_ALPHABET_FILTER' => array('enum(none=Без,standart=Стандартен,twoRows=Двоен)', 'caption=Вид на азбучника->Избор, customizeBy=powerUser'),
  81. 'CRM_CONNECTED_COMPANIES' => array('keylist(mvc=crm_Companies,select=name)', 'caption="Свързани" фирми'),
  82. );
  83. /**
  84. * Описание на системните действия
  85. */
  86. public $systemActions = array(
  87. array('title' => 'Ключови думи', 'url' => array('crm_Persons', 'repairKeywords', 'ret_url' => true), 'params' => array('title' => 'Ре-индексиране на визитките')),
  88. array('title' => 'Промяна на условия', 'url' => array('cond_ConditionsToCustomers', 'update', 'ret_url' => true), 'params' => array('title' => 'Промяна на търговските условия на контрагентите', 'ef_icon' => 'img/16/arrow_refresh.png'))
  89. );
  90. /**
  91. * Настройки за Cron
  92. */
  93. public $cronSettings = array(
  94. array(
  95. 'systemId' => 'Gather_contragent_info',
  96. 'description' => 'Събиране на информация за контрагентите',
  97. 'controller' => 'crm_ext_ContragentInfo',
  98. 'action' => 'GatherInfo',
  99. 'period' => 720,
  100. 'offset' => 70,
  101. 'timeLimit' => 300
  102. ),
  103. );
  104. /**
  105. * Списък с мениджърите, които съдържа пакета
  106. */
  107. public $managers = array(
  108. 'crm_Groups',
  109. 'crm_Persons',
  110. 'crm_Companies',
  111. 'crm_ext_IdCards',
  112. 'crm_Personalization',
  113. 'crm_ext_CourtReg',
  114. 'crm_Profiles',
  115. 'crm_Locations',
  116. 'crm_Formatter',
  117. 'crm_ext_ContragentInfo',
  118. 'crm_ext_Cards',
  119. 'migrate::updateGroupsCountry2123',
  120. 'migrate::fixCountryGroupsInput21233',
  121. 'migrate::companiesRepairSerchKeywords2124',
  122. );
  123. /**
  124. * Роли за достъп до модула
  125. */
  126. public $roles = 'crm';
  127. /**
  128. * Връзки от менюто, сочещи към модула
  129. */
  130. public $menuItems = array(
  131. array(1.32, 'Указател', 'Визитник', 'crm_Companies', 'default', 'powerUser'),
  132. );
  133. /**
  134. * Менижиране на формата формата за настройките
  135. *
  136. * @param core_Form $configForm
  137. * @return void
  138. */
  139. public function manageConfigDescriptionForm(&$configForm)
  140. {
  141. $companyOptions = array();
  142. $companyQuery = crm_Companies::getQuery();
  143. $groupId = crm_Groups::getIdFromSysId('related');
  144. $companyQuery->where("LOCATE('|{$groupId}|', #groupList)");
  145. while($cRec = $companyQuery->fetch()){
  146. $companyOptions[$cRec->id] = crm_Companies::getRecTitle($cRec, false);
  147. }
  148. $configForm->setSuggestions('CRM_CONNECTED_COMPANIES', $companyOptions);
  149. }
  150. /**
  151. * Скрипт за инсталиране
  152. */
  153. public function install()
  154. {
  155. $html = parent::install();
  156. // Кофа за снимки
  157. $Bucket = cls::get('fileman_Buckets');
  158. $html .= $Bucket->createBucket('pictures', 'Снимки', 'jpg,jpeg,image/jpeg,png', '3MB', 'user', 'every_one');
  159. // Кофа за снимки
  160. $html .= $Bucket->createBucket('location_Images', 'Снимки', 'jpg,jpeg,image/jpeg,gif,png', '6MB', 'user', 'every_one');
  161. // Кофа за crm файлове
  162. $html .= $Bucket->createBucket('crmFiles', 'CRM Файлове', null, '300 MB', 'user', 'user');
  163. // Зареждаме мениджъра на плъгините
  164. $Plugins = cls::get('core_Plugins');
  165. // Инсталираме на плъгина за превръщане на никовете в оцветени линкове
  166. $html .= $Plugins->forcePlugin('NickToLink', 'crm_ProfilesPlg', 'core_Manager', 'family');
  167. $html .= $Plugins->forcePlugin('Линкове в статусите след логване', 'crm_UsersLoginStatusPlg', 'core_Users', 'private');
  168. $html .= $Plugins->forcePlugin('Персонални настройки на системата', 'crm_PersonalConfigPlg', 'core_ObjectConfiguration', 'private');
  169. // Нагласяване на Cron
  170. $rec = new stdClass();
  171. $rec->systemId = 'PersonsToCalendarEvents';
  172. $rec->description = 'Обновяване на събитията за хората';
  173. $rec->controller = 'crm_Persons';
  174. $rec->action = 'UpdateCalendarEvents';
  175. $rec->period = 24 * 60 * 60;
  176. $rec->offset = 16;
  177. $rec->delay = 0;
  178. $html .= core_Cron::addOnce($rec);
  179. return $html;
  180. }
  181. /**
  182. * Миграция за добавяне на групи за държави
  183. */
  184. public function updateGroupsCountry2123()
  185. {
  186. $gIdArr = crm_ContragentGroupsPlg::getGroupsId();
  187. foreach (array('crm_Companies', 'crm_Persons') as $clsName) {
  188. $clsInst = cls::get($clsName);
  189. $query = $clsInst->getQuery();
  190. $query->show('groupListInput, groupList, country');
  191. while ($rec = $query->fetch()) {
  192. if (!$rec->country) {
  193. continue;
  194. }
  195. $gForAdd = drdata_CountryGroups::getGroupsArr($rec->country);
  196. foreach ($gForAdd as $id => $gRec) {
  197. $gId = $gIdArr[$id];
  198. $rec->groupListInput = type_Keylist::addKey($rec->groupListInput, $gId);
  199. }
  200. // Вземаме всички въведени от потребителя стойност
  201. $inputArr = type_Keylist::toArray($rec->groupListInput);
  202. // Намираме всички свъразани
  203. $resArr = $clsInst->expandInput($inputArr);
  204. $rec->groupList = type_Keylist::fromArray($resArr);
  205. $clsInst->save_($rec, 'groupListInput, groupList');
  206. }
  207. }
  208. crm_Groups::updateGroupsCnt('crm_Companies', 'companiesCnt');
  209. crm_Groups::updateGroupsCnt('crm_Persons', 'personsCnt');
  210. }
  211. /**
  212. * Миграция за поправка на groupsInput полето на фирмите и лицата
  213. */
  214. function fixCountryGroupsInput21233()
  215. {
  216. $gArr = crm_ContragentGroupsPlg::getGroupsId(true);
  217. foreach (array('crm_Companies', 'crm_Persons') as $clsName) {
  218. $clsInst = cls::get($clsName);
  219. $query = $clsInst->getQuery();
  220. while ($rec = $query->fetch()) {
  221. $prevVal = $rec->{$clsInst->groupFieldName};
  222. foreach ($gArr as $gId) {
  223. $rec->{$clsInst->groupFieldName} = type_Keylist::removeKey($rec->{$clsInst->groupFieldName}, $gId);
  224. }
  225. if ($prevVal != $rec->{$clsInst->groupFieldName}) {
  226. $clsInst->save_($rec, $clsInst->groupFieldName);
  227. }
  228. }
  229. }
  230. }
  231. /**
  232. * Форсира регенерирането на ключовите думи за всички мениджъри, които използват `plg_Search`
  233. */
  234. public static function companiesRepairSerchKeywords2124()
  235. {
  236. core_CallOnTime::setCall('plg_Search', 'repairSerchKeywords', 'crm_Companies', dt::addSecs(180));
  237. }
  238. }