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}