
ALTER TABLE `partinstance` ADD `statusId` int(10) unsigned NOT NULL DEFAULT 0 after `warrantyDate`, add INDEX(`statusId`);
CREATE TABLE `partinstancestatus`(
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(100) NOT NULL DEFAULT '',
  `active` tinyint(1) NOT NULL DEFAULT '1',
  `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
  `createdById` int(10) unsigned NOT NULL DEFAULT '0',
  `updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `updatedById` int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

insert into `partinstancestatus` (id, name, active, created, createdById, updated, updatedById) VALUES (1, 'AVAILABLE', 1, '2020-02-13 00:00:00', 10, '2020-02-13 00:00:00', 10);
insert into `partinstancestatus` (id, name, active, created, createdById, updated, updatedById) VALUES (2, 'IN ORDER', 1, '2020-02-13 00:00:00', 10, '2020-02-13 00:00:00', 10);
insert into `partinstancestatus` (id, name, active, created, createdById, updated, updatedById) VALUES (3, 'PICKED', 1, '2020-02-13 00:00:00', 10, '2020-02-13 00:00:00', 10);
insert into `partinstancestatus` (id, name, active, created, createdById, updated, updatedById) VALUES (4, 'SHIPPED', 1, '2020-02-13 00:00:00', 10, '2020-02-13 00:00:00', 10);
insert into `partinstancestatus` (id, name, active, created, createdById, updated, updatedById) VALUES (5, 'IN RMA', 1, '2020-02-13 00:00:00', 10, '2020-02-13 00:00:00', 10);
insert into `partinstancestatus` (id, name, active, created, createdById, updated, updatedById) VALUES (6, 'BROKEN', 1, '2020-02-13 00:00:00', 10, '2020-02-13 00:00:00', 10);
insert into `partinstancestatus` (id, name, active, created, createdById, updated, updatedById) VALUES (7, 'WRITEN OFF', 1, '2020-02-13 00:00:00', 10, '2020-02-13 00:00:00', 10);
insert into `partinstancestatus` (id, name, active, created, createdById, updated, updatedById) VALUES (8, 'SENT TO SUPPLIER', 1, '2020-02-13 00:00:00', 10, '2020-02-13 00:00:00', 10);

update partinstance set statusId = 1;


ALTER TABLE `creditnoteitem` ADD `partInstanceIds` varchar(255) DEFAULT '' after `totalPrice`;

ALTER TABLE `rmaitem` ADD `partInstanceId` INT(10) DEFAULT NULL after `updatedProductId`, add INDEX(`partInstanceId`);
ALTER TABLE `rmaitem` ADD `replacedToCustomerPartInstanceId` INT(10) DEFAULT NULL after `updatedProductId`, add INDEX(`replacedToCustomerPartInstanceId`);

ALTER TABLE `rmaitem` ADD `qtyRelatedCreditNote` INT(10) NOT NULL DEFAULT 0 after `updatedProductId`, add INDEX(`qtyRelatedCreditNote`);

ALTER TABLE `rmaitem` ADD `isWriteOff` TINYINT(10) NOT NULL DEFAULT 0 after `updatedProductId`, add INDEX(`isWriteOff`);
