gestion_user au lieu de gestion_ouvrier (qui est une ressource, donc en double avec gestionnaire_ressource) + filtre dans gestion_ressource pour avoir seulement les ressources du chantier courrant
This commit is contained in:
@@ -39,9 +39,9 @@ export default function TabLayout() {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<Tabs.Screen
|
<Tabs.Screen
|
||||||
name="gestion_ouvrier"
|
name="gestion_user"
|
||||||
options={{
|
options={{
|
||||||
title: 'Ouvriers',
|
title: 'Users',
|
||||||
tabBarIcon: ({ color }) => <IconSymbol size={28} name="person.fill" color={color} />,
|
tabBarIcon: ({ color }) => <IconSymbol size={28} name="person.fill" color={color} />,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -2,14 +2,11 @@ import { ThemedText } from "@/components/theme/themed-text";
|
|||||||
import { ThemedTextInput } from "@/components/theme/themed-textinput";
|
import { ThemedTextInput } from "@/components/theme/themed-textinput";
|
||||||
import { ThemedView } from "@/components/theme/themed-view";
|
import { ThemedView } from "@/components/theme/themed-view";
|
||||||
import Constants from "expo-constants"; //pour connaître la taille de la barre menu de l'OS en haut
|
import Constants from "expo-constants"; //pour connaître la taille de la barre menu de l'OS en haut
|
||||||
import { useLocalSearchParams, useRouter } from "expo-router";
|
import React, { useEffect, useState } from "react";
|
||||||
import React, { useEffect, useMemo, useState } from "react";
|
import { FlatList, StyleSheet, Text, View } from "react-native";
|
||||||
import { FlatList, Image, StyleSheet, Text, View } from "react-native";
|
|
||||||
import { getUsers } from "@/services/ressourcesService";
|
import { getUsers } from "@/services/ressourcesService";
|
||||||
import { useChantier } from "../ContextChantier";
|
|
||||||
import SelectChantier from "@/components/selectChantier";
|
import SelectChantier from "@/components/selectChantier";
|
||||||
import { Ressources } from "@/class/class";
|
import { User } from "@/class/class";
|
||||||
import { getRessources } from "@/services/ressourcesService";
|
|
||||||
|
|
||||||
type Concert = {
|
type Concert = {
|
||||||
group: string;
|
group: string;
|
||||||
@@ -22,19 +19,15 @@ type Concert = {
|
|||||||
favorite: boolean;
|
favorite: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function GestionOuvrier() {
|
export default function GestionUser() {
|
||||||
const router = useRouter();
|
|
||||||
const { nom, prenom } = useLocalSearchParams(); // Recup data ecran precedent
|
|
||||||
const [search, setSearch] = useState("");
|
const [search, setSearch] = useState("");
|
||||||
const { chantier, setChantier } = useChantier();
|
const [users, setUsers] = useState<User[]>([]);
|
||||||
const [artisans, setRessources] = useState<Ressources[]>([]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function loadData() {
|
async function loadData() {
|
||||||
try {
|
try {
|
||||||
//Nous ne gardons que les Ouvriers, qui peuvent être assignés à un chantier
|
const data = (await getUsers());
|
||||||
const data = (await getRessources()).filter(u => u.type === "Ouvrier");
|
setUsers(data);
|
||||||
setRessources(data);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Erreur lors du chargement :", error);
|
console.error("Erreur lors du chargement :", error);
|
||||||
}
|
}
|
||||||
@@ -42,17 +35,15 @@ export default function GestionOuvrier() {
|
|||||||
loadData();
|
loadData();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const renderItem = ({ item, index }: { item?: Ressources; index: number }) => {
|
const renderItem = ({ item, index }: { item?: User; index: number }) => {
|
||||||
if (!item) {
|
if (!item) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<ThemedView lvl={1} shadow={true} style={styles.card}>
|
<ThemedView lvl={1} shadow={true} style={styles.card}>
|
||||||
<ThemedView lvl={1} style={styles.info}>
|
<ThemedView lvl={1} style={styles.info}>
|
||||||
<Image source={{ uri: item.Image }} style={styles.image} />
|
<ThemedText style={styles.group}>{item.name} {item.last_name}</ThemedText>
|
||||||
<ThemedText style={styles.group}>{item.name}</ThemedText>
|
<ThemedText>{item.role}</ThemedText>
|
||||||
<ThemedText>{item.quantity}</ThemedText>
|
|
||||||
<ThemedText>{item.type}</ThemedText>
|
|
||||||
</ThemedView>
|
</ThemedView>
|
||||||
</ThemedView>
|
</ThemedView>
|
||||||
);
|
);
|
||||||
@@ -67,7 +58,7 @@ export default function GestionOuvrier() {
|
|||||||
|
|
||||||
|
|
||||||
<FlatList
|
<FlatList
|
||||||
data={artisans}
|
data={users}
|
||||||
renderItem={renderItem}
|
renderItem={renderItem}
|
||||||
keyExtractor={(_, index) => index.toString()}
|
keyExtractor={(_, index) => index.toString()}
|
||||||
contentContainerStyle={{ paddingBottom: 40 }}
|
contentContainerStyle={{ paddingBottom: 40 }}
|
||||||
@@ -8,19 +8,25 @@ import { useLocalSearchParams, useRouter } from "expo-router";
|
|||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { FlatList, Image, StyleSheet, Text, View } from "react-native";
|
import { FlatList, Image, StyleSheet, Text, View } from "react-native";
|
||||||
import { Ressources } from "../../class/class";
|
import { Ressources } from "../../class/class";
|
||||||
import { getRessources } from "../../services/ressourcesService";
|
import { getReservations, getRessources } from "../../services/ressourcesService";
|
||||||
import SelectChantier from "@/components/selectChantier";
|
import SelectChantier from "@/components/selectChantier";
|
||||||
import { useRessources } from "../ContextRessource";
|
import { useRessources } from "../ContextRessource";
|
||||||
|
import { useChantier } from "../ContextChantier";
|
||||||
|
import { getNbUseRessources, getNbUseRessourcesInChantier, isInChantier } from "@/class/utils";
|
||||||
|
import { useReservations } from "../ContextReservation";
|
||||||
|
|
||||||
export default function GestionnaireRessource() {
|
export default function GestionnaireRessource() {
|
||||||
const [search, setSearch] = useState("");
|
const [search, setSearch] = useState("");
|
||||||
const {ressources, setRessources} = useRessources();
|
const {ressources, setRessources} = useRessources();
|
||||||
|
const {reservations, setReservations} = useReservations();
|
||||||
|
const {chantier, setChantier} = useChantier();
|
||||||
const [filterType, setFilterType] = useState("Tout");
|
const [filterType, setFilterType] = useState("Tout");
|
||||||
const [showFilterMenu, setShowFilterMenu] = useState(false);
|
const [showFilterMenu, setShowFilterMenu] = useState(false);
|
||||||
|
const [filterChantier, setFilterChantier] = useState(false);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function loadData() {
|
async function loadDataRessources() {
|
||||||
try {
|
try {
|
||||||
const data = await getRessources();
|
const data = await getRessources();
|
||||||
setRessources(data);
|
setRessources(data);
|
||||||
@@ -28,13 +34,23 @@ export default function GestionnaireRessource() {
|
|||||||
console.error("Erreur lors du chargement :", error);
|
console.error("Erreur lors du chargement :", error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
loadData();
|
async function loadDataReservations() {
|
||||||
|
try {
|
||||||
|
const data = await getReservations();
|
||||||
|
setReservations(data);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Erreur lors du chargement :", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
loadDataRessources();
|
||||||
|
loadDataReservations();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const filteredData = ressources.filter((r) => {
|
const filteredData = ressources.filter((r) => {
|
||||||
const matchName = r.name.toLowerCase().includes(search.toLowerCase());
|
const matchName = r.name.toLowerCase().includes(search.toLowerCase());
|
||||||
const matchType = filterType === "Tout" || r.type === filterType;
|
const matchType = filterType === "Tout" || r.type === filterType;
|
||||||
return matchName && matchType;
|
|
||||||
|
return matchName && matchType && (!filterChantier || (chantier && isInChantier(r,chantier,reservations)));
|
||||||
});
|
});
|
||||||
|
|
||||||
const renderRessource = ({ item }: { item: Ressources }) => {
|
const renderRessource = ({ item }: { item: Ressources }) => {
|
||||||
@@ -43,11 +59,13 @@ export default function GestionnaireRessource() {
|
|||||||
<ThemedView lvl={1} shadow={true} style={styles.card}>
|
<ThemedView lvl={1} shadow={true} style={styles.card}>
|
||||||
<Image source={{ uri: item.Image }} style={styles.image} />
|
<Image source={{ uri: item.Image }} style={styles.image} />
|
||||||
<ThemedView lvl={1} style={styles.info}>
|
<ThemedView lvl={1} style={styles.info}>
|
||||||
<ThemedText>Id : {item.id}</ThemedText>
|
|
||||||
<ThemedText>Nom : {item.name}</ThemedText>
|
<ThemedText>Nom : {item.name}</ThemedText>
|
||||||
<ThemedText>Type : {item.type}</ThemedText>
|
<ThemedText>Type : {item.type}</ThemedText>
|
||||||
<ThemedText>Quantité totale : {item.quantity}</ThemedText>
|
<ThemedText>Quantité totale : {item.quantity}</ThemedText>
|
||||||
<ThemedText>Quantité disponible : {item.available_quantity}</ThemedText>
|
<ThemedText>Quantité disponible : {item.quantity-getNbUseRessources(item, reservations)}</ThemedText>
|
||||||
|
{filterChantier&&chantier &&
|
||||||
|
<ThemedText>Quantité utilisé dans le chantier : {getNbUseRessourcesInChantier(item,chantier, reservations)}</ThemedText>
|
||||||
|
}
|
||||||
</ThemedView>
|
</ThemedView>
|
||||||
</ThemedView>
|
</ThemedView>
|
||||||
);
|
);
|
||||||
@@ -84,15 +102,16 @@ export default function GestionnaireRessource() {
|
|||||||
>
|
>
|
||||||
<ThemedText style={{ textAlign: "center" }}>{t}</ThemedText>
|
<ThemedText style={{ textAlign: "center" }}>{t}</ThemedText>
|
||||||
</ThemedButton>
|
</ThemedButton>
|
||||||
|
|
||||||
))}
|
))}
|
||||||
|
|
||||||
{/* Bouton "Fermer" remplacé */}
|
{/* Bouton "Fermer" remplacé */}
|
||||||
<ThemedButton
|
<ThemedButton
|
||||||
lvl={1}
|
lvl={1}
|
||||||
shadow={true}
|
shadow={true}
|
||||||
style={{ padding: 10, borderRadius: 8 }}
|
style={{ padding: 10, borderRadius: 8 }}
|
||||||
onPress={() => setShowFilterMenu(false)}
|
onPress={() => setShowFilterMenu(false)}
|
||||||
>
|
>
|
||||||
<ThemedText style={{ textAlign: "center" }}>Fermer</ThemedText>
|
<ThemedText style={{ textAlign: "center" }}>Fermer</ThemedText>
|
||||||
</ThemedButton>
|
</ThemedButton>
|
||||||
</ThemedView>
|
</ThemedView>
|
||||||
@@ -117,14 +136,22 @@ export default function GestionnaireRessource() {
|
|||||||
</ThemedView>
|
</ThemedView>
|
||||||
|
|
||||||
{/* Bouton filtre en haut à droite */}
|
{/* Bouton filtre en haut à droite */}
|
||||||
<ThemedButton
|
<View style={{flexDirection: "row", gap:5}}>
|
||||||
lvl={1}
|
<ThemedButton
|
||||||
shadow={true}
|
lvl={1}
|
||||||
style={{ padding: 10, borderRadius: 8, marginTop: 10 }}
|
shadow={true}
|
||||||
onPress={() => setShowFilterMenu(true)}
|
style={styles.button}
|
||||||
>
|
onPress={() => setShowFilterMenu(true)}
|
||||||
<ThemedText>{`Filtre: ${filterType}`}</ThemedText>
|
>
|
||||||
</ThemedButton>
|
<ThemedText>{`Filtre: ${filterType}`}</ThemedText>
|
||||||
|
</ThemedButton>
|
||||||
|
<ThemedButton style={styles.button}>
|
||||||
|
<ThemedText onPress={() => setFilterChantier(!filterChantier)}>
|
||||||
|
{filterChantier?"chantier courant":"tous"}
|
||||||
|
</ThemedText>
|
||||||
|
</ThemedButton>
|
||||||
|
</View>
|
||||||
|
|
||||||
</View>
|
</View>
|
||||||
}
|
}
|
||||||
ListEmptyComponent={
|
ListEmptyComponent={
|
||||||
@@ -214,4 +241,9 @@ const styles = StyleSheet.create({
|
|||||||
marginBottom: 20,
|
marginBottom: 20,
|
||||||
textAlign: "center",
|
textAlign: "center",
|
||||||
},
|
},
|
||||||
|
button:{
|
||||||
|
padding: 10,
|
||||||
|
borderRadius: 8,
|
||||||
|
marginTop: 10
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -28,4 +28,27 @@ export function getNbUseRessources(ressource:Ressources, allReservations:Reserva
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
return res;
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getNbUseRessourcesInChantier(ressource:Ressources,chantier: Chantier, allReservations:Reservation[]):number{
|
||||||
|
var res:number = 0;
|
||||||
|
getReservationOfRessource(ressource,allReservations).forEach(reserv => {
|
||||||
|
if(reserv.chantier.id === chantier.id && reserv.ressource.id===ressource.id){
|
||||||
|
res+=reserv.quantity;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isInChantier(ressource:Ressources, chantier: Chantier, allReservations:Reservation[]):boolean{
|
||||||
|
console.log(allReservations.length+ " --------------------------------");
|
||||||
|
const reservations:Reservation[] = getReservationOfRessource(ressource,allReservations);
|
||||||
|
var res=false;
|
||||||
|
reservations.forEach(reserv => {
|
||||||
|
console.log(reserv.chantier.id + " " + chantier.id)
|
||||||
|
if(reserv.chantier.id === chantier.id){
|
||||||
|
res=true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
@@ -18,23 +18,22 @@ export default function ChantierSummary({data,style , ...otherProps }: Props) {
|
|||||||
{data.chantier ? (
|
{data.chantier ? (
|
||||||
<ThemedView lvl={4} style={styles.chantier}>
|
<ThemedView lvl={4} style={styles.chantier}>
|
||||||
<View>
|
<View>
|
||||||
<Image source={{ uri:"https://cdn.discordapp.com/attachments/1425108443571945644/1427207643180826757/raw.png?ex=693f1a72&is=693dc8f2&hm=86ffb97145fc8d3aec822b87d99be233c98477d4424c1ef58f80eb81b17c7c80&" /*chantier.urlImg*/ }} style={styles.image} />
|
<Image source={{ uri:"" /*chantier.urlImg*/ }} style={styles.image} />
|
||||||
</View>
|
</View>
|
||||||
<View style={{flex: 1}}>
|
<View style={{flex: 1}}>
|
||||||
<ThemedText selectable={true}>Id: {data.chantier.id}</ThemedText>
|
|
||||||
<ThemedText selectable={true}>Objet: {data.chantier.name}</ThemedText>
|
<ThemedText selectable={true}>Objet: {data.chantier.name}</ThemedText>
|
||||||
<ThemedText selectable={true}>Adresse: {data.chantier.adresse}</ThemedText>
|
<ThemedText selectable={true}>Adresse: {data.chantier.adresse}</ThemedText>
|
||||||
<ThemedText selectable={true}>Chef de chantier: {data.chantier.chef.last_name}{" "}{data.chantier.chef.name}</ThemedText>
|
<ThemedText selectable={true}>Chef de chantier: {data.chantier.chef.last_name}{" "}{data.chantier.chef.name}</ThemedText>
|
||||||
<ThemedText selectable={true}>État: {data.chantier.etat}</ThemedText>
|
<ThemedText selectable={true}>État: {data.chantier.etat}</ThemedText>
|
||||||
<ThemedText selectable={true}>equipe:
|
<ThemedText selectable={true}>
|
||||||
{getNbItemReservation(data.chantier.equipe)} ({data.chantier.equipe.length} type{data.chantier.equipe.length>1&&"s"})
|
equipe: {getNbItemReservation(data.chantier.equipe)} ({data.chantier.equipe.length} type{data.chantier.equipe.length>1&&"s"})
|
||||||
</ThemedText>
|
</ThemedText>
|
||||||
<ThemedText selectable={true}>materiel:
|
<ThemedText selectable={true}>
|
||||||
{getNbItemReservation(data.chantier.materiel)} ({data.chantier.materiel.length} type{data.chantier.materiel.length>1&&"s"})
|
materiel: {getNbItemReservation(data.chantier.materiel)} ({data.chantier.materiel.length} type{data.chantier.materiel.length>1&&"s"})
|
||||||
|
</ThemedText>
|
||||||
|
<ThemedText selectable={true}>
|
||||||
|
vehicules: {getNbItemReservation(data.chantier.vehicules)} ({data.chantier.vehicules.length} type{data.chantier.vehicules.length>1&&"s"})
|
||||||
</ThemedText>
|
</ThemedText>
|
||||||
<ThemedText selectable={true}>vehicules:
|
|
||||||
{getNbItemReservation(data.chantier.vehicules)} ({data.chantier.vehicules.length} type{data.chantier.vehicules.length>1&&"s"})
|
|
||||||
</ThemedText>
|
|
||||||
</View>
|
</View>
|
||||||
</ThemedView>
|
</ThemedView>
|
||||||
) :
|
) :
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ export default function SelectChantier() {
|
|||||||
<Image source={{ uri:"https://cdn.discordapp.com/attachments/1425108443571945644/1427207643180826757/raw.png?ex=693f1a72&is=693dc8f2&hm=86ffb97145fc8d3aec822b87d99be233c98477d4424c1ef58f80eb81b17c7c80&" /*chantier.urlImg*/ }} style={styles.image} />
|
<Image source={{ uri:"https://cdn.discordapp.com/attachments/1425108443571945644/1427207643180826757/raw.png?ex=693f1a72&is=693dc8f2&hm=86ffb97145fc8d3aec822b87d99be233c98477d4424c1ef58f80eb81b17c7c80&" /*chantier.urlImg*/ }} style={styles.image} />
|
||||||
</View>
|
</View>
|
||||||
<View style={{flex: 1}}>
|
<View style={{flex: 1}}>
|
||||||
<ThemedText>Renovation: {item.name}</ThemedText>
|
<ThemedText>Objet: {item.name}</ThemedText>
|
||||||
<ThemedText>Adresse: {item.adresse}</ThemedText>
|
<ThemedText>Adresse: {item.adresse}</ThemedText>
|
||||||
<ThemedText>Chef de chantier: {item.chef.last_name}{" "}{item.chef.name}</ThemedText>
|
<ThemedText>Chef de chantier: {item.chef.last_name}{" "}{item.chef.name}</ThemedText>
|
||||||
<ThemedText>État: {item.etat}</ThemedText>
|
<ThemedText>État: {item.etat}</ThemedText>
|
||||||
@@ -138,7 +138,7 @@ export default function SelectChantier() {
|
|||||||
<ThemedView lvl={2} shadow={true} style={styles.window}>
|
<ThemedView lvl={2} shadow={true} style={styles.window}>
|
||||||
<AnimatedThemedButton style={animatedButtonStyle} lvl={isOpen ? 1 : 1} onPress={() => onPressOpen()}>
|
<AnimatedThemedButton style={animatedButtonStyle} lvl={isOpen ? 1 : 1} onPress={() => onPressOpen()}>
|
||||||
<ThemedText style={styles.buttonText}>
|
<ThemedText style={styles.buttonText}>
|
||||||
{isOpen ? "Fermer" : (chantier!=null ? chantier.adresse : "Chantier")}
|
{isOpen ? "Fermer" : (chantier!=null ? chantier.name : "Chantier")}
|
||||||
</ThemedText>
|
</ThemedText>
|
||||||
</AnimatedThemedButton>
|
</AnimatedThemedButton>
|
||||||
{isOpen && (
|
{isOpen && (
|
||||||
|
|||||||
@@ -219,8 +219,14 @@ async function convertReservation(res: any): Promise<Reservation|null> {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
id: res.id,
|
id: res.id,
|
||||||
chantier: chantierSnap.data() as Chantier,
|
chantier: {
|
||||||
ressource: ressourceSnap.data() as Ressources,
|
id: chantierSnap.id,
|
||||||
|
...(chantierSnap.data() as Omit<Chantier, "id">),
|
||||||
|
},
|
||||||
|
ressource: {
|
||||||
|
id: ressourceSnap.id,
|
||||||
|
...(ressourceSnap.data() as Omit<Ressources, "id">),
|
||||||
|
},
|
||||||
quantity: data.quantity,
|
quantity: data.quantity,
|
||||||
};
|
};
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user