Skip to content

Commit

Permalink
Update FacturaScreen
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamCallao committed Mar 24, 2024
1 parent 4d097ec commit 6900873
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 50 deletions.
2 changes: 1 addition & 1 deletion src/PaymentStore.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import create from 'zustand'
import {create} from 'zustand'

const PaymentStore = create((set) => ({
pagosRealizados: [],
Expand Down
1 change: 1 addition & 0 deletions src/navigation/AppNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ function AppNavigator() {
<Stack.Screen
name="Factura"
component={FacturaScreen}
options={{ headerShown: false }}
/>
</Stack.Navigator>
</NavigationContainer>
Expand Down
122 changes: 85 additions & 37 deletions src/screens/FacturaScreen.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
import React, { useRef } from 'react';
import { View, StyleSheet, Alert, TouchableOpacity } from 'react-native';
import React, { useRef, useState, useCallback} from 'react';
import { View, ScrollView, StyleSheet, Alert, TouchableOpacity } from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import { captureRef } from 'react-native-view-shot';
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';
import Cascading from '../animation/CascadingFadeInView';
import Icon from "react-native-vector-icons/AntDesign";
import { useNavigation, useFocusEffect } from '@react-navigation/native';
import { theme } from "../../constants.js";
import { StatusBar } from 'expo-status-bar';

const cliente = "John Doe";
const numeroCliente = "20102353001";
const fechaEmision = "06/08/2024";
const brandName = 'BRAND NAME';

const SimpleScreen = () => {
const viewRef = useRef();
const navigation = useNavigation();
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 [animationKey, setAnimationKey] = useState(Date.now());
useFocusEffect(
useCallback(() => {
setAnimationKey(Date.now());
}, [])
);
const captureAndShareScreenshot = async () => {
try {
const uri = await captureRef(viewRef, {
Expand All @@ -34,92 +47,127 @@ const SimpleScreen = () => {
Alert.alert("Borrado", "Todos los pagos han sido borrados.");
};
return (
<SafeAreaView style={styles.safeArea}>
<>
<StatusBar style="ligth" backgroundColor={theme.colors.primary} />
<ScrollView style={styles.safeArea}>
<Cascading delay={100} animationKey={animationKey}>
<View style={styles.header}>
<TouchableOpacity
style={styles.back}
onPress={() => navigation.goBack()}
>
<Icon name="back" size={30} color="black" />
</TouchableOpacity>
<View style={styles.aviContainer}>
{/* <Text style={styles.avi}>Nº 150</Text>
<Text style={styles.avi}>130. Bs</Text> */}
</View>
</View>
</Cascading>
<View style={styles.container} ref={viewRef}>
<StyledText regularIntenseText style={styles.title}>COMPROBANTE DE PAGO</StyledText>
<View style={styles.separacionInferior}>
<StyledText boldTextUpper style={styles.title}>{brandName}</StyledText>
<StyledText regularIntenceText style={{textAlign:'center'}}>Comprobante de pago</StyledText>
</View>
<View style={styles.notaSection}>
<DualTextView
separation={10}
leftChild={<StyledText regularIntenceText>Cliente :</StyledText>}
rightChild={<StyledText regularText> {cliente}</StyledText>}
/>
<DualTextView
separation={10}
leftChild={<StyledText regularIntenceText>N° Cliente :</StyledText>}
rightChild={<StyledText regularText> {numeroCliente}</StyledText>}
/>
<DualTextView
separation={10}
leftChild={<StyledText regularIntenceText>Fecha de Emisión :</StyledText>}
leftChild={<StyledText regularIntenceText>Fecha :</StyledText>}
rightChild={<StyledText regularText> {fechaEmision}</StyledText>}
/>
</View>
{pagosRealizados.map((pago, index) => (
<View key={index} style={styles.notaSection}>
<DualTextView
separation={10}
leftChild={<StyledText regularIntenceText>N° Nota :</StyledText>}
rightChild={<StyledText regularText> {pago.numeroNota}</StyledText>}
/>
<DualTextView
separation={10}
leftChild={<StyledText regularIntenceText>Fecha Nota :</StyledText>}
rightChild={<StyledText regularText> {pago.fechaNota}</StyledText>}
/>
<DualTextView
separation={10}
leftChild={<StyledText regularIntenceText>Total :</StyledText>}
rightChild={<StyledText regularText> {`${pago.total} Bs`}</StyledText>}
/>
<DualTextView
separation={10}
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 style={styles.total}>
<DualTextView
leftChild={<StyledText regularIntenceText>Total Pagado :</StyledText>}
rightChild={<StyledText regularText> {`${totalPagado} Bs`}</StyledText>}
/>
</View>
</View>
<View style={{marginHorizontal:20}}>
<SimpleButton
text="Imprimir"
onPress={ captureAndShareScreenshot}
/>

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

</SafeAreaView>
/> */}

</ScrollView>
</>
);
};

const styles = StyleSheet.create({
safeArea: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
paddingTop: 35,
backgroundColor:'#fff'
},
container: {
margin: 20,
padding: 20,
padding:5,
paddingTop: 40,
paddingBottom: 50,
alignSelf: 'stretch',
borderWidth: 1,
borderColor: '#ddd',
borderRadius: 10,
backgroundColor: '#fff',
elevation: 9,
},
separacionInferior:{
margin: 20,
alignSelf: 'stretch',
},
title: {
fontSize: 22,
fontWeight: 'bold',
marginBottom: 20,
textAlign: 'center',
},
notaSection: {
marginBottom: 15,
marginBottom: 10,
marginTop: 10,
},
total:{
marginTop:20,
},
back: {
justifyContent: "center",
alignItems: "center",
backgroundColor: theme.colors.otherWhite,
borderRadius: 20,
width: 60,
height: 60,
},
header:{
marginHorizontal:20,
flex:1,
},
});

Expand Down
21 changes: 9 additions & 12 deletions src/screens/PayScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ 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());
useFocusEffect(
useCallback(() => {
Expand Down Expand Up @@ -51,17 +50,15 @@ const PayScreen = ({ route }) => {
});

const onSubmit = (data) => {
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);
console.log(data);
PaymentStore.getState().agregarPago({
numeroNota: note.nro_nota,
fechaNota: note.Fecha,
total: note.importe_nota,
pagado: data.amount,
});
console.log("Pagos realizados:", PaymentStore.getState().pagosRealizados);
navigation.goBack();
};

return (
Expand Down

0 comments on commit 6900873

Please sign in to comment.