From 1cffc96a2d5b6500249b0db8560964b3854a4f1b Mon Sep 17 00:00:00 2001 From: Pedro Augusto Torres Bento <127890688+pedroaugtb@users.noreply.github.com> Date: Sat, 14 Jun 2025 13:27:32 -0300 Subject: [PATCH 01/14] =?UTF-8?q?Commit=201=20-=20Extra=C3=A7=C3=A3o=20de?= =?UTF-8?q?=20Fun=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 70 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/index.js b/index.js index 1291cf36..3ff40237 100644 --- a/index.js +++ b/index.js @@ -1,18 +1,10 @@ -const { readFileSync } = require('fs'); - -function gerarFaturaStr (fatura, pecas) { - let totalFatura = 0; - let creditos = 0; - let faturaStr = `Fatura ${fatura.cliente}\n`; - const formato = new Intl.NumberFormat("pt-BR", - { style: "currency", currency: "BRL", - minimumFractionDigits: 2 }).format; - - for (let apre of fatura.apresentacoes) { - const peca = pecas[apre.id]; - let total = 0; - - switch (peca.tipo) { +const { readFileSync } = require("fs"); + +function gerarFaturaStr(fatura, pecas) { + + function calcularTotalApresentacao(apre, peca) { + let total = 0; + switch (peca.tipo) { case "tragedia": total = 40000; if (apre.audiencia > 30) { @@ -22,29 +14,39 @@ function gerarFaturaStr (fatura, pecas) { case "comedia": total = 30000; if (apre.audiencia > 20) { - total += 10000 + 500 * (apre.audiencia - 20); + total += 10000 + 500 * (apre.audiencia - 20); } total += 300 * apre.audiencia; break; default: - throw new Error(`Peça desconhecia: ${peca.tipo}`); - } - - // créditos para próximas contratações - creditos += Math.max(apre.audiencia - 30, 0); - if (peca.tipo === "comedia") - creditos += Math.floor(apre.audiencia / 5); - - // mais uma linha da fatura - faturaStr += ` ${peca.nome}: ${formato(total/100)} (${apre.audiencia} assentos)\n`; - totalFatura += total; + throw new Error(`Peça desconhecida: ${peca.tipo}`); } - faturaStr += `Valor total: ${formato(totalFatura/100)}\n`; - faturaStr += `Créditos acumulados: ${creditos} \n`; - return faturaStr; + return total; + } + + let totalFatura = 0; + let creditos = 0; + let faturaStr = `Fatura ${fatura.cliente}\n`; + const formato = new Intl.NumberFormat("pt-BR", + { style: "currency", currency: "BRL", minimumFractionDigits: 2 }).format; + + for (let apre of fatura.apresentacoes) { + const peca = pecas[apre.id]; + const total = calcularTotalApresentacao(apre, peca); + + creditos += Math.max(apre.audiencia - 30, 0); + if (peca.tipo === "comedia") + creditos += Math.floor(apre.audiencia / 5); + + faturaStr += ` ${peca.nome}: ${formato(total / 100)} (${apre.audiencia} assentos)\n`; + totalFatura += total; } -const faturas = JSON.parse(readFileSync('./faturas.json')); -const pecas = JSON.parse(readFileSync('./pecas.json')); -const faturaStr = gerarFaturaStr(faturas, pecas); -console.log(faturaStr); + faturaStr += `Valor total: ${formato(totalFatura / 100)}\n`; + faturaStr += `Créditos acumulados: ${creditos} \n`; + return faturaStr; +} + +const faturas = JSON.parse(readFileSync("./faturas.json")); +const pecas = JSON.parse(readFileSync("./pecas.json")); +console.log(gerarFaturaStr(faturas, pecas)); From 54e2b21f12a433d097026b6fcf5080bcf1b3ef42 Mon Sep 17 00:00:00 2001 From: Pedro Augusto Torres Bento <127890688+pedroaugtb@users.noreply.github.com> Date: Sat, 14 Jun 2025 13:27:56 -0300 Subject: [PATCH 02/14] Commit 2 - Replace Temp with Query --- index.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 3ff40237..9241135c 100644 --- a/index.js +++ b/index.js @@ -2,20 +2,22 @@ const { readFileSync } = require("fs"); function gerarFaturaStr(fatura, pecas) { - function calcularTotalApresentacao(apre, peca) { + function getPeca(apre) { + return pecas[apre.id]; + } + + function calcularTotalApresentacao(apre) { + const peca = getPeca(apre); let total = 0; switch (peca.tipo) { case "tragedia": total = 40000; - if (apre.audiencia > 30) { - total += 1000 * (apre.audiencia - 30); - } + if (apre.audiencia > 30) total += 1000 * (apre.audiencia - 30); break; case "comedia": total = 30000; - if (apre.audiencia > 20) { + if (apre.audiencia > 20) total += 10000 + 500 * (apre.audiencia - 20); - } total += 300 * apre.audiencia; break; default: @@ -31,14 +33,13 @@ function gerarFaturaStr(fatura, pecas) { { style: "currency", currency: "BRL", minimumFractionDigits: 2 }).format; for (let apre of fatura.apresentacoes) { - const peca = pecas[apre.id]; - const total = calcularTotalApresentacao(apre, peca); + const total = calcularTotalApresentacao(apre); creditos += Math.max(apre.audiencia - 30, 0); - if (peca.tipo === "comedia") + if (getPeca(apre).tipo === "comedia") creditos += Math.floor(apre.audiencia / 5); - faturaStr += ` ${peca.nome}: ${formato(total / 100)} (${apre.audiencia} assentos)\n`; + faturaStr += ` ${getPeca(apre).nome}: ${formato(total / 100)} (${apre.audiencia} assentos)\n`; totalFatura += total; } From e6b53805effca69e74a5ee9b076e10fc3b4007bc Mon Sep 17 00:00:00 2001 From: Pedro Augusto Torres Bento <127890688+pedroaugtb@users.noreply.github.com> Date: Sat, 14 Jun 2025 13:28:22 -0300 Subject: [PATCH 03/14] Commit 3 - Mais Extract Functions --- index.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 9241135c..91e17e46 100644 --- a/index.js +++ b/index.js @@ -26,24 +26,32 @@ function gerarFaturaStr(fatura, pecas) { return total; } + function calcularCredito(apre) { + let creditos = Math.max(apre.audiencia - 30, 0); + if (getPeca(apre).tipo === "comedia") + creditos += Math.floor(apre.audiencia / 5); + return creditos; + } + + function formatarMoeda(valor) { + return new Intl.NumberFormat("pt-BR", + { style: "currency", currency: "BRL", minimumFractionDigits: 2 }) + .format(valor / 100); + } + let totalFatura = 0; let creditos = 0; let faturaStr = `Fatura ${fatura.cliente}\n`; - const formato = new Intl.NumberFormat("pt-BR", - { style: "currency", currency: "BRL", minimumFractionDigits: 2 }).format; for (let apre of fatura.apresentacoes) { const total = calcularTotalApresentacao(apre); + creditos += calcularCredito(apre); - creditos += Math.max(apre.audiencia - 30, 0); - if (getPeca(apre).tipo === "comedia") - creditos += Math.floor(apre.audiencia / 5); - - faturaStr += ` ${getPeca(apre).nome}: ${formato(total / 100)} (${apre.audiencia} assentos)\n`; + faturaStr += ` ${getPeca(apre).nome}: ${formatarMoeda(total)} (${apre.audiencia} assentos)\n`; totalFatura += total; } - faturaStr += `Valor total: ${formato(totalFatura / 100)}\n`; + faturaStr += `Valor total: ${formatarMoeda(totalFatura)}\n`; faturaStr += `Créditos acumulados: ${creditos} \n`; return faturaStr; } From e7a1e9b0a2f496a72faa915c96f0c005ef360bd6 Mon Sep 17 00:00:00 2001 From: Pedro Augusto Torres Bento <127890688+pedroaugtb@users.noreply.github.com> Date: Sat, 14 Jun 2025 13:28:49 -0300 Subject: [PATCH 04/14] =?UTF-8?q?Commit=204=20-=20Separando=20Apresenta?= =?UTF-8?q?=C3=A7=C3=A3o=20dos=20C=C3=A1lculos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 92 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 48 insertions(+), 44 deletions(-) diff --git a/index.js b/index.js index 91e17e46..c90bb552 100644 --- a/index.js +++ b/index.js @@ -1,58 +1,62 @@ const { readFileSync } = require("fs"); -function gerarFaturaStr(fatura, pecas) { +function getPeca(pecas, apre) { + return pecas[apre.id]; +} - function getPeca(apre) { - return pecas[apre.id]; +function calcularTotalApresentacao(pecas, apre) { + const peca = getPeca(pecas, apre); + let total = 0; + switch (peca.tipo) { + case "tragedia": + total = 40000; + if (apre.audiencia > 30) total += 1000 * (apre.audiencia - 30); + break; + case "comedia": + total = 30000; + if (apre.audiencia > 20) + total += 10000 + 500 * (apre.audiencia - 20); + total += 300 * apre.audiencia; + break; + default: + throw new Error(`Peça desconhecida: ${peca.tipo}`); } + return total; +} - function calcularTotalApresentacao(apre) { - const peca = getPeca(apre); - let total = 0; - switch (peca.tipo) { - case "tragedia": - total = 40000; - if (apre.audiencia > 30) total += 1000 * (apre.audiencia - 30); - break; - case "comedia": - total = 30000; - if (apre.audiencia > 20) - total += 10000 + 500 * (apre.audiencia - 20); - total += 300 * apre.audiencia; - break; - default: - throw new Error(`Peça desconhecida: ${peca.tipo}`); - } - return total; - } +function calcularCredito(pecas, apre) { + let creditos = Math.max(apre.audiencia - 30, 0); + if (getPeca(pecas, apre).tipo === "comedia") + creditos += Math.floor(apre.audiencia / 5); + return creditos; +} - function calcularCredito(apre) { - let creditos = Math.max(apre.audiencia - 30, 0); - if (getPeca(apre).tipo === "comedia") - creditos += Math.floor(apre.audiencia / 5); - return creditos; - } +function formatarMoeda(valor) { + return new Intl.NumberFormat("pt-BR", + { style: "currency", currency: "BRL", minimumFractionDigits: 2 }) + .format(valor / 100); +} - function formatarMoeda(valor) { - return new Intl.NumberFormat("pt-BR", - { style: "currency", currency: "BRL", minimumFractionDigits: 2 }) - .format(valor / 100); - } +function calcularTotalFatura(pecas, apresentacoes) { + return apresentacoes + .reduce((tot, apre) => tot + calcularTotalApresentacao(pecas, apre), 0); +} - let totalFatura = 0; - let creditos = 0; - let faturaStr = `Fatura ${fatura.cliente}\n`; +function calcularTotalCreditos(pecas, apresentacoes) { + return apresentacoes + .reduce((tot, apre) => tot + calcularCredito(pecas, apre), 0); +} - for (let apre of fatura.apresentacoes) { - const total = calcularTotalApresentacao(apre); - creditos += calcularCredito(apre); +function gerarFaturaStr(fatura, pecas) { - faturaStr += ` ${getPeca(apre).nome}: ${formatarMoeda(total)} (${apre.audiencia} assentos)\n`; - totalFatura += total; + let faturaStr = `Fatura ${fatura.cliente}\n`; + for (let apre of fatura.apresentacoes) { + faturaStr += ` ${getPeca(pecas, apre).nome}: ` + + `${formatarMoeda(calcularTotalApresentacao(pecas, apre))} ` + + `(${apre.audiencia} assentos)\n`; } - - faturaStr += `Valor total: ${formatarMoeda(totalFatura)}\n`; - faturaStr += `Créditos acumulados: ${creditos} \n`; + faturaStr += `Valor total: ${formatarMoeda(calcularTotalFatura(pecas, fatura.apresentacoes))}\n`; + faturaStr += `Créditos acumulados: ${calcularTotalCreditos(pecas, fatura.apresentacoes)} \n`; return faturaStr; } From fbc4f40b65aeddf55ac1f5a0bed102fdb9320e3b Mon Sep 17 00:00:00 2001 From: Pedro Augusto Torres Bento <127890688+pedroaugtb@users.noreply.github.com> Date: Sat, 14 Jun 2025 13:29:13 -0300 Subject: [PATCH 05/14] Commit 5 - Move Function --- index.js | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/index.js b/index.js index c90bb552..4b9f7277 100644 --- a/index.js +++ b/index.js @@ -1,9 +1,22 @@ const { readFileSync } = require("fs"); +function formatarMoeda(valor) { + return new Intl.NumberFormat("pt-BR", + { style: "currency", currency: "BRL", minimumFractionDigits: 2 }) + .format(valor / 100); +} + function getPeca(pecas, apre) { return pecas[apre.id]; } +function calcularCredito(pecas, apre) { + let creditos = Math.max(apre.audiencia - 30, 0); + if (getPeca(pecas, apre).tipo === "comedia") + creditos += Math.floor(apre.audiencia / 5); + return creditos; +} + function calcularTotalApresentacao(pecas, apre) { const peca = getPeca(pecas, apre); let total = 0; @@ -24,19 +37,6 @@ function calcularTotalApresentacao(pecas, apre) { return total; } -function calcularCredito(pecas, apre) { - let creditos = Math.max(apre.audiencia - 30, 0); - if (getPeca(pecas, apre).tipo === "comedia") - creditos += Math.floor(apre.audiencia / 5); - return creditos; -} - -function formatarMoeda(valor) { - return new Intl.NumberFormat("pt-BR", - { style: "currency", currency: "BRL", minimumFractionDigits: 2 }) - .format(valor / 100); -} - function calcularTotalFatura(pecas, apresentacoes) { return apresentacoes .reduce((tot, apre) => tot + calcularTotalApresentacao(pecas, apre), 0); @@ -48,7 +48,6 @@ function calcularTotalCreditos(pecas, apresentacoes) { } function gerarFaturaStr(fatura, pecas) { - let faturaStr = `Fatura ${fatura.cliente}\n`; for (let apre of fatura.apresentacoes) { faturaStr += ` ${getPeca(pecas, apre).nome}: ` From c4ad39005467ad35342e4114c36654b148a9a4ab Mon Sep 17 00:00:00 2001 From: Pedro Augusto Torres Bento <127890688+pedroaugtb@users.noreply.github.com> Date: Sat, 14 Jun 2025 13:29:42 -0300 Subject: [PATCH 06/14] Commit 6 - Fatura em HTML --- index.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/index.js b/index.js index 4b9f7277..0663ceaf 100644 --- a/index.js +++ b/index.js @@ -59,6 +59,22 @@ function gerarFaturaStr(fatura, pecas) { return faturaStr; } +function gerarFaturaHTML(fatura, pecas) { + let html = `\n

Fatura ${fatura.cliente}

\n\n

Valor total: ` + + `${formatarMoeda(calcularTotalFatura(pecas, fatura.apresentacoes))}

\n`; + html += `

Créditos acumulados: ` + + `${calcularTotalCreditos(pecas, fatura.apresentacoes)}

\n`; + return html; +} + const faturas = JSON.parse(readFileSync("./faturas.json")); const pecas = JSON.parse(readFileSync("./pecas.json")); + console.log(gerarFaturaStr(faturas, pecas)); +console.log(gerarFaturaHTML(faturas, pecas)); From 14e05d6783adec562839f2cb887f1cbd02071132 Mon Sep 17 00:00:00 2001 From: Pedro Augusto Torres Bento <127890688+pedroaugtb@users.noreply.github.com> Date: Sat, 14 Jun 2025 13:31:08 -0300 Subject: [PATCH 07/14] Create servico.js --- servico.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 servico.js diff --git a/servico.js b/servico.js new file mode 100644 index 00000000..dbdb0ee1 --- /dev/null +++ b/servico.js @@ -0,0 +1,41 @@ +class ServicoCalculoFatura { + + calcularTotalApresentacao(pecas, apre) { + const peca = pecas[apre.id]; + let total = 0; + switch (peca.tipo) { + case "tragedia": + total = 40000; + if (apre.audiencia > 30) total += 1000 * (apre.audiencia - 30); + break; + case "comedia": + total = 30000; + if (apre.audiencia > 20) + total += 10000 + 500 * (apre.audiencia - 20); + total += 300 * apre.audiencia; + break; + default: + throw new Error(`Peça desconhecida: ${peca.tipo}`); + } + return total; + } + + calcularCredito(pecas, apre) { + let creditos = Math.max(apre.audiencia - 30, 0); + if (pecas[apre.id].tipo === "comedia") + creditos += Math.floor(apre.audiencia / 5); + return creditos; + } + + calcularTotalFatura(pecas, apresentacoes) { + return apresentacoes + .reduce((tot, apre) => tot + this.calcularTotalApresentacao(pecas, apre), 0); + } + + calcularTotalCreditos(pecas, apresentacoes) { + return apresentacoes + .reduce((tot, apre) => tot + this.calcularCredito(pecas, apre), 0); + } +} + +module.exports = ServicoCalculoFatura; From d9e2536deede504d55ca187619f35c8975396ec2 Mon Sep 17 00:00:00 2001 From: Pedro Augusto Torres Bento <127890688+pedroaugtb@users.noreply.github.com> Date: Sat, 14 Jun 2025 13:33:47 -0300 Subject: [PATCH 08/14] Commit 7 - Classe ServicoCalculoFatura --- index.js | 70 +++++++------------------------------------------------- 1 file changed, 8 insertions(+), 62 deletions(-) diff --git a/index.js b/index.js index 0663ceaf..c6110569 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,5 @@ const { readFileSync } = require("fs"); +const ServicoCalculoFatura = require("./servico"); function formatarMoeda(valor) { return new Intl.NumberFormat("pt-BR", @@ -6,75 +7,20 @@ function formatarMoeda(valor) { .format(valor / 100); } -function getPeca(pecas, apre) { - return pecas[apre.id]; -} - -function calcularCredito(pecas, apre) { - let creditos = Math.max(apre.audiencia - 30, 0); - if (getPeca(pecas, apre).tipo === "comedia") - creditos += Math.floor(apre.audiencia / 5); - return creditos; -} - -function calcularTotalApresentacao(pecas, apre) { - const peca = getPeca(pecas, apre); - let total = 0; - switch (peca.tipo) { - case "tragedia": - total = 40000; - if (apre.audiencia > 30) total += 1000 * (apre.audiencia - 30); - break; - case "comedia": - total = 30000; - if (apre.audiencia > 20) - total += 10000 + 500 * (apre.audiencia - 20); - total += 300 * apre.audiencia; - break; - default: - throw new Error(`Peça desconhecida: ${peca.tipo}`); - } - return total; -} - -function calcularTotalFatura(pecas, apresentacoes) { - return apresentacoes - .reduce((tot, apre) => tot + calcularTotalApresentacao(pecas, apre), 0); -} - -function calcularTotalCreditos(pecas, apresentacoes) { - return apresentacoes - .reduce((tot, apre) => tot + calcularCredito(pecas, apre), 0); -} - -function gerarFaturaStr(fatura, pecas) { +function gerarFaturaStr(fatura, pecas, calc) { let faturaStr = `Fatura ${fatura.cliente}\n`; for (let apre of fatura.apresentacoes) { - faturaStr += ` ${getPeca(pecas, apre).nome}: ` - + `${formatarMoeda(calcularTotalApresentacao(pecas, apre))} ` + faturaStr += ` ${pecas[apre.id].nome}: ` + + `${formatarMoeda(calc.calcularTotalApresentacao(pecas, apre))} ` + `(${apre.audiencia} assentos)\n`; } - faturaStr += `Valor total: ${formatarMoeda(calcularTotalFatura(pecas, fatura.apresentacoes))}\n`; - faturaStr += `Créditos acumulados: ${calcularTotalCreditos(pecas, fatura.apresentacoes)} \n`; + faturaStr += `Valor total: ${formatarMoeda(calc.calcularTotalFatura(pecas, fatura.apresentacoes))}\n`; + faturaStr += `Créditos acumulados: ${calc.calcularTotalCreditos(pecas, fatura.apresentacoes)} \n`; return faturaStr; } -function gerarFaturaHTML(fatura, pecas) { - let html = `\n

Fatura ${fatura.cliente}

\n\n

Valor total: ` - + `${formatarMoeda(calcularTotalFatura(pecas, fatura.apresentacoes))}

\n`; - html += `

Créditos acumulados: ` - + `${calcularTotalCreditos(pecas, fatura.apresentacoes)}

\n`; - return html; -} - const faturas = JSON.parse(readFileSync("./faturas.json")); const pecas = JSON.parse(readFileSync("./pecas.json")); +const calc = new ServicoCalculoFatura(); -console.log(gerarFaturaStr(faturas, pecas)); -console.log(gerarFaturaHTML(faturas, pecas)); +console.log(gerarFaturaStr(faturas, pecas, calc)); From f5c59a96a9dfe7893f397a55ee109bfda2b5453b Mon Sep 17 00:00:00 2001 From: Pedro Augusto Torres Bento <127890688+pedroaugtb@users.noreply.github.com> Date: Sat, 14 Jun 2025 13:34:18 -0300 Subject: [PATCH 09/14] Create repositorio.js --- repositorio.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 repositorio.js diff --git a/repositorio.js b/repositorio.js new file mode 100644 index 00000000..5896be62 --- /dev/null +++ b/repositorio.js @@ -0,0 +1,13 @@ +const { readFileSync } = require("fs"); + +class Repositorio { + constructor() { + this.pecas = JSON.parse(readFileSync("./pecas.json")); + } + + getPeca(apre) { + return this.pecas[apre.id]; + } +} + +module.exports = Repositorio; From 3ecbbc5063ed8af783d4a77cfd35bd456dd63f0e Mon Sep 17 00:00:00 2001 From: Pedro Augusto Torres Bento <127890688+pedroaugtb@users.noreply.github.com> Date: Sat, 14 Jun 2025 13:34:46 -0300 Subject: [PATCH 10/14] Commit 8 - Classe Repositorio --- servico.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/servico.js b/servico.js index dbdb0ee1..cb448cda 100644 --- a/servico.js +++ b/servico.js @@ -1,7 +1,10 @@ class ServicoCalculoFatura { + constructor(repo) { + this.repo = repo; + } - calcularTotalApresentacao(pecas, apre) { - const peca = pecas[apre.id]; + calcularTotalApresentacao(apre) { + const peca = this.repo.getPeca(apre); let total = 0; switch (peca.tipo) { case "tragedia": @@ -20,21 +23,21 @@ class ServicoCalculoFatura { return total; } - calcularCredito(pecas, apre) { + calcularCredito(apre) { let creditos = Math.max(apre.audiencia - 30, 0); - if (pecas[apre.id].tipo === "comedia") + if (this.repo.getPeca(apre).tipo === "comedia") creditos += Math.floor(apre.audiencia / 5); return creditos; } - calcularTotalFatura(pecas, apresentacoes) { + calcularTotalFatura(apresentacoes) { return apresentacoes - .reduce((tot, apre) => tot + this.calcularTotalApresentacao(pecas, apre), 0); + .reduce((tot, apre) => tot + this.calcularTotalApresentacao(apre), 0); } - calcularTotalCreditos(pecas, apresentacoes) { + calcularTotalCreditos(apresentacoes) { return apresentacoes - .reduce((tot, apre) => tot + this.calcularCredito(pecas, apre), 0); + .reduce((tot, apre) => tot + this.calcularCredito(apre), 0); } } From 9d4897367cf1e5cc3c92b54163fd92a20106a6aa Mon Sep 17 00:00:00 2001 From: Pedro Augusto Torres Bento <127890688+pedroaugtb@users.noreply.github.com> Date: Sat, 14 Jun 2025 13:35:14 -0300 Subject: [PATCH 11/14] Commit 8 - Classe Repositorio --- index.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index c6110569..39eee127 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,5 @@ const { readFileSync } = require("fs"); +const Repositorio = require("./repositorio"); const ServicoCalculoFatura = require("./servico"); function formatarMoeda(valor) { @@ -7,20 +8,19 @@ function formatarMoeda(valor) { .format(valor / 100); } -function gerarFaturaStr(fatura, pecas, calc) { +function gerarFaturaStr(fatura, calc) { let faturaStr = `Fatura ${fatura.cliente}\n`; for (let apre of fatura.apresentacoes) { - faturaStr += ` ${pecas[apre.id].nome}: ` - + `${formatarMoeda(calc.calcularTotalApresentacao(pecas, apre))} ` + faturaStr += ` ${calc.repo.getPeca(apre).nome}: ` + + `${formatarMoeda(calc.calcularTotalApresentacao(apre))} ` + `(${apre.audiencia} assentos)\n`; } - faturaStr += `Valor total: ${formatarMoeda(calc.calcularTotalFatura(pecas, fatura.apresentacoes))}\n`; - faturaStr += `Créditos acumulados: ${calc.calcularTotalCreditos(pecas, fatura.apresentacoes)} \n`; + faturaStr += `Valor total: ${formatarMoeda(calc.calcularTotalFatura(fatura.apresentacoes))}\n`; + faturaStr += `Créditos acumulados: ${calc.calcularTotalCreditos(fatura.apresentacoes)} \n`; return faturaStr; } const faturas = JSON.parse(readFileSync("./faturas.json")); -const pecas = JSON.parse(readFileSync("./pecas.json")); -const calc = new ServicoCalculoFatura(); +const calc = new ServicoCalculoFatura(new Repositorio()); -console.log(gerarFaturaStr(faturas, pecas, calc)); +console.log(gerarFaturaStr(faturas, calc)); From 8b1852c7dd46dabfca68315f90e18e6ae4b8f760 Mon Sep 17 00:00:00 2001 From: Pedro Augusto Torres Bento <127890688+pedroaugtb@users.noreply.github.com> Date: Sat, 14 Jun 2025 13:35:47 -0300 Subject: [PATCH 12/14] Commit 9 - Criando Arquivos --- util.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 util.js diff --git a/util.js b/util.js new file mode 100644 index 00000000..4aaed261 --- /dev/null +++ b/util.js @@ -0,0 +1,7 @@ +function formatarMoeda(valor) { + return new Intl.NumberFormat("pt-BR", + { style: "currency", currency: "BRL", minimumFractionDigits: 2 }) + .format(valor / 100); +} + +module.exports = { formatarMoeda }; From daf1b3fc517358c410ddca679946ca09f2f863ff Mon Sep 17 00:00:00 2001 From: Pedro Augusto Torres Bento <127890688+pedroaugtb@users.noreply.github.com> Date: Sat, 14 Jun 2025 13:36:18 -0300 Subject: [PATCH 13/14] Commit 9 - Criando Arquivos --- apresentacao.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 apresentacao.js diff --git a/apresentacao.js b/apresentacao.js new file mode 100644 index 00000000..22e0c987 --- /dev/null +++ b/apresentacao.js @@ -0,0 +1,15 @@ +const { formatarMoeda } = require("./util"); + +function gerarFaturaStr(fatura, calc) { + let faturaStr = `Fatura ${fatura.cliente}\n`; + for (let apre of fatura.apresentacoes) { + faturaStr += ` ${calc.repo.getPeca(apre).nome}: ` + + `${formatarMoeda(calc.calcularTotalApresentacao(apre))} ` + + `(${apre.audiencia} assentos)\n`; + } + faturaStr += `Valor total: ${formatarMoeda(calc.calcularTotalFatura(fatura.apresentacoes))}\n`; + faturaStr += `Créditos acumulados: ${calc.calcularTotalCreditos(fatura.apresentacoes)} \n`; + return faturaStr; +} + +module.exports = gerarFaturaStr; From 3c5c762721be04731528fe4c3238745c6283e9f4 Mon Sep 17 00:00:00 2001 From: Pedro Augusto Torres Bento <127890688+pedroaugtb@users.noreply.github.com> Date: Sat, 14 Jun 2025 13:36:50 -0300 Subject: [PATCH 14/14] Commit 9 - Criando Arquivos --- index.js | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/index.js b/index.js index 39eee127..ae176778 100644 --- a/index.js +++ b/index.js @@ -1,24 +1,8 @@ const { readFileSync } = require("fs"); + const Repositorio = require("./repositorio"); const ServicoCalculoFatura = require("./servico"); - -function formatarMoeda(valor) { - return new Intl.NumberFormat("pt-BR", - { style: "currency", currency: "BRL", minimumFractionDigits: 2 }) - .format(valor / 100); -} - -function gerarFaturaStr(fatura, calc) { - let faturaStr = `Fatura ${fatura.cliente}\n`; - for (let apre of fatura.apresentacoes) { - faturaStr += ` ${calc.repo.getPeca(apre).nome}: ` - + `${formatarMoeda(calc.calcularTotalApresentacao(apre))} ` - + `(${apre.audiencia} assentos)\n`; - } - faturaStr += `Valor total: ${formatarMoeda(calc.calcularTotalFatura(fatura.apresentacoes))}\n`; - faturaStr += `Créditos acumulados: ${calc.calcularTotalCreditos(fatura.apresentacoes)} \n`; - return faturaStr; -} +const gerarFaturaStr = require("./apresentacao"); const faturas = JSON.parse(readFileSync("./faturas.json")); const calc = new ServicoCalculoFatura(new Repositorio());