mejoras tablas y enpoint update compras
This commit is contained in:
@@ -5,7 +5,12 @@
|
|||||||
<i class="fa fa-plus fa-2x" @click="toggleDropDown"> </i>
|
<i class="fa fa-plus fa-2x" @click="toggleDropDown"> </i>
|
||||||
</a>
|
</a>
|
||||||
<span class="dropdown-menu" :class="{ show: isOpen }">
|
<span class="dropdown-menu" :class="{ show: isOpen }">
|
||||||
<div class="color_fondo p-3">
|
<card>
|
||||||
|
|
||||||
|
<template slot="header">
|
||||||
|
<img v-if="isUpdate === false" src="img//card-primary.png" alt="" />
|
||||||
|
<img v-else src="img//card-info.png" alt="" />
|
||||||
|
</template>
|
||||||
<base-input
|
<base-input
|
||||||
label="Fecha"
|
label="Fecha"
|
||||||
v-model="newCompra.fecha"
|
v-model="newCompra.fecha"
|
||||||
@@ -36,26 +41,36 @@
|
|||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
</base-input>
|
</base-input>
|
||||||
<base-button
|
<base-button v-if="isUpdate === false"
|
||||||
type="primary"
|
type="primary"
|
||||||
class="mb-3 col-12"
|
class="mb-3 col-12"
|
||||||
size="lg"
|
size="lg"
|
||||||
@click="saveCompra()"
|
@click="saveCompra()"
|
||||||
>Guardar</base-button
|
>Guardar</base-button>
|
||||||
>
|
|
||||||
</div>
|
<base-button v-else
|
||||||
|
type="info"
|
||||||
|
class="mb-3 col-12"
|
||||||
|
size="lg"
|
||||||
|
@click="updateCompra(newCompra._id)"
|
||||||
|
>Actualizar</base-button>
|
||||||
|
|
||||||
|
|
||||||
|
</card>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import Card from '../Cards/Card.vue';
|
||||||
export default {
|
export default {
|
||||||
|
components: { Card },
|
||||||
name: "Fcompras",
|
name: "Fcompras",
|
||||||
props: ["categorias", "metodos_pago", "newCompra", "saveCompra"],
|
props: ["categorias", "metodos_pago", "newCompra", "saveCompra","isUpdate","updateCompra","openForm"],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
isOpen: false,
|
isOpen: this.openForm
|
||||||
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -142,7 +142,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
|
|
||||||
this.initScrollbar();
|
this.initScrollbar();
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
14
APP/layouts/error.vue
Normal file
14
APP/layouts/error.vue
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<h1 v-if="error.statusCode === 404">Página no encontrada</h1>
|
||||||
|
<h1 v-else> !!Ha ocurrido un error!!</h1>
|
||||||
|
<NuxtLink to="/"> <i class="fas fa-home fa-2x"></i></NuxtLink>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
props: ['error'],
|
||||||
|
layout: 'error' // you can set a custom layout for the error page
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -7,4 +7,6 @@ export default function({ store, redirect }) {
|
|||||||
if (!store.state.auth) {
|
if (!store.state.auth) {
|
||||||
return redirect("/login");
|
return redirect("/login");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
layout: 'auth'
|
layout: 'error'
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
|
|||||||
@@ -14,20 +14,40 @@
|
|||||||
)
|
)
|
||||||
"
|
"
|
||||||
border
|
border
|
||||||
height="900"
|
empty-text="No hay compras realizadas"
|
||||||
|
stripe
|
||||||
|
:summary-method="getSummaries"
|
||||||
|
show-summary
|
||||||
|
style="width: 100%"
|
||||||
>
|
>
|
||||||
<el-TableColumn prop="fecha" label="Fecha" sortable> </el-TableColumn>
|
<el-TableColumn prop="fecha" label="Fecha" sortable></el-TableColumn>
|
||||||
<el-TableColumn prop="detalle" label="Detalle" sortable>
|
<el-TableColumn prop="detalle" label="Detalle" sortable>
|
||||||
</el-TableColumn>
|
</el-TableColumn>
|
||||||
<el-TableColumn prop="valor" label="Valor" sortable> </el-TableColumn>
|
<el-TableColumn prop="valor" label="Valor" sortable :formatter="cell">
|
||||||
|
|
||||||
<el-TableColumn prop="metodopago" label="Metodo de pago" sortable>
|
|
||||||
</el-TableColumn>
|
</el-TableColumn>
|
||||||
|
<el-TableColumn
|
||||||
<el-TableColumn prop="categoria" label="Categoria" sortable>
|
prop="metodopago"
|
||||||
</el-TableColumn>
|
label="Metodo de pago"
|
||||||
<el-TableColumn label="Actions" sortable>
|
sortable
|
||||||
|
></el-TableColumn>
|
||||||
|
<el-TableColumn
|
||||||
|
prop="categoria"
|
||||||
|
label="Categoria"
|
||||||
|
sortable
|
||||||
|
></el-TableColumn>
|
||||||
|
<el-TableColumn>
|
||||||
<div slot-scope="{ row, $index }">
|
<div slot-scope="{ row, $index }">
|
||||||
|
<el-tooltip content="Edit" effect="light">
|
||||||
|
<base-button
|
||||||
|
type="success"
|
||||||
|
icon
|
||||||
|
size="sm"
|
||||||
|
class="btn-link"
|
||||||
|
@click="updateCompraClic($index)"
|
||||||
|
>
|
||||||
|
<i class="el-icon-edit"></i>
|
||||||
|
</base-button>
|
||||||
|
</el-tooltip>
|
||||||
<el-tooltip content="Delete" effect="light">
|
<el-tooltip content="Delete" effect="light">
|
||||||
<base-button
|
<base-button
|
||||||
type="danger"
|
type="danger"
|
||||||
@@ -39,25 +59,9 @@
|
|||||||
<i class="el-icon-delete-solid"></i>
|
<i class="el-icon-delete-solid"></i>
|
||||||
</base-button>
|
</base-button>
|
||||||
</el-tooltip>
|
</el-tooltip>
|
||||||
<el-tooltip content="Edit">
|
|
||||||
<base-button
|
|
||||||
type="success"
|
|
||||||
icon
|
|
||||||
size="sm"
|
|
||||||
class="btn-link"
|
|
||||||
@click="deleteCompra($_id)"
|
|
||||||
>
|
|
||||||
<i class="el-icon-edit"></i>
|
|
||||||
</base-button>
|
|
||||||
</el-tooltip>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<template slot="header" slot-scope="scope">
|
<template slot="header" slot-scope="scope">
|
||||||
<el-input
|
<el-input v-model="search" size="mini" placeholder="Buscar" />
|
||||||
v-model="search"
|
|
||||||
size="mini"
|
|
||||||
placeholder="Type to search"
|
|
||||||
/>
|
|
||||||
</template>
|
</template>
|
||||||
</el-TableColumn>
|
</el-TableColumn>
|
||||||
</el-table>
|
</el-table>
|
||||||
@@ -68,6 +72,9 @@
|
|||||||
:metodos_pago="metodos_pago"
|
:metodos_pago="metodos_pago"
|
||||||
:newCompra="newCompra"
|
:newCompra="newCompra"
|
||||||
:saveCompra="saveCompra"
|
:saveCompra="saveCompra"
|
||||||
|
:updateCompra="updateCompra"
|
||||||
|
:isUpdate="isUpdate"
|
||||||
|
:openForm="openForm"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -94,27 +101,25 @@ export default {
|
|||||||
},
|
},
|
||||||
compras: [],
|
compras: [],
|
||||||
search: "",
|
search: "",
|
||||||
metodos_pago: [
|
metodos_pago: [],
|
||||||
{
|
|
||||||
metodo: "Efectivo",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
metodo: "Tarjeta Credito",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
metodo: "Tarjeta Debito",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
categorias: [],
|
categorias: [],
|
||||||
|
isUpdate: false,
|
||||||
|
openForm: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.newCompra.fecha = this.$store.state.fecha;
|
this.newCompra.fecha = this.$store.state.fecha;
|
||||||
|
this.$store.dispatch("getCategorias");
|
||||||
|
this.$store.dispatch("getMetodos");
|
||||||
this.categorias = this.$store.state.categorias;
|
this.categorias = this.$store.state.categorias;
|
||||||
this.metodos_pago = this.$store.state.metodos_de_pago;
|
this.metodos_pago = this.$store.state.metodos_de_pago;
|
||||||
this.getCompras();
|
this.getCompras();
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
cell(row, column, cellValue, index) {
|
||||||
|
return this.formatMoneda(cellValue);
|
||||||
|
},
|
||||||
getCompras() {
|
getCompras() {
|
||||||
const axiosHeader = {
|
const axiosHeader = {
|
||||||
headers: {
|
headers: {
|
||||||
@@ -130,6 +135,9 @@ export default {
|
|||||||
.catch((e) => console.log(e));
|
.catch((e) => console.log(e));
|
||||||
},
|
},
|
||||||
saveCompra() {
|
saveCompra() {
|
||||||
|
if (this.checkFormulario() === false) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const axiosHeader = {
|
const axiosHeader = {
|
||||||
headers: {
|
headers: {
|
||||||
token: this.$store.state.auth.token,
|
token: this.$store.state.auth.token,
|
||||||
@@ -146,6 +154,29 @@ export default {
|
|||||||
})
|
})
|
||||||
.catch((e) => console.log(e));
|
.catch((e) => console.log(e));
|
||||||
},
|
},
|
||||||
|
updateCompra(id) {
|
||||||
|
const axiosHeader = {
|
||||||
|
headers: {
|
||||||
|
token: this.$store.state.auth.token,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const toSend = this.newCompra;
|
||||||
|
console.log(axiosHeader.data);
|
||||||
|
this.$axios
|
||||||
|
.put("/compra", toSend, axiosHeader)
|
||||||
|
.then((res) => {
|
||||||
|
this.clearFormCompra();
|
||||||
|
console.log(res.data.status);
|
||||||
|
this.getCompras();
|
||||||
|
})
|
||||||
|
.catch((e) => console.log(e));
|
||||||
|
},
|
||||||
|
updateCompraClic(id) {
|
||||||
|
this.isUpdate = true;
|
||||||
|
this.newCompra = JSON.parse(JSON.stringify(this.compras[id]));
|
||||||
|
this.openForm = !this.openForm;
|
||||||
|
},
|
||||||
|
|
||||||
deleteCompra(id) {
|
deleteCompra(id) {
|
||||||
const axiosHeader = {
|
const axiosHeader = {
|
||||||
headers: {
|
headers: {
|
||||||
@@ -160,19 +191,105 @@ export default {
|
|||||||
.then((res) => {
|
.then((res) => {
|
||||||
console.log(res.data);
|
console.log(res.data);
|
||||||
this.getCompras();
|
this.getCompras();
|
||||||
|
this.clearFormCompra();
|
||||||
})
|
})
|
||||||
.catch((e) => console.log(e));
|
.catch((e) => console.log(e));
|
||||||
},
|
},
|
||||||
clearFormCompra() {
|
clearFormCompra() {
|
||||||
|
this.newCompra._id = "";
|
||||||
this.newCompra.detalle = "";
|
this.newCompra.detalle = "";
|
||||||
this.newCompra.valor = 0;
|
this.newCompra.valor = 0;
|
||||||
this.newCompra.metodopago = "";
|
this.newCompra.metodopago = "";
|
||||||
this.newCompra.categoria = "";
|
this.newCompra.categoria = "";
|
||||||
|
this.isUpdate = false;
|
||||||
},
|
},
|
||||||
getIcon(name) {
|
getIcon(name) {
|
||||||
const found = this.$store.state.categorias.find((ic) => ic.name === name);
|
const found = this.$store.state.categorias.find((ic) => ic.name === name);
|
||||||
console.log(found);
|
console.log(found);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
formatMoneda(dato) {
|
||||||
|
var num = dato;
|
||||||
|
if (!isNaN(num)) {
|
||||||
|
num = num
|
||||||
|
.toString()
|
||||||
|
.split("")
|
||||||
|
.reverse()
|
||||||
|
.join("")
|
||||||
|
.replace(/(?=\d*\.?)(\d{3})/g, "$1.");
|
||||||
|
num = num.split("").reverse().join("").replace(/^[\.]/, "");
|
||||||
|
//return '$' +num;
|
||||||
|
return `$ ${num}`;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
getSummaries(param) {
|
||||||
|
const { columns, data } = param;
|
||||||
|
const sums = [];
|
||||||
|
columns.forEach((column, index) => {
|
||||||
|
if (index === 0) {
|
||||||
|
sums[index] = "Valor total";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const values = data.map((item) => Number(item[column.property]));
|
||||||
|
if (!values.every((value) => isNaN(value))) {
|
||||||
|
sums[index] = this.formatMoneda(
|
||||||
|
values.reduce((prev, curr) => {
|
||||||
|
const value = Number(curr);
|
||||||
|
if (!isNaN(value)) {
|
||||||
|
return prev + curr;
|
||||||
|
} else {
|
||||||
|
return prev;
|
||||||
|
}
|
||||||
|
}, 0)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
sums[index] = "";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return sums;
|
||||||
|
},
|
||||||
|
checkFormulario() {
|
||||||
|
if (this.newCompra.valor === 0) {
|
||||||
|
this.$notify({
|
||||||
|
type: "danger",
|
||||||
|
icon: "tim-icons icon-alert-circle-exc",
|
||||||
|
message: "el campo valor no puede estar en cero :("
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.newCompra.detalle === "") {
|
||||||
|
this.$notify({
|
||||||
|
type: "danger",
|
||||||
|
icon: "tim-icons icon-alert-circle-exc",
|
||||||
|
message: "el campo detalle no puede estar vacio :("
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.newCompra.metodopago === "") {
|
||||||
|
this.$notify({
|
||||||
|
type: "danger",
|
||||||
|
icon: "tim-icons icon-alert-circle-exc",
|
||||||
|
message: "el campo metodo de pago no puede estar vacio :("
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.newCompra.categoria === "") {
|
||||||
|
this.$notify({
|
||||||
|
type: "danger",
|
||||||
|
icon: "tim-icons icon-alert-circle-exc",
|
||||||
|
message: "el campo categoría no puede estar vacio :("
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<Prueba />
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -61,14 +61,34 @@ export const actions = {
|
|||||||
|
|
||||||
this.$axios.get("/categoria", axiosHeader)
|
this.$axios.get("/categoria", axiosHeader)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
console.log(res.data.data);
|
|
||||||
|
|
||||||
this.commit("setCategorias", res.data.data);
|
this.commit("setCategorias", res.data.data);
|
||||||
|
|
||||||
|
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
});
|
});
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getMetodos() {
|
||||||
|
|
||||||
|
const axiosHeader = {
|
||||||
|
headers: {
|
||||||
|
token: this.state.auth.token,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
this.$axios
|
||||||
|
.get("/metodo", axiosHeader)
|
||||||
|
.then((res) => {
|
||||||
|
|
||||||
|
this.commit("setMetodos", res.data.data);
|
||||||
|
})
|
||||||
|
.catch((e) => console.log(e));
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
1
index.js
1
index.js
@@ -28,6 +28,7 @@ app.use('/api',require('./routes/users'));
|
|||||||
app.use('/api',require('./routes/compras'))
|
app.use('/api',require('./routes/compras'))
|
||||||
app.use('/api',require('./routes/categorias'))
|
app.use('/api',require('./routes/categorias'))
|
||||||
app.use('/api',require('./routes/metodos_pago'))
|
app.use('/api',require('./routes/metodos_pago'))
|
||||||
|
app.disable('x-powered-by');
|
||||||
module.exports = app;
|
module.exports = app;
|
||||||
|
|
||||||
app.listen(app.get('port') ,() => console.log("service startes, listening on the port: ",app.get('port')))
|
app.listen(app.get('port') ,() => console.log("service startes, listening on the port: ",app.get('port')))
|
||||||
|
|||||||
@@ -41,6 +41,22 @@ router.get("/compras", checkAuth, async (req, res) => {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
router.put("/compra", checkAuth, async (req, res) => {
|
||||||
|
const { _id, fecha, detalle, valor, metodopago, categoria } = req.body;
|
||||||
|
const compra_edit = await Compra.findOne({ _id: _id });
|
||||||
|
await compra_edit.updateOne({ fecha, detalle, valor, metodopago, categoria });
|
||||||
|
|
||||||
|
|
||||||
|
res.json({
|
||||||
|
status:"OK"
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
router.delete("/compra", checkAuth, async (req, res) => {
|
router.delete("/compra", checkAuth, async (req, res) => {
|
||||||
|
|
||||||
try{
|
try{
|
||||||
|
|||||||
Reference in New Issue
Block a user