Added validating claiming hours using shop setting

This commit is contained in:
jfrye122
2023-06-06 17:23:02 -04:00
parent 0889453998
commit ae8a0fb943
7 changed files with 85 additions and 34 deletions

View File

@@ -17,12 +17,13 @@ const mapStateToProps = createStructuredSelector({
technician: selectCurrentEmployee,
});
export function LaborAllocationsTable({ jobId, bodyshop, technician }) {
// console.log("LaborAllocationsTable, jobId", jobId);
export function LaborAllocationsTable({ jobId, bodyshop, technician,costCenterDiff,selectedCostCenter}) {
// console.log("LaborAllocationsTable, costCenterDiff", costCenterDiff);
// console.log("LaborAllocationsTable, selectedCostCenter", selectedCostCenter);
const { t } = useTranslation();
const onRefresh = async () => {
console.log("LaborAllocationsTable refetch");
// console.log("LaborAllocationsTable refetch");
return refetch();
};
@@ -43,17 +44,28 @@ export function LaborAllocationsTable({ jobId, bodyshop, technician }) {
useEffect(() => {
// console.log("LaborAllocationsTable useEffect on [all inputs] change",data?.joblines,data?.adjustments);
if (!!data?.joblines && !!data?.timetickets && !!bodyshop)
setTotals(
CalculateAllocationsTotals(
if (!!data?.joblines && !!data?.timetickets && !!bodyshop){
let temptotals = CalculateAllocationsTotals(
bodyshop,
data?.joblines,
data?.timetickets,
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([]);
}, [data?.joblines, data?.timetickets, bodyshop, data?.adjustments, jobId]);
}, [data?.joblines, data?.timetickets, bodyshop, data?.adjustments, jobId,selectedCostCenter]);
const summary =
totals &&
@@ -70,9 +82,11 @@ export function LaborAllocationsTable({ jobId, bodyshop, technician }) {
// console.log("labor summary is:", summary);
return (
<View style={{ flexGrow: 1 }}>
<View style={{ flex: 1}}>
{typeof data !== "undefined" ? (
<View style={{ flexGrow: 1 }}>
<Card style={{ flex: 1 }}>
<Card.Title><Text>Labor Allocations</Text></Card.Title>
<Card.Content>
<DataTable>
<View style={localStyles.headerArea}>
<Text style={localStyles.headertext}>Cost Center</Text>
@@ -87,9 +101,6 @@ export function LaborAllocationsTable({ jobId, bodyshop, technician }) {
<DataTable>
<FlatList
data={totals}
refreshControl={
<RefreshControl refreshing={loading} onRefresh={onRefresh} />
}
keyExtractor={(item) => item.cost_center}
ItemSeparatorComponent={<Divider orientation="vertical" />}
renderItem={(object) => (
@@ -147,7 +158,9 @@ export function LaborAllocationsTable({ jobId, bodyshop, technician }) {
</View>
)}
</DataTable>
</View>
</Card.Content>
</Card>
) : null}
{/* use "totals" for the rows in the table */}
{/* use "summary" for the totals at the bottom */}

View File

@@ -1,16 +1,16 @@
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 { useTranslation } from "react-i18next";
import { connect } from "react-redux";
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 {
selectCurrentEmployee,
selectRates,
} 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 { UPDATE_TIME_TICKET } from "../../graphql/timetickets.queries";
import { useMutation } from "@apollo/client";
@@ -20,6 +20,8 @@ import { timeTicketClockOutStart } from "../../redux/timetickets/timetickets.act
import { logImEXEvent } from "../../firebase/firebase.analytics";
import axios from "axios";
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 { QUERY_ACTIVE_TIME_TICKETS } from "../../graphql/timetickets.queries";
@@ -28,6 +30,7 @@ const mapStateToProps = createStructuredSelector({
currentRatesNCostCenters: selectRates,
currentBodyshop: selectBodyshop,
currentTmTicketJobId: selectCurrentTmTicketJobId,
currentRestrictClaimableHoursFlag: selectRestrictClaimableHoursFlag
});
const mapDispatchToProps = (dispatch) => ({
timeTicketClockOutStart,
@@ -38,8 +41,19 @@ export function TimeTicketClockOff({
currentRatesNCostCenters,
currentBodyshop,
currentTmTicketJobId,
currentRestrictClaimableHoursFlag,
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 { timeTicketId } = route.params;
// console.log("TimeTicketClockOff, timeTicketId :", timeTicketId);
@@ -74,6 +88,15 @@ export function TimeTicketClockOff({
setError({ message: t("timeticketclockoff.errors.missingvalues") });
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 = {
variables: {
timeticketId: timeTicketId,
@@ -117,17 +140,18 @@ export function TimeTicketClockOff({
// console.log("updateTimeticket, result :", result);
setLoading(false);
if (!!result.errors) {
// console.log("updateTimeticket, result.error :", result.errors);
console.log("updateTimeticket, result.error :", result.errors);
setError(JSON.stringify(result.errors));
} else {
// console.log("updateTimeticket, result :", result.data);
console.log("updateTimeticket, result :", result.data);
navigation.goBack();
}
//if (completedCallback) completedCallback();
};
return (
<View style={localStyles.content}>
<ScrollView contentContainerStyle={{ flexGrow: 1 }}>
<View style={styles.cardBackground}>
{/* style={localStyles.content}> */}
<StyleRepeater childStyle={{ margin: 4 }}>
<Card>
<Formik
initialValues={{
@@ -174,10 +198,8 @@ export function TimeTicketClockOff({
)}
</Formik>
</Card>
</ScrollView>
<View style={{ flexGrow: 1 }}>
<LaborAllocationsTable jobId={currentTmTicketJobId} />
</View>
<LaborAllocationsTable jobId={currentTmTicketJobId} costCenterDiff={costCenterDiff} selectedCostCenter={currentSCC}/>
</StyleRepeater>
</View>
);
}

View File

@@ -15,6 +15,7 @@ export const QUERY_BODYSHOP = gql`
localmediatoken
tt_allow_post_to_invoiced
md_responsibility_centers
tt_enforce_hours_for_tech_console
}
}
`;

View File

@@ -31,3 +31,15 @@ export const selectSigningIn = createSelector(
[selectUser],
(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;
}
);

View File

@@ -473,7 +473,8 @@
},
"errors": {
"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": {
"clockoff": "Clock Off"

View File

@@ -473,7 +473,8 @@
},
"errors": {
"nan": "",
"missingvalues": ""
"missingvalues": "",
"hoursenteredmorethanavailable": ""
},
"titles": {
"clockoff": ""

View File

@@ -473,7 +473,8 @@
},
"errors": {
"nan": "",
"missingvalues": ""
"missingvalues": "",
"hoursenteredmorethanavailable": ""
},
"titles": {
"clockoff": ""