CREATE TABLE `invoices` ( `invoice_id` INT(11) NOT NULL AUTO_INCREMENT, `order_id` INT(11) DEFAULT NULL, `type` CHAR(1) NOT NULL DEFAULT '1', `price_type` CHAR(1) DEFAULT NULL, `custom_price` FLOAT DEFAULT NULL, `created` DATE NOT NULL, `due` DATE NOT NULL, `code` VARCHAR(20) NOT NULL, `seller_participant_id` INT(11) NOT NULL, `buyer_participant_id` INT(11) NOT NULL, `total` FLOAT NOT NULL, `add_shipping` tinyint(1) NOT NULL DEFAULT '1', `exported_remax` datetime DEFAULT NULL, `remax_code` VARCHAR(30) NOT NULL, `exported_toptrans` datetime DEFAULT NULL, `toptrans_code` VARCHAR(30) NOT NULL, `toptrans_export_downloaded` tinyint(1) NOT NULL, `toptrans_order` text, `toptrans_report` text, `estimated_delivery` DATE DEFAULT NULL, `tracking_code_notification_sent` tinyint(1) NOT NULL, `invoice_parent` INT(11) DEFAULT NULL, `pay_price` FLOAT NOT NULL, `proforma_invoice_amount_left` FLOAT NOT NULL, PRIMARY KEY (`invoice_id`), KEY `order_id` (`order_id`), KEY `seller_participant_id` (`seller_participant_id`), KEY `buyer_participant_id` (`buyer_participant_id`), KEY `invoice_parent` (`invoice_parent`), CONSTRAINT `invoices_ibfk_1` FOREIGN KEY (`seller_participant_id`) REFERENCES `invoice_participants` (`invoice_participant_id`), CONSTRAINT `invoices_ibfk_2` FOREIGN KEY (`buyer_participant_id`) REFERENCES `invoice_participants` (`invoice_participant_id`), CONSTRAINT `invoices_ibfk_3` FOREIGN KEY (`order_id`) REFERENCES `orders` (`order_id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `invoices_ibfk_4` FOREIGN KEY (`invoice_parent`) REFERENCES `invoices` (`invoice_id`) ON DELETE SET NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8;