Here is a working version as of today (07/21/17)
http://dev-x.org/avorion/turretfactory.lua
I didn't have the original script, but thank you Alopix for pointing me to the files to get started
I've fixed the problem where you don't actually get the turret you see.
The script runs essentially twice, once on the server, and once on the client. Clicking the buttons updates the client, but the buildTurret function gets called on the server, so you need to pass the seed into that guy to update him as well.
This works in singleplayer, I do not know what may happen in multiplayer (another player may be able to change the seed of the factory your looking at, something like that).
As for the damage going below zero
That happens without mods. Being able to change the seed just makes it quicker to find.
The calculations for turret ingredients likely just go out of range, haven't looked at that yet. You can find seeds that have damage numbers that go up as you reduce the number of parts.
Note
I did change the default seeds, the seed number itself was way to large and didn't fit into the textbox
Anyway, enjoy!