CREATE TABLE SUPPLIER (
	SUP_ID INT(11) NOT NULL AUTO_INCREMENT,
	SUP_NAME VARCHAR(100) NOT NULL,
	SUP_ADDRESS VARCHAR(150) NULL,
	SUP_TAXCODE VARCHAR(50) NULL,
	SUP_PHONE VARCHAR(20) NULL,
	SUP_FAX VARCHAR(20) NULL,
	SUP_EMAIL VARCHAR(100) NULL,
	SUP_NOTE VARCHAR(200) NULL,
	SUP_DELETED char(1) DEFAULT 'N',
	PRIMARY KEY (SUP_ID)
);

INSERT INTO MENUITEM VALUES ('supplier', 'angal.menu.btn.supplier', 'angal.menu.supplier', 'x', 'S', 'generaldata', 'org.isf.supplier.gui.SupplierBrowser','N', 8);
INSERT INTO GROUPMENU (GM_UG_ID_A, GM_MNI_ID_A, GM_ACTIVE) VALUES ('admin','supplier','Y');

-- Collecting supplier old informations
INSERT INTO SUPPLIER (SUP_NAME) SELECT DISTINCT(MMV_FROM) FROM MEDICALDSRSTOCKMOV WHERE MMV_FROM IS NOT NULL;

-- Updating MEDICALDSRSTOCKMOV table with new codes
UPDATE MEDICALDSRSTOCKMOV JOIN SUPPLIER ON MMV_FROM = SUP_NAME SET MMV_FROM = SUP_ID;
-- UPDATE MEDICALDSRSTOCKMOV SET MMV_FROM = 0 WHERE MMV_FROM IS NULL;

-- Altering MEDICALDSRSTOCKMOV table to reflect codes type
ALTER TABLE MEDICALDSRSTOCKMOV CHANGE COLUMN MMV_FROM MMV_FROM INT(11) NULL DEFAULT NULL; 