@freteclick/quasar-financial-ui 1.0.103 → 1.0.105

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@freteclick/quasar-financial-ui",
3
- "version": "1.0.103",
3
+ "version": "1.0.105",
4
4
  "author": "FreteClick",
5
5
  "description": "FreteClick financial Quasar UI Component",
6
6
  "license": "MIT",
@@ -93,10 +93,7 @@
93
93
  </q-tab-panel>
94
94
 
95
95
  <q-tab-panel name="invoice" class="q-pa-none">
96
- <InvoiceInvoice
97
- :invoiceId="invoiceId"
98
- :orderId ="orderId"
99
- />
96
+ <InvoiceInvoice ref="invoiceBillet" :invoiceId="invoiceId" :orderId="orderId" :invoice="invoice" />
100
97
  </q-tab-panel>
101
98
  </q-tab-panels>
102
99
  </div>
@@ -122,7 +119,10 @@
122
119
  import { mapActions, mapGetters } from 'vuex';
123
120
  import InvoiceInvoice from './details/InvoiceInvoice';
124
121
  import InvoiceOrders from './details/InvoiceOrders';
125
- import { formatMoney } from '@freteclick/quasar-common-ui/src/utils/formatter';
122
+ import {
123
+ formatMoney,
124
+ formatDateYmdTodmY,
125
+ } from "@freteclick/quasar-common-ui/src/utils/formatter";
126
126
 
