CREATE TABLE `ma_VendorRateCategory` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `title` varchar(255) NOT NULL,
  `sorter` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;

CREATE TABLE `ma_VendorRate` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `vendorId` int(10) unsigned NOT NULL,
  `adminId` int(11) NOT NULL,
  `comment` text NOT NULL,
  `rate` int(1) NOT NULL,
  `added` datetime NOT NULL,
  `changed` datetime NOT NULL,
  PRIMARY KEY (`id`),
  KEY `vendorId` (`vendorId`),
  KEY `adminId` (`adminId`),
  CONSTRAINT `ma_VendorRate_ibfk_1` FOREIGN KEY (`adminId`) REFERENCES `ma_Admin` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `ma_VendorRate_ibfk_2` FOREIGN KEY (`vendorId`) REFERENCES `ma_Vendor` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8;

CREATE TABLE `ma_VendorRateGeneral` (
  `vendorId` int(10) unsigned NOT NULL,
  `rate` decimal(3,2) NOT NULL,
  PRIMARY KEY (`vendorId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

CREATE TABLE `ma_VendorRateItem` (
  `rateId` int(10) unsigned NOT NULL,
  `categoryId` int(10) unsigned NOT NULL,
  `meets` tinyint(1) NOT NULL,
  UNIQUE KEY `rateId` (`rateId`,`categoryId`),
  KEY `categoryId` (`categoryId`),
  CONSTRAINT `ma_VendorRateItem_ibfk_1` FOREIGN KEY (`rateId`) REFERENCES `ma_VendorRate` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `ma_VendorRateItem_ibfk_2` FOREIGN KEY (`categoryId`) REFERENCES `ma_VendorRateCategory` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

INSERT INTO `ma_Settings` (`name`, `idCategory`, `fieldType`, `label`, `value`, `options`, `description`, `required`, `system`, `sorter`, `added`, `changed`) VALUES
('vendorRateInterval', 1, 'numeric', 'Vendor Rate Interval', '14', '', '', 'n', 'n', 845, NOW(), NOW());

INSERT INTO `ma_SettingsOptions` (`name`, `variable`, `value`, `type`, `sorter`) VALUES
('vendorRateInterval', 'append', 'days', 'string', NULL),
('vendorRateInterval', 'precision', '0', 'int', NULL),
('vendorRateInterval', 'negative', '0', 'int', NULL);
