Move schema to json

This commit is contained in:
Dennis Eichhorn 2018-12-22 19:51:26 +01:00
parent 80b4f7ad14
commit 00564024ba
2 changed files with 140 additions and 178 deletions

140
Admin/Install/db.json Normal file
View File

@ -0,0 +1,140 @@
{
"accounting_account": {
"name": "accounting_account",
"fields": {
"accounting_account_id": {
"name": "accounting_account_id",
"type": "INT",
"null": false,
"primary": true,
"autoincrement": true
},
"accounting_account_name": {
"name": "accounting_account_name",
"type": "VARCHAR(50)",
"null": false
},
"accounting_account_description": {
"name": "accounting_account_description",
"type": "VARCHAR(255)",
"null": false
},
"accounting_account_type": {
"name": "accounting_account_type",
"type": "TINYINT",
"null": false
},
"accounting_account_parent": {
"name": "accounting_account_parent",
"type": "INT",
"default": null,
"null": true
}
}
},
"accounting_batch": {
"name": "accounting_batch",
"fields": {
"accounting_batch_id": {
"name": "accounting_batch_id",
"type": "INT",
"null": false,
"primary": true,
"autoincrement": true
},
"accounting_batch_title": {
"name": "accounting_batch_title",
"type": "VARCHAR(50)",
"null": false
},
"accounting_batch_creator": {
"name": "accounting_batch_creator",
"type": "INT",
"null": false,
"foreignTable": "account",
"foreignKey": "account_id"
},
"accounting_batch_created": {
"name": "accounting_batch_created",
"type": "DATETIME",
"null": false
},
"accounting_batch_type": {
"name": "accounting_batch_type",
"type": "TINYINT",
"default": null,
"null": true
}
}
},
"accounting_posting": {
"name": "accounting_posting",
"fields": {
"accounting_posting_id": {
"name": "accounting_posting_id",
"type": "INT",
"null": false,
"primary": true,
"autoincrement": true
},
"accounting_posting_batch": {
"name": "accounting_posting_batch",
"type": "INT",
"null": false,
"foreignTable": "accounting_batch",
"foreignKey": "accounting_batch_id"
},
"accounting_posting_receipt": {
"name": "accounting_posting_receipt",
"type": "INT",
"default": null,
"null": true
},
"accounting_posting_receipt_ext": {
"name": "accounting_posting_receipt_ext",
"type": "INT",
"default": null,
"null": true
},
"accounting_posting_price": {
"name": "accounting_posting_price",
"type": "BIGINT",
"null": false
}
}
},
"accounting_posting_ele": {
"name": "accounting_posting_ele",
"fields": {
"accounting_posting_ele_id": {
"name": "accounting_posting_ele_id",
"type": "INT",
"null": false,
"primary": true,
"autoincrement": true
},
"accounting_posting_ele_type": {
"name": "accounting_posting_ele_type",
"type": "TINYINT",
"null": false
},
"accounting_posting_ele_account": {
"name": "accounting_posting_ele_account",
"type": "INT",
"null": false,
"foreignTable": "accounting_account",
"foreignKey": "accounting_account_id"
},
"accounting_posting_ele_value": {
"name": "accounting_posting_ele_value",
"type": "BIGINT",
"null": false
},
"accounting_posting_ele_tax": {
"name": "accounting_posting_ele_tax",
"type": "INT",
"null": false
}
}
}
}

View File