127
127
  export default {
128
128
  components: {
@@ -188,15 +188,11 @@ export default {
188
188
  this.invoice = data;
189
189
  this.notFound = false;
190
190
 
191
- // format date
192
-
193
191
  if (this.invoice.dueDate) {
194
- this.invoice.dueDate = this.invoice.dueDate
195
- .replace(/^(\d{4})\-(\d{2})\-(\d{2})T00:00:00\+00:00$/g,"\$3\/\$2\/\$1");
192
+ this.invoice.dueDate = formatDateYmdTodmY(this.invoice.dueDate);
196
193
  }
197
194
 
198
195
  // set order
199
-
200
196
  if (this.invoice.order.length > 0) {
201
197
  this.orderId = this.invoice.order[0].order['@id'].match(/^\/purchasing\/orders\/([a-z0-9-]*)$/)[1];
202
198
  }
@@ -1,12 +1,7 @@
1
1
  <template>
2
2
  <div class="row items-center justify-center">
3
3
  <div class="flex flex-center" v-if="isLoading">
4
- <q-circular-progress
5
- :indeterminate="isLoading"
6
- size="sm"
7
- color="primary"
8
- class="q-ma-md"
9
- />
4
+ <q-circular-progress :indeterminate="isLoading" size="sm" color="primary" class="q-ma-md" />
10
5
  Carregando...
11
6
  </div>
12
7
 
@@ -20,97 +15,20 @@
20
15
 
21
16
  <!-- BILLET VIEWER SICRED -->
22
17
  <div :class="showBilletSicred ? 'full-width q-pa-lg' : 'hidden'">
23
- <div class="col-12 q-pt-lg" v-if="paymentInstitution === 'sicred'">
24
- <!-- <div class="row justify-center items-center">
25
- <q-btn
26
- icon="money"
27
- size="lg"
28
- color="primary"
29
- label="Abrir Boleto Pix"
30
- :loading="isLoadingDownload"
31
- @click="clickDownloadBilletSicred()"
32
- :disable="isPaid"
33
- />
34
- </div> -->
35
-
36
- <div style="height: 1200px">
37
- <iframe
38
- :src="invoiceUrlSicred"
39
- name="BILLETINTER" id="billet_sicred" width="100%" height="100%" frameBorder="0">
40
- <p>This browser does not support IFrame.</p>
41
- </iframe>
42
- </div>
43
- </div>
44
- </div>
45
-
46
- <!-- BILLET VIEWER INTER -->
47
- <div :class="showBilletInter ? 'full-width q-pa-lg' : 'hidden'">
48
18
  <div style="height: 1200px">
49
- <iframe
50
- :src="invoiceUrlInter"
51
- name="BILLETINTER" id="billet_inter" width="100%" height="100%" frameBorder="0">
19
+ <iframe :src="invoiceUrlSicred" name="BILLETINTER" id="billet_sicred" width="100%" height="100%"
20
+ frameBorder="0">
52
21
  <p>This browser does not support IFrame.</p>
53
22
  </iframe>
54
23
  </div>
55
24
  </div>
56
25
 
57
- <!-- BILLET VIEWER ITAU -->
58
- <div :class="showBillet ? 'full-width q-pa-lg' : 'hidden'">
59
- <q-form
60
- ref="myForm"
61
- :action="payment !== null ? payment.invoiceUrl : ''"
62
- method="post"
63
- class="q-mt-sm row justify-center items-center"
64
- target="BILLET"
65
- >
66
- <input type="hidden" name="DC" :value="itauHash"/>
67
- </q-form>
68
- <div style="height: 1200px">
69
- <iframe name="BILLET" width="100%" height="100%" frameBorder="0">
70
- <p>This browser does not support IFrame.</p>
71
- </iframe>
72
- </div>
73
- </div>
74
-
75
- <!-- BILLET GENERATOR TRIGGER -->
76
- <div class="col-12 q-pt-lg" v-if="paymentIsPending && billetMustBeCreated && paymentInstitution === 'itau'">
77
- <div style="min-height: 80vh;" class="row justify-center items-center">
78
- <q-btn
79
- icon="money"
80
- size="lg"
81
- color="primary"
82
- label="Gerar boleto"
83
- :loading="retrievingHash"
84
- @click="() => {
85
- this.retrievingHash = true;
86
- this.getItauHash().then(hash => {
87
- if (hash !== null) {
88
- this.loadOnFocus = true;
89
- this.$refs.billetForm.$el.submit();
90
- }
91
- }).finally(() => {
92
- this.retrievingHash = false;
93
- });
94
- }"
95
- :disable="isPaid"
96
- />
97
- <q-form
98
- ref="billetForm"
99
- :action="payment ? payment.invoiceUrl : ''"
100
- method="post"
101
- target="_blank"
102
- >
103
- <input type="hidden" name="DC" :value="itauHash"/>
104
- </q-form>
105
- </div>
106
- </div>
107
-
108
26
  <!-- PAID MESSAGE -->
109
- <div class="col-12" v-if="payment !== null && isPaid">
110
- <div class="row items-center justify-center" style="min-height: 90vh;">
27
+ <div class="col-12" v-if="isPaid">
28
+ <div class="row items-center justify-center q-pt-lg">
111
29
  <q-banner class="text-white bg-positive text-center text-h3" rounded>
112
30
  <template v-slot:avatar>
113
- <q-icon name="thumb_up" color="white"/>
31
+ <q-icon name="thumb_up" color="white" />
114
32
  </template>
115
33
  O boleto foi pago
116
34
  </q-banner>
@@ -120,9 +38,8 @@
120
38
  </template>
121
39
 
122
40
  <script>
123
- import {mapActions, mapGetters} from 'vuex';
124
- import axios from 'axios';
125
- import {ENTRYPOINT} from '@freteclick/../../src/config/entrypoint';
41
+ import { mapActions, mapGetters } from 'vuex';
42
+ import { ENTRYPOINT } from '@freteclick/../../src/config/entrypoint';
126
43
 
127
44
  export default {
128
45
  props: {
@@ -134,38 +51,57 @@ export default {
134
51
  type: String,
135
52
  required: true,
136
53
  },
54
+ invoice: {
55
+ type: Object,
56
+ required: true,
57
+ },
137
58
  },
138
59
 
139
60
  components: {},
140
61
 
141
62
  mounted() {
142
- window.addEventListener('focus', this.loadItauDataOnFocus);
143
- },
144
-
145
- beforeDestroy() {
146
- window.removeEventListener('focus', this.loadItauDataOnFocus);
147
63
  },
148
64
 
149
65
  created() {
150
- this.getPaymentStatus();
66
+ this.getBank();
67
+
68
+ if (this.invoice.status.status === 'paid') {
69
+ this.isPaid = true;
70
+ this.showBilletSicred = true;
71
+ }
72
+
73
+ if (this.invoice.paymentType === 'boleto' || this.invoice.invoiceBankId !== null) {
74
+ this.paymentType = 'boleto';
75
+ this.showBilletSicred = true;
76
+ this.invoiceBankId = this.invoice.invoiceBankId;
77
+ this.clickDownloadBilletSicred();
78
+ }
79
+
80
+ if (this.invoice.paymentType !== null) {
81
+ this.paymentType = this.invoice.paymentType;
82
+ }
83
+
84
+ if(!this.isPaid || this.invoice.invoiceBankId === null) {
85
+ this.generateSicredBillet();
86
+ }
151
87
  },
152
88
 
153
89
  data() {
154
90
  return {
155
- invoiceUrlInter: null,
156
91
  invoiceUrlSicred: null,
157
- showBilletInter: null,
158
- showBilletSicred: null,
92
+ showBilletSicred: false,
159
93
  showInfoBox: null,
160
94
  isLoadingDownload: false,
161
95
  isLoading: false,
162
- payment: null,
163
- isPaid: false,
164
- itauHash: null,
96
+ payment: null, // Recebe dados de pagamento
97
+ isPaid: false, // Indica se a fatura foi paga
165
98
  showBillet: false,
166
99
  loadOnFocus: false,
167
100
  retrievingHash: false,
168
- paymentInstitution: null
101
+ paymentInstitution: null,
102
+ paymentStatus: null,
103
+ paymentType: null,
104
+ invoiceBankId: null
169
105
  };
170
106
  },
171
107
 
@@ -179,11 +115,12 @@ export default {
179
115
 
180
116
  return this.payment.invoiceRealStatus === 'pending';
181
117
  },
118
+ // O Boleto deve ser Criado
182
119
  billetMustBeCreated() {
183
120
  if (this.payment === null)
184
121
  return false;
185
122
 
186
- return this.payment.paymentType === 'choose_pending' || this.payment.paymentStatus !== 'paid';
123
+ return this.payment.paymentType === 'boleto' || this.payment.paymentStatus !== 'paid';
187
124
  },
188
125
  },
189
126
 
@@ -194,162 +131,46 @@ export default {
194
131
  }
195
132
  },
196
133
 
197
- payment(data) {
198
- if (!data)
199
- return;
200
-
201
- this.isPaid = data.paymentStatus === 'paid';
202
-
203
- if(this.payment.paymentStatus === 'open')
204
- {
205
- this.showInfoBox = true;
206
- }
207
-
208
- if (data.paymentType == 'billet') {
209
-
210
- if (data.paymentStatus !== 'open') {
211
-
212
- this.showInfoBox = false;
213
-
214
- if (this.paymentInstitution === 'itau') {
215
- this.getItauHash().then(hash => {
216
- if (hash !== null) {
217
- this.showBillet = true;
218
- }
219
- });
220
-
221
- } else if(this.paymentInstitution === 'inter') {
222
-
223
- this.showBillet = false;
224
- let urlTmp = ENTRYPOINT + `/vendor/pdf.js/web/viewer.html?file=/finance/${this.invoiceId}/download?timestamp${new Date().getTime()}`;
225
- this.invoiceUrlInter = urlTmp;
226
- this.isLoading = false;
227
- this.showBilletInter = true;
228
-
229
- }
230
- else {
231
-
232
- this.showBillet = false;
233
- let urlTmp = ENTRYPOINT + `/vendor/pdf.js/web/viewer.html?file=/finance/${this.invoiceId}/bank/sicred/download?timestamp${new Date().getTime()}`;
234
- // let urlTmp = ENTRYPOINT + `/download?invoiceUrl=${this.payment.invoiceUrl}`;
235
- this.invoiceUrlSicred = urlTmp;
236
- this.isLoading = false;
237
- this.showBilletSicred = true;
238
-
239
- }
240
- }
241
-
242
- }
243
-
244
- this.$emit(
245
- 'billetStatus',
246
- {
247
- hasBillet: data.paymentType === 'billet' && data.paymentStatus === 'created',
248
- isPaid: data.paymentStatus === 'paid'
249
- }
250
- );
251
-
252
- },
253
-
254
- showBillet(show) {
255
- if (show == true) {
256
- this.$refs.myForm.$el.submit();
257
- }
258
- },
259
134
  },
