Praise be to Allah.
The employee is obliged to do his work as is required of him, so that he will be entitled to the salary that he takes in return for that work.
If there is any shortcoming in his work, then the basic principle is that he is not entitled to take the salary in full, because he did not do the work in the manner required.
It says in Fataawa al-Lajnah ad-Daa’imah (vol. 1, 15/154): What is required of the one to whom work has been given, in return for which he receives a salary, is to do the work in the manner required. If he falls short in that without a legitimate excuse, the salary that he takes is not permissible for him, because he is taking it without having done his work properly in return.
Based on that, you have to repent and not repeat what you have mentioned. You must be honest in doing the work that has been given to you to do, and give ing charity whatever is equivalent to what you took of the salary with no legitimate excuse. End quote.
Based on the above, the first thing that anyone who does any such shortcoming must do is repent to Allah, may He be exalted, from his shortcoming.
He does not have to get rid of the books that he bought with this salary, or give them away; rather he may make use of them. All that is required of him is to get rid of the salary that he received, commensurate with the degree to which he fell short. If he fell short in half of his work, he should get rid of half of that salary, and so on.
He should only get rid of it by returning it to the workplace to which it belongs, if that is possible; otherwise he may donate it to charitable causes.
Note: some countries have set up accounts for employees of the state who fell short or took anything from public funds, to pay it back. If someone is in a country where such accounts and schemes have been set up, and he falls short in his work and he is employed by the government, then he may return the money to that account and thus will have discharged his duty.
We ask Allah to help us all to shoulder responsibilities and render back trusts in the most perfect manner, for He is able to do that.
And Allah knows best.