CREATE TABLE `vn`.`routeDeliveryMan` (
    `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
    `supplierFk` int(11) DEFAULT NULL,
    `minCost` decimal(10,0) DEFAULT NULL,
    `minM3` int(10) unsigned DEFAULT NULL,
    PRIMARY KEY (`id`),
    KEY `routeDeliveryMan_FK` (`supplierFk`),
    CONSTRAINT `routeDeliveryMan_FK` FOREIGN KEY (`supplierFk`) REFERENCES `vn`.`supplier` (`id`) ON UPDATE CASCADE
) ENGINE=InnoDB;

CREATE TABLE `vn`.`routeDeliveryManAgency` (
    `deliveryManFk` INT UNSIGNED NOT NULL,
    `agencyModeFk` INT NOT NULL,
    CONSTRAINT `routeDeliveryManAgency_FK` FOREIGN KEY (`agencyModeFk`) REFERENCES `vn`.`agencyMode`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
    CONSTRAINT `routeDeliveryManAgency_FK_1` FOREIGN KEY (`deliveryManFk`) REFERENCES `vn`.`routeDeliveryMan`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE
) ENGINE=InnoDB;

ALTER TABLE `vn`.`route` ADD `invoiceOutFk` varchar(10) NULL;
ALTER TABLE `vn`.`route` ADD CONSTRAINT `route_FK` FOREIGN KEY (`invoiceOutFk`) REFERENCES `vn`.`invoiceOut`(`ref`) ON DELETE RESTRICT ON UPDATE CASCADE;

INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
    VALUES
        ('DeliveryMan', '*', '*', 'ALLOW', 'ROLE', 'employee');
