update laboralloctable
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import React, { useEffect, useMemo, useState } from "react";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FlatList, RefreshControl, StyleSheet, Text, View } from "react-native";
|
||||
import { FlatList, StyleSheet, Text, View } from "react-native";
|
||||
import _ from "lodash";
|
||||
import { ActivityIndicator, Card, DataTable, Divider } from "react-native-paper";
|
||||
import { GET_LINE_TICKET_BY_PK } from "../../graphql/jobs.queries";
|
||||
@@ -18,34 +18,19 @@ const mapStateToProps = createStructuredSelector({
|
||||
});
|
||||
|
||||
export function LaborAllocationsTable({ jobId, bodyshop, technician,costCenterDiff,selectedCostCenter, style, shouldRefresh}) {
|
||||
// console.log("LaborAllocationsTable, costCenterDiff", costCenterDiff);
|
||||
// console.log("LaborAllocationsTable, selectedCostCenter", selectedCostCenter);
|
||||
const { t } = useTranslation();
|
||||
|
||||
const onRefresh = async () => {
|
||||
// console.log("LaborAllocationsTable refetch");
|
||||
return refetch();
|
||||
};
|
||||
|
||||
const onRefresh = async () => { return refetch(); };
|
||||
const { loading, error, data, refetch } = useQuery(GET_LINE_TICKET_BY_PK, {
|
||||
variables: { id: jobId },
|
||||
skip: !!!jobId,
|
||||
fetchPolicy: "network-only",
|
||||
nextFetchPolicy: "network-only",
|
||||
});
|
||||
|
||||
// console.log("LaborAllocationsTable, data", data);
|
||||
if (error) return <ErrorDisplay errorMessage={error.message} />;
|
||||
|
||||
// if (loading) return <ActivityIndicator color="dodgerblue" size="large" />;
|
||||
const [totals, setTotals] = useState([]);
|
||||
|
||||
// useEffect(() => {
|
||||
// // console.log("LaborAllocationsTable useEffect on data change");
|
||||
// }, [data]);
|
||||
|
||||
useEffect(() => {
|
||||
// console.log("LaborAllocationsTable useEffect on [all inputs] change",data?.joblines,data?.adjustments);
|
||||
if (!!data?.joblines && !!data?.timetickets && !!bodyshop){
|
||||
let temptotals = CalculateAllocationsTotals(
|
||||
bodyshop,
|
||||
@@ -70,7 +55,6 @@ export function LaborAllocationsTable({ jobId, bodyshop, technician,costCenterDi
|
||||
}, [data?.joblines, data?.timetickets, bodyshop, data?.adjustments, jobId, selectedCostCenter]);
|
||||
|
||||
useEffect(() => {
|
||||
// console.log("made it here, shouldRefresh is :", shouldRefresh );
|
||||
!!shouldRefresh && shouldRefresh ? onRefresh() : null
|
||||
},[shouldRefresh]);
|
||||
|
||||
@@ -86,22 +70,21 @@ export function LaborAllocationsTable({ jobId, bodyshop, technician,costCenterDi
|
||||
},
|
||||
{ hrs_total: 0, hrs_claimed: 0, adjustments: 0, difference: 0 }
|
||||
);
|
||||
// console.log("labor summary is:", summary);
|
||||
|
||||
if (loading) return <ActivityIndicator color="dodgerblue" size="large" />;
|
||||
return (
|
||||
<View style={style}>
|
||||
{typeof data !== "undefined" ? (
|
||||
<Card style={{ flex: 1 }}>
|
||||
<Card.Title title={"Labor Allocations"} />
|
||||
<Card.Title title={t("laborallocations.labels.laborallocations")} />
|
||||
<Card.Content>
|
||||
<View style={localStyles.headerArea}>
|
||||
<Text style={localStyles.headertext}>Cost Center</Text>
|
||||
<Text style={localStyles.headertext}>Hours Total</Text>
|
||||
<Text style={localStyles.headertext}>Hours Claimed</Text>
|
||||
<Text style={localStyles.headertext}>{t("laborallocations.labels.costcenter")}</Text>
|
||||
<Text style={localStyles.headertext}>{t("laborallocations.labels.hourstotal")}</Text>
|
||||
<Text style={localStyles.headertext}>{t("laborallocations.labels.hoursclaimed")}</Text>
|
||||
{/* <Text numberOfLines={2} style={{ flex: 1, flexWrap:'wrap' }}>Hours Claimed</Text> */}
|
||||
<Text style={localStyles.headertextAdjusts}>Adjustments</Text>
|
||||
<Text style={localStyles.headertext}>Difference</Text>
|
||||
<Text style={localStyles.headertextAdjusts}>{t("laborallocations.labels.adjustments")}</Text>
|
||||
<Text style={localStyles.headertext}>{t("laborallocations.labels.difference")}</Text>
|
||||
</View>
|
||||
<Divider orientation="vertical" />
|
||||
<DataTable>
|
||||
@@ -148,7 +131,7 @@ export function LaborAllocationsTable({ jobId, bodyshop, technician,costCenterDi
|
||||
/>
|
||||
{summary && (
|
||||
<View style={localStyles.headerArea}>
|
||||
<Text style={localStyles.footertext}>Totals</Text>
|
||||
<Text style={localStyles.footertext}>{t("laborallocations.labels.totals")}</Text>
|
||||
<Text style={localStyles.footertext}>
|
||||
{summary.hrs_total.toFixed(1)}
|
||||
</Text>
|
||||
|
||||
Reference in New Issue
Block a user