The script must be pasted on the corresponding document at:

Settings->Purchase/sales->Documents->Run SQL

To automatically create a consignment document that includes the combined products of the receipt issued, paste the following script to the corresponding documents: