Skip to content

Commit

Permalink
Update PayScreen
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamCallao committed Mar 24, 2024
1 parent 04cc222 commit 4d097ec
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
16 changes: 16 additions & 0 deletions src/PaymentStore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import create from 'zustand'

const PaymentStore = create((set) => ({
pagosRealizados: [],
agregarPago: (nuevoPago) => set((state) => ({
pagosRealizados: [...state.pagosRealizados, nuevoPago]
})),
eliminarPago: (numeroNota) => set((state) => ({
pagosRealizados: state.pagosRealizados.filter(pago => pago.numeroNota !== numeroNota),
})),
borrarPagos: () => set(() => ({
pagosRealizados: []
}))
}))

export default PaymentStore;
2 changes: 1 addition & 1 deletion src/components/NoteItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const NoteItem = ({ note, onSelect }) => {
<View>
<SimpleButton
text="Pagar"
onPress={() => navigation.navigate("PayScreen")}
onPress={() => navigation.navigate("PayScreen", { note })}
/>
</View>
</View>
Expand Down
21 changes: 16 additions & 5 deletions src/screens/FacturaScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@ import * as Sharing from 'expo-sharing';
import StyledText from '../utils/StyledText';
import DualTextView from '../utils/DualTextView';
import SimpleButton from '../utils/SimpleButton';
import PaymentStore from '../PaymentStore';

const cliente = "John Doe";
const numeroCliente = "20102353001";
const fechaEmision = "06/08/2024";
const pagosRealizados = [
{ numeroNota: "215", fechaNota: "11/07/2024", total: "520.00", pagado: "210.00" },
{ numeroNota: "221", fechaNota: "05/08/2024", total: "340.00", pagado: "340.00" }
];
const totalPagado = pagosRealizados.reduce((acc, pago) => acc + parseFloat(pago.pagado), 0).toFixed(2);

const SimpleScreen = () => {
const viewRef = useRef();
const pagosRealizados = PaymentStore((state) => state.pagosRealizados);
const borrarPagos = PaymentStore((state) => state.borrarPagos);
const totalPagado = pagosRealizados.reduce((acc, pago) => acc + parseFloat(pago.pagado), 0).toFixed(2);

const captureAndShareScreenshot = async () => {
try {
Expand All @@ -30,6 +29,10 @@ const SimpleScreen = () => {
Alert.alert("Error", "No se pudo capturar o compartir el comprobante: " + error.message);
}
};
const handleBorrarPagos = () => {
borrarPagos();
Alert.alert("Borrado", "Todos los pagos han sido borrados.");
};
return (
<SafeAreaView style={styles.safeArea}>
<View style={styles.container} ref={viewRef}>
Expand Down Expand Up @@ -71,18 +74,26 @@ const SimpleScreen = () => {
leftChild={<StyledText regularIntenceText>Pagado :</StyledText>}
rightChild={<StyledText regularText> {`${pago.pagado} Bs`}</StyledText>}
/>

</View>
))}
<DualTextView
separation={10}
leftChild={<StyledText regularIntenceText>Total Pagado :</StyledText>}
rightChild={<StyledText regularText> {`${totalPagado} Bs`}</StyledText>}
/>

</View>
<SimpleButton
text="Imprimir"
onPress={ captureAndShareScreenshot}
/>
<SimpleButton
text="Borrar todos los pagos"
onPress={handleBorrarPagos}
style={{ marginTop: 10 }} // Añade un poco de margen entre los botones
/>

</SafeAreaView>
);
};
Expand Down
11 changes: 10 additions & 1 deletion src/screens/PayScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import { theme } from "../../constants.js";
import InputField from "../components/InputField.js";
import DateInputField from "../components/DateInputField.js";
import DropdownSelector2 from "../components/DropdownSelector2.js";

import PaymentStore from "../PaymentStore.js";
const screenWidth = Dimensions.get("window").width;
const screenHeight = Dimensions.get("window").height;

const PayScreen = ({ route }) => {
const { note } = route.params;
const navigation = useNavigation();
//const { itemClient } = route.params;
const [animationKey, setAnimationKey] = useState(Date.now());
Expand Down Expand Up @@ -53,6 +54,14 @@ const PayScreen = ({ route }) => {
console.log(data);
// Aquí puedes agregar la lógica para guardar los datos
//navigation.navigate("ClientPaymentScreen", { itemClient: item });
PaymentStore.getState().agregarPago({
numeroNota: note.nro_nota,
fechaNota: note.Fecha,
total: note.importe_nota,
pagado: data.amount,
});

console.log("Pagos realizados:", PaymentStore.getState().pagosRealizados);
};

return (
Expand Down

0 comments on commit 4d097ec

Please sign in to comment.