page.sheet.client.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. <?php
  2. global $conf,$myUser,$myFirm;
  3. require_once(__DIR__.SLASH.'Client.class.php');
  4. $client = Client::provide();
  5. if(!$myUser->can('client','read') && $client->id!=0 && !$myUser->can('client_sheet','read',$client->id)) throw new Exception("Permission non accordée sur cette fiche");
  6. if(isset($_['id']) && !$client) throw new Exception("Aucun client existant avec cet identifiant");
  7. $addresses = $client->addresses('global');
  8. $mainAddress = !empty($addresses) ? $addresses[0]: new Address();
  9. $contacts = $client->contacts();
  10. $phone = isset($contacts['phone']) ? $contacts['phone'] : new Contact();
  11. $phoneValue = $phone->value;
  12. if(!empty($phone->value)) $phoneValue = implode(' ',str_split($phone->value,2));
  13. $mail = isset($contacts['mail']) ? $contacts['mail'] : new Contact();
  14. $clientMenu = array();
  15. if($client->creator == '') $client->creator = $myUser->login;
  16. if($client->updater == '') $client->updater = $myUser->login;
  17. $creator = User::byLogin($client->creator);
  18. $updater = User::byLogin($client->updater);
  19. $subsites = $client->subsites();
  20. $holding = isset($_['parent']) ? Client::getById($_['parent']) : $client->holding();
  21. $holdingPhone = '';
  22. $holdingAddress = new Address();
  23. if($holding->id!=0){
  24. $holdingPhone = $holding->contacts('phone')->value;
  25. $holdingAddress = $holding->addresses('global');
  26. $holdingAddress = !empty($holdingAddress) ? $holdingAddress[0] : new Address();
  27. }
  28. Plugin::callHook('client_menu',array(&$clientMenu,$client));
  29. usort($clientMenu,function($a,$b){
  30. if($a->sort < $b->sort) return -1;
  31. if($a->sort > $b->sort) return 1;
  32. if($a->sort == $b->sort) return 0;
  33. });
  34. $editable = $myUser->can('client','edit') && ($client->id==0 || $client->firm==$myFirm->id || $myUser->can('client_sheet','edit',$client->id));
  35. ?>
  36. <div class="client-container" data-client-type="<?php echo !empty($client->type) ? $client->type : $conf->get('client_type'); ?>" data-id="<?php echo $client->id; ?>" data-editable="<?php echo $editable === true ?'1':'0' ?>">
  37. <div class="client-summary-panel">
  38. <div class="client-thumbnail type-firm" style="background-image:url(action.php?action=client_assets_load&type=cover&client=<?php echo $client->id; ?>)"></div>
  39. <div class="client-summary-sheet p-3">
  40. <h1 class="client-label m-0" data-live-update="#label"><?php echo $client->label; ?></h1>
  41. <small class="text-muted d-inline-block mb-2 w-100" data-live-update="#code">N° <?php echo $client->code; ?></small>
  42. <div class="button right d-block d-sm-none" title="Contacts et Adresses" onclick="client_contact_mobile_toggle();"><i class="far fa-address-book"></i></div>
  43. <h2 class="client-job type-firm" data-live-update="#job"></h2>
  44. <span class="client-city" data-city="<?php echo $mainAddress->city; ?>" data-zip="<?php echo $mainAddress->zip; ?>"><i class="fas fa-map-marker-alt"></i> <span><?php echo $mainAddress->city.(!empty($mainAddress->zip)?' ('.$mainAddress->zip.')':''); ?></span> </span>
  45. <ul class="client-contact">
  46. <li class="<?php echo empty($phone->value)?'hidden':''; ?>"><i class="fas fa-mobile-alt mr-1"></i> <span data-type="phone-text" data-live-update="#phone"><?php echo $phoneValue; ?></span></li>
  47. <li class="<?php echo empty($mail->value)?'hidden':''; ?>"><i class="fas fa-envelope-open-text"></i> <span data-live-update="#mail"><?php echo $mail->value; ?></span></li>
  48. </ul>
  49. <div class="client-created" title="Modifié le <?php echo complete_date($client->updated); ?> par <?php echo $updater->fullName(); ?>">
  50. <i class="far fa-calendar-alt"></i> Créé le <span><?php echo complete_date($client->created); ?></span><br>
  51. <i class="fas fa-user-tie"></i> Créé par <span><?php echo $creator->fullName(); ?></span>
  52. </div>
  53. <?php
  54. //hook panel de gauche après créé par...
  55. Plugin::callHook('client_panel',array($client));
  56. ?>
  57. </div>
  58. <div class="client-summary-sites type-firm">
  59. <div >
  60. <h3 class="text-uppercase mb-0"><?php echo mb_strtoupper($conf->get('client_holding_singular')); ?>
  61. <a class="right pointer client-edition editable-only" data-tooltip title="Lier cette entreprise à un client existant" onclick="client_relation_add(true);"><i class="fas fa-link" ></i></a>
  62. </h3>
  63. <ul id="holding" class="p-0 m-0"></ul>
  64. </div>
  65. <h3 class="text-uppercase"><span class="client-subsite-count"></span>Sous-établissements <a class="right pointer client-edition editable-only" data-tooltip title="Ajouter un sous-établissement" onclick="window.location = 'index.php?module=client&page=sheet.client&parent='+$.urlParam('id');"><i class="far fa-plus-square" ></i></a></h3>
  66. <div class="clear"></div>
  67. <ul id="subsites" class="m-0" >
  68. <li class="hidden site-block" data-id="{{id}}" data-level="{{level}}">
  69. <a href="index.php?module=client&page=sheet.client&id={{id}}">
  70. <h4 class="my-2"><i class="far fa-building"></i> {{label}}</h4>
  71. <p>{{#address.id}}{{address.street}} {{address.complement}}<br>
  72. {{address.zip}} {{address.city}}{{/address.id}}{{#phone}} - {{phone}}{{/phone}}</p>
  73. </a>
  74. <i class="fas fa-times text-muted btn-relation-delete" title="Supprimer la relation" onclick="client_relation_delete(this)"></i>
  75. <div class="clear"></div>
  76. </li>
  77. </ul>
  78. </div>
  79. <div class="client-summary-memberof type-individual">
  80. <h3 class="text-uppercase pb-0 mb-0">LIAISONS</h3>
  81. <ul id="memberof" class="m-0"></ul>
  82. </div>
  83. </div>
  84. <div class="client-content-panel">
  85. <div class="client-menu-bar">
  86. <ul>
  87. <?php foreach ($clientMenu as $menu): ?>
  88. <li data-slug="<?php echo $menu->slug; ?>" ><a href="<?php echo $menu->url; ?>"><?php echo $menu->label; ?></a></li>
  89. <?php endforeach; ?>
  90. </ul>
  91. <div class="button right contact-btn d-none d-sm-block" title="Contacts et Adresses" onclick="client_contact_mobile_toggle();"><i class="far fa-address-book"></i></div>
  92. </div>
  93. <div class="client-content-page">
  94. <!-- TAB CONTENT HERE -->
  95. </div>
  96. </div>
  97. <!-- CONTACTS & ADRESSES-->
  98. <div class="client-contact-panel">
  99. <div onclick="client_contact_mobile_toggle();" class="btn w-100 text-center text-uppercase d-block"><i class="fas fa-times"></i> Fermer</div>
  100. <!-- CONTACTS -->
  101. <div class="type-firm pb-2">
  102. <div onclick="client_contact_edit();" class="btn btn-info client-edition text-uppercase editable-only"><i class="fas fa-user-edit"></i> Ajouter</div>
  103. <h4 class="mt-3 mb-1 contacts-title text-uppercase">Contacts (<span>0</span>)</h4>
  104. <ul id="contacts" class="contacts-list">
  105. <li class="hidden contact-template" data-id="{{id}}" >
  106. <div class="dropdown btn-options editable-only">
  107. <div class="btn" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  108. <i class="fas fa-ellipsis-v text-muted"></i>
  109. </div>
  110. <div class="dropdown-menu p-0" aria-labelledby="dropdownMenuButton">
  111. <a class="dropdown-item px-3" title="Éditer ce contact" onclick="client_contact_edit(this)"><i class="fas fa-pencil-alt"></i> Éditer</a>
  112. <a class="dropdown-item px-3 text-danger" title="Supprimer ce contact" onclick="client_contact_delete(this)"><i class="fas fa-trash-alt"></i> Supprimer</a>
  113. </div>
  114. </div>
  115. <div class="contact-avatar" onclick="{{#link}}window.location='{{link}}';{{/link}}"><img class="avatar-rounded" src="{{avatar}}"></div>
  116. <div class="d-inline-block ml-2" onclick="{{#link}}window.location='{{link}}';{{/link}}">
  117. <h2>{{fullName}}</h2>
  118. <span class="text-muted">{{job}}</span>
  119. {{#mobile}}<span class="text-muted d-block" data-type="phone-text">{{mobile}}</span>{{/mobile}}
  120. {{^mobile}}{{#phone}}<span class="text-muted d-block" data-type="phone-text">{{phone}}</span>{{/phone}}{{/mobile}}
  121. {{#mail}}<span class="text-muted d-block"><a href="mailto:{{mail}}">{{mail}}</a></span>{{/mail}}
  122. {{#hasTag}}
  123. <div>
  124. {{#tag}}
  125. <span class="badge badge-secondary">{{.}}</span>
  126. {{/tag}}
  127. </div>
  128. {{/hasTag}}
  129. </div>
  130. </li>
  131. </ul>
  132. <h4 class="mt-3 mb-1 internals-title text-uppercase">Référents internes(<span>0</span>)</h4>
  133. <ul id="internals" class="internals-list"></ul>
  134. <hr class="mb-0">
  135. </div>
  136. <!-- ADRESSES -->
  137. <div class="pb-2">
  138. <div onclick="client_address_edit();" class="btn btn-info client-edition text-uppercase editable-only"><i class="fas fa-map-marked-alt"></i> Ajouter</div>
  139. <h4 class="mt-3 mb-1 address-title text-uppercase">Adresses (<span>0</span>)</h4>
  140. <ul id="addresses" class="addresses-list">
  141. <li class="hidden address d-flex" onclick="client_address_change(this)" data-id="{{id}}" data-street="{{street}}" data-complement="{{complement}}" data-zip="{{zip}}" data-city="{{city}}" data-country="{{country}}" data-type="{{type.slug}}">
  142. <div class="dropdown btn-options">
  143. <div class="btn" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  144. <i class="fas fa-ellipsis-v text-muted"></i>
  145. </div>
  146. <div class="dropdown-menu p-0" aria-labelledby="dropdownMenuButton">
  147. <a class="dropdown-item px-3" title="Copier cette adresse" onclick="client_address_copy(this)"><i class="fas fa-clipboard"></i> Copier adresse</a>
  148. <a class="dropdown-item px-3 editable-only" title="Éditer cette adresse client" onclick="client_address_edit(this)"><i class="fas fa-pencil-alt"></i> Éditer</a>
  149. <a class="dropdown-item px-3 text-danger editable-only" title="Supprimer cette adresse client" onclick="client_address_delete(this)"><i class="fas fa-trash-alt"></i> Supprimer</a>
  150. </div>
  151. </div>
  152. <div class="address-avatar my-auto"><i class="{{type.icon}}"></i></div>
  153. <div class="adress-content d-inline-block ml-3">
  154. <h2>{{type.label}}</h2>
  155. <p class="text-muted mb-0">
  156. {{street}} {{complement}},
  157. <br>{{#zip}}{{zip}}{{/zip}}{{^zip}}-{{/zip}} {{#city}}{{city}}{{/city}}{{^city}}-{{/city}}
  158. <br>{{#country}}{{country}}{{/country}}
  159. </p>
  160. </div>
  161. </li>
  162. </ul>
  163. </div>
  164. </div>
  165. </div>
  166. <!-- Modale contact -->
  167. <!-- Modal -->
  168. <div class="modal fade" id="contactModal" tabindex="-1" role="dialog" aria-hidden="true">
  169. <div class="modal-dialog" role="document">
  170. <div class="modal-content">
  171. <div class="modal-header bg-secondary">
  172. <h5 class="modal-title" id="contact-modal">Contact</h5>
  173. <button type="button" class="close text-white" data-dismiss="modal" aria-label="Close">
  174. <span aria-hidden="true">&times;</span>
  175. </button>
  176. </div>
  177. <div class="modal-body">
  178. <div class="row">
  179. <div class="col-md-12">
  180. <h6 class="text-muted text-uppercase">Type de contact</h6>
  181. <label class="px-2 pl-0 pointer" onclick="client_contact_type()"><input type="radio" checked="checked" name="contact-type" data-value="external" data-type="radio"> Contact externe</label>
  182. <label class="px-2 pr-0 pointer" onclick="client_contact_type()"><input type="radio" name="contact-type" data-value="client" data-type="radio"> <?php echo ucFirst($conf->get('client_label_singular')); ?> contact</label>
  183. <label class="px-2 pr-0 pointer" onclick="client_contact_type()"><input type="radio" name="contact-type" data-value="user" data-type="radio"> Référent interne</label>
  184. </div>
  185. </div>
  186. <hr class="my-2">
  187. <div class="contact-type-block external-type-block">
  188. <div class="row mb-2">
  189. <div class="col-md-6">
  190. <label class="mb-1" for="firstname">Prénom :</label>
  191. <div class="input-group">
  192. <select class="form-control form-control-sm" id="civility">
  193. <option value="m">M</option>
  194. <option value="mme">Mme</option>
  195. </select>
  196. <input id="firstname" name="firstname" class="form-control form-control-sm" placeholder="eg. John" value="" type="text">
  197. </div>
  198. </div>
  199. <div class="col-md-6">
  200. <label class="mb-1" for="name">Nom :</label>
  201. <input id="name" name="name" class="form-control form-control-sm" placeholder="eg. Doe" value="" type="text">
  202. </div>
  203. </div>
  204. <div class="row mb-2">
  205. <div class="col-md-4">
  206. <label class="mb-1" for="contact-mail">Mail :</label>
  207. <input id="contact-mail" class="form-control form-control-sm" placeholder="eg. john.doe@exemple.com" value="" type="text">
  208. </div>
  209. <div class="col-md-4">
  210. <label class="mb-1" for="contact-phone">Téléphone :</label>
  211. <input id="contact-phone" class="form-control form-control-sm" placeholder="eg. 01 23 45 67 89" value="" type="text">
  212. </div>
  213. <div class="col-md-4">
  214. <label class="mb-1" for="contact-phone">Mobile :</label>
  215. <input id="contact-mobile" class="form-control form-control-sm" placeholder="eg. 07 22 44 66 55" value="" type="text">
  216. </div>
  217. </div>
  218. </div>
  219. <div class="contact-type-block client-type-block mb-2 hidden">
  220. <label class="mb-1" for="account">Nom du contact :</label>
  221. <input required data-id="account" data-type="client" class="form-control form-control-sm" placeholder="" value="" type="text">
  222. </div>
  223. <div class="contact-type-block user-type-block mb-2 hidden">
  224. <label class="mb-1" for="account">Nom du compte :</label>
  225. <input required data-id="account" data-type="user" class="form-control form-control-sm" placeholder="" value="" type="text">
  226. </div>
  227. <label for="tag">Etiquettes</label>
  228. <input value="" class="form-control" placeholder="facturation, livraison..." type="text" data-type="tag" data-multiple=true id="tag" >
  229. <label class="mb-1" for="contact-job">Fonction :</label>
  230. <input id="contact-job" class="form-control form-control-sm" placeholder="PDG, Directeur commercial..." value="" type="text">
  231. <label class="mb-1" for="contact-comment">Commentaire :</label>
  232. <input id="contact-comment" class="form-control form-control-sm" value="" type="text">
  233. </div>
  234. <div class="modal-footer">
  235. <button type="button" class="btn btn-light" data-dismiss="modal" title="Fermer sans enregistrer">Fermer</button>
  236. <button type="button" onclick="client_contact_save();" class="btn btn-primary" title="Enregistrer la fiche contact"><i class="fas fa-check"></i> Enregistrer</button>
  237. </div>
  238. </div>
  239. </div>
  240. </div>
  241. <!-- Modale addresse -->
  242. <!-- Modal -->
  243. <div class="modal fade" id="addressModal" tabindex="-1" role="dialog" aria-hidden="true">
  244. <div class="modal-dialog" role="document">
  245. <div class="modal-content">
  246. <div class="modal-header bg-secondary">
  247. <h5 class="modal-title" id="address-modal">Adresse</h5>
  248. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  249. <span aria-hidden="true">&times;</span>
  250. </button>
  251. </div>
  252. <div class="modal-body">
  253. <div class="row">
  254. <div class="col-md-12">
  255. <h6 class="text-muted text-uppercase">Type d'adresse</h6>
  256. <select id="address-type" class="form-control form-control-sm">
  257. <?php $i=0;
  258. foreach(Client::addressType() as $key=>$type): ?>
  259. <option value="<?php echo $key; ?>" <?php echo $i==0?'selected="selected"':'' ?> ><?php echo $type['label'] ?></option>
  260. <?php $i++; endforeach; ?>
  261. </select>
  262. </div>
  263. </div>
  264. <hr class="my-2">
  265. <div class="address-type-block">
  266. <div class="row">
  267. <div class="col-md-6">
  268. <label class="mb-1" for="address-street">Rue</label>
  269. <input class="form-control form-control-sm" id="address-street" type="text" data-type="location" data-select-callback="client_address_fill">
  270. </div>
  271. <div class="col-md-6">
  272. <label class="mb-1" for="address-complement">Complément</label>
  273. <input class="form-control form-control-sm" id="address-complement">
  274. </div>
  275. </div>
  276. <div class="row">
  277. <div class="col-md-6">
  278. <label class="mb-1" for="city">Ville</label>
  279. <input id="address-city" class="form-control form-control-sm" placeholder="" type="text" value="" type="text">
  280. </div>
  281. <div class="col-md-6">
  282. <label class="mb-1" for="address-zip">Code postal</label>
  283. <input id="address-zip" class="form-control form-control-sm" placeholder="" type="text" value="" type="text">
  284. </div>
  285. </div>
  286. <div class="row">
  287. <div class="col-md-12">
  288. <label class="mb-1" for="address-country">Pays</label>
  289. <input id="address-country" class="form-control form-control-sm" placeholder="" type="text" value="France" type="text">
  290. </div>
  291. </div>
  292. </div>
  293. </div>
  294. <div class="modal-footer">
  295. <button type="button" class="btn btn-light" data-dismiss="modal" title="Fermer sans enregistrer">Fermer</button>
  296. <button type="button" onclick="client_address_save();" class="btn btn-primary" title="Enregistrer la fiche adresse"><i class="fas fa-check"></i> Enregistrer</button>
  297. </div>
  298. </div>
  299. </div>
  300. </div>
  301. <!-- Modal liaison de clients -->
  302. <div class="modal fade" id="client-holding-modal" tabindex="-1" role="dialog" aria-hidden="true">
  303. <div class="modal-dialog modal-lg" role="document">
  304. <div class="modal-content">
  305. <div class="modal-header">
  306. <h5 class="modal-title">Lier à</h5>
  307. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  308. <span aria-hidden="true">&times;</span>
  309. </button>
  310. </div>
  311. <div class="modal-body">
  312. <span class="text-muted mr-2">Lier le client</span> <input type="text" data-type="client" class="form-control d-inline-block w-25" id="relation-link"> <span class="text-muted mx-2">en tant que </span>
  313. <label><input type="radio" name="relation-level" value="holding"> <?php echo ucFirst($conf->get('client_holding_singular')); ?></label>
  314. <label><input type="radio" name="relation-level" value="subsite"> Sous établissement</label>
  315. <span class="ml-2 text-muted">du client actuellement ouvert</span>
  316. </div>
  317. <div class="modal-footer">
  318. <button type="button" class="btn btn-light" data-dismiss="modal" title="Fermer sans enregistrer">Fermer</button>
  319. <button type="button" onclick="client_relation_add();" class="btn btn-primary btn-merge"><i class="fas fa-check"></i> Lier</button>
  320. </div>
  321. </div>
  322. </div>
  323. </div>
  324. <!-- Modal fusion de clients -->
  325. <div class="modal fade" id="client-merge-modal" tabindex="-1" role="dialog" aria-hidden="true">
  326. <div class="modal-dialog modal-lg" role="document">
  327. <div class="modal-content">
  328. <div class="modal-header bg-secondary">
  329. <h5 class="modal-title" id="address-modal">Fusion</h5>
  330. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  331. <span aria-hidden="true">&times;</span>
  332. </button>
  333. </div>
  334. <div class="modal-body">
  335. <div class="row">
  336. <div class="col-md-12">
  337. <h6 class="text-muted text-uppercase">Fusionner le client ci dessous avec cette fiche</h6>
  338. <input type="text" class="form-control" id="client-merge-right" data-type="client">
  339. </div>
  340. </div>
  341. <hr class="my-2">
  342. <div class="row">
  343. <div class="col-md-12">
  344. <p>Dans le cas ou les deux clients comportent des informations, choisissez qui l'emporte</p>
  345. <table class="table">
  346. <thead>
  347. <tr>
  348. <th>Information</th>
  349. <th>Client courant</th>
  350. <th>Client fusionné</th>
  351. </tr>
  352. </thead>
  353. <tbody>
  354. <?php foreach(Client::fields(false) as $field):
  355. if($field['column']=='id' || $field['column']=='parent') continue;
  356. ?>
  357. <tr>
  358. <td><?php echo $field['label']; ?></td>
  359. <td><input type="radio" data-type="radio" data-key="<?php echo $field['column']; ?>" name="merge_<?php echo $field['column']; ?>" checked="checked" value="left"></td>
  360. <td><input type="radio" data-type="radio" data-key="<?php echo $field['column']; ?>" name="merge_<?php echo $field['column']; ?>" value="right"></td>
  361. </tr>
  362. <?php endforeach; ?>
  363. </tbody>
  364. </table>
  365. <div class="merge-logs"></div>
  366. </div>
  367. </div>
  368. </div>
  369. <div class="modal-footer">
  370. <button type="button" class="btn btn-light" data-dismiss="modal" title="Fermer sans enregistrer">Fermer</button>
  371. <button type="button" onclick="client_client_merge();" class="btn btn-primary btn-merge"><i class="fas fa-check"></i> Fusionner</button>
  372. </div>
  373. </div>
  374. </div>
  375. </div>