* fix(invoices): article pre-fills ROT/RUT and kundkort personnummer covers the claim
Two gaps reported by a user invoicing RUT work:
- Picking an article with a housework_type (arbetstypskod) left the line's
skattereduktion on 'Ingen': the editor never fetched the field. applyArticle
now derives deduction_type from the code's Skatteverket list (disjoint ROT/
RUT lists, new deductionTypeForWorkType helper) and sets work_type, with the
same overwrite semantics as description/price: an article without a code
clears the deduction so a material article never keeps claiming one.
'Spara som artikel' round-trips the code back onto the created article.
- The customer card's personnummer was never used for the ROT/RUT claim; the
user had to retype it per invoice. The browser only ever sees ciphertext or
a mask, so the fix is a server-side fallback in buildInvoiceWriteData:
typed > stored draft > kundkort. The kundkort value is decrypted, expanded
to 12 digits (new expandPersonnummerTo12, century inference incl. '+' and
samordningsnummer), Luhn-validated, and encrypted into the invoice; invalid
or unreadable values fall through to the existing 'Personnummer krävs'
error. The editor drops the required-mark and hints that the number comes
from the kundkort when one exists.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* fix(invoices): gate the kundkort personnummer fallback on individual customers
ROT/RUT is a privatperson deduction; customers.personal_number is
individual-only in the Zod schemas but not in the DB, so a stray value on a
business row must never be claimed on implicitly. Typed values unaffected.
Raised by the compliance review bot on #1634.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
---------
Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>