"""JD-01 fictional model. Run with Python 3; values are EUR unless stated.
Sensitivity function over JD-01's frozen accepted authority, funding,
reporting and employee-explanation prerequisites. This is not a general
closure validator. Missing prerequisites keep a real case open even when
both employee receipts are recorded. References require separate verification.
"""
from decimal import Decimal as D

def correction(received_a, received_b, reversed=False, credit_applied=False):
    gross = D(300)*2
    deductions = D(84)*2
    employer = D(66)*2
    net = gross-deductions
    required = gross+employer
    topup = max(D(0), required-D(300))
    return dict(net=str(net), required=str(required), topup=str(topup),
                employee_closed=received_a and received_b and not reversed,
                statutory_remittance='OPEN: allocated, receipt pending',
                commercial_credit='APPLIED' if credit_applied else 'OPEN: approved, not applied',
                next_payroll_check='OPEN: next cycle not observed',
                invoice_payable=str(D(8000)-(D(100) if credit_applied else D(0))))

if __name__ == '__main__':
    failed = correction(True,False)
    repaired = correction(True,True)
    assert failed['employee_closed'] is False
    assert repaired['employee_closed'] is True
    assert correction(True,True,True)['employee_closed'] is False
    assert failed['net']=='432' and failed['required']=='732' and failed['topup']=='432'
    assert repaired['invoice_payable']=='8000'  # approved credit is not applied credit
    assert correction(True,True,credit_applied=True)['invoice_payable']=='7900'
    salary=D(60000); ni=(salary-D(5000))*D('.15'); pension=(D(50270)-D(6240))*D('.03')
    annual=salary+ni+pension
    monthly=(annual/12).quantize(D('.01'))
    fee=D(599)/D('1.25')
    assert annual==D('69570.90') and monthly==D('5797.58')
    assert monthly+fee+D(5000)==D('11276.78')
    assert monthly*2+fee==D('12074.36')
    print({'failed':failed,'repaired':repaired,'annual_employment_gbp':str(annual),'opening_teamed_gbp':str(monthly+fee+D(5000)),'checks':'8 correction states and budget assertions passed'})
