Skip to content

Commit

Permalink
Merge branch 'main' into fft-174/pay-uplift-display
Browse files Browse the repository at this point in the history
  • Loading branch information
CaitBarnard authored Feb 12, 2025
2 parents 7d53750 + 147a329 commit 9f82d7a
Show file tree
Hide file tree
Showing 26 changed files with 941 additions and 779 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,9 @@ ner_output_file.txt

# DB
.dumps/

# hide all .env.* file
.env.*
# except for the ones we explicit allow and need to checkin
!.env.example
!.env.ci
8 changes: 7 additions & 1 deletion config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@

from django.conf import settings
from django.contrib import admin
from django.urls import include, path
from django.http import HttpResponse
from django.urls import include, path, re_path
from django.views.generic.base import RedirectView


def empty_favicon(request):
return HttpResponse(status=204)


urlpatterns = [
path("auth/", include("authbroker_client.urls", namespace="authbroker")),
path("", include("core.urls")), # default to core with no path
Expand All @@ -38,6 +43,7 @@
path("payroll/", include("payroll.urls")),
path("admin/", admin.site.urls),
# TODO - split below out into develop only?
path("favicon.ico", empty_favicon),
path(
"assets/<path:asset_path>",
RedirectView.as_view(url="/static/govuk/assets/%(asset_path)s"),
Expand Down
14 changes: 10 additions & 4 deletions forecast/templates/forecast/edit/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@

{% block title %}Edit Forecast{% endblock %}

{% block page_heading %}
<div style="display: flex; align-items: baseline; gap: 2rem;">
{{ block.super }}
{% can_access_edit_payroll user as user_can_access_edit_payroll %}
{% if user_can_access_edit_payroll and settings.PAYROLL.ENABLE_FORECAST %}
<a class="govuk-link" href="{% url 'payroll:edit' view.cost_centre_details.cost_centre_code view.financial_year %}">Go to Payroll</a>
{% endif %}
</div>
{% endblock %}

{% block page_content %}
<div class="govuk-grid-row date-selection-download">

Expand Down Expand Up @@ -41,16 +51,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
4 changes: 3 additions & 1 deletion forecast/templates/forecast/edit/forecast_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ <h2 class="govuk-notification-banner__title" id="govuk-notification-banner-title
</div>
</div>
{% endif %}
<h1 class="govuk-heading-l">{{ view.title }}</h1>
{% block page_heading %}
<h1 class="govuk-heading-l">{{ view.title }}</h1>
{% endblock page_heading %}
<a href="{% url 'forecast_cost_centre' view.cost_centre_details.cost_centre_code view.financial_year %}" target="_blank" class="govuk-heading-m cost-centre-heading-link">{{ view.cost_centre_details.cost_centre_name }} ({{ view.cost_centre_details.cost_centre_code }}) </a>
<dl class="govuk-summary-list">
<div class="govuk-summary-list__row">
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
40 changes: 5 additions & 35 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,35 +26,21 @@ 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,
);
dispatch({
type: SET_CELLS,
cells: rows,
});
let rows = processForecastData(window.table_data);
dispatch(SET_CELLS({ cells: rows }));
} else {
timer();
}
}, 100);
};

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

useEffect(() => {
const capturePaste = (event) => {
Expand Down Expand Up @@ -96,10 +81,7 @@ function EditForecast() {
if (response.status === 200) {
setSheetUpdating(false);
let rows = processForecastData(response.data);
dispatch({
type: SET_CELLS,
cells: rows,
});
dispatch(SET_CELLS({ cells: rows }));
} else {
setSheetUpdating(false);
dispatch(
Expand Down Expand Up @@ -334,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 @@ -362,10 +335,7 @@ function EditForecast() {
</div>
)}
<EditActionBar />
<Table
sheetUpdating={sheetUpdating}
payrollData={window.payroll_forecast_data}
/>
<Table sheetUpdating={sheetUpdating} />
</Fragment>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default function ForecastTable({ forecast, months }) {
className={`govuk-table__cell ${isActualClass}`}
key={month.key}
>
£{formatMoney(row[month.key])}
£{formatMoney(row[month.key] ?? 0)}
</td>
);
})}
Expand Down
47 changes: 8 additions & 39 deletions front_end/src/Components/InfoCell/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,55 +8,24 @@ const InfoCell = ({
className,
ignoreSelection,
}) => {
const selectedRow = useSelector((state) => state.selected.selectedRow);
const allSelected = useSelector((state) => state.selected.all);
let changed = false;

const checkValue = (hiddenCols) => {
if (hiddenCols.indexOf(cellKey) > -1) {
changed = true;
return false;
} else if (changed) {
changed = false;
return false;
}

return true;
};

const hiddenCols = useSelector(
(state) => state.hiddenCols.hiddenCols,
checkValue,
const isRowSelected = useSelector(
(state) => state.selected.all || state.selected.selectedRow === rowIndex,
);
const isColHidden = useSelector(
(state) => state.hiddenCols.hiddenCols.indexOf(cellKey) > -1,
);

const isSelected = () => {
if (ignoreSelection) return false;

if (allSelected) {
return true;
}

return selectedRow === rowIndex;
};

const getClasses = () => {
return (
"govuk-table__cell forecast-month-cell not-editable " +
className +
" " +
(isSelected() ? "selected " : "") +
(hiddenCols.indexOf(cellKey) > -1 ? "hidden" : "")
(!ignoreSelection && isRowSelected ? "selected " : "") +
(isColHidden ? "hidden" : "")
);
};

return <td className={getClasses()}>{children}</td>;
};

const comparisonFn = function (prevProps, nextProps) {
return (
prevProps.selectedRow === nextProps.selectedRow &&
prevProps.allSelected === nextProps.allSelected
);
};

export default memo(InfoCell, comparisonFn);
export default InfoCell;
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
Loading

0 comments on commit 9f82d7a

Please sign in to comment.