Skip to content

Commit

Permalink
Remove toggle from Edit Forecast and related code
Browse files Browse the repository at this point in the history
  • Loading branch information
CaitBarnard authored and SamDudley committed Feb 10, 2025
1 parent 20e64e4 commit 2eb45e0
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 115 deletions.
4 changes: 0 additions & 4 deletions forecast/templates/forecast/edit/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,12 @@
</form>
{% endblock %}
{% block scripts %}
{{ view.get_payroll_forecast_report|json_script:'payroll_forecast_data' }}
{% can_access_edit_payroll user as user_can_access_edit_payroll %}
<script>
window.actuals = {{ actuals|safe }};
window.period_display = {{ period_display|safe }};
window.table_data = {{ forecast_dump|safe }};
window.cost_centre = {{ view.cost_centre_details.cost_centre_code|safe }};
window.financial_year = {{ view.financial_year|safe }};
window.payroll_forecast_data = JSON.parse(document.getElementById("payroll_forecast_data").textContent);
window.can_access_edit_payroll = "{{ user_can_access_edit_payroll }}";
</script>
{% vite_dev_client %}
{% vite_js 'src/index.jsx' %}
Expand Down
13 changes: 1 addition & 12 deletions forecast/views/edit_forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.db import transaction
from django.db.models import Exists, OuterRef, Prefetch, Q, Sum
from django.http import JsonResponse
from django.shortcuts import get_object_or_404, redirect
from django.shortcuts import redirect
from django.urls import reverse
from django.views.generic.base import TemplateView
from django.views.generic.edit import FormView
Expand Down Expand Up @@ -53,7 +53,6 @@
NoCostCentreCodeInURLError,
NoFinancialYearInURLError,
)
from payroll.services import payroll as payroll_service


UNAVAILABLE_FORECAST_EDIT_TITLE = "Forecast editing is locked"
Expand Down Expand Up @@ -531,16 +530,6 @@ def get_context_data(self, **kwargs):

return context

def get_payroll_forecast_report(self):
cost_centre_obj = get_object_or_404(CostCentre, pk=self.cost_centre_code)
financial_year_obj = get_object_or_404(FinancialYear, pk=self.financial_year)
queryset = payroll_service.payroll_forecast_report(
cost_centre_obj, financial_year_obj
)
data = list(queryset)

return data

@cached_property
def future_year_display(self):
if self._future_year_display is None:
Expand Down
30 changes: 3 additions & 27 deletions front_end/src/Components/EditForecast/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
UNSELECT_ALL,
} from "../../Reducers/Selected";
import { getCellId, postData, processForecastData } from "../../Util";
import ToggleCheckbox from "../Common/ToggleCheckbox";

