From e479d42038407d41b0cf497c87adfe1530932e0e Mon Sep 17 00:00:00 2001 From: judithmarg Date: Fri, 3 May 2024 01:41:42 -0400 Subject: [PATCH 1/4] fix values bigger amount and remove n anticipo --- src/screens/AutomaticPayScreen.js | 11 +++++++---- src/screens/PayScreen.js | 10 +++++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/screens/AutomaticPayScreen.js b/src/screens/AutomaticPayScreen.js index e1ce9cb..5be4777 100644 --- a/src/screens/AutomaticPayScreen.js +++ b/src/screens/AutomaticPayScreen.js @@ -70,7 +70,7 @@ const AutomaticPayScreen = ({ route }) => { amount: "", currency: "", deposit: "", - advancePaymentNumber: "", + // advancePaymentNumber: "", checkBankNumber: "", checkBankDate: "", bankAccount: "", @@ -83,7 +83,9 @@ const AutomaticPayScreen = ({ route }) => { console.log(data); let index = 0; while(index < dataAll.length && data.amount > 0){ - if(dataAll[index].Saldo_pendiente === 0){}else{ + if(dataAll[index].Saldo_pendiente === 0 || data.amount === 0){ + return; + }else{ if(data.amount > dataAll[index].Saldo_pendiente){ data.amount -= dataAll[index].Saldo_pendiente; dataAll[index].Saldo_pendiente = 0; @@ -146,6 +148,7 @@ const AutomaticPayScreen = ({ route }) => { type="numeric" rules={{ required: "Este campo es requerido", + validate: (value) => parseFloat(value) <= vBalance || "El monto excede el saldo pendiente", pattern: { value: /^[0-9]+([.][0-9]{0,2})?$/, message: "Ingrese solo números", @@ -161,7 +164,7 @@ const AutomaticPayScreen = ({ route }) => { onOptionChange={handleCurrencyChange} /> - { }, }} errors={errors} - /> + /> */} {method === 'cheque' && { amount: "", currency: "", payMode: "", - advancePaymentNumber: "", + // advancePaymentNumber: "", checkBankNumber: "", checkBankDate: "", account: "", @@ -58,6 +58,9 @@ const PayScreen = ({ route }) => { }); const onSubmit = (data) => { + if(note.Saldo_pendiente === 0 || parseFloat(data.amount) > note.Saldo_pendiente || parseFloat(data.amount) === 0){ + return; + } PaymentStore.getState().establecerCliente(user.nombre, note.Cuenta); PaymentStore.getState().establecerMetodoPago(method); PaymentStore.getState().agregarNotaPagada({ @@ -125,6 +128,7 @@ const PayScreen = ({ route }) => { type="numeric" rules={{ required: "Este campo es requerido", + validate: value => parseFloat(value) <= note.Saldo_pendiente || "El monto excede el saldo pendiente", pattern: { value: /^[0-9]+([.][0-9]{0,2})?$/, message: "Ingrese solo números", @@ -140,7 +144,7 @@ const PayScreen = ({ route }) => { onOptionChange={handleCurrencyChange} /> - { }, }} errors={errors} - /> + /> */} {method === 'cheque' && Date: Fri, 3 May 2024 17:17:17 -0400 Subject: [PATCH 2/4] add id cobrador and automatic payscreen --- src/screens/AutomaticPayScreen.js | 282 +++++++++++++++++------------- src/screens/LoginScreen.js | 4 +- src/screens/PayScreen.js | 203 +++++++++++---------- src/stores/userStore.js | 2 + 4 files changed, 279 insertions(+), 212 deletions(-) diff --git a/src/screens/AutomaticPayScreen.js b/src/screens/AutomaticPayScreen.js index 5be4777..ef4eb5f 100644 --- a/src/screens/AutomaticPayScreen.js +++ b/src/screens/AutomaticPayScreen.js @@ -1,5 +1,5 @@ import React, { useState, useCallback, useEffect } from "react"; -import { SafeAreaView, StyleSheet, Text, TextInput, TouchableOpacity, View, Dimensions, ScrollView } from 'react-native'; +import { Alert, SafeAreaView, StyleSheet, Text, TouchableOpacity, View, Dimensions, ScrollView } from 'react-native'; import { useForm } from "react-hook-form"; import Icon from "react-native-vector-icons/AntDesign"; import { useNavigation, useFocusEffect } from '@react-navigation/native'; @@ -8,6 +8,7 @@ import Cascading from "../animation/CascadingFadeInView"; import { theme } from "../assets/Theme"; import InputField from "../components/InputField.js"; import DateInputField from "../components/DateInputField.js"; +import PaymentStore from "../stores/PaymentStore.js"; import DropdownSelector2 from "../components/DropdownSelector2.js"; import userStore from "../stores/userStore"; import useStore from "../stores/store"; @@ -21,7 +22,7 @@ const AutomaticPayScreen = ({ route }) => { const { clientInfo } = route.params; const { criteria } = route.params; const { method } = route.params; - const {updateNota, agregarPago} = useStore(state => ({state, updateNota: state.updateNota, agregarPago: state.agregarPago})); + const { updateNota, agregarPago } = useStore(state => ({ state, updateNota: state.updateNota, agregarPago: state.agregarPago })); const { user } = userStore(state => ({ user: state.user })); const [dataAll, setDataAll] = useState(null); const [animationKey, setAnimationKey] = useState(Date.now()); @@ -33,22 +34,22 @@ const AutomaticPayScreen = ({ route }) => { const vBalance = parseFloat( clientInfo.NotasPendientes.reduce( - (total, nota) => total + nota.Saldo_pendiente, - 0 + (total, nota) => total + nota.Saldo_pendiente, + 0 ).toFixed(2) - ); - useEffect(()=> { - if(criteria == "PEPS"){ + ); + useEffect(() => { + if (criteria == "PEPS") { setDataAll(clientInfo.NotasPendientes.sort((a, b) => b.Fecha - a.Fecha)); - }else if(criteria == "UEPS"){ - setDataAll(clientInfo.NotasPendientes.sort((a, b) => a.Fecha - b.Fecha)); - }else if(criteria == "MayorMenor"){ - setDataAll(clientInfo.NotasPendientes.sort((a, b) => b.Saldo_pendiente - a.Saldo_pendiente)); - }else{ - setDataAll(clientInfo.NotasPendientes.sort((a, b) => a.Saldo_pendiente - b.Saldo_pendiente)); - } - },[]); - + } else if (criteria == "UEPS") { + setDataAll(clientInfo.NotasPendientes.sort((a, b) => a.Fecha - b.Fecha)); + } else if (criteria == "MayorMenor") { + setDataAll(clientInfo.NotasPendientes.sort((a, b) => b.Saldo_pendiente - a.Saldo_pendiente)); + } else { + setDataAll(clientInfo.NotasPendientes.sort((a, b) => a.Saldo_pendiente - b.Saldo_pendiente)); + } + }, []); + const [selectedCurrency, setSelectedCurrency] = useState('Bs'); const handleCurrencyChange = (option) => { setSelectedCurrency(option); @@ -58,7 +59,7 @@ const AutomaticPayScreen = ({ route }) => { const cash_accounts = ['CTA 11101010001', 'CTA 11101010002', 'CTA 11101020001', 'CTA 11101020002']; const [selectedDate, setSelectedDate] = useState(formatDate(new Date(), 'yyyy-MM-dd')); const [selectedBank, setSelectedBank] = useState('FIE.CTA 6-8918'); - const banks = ['FIE.CTA 6-8918', 'BISA.CTA 4454770019','UNION.CTA 1-18604442', 'BNB.CTA 300017-4016','BISA.CTA 4454772011']; + const banks = ['FIE.CTA 6-8918', 'BISA.CTA 4454770019', 'UNION.CTA 1-18604442', 'BNB.CTA 300017-4016', 'BISA.CTA 4454772011']; const { @@ -79,42 +80,70 @@ const AutomaticPayScreen = ({ route }) => { }, }); + const modalConfirmacion = (data) => + Alert.alert('Confirmación', `¿Está seguro de realizar este cobro?\n Monto: ${data.amount} ${selectedCurrency}\n Método de pago: ${method}`, [ + { + text: 'Cancelar', + onPress: () => { return; }, + style: 'cancel', + }, + { text: 'Continuar', onPress: () => { onSubmit(data) } }, + ]); + + const onSubmit = (data) => { console.log(data); let index = 0; - while(index < dataAll.length && data.amount > 0){ - if(dataAll[index].Saldo_pendiente === 0 || data.amount === 0){ + while (index < dataAll.length && data.amount > 0) { + if (dataAll[index].Saldo_pendiente === 0 || data.amount === 0) { return; - }else{ - if(data.amount > dataAll[index].Saldo_pendiente){ + } else { + if (data.amount > dataAll[index].Saldo_pendiente) { data.amount -= dataAll[index].Saldo_pendiente; dataAll[index].Saldo_pendiente = 0; dataAll[index].Monto_pagado = parseFloat(dataAll[index].importe_nota); - }else{ + } else { dataAll[index].Saldo_pendiente -= parseFloat(data.amount); - dataAll[index].Monto_pagado += parseFloat(data.amount); + dataAll[index].Monto_pagado += parseFloat(data.amount.toFixed(2)); data.amount = 0; } - updateNota(dataAll[index].id, {Saldo_pendiente: dataAll[index].Saldo_pendiente, Monto_pagado: parseFloat(dataAll[index].Monto_pagado)}); + + PaymentStore.getState().establecerCliente(user.nombre, dataAll[index].Cuenta); + PaymentStore.getState().establecerMetodoPago(method); + PaymentStore.getState().agregarNotaPagada({ + fecha: selectedDate, + metodoPago: method, + detalles: [{ + numeroNota: dataAll[index].nro_nota, + fecha: dataAll[index].Fecha_venta, + total: parseFloat(dataAll[index].importe_nota), + pagado: parseFloat(data.amount), + saldo: parseFloat(dataAll[index].Saldo_pendiente), + }] + }); + + updateNota(dataAll[index].id, { Saldo_pendiente: dataAll[index].Saldo_pendiente, Monto_pagado: parseFloat(dataAll[index].Monto_pagado) }); agregarPago({ cta_deposito: selectedBank, - cuenta: dataAll[index].Cuenta|| "", + cuenta: dataAll[index].Cuenta || "", empresa_id: user.empresa_id, fecha: selectedDate, - fecha_registro: dataAll[index].Fecha_venta|| "", + fecha_registro: dataAll[index].Fecha_venta || "", modo_pago: method, moneda: selectedCurrency, monto: dataAll[index].Monto_pagado, - nro_factura: dataAll[index].nro_nota|| "", - observaciones: data.observations|| "", - pago_a_nota: dataAll[index].id|| "", - referencia: data.reference|| "", - sucursal_id: dataAll[index].sucursal_id|| "", + nro_factura: dataAll[index].nro_nota || "", + observaciones: data.observations || "", + pago_a_nota: dataAll[index].id || "", + referencia: data.reference || "", + sucursal_id: dataAll[index].sucursal_id || "", + usuario_id: user.id, }) } index++; } console.log("Pagos realizados"); + navigation.goBack(); }; @@ -140,31 +169,31 @@ const AutomaticPayScreen = ({ route }) => { - - parseFloat(value) <= vBalance || "El monto excede el saldo pendiente", - pattern: { - value: /^[0-9]+([.][0-9]{0,2})?$/, - message: "Ingrese solo números", - }, - }} - errors={errors} - /> - - - {/* + parseFloat(value) <= vBalance || "El monto excede el saldo pendiente", + pattern: { + value: /^[0-9]+([.][0-9]{0,2})?$/, + message: "Ingrese solo números", + }, + }} + errors={errors} + /> + + + {/* { }} errors={errors} /> */} - {method === 'cheque' && - } + {method === 'cheque' && + } - {/* El input de abajo necesita usar un datetime picker para la fecha */} + {/* El input de abajo necesita usar un datetime picker para la fecha */} - - + + - {method==='efectivo' && - } - {method==='banco' && - } - - - - - - Registrar Pago - - - - + {method === 'efectivo' && + } + {method === 'banco' && + } + + + + + + Registrar Pago + + + + ) }; @@ -281,7 +310,7 @@ const styles = StyleSheet.create({ fontSize: 22, textAlign: "center", }, - nombre:{ + nombre: { fontWeight: "bold", fontSize: 20, textAlign: "center", @@ -315,6 +344,25 @@ const styles = StyleSheet.create({ flexDirection: "row", justifyContent: "space-between", }, + modalView: { + margin: 20, + backgroundColor: "white", + borderRadius: 20, + padding: 35, + alignItems: "center", + shadowColor: "#000", + shadowOffset: { + width: 0, + height: 2 + }, + shadowOpacity: 0.25, + shadowRadius: 4, + elevation: 5 + }, + modalText: { + marginBottom: 15, + textAlign: "center" + } }); export default AutomaticPayScreen; diff --git a/src/screens/LoginScreen.js b/src/screens/LoginScreen.js index 048cc70..988309e 100644 --- a/src/screens/LoginScreen.js +++ b/src/screens/LoginScreen.js @@ -19,11 +19,12 @@ const LoginScreen = () => { nombre: "", }); const [message, setMessage] = useState(false); - const { user, setUser, setUserId, setName } = userStore(state => ({ + const { user, setUser, setUserId, setName, setId } = userStore(state => ({ user: state.user, setUser: state.setUser, setUserId: state.setUserId, setName: state.setName, + setId: state.setId, })); const addDocument = async (data) => { try{ @@ -55,6 +56,7 @@ const LoginScreen = () => { console.log("Document added with ID: ", id); setUserId(id); setName(info.nombre); + setId(info.cobrador_id); }) .catch((error) => { console.error("Error adding document: ", error); diff --git a/src/screens/PayScreen.js b/src/screens/PayScreen.js index d25f59a..960cbfb 100644 --- a/src/screens/PayScreen.js +++ b/src/screens/PayScreen.js @@ -1,5 +1,5 @@ import React, { useState, useCallback } from "react"; -import { SafeAreaView, StyleSheet, Text, TextInput, TouchableOpacity, View, Dimensions, ScrollView } from 'react-native'; +import { Alert, SafeAreaView, StyleSheet, Text, TextInput, KeyboardAvoidingView, TouchableOpacity, View, Dimensions, ScrollView } from 'react-native'; import { useForm } from "react-hook-form"; import Icon from "react-native-vector-icons/AntDesign"; import { useNavigation, useFocusEffect } from '@react-navigation/native'; @@ -19,7 +19,7 @@ const screenHeight = Dimensions.get("window").height; const PayScreen = ({ route }) => { const { note, method } = route.params; const navigation = useNavigation(); - const {updateNota, agregarPago} = useStore(state => ({state, updateNota: state.updateNota, agregarPago: state.agregarPago})); + const { updateNota, agregarPago } = useStore(state => ({ state, updateNota: state.updateNota, agregarPago: state.agregarPago })); const { user } = userStore(state => ({ user: state.user })); const [animationKey, setAnimationKey] = useState(Date.now()); useFocusEffect( @@ -27,7 +27,7 @@ const PayScreen = ({ route }) => { setAnimationKey(Date.now()); }, []) ); - + const [selectedCurrency, setSelectedCurrency] = useState('Bs'); const handleCurrencyChange = (option) => { setSelectedCurrency(option); @@ -37,7 +37,7 @@ const PayScreen = ({ route }) => { const cash_accounts = ['CTA 11101010001', 'CTA 11101010002', 'CTA 11101020001', 'CTA 11101020002']; const [selectedDate, setSelectedDate] = useState(formatDate(new Date(), 'yyyy-MM-dd')); const [selectedBank, setSelectedBank] = useState('FIE.CTA 6-8918'); - const banks = ['FIE.CTA 6-8918', 'BISA.CTA 4454770019','UNION.CTA 1-18604442', 'BNB.CTA 300017-4016','BISA.CTA 4454772011']; + const banks = ['FIE.CTA 6-8918', 'BISA.CTA 4454770019', 'UNION.CTA 1-18604442', 'BNB.CTA 300017-4016', 'BISA.CTA 4454772011']; const { control, @@ -57,8 +57,18 @@ const PayScreen = ({ route }) => { }, }); + const modalConfirmacion = (data) => + Alert.alert('Confirmación', `¿Está seguro de realizar este cobro?\n Monto: ${data.amount} ${selectedCurrency}\n Método de pago: ${method}`, [ + { + text: 'Cancelar', + onPress: () => { return; }, + style: 'cancel', + }, + { text: 'Continuar', onPress: () => { onSubmit(data) } }, + ]); + const onSubmit = (data) => { - if(note.Saldo_pendiente === 0 || parseFloat(data.amount) > note.Saldo_pendiente || parseFloat(data.amount) === 0){ + if (note.Saldo_pendiente === 0 || parseFloat(data.amount) > note.Saldo_pendiente || parseFloat(data.amount) === 0) { return; } PaymentStore.getState().establecerCliente(user.nombre, note.Cuenta); @@ -70,16 +80,16 @@ const PayScreen = ({ route }) => { numeroNota: note.nro_nota, fecha: note.Fecha_venta, total: parseFloat(note.importe_nota), - pagado: parseFloat(data.amount), + pagado: parseFloat(data.amount), saldo: parseFloat(note.Saldo_pendiente) - parseFloat(data.amount), }] }); - + updateNota(note.id, { Saldo_pendiente: note.Saldo_pendiente - parseFloat(data.amount), Monto_pagado: note.Monto_pagado + parseFloat(data.amount) }); - + agregarPago({ cta_deposito: selectedBank, cuenta: note.Cuenta || "", @@ -94,7 +104,8 @@ const PayScreen = ({ route }) => { pago_a_nota: note.id || "", referencia: data.reference || "", sucursal_id: note.sucursal_id || "", - }); + usuario_id: user.id || "", + }); navigation.goBack(); }; @@ -119,32 +130,34 @@ const PayScreen = ({ route }) => { - - - parseFloat(value) <= note.Saldo_pendiente || "El monto excede el saldo pendiente", - pattern: { - value: /^[0-9]+([.][0-9]{0,2})?$/, - message: "Ingrese solo números", - }, - }} - errors={errors} - /> - - - {/* + + + + parseFloat(value) <= note.Saldo_pendiente || "El monto excede el saldo pendiente", + pattern: { + value: /^[0-9]+([.][0-9]{0,2})?$/, + message: "Ingrese solo números", + }, + }} + errors={errors} + /> + + + {/* { }} errors={errors} /> */} - {method === 'cheque' && - } + {method === 'cheque' && + } - {/* El input de abajo necesita usar un datetime picker para la fecha */} + {/* El input de abajo necesita usar un datetime picker para la fecha */} - - + + - {method==='efectivo' && - } - {method==='banco' && - } - - - - - - Registrar Pago - - - + {method === 'efectivo' && + } + {method === 'banco' && + } + + + + + + Registrar Pago + + + + + ) }; diff --git a/src/stores/userStore.js b/src/stores/userStore.js index 950a540..9d6cb9c 100644 --- a/src/stores/userStore.js +++ b/src/stores/userStore.js @@ -3,11 +3,13 @@ import { create } from "zustand"; const userStore = create((set) => { return { user: { + id : "", idDoc: "", nombre: "", empresa_id: "", }, setUser: (user) => set({ user }), + setId: (id) => set((state) => ({ user : {...state.user, id}})), setUserId: (idDoc) => set((state) => ({ user : {...state.user, idDoc}})), setName: (nombre) => set((state) => ({ user : {...state.user, nombre}})), setEmpresa: (empresa_id) => set((state) => ({ user : {...state.user, empresa_id}})), From 486a6488c743e07cca8b5e26270bf9bdb9122796 Mon Sep 17 00:00:00 2001 From: judithmarg Date: Fri, 3 May 2024 17:38:54 -0400 Subject: [PATCH 3/4] falta bug --- src/components/DateInputField.js | 3 ++- src/screens/AutomaticPayScreen.js | 8 +++++--- src/screens/PayScreen.js | 3 ++- src/screens/SelectPaymentMethodScreen.js | 2 +- src/screens/SelectPaymentMethodScreen2.js | 2 +- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/components/DateInputField.js b/src/components/DateInputField.js index 15ad3b4..0589527 100644 --- a/src/components/DateInputField.js +++ b/src/components/DateInputField.js @@ -5,7 +5,7 @@ import { Controller } from 'react-hook-form'; import DateTimePicker from '@react-native-community/datetimepicker'; import { format, formatDate } from 'date-fns'; -const DateInputField = ({ control, name, title, callThrough, type = 'default' }) => { +const DateInputField = ({ control, name, title, callThrough, type = 'default', isEditable }) => { const [selectedDate, setSelectedDate] = useState(new Date()); const [showDatePicker, setShowDatePicker] = useState(false); @@ -33,6 +33,7 @@ const DateInputField = ({ control, name, title, callThrough, type = 'default' }) onBlur={onBlur} onChangeText={onChange} value={format(selectedDate, 'dd/MM/yyyy')} + editable={isEditable} /> )} diff --git a/src/screens/AutomaticPayScreen.js b/src/screens/AutomaticPayScreen.js index ef4eb5f..bc919ac 100644 --- a/src/screens/AutomaticPayScreen.js +++ b/src/screens/AutomaticPayScreen.js @@ -98,13 +98,14 @@ const AutomaticPayScreen = ({ route }) => { if (dataAll[index].Saldo_pendiente === 0 || data.amount === 0) { return; } else { + dataAll[index].Monto_pagado = parseFloat(dataAll[index].Monto_pagado); if (data.amount > dataAll[index].Saldo_pendiente) { data.amount -= dataAll[index].Saldo_pendiente; dataAll[index].Saldo_pendiente = 0; dataAll[index].Monto_pagado = parseFloat(dataAll[index].importe_nota); } else { dataAll[index].Saldo_pendiente -= parseFloat(data.amount); - dataAll[index].Monto_pagado += parseFloat(data.amount.toFixed(2)); + dataAll[index].Monto_pagado += parseFloat(data.amount).toPrecision(2); data.amount = 0; } @@ -131,7 +132,7 @@ const AutomaticPayScreen = ({ route }) => { fecha_registro: dataAll[index].Fecha_venta || "", modo_pago: method, moneda: selectedCurrency, - monto: dataAll[index].Monto_pagado, + monto: parseFloat(dataAll[index].Monto_pagado), nro_factura: dataAll[index].nro_nota || "", observaciones: data.observations || "", pago_a_nota: dataAll[index].id || "", @@ -231,6 +232,7 @@ const AutomaticPayScreen = ({ route }) => { name="checkBankDate" title={method === 'method' ? "Fecha Cheque" : "Fecha"} callThrough={setSelectedDate} + isEditable={method === 'cheque' ? true : false} /> {method === 'efectivo' && @@ -240,7 +242,7 @@ const AutomaticPayScreen = ({ route }) => { selectedOption={selectedCash} onOptionChange={setSelectedCash} />} - {method === 'banco' && + {method === 'transferencia' && { name="checkBankDate" title={method === 'method' ? "Fecha Cheque" : "Fecha"} callThrough={setSelectedDate} + isEditable={method === 'cheque' ? true : false} /> {method === 'efectivo' && @@ -204,7 +205,7 @@ const PayScreen = ({ route }) => { selectedOption={selectedCash} onOptionChange={setSelectedCash} />} - {method === 'banco' && + {method === 'transferencia' && { - navigation.navigate(destino, { note, method:"banco" })}> + navigation.navigate(destino, { note, method:"transferencia" })}> Transferencia Bancaria diff --git a/src/screens/SelectPaymentMethodScreen2.js b/src/screens/SelectPaymentMethodScreen2.js index 4e2d789..b2dfa9f 100644 --- a/src/screens/SelectPaymentMethodScreen2.js +++ b/src/screens/SelectPaymentMethodScreen2.js @@ -49,7 +49,7 @@ const SelectPaymentMethodScreen2 = ({ route }) => { - navigation.navigate(destino, { clientInfo, criteria,method:"banco" })}> + navigation.navigate(destino, { clientInfo, criteria,method:"transferencia" })}> Transferencia Bancaria From 91404ef8dbf445e190b14391915e3354383728c8 Mon Sep 17 00:00:00 2001 From: judithmarg Date: Fri, 3 May 2024 20:16:42 -0400 Subject: [PATCH 4/4] fix automatic pay screen --- src/screens/AutomaticPayScreen.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/screens/AutomaticPayScreen.js b/src/screens/AutomaticPayScreen.js index bc919ac..658e56e 100644 --- a/src/screens/AutomaticPayScreen.js +++ b/src/screens/AutomaticPayScreen.js @@ -94,19 +94,27 @@ const AutomaticPayScreen = ({ route }) => { const onSubmit = (data) => { console.log(data); let index = 0; + let amount2 = data.amount; while (index < dataAll.length && data.amount > 0) { if (dataAll[index].Saldo_pendiente === 0 || data.amount === 0) { - return; + console.log("bien", index); + if (index === dataAll.length - 1) { + return; + } } else { dataAll[index].Monto_pagado = parseFloat(dataAll[index].Monto_pagado); if (data.amount > dataAll[index].Saldo_pendiente) { data.amount -= dataAll[index].Saldo_pendiente; dataAll[index].Saldo_pendiente = 0; - dataAll[index].Monto_pagado = parseFloat(dataAll[index].importe_nota); + dataAll[index].Monto_pagado = parseFloat(dataAll[index].importe_nota).toFixed(2); + amount2 = dataAll[index].importe_nota; + console.log("Saldo pendiente: ", dataAll[index].Monto_pagado, "Monto pagado: ", data.amount); } else { - dataAll[index].Saldo_pendiente -= parseFloat(data.amount); - dataAll[index].Monto_pagado += parseFloat(data.amount).toPrecision(2); + dataAll[index].Saldo_pendiente = parseFloat((dataAll[index].Saldo_pendiente - parseFloat(data.amount)).toFixed(2)); + dataAll[index].Monto_pagado = parseFloat((dataAll[index].Monto_pagado + parseFloat(data.amount)).toFixed(2)); + amount2 = data.amount; data.amount = 0; + console.log("Saldo pendiente2: ", dataAll[index].Monto_pagado, "Monto pagado: ", data.amount) } PaymentStore.getState().establecerCliente(user.nombre, dataAll[index].Cuenta); @@ -118,12 +126,12 @@ const AutomaticPayScreen = ({ route }) => { numeroNota: dataAll[index].nro_nota, fecha: dataAll[index].Fecha_venta, total: parseFloat(dataAll[index].importe_nota), - pagado: parseFloat(data.amount), + pagado: parseFloat(amount2), saldo: parseFloat(dataAll[index].Saldo_pendiente), }] }); - updateNota(dataAll[index].id, { Saldo_pendiente: dataAll[index].Saldo_pendiente, Monto_pagado: parseFloat(dataAll[index].Monto_pagado) }); + updateNota(dataAll[index].id, { Saldo_pendiente: dataAll[index].Saldo_pendiente, Monto_pagado: dataAll[index].Monto_pagado }); agregarPago({ cta_deposito: selectedBank, cuenta: dataAll[index].Cuenta || "",