CREATE TABLE IF NOT EXISTS `agr_transaction_$mid` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `contractId` int(10) unsigned NOT NULL,
  `sum` decimal(12,2) DEFAULT NULL,
  `status` tinyint(4) DEFAULT 0,
  `createDate` datetime(3) DEFAULT NULL,
  `paymentDate` datetime(3) DEFAULT NULL,
  `agrPaymentId` int(11) DEFAULT NULL,
  `agrPaymentName` varchar(64) DEFAULT NULL,
  `paymentId` int(11) DEFAULT NULL,
  `environment` tinyint(2) DEFAULT 0,
  PRIMARY KEY (`id`),
  KEY `agr_transaction_$mid_contract_fk` (`contractId`),
  KEY `agr_transaction_$mid_payment_fk` (`paymentId`),
  CONSTRAINT `agr_transaction_$mid_contract_fk` FOREIGN KEY (`contractId`) REFERENCES `contract` (`id`) ON DELETE CASCADE,
  CONSTRAINT `agr_transaction_$mid_payment_fk` FOREIGN KEY (`paymentId`) REFERENCES `contract_payment` (`id`) ON DELETE CASCADE
);

alter table `agr_transaction_$mid` modify createDate datetime(0) null;
alter table `agr_transaction_$mid` modify paymentDate datetime(0) null;
alter table `agr_transaction_$mid` modify agrPaymentId varchar(64) null;

-- #BLOCK#
DELETE FROM script_event_type WHERE mid=$mid;
INSERT INTO script_event_type (mid, event_id, event_mode, title) VALUES ($mid, 'ru.bitel.bgbilling.modules.agr.server.bean.AGRRequestEvent', 0, 'Дополнительные параметры AGR (метод info)');
-- #ENDB#

