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 e1ce9cb..658e56e 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 {
@@ -70,7 +71,7 @@ const AutomaticPayScreen = ({ route }) => {
amount: "",
currency: "",
deposit: "",
- advancePaymentNumber: "",
+ // advancePaymentNumber: "",
checkBankNumber: "",
checkBankDate: "",
bankAccount: "",
@@ -79,40 +80,79 @@ 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){}else{
- if(data.amount > dataAll[index].Saldo_pendiente){
+ let amount2 = data.amount;
+ while (index < dataAll.length && data.amount > 0) {
+ if (dataAll[index].Saldo_pendiente === 0 || data.amount === 0) {
+ 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);
- }else{
- dataAll[index].Saldo_pendiente -= parseFloat(data.amount);
- dataAll[index].Monto_pagado += parseFloat(data.amount);
+ 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((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)
}
- 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(amount2),
+ saldo: parseFloat(dataAll[index].Saldo_pendiente),
+ }]
+ });
+
+ updateNota(dataAll[index].id, { Saldo_pendiente: dataAll[index].Saldo_pendiente, Monto_pagado: 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|| "",
+ monto: parseFloat(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 || "",
+ usuario_id: user.id,
})
}
index++;
}
console.log("Pagos realizados");
+
navigation.goBack();
};
@@ -138,30 +178,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}
+ />
+
+
+ {/* {
},
}}
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 === 'transferencia' &&
+ }
+
+
+
+
+
+ Registrar Pago
+
+
+
+
)
};
@@ -278,7 +320,7 @@ const styles = StyleSheet.create({
fontSize: 22,
textAlign: "center",
},
- nombre:{
+ nombre: {
fontWeight: "bold",
fontSize: 20,
textAlign: "center",
@@ -312,6 +354,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 6090e01..12168c0 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,
@@ -48,7 +48,7 @@ const PayScreen = ({ route }) => {
amount: "",
currency: "",
payMode: "",
- advancePaymentNumber: "",
+ // advancePaymentNumber: "",
checkBankNumber: "",
checkBankDate: "",
account: "",
@@ -57,7 +57,20 @@ 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) {
+ return;
+ }
PaymentStore.getState().establecerCliente(user.nombre, note.Cuenta);
PaymentStore.getState().establecerMetodoPago(method);
PaymentStore.getState().agregarNotaPagada({
@@ -67,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 || "",
@@ -91,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();
};
@@ -116,31 +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}
+ />
+
+
+ {/* {
},
}}
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 === 'transferencia' &&
+ }
+
+
+
+
+
+ Registrar Pago
+
+
+
+
+
)
};
diff --git a/src/screens/SelectPaymentMethodScreen.js b/src/screens/SelectPaymentMethodScreen.js
index 719c78f..809c0c4 100644
--- a/src/screens/SelectPaymentMethodScreen.js
+++ b/src/screens/SelectPaymentMethodScreen.js
@@ -52,7 +52,7 @@ const SelectPaymentMethodScreen = ({ route }) => {
- 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
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}})),