I understood that you want a calc element's value to change by means of JS when interacting with a (j)date element in the form -- "live" and in "real-time", so to speak.
Well, if that's the PHP in your calc element (haven't looked through all lines but trust the code works for you), then its returned value will be saved in the DB on form submission, if the calc element is set to do so (and I bet it is, because why else would you let it go through all those queries).
So, then it's obviously pointless to change anything in the calc element in the form with JS, because its PHP rules and will be executed anyway on save, practically "overriding" whatever happens in the form.
So, seems you'll want to approach this in a completely different way... either set/change the calc (or any other) element's value live in the form by means of JS depending on another element like date or so (no calc PHP, and the user then eventually seeing those changes in the form), or have the calc element watching the (j)date element and be updated with Ajax, or do your calcs in the element or in a PHP form on submit (the user then only seeing the result after submission in list or details).