@ -29,182 +29,4 @@ use phpOMS\Module\InstallerAbstract;
*/
class Installer extends InstallerAbstract
{
/**
* {@inheritdoc}
*/
public static function install(DatabasePool $dbPool, InfoManager $info) : void
{
parent::install($dbPool, $info);
switch ($dbPool->get()->getType()) {
case DatabaseType::MYSQL:
$dbPool->get()->con->prepare(
'CREATE TABLE if NOT EXISTS `' . $dbPool->get()->prefix . 'accounting_account` (
`accounting_account_id` int(11) NOT NULL AUTO_INCREMENT,
`accounting_account_name` varchar(25) NOT NULL,
`accounting_account_description` varchar(255) NOT NULL,
`accounting_account_type` tinyint(1) NOT NULL,
`accounting_account_parent` int(11) NOT NULL,
PRIMARY KEY (`accounting_account_id`),
KEY `accounting_account_parent` (`accounting_account_parent`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;'
)->execute();
$dbPool->get()->con->prepare(
'ALTER TABLE `' . $dbPool->get()->prefix . 'accounting_account`
ADD CONSTRAINT `' . $dbPool->get()->prefix . 'accounting_account_ibfk_1` FOREIGN KEY (`accounting_account_parent`) REFERENCES `' . $dbPool->get()->prefix . 'accounting_account` (`accounting_account_id`);'
)->execute();
$dbPool->get()->con->prepare(
'CREATE TABLE if NOT EXISTS `' . $dbPool->get()->prefix . 'accounting_batch` (
`accounting_batch_id` int(11) NOT NULL AUTO_INCREMENT,
`accounting_batch_title` varchar(30) NOT NULL,
`accounting_batch_creator` int(11) NOT NULL,
`accounting_batch_created`datetime NOT NULL,
`accounting_batch_type` tinyint(1) NOT NULL,
PRIMARY KEY (`accounting_batch_id`),
KEY `accounting_batch_creator` (`accounting_batch_creator`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;'
)->execute();
$dbPool->get()->con->prepare(
'ALTER TABLE `' . $dbPool->get()->prefix . 'accounting_batch`
ADD CONSTRAINT `' . $dbPool->get()->prefix . 'accounting_batch_ibfk_1` FOREIGN KEY (`accounting_batch_creator`) REFERENCES `' . $dbPool->get()->prefix . 'account` (`account_id`);'
)->execute();
$dbPool->get()->con->prepare(
'CREATE TABLE if NOT EXISTS `' . $dbPool->get()->prefix . 'accounting_posting` (
`accounting_posting_id` int(11) NOT NULL AUTO_INCREMENT,
`accounting_posting_batch` int(11) NOT NULL,
`accounting_posting_receipt` int(11) DEFAULT NULL,
`accounting_posting_receipt_ext` int(11) DEFAULT NULL,
`accounting_posting_price` decimal(11,3) NOT NULL,
`accounting_posting_affiliation` datetime NOT NULL,
PRIMARY KEY (`accounting_posting_id`),
KEY `accounting_posting_batch` (`accounting_posting_batch`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;'
)->execute();
$dbPool->get()->con->prepare(
'ALTER TABLE `' . $dbPool->get()->prefix . 'accounting_posting`
ADD CONSTRAINT `' . $dbPool->get()->prefix . 'accounting_posting_ibfk_1` FOREIGN KEY (`accounting_posting_batch`) REFERENCES `' . $dbPool->get()->prefix . 'accounting_batch` (`accounting_batch_id`);'
)->execute();
$dbPool->get()->con->prepare(
'CREATE TABLE if NOT EXISTS `' . $dbPool->get()->prefix . 'accounting_posting_ele` (
`accounting_posting_ele_id` int(11) NOT NULL AUTO_INCREMENT,
`accounting_posting_ele_type` tinyint(1) NOT NULL,
`accounting_posting_ele_account` int(11) NOT NULL,
`accounting_posting_ele_value` decimal(11,3) NOT NULL,
`accounting_posting_ele_tax` tinyint(1) NOT NULL,
PRIMARY KEY (`accounting_posting_ele_id`),
KEY `accounting_posting_ele_account` (`accounting_posting_ele_account`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;'
)->execute();
$dbPool->get()->con->prepare(
'ALTER TABLE `' . $dbPool->get()->prefix . 'accounting_posting_ele`
ADD CONSTRAINT `' . $dbPool->get()->prefix . 'accounting_posting_ele_ibfk_1` FOREIGN KEY (`accounting_posting_ele_account`) REFERENCES `' . $dbPool->get()->prefix . 'accounting_account` (`accounting_account_id`);'
)->execute();
/*
* type = (offer, confirmation etc.)
* soptained = date of when we received the service/order (not the invoice)
* check = person who checked or is supposed to check the invoice
* checked = date of when the invoice got approved (no datetime = no approval)
* posting referes (direct)
* payment referes to this (indirect)
* status {
* blank
* received-ok
* received-notok
* checked-ok
* checked-notok
* posted-ok
* posted-notok
* payed-ok
* payed-notok
* }
*/
/*
* TODO: Purchasing can create. person who creates automatically get's permission for these to read.
* TODO: move to different module
*/
/*
$dbPool->get()->con->prepare(
'CREATE TABLE if NOT EXISTS `' . $dbPool->get()->prefix . 'accounting_invoices_process` (
`AccountingInvoiceProcessID` int(11) NOT NULL AUTO_INCREMENT,
`media` int(11) DEFAULT NULL,
`type` tinyint(1) DEFAULT NULL,
`supplier` int(11) DEFAULT NULL,
`sname` varchar(32) DEFAULT NULL,
`optained` datetime NOT NULL,
`soptained` datetime NOT NULL,
`refnumber` varchar(24) NOT NULL,
`invoicedate` datetime NOT NULL,
`internalref` int(11) NOT NULL,
`due` datetime NOT NULL,
`duediscount` datetime NOT NULL,
`amount` decimal(11,3) NOT NULL,
`amountdiscount` decimal(11,3) NOT NULL,
`order` int(11) DEFAULT NULL,
`arrival` int(11) DEFAULT NULL,
`dnote` int(11) DEFAULT NULL,
PRIMARY KEY (`AccountingInvoiceProcessID`),
KEY `media` (`media`),
KEY `order` (`order`),
KEY `arrival` (`arrival`),
KEY `dnote` (`dnote`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;'
)->execute();
$dbPool->get()->con->prepare(
'ALTER TABLE `' . $dbPool->get()->prefix . 'accounting_invoices_process`
ADD CONSTRAINT `' . $dbPool->get()->prefix . 'accounting_invoices_process_ibfk_1` FOREIGN KEY (`media`) REFERENCES `' . $dbPool->get()->prefix . 'media` (`media_id`),
ADD CONSTRAINT `' . $dbPool->get()->prefix . 'accounting_invoices_process_ibfk_2` FOREIGN KEY (`order`) REFERENCES `' . $dbPool->get()->prefix . 'purchase_invoices` (`PurchaseInvoiceID`),
ADD CONSTRAINT `' . $dbPool->get()->prefix . 'accounting_invoices_process_ibfk_3` FOREIGN KEY (`arrival`) REFERENCES `' . $dbPool->get()->prefix . 'warehousing_arrival` (`WarehousingArrivalID`),
ADD CONSTRAINT `' . $dbPool->get()->prefix . 'accounting_invoices_process_ibfk_4` FOREIGN KEY (`dnote`) REFERENCES `' . $dbPool->get()->prefix . 'purchase_dnote` (`PurchaseDnoteID`);'
)->execute();
$dbPool->get()->con->prepare(
'CREATE TABLE if NOT EXISTS `' . $dbPool->get()->prefix . 'accounting_invoices_status` (
`AccountingInvoiceStatusID` int(11) NOT NULL AUTO_INCREMENT,
`invoice` int(11) DEFAULT NULL,
`status` tinyint(1) DEFAULT NULL,
`person` int(11) DEFAULT NULL,
`changed` datetime DEFAULT NULL,
`info` varchar(256) NOT NULL,
PRIMARY KEY (`AccountingInvoiceStatusID`),
KEY `invoice` (`invoice`),
KEY `person` (`person`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;'
)->execute();
$dbPool->get()->con->prepare(
'ALTER TABLE `' . $dbPool->get()->prefix . 'accounting_invoices_status`
ADD CONSTRAINT `' . $dbPool->get()->prefix . 'accounting_invoices_status_ibfk_1` FOREIGN KEY (`invoice`) REFERENCES `' . $dbPool->get()->prefix . 'accounting_invoices_process` (`AccountingInvoiceProcessID`),
ADD CONSTRAINT `' . $dbPool->get()->prefix . 'accounting_invoices_status_ibfk_2` FOREIGN KEY (`person`) REFERENCES `' . $dbPool->get()->prefix . 'account` (`account_id`);'
)->execute();
$dbPool->get()->con->prepare(
'CREATE TABLE if NOT EXISTS `' . $dbPool->get()->prefix . 'accounting_invoices_process_permission` (
`AccountingInvoiceProcessPermissionID` int(11) NOT NULL AUTO_INCREMENT,
`process` int(11) DEFAULT NULL,
`person` int(11) DEFAULT NULL,
`permission` int(11) DEFAULT NULL,
PRIMARY KEY (`AccountingInvoiceProcessPermissionID`),
KEY `person` (`person`),
KEY `process` (`process`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;'
)->execute();
$dbPool->get()->con->prepare(
'ALTER TABLE `' . $dbPool->get()->prefix . 'accounting_invoices_process_permission`
ADD CONSTRAINT `' . $dbPool->get()->prefix . 'accounting_invoices_process_permission_ibfk_1` FOREIGN KEY (`person`) REFERENCES `' . $dbPool->get()->prefix . 'account` (`account_id`),
ADD CONSTRAINT `' . $dbPool->get()->prefix . 'accounting_invoices_process_permission_ibfk_2` FOREIGN KEY (`process`) REFERENCES `' . $dbPool->get()->prefix . 'accounting_invoices_process` (`AccountingInvoiceProcessID`);'
)->execute();*/
break;
}
}
}