-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
1253 lines (1101 loc) · 57.4 KB
/
Copy pathscript.js
File metadata and controls
1253 lines (1101 loc) · 57.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// =============================
// TRANSLATION SYSTEM
// =============================
const translations = {
pt: {
app: {
title: 'Simulador de Crédito',
subtitle: 'Cabo Verde 🇨🇻'
},
form: {
amount: {
label: 'Quanto dinheiro quer pedir emprestado?',
helper: 'Para carro, casa ou outro fim. Mínimo 10.000 CVE, máximo 50.000.000 CVE.'
},
period: {
label: 'Em quantos meses pretende pagar?',
helper: 'Períodos maiores = prestações menores, mas mais juros no total.',
months: 'Meses',
years: 'Anos'
},
rate: {
label: 'Taxa de juro anual do banco (%)',
helper: 'Peça este valor ao seu banco. Afeta quanto vai pagar de juros.'
},
divider: { or: 'OU' },
taeg: {
label: 'Usar TAEG do banco (mais realista)',
helper: 'A TAEG inclui juros + comissões + seguros + outros encargos. Peça ao seu banco.',
hint: '💡 Com TAEG (Aviso BCV 3/2013): Total a Pagar e Custo Total incluem todos os encargos reais.'
},
buttons: {
calculate: '🔢 Calcular',
reset: '🔄 Limpar Tudo',
copy: '📋 Copiar Resultados'
}
},
results: {
title: 'Resultados',
monthlyPayment: { label: 'Prestação Mensal' },
taeg: {
label: 'TAEG (Taxa Anual Efetiva)',
labelEst: 'TAN (sem encargos)',
labelBank: 'TAEG (fornecida pelo banco)'
},
totalPayment: { label: 'Total a Pagar' },
totalInterest: {
label: 'Total de Juros (Custo do Crédito)',
labelWithTaeg: 'Custo Total do Crédito (com encargos)'
},
summary: { title: '📋 Resumo' },
affordability: {
title: '💼 Pode pagar?',
helper: 'Indique seu rendimento mensal para saber se a prestação é acessível',
income: { label: 'Seu rendimento mensal aproximado (CVE)' },
guidance: 'Recomendação geral: prestação < 20% do rendimento = confortável | 20-35% = aceitável | > 35% = apertado',
indicator: {
green: '✅ Confortável',
yellow: '⚠️ Aceitável',
red: '🔴 Apertado'
}
},
amortization: {
title: '📅 Como vai pagar?',
subtitle: 'Primeiras 12 prestações (cronograma completo disponível)',
columns: {
month: 'Mês',
payment: 'Prestação',
interest: 'Juros',
principal: 'Devolve',
balance: 'Saldo'
},
expand: 'Ver todas as prestações'
},
comparison: {
title: '🔀 Comparison Mode',
info: 'Use os controles acima para ajustar os valores. Clique no botão abaixo para comparar a situação anterior com a atual.',
button: '📸 Capturar para Comparação'
},
transparency: {
title: '🔓 Transparência',
disclaimer: 'Este simulador é apenas educativo. Os valores são estimativas com base no mercado de Cabo Verde e podem variar conforme o banco.',
privacy: '🔒 Privacidade: Não guardamos nenhum dado seu. Tudo funciona no seu browser.',
contact: 'Contactar banco: Confirme sempre os valores com sua instituição financeira antes de assinar qualquer contrato.'
}
},
footer: {
disclaimer: 'Simulação indicativa com base no mercado de Cabo Verde 🇨🇻 Consulte a instituição financeira para valores exatos.',
credit: 'Simulador de Crédito Cabo Verde',
privacy: 'Sem recolha de dados | Totalmente privado | Educativo'
},
popup: {
formula: '📐 Fórmula utilizada:',
button: 'Entendi'
},
messages: {
amountError: 'Montante deve estar entre 10.000 e 50.000.000 CVE',
periodError: 'Período deve ser superior a 0',
rateError: 'Taxa deve estar entre 0% e 30%',
taegError: 'TAEG deve ser superior a 0',
taegEstNote: '⚠️ TAEG estimada com base na TAN. Não inclui comissões, seguros nem outros encargos. Para o custo real, insira a TAEG fornecida pelo banco.',
firstCapture: 'Situação anterior capturada! Altere os valores e clique novamente para comparar.',
comparisonDone: 'Comparação realizada!',
formReset: 'Formulário reiniciado!',
copySuccess: 'Resultados copiados para a área de transferência!',
copyError: 'Erro ao copiar resultados',
executeFirst: 'Execute uma simulação primeiro',
taegBank: 'TAEG Fornecida pelo Banco',
nominalRate: 'Taxa Nominal'
},
fiscal: {
title: '🏛️ Regime Fiscal — Imposto de Selo',
isJuros: 'IS sobre Juros (3,5%)',
isCapital: 'IS sobre Capital (0,5%)',
isTotal: 'Total Imposto de Selo (estimativa)',
custoTotal: 'Custo Total Estimado c/ IS',
note: 'Conforme o Código do Imposto de Selo de Cabo Verde, aplicável a operações de crédito.',
tanOnlyBadge: 'Estimativa s/ TAEG',
tanOnlyNote: '⚠️ Estimativa calculada com base na TAN. O IS real já está incluído na TAEG fornecida pelo banco — introduza a TAEG para ver o custo total correto.',
includedInTaeg: '✅ O Imposto de Selo já está incluído na TAEG fornecida pelo banco. A TAEG reflete o custo total real do crédito, englobando juros, comissões e impostos.'
},
info: {
amount: {
title: 'Montante do Crédito',
description: 'É o valor total que pretende pedir emprestado ao banco ou instituição financeira. Por exemplo, se quer comprar uma casa ou carro, este é o valor que precisa.',
formula: 'Representado por: P (Principal)'
},
period: {
title: 'Período de Pagamento',
description: 'É o tempo que terá para pagar o crédito. Pode escolher entre meses ou anos. Quanto maior o período, menor a prestação mensal, mas mais juros pagará no total.',
formula: 'n = número de meses (anos × 12)'
},
nominalRate: {
title: 'Taxa Nominal Anual',
description: 'É a taxa de juro básica que o banco cobra por ano, sem contar com outros custos. Esta taxa serve de base para calcular a TAEG (custo real do crédito).',
formula: 'Taxa mensal = Taxa Anual ÷ 12'
},
taegInput: {
title: 'TAEG Fornecida pelo Banco',
description: 'A TAEG (Taxa Anual Efetiva Global) inclui todos os custos do crédito: juros, comissões, seguros e Imposto de Selo. É definida pelo Aviso BCV n.º 3/2013 (Anexo I) como a taxa que iguala o valor atual do crédito ao valor atual de todos os reembolsos e encargos.\n\nA Prestação Mensal mantém-se calculada com a TAN. A TAEG é usada para estimar o Custo Total real.',
formula: 'Definição BCV (Aviso 3/2013, Anexo I):\n∑ Cⱼ × (1 + TAEG)^(−tj) = ∑ Dₗ × (1 + TAEG)^(−sl)\n\nOnde:\n Cⱼ = montante utilizado do crédito\n Dₗ = reembolsos e encargos (prestações + IS + comissões)\n tj, sl = intervalos de tempo em anos\n\nAplicação no simulador:\n i_mensal = (1 + TAEG/100)^(1/12) − 1\n Custo Total = PMT(i_mensal, n, P) × n'
},
monthlyPayment: {
title: 'Prestação Mensal',
description: 'É o valor que terá de pagar todos os meses ao banco. Este valor inclui uma parte do dinheiro emprestado (capital) e os juros. A prestação é sempre calculada com base na Taxa Nominal Anual.',
formula: 'PMT = P × [i × (1+i)ⁿ] ÷ [(1+i)ⁿ - 1]\n\nOnde:\nP = Montante\ni = Taxa mensal (Taxa Nominal ÷ 12)\nn = Número de meses'
},
taeg: {
title: 'TAN vs TAEG — qual a diferença?',
description: 'Sem TAEG do banco: o cartão mostra "TAN (sem encargos)". A Taxa Anual Nominal é a taxa de juro base do contrato — não inclui comissões, seguros nem outros encargos. É o ponto de partida do cálculo, não o custo real.\n\nCom TAEG do banco: é exibida a TAEG real conforme o Aviso BCV n.º 3/2013, que inclui todos os encargos da operação. Use a TAEG para comparar propostas de diferentes bancos.',
formula: 'Sem TAEG: exibida a TAN tal como introduzida (sem cálculo)\n\nCom TAEG (BCV Anexo I) = taxa X que iguala:\nPV(crédito utilizado) = PV(reembolsos + todos os encargos)\n\nTAEG ≥ TAN sempre que existam encargos adicionais.'
},
totalPayment: {
title: 'Total a Pagar',
description: 'Sem TAEG do banco: soma de todas as prestações mensais calculadas com a TAN (capital + juros). Não inclui comissões, seguros ou outros encargos cobrados pelo banco.\n\nCom TAEG do banco: estimativa do custo total calculada com base na TAEG, que inclui todos os encargos da operação conforme o Aviso BCV n.º 3/2013.',
formula: 'Sem TAEG: Total = Prestação Mensal (TAN) × Nº de Meses\n\nCom TAEG: Total estimado = PMT(TAEG) × Nº de Meses\n(inclui juros + encargos estimados)'
},
totalInterest: {
title: 'Custo do Crédito',
description: 'Sem TAEG: juros totais calculados com a TAN — diferença entre o total pago e o montante emprestado. Não inclui comissões, seguros ou outros encargos.\n\nCom TAEG: estimativa do custo total incluindo juros, comissões, seguros e demais encargos, conforme a definição de «Custo total do crédito» do Aviso BCV n.º 3/2013.',
formula: 'Sem TAEG: Juros = Total a Pagar (TAN) − Montante\n\nCom TAEG: Custo Total = PMT(TAEG) × Nº Meses − Montante\n(inclui todos os encargos)'
},
impostoSelo: {
title: 'Imposto de Selo (Regime Fiscal CV)',
description: 'Em Cabo Verde, as operações de crédito estão sujeitas ao Imposto de Selo (IS) conforme o Código do Imposto de Selo:\n\n• 3,5% sobre os juros\n• 0,5% sobre o capital utilizado\n\nO IS já está incluído na TAEG fornecida pelo banco — a TAEG reflete o custo total real do crédito, englobando juros, comissões e impostos.\n\nQuando só é introduzida a TAN, o simulador apresenta uma estimativa do IS para dar uma ideia do custo fiscal adicional. Para o valor real, solicite a TAEG ao banco.',
formula: 'Estimativa IS (só com TAN):\nIS sobre Juros = Total Juros × 3,5%\nIS sobre Capital = Montante × 0,5%\n\nCom TAEG do banco:\nIS já incluído → não somar novamente'
}
}
},
en: {
app: {
title: 'Credit Simulator',
subtitle: 'Cape Verde 🇨🇻'
},
form: {
amount: {
label: 'How much money do you want to borrow?',
helper: 'For car, house or other purpose. Min 10,000 CVE, max 50,000,000 CVE.'
},
period: {
label: 'How many months will you pay?',
helper: 'Longer periods = lower payments, but more interest in total.',
months: 'Months',
years: 'Years'
},
rate: {
label: 'Bank annual interest rate (%)',
helper: 'Ask your bank for this value. It affects how much you pay in interest.'
},
divider: { or: 'OR' },
taeg: {
label: 'Use bank\'s TAEG (more realistic)',
helper: 'TAEG = rate that includes commissions, insurance, etc. Shows real cost.',
hint: '💡 With TAEG: Total Payment and Interest include all real costs (fees, insurance, etc.)'
},
buttons: {
calculate: '🔢 Calculate',
reset: '🔄 Clear All',
copy: '📋 Copy Results'
}
},
results: {
title: 'Results',
monthlyPayment: { label: 'Monthly Payment' },
taeg: {
label: 'TAEG (Annual Effective Rate)',
labelEst: 'TAN (excl. charges)',
labelBank: 'TAEG (provided by bank)'
},
totalPayment: { label: 'Total Payment' },
totalInterest: {
label: 'Total Interest (Cost of Credit)',
labelWithTaeg: 'Total Cost of Credit (incl. charges)'
},
summary: { title: '📋 Summary' },
affordability: {
title: '💼 Can you afford it?',
helper: 'Enter your monthly income to see if the payment is affordable',
income: { label: 'Your approximate monthly income (CVE)' },
guidance: 'General recommendation: payment < 20% of income = comfortable | 20-35% = acceptable | > 35% = tight',
indicator: {
green: '✅ Comfortable',
yellow: '⚠️ Acceptable',
red: '🔴 Tight'
}
},
amortization: {
title: '📅 How will you pay?',
subtitle: 'First 12 payments (full schedule available)',
columns: {
month: 'Month',
payment: 'Payment',
interest: 'Interest',
principal: 'Repay',
balance: 'Balance'
},
expand: 'See all payments'
},
comparison: {
title: '🔀 Comparison Mode',
info: 'Use the controls above to adjust values. Click the button below to compare the previous situation with the current one.',
button: '📸 Capture for Comparison'
},
transparency: {
title: '🔓 Transparency',
disclaimer: 'This simulator is educational only. Values are estimates based on Cape Verde market and may vary by bank.',
privacy: '🔒 Privacy: We don\'t store any of your data. Everything works in your browser.',
contact: 'Contact bank: Always confirm values with your financial institution before signing any contract.'
}
},
footer: {
disclaimer: 'Indicative simulation based on Cape Verde market 🇨🇻 Consult the financial institution for exact values.',
credit: 'Cape Verde Credit Simulator',
privacy: 'No data collection | Completely private | Educational'
},
popup: {
formula: '📐 Formula used:',
button: 'Got it'
},
messages: {
amountError: 'Amount must be between 10,000 and 50,000,000 CVE',
periodError: 'Period must be greater than 0',
rateError: 'Rate must be between 0% and 30%',
taegError: 'TAEG must be greater than 0',
taegEstNote: '⚠️ TAEG estimated from TAN only. Does not include fees, insurance or other charges. For the real cost, enter the TAEG provided by your bank.',
firstCapture: 'Previous situation captured! Change the values and click again to compare.',
comparisonDone: 'Comparison completed!',
formReset: 'Form reset!',
copySuccess: 'Results copied to clipboard!',
copyError: 'Error copying results',
executeFirst: 'Run a simulation first',
taegBank: 'TAEG Provided by Bank',
nominalRate: 'Nominal Rate'
},
info: {
amount: {
title: 'Credit Amount',
description: 'It is the total amount you want to borrow from a bank or financial institution. For example, if you want to buy a house or car, this is the amount you need.',
formula: 'Represented by: P (Principal)'
},
period: {
title: 'Payment Period',
description: 'It is the time you have to repay the credit. You can choose between months or years. The longer the period, the lower the monthly payment, but the more interest you will pay in total.',
formula: 'n = number of months (years × 12)'
},
nominalRate: {
title: 'Nominal Annual Rate',
description: 'It is the basic interest rate that the bank charges per year, without including other costs. This rate is used as a basis to calculate the TAEG (real cost of credit).',
formula: 'Monthly rate = Annual Rate ÷ 12'
},
taegInput: {
title: 'TAEG Provided by the Bank',
description: 'TAEG (Annual Effective Global Rate) includes all credit costs: interest, fees, insurance and Stamp Tax. It is defined by BCV Notice 3/2013 (Annex I) as the rate that equates the present value of the credit to the present value of all repayments and charges.\n\nThe Monthly Payment remains based on TAN. The TAEG is used to estimate the real Total Cost.',
formula: 'BCV Definition (Notice 3/2013, Annex I):\n∑ Cⱼ × (1 + TAEG)^(−tj) = ∑ Dₗ × (1 + TAEG)^(−sl)\n\nWhere:\n Cⱼ = credit amount used\n Dₗ = repayments and charges (payments + ST + fees)\n tj, sl = time intervals in years\n\nSimulator application:\n i_monthly = (1 + TAEG/100)^(1/12) − 1\n Total Cost = PMT(i_monthly, n, P) × n'
},
monthlyPayment: {
title: 'Monthly Payment',
description: 'It is the amount you will have to pay every month to the bank. This value includes part of the borrowed money (principal) and interest. The payment is always calculated based on the Nominal Annual Rate.',
formula: 'PMT = P × [i × (1+i)ⁿ] ÷ [(1+i)ⁿ - 1]\n\nWhere:\nP = Credit Amount\ni = Monthly rate (Nominal Rate ÷ 12)\nn = Number of months'
},
taeg: {
title: 'TAN vs TAEG — what\'s the difference?',
description: 'Without bank TAEG: the card shows "TAN (excl. charges)". The Nominal Annual Rate is the base interest rate in the contract — it does not include fees, insurance or other charges. It is the starting point of the calculation, not the real cost.\n\nWith bank TAEG: the real TAEG is shown as per BCV Notice 3/2013, which includes all charges. Use the TAEG to compare offers from different banks.',
formula: 'Without TAEG: TAN displayed as entered (no calculation)\n\nWith TAEG (BCV Annex I) = rate X where:\nPV(credit used) = PV(repayments + all charges)\n\nTAEG ≥ TAN whenever additional charges exist.'
},
totalPayment: {
title: 'Total Payment',
description: 'Without bank TAEG: sum of all monthly payments calculated with TAN (principal + interest). Does not include bank fees, insurance or other charges.\n\nWith bank TAEG: estimated total cost based on the TAEG, which includes all charges as per BCV Notice 3/2013.',
formula: 'Without TAEG: Total = Monthly Payment (TAN) × No. of Months\n\nWith TAEG: Estimated Total = PMT(TAEG) × No. of Months\n(includes interest + estimated charges)'
},
totalInterest: {
title: 'Cost of Credit',
description: 'Without TAEG: total interest calculated with TAN — difference between total paid and amount borrowed. Does not include fees, insurance or other charges.\n\nWith TAEG: estimated total cost including interest, fees, insurance and other charges, as per the definition of "Total cost of credit" in BCV Notice 3/2013.',
formula: 'Without TAEG: Interest = Total Payment (TAN) − Principal\n\nWith TAEG: Total Cost = PMT(TAEG) × No. Months − Principal\n(includes all charges)'
},
impostoSelo: {
title: 'Stamp Tax — Fiscal Regime CV',
description: 'In Cape Verde, credit operations are subject to Stamp Tax (IS) under the Cape Verde Stamp Tax Code:\n\n• 3.5% on interest\n• 0.5% on capital used\n\nStamp Tax is already included in the TAEG provided by the bank — the TAEG reflects the real total cost of credit, covering interest, fees and taxes.\n\nWhen only TAN is entered, the simulator shows an estimated IS to illustrate the fiscal cost. For the real value, ask your bank for the TAEG.',
formula: 'Estimated IS (TAN only):\nIS on Interest = Total Interest × 3.5%\nIS on Capital = Principal × 0.5%\n\nWith bank TAEG:\nIS already included → do not add again'
}
},
fiscal: {
title: '🏛️ Fiscal Regime — Stamp Tax',
isJuros: 'Stamp Tax on Interest (3.5%)',
isCapital: 'Stamp Tax on Capital (0.5%)',
isTotal: 'Total Stamp Tax (estimate)',
custoTotal: 'Estimated Total Cost incl. Stamp Tax',
note: 'As per the Cape Verde Stamp Tax Code, applicable to credit operations.',
tanOnlyBadge: 'Estimate without TAEG',
tanOnlyNote: '⚠️ Estimate based on TAN only. The actual Stamp Tax is already included in the bank\'s TAEG — enter the TAEG to see the correct total cost.',
includedInTaeg: '✅ Stamp Tax is already included in the TAEG provided by the bank. The TAEG reflects the real total cost of credit, covering interest, fees and taxes.'
}
}
};
// Current language
let currentLanguage = localStorage.getItem('language') || 'pt';
// Get translation value
function t(path) {
const keys = path.split('.');
let value = translations[currentLanguage];
for (let key of keys) {
value = value[key];
if (!value) return path;
}
return value;
}
// Toggle Language
function toggleLanguage() {
currentLanguage = currentLanguage === 'pt' ? 'en' : 'pt';
localStorage.setItem('language', currentLanguage);
updateLanguageDisplay();
translatePage();
// Update period display with the new language
const periodValue = parseInt(document.getElementById('periodValue').value) || 0;
const periodUnit = document.getElementById('periodUnit')?.value || 'meses';
const unitText = periodUnit === 'anos' ? (currentLanguage === 'pt' ? 'anos' : 'years') : (currentLanguage === 'pt' ? 'meses' : 'months');
document.getElementById('periodDisplay').textContent = periodValue + ' ' + unitText;
if (currentResults) calculate();
}
function updateLanguageDisplay() {
const langCode = document.getElementById('langCode');
if (langCode) {
langCode.textContent = currentLanguage === 'pt' ? 'EN' : 'PT';
}
}
// Translate all static elements
function translatePage() {
document.querySelectorAll('[data-i18n]').forEach(element => {
const key = element.getAttribute('data-i18n');
const translation = t(key);
if (element.tagName === 'OPTION') {
element.textContent = translation;
} else if (element.tagName === 'BUTTON' && element.classList.contains('popup-button')) {
element.textContent = translation;
} else if (element.tagName === 'SPAN') {
element.textContent = translation;
} else if (element.tagName === 'H1' || element.tagName === 'H3' || element.tagName === 'H2') {
element.textContent = translation;
} else if (element.tagName === 'P') {
element.textContent = translation;
} else {
element.textContent = translation;
}
});
}
// =============================
// STATE MANAGEMENT
// =============================
let currentResults = null;
let previousResults = null;
// =============================
// DARK MODE
// =============================
function toggleDarkMode() {
const html = document.documentElement;
const currentTheme = html.getAttribute('data-theme');
const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
html.setAttribute('data-theme', newTheme);
localStorage.setItem('theme', newTheme);
updateDarkModeIcon(newTheme);
}
function updateDarkModeIcon(theme) {
const icon = document.getElementById('darkModeIcon');
if (!icon) return;
if (theme === 'dark') {
icon.innerHTML = '<circle cx="12" cy="12" r="5"/><line x1="12" y1="1" x2="12" y2="3"/><line x1="12" y1="21" x2="12" y2="23"/><line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/><line x1="1" y1="12" x2="3" y2="12"/><line x1="21" y1="12" x2="23" y2="12"/><line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/><line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/>';
} else {
icon.innerHTML = '<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>';
}
}
function initializeDarkMode() {
const savedTheme = localStorage.getItem('theme') || 'light';
const html = document.documentElement;
if (!localStorage.getItem('theme')) {
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
const theme = prefersDark ? 'dark' : 'light';
html.setAttribute('data-theme', theme);
updateDarkModeIcon(theme);
} else {
html.setAttribute('data-theme', savedTheme);
updateDarkModeIcon(savedTheme);
}
}
// =============================
// FORMATTING
// =============================
function formatCurrency(value) {
const locale = currentLanguage === 'pt' ? 'pt-CV' : 'en-US';
return new Intl.NumberFormat(locale, {
minimumFractionDigits: 2,
maximumFractionDigits: 2
}).format(value);
}
function formatNumber(value) {
const locale = currentLanguage === 'pt' ? 'pt-CV' : 'en-US';
return new Intl.NumberFormat(locale, {
minimumFractionDigits: 0,
maximumFractionDigits: 0
}).format(value);
}
// =============================
// FORM VALIDATION
// =============================
function validateForm() {
const amount = parseFloat(document.getElementById('amount').value) || 0;
const period = parseFloat(document.getElementById('periodValue').value) || 0;
const rate = parseFloat(document.getElementById('nominalRate').value) || 0;
const useTaeg = document.getElementById('useTaeg').checked;
const taegInput = parseFloat(document.getElementById('taegInput').value) || 0;
let isValid = true;
if (amount <= 0 || amount > 50000000) {
showError('amountError', t('messages.amountError'));
isValid = false;
} else {
clearError('amountError');
}
if (period <= 0) {
showError('periodError', t('messages.periodError'));
isValid = false;
} else {
clearError('periodError');
}
if (rate <= 0 || rate > 30) {
showError('rateError', t('messages.rateError'));
isValid = false;
} else {
clearError('rateError');
}
if (useTaeg && taegInput <= 0) {
showError('taegError', t('messages.taegError'));
isValid = false;
} else {
clearError('taegError');
}
return isValid;
}
function showError(elementId, message) {
const element = document.getElementById(elementId);
if (element) {
element.textContent = message;
element.style.display = 'inline-block';
const inputId = elementId.replace('Error', '');
const inputElement = document.getElementById(inputId);
if (inputElement) {
inputElement.classList.add('error');
}
}
}
function clearError(elementId) {
const element = document.getElementById(elementId);
if (element) {
element.style.display = 'none';
element.textContent = '';
const inputId = elementId.replace('Error', '');
const inputElement = document.getElementById(inputId);
if (inputElement) {
inputElement.classList.remove('error');
}
}
}
// =============================
// SLIDER SYNC
// =============================
document.getElementById('amountSlider')?.addEventListener('input', function() {
document.getElementById('amount').value = this.value;
document.getElementById('amountDisplay').textContent = formatNumber(this.value);
calculate();
});
document.getElementById('periodSlider')?.addEventListener('input', function() {
document.getElementById('periodValue').value = this.value;
const value = parseInt(this.value);
const periodUnit = document.getElementById('periodUnit')?.value || 'meses';
const unitText = periodUnit === 'anos' ? (currentLanguage === 'pt' ? 'anos' : 'years') : (currentLanguage === 'pt' ? 'meses' : 'months');
document.getElementById('periodDisplay').textContent = value + ' ' + unitText;
calculate();
});
document.getElementById('rateSlider')?.addEventListener('input', function() {
document.getElementById('nominalRate').value = this.value;
document.getElementById('rateDisplay').textContent = parseFloat(this.value).toFixed(1) + '%';
calculate();
});
document.getElementById('amount')?.addEventListener('input', function() {
const numericValue = this.value;
document.getElementById('amountSlider').value = numericValue || 0;
document.getElementById('amountDisplay').textContent = formatNumber(numericValue || 0);
});
document.getElementById('amount')?.addEventListener('paste', function(e) {
e.preventDefault();
const pastedText = (e.clipboardData || window.clipboardData).getData('text');
const numericValue = pastedText.replace(/\D/g, '');
this.value = numericValue || '';
document.getElementById('amountSlider').value = numericValue || 0;
document.getElementById('amountDisplay').textContent = formatNumber(numericValue || 0);
calculate();
});
document.getElementById('periodValue')?.addEventListener('input', function() {
const value = parseInt(this.value) || 0;
document.getElementById('periodSlider').value = value;
const periodUnit = document.getElementById('periodUnit')?.value || 'meses';
const unitText = periodUnit === 'anos' ? (currentLanguage === 'pt' ? 'anos' : 'years') : (currentLanguage === 'pt' ? 'meses' : 'months');
document.getElementById('periodDisplay').textContent = value + ' ' + unitText;
});
document.getElementById('nominalRate')?.addEventListener('input', function() {
document.getElementById('rateSlider').value = this.value;
document.getElementById('rateDisplay').textContent = parseFloat(this.value).toFixed(1) + '%';
});
// =============================
// CALCULATION
// =============================
function calculate() {
if (!validateForm()) {
document.getElementById('results').style.display = 'none';
return;
}
const principal = parseFloat(document.getElementById('amount').value) || 0;
const rate = parseFloat(document.getElementById('nominalRate').value) || 0;
const period = parseFloat(document.getElementById('periodValue').value) || 0;
const periodUnit = document.getElementById('periodUnit').value;
const useTaeg = document.getElementById('useTaeg').checked;
const taegInput = parseFloat(document.getElementById('taegInput').value) || 0;
const totalMonths = periodUnit === 'anos' || periodUnit === 'years' ? period * 12 : period;
const monthlyRate = rate / 100 / 12;
const monthlyPayment = principal * (monthlyRate * Math.pow(1 + monthlyRate, totalMonths)) /
(Math.pow(1 + monthlyRate, totalMonths) - 1);
let taeg;
let totalPayment;
let totalInterest;
let calculationMethod;
if (useTaeg && taegInput > 0) {
taeg = taegInput;
calculationMethod = t('messages.taegBank');
const effectiveMonthlyRate = Math.pow(1 + taeg / 100, 1 / 12) - 1;
const effectivePayment = principal * (effectiveMonthlyRate * Math.pow(1 + effectiveMonthlyRate, totalMonths)) /
(Math.pow(1 + effectiveMonthlyRate, totalMonths) - 1);
totalPayment = effectivePayment * totalMonths;
totalInterest = totalPayment - principal;
} else {
calculationMethod = t('messages.nominalRate');
taeg = rate;
totalPayment = monthlyPayment * totalMonths;
totalInterest = totalPayment - principal;
}
currentResults = {
principal,
monthlyPayment,
taeg,
totalPayment,
totalInterest,
totalMonths,
rate,
calculationMethod,
timestamp: new Date()
};
document.getElementById('results').style.display = 'block';
document.getElementById('monthlyPayment').textContent = formatCurrency(monthlyPayment) + ' CVE';
document.getElementById('taeg').textContent = taeg.toFixed(2) + '%';
document.getElementById('totalPayment').textContent = formatCurrency(totalPayment) + ' CVE';
document.getElementById('totalInterest').textContent = formatCurrency(totalInterest) + ' CVE';
// Update result card labels dynamically based on calculation mode
const taegCardLabel = document.querySelector('.result-card.green .result-header span[data-i18n]');
const interestCardLabel = document.querySelector('.result-card.orange .result-header span[data-i18n]');
if (taegCardLabel) {
taegCardLabel.textContent = useTaeg && taegInput > 0
? t('results.taeg.labelBank')
: t('results.taeg.labelEst');
}
if (interestCardLabel) {
interestCardLabel.textContent = useTaeg && taegInput > 0
? t('results.totalInterest.labelWithTaeg')
: t('results.totalInterest.label');
}
// Imposto de Selo
document.getElementById('fiscalSection').style.display = 'block';
document.querySelector('#fiscalSection h3').textContent = t('fiscal.title');
const fiscalBadge = document.getElementById('fiscalBadge');
if (useTaeg && taegInput > 0) {
// IS already included in TAEG — just show informational message
fiscalBadge.style.display = 'none';
document.getElementById('fiscalGrid').style.display = 'none';
document.getElementById('fiscalIncluded').style.display = 'block';
document.getElementById('fiscalIncludedMsg').textContent = t('fiscal.includedInTaeg');
document.getElementById('fiscalNote').textContent = t('fiscal.note');
} else {
// TAN only — show IS estimate as additional cost
fiscalBadge.textContent = t('fiscal.tanOnlyBadge');
fiscalBadge.style.display = 'inline-block';
document.getElementById('fiscalIncluded').style.display = 'none';
document.getElementById('fiscalGrid').style.display = 'flex';
const isJuros = totalInterest * 0.035;
const isCapital = principal * 0.005;
const isTotal = isJuros + isCapital;
const custoTotalComIS = totalPayment + isTotal;
document.getElementById('labelIsJuros').textContent = t('fiscal.isJuros');
document.getElementById('labelIsCapital').textContent = t('fiscal.isCapital');
document.getElementById('labelIsTotal').textContent = t('fiscal.isTotal');
document.getElementById('labelCustoTotal').textContent = t('fiscal.custoTotal');
document.getElementById('isJuros').textContent = formatCurrency(isJuros) + ' CVE';
document.getElementById('isCapital').textContent = formatCurrency(isCapital) + ' CVE';
document.getElementById('isTotal').textContent = formatCurrency(isTotal) + ' CVE';
document.getElementById('custoTotalComIS').textContent = formatCurrency(custoTotalComIS) + ' CVE';
document.getElementById('fiscalNote').textContent = t('fiscal.tanOnlyNote');
}
const methodBadge = document.getElementById('methodBadge');
if (methodBadge) {
methodBadge.innerHTML = `<span>✓ ${calculationMethod}</span>`;
methodBadge.style.display = 'inline-block';
}
const periodText = currentLanguage === 'pt' ? 'Período' : 'Period';
const yearText = currentLanguage === 'pt' ? 'anos' : 'years';
const nominalText = currentLanguage === 'pt' ? 'Taxa Nominal' : 'Nominal Rate';
const monthlyText = currentLanguage === 'pt' ? 'Taxa Mensal' : 'Monthly Rate';
const taegCalcText = currentLanguage === 'pt' ? 'TAN (sem encargos)' : 'TAN (excl. charges)';
const taegProvText = currentLanguage === 'pt' ? 'TAEG (fornecida)' : 'TAEG (provided)';
const costsText = currentLanguage === 'pt' ? 'custos totais reais' : 'real total costs';
const baseText = currentLanguage === 'pt' ? 'base para PMT' : 'basis for PMT';
const callcText = currentLanguage === 'pt' ? '✓ Total a Pagar e Juros calculados com TAEG real' : '✓ Total Payment and Interest calculated with real TAEG';
const aoAnoText = currentLanguage === 'pt' ? 'ao ano' : 'per year';
let summaryHTML = `<p><strong>${periodText}:</strong> ${totalMonths} ${currentLanguage === 'pt' ? 'meses' : 'months'} (${(totalMonths / 12).toFixed(1)} ${yearText})</p>`;
if (useTaeg && taegInput > 0) {
summaryHTML += `
<p><strong>${nominalText}:</strong> ${rate}% ${aoAnoText} (${baseText})</p>
<p><strong>${taegProvText}:</strong> ${taegInput}% (${costsText})</p>
<p class="summary-highlight">${callcText}</p>
`;
} else {
summaryHTML += `
<p><strong>${nominalText}:</strong> ${rate}% ${aoAnoText}</p>
<p><strong>${monthlyText}:</strong> ${(rate / 12).toFixed(2)}%</p>
<p><strong>${taegCalcText}:</strong> ${taeg.toFixed(2)}%</p>
<p class="summary-note">${t('messages.taegEstNote')}</p>
`;
}
document.getElementById('summaryContent').innerHTML = summaryHTML;
document.getElementById('copyBtn').style.display = 'flex';
generateAmortizationSchedule(principal, monthlyPayment, monthlyRate, totalMonths, useTaeg && taegInput > 0);
// Update affordability indicator if income has been entered
const incomeInput = document.getElementById('incomeInput');
if (incomeInput && parseFloat(incomeInput.value) > 0) {
updateAffordabilityIndicator();
}
}
// =============================
// AMORTIZATION SCHEDULE
// =============================
function generateAmortizationSchedule(principal, monthlyPayment, monthlyRate, totalMonths, useTaeg) {
let balance = principal;
const pt = currentLanguage === 'pt';
const monthCol = pt ? 'Mês' : 'Month';
const paymentCol = pt ? 'Prestação' : 'Payment';
const interestCol = pt ? 'Juros' : 'Interest';
const principalCol = pt ? 'Capital' : 'Principal';
const isCol = pt ? 'IS (3,5%)' : 'ST (3.5%)';
const totalISCol = pt ? 'Total c/ IS' : 'Total w/ ST';
const balanceCol = pt ? 'Saldo' : 'Balance';
let tableHTML = `
<table>
<thead>
<tr>
<th>${monthCol}</th>
<th>${paymentCol}</th>
<th>${interestCol}</th>
<th>${principalCol}</th>
<th class="col-is">${isCol}</th>
<th class="col-is">${totalISCol}</th>
<th>${balanceCol}</th>
</tr>
</thead>
<tbody>
`;
const monthsToShow = Math.min(12, totalMonths);
for (let i = 1; i <= monthsToShow; i++) {
const interest = balance * monthlyRate;
const principal_payment = monthlyPayment - interest;
const isJuros = interest * 0.035;
const totalWithIS = monthlyPayment + isJuros;
balance -= principal_payment;
tableHTML += `
<tr>
<td>${i}</td>
<td>${formatCurrency(monthlyPayment)}</td>
<td>${formatCurrency(interest)}</td>
<td>${formatCurrency(principal_payment)}</td>
<td class="col-is is-value">${formatCurrency(isJuros)}</td>
<td class="col-is total-is-value">${formatCurrency(totalWithIS)}</td>
<td>${formatCurrency(Math.max(0, balance))}</td>
</tr>
`;
}
tableHTML += `</tbody></table>`;
// IS on capital — one-time charge note
const isCapital = principal * 0.005;
const isCapitalNote = pt
? `IS sobre Capital (0,5% × ${formatCurrency(principal)} CVE) = <strong>${formatCurrency(isCapital)} CVE</strong> — cobrado uma única vez no início do contrato.`
: `Stamp Tax on Capital (0.5% × ${formatCurrency(principal)} CVE) = <strong>${formatCurrency(isCapital)} CVE</strong> — charged once at contract inception.`;
tableHTML += `<p class="amort-is-note">${isCapitalNote}</p>`;
if (totalMonths > 12) {
const note = pt
? `Mostrando primeiras 12 prestações de ${totalMonths}`
: `Showing first 12 payments of ${totalMonths}`;
tableHTML += `<p style="text-align:center;font-size:0.75rem;color:var(--text-muted);margin-top:0.5rem;">${note}</p>`;
}
document.getElementById('amortizationContent').innerHTML = tableHTML;
}
// =============================
// AFFORDABILITY INDICATOR
// =============================
function updateAffordabilityIndicator() {
const monthlyPayment = currentResults.monthlyPayment;
const incomeInput = document.getElementById('incomeInput');
const income = parseFloat(incomeInput.value) || 0;
if (income <= 0) {
document.getElementById('affordabilityIndicator').style.display = 'none';
return;
}
const percentage = (monthlyPayment / income) * 100;
let color, status, message;
if (percentage < 20) {
color = '#16a34a'; // green
status = currentLanguage === 'pt' ? '✅ Confortável' : '✅ Comfortable';
} else if (percentage < 35) {
color = '#ea580c'; // warning orange
status = currentLanguage === 'pt' ? '⚠️ Aceitável' : '⚠️ Acceptable';
} else {
color = '#dc2626'; // danger red
status = currentLanguage === 'pt' ? '🔴 Apertado' : '🔴 Tight';
}
const barHTML = `<div class="bar-fill" style="width: ${Math.min(percentage, 100)}%; background-color: ${color};">${percentage >= 10 ? Math.round(percentage) + '%' : ''}</div>`;
document.querySelector('.affordability-bar').innerHTML = barHTML;
const guidanceText= currentLanguage === 'pt'
? `Sua prestação é ${Math.round(percentage)}% do seu rendimento. ${status}`
: `Your payment is ${Math.round(percentage)}% of your income. ${status}`;
document.getElementById('affordabilityText').textContent = guidanceText;
document.getElementById('affordabilityText').style.color = color;
document.getElementById('affordabilityIndicator').style.display = 'block';
}
// =============================
// TOGGLE FUNCTIONS
// =============================
function toggleAmortization() {
const content = document.getElementById('amortizationContent');
const button = event.target.closest('.toggle-btn');
content.style.display = content.style.display === 'none' ? 'block' : 'none';
button.classList.toggle('active');
}
function toggleComparison() {
const content = document.getElementById('comparisonContent');
const button = event.target.closest('.toggle-btn');
content.style.display = content.style.display === 'none' ? 'block' : 'none';
button.classList.toggle('active');
}
// =============================
// COMPARISON
// =============================
function captureComparison() {
if (!currentResults) {
alert(t('messages.executeFirst'));
return;
}
if (!previousResults) {
previousResults = { ...currentResults };
showNotification(t('messages.firstCapture'));
return;
}
const previousText = currentLanguage === 'pt' ? 'Situação Anterior' : 'Previous Situation';
const currentText = currentLanguage === 'pt' ? 'Situação Atual' : 'Current Situation';
const paymentText = currentLanguage === 'pt' ? 'Prestação Mensal' : 'Monthly Payment';
const fullPaymentText = currentLanguage === 'pt' ? 'Total a Pagar' : 'Total Payment';
const interestText = currentLanguage === 'pt' ? 'Total de Juros' : 'Total Interest';
const comparisonHTML = `
<div class="comparison-result">
<div class="comparison-card">
<h4>${previousText}</h4>
<div class="comparison-item">
<span>${paymentText}:</span>
<span class="comparison-value">${formatCurrency(previousResults.monthlyPayment)} CVE</span>
</div>
<div class="comparison-item">
<span>${fullPaymentText}:</span>
<span class="comparison-value">${formatCurrency(previousResults.totalPayment)} CVE</span>
</div>
<div class="comparison-item">
<span>${interestText}:</span>
<span class="comparison-value">${formatCurrency(previousResults.totalInterest)} CVE</span>
</div>
</div>
<div class="comparison-card">
<h4>${currentText}</h4>
<div class="comparison-item">
<span>${paymentText}:</span>
<span class="comparison-value">${formatCurrency(currentResults.monthlyPayment)} CVE
${getDifference(currentResults.monthlyPayment, previousResults.monthlyPayment)}
</span>
</div>
<div class="comparison-item">
<span>${fullPaymentText}:</span>
<span class="comparison-value">${formatCurrency(currentResults.totalPayment)} CVE
${getDifference(currentResults.totalPayment, previousResults.totalPayment)}
</span>
</div>
<div class="comparison-item">
<span>${interestText}:</span>
<span class="comparison-value">${formatCurrency(currentResults.totalInterest)} CVE
${getDifference(currentResults.totalInterest, previousResults.totalInterest)}
</span>
</div>
</div>
</div>
`;
document.getElementById('comparisonResults').innerHTML = comparisonHTML;
document.getElementById('comparisonResults').style.display = 'block';
previousResults = { ...currentResults };
showNotification(t('messages.comparisonDone'));
}
function getDifference(current, previous) {
const diff = current - previous;
if (diff === 0) return '';
const isPositive = diff > 0;
const className = isPositive ? 'difference-negative' : 'difference-positive';
const symbol = isPositive ? '+' : '';
return `<span class="comparison-difference ${className}">${symbol}${formatCurrency(diff)}</span>`;
}
// =============================
// COPY RESULTS
// =============================
function copyResults() {
if (!currentResults) return;
const headerText = currentLanguage === 'pt' ? 'SIMULADOR DE CRÉDITO - CABO VERDE' : 'CAPE VERDE CREDIT SIMULATOR';
const amountText = currentLanguage === 'pt' ? 'Montante' : 'Amount';
const periodText = currentLanguage === 'pt' ? 'Período' : 'Period';
const nominalText = currentLanguage === 'pt' ? 'Taxa Nominal' : 'Nominal Rate';
const paymentText = currentLanguage === 'pt' ? 'Prestação Mensal' : 'Monthly Payment';
const taegText = currentLanguage === 'pt' ? 'TAEG' : 'TAEG';
const totalPaymentText = currentLanguage === 'pt' ? 'Total a Pagar' : 'Total Payment';
const totalInterestText = currentLanguage === 'pt' ? 'Total de Juros' : 'Total Interest';
const methodText = currentLanguage === 'pt' ? 'Método de Cálculo' : 'Calculation Method';
const monthsText = currentLanguage === 'pt' ? 'meses' : 'months';
const text = `
${headerText}
${amountText}: ${formatCurrency(currentResults.principal)} CVE
${periodText}: ${currentResults.totalMonths} ${monthsText}
${nominalText}: ${currentResults.rate}%
${paymentText}: ${formatCurrency(currentResults.monthlyPayment)} CVE
${taegText}: ${currentResults.taeg.toFixed(2)}%
${totalPaymentText}: ${formatCurrency(currentResults.totalPayment)} CVE
${totalInterestText}: ${formatCurrency(currentResults.totalInterest)} CVE
${methodText}: ${currentResults.calculationMethod}
`;
navigator.clipboard.writeText(text).then(() => {
showNotification(t('messages.copySuccess'));
}).catch(() => {
alert(t('messages.copyError'));
});
}
// =============================
// NOTIFICATIONS