subscription.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. <!--
  2. Page 'Mon abonnement'
  3. @see https://ressources.opentalent.fr/display/SPEC/Mon+abonnement
  4. -->
  5. <template>
  6. <LayoutContainer>
  7. <v-expansion-panels v-model="openedPanels" :multiple="true">
  8. <UiExpansionPanel title="subscription_page" icon="fas fa-info">
  9. <v-container fluid class="container">
  10. <v-row>
  11. <v-col cols="12" lg="6" sm="12">
  12. {{ $t('version') }} :
  13. <strong>{{
  14. dolibarrAccount ? $t(dolibarrAccount.product) : '-'
  15. }}</strong>
  16. </v-col>
  17. <v-col cols="12" lg="6" sm="12">
  18. {{ $t('client_id') }} :
  19. {{ dolibarrAccount ? dolibarrAccount.clientNumber : '-' }}
  20. </v-col>
  21. </v-row>
  22. </v-container>
  23. </UiExpansionPanel>
  24. <UiExpansionPanel
  25. title="service_detail"
  26. icon="fas fa-info"
  27. v-if="dolibarrAccount && dolibarrAccount.contract"
  28. >
  29. <v-container fluid class="container">
  30. <v-row>
  31. <v-col
  32. cols="12"
  33. lg="12"
  34. v-for="line in dolibarrAccount.contract.lines"
  35. :key="line.id"
  36. >
  37. <strong>{{ line.serviceLabel }}</strong> - {{ $t('until') }} :
  38. {{ $d(line.dateEnd) }}
  39. </v-col>
  40. <v-col cols="12" lg="12" v-if="ability.can('manage', 'texto')">
  41. <strong>{{ $t('remaining_sms_credit') }}</strong> -
  42. <span
  43. v-if="
  44. !mobytPending && mobytStatus !== null && mobytStatus.active
  45. "
  46. >
  47. {{
  48. mobytStatus.money.toLocaleString($i18n.locale, {
  49. style: 'currency',
  50. currency: 'EUR',
  51. })
  52. }}
  53. {{
  54. i18n.t('convert_price_to_sms', {
  55. nb_sms: mobytStatus.amount,
  56. })
  57. }}
  58. </span>
  59. </v-col>
  60. </v-row>
  61. </v-container>
  62. </UiExpansionPanel>
  63. <UiExpansionPanel
  64. v-if="showDolibarrPanel"
  65. title="bills"
  66. icon="fas fa-file"
  67. >
  68. <v-container :fluid="true" class="container">
  69. <v-row>
  70. <v-table v-if="dolibarrAccount !== null">
  71. <thead>
  72. <tr>
  73. <th>{{ $t('reference') }}</th>
  74. <th>{{ $t('date') }}</th>
  75. <th>{{ $t('taxExcludedAmount') }}</th>
  76. <th>{{ $t('status') }}</th>
  77. <th></th>
  78. </tr>
  79. </thead>
  80. <tbody>
  81. <tr v-for="bill in dolibarrAccount.bills" :key="bill.id">
  82. <td>{{ bill.ref }}</td>
  83. <td>{{ $d(bill.date) }}</td>
  84. <td>
  85. {{
  86. bill.taxExcludedAmount.toLocaleString($i18n.locale, {
  87. style: 'currency',
  88. currency: 'EUR',
  89. })
  90. }}
  91. </td>
  92. <td>
  93. {{ bill.paid === true ? $t('paid') : $t('unpaid') }}
  94. </td>
  95. <td>
  96. <a
  97. @click="downloadDolibarrBill(bill.ref)"
  98. class="clickable"
  99. >
  100. {{ $t('download') }}
  101. </a>
  102. </td>
  103. </tr>
  104. </tbody>
  105. </v-table>
  106. </v-row>
  107. </v-container>
  108. </UiExpansionPanel>
  109. <UiExpansionPanel
  110. title="opentalent_offers"
  111. icon="fas fa-plus"
  112. v-if="!organizationProfile.isManagerProduct"
  113. >
  114. <v-container fluid class="container">
  115. <v-row
  116. class="offer_title"
  117. v-if="!md && mdAndUp && !organizationProfile.isSchool"
  118. >
  119. <v-col
  120. cols="12"
  121. :lg="organizationProfile.isArtistPremiumProduct ? 3 : 6"
  122. sm="12"
  123. >
  124. <span class="theme-artist"
  125. >Pour les orchestres, chorales, compagnies et troupes
  126. artistiques</span
  127. >
  128. </v-col>
  129. <v-col
  130. cols="12"
  131. :lg="organizationProfile.isArtistPremiumProduct ? 3 : 5"
  132. sm="12"
  133. :offset="organizationProfile.isArtistPremiumProduct ? 0 : 1"
  134. >
  135. <span class="theme-school"
  136. >Pour les établissements d'enseignements artistiques*</span
  137. >
  138. </v-col>
  139. </v-row>
  140. <v-row class="card-container">
  141. <v-col
  142. lg="3"
  143. sm="12"
  144. md="6"
  145. v-if="organizationProfile.isArtistProduct"
  146. >
  147. <LayoutPagesSubscriptionCard
  148. class="artistCard"
  149. title="Logiciel Artist Standard"
  150. :extraHeader="
  151. organizationProfile.isArtistProduct
  152. ? 'Votre version'
  153. : undefined
  154. "
  155. color="artist"
  156. :list="listCheck.artist"
  157. >
  158. <template #card.subTitle>
  159. <div class="priceBlock">
  160. <span class="price">{{ formatCurrency(11, 'EUR') }}</span>
  161. TTC/mois
  162. </div>
  163. </template>
  164. <template #card.action>
  165. <v-btn
  166. v-if="!organizationProfile.isArtistProduct"
  167. class="theme-artist btn"
  168. href="https://logiciels.opentalent.fr/opentalent-artist"
  169. target="_blank"
  170. >
  171. {{ $t('to_know_more') }}
  172. <i class="fa-solid fa-greater-than small"></i>
  173. </v-btn>
  174. </template>
  175. </LayoutPagesSubscriptionCard>
  176. </v-col>
  177. <v-col lg="3" sm="12" md="6" v-if="organizationProfile.isArtist">
  178. <LayoutPagesSubscriptionCard
  179. class="artistCard"
  180. title="Logiciel Artist Premium*"
  181. :extraHeader="
  182. organizationProfile.isArtistPremiumProduct
  183. ? organizationProfile.isTrialActive
  184. ? `Version en cours d'essai J-${organizationProfile.trialCountDown}`
  185. : 'Votre version'
  186. : '1 mois d\'essai offert'
  187. "
  188. color="artist"
  189. :list="listCheck.artistPremium"
  190. >
  191. <template #card.subTitle>
  192. <div class="priceBlock">
  193. <span class="price">{{
  194. organizationProfile.isCmf
  195. ? formatCurrency(7.5, 'EUR')
  196. : formatCurrency(18.0, 'EUR')
  197. }}</span>
  198. TTC/mois
  199. </div>
  200. </template>
  201. <template #card.action>
  202. <v-row>
  203. <v-col
  204. cols="12"
  205. v-if="
  206. !organizationProfile.isArtistPremiumProduct &&
  207. (accessProfileStore.isAdmin ||
  208. accessProfileStore.isCaMember)
  209. "
  210. >
  211. <v-btn class="btn trialBtn" @click="startTrial">
  212. {{ $t('try_premium_version') }}
  213. <i class="fa-solid fa-greater-than small"></i>
  214. </v-btn>
  215. </v-col>
  216. <v-col
  217. cols="12"
  218. v-if="
  219. (!organizationProfile.isArtistPremiumProduct ||
  220. organizationProfile.isTrialActive) &&
  221. (accessProfileStore.isAdmin ||
  222. accessProfileStore.isCaMember)
  223. "
  224. >
  225. <v-btn class="theme-artist btn" @click="subscription">
  226. {{ $t('subscribe_to_the_offer') }}
  227. <i class="fa-solid fa-greater-than small"></i>
  228. </v-btn>
  229. </v-col>
  230. <v-col
  231. cols="12"
  232. v-if="
  233. organizationProfile.isTrialActive &&
  234. (accessProfileStore.isAdmin ||
  235. accessProfileStore.isCaMember)
  236. "
  237. >
  238. <v-btn class="stop_btn" @click="showStopTrialDialog">
  239. {{ $t('stop_trial') }}
  240. </v-btn>
  241. </v-col>
  242. <v-col cols="12">
  243. <span class="special_conditions">
  244. *Convient aux petites écoles sans besoins spécifiques de
  245. gestion pédagogique, de facturation, etc. Pour une
  246. solution complète optez pour Opentalent School
  247. </span>
  248. </v-col>
  249. </v-row>
  250. </template>
  251. </LayoutPagesSubscriptionCard>
  252. </v-col>
  253. <v-col
  254. lg="3"
  255. sm="12"
  256. md="6"
  257. :offset="
  258. !md && mdAndUp
  259. ? organizationProfile.isSchool
  260. ? 4
  261. : organizationProfile.isArtistPremiumProduct
  262. ? 0
  263. : 2
  264. : 0
  265. "
  266. >
  267. <LayoutPagesSubscriptionCard
  268. class="schoolCard"
  269. :title="
  270. !organizationProfile.isSchool
  271. ? 'Logiciel School Standard / Premium'
  272. : organizationProfile.isSchoolPremiumProduct
  273. ? 'Logiciel School Premium'
  274. : 'Logiciel School Standard'
  275. "
  276. :subTitle="!organizationProfile.isSchool ? 'Sur devis' : ''"
  277. :extraHeader="
  278. organizationProfile.isSchool ? 'Votre version' : undefined
  279. "
  280. color="school"
  281. :list="listCheck.school"
  282. >
  283. <template #card.action>
  284. <v-row>
  285. <v-col cols="12">
  286. <v-btn
  287. v-if="!organizationProfile.isSchool"
  288. class="theme-school btn"
  289. href="https://logiciels.opentalent.fr/opentalent-school"
  290. target="_blank"
  291. >
  292. {{ $t('to_know_more') }}
  293. <i class="fa-solid fa-greater-than small"></i>
  294. </v-btn>
  295. </v-col>
  296. <v-col cols="12">
  297. <span class="special_conditions">
  298. *Extranet disponible uniquement dans la version
  299. Opentalent School Premium
  300. </span>
  301. </v-col>
  302. </v-row>
  303. </template>
  304. </LayoutPagesSubscriptionCard>
  305. </v-col>
  306. </v-row>
  307. </v-container>
  308. </UiExpansionPanel>
  309. <UiExpansionPanel title="opentalent_options" icon="fas fa-plus">
  310. <v-container fluid class="container card-container">
  311. <v-row cols="12">
  312. <v-col lg="3" sm="12" md="6">
  313. <LayoutPagesSubscriptionCard
  314. class="optionsCard"
  315. title="SMS"
  316. sub-title="Option payante"
  317. color="primary"
  318. :list="listCheck.sms"
  319. >
  320. <template #card.action>
  321. <v-btn
  322. class="theme-primary btn"
  323. :href="
  324. runtimeConfig.public.fileStorageBaseUrl +
  325. (organizationProfile.isCmf
  326. ? '/Bon_de_commande/Achat_SMS_CMF.pdf'
  327. : '/Bon_de_commande/Achat_SMS_Public.pdf')
  328. "
  329. target="_blank"
  330. >
  331. acheter des credits SMS
  332. <i class="fa-solid fa-greater-than small"></i>
  333. </v-btn>
  334. </template>
  335. </LayoutPagesSubscriptionCard>
  336. </v-col>
  337. <v-col lg="3" sm="12" md="6">
  338. <LayoutPagesSubscriptionCard
  339. class="optionsCard"
  340. title="Nom de domaine"
  341. sub-title="Option payante"
  342. color="primary"
  343. :list="listCheck.domain"
  344. >
  345. <template #card.action>
  346. <v-btn
  347. class="theme-primary btn"
  348. :href="
  349. runtimeConfig.public.fileStorageBaseUrl +
  350. '/Bon_de_commande/Nom_de_domaine.pdf'
  351. "
  352. target="_blank"
  353. >
  354. souscrire à l'option
  355. <i class="fa-solid fa-greater-than small"></i>
  356. </v-btn>
  357. </template>
  358. </LayoutPagesSubscriptionCard>
  359. </v-col>
  360. </v-row>
  361. </v-container>
  362. </UiExpansionPanel>
  363. </v-expansion-panels>
  364. </LayoutContainer>
  365. <LayoutDialogTrialAlreadyDid
  366. :show="showDialogTrialAllReadyDid"
  367. @closeDialog="showDialogTrialAllReadyDid = false"
  368. />
  369. <LayoutDialogTrialStopConfirmation
  370. :show="showDialogTrialStopConfirmation"
  371. @closeDialog="showDialogTrialStopConfirmation = false"
  372. @stopTrial="stopTrial"
  373. />
  374. </template>
  375. <script setup lang="ts">
  376. import { useAbility } from '@casl/vue'
  377. import type { Ref } from 'vue'
  378. import { useDisplay } from 'vuetify'
  379. import type { AsyncData } from '#app'
  380. import { useOrganizationProfileStore } from '~/stores/organizationProfile'
  381. import { useEntityFetch } from '~/composables/data/useEntityFetch'
  382. import DolibarrAccount from '~/models/Organization/DolibarrAccount'
  383. import MobytUserStatus from '~/models/Organization/MobytUserStatus'
  384. import UrlUtils from '~/services/utils/urlUtils'
  385. import { useDownloadFromRoute } from '~/composables/utils/useDownloadFromRoute'
  386. import { useApiLegacyRequestService } from '~/composables/data/useApiLegacyRequestService'
  387. import { usePageStore } from '~/stores/page'
  388. //meta
  389. definePageMeta({
  390. name: 'subscription_page',
  391. })
  392. //Get composables
  393. const ability = useAbility()
  394. const runtimeConfig = useRuntimeConfig()
  395. const { mdAndUp, md } = useDisplay()
  396. const { fetch } = useEntityFetch()
  397. const i18n = useI18n()
  398. const { apiRequestService } = useApiLegacyRequestService()
  399. //Init ref
  400. const showDialogTrialAllReadyDid: Ref<boolean> = ref(false)
  401. const showDialogTrialStopConfirmation: Ref<boolean> = ref(false)
  402. const openedPanels: Ref<Array<string>> = initPanel()
  403. const organizationProfile = getOrganizationProfile()
  404. const accessProfileStore = useAccessProfileStore()
  405. const { mobytStatus, mobytPending } = getMobytInformations()
  406. const { data: dolibarrAccount, pending: dolibarrPending } = fetch(
  407. DolibarrAccount,
  408. organizationProfile.id,
  409. )
  410. const showDolibarrPanel = computed(
  411. () =>
  412. !dolibarrPending.value &&
  413. dolibarrAccount.value &&
  414. dolibarrAccount.value.bills.length > 0,
  415. )
  416. const formatCurrency = (value: number, currency: string): string => {
  417. return value.toLocaleString(i18n.locale.value, {
  418. style: 'currency',
  419. currency,
  420. })
  421. }
  422. const listCheck: Record<string, Array<string>> = {
  423. artist: [
  424. '100 Mo de stockage',
  425. '75 comptes utilisateurs',
  426. 'Gestion de la structure',
  427. 'Site internet restreint',
  428. 'Options disponibles',
  429. ],
  430. artistPremium: [
  431. '1Go de stockage',
  432. '150 comptes utilisateurs',
  433. 'Gestion de la structure',
  434. 'Module de communication',
  435. 'Site internet illimité',
  436. 'Options disponibles',
  437. ],
  438. school: [
  439. '500 Mo ou 1Go de stockage',
  440. '3 comptes administrateurs',
  441. 'Extranet élèves, tuteurs, professeurs*',
  442. 'Gestion de la structure',
  443. 'Suivi pédagogique, facturation, ...',
  444. 'Site internet complet',
  445. 'Options adaptées à chaque structure',
  446. ],
  447. sms: [
  448. 'Envoyez des SMS depuis votre logiciel',
  449. 'Choisissez le nombre de crédits',
  450. ],
  451. domain: [
  452. 'Bénéficiez de votre propre nom de domaine',
  453. "Et d'une adresse mail personnalisée",
  454. ],
  455. }
  456. /**
  457. * Initialisation des panels ouverts
  458. */
  459. function initPanel(): Ref<Array<string>> {
  460. // On déplie les expansion panels dans le onMounted en attendant la résolution du bug : https://github.com/vuetifyjs/vuetify/issues/16427#issuecomment-1380927133
  461. // TODO: quand le bug ci dessus est résolu, remplacer par `const openedPanels: Ref<Array<string>> = ref([...])`
  462. const openedPanels: Ref<Array<string>> = ref([])
  463. onMounted(() => {
  464. openedPanels.value = [
  465. 'subscription_page',
  466. 'service_detail',
  467. 'bills',
  468. 'opentalent_offers',
  469. 'opentalent_options',
  470. ]
  471. })
  472. return openedPanels
  473. }
  474. /**
  475. * Récupération de l'organization profile
  476. */
  477. function getOrganizationProfile() {
  478. const organizationProfile = useOrganizationProfileStore()
  479. if (organizationProfile.id === null) {
  480. throw new Error("Missing organization's id")
  481. }
  482. return organizationProfile
  483. }
  484. /**
  485. * Récupération des informations Mobyt
  486. */
  487. function getMobytInformations(): {
  488. mobytStatus: Ref<MobytUserStatus | null>
  489. mobytPending: Ref<boolean>
  490. } {
  491. let mobytStatus: Ref<MobytUserStatus | null> = ref(null)
  492. let mobytPending: Ref<boolean> = ref(false)
  493. if (ability.can('manage', 'texto')) {
  494. const { data, pending } = fetch(
  495. MobytUserStatus,
  496. organizationProfile!.id!,
  497. ) as AsyncData<MobytUserStatus | null, Error | null>
  498. mobytStatus = data
  499. mobytPending = pending
  500. }
  501. return { mobytStatus, mobytPending }
  502. }
  503. /**
  504. * Action lorsque l'on souhaite démarrer l'essai
  505. */
  506. async function startTrial() {
  507. try {
  508. await apiRequestService.get('/trial/is_available')
  509. const v1BaseURL =
  510. runtimeConfig.baseUrlAdminLegacy ||
  511. runtimeConfig.public.baseUrlAdminLegacy
  512. await navigateTo(UrlUtils.join(v1BaseURL, '#', 'trial'), {
  513. external: true,
  514. })
  515. } catch (error) {
  516. showDialogTrialAllReadyDid.value = true
  517. }
  518. }
  519. /**
  520. * Action lorsque l'on souhaite souscrire à artist premium
  521. */
  522. async function subscription() {
  523. const v1BaseURL =
  524. runtimeConfig.baseUrlAdminLegacy || runtimeConfig.public.baseUrlAdminLegacy
  525. await navigateTo(UrlUtils.join(v1BaseURL, '#', 'subscribe'), {
  526. external: true,
  527. })
  528. }
  529. /**
  530. * Action lorsque l'on souhaite afficher la modal de confirmation pour stopper
  531. */
  532. function showStopTrialDialog() {
  533. showDialogTrialStopConfirmation.value = true
  534. }
  535. /**
  536. * Action lorsque l'on souhaite stopper l'essai
  537. */
  538. async function stopTrial() {
  539. usePageStore().loading = true
  540. await apiRequestService.post('/trial/stop')
  541. const v1BaseURL =
  542. runtimeConfig.baseUrlAdminLegacy || runtimeConfig.public.baseUrlAdminLegacy
  543. await navigateTo(UrlUtils.join(v1BaseURL, '#', 'dashboard'), {
  544. external: true,
  545. })
  546. }
  547. const downloadDolibarrBill = (ref: string): void => {
  548. const route = UrlUtils.join('api/dolibarr/download/invoice', ref)
  549. useDownloadFromRoute(route, `${ref}.pdf`)
  550. }
  551. </script>
  552. <style scoped lang="scss">
  553. .clickable {
  554. cursor: pointer;
  555. text-decoration: underline;
  556. }
  557. .offer_title {
  558. span {
  559. border-radius: 5px;
  560. display: block;
  561. font-weight: bold;
  562. text-align: center;
  563. padding: 5px;
  564. }
  565. }
  566. .card-container {
  567. .v-row {
  568. display: -webkit-box;
  569. display: -webkit-flex;
  570. display: -ms-flexbox;
  571. display: flex;
  572. flex-wrap: wrap;
  573. }
  574. .v-row > [class*='v-col-'] {
  575. display: flex;
  576. flex-direction: column;
  577. }
  578. .small {
  579. font-size: 6px;
  580. padding-top: 5px;
  581. padding-left: 5px;
  582. }
  583. .priceBlock {
  584. text-align: center;
  585. font-size: 15px;
  586. font-weight: normal;
  587. .price {
  588. font-size: 30px;
  589. font-weight: bold;
  590. }
  591. }
  592. }
  593. .artistCard {
  594. :deep(.v-card-title) {
  595. text-align: center;
  596. }
  597. }
  598. .special_conditions {
  599. font-size: 10px;
  600. }
  601. .trialBtn {
  602. color: #000;
  603. border: 1px solid rgb(var(--v-theme-artist));
  604. }
  605. .optionsCard {
  606. :deep(.margin-sup) {
  607. margin-top: 0;
  608. }
  609. }
  610. .stop_btn {
  611. color: rgb(var(--v-theme-danger));
  612. }
  613. .plus_btn {
  614. color: rgb(var(--v-theme-on-neutral));
  615. }
  616. </style>