260
135
 
261
136
  methods: {
262
137
  ...mapActions({
263
- getItauData: 'receiveInvoice/bankItau',
264
- getInterData: 'receiveInvoice/bankInter',
265
138
  getSicredData: 'receiveInvoice/bankSicred',
139
+ getInvoice: 'receiveInvoice/getInvoice',
266
140
  getBankPerInvoiceId: 'receiveInvoice/getBankPerInvoiceId',
267
141
  }),
268
142
 
269
- mountInvoiceUrlInter() {
270
- let invoiceUrl = encodeURIComponent(this.payment.invoiceUrl);
271
- return axios({
272
- url: ENTRYPOINT + `/download?invoiceUrl=${invoiceUrl}&timestamp=${new Date().getTime()}`,
273
- method: 'get',
274
- responseType: 'blob'
275
- }).then((response) => {
276
- let blob = new Blob([response.data], {type: 'application/pdf'}), url = window.URL.createObjectURL(blob);
277
- return url;
278
- });
279
- },
280
-
281
- clickDownloadBilletInter() {
282
- let urlTmp = ENTRYPOINT + `/vendor/pdf.js/web/viewer.html?file=/finance/${this.invoiceId}/download?timestamp${new Date().getTime()}`;
283
- window.open(urlTmp);
284
- },
285
-
286
- mountInvoiceUrlSicred() {
287
- let invoiceUrl = encodeURIComponent(this.payment.invoiceUrl);
288
- return axios({
289
- url: ENTRYPOINT + `/download?invoiceUrl=${invoiceUrl}&timestamp=${new Date().getTime()}`,
290
- method: 'get',
291
- responseType: 'blob'
292
- }).then((response) => {
293
- let blob = new Blob([response.data], {type: 'application/pdf'}), url = window.URL.createObjectURL(blob);
143
+ // Ver boleto ou baixar
144
+ clickDownloadBilletSicred() {
145
+ if (this.isLoadingDownload) {
146
+ return null;
147
+ }
294
148
 
295
- console.log(url);
149
+ this.isLoadingDownload = true;
296
150
 
297
- return url;
298
- });
299
- },
151
+ const viewerUrl = ENTRYPOINT + `/vendor/pdf.js/web/viewer.html?file=/finance/${this.invoiceId}/bank/sicred/download?timestamp=${new Date().getTime()}`;
152
+ this.invoiceUrlSicred = viewerUrl;
153
+ this.showBilletSicred = true;
300
154
 
301
- clickDownloadBilletSicred() {
302
- let urlTmp = ENTRYPOINT + `/download?invoiceUrl=${this.payment.invoiceUrl}`;
303
- window.open(urlTmp);
155
+ this.isLoadingDownload = false;
304
156
  },
305
157
 
158
+ // Consulta informações do banco
306
159
  getBank() {
307
- return this.getBankPerInvoiceId({
308
- invoiceId: this.invoiceId
309
- }).then(data => {
310
- if (data !== null) {
311
- this.paymentInstitution = data.config_value;
312
- this.getPaymentStatus();
313
- return data;
314
- }
315
- return null;
316
- }).catch(error => {
317
- });
318
- },
319
-
320
- refresh() {
321
- this.getPaymentStatus();
322
- },
160
+ return this.getBankPerInvoiceId({ invoiceId: this.invoiceId })
161
+ .then(data => {
162
+ if (data !== null) {
163
+ this.paymentInstitution = data.config_value;
164
+ return data;
165
+ }
166
+ return null;
323
167
 
324
- loadItauDataOnFocus() {
325
- if (this.loadOnFocus) {
326
- this.getPaymentStatus().then(data => {
327
- this.loadOnFocus = false;
168
+ }).catch(error => {
328
169
  });
329
- }
330
- },
331
-
332
- getItauHash() {
333
- let params = {};
334
-
335
- if (this.myCompany !== null)
336
- params['myCompany'] = this.myCompany.id;
337
-
338
- return this.getItauData({
339
- invoiceId: this.invoiceId,
340
- operation: 'itauhash',
341
- params: params
342
- }).then(data => {
343
- if (data !== null) {
344
- return this.itauHash = data;
345
- }
346
- return null;
347
- }).catch(error => {
348
-
349
- });
350
170
  },
351
171
 
352
- getPaymentStatus() {
172
+ // Gera o boleto
173
+ generateSicredBillet() {
353
174
 
354
175
  if (this.isLoading) {
355
176
  return null;
@@ -363,94 +184,36 @@ export default {
363
184
  params['myCompany'] = this.myCompany.id;
364
185
  }
365
186
 
366
- return this.getBank().then(data2 => {
367
-
368
- if (this.paymentInstitution === 'itau') {
369
-
370
- this.getItauData({
371
- invoiceId: this.invoiceId,
372
- operation: 'payment',
373
- params: params
374
- }).then(data => {
375
- if (data !== null) {
376
- return this.payment = data;
377
- }
378
- return null;
379
- }).catch(error => {
380
-
381
- }).finally(() => {
382
- this.isLoading = false;
383
- // this.isLoading = false;
384
- });
385
-
386
- } else if(this.paymentInstitution === 'inter'){
387
-
388
- this.getInterData({
389
- invoiceId: this.invoiceId,
390
- operation: 'payment',
391
- params: params
392
- }).then(data => {
393
- if (data !== null) {
394
- if (!data.response.success) {
395
- let msgErro = data.response.error;
396
- this.$q.notify({
397
- message: msgErro,
398
- html: true,
399
- group: false,
400
- multiLine: true,
401
- position: 'bottom',
402
- type: 'negative',
403
- });
404
- return this.payment = null;
405
- } else {
406
- return this.payment = data.response.data;
407
- }
408
- } else {
409
- return this.payment = null;
410
- }
411
- return null;
412
- }).catch(error => {
413
- console.table(error);
414
- }).finally(() => {
415
- this.isLoading = false;
416
- });
417
-
418
- }
419
- else {
420
-
421
- this.getSicredData({
422
- invoiceId: this.invoiceId,
423
- operation: 'payment',
424
- params: params
425
- }).then(data => {
426
- if (data !== null) {
427
- if (!data.response.success) {
428
- let msgErro = data.response.error;
429
- this.$q.notify({
430
- message: msgErro,
431
- html: true,
432
- group: false,
433
- multiLine: true,
434
- position: 'bottom',
435
- type: 'negative',
436
- });
437
- return this.payment = null;
438
- } else {
439
- return this.payment = data.response.data;
440
- }
441
- } else {
442
- return this.payment = null;
443
- }
444
- return null;
445
- }).catch(error => {
446
- console.table(error);
447
- }).finally(() => {
448
- this.isLoading = false;
449
- });
450
-
187
+ this.getSicredData({
188
+ invoiceId: this.invoiceId,
189
+ operation: 'payment',
190
+ params: params
191
+ }).then(data => {
192
+ if (data !== null) {
193
+ if (!data.response.success) {
194
+ let msgErro = data.response.error;
195
+ this.$q.notify({
196
+ message: msgErro,
197
+ html: true,
198
+ group: false,
199
+ multiLine: true,
200
+ position: 'bottom',
201
+ type: 'negative',
202
+ });
203
+ return this.payment = null;
204
+ } else {
205
+ return this.payment = data.response.data;
206
+ }
207
+ } else {
208
+ return this.payment = null;
451
209
  }
452
210
 
211
+ }).catch(error => {
212
+ console.table(error);
213
+ }).finally(() => {
214
+ this.isLoading = false;
453
215
  });
216
+
454
217
  },
455
218
  },
456
219
  };