Fixes for Automatic Purchase Invoice Creation

Fixes for Automatic Purchase Invoice Creation

Resolved an issue where the incorrect invoice was selected when using the invoice workflow to create new invoices in the background.

Fixed an issue where the due date was not always transferred correctly.