Skip to content

Commit

Permalink
added functionality to add new orcamento
Browse files Browse the repository at this point in the history
  • Loading branch information
MarchisLost committed Jun 21, 2020
1 parent a79a117 commit 9e745eb
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 9 deletions.
14 changes: 12 additions & 2 deletions src/db/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const getProblemas = async (id) => {

const getListaTarefas = async (id) => {
let data = await db.query(
"select tarefa.descricao from tarefa,entrada,checklist where entrada.id_checklist = checklist.id_checklist and tarefa.id_checklist = checklist.id_checklist and entrada.cliente = $1", [id]
"select tarefa.descricao from tarefa,entrada,checklist where entrada.id_checklist = checklist.id_checklist and tarefa.id_checklist = checklist.id_checklist and entrada.cliente = $1", [id]
)
.catch(e => console.error(e.stack))

Expand Down Expand Up @@ -306,6 +306,15 @@ const aprovarOrcamentoIdVeiculo = async (date, time, idCliente, idVeiculo) => {
return data.rows ? data.rows : null
}

//Adicioanr orcamento
const adicionarOrcamento = async (valor, idCliente, idVeiculo) => {
let data = await db.query(
"INSERT INTO orcamento (id_orcamento, valor, descricao, id_cliente, id_veiculo, aprovacao) VALUES (default, $1, 'Os problemas que nos comunicou à chegada estão a ser resolvidos neste momento', $2, $3, '0')", [valor, idCliente, idVeiculo]
)
.catch(e => console.error(e.stack))

return data.rows ? data.rows : null
}
// ---------------------------------------------------------------------------------------------
// Admin
// ---------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -383,5 +392,6 @@ module.exports = {
getClientes,
getChecklists,
addEntrada,
addCliente
addCliente,
adicionarOrcamento
}
28 changes: 23 additions & 5 deletions src/routers/roleRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ const saltRounds = 10

const { getWorkviewInfo, getTarefasCompletas, getdetalhesOrcamento,
getProblemas, getListaTarefas, getFuncionarioByUsername,
getClientByLink, getVeiculoById, getNomeCliente, aproletOrcamento,
getClientByLink, getVeiculoById, getNomeCliente, aprovarOrcamento,
getVeiculosByFuncionario, getTarefasVeiculo, maxIDVeiculo,
getVeiculo, getIdChecklistByEntrada, adicionarTarefa, maxIDTarefa, getListaMecanicos,
getTarefasIncompletas, markTaskAsCompleted, getListaVeiculos, adicionarVeiculo, adicionarFuncionario, getFuncionario, editFuncionario, getLogin, getClientIdByEmail, aproletOrcamentoIdVeiculo, getVeiculoIdByPlate, newChecklist, getClientes, getChecklists, addEntrada, addCliente } = require('../db/templates')
getTarefasIncompletas, markTaskAsCompleted, getListaVeiculos, adicionarVeiculo, adicionarFuncionario, getFuncionario, editFuncionario, getLogin, getClientIdByEmail, aprovarOrcamentoIdVeiculo, getVeiculoIdByPlate, newChecklist, getClientes, getChecklists, addEntrada, addCliente, adicionarOrcamento} = require('../db/templates')

//--------------------------------------------------------------------
// Mecanico ----------------------------------------------------------
Expand Down Expand Up @@ -403,7 +403,7 @@ router.get('/getAllTarefas', async (req, res) => {
})

//Gets info about cars without a mecanic and sends it to responsavel.hbs
router.post('/aproletOrcamentos', async (req, res) => {
router.post('/aprovarOrcamentos', async (req, res) => {

const clientEmail = req.body.email
const matriculaCarro = req.body.matricula
Expand Down Expand Up @@ -441,7 +441,25 @@ router.post('/aproletOrcamentos', async (req, res) => {
let idVeiculo = await getVeiculoIdByPlate(matriculaCarro)
idVeiculo = idVeiculo.id_veiculo

const submitDetails = await aproletOrcamentoIdVeiculo(today, currentTime, idCliente, idVeiculo)
const submitDetails = await aprovarOrcamentoIdVeiculo(today, currentTime, idCliente, idVeiculo)

res.redirect('/responsavel/' + req.body.nomeAdmin)
})

//adds new value to orcamento
router.post('/adicionarOrcamentos', async (req, res) => {

const clientEmail = req.body.email2
const matriculaCarro = req.body.matricula2
const valor = req.body.preco

//Get client and veiculo id
let idCliente = await getClientIdByEmail(clientEmail)
idCliente = idCliente.id_cliente
let idVeiculo = await getVeiculoIdByPlate(matriculaCarro)
idVeiculo = idVeiculo.id_veiculo

const submitDetails = await adicionarOrcamento(valor, idCliente, idVeiculo)

res.redirect('/responsavel/' + req.body.nomeAdmin)
})
Expand Down Expand Up @@ -632,7 +650,7 @@ router.post('/orcamentoAprovado/:link', async (req, res) => {
let idCliente = await getClientByLink(urlCode)
idCliente = idCliente[0].cliente

const submitDetails = await aproletOrcamento(today, currentTime, idCliente)
const submitDetails = await aprovarOrcamento(today, currentTime, idCliente)

res.render('aproveSuccess')
})
Expand Down
78 changes: 76 additions & 2 deletions views/responsavel.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<p>{{user}}</p>
<li>
<a class="dropdown-toggle" data-toggle="modal" href="#exampleModal">Aceitar Orçamentos</a>
<a class="dropdown-toggle" data-toggle="modal" href="#exampleModal2">Adicionar Orçamentos</a>
<a href="/dashboard">Dashboard</a>
<a href="/rececionista/{{user}}">Rececionista</a>
<a href="/workview/{{user}}">Mecanico</a>
Expand Down Expand Up @@ -142,6 +143,50 @@
</div>
</div>

<!-- Modal Adicionar orçamentos -->
<div class="modal fade" id="exampleModal2" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel2"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel2">Adicionar Orçamento</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<form id="form2" method="post" action="http://localhost:3000/adicionarOrcamentos">
<div class="form-group">
<label for="exampleInputEmail2">Email Cliente</label>
<select class="custom-select" id="email2" name="email2" required>
<option value="">Escolha...</option>
</select>
</div>

<div class="form-group">
<label for="exampleInputEmail2">Matrícula Veículo</label>
<select class="custom-select" id="matricula2" name="matricula2" required>
<option value="">Escolha...</option>
</select>
</div>
<div class="form-group">
<label for="exampleInputEmail2">Valor orçamento</label>
<input type="text" class="form-control" name="preco" id="preco" aria-describedby="emailHelp" value="">
</div>
<div class="form-group" hidden>
<label for="exampleInputEmail1">nomeAdmin</label>
<input type="text" class="form-control" name="nomeAdmin" id="nomeAdmin" aria-describedby="emailHelp" value="{{user}}" hidden>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" id="dismissalButton" class="btn btn-warning" data-dismiss="modal">Close</button>
<button id="botaoAdicionarOrcamento" type="submit" form="form2" class="btn btn-primary">Adicionar</button>
</div>
</div>
</div>
</div>

{{!-- Receive data for later --}}
<p id="matriculasEspera" hidden>{{matriculasEspera}}</p>
<p id="matriculasTrabalho" hidden>{{matriculasTrabalho}}</p>
Expand Down Expand Up @@ -394,6 +439,7 @@
let select = document.getElementById("email"), arr = jsonData1
//Add to aceitar
for (let i = 0; i < arr.length; i++) {
let option = document.createElement("OPTION"),
txt = document.createTextNode(arr[i].email);
Expand All @@ -402,9 +448,21 @@
option.setAttribute("value", arr[i].email);
select.insertBefore(option, select.lastChild);
}
//Add to adicionar
let select2 = document.getElementById("email2"), arr2 = jsonData1
for (let i = 0; i < arr2.length; i++) {
let option2 = document.createElement("OPTION"),
txt2 = document.createTextNode(arr2[i].email);
option2.appendChild(txt2);
option2.setAttribute("id", "botaoAddClient2" + [i + 1])
option2.setAttribute("value", arr2[i].email);
select2.insertBefore(option2, select2.lastChild);
}
}
).catch((e) => {
console.log('Couldnt get data from server')
console.log('Couldnt get data from server - cliente')
})
//Fetch veiculos to show on the modal
Expand All @@ -414,17 +472,33 @@
jsonData2 = await result.json();
//console.log(jsonData2)
//Add to aceitar
let select = document.getElementById("matricula"), arr = jsonData2
for (let i = 0; i < arr.length; i++) {
let option = document.createElement("OPTION"),
txt = document.createTextNode(arr[i].matricula);
option.appendChild(txt);
option.setAttribute("id", "botaoAddVeiculo" + [i + 1])
option.setAttribute("value", arr[i].matricula);
select.insertBefore(option, select.lastChild);
}
//Add to adicionar
let select2 = document.getElementById("matricula2"), arr2 = jsonData2
for (let i = 0; i < arr2.length; i++) {
let option2 = document.createElement("OPTION"),
txt2 = document.createTextNode(arr2[i].matricula);
option2.appendChild(txt2);
option2.setAttribute("id", "botaoAddVeiculo2" + [i + 1])
option2.setAttribute("value", arr2[i].matricula);
select2.insertBefore(option2, select2.lastChild);
}
}
)
).catch((e) => {
console.log('Couldnt get data from server - veiculo')
})
</script>

</html>

0 comments on commit 9e745eb

Please sign in to comment.