How does the due date get calculated in the invoice?

Suggestion:
The Systems calculates the Credit Period from the customer master, it’s the number of days credit can be given to the customer. Due date is calculated by adding these days to the despatch date. If the Credit Period is left blank in customer master then the credit period is picked up from the credit term master defined in the Sales order.
Example: If the Credit term defined in Order is CR031 and in credit term master the credit days for this credit term is 21 days. And, if invoices are made on 30-jun-2019 and credit days are 21 days, the due date gets auto populated as 21-July-2019, which is set by system in invoices ‘due date’ field.