Untitled
unknown
javascript
2 years ago
14 kB
9
Indexable
<template>
<div>
<v-dialog v-model="status" @keydown.esc="closeModal" persistent max-width="800px">
<v-form ref="form" v-model="valid" lazy-validation>
<v-card>
<v-card-title class="primary" color="primary" dark>
Facturación Electronica
</v-card-title>
<v-card-text>
<v-container grid-list-md>
<v-layout wrap>
<v-flex xs4>
<v-select
:items="type_person"
item-text="name"
label="Tipo de persona"
item-value="id"
v-model="dataInvoice.kind_of_person"
@change="setTypeDocument()"
required
/>
</v-flex>
<v-flex xs3>
<v-select
:items="documents"
item-text="name"
label="Tipo de documento"
item-value="id"
v-model="dataInvoice.factura_document_type_id"
@change="changeTypeDocument()"
required
/>
</v-flex>
<v-flex xs4>
<v-text-field
:label="'Número de documento'"
v-model="dataInvoice.document"
required
:maxlength="documentSelected.max_length"
/>
</v-flex>
<v-flex xs1>
<v-btn
v-if="isPeru"
color="primary" small dark @click="getDocumentData"
append-icon="search"
>Buscar
</v-btn>
</v-flex>
<v-flex xs12>
<div v-if="messageApi">
<p class="message-notfound">{{ messageApi }}</p>
</div>
</v-flex>
<v-flex xs6>
<v-text-field
label="Razon social o Nombre"
v-model="dataInvoice.socialReason"
required
/>
</v-flex>
<v-flex xs3>
<v-select
v-if="regimens.length > 0"
:items="regimens"
item-text="name"
label="Tipo de regimen"
item-value="code"
v-model="regimenSelected"
/>
</v-flex>
<v-flex xs3>
<v-select
v-if="countries_id == 2"
:items="cfdi"
item-text="description"
label="Tipo de CFDI"
item-value="code"
v-model="cfdiSelected"
/>
</v-flex>
<v-flex xs12>
<v-textarea
v-if="countries_id !== 2"
class="purple-input"
rows="2"
label="Dirección"
v-model="dataInvoice.address"
required
/>
</v-flex>
<v-flex xs3>
<v-text-field
v-if="countries_id === 2"
label="Calle"
v-model="dataInvoice.street"
required
/>
</v-flex>
<v-flex xs3>
<v-text-field
v-if="countries_id === 2"
label="Colonia"
v-model="dataInvoice.colony"
required
/>
</v-flex>
<v-flex xs3>
<v-text-field
v-if="countries_id === 2"
label="Estado"
v-model="dataInvoice.state"
required
/>
</v-flex>
<v-flex xs3>
<v-text-field
v-if="countries_id === 2"
label="Código postal"
v-model="dataInvoice.zip_code"
type="number"
required
/>
</v-flex>
<v-flex xs4>
<v-select
:items="receipt_type"
item-value="id"
item-text="name"
label="Documento a emitir"
v-model="dataInvoice.document_bill_type"
required
/>
</v-flex>
<v-flex xs4>
<v-select
:items="methodPayment"
item-value="code"
item-text="name"
label="Metodo de pago"
v-model="dataInvoice.method_payment"
required
/>
</v-flex>
<v-flex xs4>
<v-dialog
ref="dialog"
v-model="modal"
:return-value.sync="date"
:disabled="Disabled"
width="290px"
>
<template v-slot:activator="{ on }">
<v-text-field
v-on="on"
v-model="dataInvoice.date"
label="Fecha de emision"
prepend-icon="event"
readonly
/>
</template>
<v-date-picker
:min="lastDate"
v-model="dataInvoice.date"
:show-current="lastDate"
:max="maxDate"
scrollable locale="es-pe">
<v-spacer/>
<v-btn color="primary" @click="closeModal">Cancelar</v-btn>
<v-btn color="primary" @click="$refs.dialog.save(dataInvoice.date)">
SELECCIONAR
</v-btn>
</v-date-picker>
</v-dialog>
</v-flex>
<v-flex xs4>
<v-checkbox
v-model="dataInvoice.sendEmail"
label="Enviar email con la factura"
/>
</v-flex>
</v-layout>
</v-container>
</v-card-text>
<v-card-actions>
<v-btn color="red" dark @click="closeModal">Cancelar</v-btn>
<v-spacer/>
<v-btn color="primary" dark @click="Billing">EMITIR DOCUMENTO</v-btn>
</v-card-actions>
</v-card>
</v-form>
</v-dialog>
</div>
</template>
<script>
import axios from "axios";
import Invoice from "../../mixins/InvoiceMixins";
import Swal from "sweetalert2";
export default {
name: "CreateInvoice.vue",
props: {
data: Object,
status: Boolean,
},
watch: {
dialogCreate(val) {
if (val == false) {
this.dataInvoice = {
factura_document_type_id: 1,
document: null,
socialReason: '',
address: '',
document_bill_type: 1,
sendEmail: true,
costDelivery: '',
kind_of_person: 'PERSON_ENTITY'
}
}
},
status(val) {
if (val) {
this.invoiceModal(this.data)
}
}
},
data() {
return {
dialogCreate: true,
valid: false,
modal: false,
countries_id: 1,
}
},
mixins: [Invoice],
methods: {
Billing() {
if (this.dataInvoice.document_bill_type == null) {
this.showMessage('EL DOCUMENTO A EMITIR ES OBLIGATORIO', 'danger')
return null
}
if (this.dataInvoice.factura_document_type_id === 4) {
if (this.dataInvoice.document.length < 11 || this.dataInvoice.document.length > 13) {
this.showMessage('EL RFC DEBE TENER 12 o 13 DIGITOS', 'danger')
return null
}
}
if (this.dataInvoice.factura_document_type_id === 2 && this.dataInvoice.document.length != 11) {
this.showMessage('EL RUC DEBE TENER 11 DIGITOS', 'danger')
return null
}
if (this.dataInvoice.factura_document_type_id === 1 && this.dataInvoice.document.length != 8) {
this.showMessage('EL DNI DEBE TENER 8 DIGITOS', 'danger')
return null
}
if (this.dataInvoice.factura_document_type_id === 1 && this.dataInvoice.document_bill_type == 2) {
this.showMessage('SOLO SE PUEDE EMITIR FACTURAS CON RUC', 'danger')
return null
}
if (this.dataInvoice.method_payment == null) {
this.showMessage('EL METODO DE PAGO ES OBLIGATORIO', 'danger')
return null
}
axios.post("/charges/facturar", {
dataInvoice: this.dataInvoice,
tempDataUser: this.tempDataUser,
regimens: this.regimenSelected,
cdfi: this.cfdiSelected
}).then(response => {
Swal(response.data.success ? 'Exelente!' : 'Error', response.data.detail.message, response.data.success ? 'success': 'error')
if (response.data.success) {
this.$store.commit("UPDATE_CHARGE_DATA", response.data.detail.membership_charge_id)
this.closeModal()
}
}).catch(function (error) {
Swal('Error inesperado!', error.response.data.detail.message, 'error')
})
},
closeModal() {
this.clearData()
this.$emit('close')
},
clearData() {
this.dataInvoice = {
factura_document_type_id: 1,
document: null,
socialReason: '',
address: '',
document_bill_type: 1,
sendEmail: true,
costDelivery: ''
}
}
}
}
</script>
<style scoped>
</style>
Editor is loading...
Leave a Comment