client.plugin.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. <?php
  2. //Déclaration d'un item de menu dans le menu principal
  3. function client_menu(&$menuItems){
  4. global $myUser;
  5. if(!$myUser->can('client','read')) return;
  6. $menuItems[] = array(
  7. 'sort'=>3,
  8. 'url'=>'index.php?module=client',
  9. 'label'=>'Clients',
  10. 'icon'=> 'fas fa-user-tie',
  11. 'color'=> '#3498db'
  12. );
  13. }
  14. //Cette fonction va generer une page quand on clique sur client dans menu
  15. function client_page(){
  16. global $_;
  17. if(!isset($_['module']) || $_['module'] !='client') return;
  18. $page = !isset($_['page']) ? 'list.client' : $_['page'];
  19. $page = str_replace('..','',$page);
  20. $file = __DIR__.SLASH.'page.'.$page.'.php';
  21. if(!file_exists($file)) throw new Exception("Page ".$page." inexistante");
  22. require_once($file);
  23. }
  24. //Fonction executée lors de l'activation du plugin
  25. function client_install($id){
  26. if($id != 'fr.core.client') return;
  27. global $conf;
  28. Entity::install(__DIR__);
  29. $conf->put('client_code_mask','{{label[2]}}-{{Y}}{{M}}-{{id}}');
  30. $conf->put('client_enable_map', 1);
  31. $conf->put('client_sheet_max_field', 8);
  32. $conf->put('client_type', "both");
  33. //Doc sur : https://entreprise.data.gouv.fr/api_doc/sirene
  34. $conf->put('client_api_url','https://entreprise.data.gouv.fr/api/sirene/v1/full_text/{{label}}');
  35. $conf->put('client_api_sheet_url','https://entreprise.data.gouv.fr/api/sirene/v3/etablissements/?siren={{siret}}');
  36. $conf->put('client_label_plural','clients');
  37. $conf->put('client_label_singular','client');
  38. $conf->put('client_holding_singular','holding');
  39. $dictionary = new Dictionary();
  40. $dictionary->slug = 'client_category';
  41. $dictionary->label = 'Categorie de client';
  42. $dictionary->parent = 0;
  43. $dictionary->state = Dictionary::ACTIVE;
  44. $dictionary->save();
  45. $item = new Dictionary();
  46. $item->slug = 'client_category_none';
  47. $item->label = 'Aucune';
  48. $item->parent = $dictionary->id;
  49. $item->state = Dictionary::ACTIVE;
  50. $item->save();
  51. global $myFirm;
  52. if($myFirm->has_plugin('fr.core.export')){
  53. Plugin::need('export/ExportModel');
  54. $model = new ExportModel();
  55. $model->label = 'Export fiche client';
  56. $model->privacy = 'public';
  57. $model->dataset = 'client-sheet';
  58. $model->slug = 'client-sheet';
  59. $model->description= "Modèle d'export PDF utilisé depuis la fiche d'un client";
  60. $model->document_temporary = '';
  61. $model->export_format = 'pdf';
  62. $model->plugin = 'client';
  63. $model->filename = 'Fiche clients.html';
  64. $model->save();
  65. copy(__DIR__.SLASH.'export.html',File::dir().$model->filename);
  66. File::move(File::dir().$model->filename, 'export'.SLASH.'documents'.SLASH.'client'.SLASH.$model->id.SLASH.$model->filename);
  67. }
  68. }
  69. //Fonction executée lors de la désactivation du plugin
  70. function client_uninstall($id){
  71. if($id != 'fr.core.client') return;
  72. Entity::uninstall(__DIR__);
  73. }
  74. //Déclaration des sections de droits du plugin
  75. Right::register("client",array('label'=>"Gestion des droits sur le plugin client"));
  76. Right::register("client_history",array('label'=>"Gestion des droits sur historique du plugin client"));
  77. //Droits ciblés sur les fiches client
  78. Right::register('client_sheet',array(
  79. 'label'=>'Gestion des droits sur une fiche client particuliere',
  80. 'global'=> false,
  81. 'check' => function($action,$right){
  82. global $myUser;
  83. if($right->uid <= 0) throw new Exception('Id non spécifié');
  84. if(!$myUser->can('client','edit')) throw new Exception('Seul le un edtieur de client peut définir des droits pour cette fiche');
  85. }
  86. ));
  87. require_once(__DIR__.SLASH.'action.php');
  88. //Déclaration du menu de réglages
  89. function client_menu_setting(&$settingMenu){
  90. global $myUser;
  91. if(!$myUser->can('client','configure')) return;
  92. $settingMenu[]= array(
  93. 'sort' =>1,
  94. 'url' => 'setting.php?section=global.client',
  95. 'icon' => 'fas fa-angle-right',
  96. 'label' => 'Client'
  97. );
  98. }
  99. //Déclaration des pages de réglages
  100. function client_content_setting(){
  101. global $_;
  102. if(file_exists(__DIR__.SLASH.'setting.'.$_['section'].'.php'))
  103. require_once(__DIR__.SLASH.'setting.'.$_['section'].'.php');
  104. }
  105. //Déclaration des settings de base
  106. //Types possibles : text,select ( + "values"=> array('1'=>'Val 1'),password,checkbox. Un simple string définit une catégorie.
  107. Configuration::setting('client',array(
  108. "Général",
  109. 'client_code_mask' => array("label"=>"Masque de generation de code",
  110. "legend"=>"Macro possibles : <br>
  111. {{id}} : Identifiant unique client<br>
  112. {{label}} : libellé client, possible {{label[x]}} ou x est le nombre de lettres a conserver<br>
  113. {{M}} : Mois sur 2 digits<br>
  114. {{Y}} : Années sur 4 digits<br>
  115. {{y}} : Années sur 2 digits<br>
  116. {{rand(x,y)}} : Chiffre aléatoire entre x et y<br>
  117. ",
  118. "placeholder"=>"ex: {{label[2]}}-{{Y}}{{M}}-{{id}}","type"=>"text"),
  119. 'client_enable_map' => array("label"=>"Afficher la mini-map","type"=>"boolean"),
  120. 'client_sheet_max_field' => array("label"=>"Nombre de champs avant résumé","type"=>"number"),
  121. 'client_type' => array("label"=>"Type de client","type"=>"list",'values' => array('individual'=>'Particulier','firm'=>'Entreprise','both'=>'Les deux'), 'default'=>'both'),
  122. 'client_condition' => array("label"=>"Statut de client","type"=>"list",'values' => array('prospect'=>'Prospect','client'=>'Client','both'=>'Les deux'), 'default'=>'both'),
  123. 'client_hide_fields' => array("label"=>"Masquer les uid champs suivants","legend"=>"Uid des champs séparés par saut de ligne (ex: condition <saut de ligne> siret","type"=>"textarea"),
  124. 'Api',
  125. 'client_api_search_url' => array("label"=>"Api de recherche client","placeholder"=>"ex: https://entreprise.data.gouv.fr/api/sirene/v1/full_text/{{label}}","type"=>"text"),
  126. 'client_api_sheet_url' => array("label"=>"Api de fiche client","placeholder"=>"ex: https://entreprise.data.gouv.fr/api/sirene/v3/etablissements/?siren={{siret}}","type"=>"text"),
  127. "Terminologie",
  128. 'client_holding_singular' => array("label"=>"Libellé des holdings (singulier)",'placeholder'=>'holding',"type"=>"text"),
  129. 'client_label_plural' => array("label"=>"Libellé des clients (pluriel)",'placeholder'=>'clients',"type"=>"text"),
  130. 'client_label_singular' => array("label"=>"Libellé des clients (singulier)",'placeholder'=>'client',"type"=>"text"),
  131. ));
  132. //Affichage du/des widget(s)
  133. function client_widget(&$widgets){
  134. global $myUser;
  135. require_once(PLUGIN_PATH.'dashboard'.SLASH.'DashboardWidget.class.php');
  136. $modelWidget = new DashboardWidget();
  137. $modelWidget->model = 'client';
  138. $modelWidget->title = 'Client';
  139. $modelWidget->icon = 'fas fa-user-tie';
  140. $modelWidget->background = '#6B5B95';
  141. $modelWidget->load = 'action.php?action=client_widget_load';
  142. $modelWidget->js = [Plugin::url().'/js/widget.js?v=2'];
  143. $modelWidget->css = [Plugin::url().'/css/widget.css?v=2'];
  144. $modelWidget->description = "Module de gestion des clients et prospects";
  145. $widgets[] = $modelWidget;
  146. }
  147. function client_tab_menu(&$clientMenu,$client){
  148. $menu = new MenuItem();
  149. $menu->label = 'Accueil';
  150. $menu->url = '#tab=home';
  151. $menu->slug = 'home';
  152. $menu->sort = -1;
  153. $clientMenu[] = $menu;
  154. }
  155. function client_tab_page($slug){
  156. if($slug != 'home') return;
  157. require_once(__DIR__.SLASH.'tab.home.php');
  158. }
  159. function client_merge($clientBase,$clientToMerge,&$logs){
  160. require_once(__DIR__.SLASH.'Client.class.php');
  161. $logs[] = ' Migration des sous clients attachés ';
  162. Client::change(array('parent'=>$clientBase->id),array('parent'=>$clientToMerge->id));
  163. $logs[] = ' Migration des contacts attachés ';
  164. ContactPerson::change(array('uid'=>$clientBase->id),array('scope'=>'client','uid'=>$clientToMerge->id));
  165. $logs[] = ' Migration des adresses attachées ';
  166. Address::change(array('uid'=>$clientBase->id),array('scope'=>'client','uid'=>$clientToMerge->id));
  167. }
  168. //Declaration des évenements et entités workflow
  169. Plugin::addHook("workflow_event", function(&$events){
  170. //Evenement entité
  171. $events[] = WorkflowEvent::registerEntity(__DIR__.SLASH.'Client.class.php');
  172. //Evenement liste d'entité
  173. $events[] = WorkflowEvent::registerList(__DIR__.SLASH.'Client.class.php');
  174. });
  175. global $myFirm;
  176. if( $myFirm->has_plugin('fr.core.export')){
  177. require_once(__ROOT__.PLUGIN_PATH.'export'.SLASH.'ExportModel.class.php');
  178. ExportModel::add('client','client-sheet', 'Fiche client', function($parameters){
  179. global $myUser,$myFirm;
  180. require_once(__DIR__.SLASH.'Client.class.php');
  181. $client = new Client();
  182. if(isset($parameters['description']) && $parameters['description']!=true && !empty($parameters['id']))
  183. $client = Client::getById($parameters['id']);
  184. $data['client'] = ExportModel::fromEntity($client);
  185. unset($data['client']['value']['parent']);
  186. if(empty($client->comment)) unset($data['client']['value']['comment']['value']);
  187. $data['client']['value']['category']['value'] =
  188. isset($data['client']['value']['category']) && $data['client']['value']['category']['value']!=0 ? Dictionary::getById($data['client']['value']['category']['value'])->label: 'Aucune';
  189. if(!empty($data['client']['value']['type']['value']))
  190. $data['client']['value']['type']['value'] = Client::types($data['client']['value']['type']['value'])['label'];
  191. if(!empty($data['client']['value']['condition']['value']))
  192. $data['client']['value']['condition']['value'] = Client::conditions($data['client']['value']['condition']['value'])['label'];
  193. $data['client']['value']['created']['value'] = $data['client']['value']['created']['value'];
  194. $data['client']['value']['updated']['value'] = $data['client']['value']['updated']['value'];
  195. $data['client']['value']['updater']['value'] = User::byLogin($data['client']['value']['updater']['value'])->fullName();
  196. $data['client']['value']['creator']['value'] = User::byLogin($data['client']['value']['creator']['value'])->fullName();
  197. //export des contacts liés
  198. $data['client']['value']['contacts'] = array('label'=>'Liste des contacts', 'type'=>'list','value' => array());
  199. $contacts = $client->id == 0 ? array(new ContactPerson()) :ContactPerson::loadAll(array('scope'=>'client','uid'=>$client->id));
  200. foreach($contacts as $contact){
  201. $contact->meta();
  202. $contactRow = ExportModel::fromEntity($contact)['value'];
  203. $contactRow['phone']['value'] = $contact->phone;
  204. $contactRow['mobile']['value'] = $contact->mobile;
  205. $contactRow['mail']['value'] = $contact->mail;
  206. $data['client']['value']['contacts']['value'][] = $contactRow;
  207. }
  208. //export des adresses liées
  209. $data['client']['value']['addresses'] = array('label'=>'Liste des adresses liées', 'type'=>'list','value' => array());
  210. $addresses = $client->id == 0 ? array(new Address()) :$client->addresses();
  211. foreach($addresses as $address){
  212. $data['client']['value']['addresses']['value'][] = ExportModel::fromEntity($address)['value'];
  213. }
  214. //export des champs custom
  215. if($myFirm->has_plugin('fr.core.dynamicform')){
  216. Plugin::need('dynamicform/DynamicForm');
  217. $data['client']['value']['dynamicFields'] = array('label'=>'Champs personnalisés liés', 'type'=>'list','value' => array());
  218. $dynamicFields = DynamicForm::show('client-sheet-custom',array(
  219. 'arrayOutput' => true,
  220. 'firm' => $myFirm->id,
  221. 'uid' => $client->id,
  222. 'scope' => 'client'
  223. ));
  224. $fieldTypes = FieldType::available();
  225. if(is_array($dynamicFields)){
  226. foreach($dynamicFields as $dynamicField){
  227. $value = $dynamicField['value'];
  228. if(!isset( $fieldTypes[$dynamicField['type']->slug]) ) continue;
  229. $type = $fieldTypes[$dynamicField['type']->slug];
  230. if(!empty($value) && property_exists($type,"onRawDisplay")){
  231. $method = $type->onRawDisplay;
  232. $value = $method($value,array('type'=>$type));
  233. }
  234. $data['client']['value']['dynamicFields']['value'][] = array(
  235. 'value' => array('label' => $dynamicField['label'] , 'value' => $value )
  236. );
  237. }
  238. }
  239. }
  240. $data['client']['value']['logo'] = array(
  241. 'label'=>'Logo du client',
  242. 'type'=>'image',
  243. 'value' => file_get_contents($client->logo(true))
  244. );
  245. if(empty($client->comment)) $data['client']['value']['comment']['value'] = false;
  246. $parent = new Client();
  247. $parent->label = 'Aucun';
  248. if(!empty($client->parent)) $parent = Client::getById($client->parent);
  249. $data['client']['value']['parent'] = ExportModel::fromEntity($parent);
  250. // print_r($data['client']['value']['parent']);
  251. // print_r($client->parent);
  252. // exit();
  253. return $data;
  254. });
  255. }
  256. function client_list_action(){
  257. ?>
  258. <a class="dropdown-item" onclick="client_client_search({exportMode:true,keepChecked:true});" href="#"><i class="fa fa-file-export"></i> Exporter en excel</a>
  259. <a class="dropdown-item" onclick="client_client_mail_copy();" href="#"><i class="far fa-envelope-open"></i> Copier les e-mails</a>
  260. <?php
  261. }
  262. function client_filter(&$filters){
  263. global $conf;
  264. require_once(__DIR__.SLASH.'Client.class.php');
  265. $types = array();
  266. foreach (Client::types() as $key => $value)
  267. $types[$key] = $value['label'];
  268. $conditions = array();
  269. foreach (Client::conditions() as $key => $value)
  270. $conditions[$key] = $value['label'];
  271. $hideFields = explode("\n",$conf->get('client_hide_fields'));
  272. $currentFilters = array(
  273. 'id' => '<option value="main.id" data-filter-type="number">Identifiant unique</option>',
  274. 'type' => '<option value="main.type" data-filter-type="list" data-values=\''.json_encode($types).'\'>Type</option>',
  275. 'condition' => '<option value="main.condition" data-filter-type="list" data-values=\''.json_encode($conditions).'\'>Statut</option>',
  276. 'creator' => '<option value="main.creator" data-filter-type="user">Auteur</option>',
  277. 'label' => '<option value="main.label" data-filter-type="text">Libellé</option>',
  278. 'firm' => '<option value="fi.id" data-filter-type="firm">Etablissement</option>',
  279. 'created' => '<option value="main.created" data-filter-type="date">Création</option>',
  280. 'job' => '<option value="main.job" data-filter-type="text">Métier</option>',
  281. 'code' => '<option value="main.code" data-filter-type="text">Code '.$conf->get('client_label_singular').'</option>',
  282. 'siret' => '<option value="main.siret" data-filter-type="text">N° SIRET</option>',
  283. 'address.city' => '<option value="address.city" data-filter-type="text">Ville</option>',
  284. 'address.zip' => '<option value="address.zip" data-filter-type="text">Code postal</option>',
  285. 'mail.value' => '<option value="mail.value" data-filter-type="text">Adresse E-mail</option>',
  286. 'phone.value' => '<option value="phone.value" data-filter-type="text">N° Téléphone</option>',
  287. 'comment' => '<option value="main.comment" data-filter-type="text">Commentaire</option>',
  288. 'internal_contact' => '<option value="internal_contact" data-filter-type="user">Client contact</option>'
  289. );
  290. foreach($currentFilters as $key=>$filter){
  291. if(in_array($key,$hideFields)) unset($currentFilters[$key]);
  292. }
  293. $filters = array_merge($filters, $currentFilters);
  294. }
  295. function client_search_view(&$columns){
  296. global $conf;
  297. $hideFields = explode("\n",$conf->get('client_hide_fields'));
  298. $mycolumns = array(
  299. 'logo' =>
  300. array(
  301. 'head' => '<th></th>',
  302. 'body' => '<td class="align-middle text-center"><img class="client-logo-mini avatar-rounded" data-src="{{logo}}"></td>',
  303. ),
  304. 'label' =>
  305. array(
  306. 'head' => '<th data-sortable="main.label">Libellé</th>',
  307. 'body' => '<td class="align-middle">
  308. <a href="index.php?module=client&page=sheet.client&id={{id}}" data-type="card" data-show-delay="800" data-action="client_card" data-parameters=\'{"id":"{{id}}"}\'>{{{label}}}</a> {{#pseudonym}}<small class="text-muted">({{{pseudonym}}})</small>{{/pseudonym}}
  309. {{#holding}}<br><small class="text-muted">Sous etablissement de <a href="index.php?module=client&page=sheet.client&id={{holding.id}}">{{{holding.label}}}</a></small>{{/holding}}
  310. {{#affiliate}}<br><small class="text-muted">'.$conf->get('client_holding_singular').' de <span class="text-info" title="{{#affiliate.rows}}{{label}}{{/affiliate.rows}}">{{affiliate.count}} Etablissement(s)</span></small>{{/affiliate}}
  311. {{#job}}<br/><small class="text-muted">{{{job}}}</small>{{/job}}
  312. </td>',
  313. ),
  314. 'code' =>
  315. array(
  316. 'head' => '<th data-sortable="code" data-available="created">Code '.($conf->get('client_label_singular')).'</th>',
  317. 'body' => '<td class="align-middle">{{code}}</td>',
  318. ),
  319. 'city' =>
  320. array(
  321. 'head' => '<th data-sortable="address.city">Ville</th>',
  322. 'body' => '<td class="align-middle text-warning" title="{{address.street}} {{address.complement}} {{address.zip}} {{address.city}}">
  323. {{address.city}} {{#address.zip}}
  324. <small class="text-muted">
  325. ({{address.zip}})
  326. <a title="Afficher sur Google Map" target="_blank" href="{{address.mapurl}}"><i class="fas fa-map-marked-alt text-muted ml-2 pointer"></i></a>
  327. </small>
  328. {{/address.zip}}
  329. </td>',
  330. ),
  331. 'type' =>
  332. array(
  333. 'head' => '<th data-sortable="main.type" data-available="main.type">Type</th>',
  334. 'body' => '<td class="align-middle">{{type.label}}</td>',
  335. ),
  336. 'category' =>
  337. array(
  338. 'head' => '<th data-sortable="category.label" data-available="main.category">Categorie</th>',
  339. 'body' => '<td class="align-middle">{{category.label}}</td>',
  340. ),
  341. 'mail' =>
  342. array(
  343. 'head' => '<th data-sortable="mail.value" data-available="mail">E-mail</th>',
  344. 'body' => '<td class="align-middle"><a href="mailto:{{mail}}">{{mail}}</a></td>',
  345. ),
  346. 'phone' =>
  347. array(
  348. 'head' => '<th data-sortable="phone.value" data-available="main.phone">Téléphone</th>',
  349. 'body' => '<td class="align-middle">{{phone}}</td>',
  350. ),
  351. 'comment' =>
  352. array(
  353. 'head' => '<th data-sortable="main.comment" data-available="main.comment">Commentaire</th>',
  354. 'body' => '<td class="align-middle" ><small style="display:block;max-width:300px;max-height:40px;overflow:auto;">{{comment}}</small></td>',
  355. ),
  356. 'condition' =>
  357. array(
  358. 'head' => '<th data-sortable="main.condition" data-available="main.created">Statut</th>',
  359. 'body' => '<td class="align-middle">{{condition.label}}</td>',
  360. ),
  361. 'firm' =>
  362. array(
  363. 'head' => '<th data-sortable="fi.label" data-available="fi.label">Etablissement</th>',
  364. 'body' => '<td class="align-middle">{{firm.label}}</td>',
  365. )
  366. );
  367. foreach($mycolumns as $key=>$column){
  368. if(in_array($key,$hideFields)) continue;
  369. $columns[$key]= $column;
  370. }
  371. }
  372. function client_sheet(&$sheet,$client){
  373. global $conf;
  374. $contacts = $client->contacts();
  375. $phone = isset($contacts[Contact::MOBILE]) ? $contacts[Contact::MOBILE] : new Contact();
  376. $mail = isset($contacts[Contact::PROFESSIONAL_MAIL]) ? $contacts[Contact::PROFESSIONAL_MAIL] : new Contact();
  377. $sheet = array();
  378. $hideFields = explode("\n",$conf->get('client_hide_fields'));
  379. $sheet['label'] = array(
  380. 'client-type' => 'firm',
  381. 'label' => 'Libellé <small>'.( !empty($client->code) ? '(N°'.$client->code.')':'').'</small>',
  382. 'before' => '<div class="input-group">',
  383. 'after' => '
  384. <div class="input-group-append editable-only"> '.(!empty($conf->get('client_api_search_url')) ? '<span class="btn text-muted" onclick="client_internet_modal()"><i class="fas fa-globe pointer" data-tooltip title="Récuperer les informations sur internet"></i></span>':'').'
  385. </div>
  386. <div class="input-group-append"> <span class="btn text-muted" onclick="client_switch_pseudonym(true)"><i class="fas fa-sort" data-tooltip title="Renseigner un pseudonyme"></i></span>
  387. </div>
  388. </div>',
  389. 'sort' => 10,
  390. 'block-class' => 'type-both block-label',
  391. 'attributes' => array(
  392. 'onchange' => '"client_client_check_duplicate(this)"'
  393. ),
  394. 'class' => 'text-uppercase',
  395. 'value' => html_entity_decode($client->label)
  396. );
  397. $sheet['pseudonym'] = array(
  398. 'client-type' => 'firm',
  399. 'label' => 'Pseudonyme',
  400. 'before' => '<div class="input-group">',
  401. 'after' => '
  402. <div class="input-group-append"> <span class="btn text-muted" onclick="client_switch_pseudonym(false)"><i class="fas fa-sort" data-tooltip title="Renseigner le libellé"></i></span>
  403. </div>
  404. </div>',
  405. 'sort' => 11,
  406. 'block-class' => 'type-both block-pseudonym hidden',
  407. 'class' => 'text-uppercase',
  408. 'value' => html_entity_decode($client->pseudonym)
  409. );
  410. if(!in_array('job',$hideFields))
  411. $sheet['job'] = array(
  412. 'client-type' => 'firm',
  413. 'label' => 'Métier',
  414. 'sort' => 20,
  415. 'block-class' => 'type-both',
  416. 'value' => html_entity_decode($client->job)
  417. );
  418. $sheet['firstname'] = array(
  419. 'client-type' => 'individual',
  420. 'label' => 'Prénom',
  421. 'sort' => 8,
  422. 'block-class' => 'type-individual',
  423. 'attributes' => array(
  424. 'onkeyup' => '"client_name_change()"'
  425. ),
  426. 'value' => html_entity_decode($client->firstname)
  427. );
  428. $sheet['name'] = array(
  429. 'client-type' => 'individual',
  430. 'label' => 'Nom',
  431. 'sort' => 9,
  432. 'block-class' => 'type-individual',
  433. 'class' => 'text-uppercase',
  434. 'attributes' => array(
  435. 'onkeyup' => '"client_name_change()"'
  436. ),
  437. 'value' => html_entity_decode($client->name)
  438. );
  439. if($conf->get('client_condition') == 'both' || empty($conf->get('client_condition')) ){
  440. $sheet['condition'] = array(
  441. 'sort' => 30,
  442. 'label' => 'Statut',
  443. 'type' => 'choice',
  444. 'block-class' => 'condition-block',
  445. 'values' => array(
  446. 'prospect' => 'Prospect',
  447. 'client' => 'Client',
  448. ),
  449. 'value' => $client->condition == '' ? 'prospect' : $client->condition,
  450. );
  451. }
  452. if(!in_array('category',$hideFields))
  453. $sheet['category'] = array(
  454. 'sort' => 40,
  455. 'label' => 'Catégorie',
  456. 'block-class' => 'field-block',
  457. 'type' => 'dictionary',
  458. 'attributes' => array(
  459. 'data-slug' => '"client_category"',
  460. 'data-value' => '"'.$client->category.'"'
  461. )
  462. );
  463. if(!in_array('mail',$hideFields))
  464. $sheet['mail'] = array(
  465. 'sort' => 60,
  466. 'label' => 'E-Mail',
  467. 'before' => '<div class="input-group">',
  468. 'after' => '</div>',
  469. 'attributes' => array(
  470. 'onchange' => '"client_client_check_duplicate(this)"'
  471. ),
  472. 'value' => html_entity_decode($mail->value)
  473. );
  474. if(!in_array('phone',$hideFields))
  475. $sheet['phone'] = array(
  476. 'sort' => 70,
  477. 'label' => 'Téléphone',
  478. 'before' => '<div class="input-group">',
  479. 'after' => '</div>',
  480. 'attributes' => array(
  481. 'onchange' => '"client_client_check_duplicate(this)"'
  482. ),
  483. 'value' => normalize_phone_number($phone->value)
  484. );
  485. if(!in_array('siret',$hideFields))
  486. $sheet['siret'] = array(
  487. 'sort' => 80,
  488. 'client-type' => 'firm',
  489. 'label' => 'N° SIRET',
  490. 'block-class' => 'type-firm',
  491. 'before' => '<div class="input-group">',
  492. 'after' => '</div>',
  493. 'attributes' => array(
  494. 'onchange' => '"client_client_check_duplicate(this)"'
  495. ),
  496. 'value' => $client->siret
  497. );
  498. if(!in_array('comment',$hideFields))
  499. $sheet['comment'] = array(
  500. 'type' => 'textarea',
  501. 'label' => 'Commentaire',
  502. 'value' => html_entity_decode($client->comment)
  503. );
  504. }
  505. function client_field_type(&$types){
  506. //User
  507. $type = new FieldType();
  508. $type->slug = 'client';
  509. $type->label = 'Client';
  510. $type->sqlType = 'integer';
  511. $type->default_attributes =
  512. array(
  513. 'class'=>'"form-control"',
  514. 'data-type'=>'"client"',
  515. 'type'=>'"text"'
  516. );
  517. $type->filter = array(
  518. 'operators' => array (
  519. '=' =>array('view'=>'client'),
  520. '!=' =>array('view'=>'client'),
  521. 'null' =>array(),
  522. 'not null' =>array()
  523. )
  524. );
  525. $type->onInput = $types['text']->onInput;
  526. $type->onRawDisplay = function($value,$options = array()){
  527. if(is_null($value) || empty($value)) return;
  528. require_once(__DIR__.SLASH.'Client.class.php');
  529. if(empty($value)) return '';
  530. $client = Client::getById($value);
  531. return !$client ? '' : $client->label;
  532. };
  533. $type->onHtmlDisplay = function($value,$options){
  534. if(is_null($value) || empty($value)) return;
  535. require_once(__DIR__.SLASH.'Client.class.php');
  536. $client = Client::getById($value);
  537. return '<a href="index.php?module=client&page=sheet.client&id='.$value.'">'.$client->label.'</a>';
  538. };
  539. $type->icon = 'fab fa-black-tie';
  540. $type->description = 'Autocompletion sur les clients';
  541. $type->default = '';
  542. $types[$type->slug] = $type;
  543. }
  544. function client_sheet_option(&$options){
  545. global $myUser,$_,$myFirm;
  546. if($myUser->can('client','configure')):
  547. $options[] = '<div class="dropdown-item pointer user-select-none px-3" title="Fusionner ce client" onclick="client_client_merge_edit()"><i class="fas fa-object-group text-warning"></i> Fusionner</div>';
  548. endif;
  549. if($myUser->can('export', 'read') && $myFirm->has_plugin('fr.core.export')) :
  550. $options[] = '<div class="d-inline-block" data-type="export-model" data-parameters=\''.stripslashes(json_encode(array("plugin"=>"client","dataset"=>"client-sheet","id"=>$_['id']))).'\'>
  551. <div class="dropdown-item pointer user-select-none px-3" title="Exporter ce client"><i class="fas fa-download"></i> Exporter</div>
  552. </div>';
  553. endif;
  554. if($myUser->can('client','edit') || ($_['id']!=0 && $myUser->can('client_sheet','edit',$_['id']))):
  555. $options[] = '<div class="dropdown-item pointer user-select-none px-3" data-type="right"
  556. data-scope = "client_sheet" data-uid = "'.$_['id'].'"><i class="fas fa-user-lock"></i> Permissions sur la fiche</div>';
  557. endif;
  558. if($myUser->can('client','delete') || ($_['id']!=0 && $myUser->can('client_sheet','delete',$_['id']))):
  559. $options[] = '<div class="dropdown-item text-danger pointer user-select-none px-3" title="Supprimer ce client" onclick="client_client_delete()"><i class="fa fa-trash-alt"></i> Supprimer</div>';
  560. endif;
  561. }
  562. //Déclation des assets
  563. Plugin::addCss("/css/main.css");
  564. Plugin::addJs("/js/main.js");
  565. Plugin::addCss('/css/component.css');
  566. Plugin::addJs('/js/component.js');
  567. //Mapping hook / fonctions
  568. Plugin::addHook("install", "client_install");
  569. Plugin::addHook("uninstall", "client_uninstall");
  570. Plugin::addHook("menu_main", "client_menu");
  571. Plugin::addHook("page", "client_page");
  572. Plugin::addHook("menu_setting", "client_menu_setting");
  573. Plugin::addHook("content_setting", "client_content_setting");
  574. Plugin::addHook("widget", "client_widget");
  575. Plugin::addHook("client_merge", "client_merge");
  576. Plugin::addHook("field_types", "client_field_type");
  577. Plugin::addHook("client_sheet_option", "client_sheet_option");
  578. Plugin::addHook("client_list_action","client_list_action");
  579. Plugin::addHook("client_menu", "client_tab_menu");
  580. Plugin::addHook("client_page", "client_tab_page");
  581. Plugin::addHook("client_filter", "client_filter");
  582. Plugin::addHook("client_sheet", "client_sheet");
  583. Plugin::addHook("client_search_view","client_search_view");
  584. ?>