Scope Nuclear RAB levy field to electric tariffs only
RAB levy funds nuclear electricity generation, so it can't apply to gas/oil/water tariffs. Hide the field for non-electric categories and clear any stray value if a tariff's category changes or is saved as non-electric. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
3b261a4d8d
commit
23d8009e00
1 changed files with 15 additions and 7 deletions
|
|
@ -109,13 +109,14 @@ export default function Tariffs() {
|
||||||
? Object.fromEntries(form.windows.map(w => [w.label.toLowerCase(), w.split_pct]))
|
? Object.fromEntries(form.windows.map(w => [w.label.toLowerCase(), w.split_pct]))
|
||||||
: {}
|
: {}
|
||||||
const windows = form.windows.map(({ split_pct: _split_pct, ...w }) => w)
|
const windows = form.windows.map(({ split_pct: _split_pct, ...w }) => w)
|
||||||
|
const isElectric = categories.find(c => c.id === form.category_id)?.key === 'electric'
|
||||||
const body = {
|
const body = {
|
||||||
category_id: form.category_id, name: form.name.trim(), supplier: form.supplier || null,
|
category_id: form.category_id, name: form.name.trim(), supplier: form.supplier || null,
|
||||||
effective_from: form.effective_from, effective_to: form.effective_to || null,
|
effective_from: form.effective_from, effective_to: form.effective_to || null,
|
||||||
standing_charge_pence_per_day: form.standing_charge_pence_per_day,
|
standing_charge_pence_per_day: form.standing_charge_pence_per_day,
|
||||||
ccl_rate_pence_per_unit: form.ccl_rate_pence_per_unit === '' ? null : form.ccl_rate_pence_per_unit,
|
ccl_rate_pence_per_unit: form.ccl_rate_pence_per_unit === '' ? null : form.ccl_rate_pence_per_unit,
|
||||||
ccl_exempt: form.ccl_exempt,
|
ccl_exempt: form.ccl_exempt,
|
||||||
rab_levy_rate_pence_per_unit: form.rab_levy_rate_pence_per_unit === '' ? null : form.rab_levy_rate_pence_per_unit,
|
rab_levy_rate_pence_per_unit: !isElectric || form.rab_levy_rate_pence_per_unit === '' ? null : form.rab_levy_rate_pence_per_unit,
|
||||||
metering_charge_pence_per_month: form.metering_charge_pence_per_month,
|
metering_charge_pence_per_month: form.metering_charge_pence_per_month,
|
||||||
other_charges_pence_per_month: form.other_charges_pence_per_month,
|
other_charges_pence_per_month: form.other_charges_pence_per_month,
|
||||||
vat_rate_pct: form.vat_rate_pct, is_time_of_use: form.is_time_of_use,
|
vat_rate_pct: form.vat_rate_pct, is_time_of_use: form.is_time_of_use,
|
||||||
|
|
@ -195,7 +196,12 @@ export default function Tariffs() {
|
||||||
</div>
|
</div>
|
||||||
<div className="field">
|
<div className="field">
|
||||||
<label>Category</label>
|
<label>Category</label>
|
||||||
<select value={form.category_id} onChange={e => setForm({ ...form, category_id: parseInt(e.target.value) })}>
|
<select value={form.category_id} onChange={e => {
|
||||||
|
const category_id = parseInt(e.target.value)
|
||||||
|
const category = categories.find(c => c.id === category_id)
|
||||||
|
const clearRabLevy = category?.key !== 'electric'
|
||||||
|
setForm({ ...form, category_id, rab_levy_rate_pence_per_unit: clearRabLevy ? '' : form.rab_levy_rate_pence_per_unit })
|
||||||
|
}}>
|
||||||
{categories.map(c => <option key={c.id} value={c.id}>{c.name}</option>)}
|
{categories.map(c => <option key={c.id} value={c.id}>{c.name}</option>)}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -238,11 +244,13 @@ export default function Tariffs() {
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<div className="field-row">
|
<div className="field-row">
|
||||||
|
{categories.find(c => c.id === form.category_id)?.key === 'electric' && (
|
||||||
<div className="field">
|
<div className="field">
|
||||||
<label>Nuclear RAB levy (pence/unit)</label>
|
<label>Nuclear RAB levy (pence/unit)</label>
|
||||||
<input type="number" step="0.0001" value={form.rab_levy_rate_pence_per_unit}
|
<input type="number" step="0.0001" value={form.rab_levy_rate_pence_per_unit}
|
||||||
onChange={e => setForm({ ...form, rab_levy_rate_pence_per_unit: e.target.value === '' ? '' : parseFloat(e.target.value) })} />
|
onChange={e => setForm({ ...form, rab_levy_rate_pence_per_unit: e.target.value === '' ? '' : parseFloat(e.target.value) })} />
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
<div className="field">
|
<div className="field">
|
||||||
<label>Metering charge (£/month)</label>
|
<label>Metering charge (£/month)</label>
|
||||||
<input type="number" step="0.01" value={form.metering_charge_pence_per_month / 100}
|
<input type="number" step="0.01" value={form.metering_charge_pence_per_month / 100}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue