feat(Purchase): add change cash.
This commit is contained in:
		@@ -116,6 +116,7 @@
 | 
				
			|||||||
          readonly
 | 
					          readonly
 | 
				
			||||||
          persistent-placeholder="true"
 | 
					          persistent-placeholder="true"
 | 
				
			||||||
        ></v-text-field>
 | 
					        ></v-text-field>
 | 
				
			||||||
 | 
					        <v-container v-if="calculateTotal > 0">
 | 
				
			||||||
          <v-select
 | 
					          <v-select
 | 
				
			||||||
            :items="payment_methods"
 | 
					            :items="payment_methods"
 | 
				
			||||||
            v-model="purchase.payment_method"
 | 
					            v-model="purchase.payment_method"
 | 
				
			||||||
@@ -123,6 +124,24 @@
 | 
				
			|||||||
            item-value="value"
 | 
					            item-value="value"
 | 
				
			||||||
            label="Pago en"
 | 
					            label="Pago en"
 | 
				
			||||||
          ></v-select>
 | 
					          ></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-btn @click="submit" color="green">Comprar</v-btn>
 | 
				
			||||||
  </v-form>
 | 
					  </v-form>
 | 
				
			||||||
</v-container>
 | 
					</v-container>
 | 
				
			||||||
@@ -144,6 +163,7 @@
 | 
				
			|||||||
       valid: false,
 | 
					       valid: false,
 | 
				
			||||||
       client_search: '',
 | 
					       client_search: '',
 | 
				
			||||||
       product_search: '',
 | 
					       product_search: '',
 | 
				
			||||||
 | 
					       payment_cash: 0,
 | 
				
			||||||
       payment_methods: [
 | 
					       payment_methods: [
 | 
				
			||||||
         {'text': 'Efectivo', 'value': 'CASH'},
 | 
					         {'text': 'Efectivo', 'value': 'CASH'},
 | 
				
			||||||
         {'text': 'Confiar', 'value': 'CONFIAR'},
 | 
					         {'text': 'Confiar', 'value': 'CONFIAR'},
 | 
				
			||||||
@@ -153,7 +173,7 @@
 | 
				
			|||||||
         date: this.getCurrentDate(),
 | 
					         date: this.getCurrentDate(),
 | 
				
			||||||
         customer: null,
 | 
					         customer: null,
 | 
				
			||||||
         notes: '',
 | 
					         notes: '',
 | 
				
			||||||
         payment_method: {'text': 'Efectivo', 'value': 'CASH'},
 | 
					         payment_method: null,
 | 
				
			||||||
         saleline_set: [{product:'', unit_price: 0, quantity: 0, unit: ''}],
 | 
					         saleline_set: [{product:'', unit_price: 0, quantity: 0, unit: ''}],
 | 
				
			||||||
       },
 | 
					       },
 | 
				
			||||||
       rules: {
 | 
					       rules: {
 | 
				
			||||||
@@ -182,6 +202,23 @@
 | 
				
			|||||||
         return total + this.calculateSubtotal(saleline);
 | 
					         return total + this.calculateSubtotal(saleline);
 | 
				
			||||||
       }, 0);
 | 
					       }, 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() {
 | 
					     filteredClients() {
 | 
				
			||||||
       return this.clients.filter(client => {
 | 
					       return this.clients.filter(client => {
 | 
				
			||||||
         if (this.client_search === '') {
 | 
					         if (this.client_search === '') {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user