Automaic sales order creation

how to create a sales order based on quotation status if it is in open or confirm then automatically copy of quotation add into sales order and invoice also how to do that ??