parent
d220d4b2fd
commit
477d589aac
@ -0,0 +1,37 @@
|
||||
import { FC, useContext } from 'react'
|
||||
import { FlatList, ScrollView, Text, View } from 'react-native'
|
||||
import { SalesOrderContext } from '../screens/salesorder/SalesOrderContex';
|
||||
|
||||
|
||||
interface Props {
|
||||
//control: any,
|
||||
//fields: any
|
||||
}
|
||||
|
||||
const OneToMany: FC<Props> = ({}) => {
|
||||
|
||||
const { lines } = useContext(SalesOrderContext);
|
||||
console.log("Lineas: "+JSON.stringify(lines))
|
||||
|
||||
return (
|
||||
<ScrollView style={{flex: 1}}>
|
||||
<FlatList
|
||||
style={{flex: 1}}
|
||||
contentContainerStyle={{ paddingBottom: 20 }}
|
||||
data={lines}
|
||||
extraData={lines}
|
||||
renderItem={({ item }) =>
|
||||
<View className='flex-1 items-center bg-red-200'>
|
||||
<>
|
||||
<Text className='text-xl text-center my-4'>{item.producto.nombre}</Text>
|
||||
</>
|
||||
</View>
|
||||
}
|
||||
keyExtractor={(item: SalesOrderLine) => String(item.producto.id)}
|
||||
/>
|
||||
{lines.map((line: SalesOrderLine) =>(<Text key={line.producto.id}>{line.producto.id}</Text>))}
|
||||
</ScrollView>
|
||||
)
|
||||
}
|
||||
|
||||
export default OneToMany
|
||||
@ -0,0 +1,4 @@
|
||||
interface Product {
|
||||
id: number;
|
||||
nombre: string;
|
||||
}
|
||||
@ -0,0 +1,69 @@
|
||||
import React, { FC, useContext, useEffect, useState } from 'react'
|
||||
import { FlatList, RefreshControl, Text, TouchableOpacity, View } from 'react-native'
|
||||
|
||||
import { useNavigation } from '@react-navigation/native';
|
||||
|
||||
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
|
||||
import { Avatar, Layout } from '@ui-kitten/components';
|
||||
import { CardItem } from '../../components/CardItem';
|
||||
import { SalesOrderContext } from './SalesOrderContex';
|
||||
|
||||
interface Props {
|
||||
entities: [],
|
||||
screenName: string,
|
||||
columnDisplay: string
|
||||
}
|
||||
|
||||
export const ProductItem: FC<Props> = ({ entities, screenName, columnDisplay }) => {
|
||||
|
||||
const navigation = useNavigation<NativeStackNavigationProp<any>>();
|
||||
const {lines, setLines, add} = useContext(SalesOrderContext);
|
||||
return (
|
||||
<>
|
||||
|
||||
<FlatList
|
||||
|
||||
data={entities}
|
||||
renderItem={({ item }) =>
|
||||
|
||||
<TouchableOpacity
|
||||
onPress={() => {
|
||||
// Pass and merge params back to home screen
|
||||
const newLine: SalesOrderLine = {
|
||||
producto: { id: item['id'], nombre: item["nombre"] },
|
||||
cantidad: 1,
|
||||
precio: 0
|
||||
}
|
||||
add(newLine)
|
||||
navigation.navigate(
|
||||
{
|
||||
name: screenName,
|
||||
params: { productId: item['id'] },
|
||||
merge: true,
|
||||
} as never
|
||||
);
|
||||
}}
|
||||
>
|
||||
<CardItem>
|
||||
<View className='flex-row'>
|
||||
<Avatar
|
||||
size='giant'
|
||||
source={{ uri: 'https://images.philips.com/is/image/PhilipsConsumer/271V8_69-IMS-en_HK?$jpglarge$&wid=1250' }}
|
||||
/>
|
||||
<Text className='mx-4'>
|
||||
{item[columnDisplay]}
|
||||
</Text>
|
||||
</View>
|
||||
|
||||
</CardItem>
|
||||
|
||||
</TouchableOpacity>
|
||||
|
||||
}
|
||||
keyExtractor={item => item["id"]}
|
||||
/>
|
||||
|
||||
|
||||
</>
|
||||
)
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
interface SalesOrder {
|
||||
id: number;
|
||||
numero: string;
|
||||
cliente: {
|
||||
id: number;
|
||||
};
|
||||
detalle: SalesOrderLine[];
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
import React, { createContext, useState } from 'react';
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||
|
||||
|
||||
type SalesOrderContextProps = {
|
||||
lines: SalesOrderLine[],
|
||||
add: (newLine:SalesOrderLine)=>void,
|
||||
remove: (productId: number)=>void,
|
||||
setLines: (lines: SalesOrderLine[])=>void
|
||||
}
|
||||
|
||||
export const SalesOrderContext = createContext({} as SalesOrderContextProps);
|
||||
|
||||
export const SalesOrderProvider = ({ children }: {children: JSX.Element | JSX.Element[]})=> {
|
||||
|
||||
const [lines, setLines] = useState<SalesOrderLine[]>([]);
|
||||
|
||||
const add = (newLine:SalesOrderLine) => {
|
||||
setLines([...lines,newLine]);
|
||||
}
|
||||
|
||||
const remove = (productId:number) => {
|
||||
setLines(lines.filter(line => line.producto.id === productId));
|
||||
}
|
||||
|
||||
return (
|
||||
<SalesOrderContext.Provider value={{
|
||||
lines,
|
||||
add,
|
||||
remove,
|
||||
setLines
|
||||
}}>
|
||||
{ children }
|
||||
</SalesOrderContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
@ -0,0 +1,6 @@
|
||||
interface SalesOrderLine {
|
||||
id?: number
|
||||
producto: Product,
|
||||
cantidad: number,
|
||||
precio: number
|
||||
}
|
||||
Loading…
Reference in new issue