My experience is that Social security and Hacienda never (ok, never say never) get it wrong and it is normally a poorly informed foreigner or an inept “gestor” –
the system works very well and is the envy of most of Europe; ask the big accounting firms !! Stop blaming Spain, get to grips with the system or employ a hot asesor fiscal!! you’ll save all the fees every year with good advise!!