Added validating claiming hours using shop setting
This commit is contained in:
@@ -17,12 +17,13 @@ const mapStateToProps = createStructuredSelector({
|
|||||||
technician: selectCurrentEmployee,
|
technician: selectCurrentEmployee,
|
||||||
});
|
});
|
||||||
|
|
||||||
export function LaborAllocationsTable({ jobId, bodyshop, technician }) {
|
export function LaborAllocationsTable({ jobId, bodyshop, technician,costCenterDiff,selectedCostCenter}) {
|
||||||
// console.log("LaborAllocationsTable, jobId", jobId);
|
// console.log("LaborAllocationsTable, costCenterDiff", costCenterDiff);
|
||||||
|
// console.log("LaborAllocationsTable, selectedCostCenter", selectedCostCenter);
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const onRefresh = async () => {
|
const onRefresh = async () => {
|
||||||
console.log("LaborAllocationsTable refetch");
|
// console.log("LaborAllocationsTable refetch");
|
||||||
return refetch();
|
return refetch();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -43,17 +44,28 @@ export function LaborAllocationsTable({ jobId, bodyshop, technician }) {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// console.log("LaborAllocationsTable useEffect on [all inputs] change",data?.joblines,data?.adjustments);
|
// console.log("LaborAllocationsTable useEffect on [all inputs] change",data?.joblines,data?.adjustments);
|
||||||
if (!!data?.joblines && !!data?.timetickets && !!bodyshop)
|
if (!!data?.joblines && !!data?.timetickets && !!bodyshop){
|
||||||
setTotals(
|
let temptotals = CalculateAllocationsTotals(
|
||||||
CalculateAllocationsTotals(
|
bodyshop,
|
||||||
bodyshop,
|
data?.joblines,
|
||||||
data?.joblines,
|
data?.timetickets,
|
||||||
data?.timetickets,
|
data?.adjustments
|
||||||
data?.adjustments
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
if(!!selectedCostCenter){
|
||||||
|
let tempCostCenterDiff = Math.round(
|
||||||
|
temptotals.find(
|
||||||
|
(total) =>
|
||||||
|
total["cost_center"] === selectedCostCenter.label
|
||||||
|
)?.difference * 10
|
||||||
|
) / 10;
|
||||||
|
costCenterDiff.current= tempCostCenterDiff;
|
||||||
|
}
|
||||||
|
setTotals(
|
||||||
|
temptotals
|
||||||
|
);
|
||||||
|
}
|
||||||
if (!jobId) setTotals([]);
|
if (!jobId) setTotals([]);
|
||||||
}, [data?.joblines, data?.timetickets, bodyshop, data?.adjustments, jobId]);
|
}, [data?.joblines, data?.timetickets, bodyshop, data?.adjustments, jobId,selectedCostCenter]);
|
||||||
|
|
||||||
const summary =
|
const summary =
|
||||||
totals &&
|
totals &&
|
||||||
@@ -70,9 +82,11 @@ export function LaborAllocationsTable({ jobId, bodyshop, technician }) {
|
|||||||
// console.log("labor summary is:", summary);
|
// console.log("labor summary is:", summary);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={{ flexGrow: 1 }}>
|
<View style={{ flex: 1}}>
|
||||||
{typeof data !== "undefined" ? (
|
{typeof data !== "undefined" ? (
|
||||||
<View style={{ flexGrow: 1 }}>
|
<Card style={{ flex: 1 }}>
|
||||||
|
<Card.Title><Text>Labor Allocations</Text></Card.Title>
|
||||||
|
<Card.Content>
|
||||||
<DataTable>
|
<DataTable>
|
||||||
<View style={localStyles.headerArea}>
|
<View style={localStyles.headerArea}>
|
||||||
<Text style={localStyles.headertext}>Cost Center</Text>
|
<Text style={localStyles.headertext}>Cost Center</Text>
|
||||||
@@ -87,9 +101,6 @@ export function LaborAllocationsTable({ jobId, bodyshop, technician }) {
|
|||||||
<DataTable>
|
<DataTable>
|
||||||
<FlatList
|
<FlatList
|
||||||
data={totals}
|
data={totals}
|
||||||
refreshControl={
|
|
||||||
<RefreshControl refreshing={loading} onRefresh={onRefresh} />
|
|
||||||
}
|
|
||||||
keyExtractor={(item) => item.cost_center}
|
keyExtractor={(item) => item.cost_center}
|
||||||
ItemSeparatorComponent={<Divider orientation="vertical" />}
|
ItemSeparatorComponent={<Divider orientation="vertical" />}
|
||||||
renderItem={(object) => (
|
renderItem={(object) => (
|
||||||
@@ -147,7 +158,9 @@ export function LaborAllocationsTable({ jobId, bodyshop, technician }) {
|
|||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
</DataTable>
|
</DataTable>
|
||||||
</View>
|
</Card.Content>
|
||||||
|
|
||||||
|
</Card>
|
||||||
) : null}
|
) : null}
|
||||||
{/* use "totals" for the rows in the table */}
|
{/* use "totals" for the rows in the table */}
|
||||||
{/* use "summary" for the totals at the bottom */}
|
{/* use "summary" for the totals at the bottom */}
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
import { Formik } from "formik";
|
import { Formik } from "formik";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState, useRef } from "react";
|
||||||
import { StyleSheet, Text, View, ScrollView } from "react-native";
|
import { StyleSheet, Text, View, ScrollView } from "react-native";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { createStructuredSelector } from "reselect";
|
import { createStructuredSelector } from "reselect";
|
||||||
import { Button, TextInput, Card } from "react-native-paper";
|
import { Button, TextInput, Card, Headline, Subheading } from "react-native-paper";
|
||||||
import CostCenterSelect from "../Selects/select-cost-center";
|
import CostCenterSelect from "../Selects/select-cost-center";
|
||||||
import {
|
import {
|
||||||
selectCurrentEmployee,
|
selectCurrentEmployee,
|
||||||
selectRates,
|
selectRates,
|
||||||
} from "../../redux/employee/employee.selectors";
|
} from "../../redux/employee/employee.selectors";
|
||||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
import { selectBodyshop,selectRestrictClaimableHoursFlag } from "../../redux/user/user.selectors";
|
||||||
import LaborAllocationsTable from "../labor-allocations-table/labor-allocations-table.component";
|
import LaborAllocationsTable from "../labor-allocations-table/labor-allocations-table.component";
|
||||||
import { UPDATE_TIME_TICKET } from "../../graphql/timetickets.queries";
|
import { UPDATE_TIME_TICKET } from "../../graphql/timetickets.queries";
|
||||||
import { useMutation } from "@apollo/client";
|
import { useMutation } from "@apollo/client";
|
||||||
@@ -20,6 +20,8 @@ import { timeTicketClockOutStart } from "../../redux/timetickets/timetickets.act
|
|||||||
import { logImEXEvent } from "../../firebase/firebase.analytics";
|
import { logImEXEvent } from "../../firebase/firebase.analytics";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { useNavigation } from "@react-navigation/native";
|
import { useNavigation } from "@react-navigation/native";
|
||||||
|
import styles from "../styles";
|
||||||
|
import StyleRepeater from "../style-repeater/style-repeater";
|
||||||
// import { selectCurrentTimeTicketJobId } from "../../redux/timetickets/timetickets.selectors";
|
// import { selectCurrentTimeTicketJobId } from "../../redux/timetickets/timetickets.selectors";
|
||||||
|
|
||||||
import { QUERY_ACTIVE_TIME_TICKETS } from "../../graphql/timetickets.queries";
|
import { QUERY_ACTIVE_TIME_TICKETS } from "../../graphql/timetickets.queries";
|
||||||
@@ -28,6 +30,7 @@ const mapStateToProps = createStructuredSelector({
|
|||||||
currentRatesNCostCenters: selectRates,
|
currentRatesNCostCenters: selectRates,
|
||||||
currentBodyshop: selectBodyshop,
|
currentBodyshop: selectBodyshop,
|
||||||
currentTmTicketJobId: selectCurrentTmTicketJobId,
|
currentTmTicketJobId: selectCurrentTmTicketJobId,
|
||||||
|
currentRestrictClaimableHoursFlag: selectRestrictClaimableHoursFlag
|
||||||
});
|
});
|
||||||
const mapDispatchToProps = (dispatch) => ({
|
const mapDispatchToProps = (dispatch) => ({
|
||||||
timeTicketClockOutStart,
|
timeTicketClockOutStart,
|
||||||
@@ -38,8 +41,19 @@ export function TimeTicketClockOff({
|
|||||||
currentRatesNCostCenters,
|
currentRatesNCostCenters,
|
||||||
currentBodyshop,
|
currentBodyshop,
|
||||||
currentTmTicketJobId,
|
currentTmTicketJobId,
|
||||||
|
currentRestrictClaimableHoursFlag,
|
||||||
route,
|
route,
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
|
const costCenterDiff = useRef(0);
|
||||||
|
// console.log("TimeTicketClockOff, costCenterDiff :", costCenterDiff);
|
||||||
|
|
||||||
|
|
||||||
|
const setCostCenterDiff = (value) => {
|
||||||
|
countRef.current = val;
|
||||||
|
console.log(`Button clicked ${countRef.current} times`);
|
||||||
|
};
|
||||||
|
|
||||||
const navigation = useNavigation();
|
const navigation = useNavigation();
|
||||||
const { timeTicketId } = route.params;
|
const { timeTicketId } = route.params;
|
||||||
// console.log("TimeTicketClockOff, timeTicketId :", timeTicketId);
|
// console.log("TimeTicketClockOff, timeTicketId :", timeTicketId);
|
||||||
@@ -74,6 +88,15 @@ export function TimeTicketClockOff({
|
|||||||
setError({ message: t("timeticketclockoff.errors.missingvalues") });
|
setError({ message: t("timeticketclockoff.errors.missingvalues") });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// console.log("TimeTicketClockOff, currentRestrictClaimableHoursFlag :", currentRestrictClaimableHoursFlag);
|
||||||
|
if(!!currentRestrictClaimableHoursFlag){
|
||||||
|
// console.log("TimeTicketClockOff, currentRestrictClaimableHoursFlag I am here:", currentRestrictClaimableHoursFlag);
|
||||||
|
if (values.productivehours > costCenterDiff.current){
|
||||||
|
setError({ message: t("timeticketclockoff.errors.hoursenteredmorethanavailable") });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const tempcallobj = {
|
const tempcallobj = {
|
||||||
variables: {
|
variables: {
|
||||||
timeticketId: timeTicketId,
|
timeticketId: timeTicketId,
|
||||||
@@ -117,18 +140,19 @@ export function TimeTicketClockOff({
|
|||||||
// console.log("updateTimeticket, result :", result);
|
// console.log("updateTimeticket, result :", result);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
if (!!result.errors) {
|
if (!!result.errors) {
|
||||||
// console.log("updateTimeticket, result.error :", result.errors);
|
console.log("updateTimeticket, result.error :", result.errors);
|
||||||
setError(JSON.stringify(result.errors));
|
setError(JSON.stringify(result.errors));
|
||||||
} else {
|
} else {
|
||||||
// console.log("updateTimeticket, result :", result.data);
|
console.log("updateTimeticket, result :", result.data);
|
||||||
navigation.goBack();
|
navigation.goBack();
|
||||||
}
|
}
|
||||||
//if (completedCallback) completedCallback();
|
//if (completedCallback) completedCallback();
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<View style={localStyles.content}>
|
<View style={styles.cardBackground}>
|
||||||
<ScrollView contentContainerStyle={{ flexGrow: 1 }}>
|
{/* style={localStyles.content}> */}
|
||||||
<Card>
|
<StyleRepeater childStyle={{ margin: 4 }}>
|
||||||
|
<Card>
|
||||||
<Formik
|
<Formik
|
||||||
initialValues={{
|
initialValues={{
|
||||||
costcenter: { currentSCC },
|
costcenter: { currentSCC },
|
||||||
@@ -174,10 +198,8 @@ export function TimeTicketClockOff({
|
|||||||
)}
|
)}
|
||||||
</Formik>
|
</Formik>
|
||||||
</Card>
|
</Card>
|
||||||
</ScrollView>
|
<LaborAllocationsTable jobId={currentTmTicketJobId} costCenterDiff={costCenterDiff} selectedCostCenter={currentSCC}/>
|
||||||
<View style={{ flexGrow: 1 }}>
|
</StyleRepeater>
|
||||||
<LaborAllocationsTable jobId={currentTmTicketJobId} />
|
|
||||||
</View>
|
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ export const QUERY_BODYSHOP = gql`
|
|||||||
features
|
features
|
||||||
localmediatoken
|
localmediatoken
|
||||||
tt_allow_post_to_invoiced
|
tt_allow_post_to_invoiced
|
||||||
md_responsibility_centers
|
md_responsibility_centers
|
||||||
|
tt_enforce_hours_for_tech_console
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -31,3 +31,15 @@ export const selectSigningIn = createSelector(
|
|||||||
[selectUser],
|
[selectUser],
|
||||||
(user) => user.signingIn
|
(user) => user.signingIn
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const selectRestrictClaimableHoursFlag = createSelector(
|
||||||
|
[selectUser],
|
||||||
|
(user) => {
|
||||||
|
if (!user.bodyshop || !user.bodyshop.tt_enforce_hours_for_tech_console) {
|
||||||
|
console.info("selectRestrictClaimableHoursFlag returning null");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
console.info("selectRestrictClaimableHoursFlag returning :", user.bodyshop.tt_enforce_hours_for_tech_console);
|
||||||
|
return user.bodyshop.tt_enforce_hours_for_tech_console;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|||||||
@@ -473,7 +473,8 @@
|
|||||||
},
|
},
|
||||||
"errors": {
|
"errors": {
|
||||||
"nan": "Please make sure all fields have valid values.",
|
"nan": "Please make sure all fields have valid values.",
|
||||||
"missingvalues": "Please make sure all fields have a value."
|
"missingvalues": "Please make sure all fields have a value.",
|
||||||
|
"hoursenteredmorethanavailable": "The number of hours entered is more than what is available for this cost center."
|
||||||
},
|
},
|
||||||
"titles": {
|
"titles": {
|
||||||
"clockoff": "Clock Off"
|
"clockoff": "Clock Off"
|
||||||
|
|||||||
@@ -473,7 +473,8 @@
|
|||||||
},
|
},
|
||||||
"errors": {
|
"errors": {
|
||||||
"nan": "",
|
"nan": "",
|
||||||
"missingvalues": ""
|
"missingvalues": "",
|
||||||
|
"hoursenteredmorethanavailable": ""
|
||||||
},
|
},
|
||||||
"titles": {
|
"titles": {
|
||||||
"clockoff": ""
|
"clockoff": ""
|
||||||
|
|||||||
@@ -473,7 +473,8 @@
|
|||||||
},
|
},
|
||||||
"errors": {
|
"errors": {
|
||||||
"nan": "",
|
"nan": "",
|
||||||
"missingvalues": ""
|
"missingvalues": "",
|
||||||
|
"hoursenteredmorethanavailable": ""
|
||||||
},
|
},
|
||||||
"titles": {
|
"titles": {
|
||||||
"clockoff": ""
|
"clockoff": ""
|
||||||
|
|||||||
Reference in New Issue
Block a user