feat(Purchase): add change cash.

This commit is contained in:
Mono Mono 2024-11-11 14:33:51 -05:00
parent 8f62dfb9ec
commit acd9bf53c6

View File

@ -116,16 +116,35 @@
readonly
persistent-placeholder="true"
></v-text-field>
<v-select
:items="payment_methods"
v-model="purchase.payment_method"
item-title="text"
item-value="value"
label="Pago en"
></v-select>
<v-container v-if="calculateTotal > 0">
<v-select
:items="payment_methods"
v-model="purchase.payment_method"
item-title="text"
item-value="value"
label="Pago en"
></v-select>
<v-text-field
v-if="purchase.payment_method === 'CASH'"
v-model="payment_cash"
label="Dinero"
prefix="$"
type="number"
:error-messages="isValidPayment ? [] : ['El dinero debe ser mayor o igual al total']"
:disable="calculateTotal === 0"
></v-text-field>
<v-text-field
v-if="purchase.payment_method === 'CASH'"
:value="calculateChange"
label="Devuelta"
prefix="$"
readonly
presistent-placeholder="true"
></v-text-field>
</v-container>
<v-btn @click="submit" color="green">Comprar</v-btn>
</v-form>
</v-container>
</v-form>
</v-container>
</template>
<script>
@ -144,6 +163,7 @@
valid: false,
client_search: '',
product_search: '',
payment_cash: 0,
payment_methods: [
{'text': 'Efectivo', 'value': 'CASH'},
{'text': 'Confiar', 'value': 'CONFIAR'},
@ -153,7 +173,7 @@
date: this.getCurrentDate(),
customer: null,
notes: '',
payment_method: {'text': 'Efectivo', 'value': 'CASH'},
payment_method: null,
saleline_set: [{product:'', unit_price: 0, quantity: 0, unit: ''}],
},
rules: {
@ -182,6 +202,23 @@
return total + this.calculateSubtotal(saleline);
}, 0);
},
calculateChange() {
if (this.purchase.payment_method === 'CASH') {
return (this.payment_cash || 0) - this.calculateTotal;
} else {
return 0;
}
},
isValidPayment() {
if (this.calculateTotal === 0) {
return false;
}
if (this.purchase.payment_method === 'CASH' && this.payment_cash < this.calculateTotal) {
return false;
}
return true;
},
filteredClients() {
return this.clients.filter(client => {
if (this.client_search === '') {