Add database foreign keys related to rewards

This commit is contained in:
FrancescoUK
2017-07-29 22:21:20 +01:00
parent cd792eb56a
commit 6485cf050d
5 changed files with 130 additions and 51 deletions

View File

@@ -1,26 +1,26 @@
-- alter quantity fields to be all decimal
ALTER TABLE `ospos_items`
ADD COLUMN `stock_type` TINYINT(2) NOT NULL DEFAULT 0,
ADD COLUMN `item_type` TINYINT(2) NOT NULL DEFAULT 0;
ADD COLUMN `stock_type` TINYINT(2) NOT NULL DEFAULT 0,
ADD COLUMN `item_type` TINYINT(2) NOT NULL DEFAULT 0;
ALTER TABLE `ospos_item_kits`
ADD COLUMN `item_id` INT(10) NOT NULL DEFAULT 0,
ADD COLUMN `kit_discount_percent` DECIMAL(15,2) NOT NULL DEFAULT 0.00,
ADD COLUMN `price_option` TINYINT(2) NOT NULL DEFAULT 0,
ADD COLUMN `print_option` TINYINT(2) NOT NULL DEFAULT 0;
ADD COLUMN `item_id` INT(10) NOT NULL DEFAULT 0,
ADD COLUMN `kit_discount_percent` DECIMAL(15,2) NOT NULL DEFAULT 0.00,
ADD COLUMN `price_option` TINYINT(2) NOT NULL DEFAULT 0,
ADD COLUMN `print_option` TINYINT(2) NOT NULL DEFAULT 0;
ALTER TABLE `ospos_item_kit_items`
ADD COLUMN `kit_sequence` INT(3) NOT NULL DEFAULT 0;
ADD COLUMN `kit_sequence` INT(3) NOT NULL DEFAULT 0;
ALTER TABLE `ospos_sales_items`
ADD COLUMN `print_option` TINYINT(2) NOT NULL DEFAULT 0;
ADD COLUMN `print_option` TINYINT(2) NOT NULL DEFAULT 0;
ALTER TABLE `ospos_sales_suspended`
ADD COLUMN `quote_number` varchar(32) DEFAULT NULL AFTER `invoice_number`;
ADD COLUMN `quote_number` varchar(32) DEFAULT NULL AFTER `invoice_number`;
ALTER TABLE `ospos_sales_suspended_items`
ADD COLUMN `print_option` TINYINT(2) NOT NULL DEFAULT 0;
ADD COLUMN `print_option` TINYINT(2) NOT NULL DEFAULT 0;
-- alter pic_id field, to rather contain a file name
@@ -39,37 +39,37 @@ CREATE TABLE IF NOT EXISTS `ospos_dinner_tables` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `ospos_dinner_tables` (`dinner_table_id`, `name`, `status`, `deleted`) VALUES
(1, 'Delivery', 0, 0),
(2, 'Take Away', 0, 0);
(1, 'Delivery', 0, 0),
(2, 'Take Away', 0, 0);
-- alter ospos_sales table
ALTER TABLE `ospos_sales`
ADD COLUMN `dinner_table_id` int(11) NULL AFTER `invoice_number`;
ADD COLUMN `dinner_table_id` int(11) NULL AFTER `invoice_number`;
ALTER TABLE `ospos_sales`
ADD KEY `dinner_table_id` (`dinner_table_id`),
ADD CONSTRAINT `ospos_sales_ibfk_3` FOREIGN KEY (`dinner_table_id`) REFERENCES `ospos_dinner_tables` (`dinner_table_id`);
ADD KEY `dinner_table_id` (`dinner_table_id`),
ADD CONSTRAINT `ospos_sales_ibfk_3` FOREIGN KEY (`dinner_table_id`) REFERENCES `ospos_dinner_tables` (`dinner_table_id`);
-- alter ospos_sales_suspended table
ALTER TABLE `ospos_sales_suspended`
ADD COLUMN `dinner_table_id` int(11) NULL AFTER `quote_number`;
ADD COLUMN `dinner_table_id` int(11) NULL AFTER `quote_number`;
ALTER TABLE `ospos_sales_suspended`
ADD KEY `dinner_table_id` (`dinner_table_id`),
ADD CONSTRAINT `ospos_sales_suspended_ibfk_3` FOREIGN KEY (`dinner_table_id`) REFERENCES `ospos_dinner_tables` (`dinner_table_id`);
ADD KEY `dinner_table_id` (`dinner_table_id`),
ADD CONSTRAINT `ospos_sales_suspended_ibfk_3` FOREIGN KEY (`dinner_table_id`) REFERENCES `ospos_dinner_tables` (`dinner_table_id`);
-- add enabled dinner tables key into config
INSERT INTO `ospos_app_config` (`key`, `value`) VALUES
('date_or_time_format', ''),
('sales_quote_format', 'Q%y{QSEQ:6}'),
('default_register_mode', 'sale'),
('last_used_invoice_number', '0'),
('last_used_quote_number', '0'),
('line_sequence', '0'),
('dinner_table_enable','');
('date_or_time_format', ''),
('sales_quote_format', 'Q%y{QSEQ:6}'),
('default_register_mode', 'sale'),
('last_used_invoice_number', '0'),
('last_used_quote_number', '0'),
('line_sequence', '0'),
('dinner_table_enable','');
--
-- Table structure for table `ospos_customer_packages`
@@ -81,14 +81,14 @@ CREATE TABLE IF NOT EXISTS `ospos_customers_packages` (
`points_percent` float NOT NULL DEFAULT '0',
`deleted` int(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`package_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
INSERT INTO `ospos_customers_packages` (`package_id`, `package_name`, `points_percent`, `deleted`) VALUES
(1, 'Default', 0, 0),
(2, 'Bronze', 10, 0),
(3, 'Silver', 20, 0),
(4, 'Gold', 30, 0),
(5, 'Premium', 50, 0);
(1, 'Default', 0, 0),
(2, 'Bronze', 10, 0),
(3, 'Silver', 20, 0),
(4, 'Gold', 30, 0),
(5, 'Premium', 50, 0);
--
-- Table structure for table `ospos_customer_points`
@@ -101,7 +101,7 @@ CREATE TABLE IF NOT EXISTS `ospos_customers_points` (
`sale_id` int(11) NOT NULL,
`points_earned` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
--
-- Table structure for table `ospos_sales_reward_points`
@@ -113,18 +113,19 @@ CREATE TABLE IF NOT EXISTS `ospos_sales_reward_points` (
`earned` float NOT NULL,
`used` float NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
-- alter ospos_customers table
ALTER TABLE ospos_customers
ADD COLUMN `package_id` int(11) DEFAULT NULL AFTER `discount_percent`,
ADD COLUMN `points` int(11) DEFAULT NULL AFTER `package_id`;
ADD COLUMN `package_id` int(11) DEFAULT NULL AFTER `discount_percent`,
ADD COLUMN `points` int(11) DEFAULT NULL AFTER `package_id`;
-- add enabled reward points key into config
INSERT INTO `ospos_app_config` (`key`, `value`) VALUES
('customer_reward_enable','');
('customer_reward_enable','');
--
-- The following changes are in support of customer sales tax changes
@@ -210,7 +211,7 @@ ALTER TABLE `ospos_people`
-- add financial year start into config
INSERT INTO `ospos_app_config` (`key`, `value`) VALUES
('financial_year', '1');
('financial_year', '1');
-- alter giftcard field number to be varchar
@@ -251,7 +252,7 @@ DELETE FROM `ospos_tax_categories` where tax_category_id in (0, 1, 2, 3);
ALTER TABLE `ospos_tax_categories`
MODIFY COLUMN `tax_category_id` int(10) NOT NULL AUTO_INCREMENT;
INSERT INTO `ospos_tax_categories` ( `tax_category_id`,`tax_category`, `tax_group_sequence` ) VALUES
INSERT INTO `ospos_tax_categories` ( `tax_category_id`, `tax_category`, `tax_group_sequence` ) VALUES
(1, 'Standard', 10),
(2, 'Service', 12),
(3, 'Alcohol', 11);
@@ -272,5 +273,26 @@ UPDATE `ospos_tax_code_rates` SET rate_tax_category_id = 1 WHERE rate_tax_catego
-- add receipt font size
INSERT INTO `ospos_app_config` (`key`, `value`) VALUES
('receipt_font_size', '12');
('receipt_font_size', '12');
--
-- Add rewards foreign keys
--
ALTER TABLE `ospos_customers_points`
ADD KEY `person_id` (`person_id`),
ADD KEY `package_id` (`package_id`),
ADD KEY `sale_id` (`sale_id`),
ADD CONSTRAINT `ospos_customers_points_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `ospos_customers` (`person_id`),
ADD CONSTRAINT `ospos_customers_points_ibfk_2` FOREIGN KEY (`package_id`) REFERENCES `ospos_customers_packages` (`package_id`),
ADD CONSTRAINT `ospos_customers_points_ibfk_3` FOREIGN KEY (`sale_id`) REFERENCES `ospos_sales_items` (`sale_id`);
ALTER TABLE `ospos_sales_reward_points`
ADD KEY `sale_id` (`sale_id`),
ADD CONSTRAINT `ospos_sales_reward_points_ibfk_1` FOREIGN KEY (`sale_id`) REFERENCES `ospos_sales_items` (`sale_id`);
ALTER TABLE `ospos_customers`
ADD KEY `package_id` (`package_id`),
ADD CONSTRAINT `ospos_customers_ibfk_2` FOREIGN KEY (`package_id`) REFERENCES `ospos_customers_packages` (`package_id`);

View File

@@ -6,7 +6,8 @@
-- Constraints for table `ospos_customers`
--
ALTER TABLE `ospos_customers`
ADD CONSTRAINT `ospos_customers_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `ospos_people` (`person_id`);
ADD CONSTRAINT `ospos_customers_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `ospos_people` (`person_id`),
ADD CONSTRAINT `ospos_customers_ibfk_2` FOREIGN KEY (`package_id`) REFERENCES `ospos_customers_packages` (`package_id`);
--
-- Constraints for table `ospos_employees`
@@ -146,3 +147,16 @@ ALTER TABLE `ospos_suppliers`
ALTER TABLE `ospos_giftcards`
ADD CONSTRAINT `ospos_giftcards_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `ospos_people` (`person_id`);
--
-- Constraints for table `ospos_customers_points`
--
ALTER TABLE `ospos_customers_points`
ADD CONSTRAINT `ospos_customers_points_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `ospos_customers` (`person_id`),
ADD CONSTRAINT `ospos_customers_points_ibfk_2` FOREIGN KEY (`package_id`) REFERENCES `ospos_customers_packages` (`package_id`),
ADD CONSTRAINT `ospos_customers_points_ibfk_3` FOREIGN KEY (`sale_id`) REFERENCES `ospos_sales_items` (`sale_id`);
--
-- Constraints for table `ospos_sales_reward_points`
--
ALTER TABLE `ospos_sales_reward_points`
ADD CONSTRAINT `ospos_sales_reward_points_ibfk_1` FOREIGN KEY (`sale_id`) REFERENCES `ospos_sales_items` (`sale_id`);

View File

@@ -117,7 +117,8 @@ CREATE TABLE `ospos_customers` (
`points` int(11) DEFAULT NULL,
`deleted` int(1) NOT NULL DEFAULT '0',
UNIQUE KEY `account_number` (`account_number`),
KEY `person_id` (`person_id`)
KEY `person_id` (`person_id`),
KEY `package_id` (`package_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
@@ -923,7 +924,10 @@ CREATE TABLE IF NOT EXISTS `ospos_customers_points` (
`package_id` int(11) NOT NULL,
`sale_id` int(11) NOT NULL,
`points_earned` int(11) NOT NULL,
PRIMARY KEY (`id`)
PRIMARY KEY (`id`),
KEY `person_id` (`person_id`),
KEY `package_id` (`package_id`),
KEY `sale_id` (`sale_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
@@ -938,7 +942,8 @@ CREATE TABLE IF NOT EXISTS `ospos_sales_reward_points` (
`sale_id` int(11) NOT NULL,
`earned` float NOT NULL,
`used` float NOT NULL,
PRIMARY KEY (`id`)
PRIMARY KEY (`id`),
KEY `sale_id` (`sale_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
@@ -952,7 +957,8 @@ CREATE TABLE IF NOT EXISTS `ospos_sales_reward_points` (
-- Constraints for table `ospos_customers`
--
ALTER TABLE `ospos_customers`
ADD CONSTRAINT `ospos_customers_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `ospos_people` (`person_id`);
ADD CONSTRAINT `ospos_customers_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `ospos_people` (`person_id`),
ADD CONSTRAINT `ospos_customers_ibfk_2` FOREIGN KEY (`package_id`) REFERENCES `ospos_customers_packages` (`package_id`);
--
-- Constraints for table `ospos_employees`
@@ -1092,3 +1098,16 @@ ALTER TABLE `ospos_suppliers`
ALTER TABLE `ospos_giftcards`
ADD CONSTRAINT `ospos_giftcards_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `ospos_people` (`person_id`);
--
-- Constraints for table `ospos_customers_points`
--
ALTER TABLE `ospos_customers_points`
ADD CONSTRAINT `ospos_customers_points_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `ospos_customers` (`person_id`),
ADD CONSTRAINT `ospos_customers_points_ibfk_2` FOREIGN KEY (`package_id`) REFERENCES `ospos_customers_packages` (`package_id`),
ADD CONSTRAINT `ospos_customers_points_ibfk_3` FOREIGN KEY (`sale_id`) REFERENCES `ospos_sales_items` (`sale_id`);
--
-- Constraints for table `ospos_sales_reward_points`
--
ALTER TABLE `ospos_sales_reward_points`
ADD CONSTRAINT `ospos_sales_reward_points_ibfk_1` FOREIGN KEY (`sale_id`) REFERENCES `ospos_sales_items` (`sale_id`);

View File

@@ -117,7 +117,8 @@ CREATE TABLE `ospos_customers` (
`points` int(11) DEFAULT NULL,
`deleted` int(1) NOT NULL DEFAULT '0',
UNIQUE KEY `account_number` (`account_number`),
KEY `person_id` (`person_id`)
KEY `person_id` (`person_id`),
KEY `package_id` (`package_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
@@ -923,7 +924,10 @@ CREATE TABLE IF NOT EXISTS `ospos_customers_points` (
`package_id` int(11) NOT NULL,
`sale_id` int(11) NOT NULL,
`points_earned` int(11) NOT NULL,
PRIMARY KEY (`id`)
PRIMARY KEY (`id`),
KEY `person_id` (`person_id`),
KEY `package_id` (`package_id`),
KEY `sale_id` (`sale_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
@@ -938,7 +942,8 @@ CREATE TABLE IF NOT EXISTS `ospos_sales_reward_points` (
`sale_id` int(11) NOT NULL,
`earned` float NOT NULL,
`used` float NOT NULL,
PRIMARY KEY (`id`)
PRIMARY KEY (`id`),
KEY `sale_id` (`sale_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
@@ -1123,7 +1128,8 @@ SELECT `dinner_table_id`, `name`, `status`, `deleted` FROM `phppos`.phppos_dinne
-- Constraints for table `ospos_customers`
--
ALTER TABLE `ospos_customers`
ADD CONSTRAINT `ospos_customers_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `ospos_people` (`person_id`);
ADD CONSTRAINT `ospos_customers_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `ospos_people` (`person_id`),
ADD CONSTRAINT `ospos_customers_ibfk_2` FOREIGN KEY (`package_id`) REFERENCES `ospos_customers_packages` (`package_id`);
--
-- Constraints for table `ospos_employees`
@@ -1263,3 +1269,16 @@ ALTER TABLE `ospos_suppliers`
ALTER TABLE `ospos_giftcards`
ADD CONSTRAINT `ospos_giftcards_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `ospos_people` (`person_id`);
--
-- Constraints for table `ospos_customers_points`
--
ALTER TABLE `ospos_customers_points`
ADD CONSTRAINT `ospos_customers_points_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `ospos_customers` (`person_id`),
ADD CONSTRAINT `ospos_customers_points_ibfk_2` FOREIGN KEY (`package_id`) REFERENCES `ospos_customers_packages` (`package_id`),
ADD CONSTRAINT `ospos_customers_points_ibfk_3` FOREIGN KEY (`sale_id`) REFERENCES `ospos_sales_items` (`sale_id`);
--
-- Constraints for table `ospos_sales_reward_points`
--
ALTER TABLE `ospos_sales_reward_points`
ADD CONSTRAINT `ospos_sales_reward_points_ibfk_1` FOREIGN KEY (`sale_id`) REFERENCES `ospos_sales_items` (`sale_id`);

View File

@@ -117,7 +117,8 @@ CREATE TABLE `ospos_customers` (
`points` int(11) DEFAULT NULL,
`deleted` int(1) NOT NULL DEFAULT '0',
UNIQUE KEY `account_number` (`account_number`),
KEY `person_id` (`person_id`)
KEY `person_id` (`person_id`),
KEY `package_id` (`package_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
@@ -923,7 +924,10 @@ CREATE TABLE IF NOT EXISTS `ospos_customers_points` (
`package_id` int(11) NOT NULL,
`sale_id` int(11) NOT NULL,
`points_earned` int(11) NOT NULL,
PRIMARY KEY (`id`)
PRIMARY KEY (`id`),
KEY `person_id` (`person_id`),
KEY `package_id` (`package_id`),
KEY `sale_id` (`sale_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
@@ -938,7 +942,8 @@ CREATE TABLE IF NOT EXISTS `ospos_sales_reward_points` (
`sale_id` int(11) NOT NULL,
`earned` float NOT NULL,
`used` float NOT NULL,
PRIMARY KEY (`id`)
PRIMARY KEY (`id`),
KEY `sale_id` (`sale_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;