Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FFT-173 Remove toggle from Edit Forecast and related code #616

Merged
merged 4 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(SET_CELLS({ cells: rows }));
} else {
timer();
Expand All @@ -52,7 +40,7 @@ function EditForecast() {
};

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

useEffect(() => {
const capturePaste = (event) => {
Expand Down Expand Up @@ -328,15 +316,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 @@ -356,10 +335,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
34 changes: 8 additions & 26 deletions front_end/src/Components/TableCell/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,13 @@ 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 isPayrollEnabled = JSON.parse(localStorage.getItem("isPayrollEnabled"));

const TableCell = ({ rowIndex, cellId, cellKey, sheetUpdating }) => {
const dispatch = useDispatch();

const row = useSelector((state) => state.allCells.cells[rowIndex]);
const cell = row[cellKey];
const isEditing = useSelector((state) => state.edit.cellId === cellId);

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 isRowSelected = useSelector(
Expand Down Expand Up @@ -72,7 +55,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 @@ -131,11 +113,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(SET_CELLS({ cells: rows }));
} else {
dispatch(
Expand Down Expand Up @@ -225,8 +203,12 @@ const TableCell = ({
className={getClasses()}
id={getId()}
onDoubleClick={() => {
if (isEditable && !isOverride()) {
dispatch(SET_EDITING_CELL({ cellId: cellId }));
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
Loading