Integrate refund logic

This commit is contained in:
2026-04-01 19:58:53 -06:00
parent a45a437d39
commit 3efb285e17
8 changed files with 4338 additions and 7 deletions

View File

@@ -0,0 +1,33 @@
-- Consolidated Updates: Phone Normalization and Refund Items
-- 1. Create refund_item table
CREATE TABLE IF NOT EXISTS refund_item (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
refund_id BIGINT NOT NULL,
prod_id BIGINT NOT NULL,
quantity INT NOT NULL,
unit_price DECIMAL(10, 2) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (refund_id) REFERENCES refund(id) ON DELETE CASCADE,
FOREIGN KEY (prod_id) REFERENCES product(prodId)
);
-- 2. Normalize existing phone numbers (MySQL Set-based)
UPDATE users
SET phone = CONCAT('(', SUBSTRING(REGEXP_REPLACE(phone, '[^0-9]', ''), -10, 3), ') ',
SUBSTRING(REGEXP_REPLACE(phone, '[^0-9]', ''), -7, 3), '-',
SUBSTRING(REGEXP_REPLACE(phone, '[^0-9]', ''), -4))
WHERE phone REGEXP '[0-9].*[0-9].*[0-9].*[0-9].*[0-9].*[0-9].*[0-9].*[0-9].*[0-9].*[0-9]';
UPDATE supplier
SET supPhone = CONCAT('(', SUBSTRING(REGEXP_REPLACE(supPhone, '[^0-9]', ''), -10, 3), ') ',
SUBSTRING(REGEXP_REPLACE(supPhone, '[^0-9]', ''), -7, 3), '-',
SUBSTRING(REGEXP_REPLACE(supPhone, '[^0-9]', ''), -4))
WHERE supPhone REGEXP '[0-9].*[0-9].*[0-9].*[0-9].*[0-9].*[0-9].*[0-9].*[0-9].*[0-9].*[0-9]';
UPDATE storeLocation
SET phone = CONCAT('(', SUBSTRING(REGEXP_REPLACE(phone, '[^0-9]', ''), -10, 3), ') ',
SUBSTRING(REGEXP_REPLACE(phone, '[^0-9]', ''), -7, 3), '-',
SUBSTRING(REGEXP_REPLACE(phone, '[^0-9]', ''), -4))
WHERE phone REGEXP '[0-9].*[0-9].*[0-9].*[0-9].*[0-9].*[0-9].*[0-9].*[0-9].*[0-9].*[0-9]';