From e4d78286bfd0ed9937893080ce287b36ec53f7f5 Mon Sep 17 00:00:00 2001 From: MARIA PAULA LACERDA SANTOS FONSECA <0083470@ifmg.edu.br> Date: Mon, 15 Jun 2026 09:46:16 -0300 Subject: [PATCH 01/10] =?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 | 53 ++++++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/index.js b/index.js index 1291cf36..98ae2bf3 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,28 @@ 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) { + 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 desconhecia: ${peca.tipo}`); + } + return total; + } + let totalFatura = 0; let creditos = 0; let faturaStr = `Fatura ${fatura.cliente}\n`; @@ -10,41 +32,22 @@ function gerarFaturaStr (fatura, pecas) { for (let apre of fatura.apresentacoes) { 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 desconhecia: ${peca.tipo}`); - } - - // créditos para próximas contratações + + let total = calcularTotalApresentacao(apre, peca); + 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; } 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')); const faturaStr = gerarFaturaStr(faturas, pecas); -console.log(faturaStr); +console.log(faturaStr); \ No newline at end of file From c8cf479a8904ee8a2ac1cd292239428a335ad2b0 Mon Sep 17 00:00:00 2001 From: MARIA PAULA LACERDA SANTOS FONSECA <0083470@ifmg.edu.br> Date: Mon, 15 Jun 2026 10:02:49 -0300 Subject: [PATCH 02/10] Commit 2 - Replace Temp with Query --- index.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 98ae2bf3..8790ceda 100644 --- a/index.js +++ b/index.js @@ -1,9 +1,14 @@ const { readFileSync } = require('fs'); function gerarFaturaStr (fatura, pecas) { - function calcularTotalApresentacao(apre, peca) { + + function getPeca(apresentacao) { + return pecas[apresentacao.id]; + } + + function calcularTotalApresentacao(apre) { let total = 0; - switch (peca.tipo) { + switch (getPeca(apre).tipo) { case "tragedia": total = 40000; if (apre.audiencia > 30) { @@ -18,7 +23,7 @@ function gerarFaturaStr (fatura, pecas) { total += 300 * apre.audiencia; break; default: - throw new Error(`Peça desconhecia: ${peca.tipo}`); + throw new Error(`Peça desconhecida: ${getPeca(apre).tipo}`); } return total; } @@ -31,15 +36,13 @@ function gerarFaturaStr (fatura, pecas) { minimumFractionDigits: 2 }).format; for (let apre of fatura.apresentacoes) { - const peca = pecas[apre.id]; - - let total = calcularTotalApresentacao(apre, peca); + let 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; } faturaStr += `Valor total: ${formato(totalFatura/100)}\n`; From ae3efecba298d2f132e4e3fc63624ec092e6b81a Mon Sep 17 00:00:00 2001 From: MARIA PAULA LACERDA SANTOS FONSECA <0083470@ifmg.edu.br> Date: Mon, 15 Jun 2026 10:06:23 -0300 Subject: [PATCH 03/10] Commit 3 - Mais Extract Functions --- index.js | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 8790ceda..8d7137e9 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,6 @@ const { readFileSync } = require('fs'); function gerarFaturaStr (fatura, pecas) { - function getPeca(apresentacao) { return pecas[apresentacao.id]; } @@ -28,24 +27,33 @@ function gerarFaturaStr (fatura, pecas) { return total; } + function calcularCredito(apre) { + let creditos = 0; + 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) { let total = calcularTotalApresentacao(apre); - creditos += Math.max(apre.audiencia - 30, 0); - if (getPeca(apre).tipo === "comedia") - creditos += Math.floor(apre.audiencia / 5); + creditos += calcularCredito(apre); - 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 159a47e17cdb0c9182fcde7a94cdb1950544426f Mon Sep 17 00:00:00 2001 From: MARIA PAULA LACERDA SANTOS FONSECA <0083470@ifmg.edu.br> Date: Mon, 15 Jun 2026 10:08:19 -0300 Subject: [PATCH 04/10] =?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 | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index 8d7137e9..da0924fe 100644 --- a/index.js +++ b/index.js @@ -41,20 +41,28 @@ function gerarFaturaStr (fatura, pecas) { minimumFractionDigits: 2 }).format(valor / 100); } - let totalFatura = 0; - let creditos = 0; - let faturaStr = `Fatura ${fatura.cliente}\n`; - - for (let apre of fatura.apresentacoes) { - let total = calcularTotalApresentacao(apre); + function calcularTotalFatura() { + let total = 0; + for (let apre of fatura.apresentacoes) { + total += calcularTotalApresentacao(apre); + } + return total; + } - creditos += calcularCredito(apre); + function calcularTotalCreditos() { + let totalCreditos = 0; + for (let apre of fatura.apresentacoes) { + totalCreditos += calcularCredito(apre); + } + return totalCreditos; + } - 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(apre).nome}: ${formatarMoeda(calcularTotalApresentacao(apre))} (${apre.audiencia} assentos)\n`; } - faturaStr += `Valor total: ${formatarMoeda(totalFatura)}\n`; - faturaStr += `Créditos acumulados: ${creditos} \n`; + faturaStr += `Valor total: ${formatarMoeda(calcularTotalFatura())}\n`; + faturaStr += `Créditos acumulados: ${calcularTotalCreditos()} \n`; return faturaStr; } From 1cc5f264c98a6b89906501a3c9b018dc029b6bbf Mon Sep 17 00:00:00 2001 From: MARIA PAULA LACERDA SANTOS FONSECA <0083470@ifmg.edu.br> Date: Mon, 15 Jun 2026 10:10:59 -0300 Subject: [PATCH 05/10] Commit 5 - Move Function --- index.js | 115 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 58 insertions(+), 57 deletions(-) diff --git a/index.js b/index.js index da0924fe..2598c966 100644 --- a/index.js +++ b/index.js @@ -1,69 +1,70 @@ const { readFileSync } = require('fs'); -function gerarFaturaStr (fatura, pecas) { - function getPeca(apresentacao) { - return pecas[apresentacao.id]; - } +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 calcularTotalApresentacao(apre) { - let total = 0; - switch (getPeca(apre).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: ${getPeca(apre).tipo}`); +function calcularTotalApresentacao(pecas, apre) { + let total = 0; + switch (getPeca(pecas, apre).tipo) { + case "tragedia": + total = 40000; + if (apre.audiencia > 30) { + total += 1000 * (apre.audiencia - 30); } - return total; - } + 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: ${getPeca(pecas, apre).tipo}`); + } + return total; +} - function calcularCredito(apre) { - let creditos = 0; - creditos += Math.max(apre.audiencia - 30, 0); - if (getPeca(apre).tipo === "comedia") - creditos += Math.floor(apre.audiencia / 5); - return creditos; - } +function calcularCredito(pecas, apre) { + let creditos = 0; + 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) { + let total = 0; + for (let apre of apresentacoes) { + total += calcularTotalApresentacao(pecas, apre); + } + return total; +} - function calcularTotalFatura() { - let total = 0; - for (let apre of fatura.apresentacoes) { - total += calcularTotalApresentacao(apre); - } - return total; - } +function calcularTotalCreditos(pecas, apresentacoes) { + let totalCreditos = 0; + for (let apre of apresentacoes) { + totalCreditos += calcularCredito(pecas, apre); + } + return totalCreditos; +} - function calcularTotalCreditos() { - let totalCreditos = 0; - for (let apre of fatura.apresentacoes) { - totalCreditos += calcularCredito(apre); - } - return totalCreditos; - } - let faturaStr = `Fatura ${fatura.cliente}\n`; - for (let apre of fatura.apresentacoes) { - faturaStr += ` ${getPeca(apre).nome}: ${formatarMoeda(calcularTotalApresentacao(apre))} (${apre.audiencia} assentos)\n`; - } - faturaStr += `Valor total: ${formatarMoeda(calcularTotalFatura())}\n`; - faturaStr += `Créditos acumulados: ${calcularTotalCreditos()} \n`; - return faturaStr; +function gerarFaturaStr(fatura, pecas) { + 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(calcularTotalFatura(pecas, fatura.apresentacoes))}\n`; + faturaStr += `Créditos acumulados: ${calcularTotalCreditos(pecas, fatura.apresentacoes)} \n`; + return faturaStr; } const faturas = JSON.parse(readFileSync('./faturas.json')); From a21ef8d168b33b310538071d2c3ea8c2cfba565d Mon Sep 17 00:00:00 2001 From: MARIA PAULA LACERDA SANTOS FONSECA <0083470@ifmg.edu.br> Date: Mon, 15 Jun 2026 10:17:21 -0300 Subject: [PATCH 06/10] Commit 6 - Fatura em HTML --- index.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 2598c966..57d527fc 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,4 @@ const { readFileSync } = require('fs'); - function formatarMoeda(valor) { return new Intl.NumberFormat("pt-BR", { style: "currency", currency: "BRL", @@ -56,7 +55,6 @@ function calcularTotalCreditos(pecas, apresentacoes) { return totalCreditos; } - function gerarFaturaStr(fatura, pecas) { let faturaStr = `Fatura ${fatura.cliente}\n`; for (let apre of fatura.apresentacoes) { @@ -67,7 +65,22 @@ function gerarFaturaStr(fatura, pecas) { return faturaStr; } +// 2. Nova funcionalidade: Apresentação em formato HTML +function gerarFaturaHTML(fatura, pecas) { + let faturaHTML = `
Fatura ${fatura.cliente}
Valor total: ${formatarMoeda(calcularTotalFatura(pecas, fatura.apresentacoes))}
`; + faturaHTML += `Créditos acumulados: ${calcularTotalCreditos(pecas, fatura.apresentacoes)}
`; + return faturaHTML; +} + const faturas = JSON.parse(readFileSync('./faturas.json')); const pecas = JSON.parse(readFileSync('./pecas.json')); + const faturaStr = gerarFaturaStr(faturas, pecas); -console.log(faturaStr); \ No newline at end of file +console.log(faturaStr); + +const faturaHTML = gerarFaturaHTML(faturas, pecas); +console.log(faturaHTML); \ No newline at end of file From d52d59a12b5bd9aad76439a7c1367d08ba38f7b1 Mon Sep 17 00:00:00 2001 From: MARIA PAULA LACERDA SANTOS FONSECA <0083470@ifmg.edu.br> Date: Mon, 15 Jun 2026 10:19:41 -0300 Subject: [PATCH 07/10] Commit 7 - Classe ServicoCalculoFatura --- index.js | 97 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 49 insertions(+), 48 deletions(-) diff --git a/index.js b/index.js index 57d527fc..a31fed07 100644 --- a/index.js +++ b/index.js @@ -9,63 +9,66 @@ function getPeca(pecas, apre) { return pecas[apre.id]; } -function calcularTotalApresentacao(pecas, apre) { - let total = 0; - switch (getPeca(pecas, apre).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: ${getPeca(pecas, apre).tipo}`); +class ServicoCalculoFatura { + + calcularTotalApresentacao(pecas, apre) { + let total = 0; + switch (getPeca(pecas, apre).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: ${getPeca(pecas, apre).tipo}`); + } + return total; } - return total; -} -function calcularCredito(pecas, apre) { - let creditos = 0; - creditos += Math.max(apre.audiencia - 30, 0); - if (getPeca(pecas, apre).tipo === "comedia") - creditos += Math.floor(apre.audiencia / 5); - return creditos; -} + calcularCredito(pecas, apre) { + let creditos = 0; + creditos += Math.max(apre.audiencia - 30, 0); + if (getPeca(pecas, apre).tipo === "comedia") + creditos += Math.floor(apre.audiencia / 5); + return creditos; + } -function calcularTotalFatura(pecas, apresentacoes) { - let total = 0; - for (let apre of apresentacoes) { - total += calcularTotalApresentacao(pecas, apre); + calcularTotalFatura(pecas, apresentacoes) { + let total = 0; + for (let apre of apresentacoes) { + total += this.calcularTotalApresentacao(pecas, apre); + } + return total; } - return total; -} -function calcularTotalCreditos(pecas, apresentacoes) { - let totalCreditos = 0; - for (let apre of apresentacoes) { - totalCreditos += calcularCredito(pecas, apre); + calcularTotalCreditos(pecas, apresentacoes) { + let totalCreditos = 0; + for (let apre of apresentacoes) { + totalCreditos += this.calcularCredito(pecas, apre); + } + return totalCreditos; } - return totalCreditos; } -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))} (${apre.audiencia} assentos)\n`; + faturaStr += ` ${getPeca(pecas, apre).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; } -// 2. Nova funcionalidade: Apresentação em formato HTML +/* function gerarFaturaHTML(fatura, pecas) { let faturaHTML = `Fatura ${fatura.cliente}
Créditos acumulados: ${calcularTotalCreditos(pecas, fatura.apresentacoes)}
`; return faturaHTML; } - +*/ const faturas = JSON.parse(readFileSync('./faturas.json')); const pecas = JSON.parse(readFileSync('./pecas.json')); -const faturaStr = gerarFaturaStr(faturas, pecas); +const calc = new ServicoCalculoFatura(); +const faturaStr = gerarFaturaStr(faturas, pecas, calc); console.log(faturaStr); - -const faturaHTML = gerarFaturaHTML(faturas, pecas); -console.log(faturaHTML); \ No newline at end of file From d0ab174f1430994678681f058aca16c7d3a17367 Mon Sep 17 00:00:00 2001 From: MARIA PAULA LACERDA SANTOS FONSECA <0083470@ifmg.edu.br> Date: Mon, 15 Jun 2026 10:22:12 -0300 Subject: [PATCH 08/10] Commit 8 - Classe Repositorio --- index.js | 63 ++++++++++++++++++++++++++------------------------------ 1 file changed, 29 insertions(+), 34 deletions(-) diff --git a/index.js b/index.js index a31fed07..615f39d9 100644 --- a/index.js +++ b/index.js @@ -1,19 +1,28 @@ const { readFileSync } = require('fs'); +class Repositorio { + constructor() { + this.pecas = JSON.parse(readFileSync('./pecas.json')); + } + + getPeca(apre) { + return this.pecas[apre.id]; + } +} + 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]; -} - class ServicoCalculoFatura { + constructor(repo) { + this.repo = repo; + } - calcularTotalApresentacao(pecas, apre) { + calcularTotalApresentacao(apre) { let total = 0; - switch (getPeca(pecas, apre).tipo) { + switch (this.repo.getPeca(apre).tipo) { case "tragedia": total = 40000; if (apre.audiencia > 30) { @@ -28,60 +37,46 @@ class ServicoCalculoFatura { total += 300 * apre.audiencia; break; default: - throw new Error(`Peça desconhecida: ${getPeca(pecas, apre).tipo}`); + throw new Error(`Peça desconhecida: ${this.repo.getPeca(apre).tipo}`); } return total; } - calcularCredito(pecas, apre) { + calcularCredito(apre) { let creditos = 0; creditos += Math.max(apre.audiencia - 30, 0); - if (getPeca(pecas, apre).tipo === "comedia") + if (this.repo.getPeca(apre).tipo === "comedia") creditos += Math.floor(apre.audiencia / 5); return creditos; } - calcularTotalFatura(pecas, apresentacoes) { + calcularTotalFatura(apresentacoes) { let total = 0; for (let apre of apresentacoes) { - total += this.calcularTotalApresentacao(pecas, apre); + total += this.calcularTotalApresentacao(apre); } return total; } - calcularTotalCreditos(pecas, apresentacoes) { + calcularTotalCreditos(apresentacoes) { let totalCreditos = 0; for (let apre of apresentacoes) { - totalCreditos += this.calcularCredito(pecas, apre); + totalCreditos += this.calcularCredito(apre); } return totalCreditos; } } - -function gerarFaturaStr(fatura, pecas, calc) { +function gerarFaturaStr(fatura, calc) { let faturaStr = `Fatura ${fatura.cliente}\n`; for (let apre of fatura.apresentacoes) { - faturaStr += ` ${getPeca(pecas, apre).nome}: ${formatarMoeda(calc.calcularTotalApresentacao(pecas, apre))} (${apre.audiencia} assentos)\n`; + 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.fatura.apresentacoes || fatura.apresentacoes)} \n`; return faturaStr; } - -/* -function gerarFaturaHTML(fatura, pecas) { - let faturaHTML = `Fatura ${fatura.cliente}
Valor total: ${formatarMoeda(calcularTotalFatura(pecas, fatura.apresentacoes))}
`; - faturaHTML += `Créditos acumulados: ${calcularTotalCreditos(pecas, fatura.apresentacoes)}
`; - return faturaHTML; -} -*/ const faturas = JSON.parse(readFileSync('./faturas.json')); -const pecas = JSON.parse(readFileSync('./pecas.json')); -const calc = new ServicoCalculoFatura(); -const faturaStr = gerarFaturaStr(faturas, pecas, calc); -console.log(faturaStr); +const calc = new ServicoCalculoFatura(new Repositorio()); +const faturaStr = gerarFaturaStr(faturas, calc); +console.log(faturaStr); \ No newline at end of file From 912fcbb342e4259d2b6da1d189e111f3545b90df Mon Sep 17 00:00:00 2001 From: MARIA PAULA LACERDA SANTOS FONSECA <0083470@ifmg.edu.br> Date: Mon, 15 Jun 2026 10:25:43 -0300 Subject: [PATCH 09/10] Commit 9 - Criando Arquivos --- index.js | 79 +++----------------------------------------------------- 1 file changed, 3 insertions(+), 76 deletions(-) diff --git a/index.js b/index.js index 615f39d9..aa7f1270 100644 --- a/index.js +++ b/index.js @@ -1,82 +1,9 @@ const { readFileSync } = require('fs'); -class Repositorio { - constructor() { - this.pecas = JSON.parse(readFileSync('./pecas.json')); - } +var Repositorio = require("./repositorio.js"); +var ServicoCalculoFatura = require("./servico.js") ; +var gerarFaturaStr = require("./apresentacao.js"); - getPeca(apre) { - return this.pecas[apre.id]; - } -} - -function formatarMoeda(valor) { - return new Intl.NumberFormat("pt-BR", - { style: "currency", currency: "BRL", - minimumFractionDigits: 2 }).format(valor / 100); -} - -class ServicoCalculoFatura { - constructor(repo) { - this.repo = repo; - } - - calcularTotalApresentacao(apre) { - let total = 0; - switch (this.repo.getPeca(apre).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: ${this.repo.getPeca(apre).tipo}`); - } - return total; - } - - calcularCredito(apre) { - let creditos = 0; - creditos += Math.max(apre.audiencia - 30, 0); - if (this.repo.getPeca(apre).tipo === "comedia") - creditos += Math.floor(apre.audiencia / 5); - return creditos; - } - - calcularTotalFatura(apresentacoes) { - let total = 0; - for (let apre of apresentacoes) { - total += this.calcularTotalApresentacao(apre); - } - return total; - } - - calcularTotalCreditos(apresentacoes) { - let totalCreditos = 0; - for (let apre of apresentacoes) { - totalCreditos += this.calcularCredito(apre); - } - return totalCreditos; - } -} -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.fatura.apresentacoes || fatura.apresentacoes)} \n`; - return faturaStr; -} const faturas = JSON.parse(readFileSync('./faturas.json')); - const calc = new ServicoCalculoFatura(new Repositorio()); const faturaStr = gerarFaturaStr(faturas, calc); console.log(faturaStr); \ No newline at end of file From e98dee260ebdfec5b78a90713ca562e823913611 Mon Sep 17 00:00:00 2001 From: MARIA PAULA LACERDA SANTOS FONSECA <0083470@ifmg.edu.br> Date: Mon, 15 Jun 2026 10:27:05 -0300 Subject: [PATCH 10/10] Commit 9 - Criando Arquivos --- apresentacao.js | 11 +++++++++++ index.js | 3 ++- repositorio.js | 11 +++++++++++ servico.js | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ util.js | 7 +++++++ 5 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 apresentacao.js create mode 100644 repositorio.js create mode 100644 servico.js create mode 100644 util.js diff --git a/apresentacao.js b/apresentacao.js new file mode 100644 index 00000000..a7d638d2 --- /dev/null +++ b/apresentacao.js @@ -0,0 +1,11 @@ +const { formatarMoeda } = require('./util.js'); + +module.exports = 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; +}; \ No newline at end of file diff --git a/index.js b/index.js index aa7f1270..0a46609e 100644 --- a/index.js +++ b/index.js @@ -6,4 +6,5 @@ var gerarFaturaStr = require("./apresentacao.js"); const faturas = JSON.parse(readFileSync('./faturas.json')); const calc = new ServicoCalculoFatura(new Repositorio()); const faturaStr = gerarFaturaStr(faturas, calc); -console.log(faturaStr); \ No newline at end of file +console.log(faturaStr); +// \ No newline at end of file diff --git a/repositorio.js b/repositorio.js new file mode 100644 index 00000000..0cbfd74c --- /dev/null +++ b/repositorio.js @@ -0,0 +1,11 @@ +const { readFileSync } = require('fs'); + +module.exports = class Repositorio { + constructor() { + this.pecas = JSON.parse(readFileSync('./pecas.json')); + } + + getPeca(apre) { + return this.pecas[apre.id]; + } +}; \ No newline at end of file diff --git a/servico.js b/servico.js new file mode 100644 index 00000000..51344d69 --- /dev/null +++ b/servico.js @@ -0,0 +1,51 @@ +module.exports = class ServicoCalculoFatura { + constructor(repo) { + this.repo = repo; + } + + calcularTotalApresentacao(apre) { + let total = 0; + switch (this.repo.getPeca(apre).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: ${this.repo.getPeca(apre).tipo}`); + } + return total; + } + + calcularCredito(apre) { + let creditos = 0; + creditos += Math.max(apre.audiencia - 30, 0); + if (this.repo.getPeca(apre).tipo === "comedia") + creditos += Math.floor(apre.audiencia / 5); + return creditos; + } + + calcularTotalFatura(apresentacoes) { + let total = 0; + for (let apre of apresentacoes) { + total += this.calcularTotalApresentacao(apre); + } + return total; + } + + calcularTotalCreditos(apresentacoes) { + let totalCreditos = 0; + for (let apre of apresentacoes) { + totalCreditos += this.calcularCredito(apre); + } + return totalCreditos; + } +}; \ No newline at end of file diff --git a/util.js b/util.js new file mode 100644 index 00000000..0e6944d1 --- /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 }; \ No newline at end of file