diff --git a/components/labor-allocations-table/labor-allocations-table.component.jsx b/components/labor-allocations-table/labor-allocations-table.component.jsx index bfb3011..8a44a75 100644 --- a/components/labor-allocations-table/labor-allocations-table.component.jsx +++ b/components/labor-allocations-table/labor-allocations-table.component.jsx @@ -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( - bodyshop, - data?.joblines, - data?.timetickets, - data?.adjustments - ) + 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 ( - + {typeof data !== "undefined" ? ( - + + Labor Allocations + Cost Center @@ -87,9 +101,6 @@ export function LaborAllocationsTable({ jobId, bodyshop, technician }) { - } keyExtractor={(item) => item.cost_center} ItemSeparatorComponent={} renderItem={(object) => ( @@ -147,7 +158,9 @@ export function LaborAllocationsTable({ jobId, bodyshop, technician }) { )} - + + + ) : null} {/* use "totals" for the rows in the table */} {/* use "summary" for the totals at the bottom */} diff --git a/components/time-ticket/screen-time-ticket-clockoff.component.jsx b/components/time-ticket/screen-time-ticket-clockoff.component.jsx index 30ee77e..3fcadd6 100644 --- a/components/time-ticket/screen-time-ticket-clockoff.component.jsx +++ b/components/time-ticket/screen-time-ticket-clockoff.component.jsx @@ -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,18 +140,19 @@ 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 ( - - - + + {/* style={localStyles.content}> */} + + - - - - + + ); } diff --git a/graphql/bodyshop.queries.js b/graphql/bodyshop.queries.js index 64cd553..ad6c226 100644 --- a/graphql/bodyshop.queries.js +++ b/graphql/bodyshop.queries.js @@ -14,7 +14,8 @@ export const QUERY_BODYSHOP = gql` features localmediatoken tt_allow_post_to_invoiced - md_responsibility_centers + md_responsibility_centers + tt_enforce_hours_for_tech_console } } `; diff --git a/redux/user/user.selectors.js b/redux/user/user.selectors.js index b6b762a..de0c823 100644 --- a/redux/user/user.selectors.js +++ b/redux/user/user.selectors.js @@ -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; + } +); diff --git a/translations/en-US/common.json b/translations/en-US/common.json index 41fe116..5aabbc7 100644 --- a/translations/en-US/common.json +++ b/translations/en-US/common.json @@ -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" diff --git a/translations/es-MX/common.json b/translations/es-MX/common.json index 60f8aa7..145017f 100644 --- a/translations/es-MX/common.json +++ b/translations/es-MX/common.json @@ -473,7 +473,8 @@ }, "errors": { "nan": "", - "missingvalues": "" + "missingvalues": "", + "hoursenteredmorethanavailable": "" }, "titles": { "clockoff": "" diff --git a/translations/fr-CA/common.json b/translations/fr-CA/common.json index d6abc2d..c52eb80 100644 --- a/translations/fr-CA/common.json +++ b/translations/fr-CA/common.json @@ -473,7 +473,8 @@ }, "errors": { "nan": "", - "missingvalues": "" + "missingvalues": "", + "hoursenteredmorethanavailable": "" }, "titles": { "clockoff": ""