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

HWPV-195: View & Edit individual claim page #650

Open
wants to merge 35 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
0bdbc8c
HWPV-195: WIP update to move to new component library & design tweaks
ashleygyngell Jun 18, 2024
29dcdfb
HWPV-195: visitor section
ashleygyngell Jun 19, 2024
4411511
HWPV-195: bank, benefit & child sections
ashleygyngell Jun 19, 2024
e6ba557
HWPV-195: prisoner & release date section
ashleygyngell Jun 19, 2024
dd6a852
HWPV-195: visit section
ashleygyngell Jun 19, 2024
4cbf08d
HWPV-195 claim section
ashleygyngell Jun 27, 2024
88c1623
HWPV-195 claim section -2
ashleygyngell Jun 27, 2024
66d7afc
HWPV-195: deduction section
ashleygyngell Jun 27, 2024
95fa804
HWPV-195: deduction section -2
ashleygyngell Jun 28, 2024
cc0586d
HWPV-195: add note section
ashleygyngell Jul 1, 2024
3cb9cbf
HWPV-195: lint
ashleygyngell Jul 2, 2024
9e6e072
HWPV-195: closed claim action sections
ashleygyngell Jul 2, 2024
a3cc71c
HWPV-195: event section + timeline
ashleygyngell Jul 2, 2024
1844329
HWPV-195: errors for open claim
ashleygyngell Jul 3, 2024
f001589
HWPV-195: errors for closed claim
ashleygyngell Jul 3, 2024
3b2beba
Merge branch 'main' of ssh://github.com/ministryofjustice/help-with-p…
ashleygyngell Jul 3, 2024
e2a8ae1
HWPV-195: remove manual errors
ashleygyngell Jul 3, 2024
9fdddff
HWPV-195: styling for errors
ashleygyngell Jul 3, 2024
10c4cc8
HWPV-195: warning components
ashleygyngell Jul 4, 2024
0e5e44a
HWPV-195: refactor for decimal input
ashleygyngell Jul 4, 2024
7601f0c
HWPV-195: Logic update for approved claim
ashleygyngell Jul 5, 2024
0cbda76
HWPV-195: js refactor
ashleygyngell Jul 8, 2024
5d866ac
HWPV-195: html refactor
ashleygyngell Jul 8, 2024
c886749
HWPV-195: Add release date checkbox
ashleygyngell Jul 8, 2024
0c880b5
Merge branch 'main' of ssh://github.com/ministryofjustice/help-with-p…
ashleygyngell Jul 8, 2024
d9d5aca
HWPV-195: updating claim approved costs logic & layout tweak
ashleygyngell Jul 9, 2024
a23e94c
HWPV-195: display approved cost logic fix
ashleygyngell Jul 10, 2024
ddb41e0
HWPV-195: WIP logic update for total approved cost
ashleygyngell Jul 12, 2024
e0c4374
HWPV-195: update headings to sentence case
ashleygyngell Jul 12, 2024
b6724c2
HWPV-195: errors anchor update
ashleygyngell Jul 12, 2024
422eb74
HWPV-195: bug fix for expenses still displaying non-submitted values …
ashleygyngell Jul 12, 2024
a34e1c3
HWPV-195: lint
ashleygyngell Jul 12, 2024
b06ee86
HWPV-195: Tidy up following comments
ashleygyngell Jul 24, 2024
4e5bdb2
Merge branch 'main' into claim-editing-page
psoleckimoj Aug 6, 2024
c2d6a37
Merge branch 'main' into claim-editing-page
psoleckimoj Aug 8, 2024
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
220 changes: 130 additions & 90 deletions app/assets/javascripts/view-claim.js
Original file line number Diff line number Diff line change
@@ -1,111 +1,151 @@
$(function () {
totalApproved()
function totalApproved () {
let approvedCost = 0
const manuallyProcessed = 0
let deduction = 0

if (document.getElementById('additional-info-reject') !== null) {
if (document.getElementById('additional-info-reject').value === 'Other') {
document.getElementById('additional-info-reject-manual').style.display = 'block'
document.getElementById('manual-label').style.display = 'block'
}
function isValidValue (value) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I seem to spot things after re-reading. Is value a string or Number? isNan doesn't make sense if you're also using trim on a string? isNaN will be OK with 1e3 for example.

return !isNaN(value) && value.trim().length !== 0 && value.indexOf('e') === -1 && value.indexOf('E') === -1
}

$('.claim-expense-status').change(function () {
const id = $(this).attr('data-id')
const value = $(this).val()
if (value === 'APPROVED-DIFF-AMOUNT') {
$(`#claim-expense-${id}-approvedcost`).removeClass('visibility-hidden').addClass('visibility-visible')
$(this).next('input').on('input').addClass('approved-amount')
$(this).parent().parent().find('td.cost').removeClass('approved-amount')
$('input.approved-amount').on('input', function () {
totalApproved()
})
} else if (value === 'APPROVED') {
$(`#claim-expense-${id}-approvedcost`).removeClass('visibility-visible').addClass('visibility-hidden')
$(this).parent().parent().find('td.cost').addClass('approved-amount')
$(this).next('input').on('input').removeClass('approved-amount')
} else {
$(`#claim-expense-${id}-approvedcost`).removeClass('visibility-visible').addClass('visibility-hidden')
$(this).parent().parent().find('td.cost').removeClass('approved-amount')
$(this).next('input').on('input').removeClass('approved-amount')
} totalApproved()
})
if ($('#unassign').length) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how I missed this, the code inside the if and the else are identical so no need for the statement?

$('.approved-amount').each(function () {
const value = $(this).val()
if (isValidValue(value)) {
approvedCost += parseFloat(value)
}
approvedCost += +$(this).text().replace('£', '').trim()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this doesn't make sense, you're using approvedCost as both a running total but you're also appending string/text to it, then using it as a number on line 32?

})
} else {
$('.approved-amount').each(function () {
const value = $(this).val()
if (isValidValue(value)) {
approvedCost += parseFloat(value)
}
approvedCost += +$(this).text().replace('£', '').trim()
})
}

$('input[value="Remove"]').parent().parent().find('td.deduction').addClass('approved-amount')
$('input.approved-amount').on('input', function () {
totalApproved()
$('.deduction').each(function () {
deduction += +$(this).text().replace(' £', '')
})

$('.claim-expense-status').each(function () {
const value = this[this.selectedIndex].value
if (value === 'APPROVED') {
$(this).parent().parent().find('td.cost').addClass('approved-amount')
$(this).next('input').removeClass('approved-amount')
} else if (value === 'APPROVED-DIFF-AMOUNT') {
$(this).next('input').addClass('approved-amount')
$(this).parent().parent().find('td.cost').removeClass('approved-amount')
} else {
$(this).parent().parent().find('td.cost').removeClass('approved-amount')
}
})
const totalCost = approvedCost + manuallyProcessed + deduction

$('.approved-amount').each(function () {
totalApproved()
})
const formattedCost = totalCost < 0 ? '- £' + Math.abs(totalCost).toFixed(2) : '£' + totalCost.toFixed(2)
$('.claim-expense-approvedCostText').text(formattedCost)

$('#overpayment-toggle').change(function () {
showClosedClaimActionSection('#overpayment-input')
})
if (totalCost < 0) {
$('.claim-expense-approvedCostText').addClass('claim-table-negative')
} else {
$('.claim-expense-approvedCostText').removeClass('claim-table-negative')
}
}

$('#close-toggle').change(function () {
showClosedClaimActionSection('#close-advanced-claim-input')
})
$(document).ready(function () {
function initializeState () {
if ($('#unassign').length) {
// setting initial state for when assigned
$('.claim-expense-status').each(function () {
const id = $(this).attr('data-id')
const value = $(this).val()
if (value === 'APPROVED') {
$(`#text-for-${id}-approved-cost`).text($(`#claimed-expense-for-${id}`).text().trim())
} else if (value === 'APPROVED-DIFF-AMOUNT') {
$(`#text-for-${id}-approved-cost`).addClass('js-hidden').removeClass('approved-amount')
$(`.input-container-for-${id}-approve-different-cost`).removeClass('js-hidden')
$(`.input-value-for-${id}-approve-different-cost`).addClass('approved-amount')
}
})
}
$('#additional-info-reject').each(function () {
if (this[this.selectedIndex].value === 'Other') {
$('.rejection-reason-other').removeClass('js-hidden')
}
})
$('#release-date-is-set').each(function () {
if ($(this).is(':checked')) {
$('#release').removeClass('js-hidden')
}
})
$('#is-trusted-checkbox').each(function () {
if ($(this).is(':checked')) {
$('.reject-auto-approval').addClass('js-hidden')
} else {
$('.reject-auto-approval').removeClass('js-hidden')
}
})
totalApproved()
}
initializeState()

$('#request-new-payment-details-toggle').change(function () {
showClosedClaimActionSection('#request-new-payment-details-input')
})
$(function () {
$('.claim-expense-status').change(function () {
const id = $(this).attr('data-id')
const value = $(this).val()
if (value === 'APPROVED') {
$(`#text-for-${id}-approved-cost`).removeClass('js-hidden').addClass('approved-amount').text($(`#claimed-expense-for-${id}`).text())
$(`.input-container-for-${id}-approve-different-cost`).addClass('js-hidden')
$(`.input-value-for-${id}-approve-different-cost`).removeClass('approved-amount').val($(`#claimed-expense-for-${id}`).text().replace('£', ''))
$(`.claim-expense-${id}-approvedcost`).val($(`#claimed-expense-for-${id}`).text())
} else if (value === 'APPROVED-DIFF-AMOUNT') {
$(`#text-for-${id}-approved-cost`).addClass('js-hidden').removeClass('approved-amount')
$(`.input-container-for-${id}-approve-different-cost`).removeClass('js-hidden')
$(`.input-value-for-${id}-approve-different-cost`).addClass('approved-amount').val($(`#claimed-expense-for-${id}`).text().replace('£', ''))
} else {
$(`#text-for-${id}-approved-cost`).addClass('js-hidden').addClass('approved-amount').text('0.00')
$(`.input-container-for-${id}-approve-different-cost`).addClass('js-hidden')
$(`.input-value-for-${id}-approve-different-cost`).removeClass('approved-amount').val('0.00')
}
totalApproved()
})

$('#additional-info-reject').change(function () {
if (this[this.selectedIndex].value === 'Other') {
document.getElementById('additional-info-reject-manual').style.display = 'block'
document.getElementById('manual-label').style.display = 'block'
} else {
document.getElementById('additional-info-reject-manual').style.display = 'none'
document.getElementById('manual-label').style.display = 'none'
document.getElementById('additional-info-reject-manual').value = ''
}
})
})
$('.input-for-different-cost').on('input', function () {
totalApproved()
})

function totalApproved () {
let approvedCost = 0
let manuallyProcessed = 0
$('input[value="Remove"]').parent().parent().find('td.deduction').addClass('approved-amount')

if ($('#unassign').length) {
$('input.approved-amount').each(function () {
if (!isNaN(this.value) && this.value.length !== 0 && this.value.indexOf('e') === -1 && this.value.indexOf('E') === -1) {
manuallyProcessed += parseFloat(this.value)
}
$('#overpayment-toggle').change(function () {
showClosedClaimActionSection('#overpayment-input')
})

$('td.approved-amount').each(function () {
approvedCost += +$(this).text().replace('£', '')
$('#close-toggle').change(function () {
showClosedClaimActionSection('#close-advanced-claim-input')
})
} else { // use hidden approved cost for unassigned claims
$('input.approved-cost').each(function () {
if (!isNaN(this.value) && this.value.length !== 0) {
approvedCost += parseFloat(this.value)

$('#request-new-payment-details-toggle').change(function () {
showClosedClaimActionSection('#request-new-payment-details-input')
})

$('#additional-info-reject').change(function () {
if (this[this.selectedIndex].value === 'Other') {
$('.rejection-reason-other').removeClass('js-hidden')
} else {
$('.rejection-reason-other').addClass('js-hidden')
}
})
$('td.deduction').each(function () {
approvedCost += +$(this).text().replace('£', '')

$('#is-trusted-checkbox').on('click', function () {
if ($(this).is(':checked')) {
$('.reject-auto-approval').addClass('js-hidden')
} else {
$('.reject-auto-approval').removeClass('js-hidden')
}
})
}

$('.claim-expense-approvedCostText').text('£' + (approvedCost + manuallyProcessed).toFixed(2))
}
$('#release-date-is-set').on('click', function () {
if ($(this).is(':checked')) {
$('#release').removeClass('js-hidden')
} else {
$('#release').addClass('js-hidden')
}
})
})

function showClosedClaimActionSection (id) {
$('#overpayment-input').addClass('js-hidden')
$('#close-advanced-claim-input').addClass('js-hidden')
$('#request-new-payment-details-input').addClass('js-hidden')
$(id).removeClass('js-hidden')
}
function showClosedClaimActionSection (id) {
$('#overpayment-input').addClass('js-hidden')
$('#close-advanced-claim-input').addClass('js-hidden')
$('#request-new-payment-details-input').addClass('js-hidden')
$(id).removeClass('js-hidden')
}
})
Loading