function EditForecast() {
const dispatch = useDispatch();
Expand All @@ -27,23 +26,12 @@ function EditForecast() {
const editCellId = useSelector((state) => state.edit.cellId);

const [sheetUpdating, setSheetUpdating] = useState(false);
const [isPayrollEnabled, setIsPayrollEnabled] = useState(false);

const handleIsPayrollEnabled = () => {
setIsPayrollEnabled(!isPayrollEnabled);

localStorage.setItem("isPayrollEnabled", JSON.stringify(!isPayrollEnabled));
};

useEffect(() => {
const timer = () => {
setTimeout(() => {
if (window.table_data) {
let rows = processForecastData(
window.table_data,
window.payroll_forecast_data,
isPayrollEnabled,
);
let rows = processForecastData(window.table_data);
dispatch({
type: SET_CELLS,
cells: rows,
Expand All @@ -55,7 +43,7 @@ function EditForecast() {
};

timer();
}, [dispatch, isPayrollEnabled]);
}, [dispatch]);

useEffect(() => {
const capturePaste = (event) => {
Expand Down Expand Up @@ -334,15 +322,6 @@ function EditForecast() {

return (
<Fragment>
{window.can_access_edit_payroll === "True" && (
<ToggleCheckbox
toggle={isPayrollEnabled}
handler={handleIsPayrollEnabled}
id="payroll-forecast"
value="payroll"
label="Toggle payroll forecast rows"
/>
)}
{errorMessage != null && (
<div
className="govuk-error-summary"
Expand All @@ -362,10 +341,7 @@ function EditForecast() {
</div>
)}
<EditActionBar />
<Table
sheetUpdating={sheetUpdating}
payrollData={window.payroll_forecast_data}
/>
<Table sheetUpdating={sheetUpdating} />
</Fragment>
);
}
Expand Down
3 changes: 1 addition & 2 deletions front_end/src/Components/Table/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
UNSELECT_ALL,
} from "../../Reducers/Selected";

function Table({ rowData, sheetUpdating, payrollData }) {
function Table({ sheetUpdating }) {
const dispatch = useDispatch();
const rows = useSelector((state) => state.allCells.cells);

Expand Down Expand Up @@ -194,7 +194,6 @@ function Table({ rowData, sheetUpdating, payrollData }) {
<TableCell
key={nanoid()}
sheetUpdating={sheetUpdating}
payrollData={payrollData}
cellId={getCellId(rowIndex, value)}
rowIndex={rowIndex}
cellKey={value}
Expand Down
27 changes: 3 additions & 24 deletions front_end/src/Components/TableCell/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,8 @@ import { postData, processForecastData, formatValue } from "../../Util";
import { SET_ERROR } from "../../Reducers/Error";
import { SET_CELLS } from "../../Reducers/Cells";

const TableCell = ({
rowIndex,
cellId,
cellKey,
sheetUpdating,
payrollData,
}) => {
const TableCell = ({ rowIndex, cellId, cellKey, sheetUpdating }) => {
let editing = false;
const isPayrollEnabled = JSON.parse(localStorage.getItem("isPayrollEnabled"));

const checkValue = (val) => {
if (cellId === val) {
Expand Down Expand Up @@ -48,15 +41,6 @@ const TableCell = ({
const cell = row[cellKey];
const editCellId = useSelector((state) => state.edit.cellId, checkValue);

const isOverride = () => {
// Is override if cell exists, has an override amount and is not an actual
return cell && cell.overrideAmount !== null && cell.isEditable;
};

if (isOverride()) {
cell.amount = cell.overrideAmount;
}

const [isUpdating, setIsUpdating] = useState(false);

const selectedRow = useSelector(
Expand Down Expand Up @@ -110,7 +94,6 @@ const TableCell = ({
if (!cell) return classes.join(" ");

if (cell && cell.amount < 0) classes.push("negative");
if (isOverride()) classes.push("override");
if (wasEdited()) classes.push("edited");
isActual ? classes.push("is-actual") : classes.push("is-forecast");

Expand Down Expand Up @@ -169,11 +152,7 @@ const TableCell = ({
setIsUpdating(false);
if (response.status === 200) {
// TODO (FFT-100): Test paste to excel with locked payroll forecast rows
let rows = processForecastData(
response.data,
payrollData,
isPayrollEnabled,
);
let rows = processForecastData(response.data);
dispatch({
type: SET_CELLS,
cells: rows,
Expand Down Expand Up @@ -266,7 +245,7 @@ const TableCell = ({
className={getClasses()}
id={getId()}
onDoubleClick={() => {
if (isEditable && !isOverride()) {
if (isEditable) {
dispatch(
SET_EDITING_CELL({
cellId: cellId,
Expand Down
46 changes: 1 addition & 45 deletions front_end/src/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,8 @@ export async function postData(url = "", data = {}) {
};
}

export const processForecastData = (
forecastData,
payrollData = null,
isPayrollEnabled = false,
) => {
export const processForecastData = (forecastData) => {
let rows = [];
let mappedPayrollData = null;

if (isPayrollEnabled) {
mappedPayrollData = processPayrollData(payrollData);
}

let financialCodeCols = [
"analysis1_code",
Expand Down Expand Up @@ -167,35 +158,16 @@ export const processForecastData = (
colIndex++;
}

const forecastKey = makeFinancialCodeKey(
"",
rowData.programme,
rowData.natural_account_code,
{
analysis1: rowData.analysis1_code,
analysis2: rowData.analysis2_code,
project: rowData.project_code,
},
);

// eslint-disable-next-line
for (const [key, monthlyFigure] of Object.entries(
rowData["monthly_figures"],
)) {
let overrideAmount = null;

if (isPayrollEnabled && mappedPayrollData[forecastKey]) {
const period = months[parseInt(key)];
overrideAmount = mappedPayrollData[forecastKey][period];
}

row[monthlyFigure.month] = {
rowIndex: rowIndex,
colIndex: colIndex,
key: monthlyFigure.month,
amount: monthlyFigure.amount,
startingAmount: monthlyFigure.starting_amount,
overrideAmount: overrideAmount,
};

colIndex++;
Expand All @@ -207,22 +179,6 @@ export const processForecastData = (
return rows;
};

const processPayrollData = (payrollData) => {
const results = {};

for (const [key, value] of Object.entries(payrollData)) {
const generatedKey = makeFinancialCodeKey(
"",
value.programme_code,
value.natural_account_code,
);

results[generatedKey] = value;
}

return results;
};

export const makeFinancialCodeKey = (
costCentre,
programme,
Expand Down
1 change: 0 additions & 1 deletion front_end/styles/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ th {
background-color: rgba(86, 148, 202, 0.25);
}

.override,
.not-editable.is-forecast {
background-color: rgba(201, 155, 75, 0.25);

Expand Down

0 comments on commit 2eb45e0

Please sign in to comment.