diff --git a/app.py b/app.py index dde2d44c..7c6869d8 100644 --- a/app.py +++ b/app.py @@ -17,8 +17,9 @@ Initializes the Flask application, sets the configuration based on the environme # IMPORTS # internal from config import app_config, Config -from controllers.core import routes_core -from controllers.legal import routes_legal +from controllers.core.contact import routes_core_contact +from controllers.core.home import routes_core_home +from controllers.legal.legal import routes_legal from extensions import db, csrf, mail, oauth from helpers.helper_app import Helper_App # external @@ -106,7 +107,8 @@ with app.app_context(): ) -app.register_blueprint(routes_core) +app.register_blueprint(routes_core_home) +app.register_blueprint(routes_core_contact) app.register_blueprint(routes_legal) diff --git a/business_objects/address.py b/business_objects/address.py deleted file mode 100644 index 572a6ff6..00000000 --- a/business_objects/address.py +++ /dev/null @@ -1,106 +0,0 @@ -""" -Project: PARTS Website -Author: Edward Middleton-Smith - Precision And Research Technology Systems Limited - -Technology: Business Objects -Feature: Address Business Object - -Description: -Business object for address -""" - -# internal -import lib.argument_validation as av -from business_objects.base import Base -from business_objects.region import Region -from extensions import db -from helpers.helper_app import Helper_App -# external -from typing import ClassVar -from flask import jsonify - -class Address(db.Model, Base): - FLAG_ADDRESS_LINE_1: ClassVar[str] = 'address_line_1' - FLAG_ADDRESS_LINE_2: ClassVar[str] = 'address_line_2' - FLAG_CITY: ClassVar[str] = 'city' - FLAG_COUNTY: ClassVar[str] = 'county' - NAME_ATTR_OPTION_VALUE: ClassVar[str] = Base.ATTR_ID_ADDRESS - NAME_ATTR_OPTION_TEXT: ClassVar[str] = Base.FLAG_POSTCODE - __tablename__ = 'Shop_Address' - id_address = db.Column(db.Integer, primary_key=True) - id_region = db.Column(db.Integer) - postcode = db.Column(db.String(20)) - address_line_1 = db.Column(db.String(256)) - address_line_2 = db.Column(db.String(256)) - city = db.Column(db.String(256)) - county = db.Column(db.String(256)) - active = db.Column(db.Boolean) - - # region = None - - def __init__(self): - super().__init__() - Base.__init__(self) - self.region = None - @classmethod - def from_DB_storage_location(cls, query_row): - address = cls() - address.id_address = query_row[2] - address.id_region = query_row[3] - return address - @classmethod - def from_DB_plant(cls, query_row): - address = cls() - address.id_address = query_row[1] - address.id_region = query_row[2] - return address - @classmethod - def from_DB_stock_item(cls, query_row): - address = cls() - address.id_address = query_row[6] - address.id_region = query_row[7] - return address - @classmethod - def from_DB_supplier(cls, query_row): - address = cls() - address.id_address = query_row[1] - address.postcode = query_row[2] - return address - def __repr__(self): - return f''' - {self.ATTR_ID_ADDRESS}: {self.id_address} - {self.FLAG_REGION}: {self.region} - {self.FLAG_POSTCODE}: {self.postcode} - {self.FLAG_ADDRESS_LINE_1}: {self.address_line_1} - {self.FLAG_ADDRESS_LINE_2}: {self.address_line_2} - {self.FLAG_CITY}: {self.city} - {self.FLAG_COUNTY}: {self.county} - {self.FLAG_ACTIVE}: {self.active} - ''' - def to_json(self): - return { - **self.get_shared_json_attributes(self), - self.ATTR_ID_ADDRESS: self.id_address, - self.FLAG_REGION: None if self.region is None else self.region.to_json(), - self.FLAG_POSTCODE: self.postcode, - self.FLAG_ADDRESS_LINE_1: self.address_line_1, - self.FLAG_ADDRESS_LINE_2: self.address_line_2, - self.FLAG_CITY: self.city, - self.FLAG_COUNTY: self.county, - self.FLAG_ACTIVE: 1 if av.input_bool(self.active, self.FLAG_ACTIVE, f'{self.__class__.__name__}.to_json') else 0 - } - def to_json_str(self): - return jsonify(self.to_json()) - @classmethod - def from_json(cls, json): - address = cls() - address.id_address = json[cls.ATTR_ID_ADDRESS], - address.region = Region.from_json(json[cls.FLAG_REGION]), - address.postcode = json[cls.FLAG_POSTCODE], - address.address_line_1 = json[cls.FLAG_ADDRESS_LINE_1], - address.address_line_2 = json.get(cls.FLAG_ADDRESS_LINE_2, ''), - address.city = json[cls.FLAG_CITY], - address.county = json[cls.FLAG_COUNTY], - address.active = json[cls.FLAG_ACTIVE] - return address \ No newline at end of file diff --git a/business_objects/base.py b/business_objects/base.py index c2ea34d7..dcf44648 100644 --- a/business_objects/base.py +++ b/business_objects/base.py @@ -7,7 +7,7 @@ Technology: Business Objects Feature: Base Business Object Description: -Abstract business object +Abstract base class for all business objects in app """ # internal @@ -67,6 +67,7 @@ class Base(): FLAG_VALUE_LOCAL_VAT_EXCL: ClassVar[str] = 'value_local_vat_excl' FLAG_VALUE_LOCAL_VAT_INCL: ClassVar[str] = 'value_local_vat_incl' FLAG_WEBSITE: ClassVar[str] = 'website' + ID_USER_GUEST: ClassVar[int] = 3 """ NAME_ATTR_OPTION_TEXT: ClassVar[str] = 'name-attribute-option-text' NAME_ATTR_OPTION_VALUE: ClassVar[str] = 'name-attribute-option-value' diff --git a/business_objects/currency.py b/business_objects/currency.py deleted file mode 100644 index 28af019f..00000000 --- a/business_objects/currency.py +++ /dev/null @@ -1,147 +0,0 @@ -""" -Project: PARTS Website -Author: Edward Middleton-Smith - Precision And Research Technology Systems Limited - -Technology: Business Objects -Feature: Product Business Object - -Description: -Business object for product -""" - -# internal -from business_objects.store.store_base import Store_Base -from extensions import db -from lib import argument_validation as av -# external -from typing import ClassVar - -# CLASSES -""" -class Currency_Enum(Enum): - GBP = 1 - - def text(self): - return Currency_Enum.Currency_Enum_Text(self) - - def Currency_Enum_Text(currency): - av.val_instance(currency, 'currency', 'Currency_Enum_Text', Currency_Enum) - if currency == Currency_Enum.GBP: - return 'GBP' - else: - # return 'Unknown' - raise ValueError("Unknown Currency Enum.") - - def get_member_by_text(text): - for member in Resolution_Level_Enum.__members__.values(): - if member.name == text: - return member - raise ValueError("Unknown Currency Enum.") - # return Resolution_Level_Enum.HIGH -""" - -class Currency(db.Model, Store_Base): - FLAG_FACTOR_FROM_GBP: ClassVar[str] = 'factor-from-GBP' - NAME_ATTR_OPTION_VALUE: ClassVar[str] = Store_Base.ATTR_ID_CURRENCY - NAME_ATTR_OPTION_TEXT: ClassVar[str] = Store_Base.FLAG_NAME - - id_currency = db.Column(db.Integer, primary_key=True) - code = db.Column(db.String(50)) - name = db.Column(db.String(255)) - symbol = db.Column(db.String(50)) - factor_from_GBP = db.Column(db.Float) - display_order = db.Column(db.Integer) - active = db.Column(db.Boolean) - @classmethod - def from_DB_currency(cls, query_row): - _m = 'Currency.from_DB_currency' - v_arg_type = 'class attribute' - currency = cls() - currency.id_currency = query_row[0] - currency.code = query_row[1] - currency.name = query_row[2] - currency.symbol = query_row[3] - currency.factor_from_GBP = query_row[4] - currency.display_order = query_row[5] - currency.active = av.input_bool(query_row[6], 'active', _m, v_arg_type=v_arg_type) - return currency - @classmethod - def from_DB_get_many_product_catalogue_product_permutation(cls, query_row): - currency = cls() - currency.id_currency = query_row[6] - currency.code = query_row[7] - currency.symbol = query_row[8] - return currency - @classmethod - def from_DB_get_many_product_price_and_discount_and_delivery_region(cls, query_row): - currency = cls() - return currency - @classmethod - def from_DB_stock_item(cls, query_row): - currency = cls() - currency.id_currency = query_row[12] - currency.code = query_row[13] - currency.symbol = query_row[14] - return currency - @classmethod - def from_DB_supplier(cls, query_row): - currency = cls() - currency.id_currency = query_row[1] - currency.code = query_row[2] - currency.symbol = query_row[3] - return currency - @classmethod - def from_DB_supplier_purchase_order(cls, query_row): - currency = cls() - currency.id_currency = query_row[3] - currency.code = query_row[4] - currency.symbol = query_row[5] - return currency - @classmethod - def from_DB_manufacturing_purchase_order(cls, query_row): - currency = cls() - currency.id_currency = query_row[1] - currency.code = query_row[2] - currency.symbol = query_row[3] - return currency - def __repr__(self): - return f''' - id: {self.id_currency} - name: {self.name} - code: {self.code} - symbol: {self.symbol} - factor from GBP: {self.factor_from_GBP} - display_order: {self.display_order} - active: {self.active} - ''' - def to_json(self): - return { - **self.get_shared_json_attributes(self), - self.NAME_ATTR_OPTION_TEXT: self.FLAG_NAME, - self.NAME_ATTR_OPTION_VALUE: self.ATTR_ID_CURRENCY, - self.ATTR_ID_CURRENCY: self.id_currency, - self.FLAG_CODE: self.code, - self.FLAG_NAME: self.name, - self.FLAG_SYMBOL: self.symbol, - self.FLAG_FACTOR_FROM_GBP: self.factor_from_GBP, - self.FLAG_DISPLAY_ORDER: self.display_order, - self.FLAG_ACTIVE: self.active, - } - @classmethod - def from_json(cls, json_currency, key_suffix = ''): - currency = cls() - currency.id_currency = json_currency[f'{cls.ATTR_ID_CURRENCY}{key_suffix}'] - currency.code = json_currency.get(f'{cls.FLAG_CODE}{key_suffix}') - currency.name = json_currency.get(f'{cls.FLAG_NAME}{key_suffix}') - currency.symbol = json_currency.get(f'{cls.FLAG_SYMBOL}{key_suffix}') - currency.factor_from_GBP = json_currency.get(f'{cls.FLAG_FACTOR_FROM_GBP}{key_suffix}') - currency.display_order = json_currency.get(f'{cls.FLAG_DISPLAY_ORDER}{key_suffix}') - currency.active = json_currency.get(f'{cls.FLAG_ACTIVE}{key_suffix}') - return currency - - def to_json_option(self): - return { - 'value': self.id_currency, - 'text': self.name - } \ No newline at end of file diff --git a/business_objects/db_base.py b/business_objects/db_base.py index b711a9fd..f82a7378 100644 --- a/business_objects/db_base.py +++ b/business_objects/db_base.py @@ -7,7 +7,7 @@ Technology: Business Objects Feature: Database Base Business Objects Description: -Abstract business object for database objects +Abstract base class for database objects """ # internal @@ -22,32 +22,7 @@ from sqlalchemy.ext.declarative import DeclarativeMeta # from flask_sqlalchemy import SQLAlchemy -class Get_Many_Parameters_Base(BaseModel, metaclass=ABCMeta): - # a_id_user: int - def __init__(self, **kwargs): # , a_id_user - super().__init__(**kwargs) # a_id_user=a_id_user, - @classmethod - @abstractmethod - def get_default(cls): # , id_user - pass - def to_json(self): - return self.dict() - """ - @classmethod - @abstractmethod - def from_json(cls, json): - pass - """ - """ - @classmethod - @abstractmethod - def from_form(cls, form): - pass - """ - -# db = SQLAlchemy() -# Base = declarative_base() class SQLAlchemy_ABCMeta(db.Model.__class__, ABCMeta): pass @@ -63,10 +38,6 @@ class SQLAlchemy_ABC(db.Model, metaclass=SQLAlchemy_ABCMeta): @classmethod def from_json(cls, json): pass - """ - def to_json_option(self): - pass - """ def to_temporary_record(self): pass def to_object_with_missing_attributes(self, excluded_attributes): diff --git a/business_objects/access_level.py b/business_objects/project_hub/DEPRECATED - access_level.py similarity index 95% rename from business_objects/access_level.py rename to business_objects/project_hub/DEPRECATED - access_level.py index 95828157..743c0a7d 100644 --- a/business_objects/access_level.py +++ b/business_objects/project_hub/DEPRECATED - access_level.py @@ -23,16 +23,13 @@ from typing import ClassVar class Access_Level(db.Model, Base): NAME_ATTR_OPTION_VALUE: ClassVar[str] = Base.ATTR_ID_ACCESS_LEVEL NAME_ATTR_OPTION_TEXT: ClassVar[str] = Base.FLAG_NAME - __tablename__ = 'Shop_Access_Level_Temp' + __tablename__ = 'PH_Access_Level_Temp' id_access_level = db.Column(db.Integer, primary_key=True) code = db.Column(db.String(50)) name = db.Column(db.String(255)) - description = db.Column(db.String(4000)) priority = db.Column(db.Integer) display_order = db.Column(db.Integer) active = db.Column(db.Boolean) - created_on = db.Column(db.DateTime) - created_by = db.Column(db.Integer) def __init__(self): super().__init__() Base.__init__(self) diff --git a/business_objects/project_hub/__init__.py b/business_objects/project_hub/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/business_objects/project_hub/contact_form.py b/business_objects/project_hub/contact_form.py new file mode 100644 index 00000000..28f68ce4 --- /dev/null +++ b/business_objects/project_hub/contact_form.py @@ -0,0 +1,136 @@ +""" +Project: PARTS Website +Author: Edward Middleton-Smith + Precision And Research Technology Systems Limited + +Technology: Business Objects +Feature: Contact_Form Business Object +""" + +# internal +from business_objects.base import Base +from business_objects.db_base import SQLAlchemy_ABC +import lib.argument_validation as av +from extensions import db +from helpers.helper_app import Helper_App +# external +from dataclasses import dataclass +from typing import ClassVar + + +class Contact_Form(SQLAlchemy_ABC, Base): + FLAG_ALTCHA: ClassVar[str] = 'altcha' + FLAG_CONTACT_FORM: ClassVar[str] = 'contact-form' + FLAG_NAME_COMPANY: ClassVar[str] = 'name-company' + FLAG_NAME_CONTACT: ClassVar[str] = 'name-contact' + FLAG_MESSAGE: ClassVar[str] = 'message' + FLAG_RECEIVE_MARKETING_COMMUNICATIONS: ClassVar[str] = 'receive-marketing-communications' + NAME_ATTR_OPTION_VALUE: ClassVar[str] = FLAG_CONTACT_FORM + NAME_ATTR_OPTION_TEXT: ClassVar[str] = Base.FLAG_EMAIL + + __tablename__ = 'PH_Contact_Form' + __table_args__ = { 'extend_existing': True } + + id_contact_form = db.Column(db.Integer, primary_key=True) + email = db.Column(db.String(255)) + name_contact = db.Column(db.String(255)) + name_company = db.Column(db.String(255)) + message = db.Column(db.Text) + receive_marketing_communications = db.Column(db.Boolean) + active = db.Column(db.Boolean) + created_on = db.Column(db.DateTime) + + def __init__(self): + self.id_contact_form = 0 + self.is_new = False + super().__init__() + + def from_DB_Contact_Form(query_row): + _m = 'Contact_Form.from_DB_Contact_Form' + contact_form = Contact_Form() + contact_form.id_contact_form = query_row[0] + contact_form.email = query_row[1] + contact_form.name_contact = query_row[2] + contact_form.name_company = query_row[3] + contact_form.message = query_row[4] + contact_form.receive_marketing_communications = av.input_bool(query_row[5], 'receive_marketing_communications', _m) + contact_form.active = av.input_bool(query_row[6], 'active', _m) + contact_form.created_on = query_row[7] + return contact_form + + @classmethod + def from_json(cls, json): + _m = 'Contact_Form.from_json' + contact_form = cls() + if json is None: return Contact_Form + Helper_App.console_log(f'{_m}\njson: {json}') + contact_form.id_contact_form = -1 + contact_form.email = json[cls.FLAG_EMAIL] + contact_form.name_contact = json[cls.FLAG_NAME_CONTACT] + contact_form.name_company = json[cls.FLAG_NAME_COMPANY] + contact_form.message = json[cls.FLAG_MESSAGE] + contact_form.receive_marketing_communications = json[cls.FLAG_RECEIVE_MARKETING_COMMUNICATIONS] + contact_form.active = json[cls.FLAG_ACTIVE] + contact_form.created_on = json.get(cls.FLAG_CREATED_ON, None) + Helper_App.console_log(f'Contact_Form: {contact_form}') + return contact_form + + + def to_json(self): + as_json = { + self.FLAG_CONTACT_FORM: self.id_contact_form + , self.FLAG_EMAIL: self.email + , self.FLAG_NAME_CONTACT: self.name_contact + , self.FLAG_NAME_COMPANY: self.name_company + , self.FLAG_MESSAGE: self.message + , self.FLAG_RECEIVE_MARKETING_COMMUNICATIONS: self.receive_marketing_communications + , self.FLAG_ACTIVE: self.active + , self.FLAG_CREATED_ON: self.created_on + } + Helper_App.console_log(f'as_json: {as_json}') + return as_json + + def __repr__(self): + return f''' +{self.__class__.__name__}( + {self.FLAG_CONTACT_FORM}: {self.id_contact_form} + {self.FLAG_EMAIL}: {self.email} + {self.FLAG_NAME_CONTACT}: {self.name_contact} + {self.FLAG_NAME_COMPANY}: {self.name_company} + {self.FLAG_MESSAGE}: {self.message} + {self.FLAG_RECEIVE_MARKETING_COMMUNICATIONS}: {self.receive_marketing_communications} + {self.FLAG_ACTIVE}: {self.active} + {self.FLAG_CREATED_ON}: {self.created_on} +) + ''' + +class Contact_Form_Temp(db.Model, Base): + __tablename__ = 'PH_Contact_Form_Temp' + __table_args__ = { 'extend_existing': True } + id_temp = db.Column(db.Integer, primary_key=True) + id_contact_form = db.Column(db.Integer) + email = db.Column(db.String(255)) + name_contact = db.Column(db.String(255)) + name_company = db.Column(db.String(255)) + message = db.Column(db.Text) + receive_marketing_communications = db.Column(db.Boolean) + active = db.Column(db.Boolean) + created_on = db.Column(db.DateTime) + guid: str = db.Column(db.String(36)) + + def __init__(self): + super().__init__() + + @classmethod + def from_contact_form(cls, contact_form): + _m = 'Contact_Form_Temp.from_Contact_Form' + temp = cls() + temp.id_contact_form = contact_form.id_contact_form + temp.email = contact_form.email + temp.name_contact = contact_form.name_contact + temp.name_company = contact_form.name_company + temp.message = contact_form.message + temp.receive_marketing_communications + temp.active = contact_form.active + temp.created_on = contact_form.created_on + return temp \ No newline at end of file diff --git a/business_objects/project_hub/user.py b/business_objects/project_hub/user.py new file mode 100644 index 00000000..e5b5551c --- /dev/null +++ b/business_objects/project_hub/user.py @@ -0,0 +1,133 @@ +""" +Project: PARTS Website +Author: Edward Middleton-Smith + Precision And Research Technology Systems Limited + +Technology: Business Objects +Feature: User Business Object +""" + +# internal +from business_objects.base import Base +from business_objects.db_base import SQLAlchemy_ABC +import lib.argument_validation as av +from forms.forms import Form_Contact +from extensions import db +from helpers.helper_app import Helper_App +# external +from dataclasses import dataclass +from typing import ClassVar + + +class User(SQLAlchemy_ABC, Base): + NAME_ATTR_OPTION_VALUE: ClassVar[str] = Base.ATTR_ID_USER + NAME_ATTR_OPTION_TEXT: ClassVar[str] = 'email' + + __tablename__ = 'PH_User' + __table_args__ = { 'extend_existing': True } + + id_user = db.Column(db.Integer, primary_key=True) + id_user_auth0 = db.Column(db.String(255)) + firstname = db.Column(db.String(255)) + surname = db.Column(db.String(255)) + email = db.Column(db.String(255)) + is_email_verified = db.Column(db.Boolean) + is_super_user = db.Column(db.Boolean) + is_new = db.Column(db.Boolean) + + def __init__(self): + self.id_user = 0 + self.is_new = False + super().__init__() + + def from_DB_user(query_row): + _m = 'User.from_DB_user' + user = User() + user.id_user = query_row[0] + user.id_user_auth0 = query_row[1] + user.firstname = query_row[2] + user.surname = query_row[3] + user.email = query_row[4] + user.is_email_verified = av.input_bool(query_row[5], 'is_email_verified', _m) + user.is_super_user = av.input_bool(query_row[9], 'is_super_user', _m) + user.is_new = av.input_bool(query_row[12], 'is_new', _m) + return user + + @staticmethod + def from_json(json): + _m = 'User.from_json' + user = User() + if json is None: return user + Helper_App.console_log(f'{_m}\njson: {json}') + user.id_user = json['id_user'] + user.id_user_auth0 = json['id_user_auth0'] + user.firstname = json['firstname'] + user.surname = json['surname'] + user.email = json['email'] + user.is_email_verified = av.input_bool(json['is_email_verified'], 'is_email_verified', _m) + user.is_super_user = av.input_bool(json['is_super_user'], 'is_super_user', _m) + Helper_App.console_log(f'user: {user}') + return user + + @staticmethod + def from_json_auth0(json): + _m = 'User.from_json_auth0' + user = User() + if json is None: return user + Helper_App.console_log(f'{_m}\njson: {json}') + user_info = json['userinfo'] + user.id_user = None + user.id_user_auth0 = user_info['sub'] + user.firstname = None + user.surname = None + user.email = user_info['email'] + user.is_email_verified = av.input_bool(user_info['email_verified'], 'is_email_verified', _m) + user.is_super_user = None + Helper_App.console_log(f'user: {user}') + return user + + def to_json(self): + as_json = { + 'id_user': self.id_user, + 'id_user_auth0': self.id_user_auth0, + 'firstname': self.firstname, + 'surname': self.surname, + 'email': self.email, + 'is_email_verified': self.is_email_verified, + 'is_super_user': self.is_super_user + } + Helper_App.console_log(f'as_json: {as_json}') + return as_json + + def __repr__(self): + return f''' + id_user: {self.id_user} + id_user_auth0: {self.id_user_auth0} + firstname: {self.firstname} + surname: {self.surname} + email: {self.email} + is_email_verified: {self.is_email_verified} + is_super_user: {self.is_super_user} + ''' + + def get_is_logged_in(self): + return (self.id_user > 0 and self.id_user != Base.ID_USER_GUEST) + +class User_Temp(db.Model, Base): + __tablename__ = 'Shop_User_Temp' + __table_args__ = { 'extend_existing': True } + id_user = db.Column(db.Integer, primary_key=True) + id_user_auth0 = db.Column(db.String(255)) + firstname = db.Column(db.String(255)) + surname = db.Column(db.String(255)) + email = db.Column(db.String(255)) + is_email_verified = db.Column(db.Boolean) + is_super_user = db.Column(db.Boolean) + id_currency_default = db.Column(db.Integer) + id_region_default = db.Column(db.Integer) + is_included_VAT_default = db.Column(db.Boolean) + # is_logged_in: bool + + def __init__(self): + self.id_user = 0 + super().__init__() \ No newline at end of file diff --git a/business_objects/region.py b/business_objects/region.py deleted file mode 100644 index dbecd0c5..00000000 --- a/business_objects/region.py +++ /dev/null @@ -1,86 +0,0 @@ -""" -Project: PARTS Website -Author: Edward Middleton-Smith - Precision And Research Technology Systems Limited - -Technology: Business Objects -Feature: Address Region Business Object - -Description: -Business object for address region -""" - -# internal -import lib.argument_validation as av -from business_objects.base import Base -from extensions import db -from helpers.helper_app import Helper_App -# external -from typing import ClassVar - - -class Region(db.Model, Base): - NAME_ATTR_OPTION_VALUE: ClassVar[str] = Base.ATTR_ID_REGION - NAME_ATTR_OPTION_TEXT: ClassVar[str] = Base.FLAG_NAME - __tablename__ = 'Shop_Region' - id_region = db.Column(db.Integer, primary_key=True) - code = db.Column(db.String(50)) - name = db.Column(db.String(200)) - active = db.Column(db.Boolean) - - # region = None - - def __init__(self): - super().__init__() - Base.__init__(self) - - @classmethod - def from_DB_stock_item(cls, query_row): - region = cls() - region.id_region = query_row[7] - return region - @classmethod - def from_DB_supplier(cls, query_row): - region = cls() - region.id_region = query_row[2] - region.name = query_row[3] - return region - def __repr__(self): - return f''' - {self.ATTR_ID_REGION}: {self.id_region} - {self.FLAG_CODE}: {self.code} - {self.FLAG_NAME}: {self.name} - {self.FLAG_ACTIVE}: {self.active} - ''' - def to_json(self): - return { - **self.get_shared_json_attributes(self), - self.ATTR_ID_REGION: self.id_region, - self.FLAG_CODE: self.code, - self.FLAG_NAME: self.name, - self.FLAG_ACTIVE: 1 if av.input_bool(self.active, self.FLAG_ACTIVE, f'{self.__class__.__name__}.to_json') else 0 - } - @classmethod - def from_json(cls, json): - plant = cls() - plant.id_region = json[cls.ATTR_ID_REGION] - plant.code = json[cls.FLAG_CODE] - plant.name = json[cls.FLAG_NAME] - plant.active = json[cls.FLAG_ACTIVE] - return plant - @classmethod - def from_DB_get_many_product_catalogue(cls, query_row): - region = cls() - region.id_region = query_row[0] - region.name = query_row[1] - region.code = query_row[2] - # self.display_order = query_row[3] - return region - @classmethod - def from_DB_region(cls, query_row): - region = cls() - region.id_region = query_row[0] - region.code = query_row[1] - region.name = query_row[2] - region.active = av.input_bool(query_row[3], cls.FLAG_ACTIVE, f'{cls.__name__}.from_DB_region') - return region diff --git a/business_objects/sql_error.py b/business_objects/sql_error.py index d7214428..1b562b2e 100644 --- a/business_objects/sql_error.py +++ b/business_objects/sql_error.py @@ -7,7 +7,7 @@ Technology: Business Objects Feature: SQL Error Business Object Description: -Business object for SQL errors +Business object for SQL errors returned by Get Many Stored Procedures """ # internal @@ -22,11 +22,9 @@ import locale from flask_sqlalchemy import SQLAlchemy -# VARIABLE INSTANTIATION db = SQLAlchemy() -# CLASSES class SQL_Error(db.Model): display_order = db.Column(db.Integer, primary_key=True) id_type = db.Column(db.Integer) diff --git a/business_objects/unit_measurement.py b/business_objects/unit_measurement.py deleted file mode 100644 index 2f5cc80e..00000000 --- a/business_objects/unit_measurement.py +++ /dev/null @@ -1,109 +0,0 @@ -""" -Project: PARTS Website -Author: Edward Middleton-Smith - Precision And Research Technology Systems Limited - -Technology: Business Objects -Feature: Unit of Measurement Business Object -""" - -# internal -from business_objects.base import Base -from business_objects.db_base import SQLAlchemy_ABC, Get_Many_Parameters_Base -from extensions import db -# from forms.forms import Form_Filters_User -from helpers.helper_app import Helper_App -import lib.argument_validation as av -# external -from dataclasses import dataclass -from typing import ClassVar - - -class Unit_Measurement(SQLAlchemy_ABC, Base): - ATTR_ID_UNIT_MEASUREMENT: ClassVar[str] = 'id_unit_measurement' - FLAG_IS_BASE_UNIT: ClassVar[str] = 'is_base_unit' - FLAG_IS_UNIT_OF_DISTANCE: ClassVar[str] = 'is_unit_of_distance' - FLAG_IS_UNIT_OF_MASS: ClassVar[str] = 'is_unit_of_mass' - FLAG_IS_UNIT_OF_TIME: ClassVar[str] = 'is_unit_of_time' - FLAG_IS_UNIT_OF_VOLUME: ClassVar[str] = 'is_unit_of_volume' - FLAG_NAME_PLURAL: ClassVar[str] = 'name_plural' - FLAG_NAME_SINGULAR: ClassVar[str] = 'name_singular' - FLAG_SYMBOL: ClassVar[str] = 'symbol' - FLAG_SYMBOL_IS_SUFFIX_NOT_PREFIX: ClassVar[str] = 'symbol_is_suffix_not_prefix' - # KEY_UNIT_MEASUREMENT: ClassVar[str] = 'unit_of_measurement' - NAME_ATTR_OPTION_VALUE: ClassVar[str] = ATTR_ID_UNIT_MEASUREMENT - NAME_ATTR_OPTION_TEXT: ClassVar[str] = FLAG_NAME_SINGULAR - - id_unit_measurement = db.Column(db.Integer, primary_key=True) - name_singular = db.Column(db.String(255)) - name_plural = db.Column(db.String(256)) - symbol = db.Column(db.String(50)) - symbol_is_suffix_not_prefix = db.Column(db.Boolean) - is_base_unit = db.Column(db.Boolean) - is_unit_of_distance = db.Column(db.Boolean) - is_unit_of_mass = db.Column(db.Boolean) - is_unit_of_time = db.Column(db.Boolean) - is_unit_of_volume = db.Column(db.Boolean) - active = db.Column(db.Boolean) - - def from_DB_unit_measurement(query_row): - _m = 'Unit_Measurement.from_DB_unit_measurement' - unit = Unit_Measurement() - unit.id_unit_measurement = query_row[0] - unit.name_singular = query_row[1] - unit.name_plural = query_row[2] - unit.symbol = query_row[3] - unit.symbol_is_suffix_not_prefix = av.input_bool(query_row[4], 'symbol_is_suffix_not_prefix', _m) - unit.is_base_unit = av.input_bool(query_row[5], 'is_base_unit', _m) - unit.is_unit_of_distance = av.input_bool(query_row[6], 'is_unit_of_distance', _m) - unit.is_unit_of_mass = av.input_bool(query_row[7], 'is_unit_of_mass', _m) - unit.is_unit_of_time = av.input_bool(query_row[8], 'is_unit_of_time', _m) - unit.is_unit_of_volume = av.input_bool(query_row[9], 'is_unit_of_volume', _m) - unit.active = av.input_bool(query_row[10], 'active', _m) - return unit - - def to_json(self): - return { - **self.get_shared_json_attributes(self), - self.ATTR_ID_UNIT_MEASUREMENT: self.id_unit_measurement, - self.FLAG_NAME_SINGULAR: self.name_singular, - self.FLAG_NAME_PLURAL: self.name_plural, - self.FLAG_SYMBOL: self.symbol, - self.FLAG_SYMBOL_IS_SUFFIX_NOT_PREFIX: self.symbol_is_suffix_not_prefix, - self.FLAG_IS_BASE_UNIT: self.is_base_unit, - self.FLAG_IS_UNIT_OF_DISTANCE: self.is_unit_of_distance, - self.FLAG_IS_UNIT_OF_MASS: self.is_unit_of_mass, - self.FLAG_IS_UNIT_OF_TIME: self.is_unit_of_time, - self.FLAG_IS_UNIT_OF_VOLUME: self.is_unit_of_volume, - self.FLAG_ACTIVE: self.active, - } - @classmethod - def from_json(cls, json): - unit = cls() - unit.id_unit_measurement = json[cls.ATTR_ID_UNIT_MEASUREMENT] - unit.name_singular = json[cls.FLAG_NAME_SINGULAR] - unit.name_plural = json[cls.FLAG_NAME_PLURAL] - unit.symbol = json[cls.FLAG_SYMBOL] - unit.symbol_is_suffix_not_prefix = json[cls.FLAG_SYMBOL_IS_SUFFIX_NOT_PREFIX] - unit.is_base_unit = json[cls.FLAG_IS_BASE_UNIT] - unit.is_unit_of_distance = json[cls.FLAG_IS_UNIT_OF_DISTANCE] - unit.is_unit_of_mass = json[cls.FLAG_IS_UNIT_OF_MASS] - unit.is_unit_of_time = json[cls.FLAG_IS_UNIT_OF_TIME] - unit.is_unit_of_volume = json[cls.FLAG_IS_UNIT_OF_VOLUME] - unit.active = json[cls.FLAG_ACTIVE] - return unit - - def __repr__(self): - return f''' - id_unit_of_measurement: {self.id_unit_measurement}, - name_singular: {self.name_singular}, - name_plural: {self.name_plural}, - symbol: {self.symbol}, - symbol_is_suffix_not_prefix: {self.symbol_is_suffix_not_prefix}, - is_base_unit: {self.is_base_unit}, - is_unit_of_distance: {self.is_unit_of_distance}, - is_unit_of_mass: {self.is_unit_of_mass}, - is_unit_of_time: {self.is_unit_of_time}, - is_unit_of_volume: {self.is_unit_of_volume}, - active: {self.active} - ''' diff --git a/business_objects/user.py b/business_objects/user.py deleted file mode 100644 index c198bbb2..00000000 --- a/business_objects/user.py +++ /dev/null @@ -1,293 +0,0 @@ -""" -Project: PARTS Website -Author: Edward Middleton-Smith - Precision And Research Technology Systems Limited - -Technology: Business Objects -Feature: User Business Object -""" - -# internal -from business_objects.base import Base -from business_objects.db_base import Get_Many_Parameters_Base -import lib.argument_validation as av -from forms.forms import Form_Filters_User -from extensions import db -from helpers.helper_app import Helper_App -# external -from dataclasses import dataclass -from typing import ClassVar - - -class User(db.Model, Base): - NAME_ATTR_OPTION_VALUE: ClassVar[str] = Base.ATTR_ID_USER - NAME_ATTR_OPTION_TEXT: ClassVar[str] = 'email' - - __tablename__ = 'Shop_User' - __table_args__ = { 'extend_existing': True } - - id_user = db.Column(db.Integer, primary_key=True) - id_user_auth0 = db.Column(db.String(255)) - firstname = db.Column(db.String(255)) - surname = db.Column(db.String(255)) - email = db.Column(db.String(255)) - is_email_verified = db.Column(db.Boolean) - is_super_user = db.Column(db.Boolean) - id_currency_default = db.Column(db.Integer) - id_region_default = db.Column(db.Integer) - is_included_VAT_default = db.Column(db.Boolean) - can_admin_store = db.Column(db.Boolean) - can_admin_user = db.Column(db.Boolean) - is_new = db.Column(db.Boolean) - # is_logged_in: bool - - def __init__(self): - self.id_user = 0 - self.is_logged_in = False - self.is_new = False - super().__init__() - self.currency_default = None - self.region_default = None - - def from_DB_user(query_row): - _m = 'User.from_DB_user' - user = User() - user.id_user = query_row[0] - user.id_user_auth0 = query_row[1] - user.firstname = query_row[2] - user.surname = query_row[3] - user.email = query_row[4] - user.is_email_verified = av.input_bool(query_row[5], 'is_email_verified', _m) - user.id_currency_default = query_row[6] - user.id_region_default = query_row[7] - user.is_included_VAT_default = av.input_bool(query_row[8], 'is_included_VAT_default', _m) - user.is_super_user = av.input_bool(query_row[9], 'is_super_user', _m) - user.can_admin_store = av.input_bool(query_row[10], 'can_admin_store', _m) - user.can_admin_user = av.input_bool(query_row[11], 'can_admin_user', _m) - user.is_logged_in = (user.id_user is not None and user.id_user > 0) - user.is_new = av.input_bool(query_row[12], 'is_new', _m) - return user - - @staticmethod - def from_json(json): - _m = 'User.from_json' - user = User() - if json is None: return user - Helper_App.console_log(f'{_m}\njson: {json}') - user.id_user = json['id_user'] - user.id_user_auth0 = json['id_user_auth0'] - user.firstname = json['firstname'] - user.surname = json['surname'] - user.email = json['email'] - user.is_email_verified = av.input_bool(json['is_email_verified'], 'is_email_verified', _m) - user.is_super_user = av.input_bool(json['is_super_user'], 'is_super_user', _m) - user.id_currency_default = json['id_currency_default'] - user.id_region_default = json['id_region_default'] - user.is_included_VAT_default = av.input_bool(json['is_included_VAT_default'], 'is_included_VAT_default', _m) - user.can_admin_store = av.input_bool(json['can_admin_store'], 'can_admin_store', _m) - user.can_admin_user = av.input_bool(json['can_admin_user'], 'can_admin_user', _m) - user.is_logged_in = (user.id_user_auth0 is not None) - Helper_App.console_log(f'user: {user}') - return user - - # Helper_App.console_log(f'user: {user}') - @staticmethod - def from_json_auth0(json): - _m = 'User.from_json_auth0' - user = User() - if json is None: return user - Helper_App.console_log(f'{_m}\njson: {json}') - user_info = json['userinfo'] - user.id_user = None - user.id_user_auth0 = user_info['sub'] - user.firstname = None - user.surname = None - user.email = user_info['email'] - user.is_email_verified = av.input_bool(user_info['email_verified'], 'is_email_verified', _m) - user.is_super_user = None - user.id_currency_default = None - user.id_region_default = None - user.is_included_VAT_default = None - user.can_admin_store = None - user.can_admin_user = None - user.is_logged_in = (user.id_user_auth0 is not None and user.id_user_auth0 != '') - Helper_App.console_log(f'user: {user}') - return user - - def to_json(self): - as_json = { - 'id_user': self.id_user, - 'id_user_auth0': self.id_user_auth0, - 'firstname': self.firstname, - 'surname': self.surname, - 'email': self.email, - 'is_email_verified': self.is_email_verified, - 'is_super_user': self.is_super_user, - 'id_currency_default': self.id_currency_default, - 'id_region_default': self.id_region_default, - 'is_included_VAT_default': self.is_included_VAT_default, - 'can_admin_store': self.can_admin_store, - 'can_admin_user': self.can_admin_user - } - Helper_App.console_log(f'as_json: {as_json}') - return as_json - - def __repr__(self): - return f''' - id_user: {self.id_user} - id_user_auth0: {self.id_user_auth0} - firstname: {self.firstname} - surname: {self.surname} - email: {self.email} - is_email_verified: {self.is_email_verified} - is_super_user: {self.is_super_user} - id_currency_default: {self.id_currency_default} - id_region_default: {self.id_region_default} - is_included_VAT_default: {self.is_included_VAT_default} - can_admin_store: {self.can_admin_store} - can_admin_user: {self.can_admin_user} - ''' - - -class Parameters_User(Get_Many_Parameters_Base): - get_all_user: bool - get_inactive_user: bool - ids_user: str - ids_user_auth0: str - - @staticmethod - def from_form(form): - av.val_instance(form, 'form', 'Parameters_User.from_form', Form_Filters_User) - get_inactive = av.input_bool(form.active.data, "active", "Parameters_User.from_form") - id_user = '' if form.id_user.data is None else form.id_user.data - return Parameters_User( - get_all_user = (id_user == ''), - get_inactive_user = get_inactive, - ids_user = id_user, - ids_user_auth0 = '', - ) - - @staticmethod - def from_user(user): - av.val_instance(user, 'user', 'Parameters_User.from_user', User) - return Parameters_User( - get_all_user = ((user.id_user is None or user.id_user == 0) and user.id_user_auth0 is None), - get_inactive_user = False, - ids_user = '' if user.id_user is None else str(user.id_user), - ids_user_auth0 = user.id_user_auth0, - ) - - @staticmethod - def get_default(): - return Parameters_User( - get_all_user = False, - get_inactive_user = False, - ids_user = '', - ids_user_auth0 = '' - ) -""" User_Eval -@dataclass -class User_Filters(): - ids_user: str - get_inactive_users: bool - ids_permission: str - ids_access_level: str - ids_product: str - - def to_json(self): - return { - **self.get_shared_json_attributes(self), - 'a_ids_user': self.ids_user, - 'a_get_inactive_users': self.get_inactive_users, - 'a_ids_permission': self.ids_permission, - 'a_ids_access_level': self.ids_access_level, - 'a_ids_product': self.ids_product, - } - - @staticmethod - def from_form(form): - av.val_instance(form, 'form', 'User_Filters.from_form', Form_Filters_User) - get_inactive = av.input_bool(form.active.data, "active", "User_Filters.from_form") - return User_Filters( - ids_user = form.id_user.data, - get_inactive_users = get_inactive, - ids_permission = form.ids_permission.data, - ids_access_level = form.ids_access_level.data, - ids_product = form.ids_product.data, - ) - - @staticmethod - def get_default(datastore_store): - is_user_logged_in, id_user = datastore_store.get_login_user() - return User_Filters( - ids_user = id_user, - get_inactive_users = False, - ids_permission = '', - ids_access_level = '', - ids_product = '', - ) -""" - -class User_Permission_Evaluation(db.Model): - id_evaluation = db.Column(db.Integer, primary_key=True) - guid = db.Column(db.String(255)) - id_user = db.Column(db.Integer) - id_permission_required = db.Column(db.Integer) - priority_access_level_required = db.Column(db.Integer) - id_product = db.Column(db.Integer) - is_super_user = db.Column(db.Boolean) - priority_access_level_user = db.Column(db.Integer) - can_view = db.Column(db.Boolean) - can_edit = db.Column(db.Boolean) - can_admin = db.Column(db.Boolean) - - def from_DB_user_eval(query_row): - user_permission_evaluation = User_Permission_Evaluation() - user_permission_evaluation.id_evaluation = query_row[0] - user_permission_evaluation.guid = query_row[1] - user_permission_evaluation.id_user = query_row[2] - user_permission_evaluation.id_permission_required = query_row[3] - user_permission_evaluation.priority_access_level_required = query_row[4] - user_permission_evaluation.id_product = query_row[5] - user_permission_evaluation.is_super_user = query_row[6] - user_permission_evaluation.priority_access_level_user = query_row[7] - user_permission_evaluation.can_view = query_row[8] - user_permission_evaluation.can_edit = query_row[9] - user_permission_evaluation.can_admin = query_row[10] - return user_permission_evaluation - - def __repr__(self): - return f''' - id_evaluation: {self.id_evaluation} - guid: {self.guid} - id_user: {self.id_user} - id_permission_required: {self.id_permission_required} - priority_access_level_required: {self.priority_access_level_required} - id_product: {self.id_product} - is_super_user: {self.is_super_user} - priority_access_level_user: {self.priority_access_level_user} - can_view: {self.can_view} - can_edit: {self.can_edit} - can_admin: {self.can_admin} - ''' - - -class User_Temp(db.Model, Base): - __tablename__ = 'Shop_User_Temp' - __table_args__ = { 'extend_existing': True } - id_user = db.Column(db.Integer, primary_key=True) - id_user_auth0 = db.Column(db.String(255)) - firstname = db.Column(db.String(255)) - surname = db.Column(db.String(255)) - email = db.Column(db.String(255)) - is_email_verified = db.Column(db.Boolean) - is_super_user = db.Column(db.Boolean) - id_currency_default = db.Column(db.Integer) - id_region_default = db.Column(db.Integer) - is_included_VAT_default = db.Column(db.Boolean) - # is_logged_in: bool - - def __init__(self): - self.id_user = 0 - self.is_logged_in = False - super().__init__() \ No newline at end of file diff --git a/controllers/core/__init__.py b/controllers/core/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/controllers/core.py b/controllers/core/contact.py similarity index 82% rename from controllers/core.py rename to controllers/core/contact.py index 279513c7..793b36d8 100644 --- a/controllers/core.py +++ b/controllers/core/contact.py @@ -4,16 +4,17 @@ Author: Edward Middleton-Smith Precision And Research Technology Systems Limited Technology: App Routing -Feature: Core Routes +Feature: Core - Contact Routes Description: -Initializes the Flask application, sets the configuration based on the environment, and defines two routes (/ and /about) that render templates with the specified titles. +Contact Page Controller. """ # IMPORTS # internal from business_objects.api import API -from datastores.datastore_base import DataStore_Base +from business_objects.project_hub.contact_form import Contact_Form +from parts_website.datastores.project_hub.datastore_contact_form import DataStore_Contact_Form from forms.contact import Form_Contact from helpers.helper_app import Helper_App from models.model_view_contact import Model_View_Contact @@ -35,19 +36,10 @@ import hashlib import datetime from altcha import ChallengeOptions, create_challenge, verify_solution -routes_core = Blueprint('routes_core', __name__) +routes_core_contact = Blueprint('routes_core_contact', __name__) -@routes_core.route(Model_View_Home.HASH_PAGE_HOME, methods=['GET']) -def home(): - try: - model = Model_View_Home() - html_body = render_template('pages/core/_home.html', model = model) - except Exception as e: - return jsonify(error=str(e)), 403 - return html_body - -@routes_core.route(Model_View_Contact.HASH_PAGE_CONTACT, methods=['GET']) +@routes_core_contact.route(Model_View_Contact.HASH_PAGE_CONTACT, methods=['GET']) def contact(): try: form = Form_Contact() @@ -64,7 +56,7 @@ def contact(): meta = None ) -@routes_core.route(Model_View_Contact.HASH_GET_ALTCHA_CHALLENGE, methods=['GET']) +@routes_core_contact.route(Model_View_Contact.HASH_GET_ALTCHA_CHALLENGE, methods=['GET']) def create_altcha_challenge(): options = ChallengeOptions( expires = datetime.datetime.now() + datetime.timedelta(hours=1), @@ -81,7 +73,7 @@ def create_altcha_challenge(): "signature": challenge.signature, }) -@routes_core.route(Model_View_Contact.HASH_PAGE_CONTACT, methods=['POST']) +@routes_core_contact.route(Model_View_Contact.HASH_PAGE_CONTACT, methods=['POST']) def contact_post(): try: form = Form_Contact() @@ -98,6 +90,13 @@ def contact_post(): mailItem = Message("PARTS Website Contact Us Message", recipients=[current_app.config['MAIL_CONTACT_PUBLIC']]) mailItem.body = f"Dear Lord Edward Middleton-Smith,\n\n{message}\n{receive_marketing_text}\nKind regards,\n{contact_name}\n{company_name}\n{email}" mail.send(mailItem) + # save to database + datastore = DataStore_Contact_Form() + contact_form = Contact_Form.from_json(form.to_json()) + datastore.save_contact_forms( + comment = contact_form.message + , contact_forms = [contact_form] + ) return redirect(url_for(Model_View_Contact.ENDPOINT_PAGE_CONTACT_SUCCESS)) except Exception as e: return API.get_standard_response( @@ -127,7 +126,7 @@ def contact_post(): meta = None ) -@routes_core.route(Model_View_Contact.HASH_PAGE_CONTACT_SUCCESS, methods=['GET']) +@routes_core_contact.route(Model_View_Contact.HASH_PAGE_CONTACT_SUCCESS, methods=['GET']) def contact_success(): try: model = Model_View_Contact_Success() diff --git a/controllers/core/home.py b/controllers/core/home.py new file mode 100644 index 00000000..f2994248 --- /dev/null +++ b/controllers/core/home.py @@ -0,0 +1,31 @@ +""" +Project: PARTS Website +Author: Edward Middleton-Smith + Precision And Research Technology Systems Limited + +Technology: App Routing +Feature: Core - Home Routes + +Description: +Home Page Controller. +""" + +# internal +from business_objects.api import API +from models.model_view_home import Model_View_Home +# external +from flask import render_template, jsonify, Blueprint + + +routes_core_home = Blueprint('routes_core_home', __name__) + + +@routes_core_home.route(Model_View_Home.HASH_PAGE_HOME, methods=['GET']) +def home(): + try: + model = Model_View_Home() + html_body = render_template('pages/core/_home.html', model = model) + except Exception as e: + return jsonify(error=str(e)), 403 + return html_body + \ No newline at end of file diff --git a/controllers/legal/__init__.py b/controllers/legal/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/controllers/legal.py b/controllers/legal/legal.py similarity index 79% rename from controllers/legal.py rename to controllers/legal/legal.py index af249a79..4161312c 100644 --- a/controllers/legal.py +++ b/controllers/legal/legal.py @@ -7,7 +7,7 @@ Technology: App Routing Feature: Legal Routes Description: -Initializes the Flask application, sets the configuration based on the environment, and defines two routes (/ and /about) that render templates with the specified titles. +Legal Section Controller. """ # IMPORTS @@ -20,12 +20,8 @@ from models.model_view_accessibility_statement import Model_View_Accessibility_S from models.model_view_retention_schedule import Model_View_Retention_Schedule import lib.argument_validation as av # external -from flask import Flask, render_template, jsonify, request, render_template_string, send_from_directory, redirect, url_for, session, Blueprint, current_app -from extensions import db, oauth -from urllib.parse import quote_plus, urlencode -from authlib.integrations.flask_client import OAuth -from authlib.integrations.base_client import OAuthError -from urllib.parse import quote, urlparse, parse_qs +from flask import render_template, Blueprint + routes_legal = Blueprint('routes_legal', __name__) diff --git a/datastores/datastore_base.py b/datastores/datastore_base.py index 97c00721..bf9f57fd 100644 --- a/datastores/datastore_base.py +++ b/datastores/datastore_base.py @@ -13,11 +13,8 @@ Datastore for Store # internal # from routes import bp_home import lib.argument_validation as av -from business_objects.access_level import Access_Level -from business_objects.region import Region from business_objects.sql_error import SQL_Error -from business_objects.unit_measurement import Unit_Measurement -from business_objects.user import User, Parameters_User, User_Permission_Evaluation +from business_objects.project_hub.user import User # from helpers.helper_db_mysql import Helper_DB_MySQL # from models.model_view_store_checkout import Model_View_Store_Checkout # circular! from extensions import db @@ -25,52 +22,26 @@ from forms.access_level import Filters_Access_Level from forms.unit_measurement import Filters_Unit_Measurement from helpers.helper_app import Helper_App # external -# from abc import ABC, abstractmethod, abstractproperty -from flask_sqlalchemy import SQLAlchemy from sqlalchemy import text -import stripe -import os from flask import Flask, session, current_app from pydantic import BaseModel, ConfigDict -from typing import ClassVar -from datetime import datetime import time from sqlalchemy.exc import OperationalError -# db = SQLAlchemy() class DataStore_Base(BaseModel): - # Global constants - # Attributes - """ - app: Flask = None - db: SQLAlchemy = None - session: object = None - """ - - # model_config = ConfigDict(arbitrary_types_allowed=True) def __init__(self, **kwargs): super().__init__(**kwargs) - # Constructor - """ - self.db = db - self.app = current_app - with self.app.app_context(): - self.session = session - """ + @staticmethod def db_procedure_execute(proc_name, argument_dict_list = None): # Argument validation _m = 'DataStore_Base.db_procedure_execute' av.val_str(proc_name, 'proc_name', _m) - has_arguments = not str(type(argument_dict_list)) == "" - if has_arguments: - # av.val_list_instances(argument_dict_list, 'argument_dict_list', _m, dict) - pass - # Methods proc_string = f'CALL {proc_name}(' + has_arguments = not str(type(argument_dict_list)) == "" if has_arguments: arg_keys = list(argument_dict_list.keys()) for i in range(len(arg_keys)): @@ -79,9 +50,6 @@ class DataStore_Base(BaseModel): proc_string = text(proc_string) Helper_App.console_log(f'{_m}\nproc_string: {proc_string}\nargs: {argument_dict_list}') - # with self.db.session.begin() as session: - # conn = Helper_DB_MySQL(self.app).get_db_connection() - if has_arguments: result = db.session.execute(proc_string, argument_dict_list) else: @@ -94,60 +62,14 @@ class DataStore_Base(BaseModel): def db_cursor_clear(cursor): while cursor.nextset(): Helper_App.console_log(f'new result set: {cursor.fetchall()}') + @staticmethod def get_user_session(): Helper_App.console_log('DataStore_Base.get_user_session') user = User.from_json(session.get(User.FLAG_USER)) - if user.is_logged_in: - filters_user = Parameters_User.get_default() - filters_user.ids_user = user.id_user - users = DataStore_Base.get_many_user(filters_user) + if user.id_user <= 0: + user.id_user = 3 return user - @classmethod - def get_many_user(cls, filters=None): - _m = 'DataStore_Store_Base.get_many_access_level' - user = User.from_json(session.get(User.FLAG_USER)) - if filters is None: - filters_user = Parameters_User.get_default() - filters_user.ids_user = user.id_user if user.is_logged_in else None - av.val_instance(filters, 'filters', _m, Parameters_User) - argument_dict = filters.to_json() - - argument_dict = { - 'a_id_user': user.id_user, - 'a_id_user_auth0': user.id_user_auth0, - **argument_dict, - 'a_debug': 0, - } - - Helper_App.console_log(f'argument_dict: {argument_dict}') - Helper_App.console_log('executing p_get_many_user') - result = cls.db_procedure_execute('p_get_many_user', argument_dict) - cursor = result.cursor - Helper_App.console_log('data received') - - # users - result_set_1 = cursor.fetchall() - Helper_App.console_log(f'raw users: {result_set_1}') - users = [] - for row in result_set_1: - new_user = User.from_DB_user(row) - users.append(new_user) - - # Errors - cursor.nextset() - result_set_e = cursor.fetchall() - Helper_App.console_log(f'raw errors: {result_set_e}') - errors = [] - if len(result_set_e) > 0: - errors = [SQL_Error.from_DB_record(row) for row in result_set_e] # (row[0], row[1]) - for error in errors: - Helper_App.console_log(f"Error [{error.code}]: {error.msg}") - - DataStore_Base.db_cursor_clear(cursor) - cursor.close() - - return users, errors @staticmethod def upload_bulk(permanent_table_name, records, batch_size): @@ -190,81 +112,3 @@ class DataStore_Base(BaseModel): except Exception as e: db.session.rollback() raise e - - @classmethod - def get_many_access_level(cls, filters=None): - _m = 'DataStore_Store_Base.get_many_access_level' - if filters is None: - filters = Filters_Access_Level() - av.val_instance(filters, 'filters', _m, Filters_Access_Level) - argument_dict = filters.to_json() - result = cls.db_procedure_execute('p_shop_get_many_access_level', argument_dict) - cursor = result.cursor - result_set_1 = cursor.fetchall() - access_levels = [] - for row in result_set_1: - new_access_level = Access_Level.from_DB_access_level(row) - access_levels.append(new_access_level) - - # Errors - cursor.nextset() - result_set_e = cursor.fetchall() - errors = [] - if len(result_set_e) > 0: - errors = [SQL_Error.from_DB_record(row) for row in result_set_e] # (row[0], row[1]) - for error in errors: - Helper_App.console_log(f"Error [{error.code}]: {error.msg}") - - DataStore_Base.db_cursor_clear(cursor) - cursor.close() - - return access_levels, errors - @classmethod - def get_many_unit_measurement(cls, filters=None): - _m = 'DataStore_Store_Base.get_many_unit_measurement' - if filters is None: - filters = Filters_Unit_Measurement() - av.val_instance(filters, 'filters', _m, Filters_Unit_Measurement) - argument_dict = filters.to_json() - result = cls.db_procedure_execute('p_shop_get_many_unit_measurement', argument_dict) - cursor = result.cursor - result_set_1 = cursor.fetchall() - units = [] - for row in result_set_1: - new_unit = Unit_Measurement.from_DB_unit_measurement(row) - units.append(new_unit) - - # Errors - cursor.nextset() - result_set_e = cursor.fetchall() - errors = [] - if len(result_set_e) > 0: - errors = [SQL_Error.from_DB_record(row) for row in result_set_e] # (row[0], row[1]) - for error in errors: - Helper_App.console_log(f"Error [{error.code}]: {error.msg}") - - DataStore_Base.db_cursor_clear(cursor) - cursor.close() - - return units, errors - - @classmethod - def get_many_region(cls, get_inactive = False): - _m = 'DataStore_Store_Base.get_many_region' - _m_db_region = 'p_shop_get_many_region' - - argument_dict_list_region = { - 'a_get_inactive_region': 1 if get_inactive else 0 - } - - result = cls.db_procedure_execute(_m_db_region, argument_dict_list_region) - cursor = result.cursor - result_set_1 = cursor.fetchall() - regions = [] - for row in result_set_1: - region = Region.from_DB_region(row) - regions.append(region) - DataStore_Base.db_cursor_clear(cursor) - cursor.close() - - return regions \ No newline at end of file diff --git a/datastores/datastore_user.py b/datastores/datastore_user.py deleted file mode 100644 index 3960c23c..00000000 --- a/datastores/datastore_user.py +++ /dev/null @@ -1,147 +0,0 @@ -""" -Project: PARTS Website -Author: Edward Middleton-Smith - Precision And Research Technology Systems Limited - -Technology: DataStores -Feature: User DataStore - -Description: -Datastore for Users -""" - -# internal -# from routes import bp_home -import lib.argument_validation as av -from business_objects.sql_error import SQL_Error -from business_objects.user import User, Parameters_User, User_Permission_Evaluation -from datastores.datastore_base import DataStore_Base -from helpers.helper_app import Helper_App -from helpers.helper_db_mysql import Helper_DB_MySQL -# from models.model_view_store_checkout import Model_View_Store_Checkout # circular! -from extensions import db -# external -# from abc import ABC, abstractmethod, abstractproperty -from flask_sqlalchemy import SQLAlchemy -from sqlalchemy import text -import stripe -import os -from flask import Flask, session, current_app -from pydantic import BaseModel, ConfigDict -from typing import ClassVar -from datetime import datetime - -db = SQLAlchemy() - - -class DataStore_User(DataStore_Base): - # Global constants - # Attributes - - def __init__(self): - super().__init__() - - def edit_user(self): - _m = 'DataStore_User.edit_user' - - argument_dict_list = { - 'a_id_user': self.info_user.get('sub'), - 'a_name': self.info_user.get('name'), - 'a_email': self.info_user.get('email'), - 'a_email_verified': 1 if self.info_user.get('email_verified') == 'True' else 0 - } - - result = self.db_procedure_execute('p_shop_edit_user', argument_dict_list) - cursor = result.cursor - - result_set_1 = cursor.fetchall() - - # Errors - cursor.nextset() - result_set_e = cursor.fetchall() - if len(result_set_e) > 0: - errors = [SQL_Error.from_DB_record(row) for row in result_set_e] # [SQL_Error(row[0], row[1]) for row in result_set_2] - for error in errors: - Helper_App.console_log(f"Error [{error.code}]: {error.msg}") - - DataStore_User.db_cursor_clear(cursor) - - return (result_set_1[0][1] == b'\x01') - - def get_many_user(self, user_filters, user=None): - _m = 'DataStore_User.get_many_user' - av.val_instance(user_filters, 'user_filters', _m, Parameters_User) - - guid = Helper_DB_MySQL.create_guid() - if user is None: - user = self.get_user_session() - argument_dict_list = { - # 'a_guid': guid - 'a_id_user': user.id_user - , 'a_id_user_auth0': user.id_user_auth0 - , **user_filters.to_json() - , 'a_debug': 0 - - } - result = self.db_procedure_execute('p_get_many_user', argument_dict_list) - cursor = result.cursor - result_set = cursor.fetchall() - users = [] - if len(result_set) > 0: - for row in result_set: - Helper_App.console_log(f'row: {row}') - user = User.from_DB_user(row) - users.append(user) - Helper_App.console_log(f'user {str(type(user))}: {user}') - errors = [] - cursor.nextset() - result_set_e = cursor.fetchall() - Helper_App.console_log(f'raw errors: {result_set_e}') - if len(result_set_e) > 0: - errors = [SQL_Error.from_DB_record(row) for row in result_set_e] # [SQL_Error(row[0], row[1]) for row in result_set_e] - for error in errors: - Helper_App.console_log(f"Error [{error.code}]: {error.msg}") - - DataStore_User.db_cursor_clear(cursor) - - return users, errors - - def get_many_user(self, user_filters, user=None): - _m = 'DataStore_User.get_many_user' - av.val_instance(user_filters, 'user_filters', _m, Parameters_User) - - guid = Helper_DB_MySQL.create_guid() - if user is None: - user = self.get_user_session() - argument_dict_list = { - # 'a_guid': guid - 'a_id_user': user.id_user - , 'a_id_user_auth0': user.id_user_auth0 - , **user_filters.to_json() - , 'a_debug': 0 - - } - result = self.db_procedure_execute('p_get_many_user', argument_dict_list) - cursor = result.cursor - result_set = cursor.fetchall() - users = [] - if len(result_set) > 0: - for row in result_set: - Helper_App.console_log(f'row: {row}') - user = User.from_DB_user(row) - users.append(user) - Helper_App.console_log(f'user {str(type(user))}: {user}') - Helper_App.console_log(f'type users: {str(type(users))}\n type user 0: {str(type(None if len(users) == 0 else users[0]))}') - # error_list, cursor = self.get_error_list_from_cursor(cursor) - errors = [] - cursor.nextset() - result_set_e = cursor.fetchall() - Helper_App.console_log(f'raw errors: {result_set_e}') - if len(result_set_e) > 0: - errors = [SQL_Error.from_DB_record(row) for row in result_set_e] # [SQL_Error(row[0], row[1]) for row in result_set_e] - for error in errors: - Helper_App.console_log(f"Error [{error.code}]: {error.msg}") - - DataStore_User.db_cursor_clear(cursor) - - return users, errors diff --git a/datastores/project_hub/datastore_contact_form.py b/datastores/project_hub/datastore_contact_form.py new file mode 100644 index 00000000..b3ea56b9 --- /dev/null +++ b/datastores/project_hub/datastore_contact_form.py @@ -0,0 +1,113 @@ +""" +Project: PARTS Website +Author: Edward Middleton-Smith + Precision And Research Technology Systems Limited + +Technology: DataStores +Feature: User DataStore + +Description: +Datastore for Users +""" + +# internal +# from routes import bp_home +import lib.argument_validation as av +from business_objects.sql_error import SQL_Error +from parts_website.business_objects.project_hub.contact_form import Contact_Form, Contact_Form_Temp +from datastores.datastore_base import DataStore_Base +from helpers.helper_app import Helper_App +from helpers.helper_db_mysql import Helper_DB_MySQL +# from models.model_view_store_checkout import Model_View_Store_Checkout # circular! +from extensions import db +# external +from flask_sqlalchemy import SQLAlchemy +from datetime import datetime + +db = SQLAlchemy() + + +class DataStore_Contact_Form(DataStore_Base): + + def __init__(self): + super().__init__() + + @classmethod + def get_many_contact_form(cls): + _m = f'{cls.__qualname__}.get_many_contact_form' + user = cls.get_user_session() + argument_dict = { + 'a_id_user': user.id_user + , 'a_debug': 0 + } + Helper_App.console_log(f'argument_dict: {argument_dict}') + result = cls.db_procedure_execute('p_ph_get_many_contact_form', argument_dict) + cursor = result.cursor + + # Contact_Forms + result_set_1 = cursor.fetchall() + Helper_App.console_log(f'raw contact_forms: {result_set_1}') + contact_forms = [] + contact_form_indexes = {} + for row in result_set_1: + new_contact_form = Contact_Form.from_DB_contact_form(row) + contact_form_indexes[new_contact_form.id_contact_form] = len(contact_forms) + contact_forms.append(new_contact_form) + + # Errors + cursor.nextset() + result_set_e = cursor.fetchall() + Helper_App.console_log(f'raw errors: {result_set_e}') + errors = [] + if len(result_set_e) > 0: + errors = [SQL_Error.from_DB_record(row) for row in result_set_e] + for error in errors: + Helper_App.console_log(f"Error [{error.code}]: {error.msg}") + + cls.db_cursor_clear(cursor) + + return contact_forms, errors + + @classmethod + def save_contact_forms(cls, comment, contact_forms): + _m = f'{cls}.save_contact_forms' + av.val_str(comment, 'comment', _m) + + guid = Helper_DB_MySQL.create_guid_str() + now = datetime.now() + user = cls.get_user_session() + + Helper_App.console_log(f'saving contact forms: {contact_forms}') + + rows = [] + for contact_form in contact_forms: + row = Contact_Form_Temp.from_contact_form(contact_form) + row.guid = guid + rows.append(row) + + cls.upload_bulk(Contact_Form_Temp.__tablename__, rows, 1000) + + Helper_App.console_log('Contact Forms uploaded') + + argument_dict_list = { + 'a_comment': comment, + 'a_guid': guid, + 'a_id_user': user.id_user, + 'a_debug': 0 + } + result = cls.db_procedure_execute('p_ph_save_contact_form', argument_dict_list) + + Helper_App.console_log('Contact Forms saved') + + # Errors + cursor = result.cursor + cursor.nextset() + result_set_e = cursor.fetchall() + errors = [] + if len(result_set_e) > 0: + errors = [SQL_Error.from_DB_record(row) for row in result_set_e] + for error in errors: + Helper_App.console_log(f"Error [{error.code}]: {error.msg}") + + cls.db_cursor_clear(cursor) + return errors diff --git a/forms/contact.py b/forms/contact.py index 7bb9e73a..c1371ed3 100644 --- a/forms/contact.py +++ b/forms/contact.py @@ -12,7 +12,8 @@ Defines Flask-WTF form for handling user input on Contact Us page. # IMPORTS # internal -# from business_objects.store.product_category import Filters_Product_Category # circular +from business_objects.base import Base +from business_objects.project_hub.contact_form import Contact_Form # from models.model_view_store import Model_View_Store # circular from models.model_view_base import Model_View_Base from forms.base import Form_Base @@ -85,3 +86,15 @@ class Form_Contact(FlaskForm): # altcha = HiddenField('ALTCHA') # , validators=[validate_altcha] altcha = ALTCHAField('Verify you are human') submit = SubmitField('Send Message') + + def to_json(self): + return { + Base.FLAG_EMAIL: self.email.data + , Contact_Form.FLAG_NAME_CONTACT: self.contact_name.data + , Contact_Form.FLAG_NAME_COMPANY: self.company_name.data + , Contact_Form.FLAG_MESSAGE: self.message.data + , Contact_Form.FLAG_RECEIVE_MARKETING_COMMUNICATIONS: self.receive_marketing.data + , Contact_Form.FLAG_ALTCHA: self.altcha.data + , Base.FLAG_ACTIVE: True + , Base.FLAG_CREATED_ON: None + } diff --git a/models/model_view_base.py b/models/model_view_base.py index 62256e5b..11b8059a 100644 --- a/models/model_view_base.py +++ b/models/model_view_base.py @@ -18,9 +18,10 @@ Base data model for views # internal # from routes import bp_home from business_objects.base import Base -from business_objects.user import User, Parameters_User +from business_objects.project_hub.user import User +from parts_website.business_objects.project_hub.contact_form import Contact_Form from datastores.datastore_base import DataStore_Base -from datastores.datastore_user import DataStore_User +from parts_website.datastores.project_hub.datastore_contact_form import DataStore_Contact_Form from forms.access_level import Filters_Access_Level from forms.forms import Form_Is_Included_VAT, Form_Delivery_Region, Form_Currency from forms.unit_measurement import Filters_Unit_Measurement @@ -35,37 +36,26 @@ from typing import ClassVar class Model_View_Base(BaseModel, ABC): - # Global constants - # ATTR_FOR: ClassVar[str] = 'for' - ATTR_ID_ACCESS_LEVEL: ClassVar[str] = Base.ATTR_ID_ACCESS_LEVEL - ATTR_ID_ADDRESS: ClassVar[str] = Base.ATTR_ID_ADDRESS - ATTR_ID_CURRENCY: ClassVar[str] = Base.ATTR_ID_CURRENCY - ATTR_ID_REGION: ClassVar[str] = Base.ATTR_ID_REGION ATTR_TEXT_COLLAPSED: ClassVar[str] = 'textCollapsed' ATTR_TEXT_EXPANDED: ClassVar[str] = 'textExpanded' ATTR_VALUE_CURRENT: ClassVar[str] = 'current-value' ATTR_VALUE_PREVIOUS: ClassVar[str] = 'previous-value' COMPANY_ADDRESS_SHORT: ClassVar[str] = '53 Alfred Green Close, Rugby, United Kingdom, CV22 6DN' COMPANY_NUMBER: ClassVar[str] = '13587499' - ENDPOINT_GET_ALTCHA_CHALLENGE: ClassVar[str] = 'routes_core.create_altcha_challenge' + ENDPOINT_GET_ALTCHA_CHALLENGE: ClassVar[str] = 'routes_core_contact.create_altcha_challenge' ENDPOINT_PAGE_ACCESSIBILITY_REPORT: ClassVar[str] = 'routes_legal.accessibility_report' ENDPOINT_PAGE_ACCESSIBILITY_STATEMENT: ClassVar[str] = 'routes_legal.accessibility_statement' - ENDPOINT_PAGE_CONTACT: ClassVar[str] = 'routes_core.contact' - ENDPOINT_PAGE_CONTACT_SUCCESS: ClassVar[str] = 'routes_core.contact_success' + ENDPOINT_PAGE_CONTACT: ClassVar[str] = 'routes_core_contact.contact' + ENDPOINT_PAGE_CONTACT_SUCCESS: ClassVar[str] = 'routes_core_contact.contact_success' ENDPOINT_PAGE_DATA_RETENTION_SCHEDULE: ClassVar[str] = 'routes_legal.retention_schedule' ENDPOINT_PAGE_ERROR_NO_PERMISSION: ClassVar[str] = 'routes_core.error_no_permission' - ENDPOINT_PAGE_HOME: ClassVar[str] = 'routes_core.home' + ENDPOINT_PAGE_HOME: ClassVar[str] = 'routes_core_home.home' ENDPOINT_PAGE_LICENSE: ClassVar[str] = 'routes_legal.license' ENDPOINT_PAGE_PRIVACY_POLICY: ClassVar[str] = 'routes_legal.privacy_policy' - ENDPOINT_POST_CONTACT_FORM: ClassVar[str] = 'routes_core.contact_post' - FLAG_ACCESS_LEVEL: ClassVar[str] = 'access_level' - FLAG_ACCESS_LEVEL_REQUIRED: ClassVar[str] = Base.FLAG_ACCESS_LEVEL_REQUIRED + ENDPOINT_POST_CONTACT_FORM: ClassVar[str] = 'routes_core_contact.contact_post' FLAG_ACTIVE: ClassVar[str] = Base.FLAG_ACTIVE FLAG_ADD: ClassVar[str] = 'add' # FLAG_ADD_DELETE: ClassVar[str] = 'add-delete' - FLAG_ADDRESS: ClassVar[str] = Base.FLAG_ADDRESS - FLAG_ADDRESS_LINE_1: ClassVar[str] = Base.FLAG_ADDRESS_LINE_1 - FLAG_ADDRESS_LINE_2: ClassVar[str] = Base.FLAG_ADDRESS_LINE_2 FLAG_BOOL_FALSE: ClassVar[str] = 'false' FLAG_BOOL_TRUE: ClassVar[str] = 'true' FLAG_BUTTON: ClassVar[str] = 'button' @@ -75,28 +65,24 @@ class Model_View_Base(BaseModel, ABC): FLAG_CALLBACK: ClassVar[str] = 'callback' FLAG_CAPTCHA: ClassVar[str] = 'captcha' FLAG_CARD: ClassVar[str] = 'card' - FLAG_CITY: ClassVar[str] = Base.FLAG_CITY FLAG_CLOSE_TEMPORARY_ELEMENT: ClassVar[str] = 'button-temporary-element-close' FLAG_CODE: ClassVar[str] = Base.FLAG_CODE FLAG_COLLAPSED: ClassVar[str] = 'collapsed' FLAG_COLLAPSIBLE: ClassVar[str] = 'collapsible' FLAG_COLUMN: ClassVar[str] = 'column' FLAG_COMMENT: ClassVar[str] = 'comment' - # FLAG_CONTACT_US: ClassVar[str] = 'button-contact' FLAG_CONTAINER: ClassVar[str] = 'container' FLAG_CONTAINER_CHECKBOX: ClassVar[str] = 'container-checkbox' FLAG_CONTAINER_ICON_AND_LABEL: ClassVar[str] = 'container-icon-label' FLAG_CONTAINER_INPUT: ClassVar[str] = 'container-input' - FLAG_COUNTY: ClassVar[str] = Base.FLAG_COUNTY FLAG_CSRF_TOKEN: ClassVar[str] = 'X-CSRFToken' - FLAG_CURRENCY: ClassVar[str] = 'currency' FLAG_DATA: ClassVar[str] = 'data' FLAG_DATE_FROM: ClassVar[str] = Base.FLAG_DATE_FROM FLAG_DATE_TO: ClassVar[str] = Base.FLAG_DATE_TO FLAG_DELETE: ClassVar[str] = 'delete' FLAG_DESCRIPTION: ClassVar[str] = Base.FLAG_DESCRIPTION FLAG_DETAIL: ClassVar[str] = 'detail' - FLAG_DIALOG: ClassVar[str] = 'dialog' # try element + FLAG_DIALOG: ClassVar[str] = 'dialog' FLAG_DIRTY: ClassVar[str] = 'dirty' FLAG_DISPLAY_ORDER: ClassVar[str] = Base.FLAG_DISPLAY_ORDER FLAG_EDIT: ClassVar[str] = 'edit' @@ -104,17 +90,15 @@ class Model_View_Base(BaseModel, ABC): FLAG_ERROR: ClassVar[str] = 'error' FLAG_EXPANDED: ClassVar[str] = 'expanded' FLAG_FAILURE: ClassVar[str] = 'failure' - FLAG_FAX: ClassVar[str] = Base.FLAG_FAX FLAG_FILTER: ClassVar[str] = 'filter' FLAG_FORM: ClassVar[str] = 'form' FLAG_FORM_FILTERS: ClassVar[str] = 'form-filters' FLAG_HAMBURGER: ClassVar[str] = 'hamburger' FLAG_IMAGE_LOGO: ClassVar[str] = 'image-logo' FLAG_INITIALISED: ClassVar[str] = 'initialised' - FLAG_IS_INCLUDED_VAT: ClassVar[str] = 'is_included_VAT' FLAG_LEFT_HAND_STUB: ClassVar[str] = 'lhs' FLAG_LOGO: ClassVar[str] = 'logo' - FLAG_MESSAGE: ClassVar[str] = 'message' + FLAG_MESSAGE: ClassVar[str] = Contact_Form.FLAG_MESSAGE FLAG_MODAL: ClassVar[str] = 'modal' FLAG_NAME: ClassVar[str] = Base.FLAG_NAME FLAG_NAME_ATTR_OPTION_TEXT: ClassVar[str] = Base.FLAG_NAME_ATTR_OPTION_TEXT @@ -125,8 +109,6 @@ class Model_View_Base(BaseModel, ABC): FLAG_NAV_HOME: ClassVar[str] = 'navHome' FLAG_OVERLAY: ClassVar[str] = 'overlay' FLAG_PAGE_BODY: ClassVar[str] = 'page-body' - FLAG_PHONE_NUMBER: ClassVar[str] = Base.FLAG_PHONE_NUMBER - FLAG_POSTCODE: ClassVar[str] = Base.FLAG_POSTCODE FLAG_RIGHT_HAND_SIDE: ClassVar[str] = 'rhs' FLAG_ROW: ClassVar[str] = 'row' FLAG_ROW_NEW: ClassVar[str] = 'row-new' @@ -136,7 +118,6 @@ class Model_View_Base(BaseModel, ABC): FLAG_SLIDER: ClassVar[str] = 'slider' FLAG_STATUS: ClassVar[str] = 'status' FLAG_SUBMIT: ClassVar[str] = 'submit' - FLAG_SUBMITTED: ClassVar[str] = 'submitted' FLAG_SUCCESS: ClassVar[str] = 'success' FLAG_TEMPORARY_ELEMENT: ClassVar[str] = 'temporary-element' FLAG_USER: ClassVar[str] = User.FLAG_USER @@ -195,9 +176,9 @@ class Model_View_Base(BaseModel, ABC): self.is_page_store = False Helper_App.console_log(f'session: {self.session}') - datastore_user = DataStore_User() - self.user = datastore_user.get_user_session() - self.is_user_logged_in = self.user.is_logged_in + datastore_base = DataStore_Base() + self.user = datastore_base.get_user_session() + self.is_user_logged_in = self.user.get_is_logged_in() # Helper_App.console_log(f'model_view_base init end - model.user: {self.user}') def output_bool(self, boolean): diff --git a/models/model_view_contact.py b/models/model_view_contact.py index 5290a399..6bf57b79 100644 --- a/models/model_view_contact.py +++ b/models/model_view_contact.py @@ -11,6 +11,7 @@ Data model for contact view """ # internal +from business_objects.project_hub.contact_form import Contact_Form from models.model_view_base import Model_View_Base # from routes import bp_home from lib import argument_validation as av @@ -22,11 +23,6 @@ from pydantic import BaseModel from typing import ClassVar class Model_View_Contact(Model_View_Base): - FLAG_ALTCHA_WIDGET: ClassVar[str] = 'altcha-widget' - FLAG_COMPANY_NAME: ClassVar[str] = 'company_name' - FLAG_CONTACT_NAME: ClassVar[str] = 'contact_name' - FLAG_RECEIVE_MARKETING: ClassVar[str] = 'receive_marketing' - ID_CONTACT_FORM: ClassVar[str] = 'contact-form' form_contact: Form_Contact diff --git a/models/model_view_user.py b/models/model_view_user.py deleted file mode 100644 index b5a9e446..00000000 --- a/models/model_view_user.py +++ /dev/null @@ -1,40 +0,0 @@ -""" -Project: PARTS Website -Author: Edward Middleton-Smith - Precision And Research Technology Systems Limited - -Technology: View Models -Feature: User View Model - -Description: -Data model for user view -""" - -# internal -from datastores.datastore_user import DataStore_User -from models.model_view_base import Model_View_Base -# from routes import bp_home -# external -from typing import ClassVar - -class Model_View_User(Model_View_Base): - FLAG_ERROR_OAUTH: ClassVar[str] = 'error' - FLAG_ERROR_DESCRIPTION_OAUTH: ClassVar[str] = 'error_description' - FLAG_FIRSTNAME: ClassVar[str] = 'firstname' - FLAG_SURNAME: ClassVar[str] = 'surname' - FLAG_STATE_OAUTH: ClassVar[str] = 'state' - # Attributes - currencies: list = None - regions: list = None - users: list = None - @property - def title(self): - return 'User' - - def __init__(self, hash_page_current=Model_View_Base.HASH_PAGE_USER_ACCOUNT): - # Constructor - super().__init__(hash_page_current=hash_page_current, form_filters_old = None) - datastore_user = DataStore_User() - self.currencies = datastore_user.get_many_currency() - self.regions = datastore_user.get_many_region() - \ No newline at end of file diff --git a/packages-microsoft-prod.deb b/packages-microsoft-prod.deb new file mode 100644 index 00000000..14e3c628 Binary files /dev/null and b/packages-microsoft-prod.deb differ diff --git a/static/MySQL/0000_combined.sql b/static/MySQL/0000_combined.sql index 8df9fa34..1e89d329 100644 --- a/static/MySQL/0000_combined.sql +++ b/static/MySQL/0000_combined.sql @@ -1,3879 +1,587 @@ --- File: 0001_destroy.sql - -/* Clear Store DataBase */ USE partsltd_prod; --- Drop dependencies -DROP TABLE IF EXISTS tmp_Shop_Calc_User; -DROP TABLE IF EXISTS tmp_Product_Calc_User; -DROP TABLE IF EXISTS tmp_Product_p_Shop_User_Eval; -DROP TABLE IF EXISTS tmp_Msg_Error; -DROP TABLE IF EXISTS tmp_Currency; -DROP TABLE IF EXISTS tmp_Delivery_Option; -DROP TABLE IF EXISTS tmp_Delivery_Region; -DROP TABLE IF EXISTS tmp_Region; -DROP TABLE IF EXISTS tmp_Price; -DROP TABLE IF EXISTS tmp_Shop_User; -DROP TABLE IF EXISTS tmp_Shop_Order; -DROP TABLE IF EXISTS tmp_Shop_Product; -DROP TABLE IF EXISTS tmp_Product; -DROP TABLE IF EXISTS tmp_Product_Permutation; -DROP TABLE IF EXISTS tmp_Permutation_Variation_Link; -DROP TABLE IF EXISTS tmp_Permutation; -DROP TABLE IF EXISTS tmp_Shop_Product_p_shop_calc_user; -DROP TABLE IF EXISTS tmp_Shop_Product_p_Shop_Calc_User; -DROP TABLE IF EXISTS tmp_Shop_Image; -DROP TABLE IF EXISTS tmp_Image; -DROP TABLE IF EXISTS tmp_Product_Image; -DROP TABLE IF EXISTS tmp_Shop_Variation; -DROP TABLE IF EXISTS tmp_Variation; -DROP TABLE IF EXISTS tmp_Variation_Type; -DROP TABLE IF EXISTS tmp_Shop_Discount; -DROP TABLE IF EXISTS tmp_Discount; -DROP TABLE IF EXISTS tmp_Shop_Category; -DROP TABLE IF EXISTS tmp_Category; -DROP TABLE IF EXISTS tmp_Shop_Product_Category; -DROP TABLE IF EXISTS tmp_Product_Category; -DROP TABLE IF EXISTS tmp_Shop_Product_Currency_Region_Link; -DROP TABLE IF EXISTS tmp_Shop_Product_Currency_Link; -DROP TABLE IF EXISTS tmp_User_Role_Link; -DROP TABLE IF EXISTS tmp_Shop_Basket; -DROP TABLE IF EXISTS tmp_Shop_Supplier_Purchase_Order_Product_Link; -DROP TABLE IF EXISTS tmp_Supplier_Purchase_Order_Product_Link; -DROP TABLE IF EXISTS tmp_Shop_Supplier_Purchase_Order; -DROP TABLE IF EXISTS tmp_Supplier_Purchase_Order; -DROP TABLE IF EXISTS tmp_Shop_Supplier; -DROP TABLE IF EXISTS tmp_Supplier; -DROP TABLE IF EXISTS tmp_Supplier_Address; -DROP TABLE IF EXISTS tmp_Shop_Manufacturing_Purchase_Order_Product_Link; -DROP TABLE IF EXISTS tmp_Manufacturing_Purchase_Order_Product_Link; -DROP TABLE IF EXISTS tmp_Shop_Manufacturing_Purchase_Order; -DROP TABLE IF EXISTS tmp_Manufacturing_Purchase_Order; -DROP TABLE IF EXISTS tmp_Shop_Customer; -DROP TABLE IF EXISTS tmp_Shop_Customer_Sale_Order_Product_Link; -DROP TABLE IF EXISTS tmp_Shop_Customer_Sale_Order; -DROP TABLE IF EXISTS tmp_Get_Variation_From_Csv_Variations; +-- Permanent Temp Tables +DROP TABLE IF EXISTS partsltd_prod.tmp_ph_Calc_User; +DROP TABLE IF EXISTS partsltd_prod.tmp_core_Msg_Error; +DROP TABLE IF EXISTS partsltd_prod.tmp_ph_User; +DROP TABLE IF EXISTS partsltd_prod.tmp_ph_User_Role_Link; --- Delete old tables -DROP TABLE IF EXISTS Split_Temp; -DROP TABLE IF EXISTS Split_Key_Value_Pair_Csv_Temp; -DROP TABLE IF EXISTS Split_Key_Value_Pair_Temp; +-- Permanent Tables +DROP TABLE IF EXISTS partsltd_prod.PH_Contact_Form_Temp; +DROP TABLE IF EXISTS partsltd_prod.PH_Contact_Form_Audit; +DROP TABLE IF EXISTS partsltd_prod.PH_Contact_Form; -DROP TABLE IF EXISTS Shop_User_Eval_Temp; -DROP TABLE IF EXISTS Shop_Calc_User_Temp; +DROP TABLE IF EXISTS partsltd_prod.PH_Contact_Form_Change_Set; -DROP TABLE IF EXISTS Shop_Customer_Sales_Order_Product_Link_Temp; -DROP TABLE IF EXISTS Shop_Customer_Sales_Order_Product_Link_Audit; -DROP TABLE IF EXISTS Shop_Customer_Sales_Order_Product_Link; +DROP TABLE IF EXISTS partsltd_prod.PH_Calc_User_Temp; -DROP TABLE IF EXISTS Shop_Manufacturing_Purchase_Order_Product_Link_Temp; -DROP TABLE IF EXISTS Shop_Manufacturing_Purchase_Order_Product_Link_Audit; -DROP TABLE IF EXISTS Shop_Manufacturing_Purchase_Order_Product_Link; +DROP TABLE IF EXISTS partsltd_prod.PH_User_Role_Link_Audit; +DROP TABLE IF EXISTS partsltd_prod.PH_User_Role_Link; -DROP TABLE IF EXISTS Shop_Supplier_Purchase_Order_Product_Link_Temp; -DROP TABLE IF EXISTS Shop_Supplier_Purchase_Order_Product_Link_Audit; -DROP TABLE IF EXISTS Shop_Supplier_Purchase_Order_Product_Link; +DROP TABLE IF EXISTS partsltd_prod.PH_Role_Permission_Link_Audit; +DROP TABLE IF EXISTS partsltd_prod.PH_Role_Permission_Link; -DROP TABLE IF EXISTS Shop_Stock_Item_Temp; -DROP TABLE IF EXISTS Shop_Stock_Item_Audit; -DROP TABLE IF EXISTS Shop_Stock_Item; +DROP TABLE IF EXISTS partsltd_prod.PH_Role_Audit; +DROP TABLE IF EXISTS partsltd_prod.PH_Role; -DROP TABLE IF EXISTS Shop_Customer_Sales_Order_Audit; -DROP TABLE IF EXISTS Shop_Customer_Sales_Order; +DROP TABLE IF EXISTS partsltd_prod.PH_User_Temp; +DROP TABLE IF EXISTS partsltd_prod.PH_User_Audit; +DROP TABLE IF EXISTS partsltd_prod.PH_User; -DROP TABLE IF EXISTS Shop_Customer_Temp; -DROP TABLE IF EXISTS Shop_Customer_Audit; -DROP TABLE IF EXISTS Shop_Customer; +DROP TABLE IF EXISTS partsltd_prod.PH_Permission_Audit; +DROP TABLE IF EXISTS partsltd_prod.PH_Permission; -DROP TABLE IF EXISTS Shop_Manufacturing_Purchase_Order_Temp; -DROP TABLE IF EXISTS Shop_Manufacturing_Purchase_Order_Audit; -DROP TABLE IF EXISTS Shop_Manufacturing_Purchase_Order; +DROP TABLE IF EXISTS partsltd_prod.PH_Permission_Group_Audit; +DROP TABLE IF EXISTS partsltd_prod.PH_Permission_Group; -DROP TABLE IF EXISTS Shop_Supplier_Purchase_Order_Temp; -DROP TABLE IF EXISTS Shop_Supplier_Purchase_Order_Audit; -DROP TABLE IF EXISTS Shop_Supplier_Purchase_Order; +DROP TABLE IF EXISTS partsltd_prod.PH_Access_Level_Audit; +DROP TABLE IF EXISTS partsltd_prod.PH_Access_Level; -DROP TABLE IF EXISTS Shop_Supplier_Address_Temp; -DROP TABLE IF EXISTS Shop_Supplier_Address_Audit; -DROP TABLE IF EXISTS Shop_Supplier_Address; +DROP TABLE IF EXISTS partsltd_prod.PH_User_Change_Set; -DROP TABLE IF EXISTS Shop_Supplier_Temp; -DROP TABLE IF EXISTS Shop_Supplier_Audit; -DROP TABLE IF EXISTS Shop_Supplier; +DROP TABLE IF EXISTS partsltd_prod.CORE_Split_Key_Value_Pair_Csv_Temp; +DROP TABLE IF EXISTS partsltd_prod.CORE_Split_Temp; +DROP TABLE IF EXISTS partsltd_prod.CORE_Msg_Error_Type; -DROP TABLE IF EXISTS Shop_User_Order_Product_Link_Audit; -DROP TABLE IF EXISTS Shop_User_Order_Product_Link; -DROP TABLE IF EXISTS Shop_User_Order_Audit; -DROP TABLE IF EXISTS Shop_User_Order; +-- Stored Procedures +DROP PROCEDURE IF EXISTS partsltd_prod.p_ph_test_get_many_contact_form; +DROP PROCEDURE IF EXISTS partsltd_prod.p_ph_get_many_contact_form; +DROP PROCEDURE IF EXISTS partsltd_prod.p_ph_test_save_contact_form; +DROP PROCEDURE IF EXISTS partsltd_prod.p_ph_save_contact_form; -DROP TABLE IF EXISTS Shop_User_Order_Status_Audit; -DROP TABLE IF EXISTS Shop_User_Order_Status; +DROP PROCEDURE IF EXISTS partsltd_prod.p_ph_clear_calc_user; +DROP PROCEDURE IF EXISTS partsltd_prod.p_ph_calc_user; -DROP TABLE IF EXISTS Shop_User_Basket_Audit; -DROP TABLE IF EXISTS Shop_User_Basket; +DROP PROCEDURE IF EXISTS partsltd_prod.p_core_clear_split_key_value_pair_csv; +DROP PROCEDURE IF EXISTS partsltd_prod.p_core_split_key_value_pair_csv; +DROP PROCEDURE IF EXISTS partsltd_prod.p_core_clear_split; +DROP PROCEDURE IF EXISTS partsltd_prod.p_core_split; +DROP PROCEDURE IF EXISTS partsltd_prod.p_clear_split_key_value_pair_csv; +DROP PROCEDURE IF EXISTS partsltd_prod.p_split_key_value_pair_csv; +DROP PROCEDURE IF EXISTS partsltd_prod.p_clear_split; +DROP PROCEDURE IF EXISTS partsltd_prod.p_split; -DROP TABLE IF EXISTS Shop_User_Address_Audit; -DROP TABLE IF EXISTS Shop_User_Address; +DROP PROCEDURE IF EXISTS partsltd_prod.p_core_debug_timing_reporting; +DROP PROCEDURE IF EXISTS partsltd_prod.p_debug_timing_reporting; +DROP PROCEDURE IF EXISTS partsltd_prod.p_core_validate_guid; +DROP PROCEDURE IF EXISTS partsltd_prod.p_core_validate_guid_test; -DROP TABLE IF EXISTS Shop_User_Role_Link_Audit; -DROP TABLE IF EXISTS Shop_User_Role_Link; +USE partsltd_prod; -DROP TABLE IF EXISTS Shop_User_Temp; -DROP TABLE IF EXISTS Shop_User_Audit; -DROP TABLE IF EXISTS Shop_User; +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'CORE_Msg_Error_Type' +; -DROP TABLE IF EXISTS Shop_Role_Permission_Link_Audit; -DROP TABLE IF EXISTS Shop_Role_Permission_Link; - -DROP TABLE IF EXISTS Shop_Role_Audit; -DROP TABLE IF EXISTS Shop_Role; - -DROP TABLE IF EXISTS Shop_Permission_Audit; -DROP TABLE IF EXISTS Shop_Permission; - -DROP TABLE IF EXISTS Shop_Permission_Group_Audit; -DROP TABLE IF EXISTS Shop_Permission_Group; - - -DROP TABLE IF EXISTS Shop_Discount_Region_Currency_Link_Audit; -DROP TABLE IF EXISTS Shop_Discount_Region_Currency_Link; - -DROP TABLE IF EXISTS Shop_Discount_Audit; -DROP TABLE IF EXISTS Shop_Discount; - -DROP TABLE IF EXISTS Shop_Product_Permutation_Delivery_Option_Link_Audit; -DROP TABLE IF EXISTS Shop_Product_Permutation_Delivery_Option_Link; -DROP TABLE IF EXISTS Shop_Product_Delivery_Option_Link_Audit; -DROP TABLE IF EXISTS Shop_Product_Delivery_Option_Link; - -DROP TABLE IF EXISTS Shop_Delivery_Option_Audit; -DROP TABLE IF EXISTS Shop_Delivery_Option; - -DROP TABLE IF EXISTS Shop_Product_Image_Audit; -DROP TABLE IF EXISTS Shop_Product_Image; -DROP TABLE IF EXISTS Shop_Image_Audit; -DROP TABLE IF EXISTS Shop_Image; - -DROP TABLE IF EXISTS Shop_Product_Price_Temp; -DROP TABLE IF EXISTS Shop_Product_Price_Audit; -DROP TABLE IF EXISTS Shop_Product_Price; - -DROP TABLE IF EXISTS Shop_Product_Currency_Region_Link_Audit; -DROP TABLE IF EXISTS Shop_Product_Currency_Region_Link; -DROP TABLE IF EXISTS Shop_Product_Currency_Link_Audit; -DROP TABLE IF EXISTS Shop_Product_Currency_Link; - -DROP TABLE IF EXISTS Shop_Product_Variation_Link_Audit; -DROP TABLE IF EXISTS Shop_Product_Variation_Link; -DROP TABLE IF EXISTS Shop_Product_Permutation_Variation_Link_Temp; -DROP TABLE IF EXISTS Shop_Product_Permutation_Variation_Link_Audit; -DROP TABLE IF EXISTS Shop_Product_Permutation_Variation_Link; - -DROP TABLE IF EXISTS Shop_Variation_Temp; -DROP TABLE IF EXISTS Shop_Variation_Audit; -DROP TABLE IF EXISTS Shop_Variation; -DROP TABLE IF EXISTS Shop_Product_Variation_Type_Link_Audit; -DROP TABLE IF EXISTS Shop_Product_Variation_Type_Link; -DROP TABLE IF EXISTS Shop_Product_Variation_Temp; -DROP TABLE IF EXISTS Shop_Product_Variation; - -DROP TABLE IF EXISTS Shop_Variation_Type_Temp; -DROP TABLE IF EXISTS Shop_Variation_Type_Audit; -DROP TABLE IF EXISTS Shop_Variation_Type; -DROP TABLE IF EXISTS Shop_Product_Variation_Type_Temp; -DROP TABLE IF EXISTS Shop_Product_Variation_Type; - -DROP TABLE IF EXISTS Shop_Product_Permutation_Temp; -DROP TABLE IF EXISTS Shop_Product_Permutation_Audit; -DROP TABLE IF EXISTS Shop_Product_Permutation; - -DROP TABLE IF EXISTS Shop_Interval_Recurrence_Audit; -DROP TABLE IF EXISTS Shop_Interval_Recurrence; - -DROP TABLE IF EXISTS Shop_Product_Audit; -DROP TABLE IF EXISTS Shop_Product; -DROP TABLE IF EXISTS Shop_Product_Temp; - -DROP TABLE IF EXISTS Shop_Product_Category_Temp; -DROP TABLE IF EXISTS Shop_Product_Category_Audit; -DROP TABLE IF EXISTS Shop_Product_Category; -DROP TABLE IF EXISTS Shop_Category_Audit; -DROP TABLE IF EXISTS Shop_Category; - -DROP TABLE IF EXISTS Shop_Tax_Or_Surcharge_Temp; -DROP TABLE IF EXISTS Shop_Tax_Or_Surcharge_Audit; -DROP TABLE IF EXISTS Shop_Tax_Or_Surcharge; - -DROP TABLE IF EXISTS Shop_Currency_Temp; -DROP TABLE IF EXISTS Shop_Currency_Audit; -DROP TABLE IF EXISTS Shop_Currency; - -DROP TABLE IF EXISTS Shop_Storage_Location_Branch_Temp; -DROP TABLE IF EXISTS Shop_Storage_Location_Branch_Audit; -DROP TABLE IF EXISTS Shop_Storage_Location_Branch; - -DROP TABLE IF EXISTS Shop_Storage_Location_Temp; -DROP TABLE IF EXISTS Shop_Storage_Location_Audit; -DROP TABLE IF EXISTS Shop_Storage_Location; - -DROP TABLE IF EXISTS Shop_Plant_Temp; -DROP TABLE IF EXISTS Shop_Plant_Audit; -DROP TABLE IF EXISTS Shop_Plant; - -DROP TABLE IF EXISTS Shop_Address_Audit; -DROP TABLE IF EXISTS Shop_Address; - -DROP TABLE IF EXISTS Shop_Delivery_Region_Branch_Audit; -DROP TABLE IF EXISTS Shop_Delivery_Region_Branch; -DROP TABLE IF EXISTS Shop_Region_Branch_Temp; -DROP TABLE IF EXISTS Shop_Region_Branch_Audit; -DROP TABLE IF EXISTS Shop_Region_Branch; - -DROP TABLE IF EXISTS Shop_Delivery_Region_Audit; -DROP TABLE IF EXISTS Shop_Delivery_Region; -DROP TABLE IF EXISTS Shop_Region_Temp; -DROP TABLE IF EXISTS Shop_Region_Audit; -DROP TABLE IF EXISTS Shop_Region; - - -DROP TABLE IF EXISTS Shop_Unit_Measurement_Conversion_Audit; -DROP TABLE IF EXISTS Shop_Unit_Measurement_Conversion; - -DROP TABLE IF EXISTS Shop_Unit_Measurement_Audit; -DROP TABLE IF EXISTS Shop_Unit_Measurement; - -DROP TABLE IF EXISTS Shop_Image_Type_Audit; -DROP TABLE IF EXISTS Shop_Image_Type; - -DROP TABLE IF EXISTS Shop_General_Audit; -DROP TABLE IF EXISTS Shop_General; - -DROP TABLE IF EXISTS File_Type_Audit; -DROP TABLE IF EXISTS File_Type; - -DROP TABLE IF EXISTS Msg_Error_Type; -DROP TABLE IF EXISTS Shop_Msg_Error_Type; - -DROP TABLE IF EXISTS Shop_Access_Level_Audit; -DROP TABLE IF EXISTS Shop_Access_Level; - -DROP TABLE IF EXISTS Shop_Sales_And_Purchasing_Change_Set; -DROP TABLE IF EXISTS Shop_User_Change_Set; -DROP TABLE IF EXISTS Shop_Product_Change_Set; - - --- Procedures -DROP PROCEDURE IF EXISTS p_split; -DROP PROCEDURE IF EXISTS p_clear_split_temp; -DROP PROCEDURE IF EXISTS p_split_key_value_pair_csv; -DROP PROCEDURE IF EXISTS p_clear_split_key_value_csv_temp; -DROP PROCEDURE IF EXISTS p_clear_split_key_value_pair_csv_temp; - -DROP PROCEDURE IF EXISTS p_debug_timing_reporting; -DROP PROCEDURE IF EXISTS p_validate_guid; -DROP PROCEDURE IF EXISTS p_validate_guid_test; - -DROP FUNCTION IF EXISTS fn_shop_get_product_permutation_name; - -DROP PROCEDURE IF EXISTS p_shop_calc_user; -DROP PROCEDURE IF EXISTS p_shop_calc_user; -DROP PROCEDURE IF EXISTS p_shop_clear_user_eval_temp; -DROP PROCEDURE IF EXISTS p_shop_clear_calc_user; - -DROP PROCEDURE IF EXISTS p_shop_get_many_access_level; -DROP PROCEDURE IF EXISTS p_shop_get_many_unit_measurement; - -DROP PROCEDURE IF EXISTS p_shop_get_many_region; -DROP PROCEDURE IF EXISTS p_shop_get_many_plant; -DROP PROCEDURE IF EXISTS p_shop_get_many_storage_location; -DROP PROCEDURE IF EXISTS p_shop_get_many_currency; - -DROP PROCEDURE IF EXISTS p_shop_save_category; -DROP PROCEDURE IF EXISTS p_shop_save_category_test; -DROP PROCEDURE IF EXISTS p_shop_save_product_category; -DROP PROCEDURE IF EXISTS p_shop_save_product_category_test; -DROP PROCEDURE IF EXISTS p_shop_save_product; -DROP PROCEDURE IF EXISTS p_shop_save_product_test; -DROP PROCEDURE IF EXISTS p_shop_calc_product_permutation; -DROP PROCEDURE IF EXISTS p_shop_clear_calc_product_permutation; -DROP PROCEDURE IF EXISTS p_shop_get_many_product; -DROP PROCEDURE IF EXISTS p_shop_get_many_stripe_product_new; -DROP PROCEDURE IF EXISTS p_shop_save_permutation; -DROP PROCEDURE IF EXISTS p_shop_save_product_permutation; -DROP PROCEDURE IF EXISTS p_shop_save_product_permutation_test; -DROP PROCEDURE IF EXISTS p_shop_save_product_variation; -DROP PROCEDURE IF EXISTS p_shop_save_product_variation_test; -DROP PROCEDURE IF EXISTS p_shop_get_many_product_variation; -DROP FUNCTION IF EXISTS fn_shop_get_id_product_permutation_from_variation_csv_list; -DROP FUNCTION IF EXISTS fn_shop_get_product_variations_from_id_csv_list; -DROP FUNCTION IF EXISTS fn_shop_get_product_permutation_variations_csv; -DROP PROCEDURE IF EXISTS p_shop_save_stock_item; -DROP PROCEDURE IF EXISTS p_shop_save_stock_item_test; -DROP PROCEDURE IF EXISTS p_shop_get_many_stock_item; -DROP PROCEDURE IF EXISTS p_shop_get_many_product_price_and_discount_and_delivery_option; -DROP PROCEDURE IF EXISTS p_shop_get_many_product_price_and_discount_and_delivery_option; -DROP PROCEDURE IF EXISTS p_shop_get_many_stripe_price_new; -DROP PROCEDURE IF EXISTS p_shop_save_user; -DROP PROCEDURE IF EXISTS p_shop_edit_user; -DROP PROCEDURE IF EXISTS p_shop_get_many_user; -DROP PROCEDURE IF EXISTS p_get_many_user; -DROP PROCEDURE IF EXISTS p_shop_get_many_user_basket; -DROP PROCEDURE IF EXISTS p_shop_edit_user_basket; -DROP PROCEDURE IF EXISTS p_shop_save_supplier; -DROP PROCEDURE IF EXISTS p_shop_save_supplier_test; -DROP PROCEDURE IF EXISTS p_shop_get_many_supplier; -DROP PROCEDURE IF EXISTS p_shop_save_supplier_purchase_order; -DROP PROCEDURE IF EXISTS p_shop_save_supplier_purchase_order_test; -DROP PROCEDURE IF EXISTS p_shop_get_many_supplier_purchase_order; -DROP PROCEDURE IF EXISTS p_shop_save_manufacturing_purchase_order; -DROP PROCEDURE IF EXISTS p_shop_save_manufacturing_purchase_order_test; -DROP PROCEDURE IF EXISTS p_shop_get_many_manufacturing_purchase_order; -DROP PROCEDURE IF EXISTS p_shop_save_customer; -DROP PROCEDURE IF EXISTS p_shop_get_many_customer; -DROP PROCEDURE IF EXISTS p_shop_save_customer_sales_order; -DROP PROCEDURE IF EXISTS p_shop_get_many_customer_sales_order; - - --- File: 1000_tbl_Shop_Product_Change_Set.sql - --- Product Change Sets - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Change_Set'; - -CREATE TABLE Shop_Product_Change_Set ( - id_change_set INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - comment VARCHAR(500), - updated_last_on DATETIME, - updated_last_by VARCHAR(100) +CREATE TABLE IF NOT EXISTS partsltd_prod.CORE_Msg_Error_Type ( + id_type INT NOT NULL AUTO_INCREMENT PRIMARY KEY + , code VARCHAR(50) NOT NULL + , name VARCHAR(500) NOT NULL + , description VARCHAR(1000) ); --- File: 1000_tbl_Split_Temp.sql +USE partsltd_prod; --- Split Staging --- USE partsltd_prod; --- DROP TABLE IF EXISTS Split_Temp; +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'CORE_Split_Temp' +; -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Split_Temp'; - -CREATE TABLE Split_Temp ( - guid BINARY(36) NOT NULL +CREATE TABLE IF NOT EXISTS partsltd_prod.CORE_Split_Temp ( + guid BINARY(36) NOT NULL , display_order INT NOT NULL , substring VARCHAR(4000) NOT NULL ); +USE partsltd_prod; --- File: 1001_tbl_Shop_User_Change_Set.sql +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'CORE_Split_Key_Value_Pair_Csv_Temp' +; --- User Change Sets - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Change_Set'; - -CREATE TABLE IF NOT EXISTS Shop_User_Change_Set ( - id_change_set INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - comment VARCHAR(500), - updated_last_on DATETIME, - updated_last_by VARCHAR(100) -); - --- File: 1001_tbl_Split_Key_Value_Pair_Csv_Temp.sql - --- Split Key Value Pair CSV Staging --- USE partsltd_prod; --- DROP TABLE IF EXISTS Split_Temp; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Split_Key_Value_Pair_Csv_Temp'; - -CREATE TABLE Split_Key_Value_Pair_Csv_Temp ( - guid BINARY(36) NOT NULL +CREATE TABLE IF NOT EXISTS partsltd_prod.CORE_Split_Key_Value_Pair_Csv_Temp ( + guid BINARY(36) NOT NULL , id INT NOT NULL , key_column VARCHAR(4000) NULL , value_column VARCHAR(4000) NULL ); +USE partsltd_prod; --- File: 1002_tbl_Shop_Sales_And_Purchasing_Change_Set.sql +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'PH_User_Change_Set' +; --- Sales And Purchasing Change Sets - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Sales_And_Purchasing_Change_Set'; - -CREATE TABLE Shop_Sales_And_Purchasing_Change_Set ( - id_change_set INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - comment VARCHAR(500), - updated_last_on DATETIME, - updated_last_by VARCHAR(100) +CREATE TABLE IF NOT EXISTS partsltd_prod.PH_User_Change_Set ( + id_change_set INT NOT NULL AUTO_INCREMENT PRIMARY KEY + , comment VARCHAR(500) + , updated_last_on DATETIME + , id_user_updated_last_by INT ); +USE partsltd_prod; --- File: 1003_tbl_Shop_Access_Level.sql +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'PH_Access_Level' +; --- Access Levels - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Access_Level'; - -CREATE TABLE IF NOT EXISTS Shop_Access_Level ( - id_access_level INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - code VARCHAR(50), - name VARCHAR(255), - priority INT NOT NULL, - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Access_Level_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) +CREATE TABLE IF NOT EXISTS partsltd_prod.PH_Access_Level ( + id_access_level INT NOT NULL AUTO_INCREMENT PRIMARY KEY + , code VARCHAR(50) + , name VARCHAR(255) + , priority INT NOT NULL + , display_order INT NOT NULL + , active BIT NOT NULL DEFAULT 1 ); +USE partsltd_prod; --- File: 1004_tbl_Shop_Access_Level_Audit.sql +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'PH_Permission_Group' +; --- Access Level Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Access_Level_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Access_Level_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_access_level INT NOT NULL, - CONSTRAINT FK_Shop_Access_Level_Audit_id_access_level - FOREIGN KEY (id_access_level) - REFERENCES Shop_Access_Level(id_access_level) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Access_Level_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) +CREATE TABLE IF NOT EXISTS partsltd_prod.PH_Permission_Group ( + id_group INT NOT NULL AUTO_INCREMENT PRIMARY KEY + , code VARCHAR(50) + , name VARCHAR(255) + , display_order INT NOT NULL + , active BIT NOT NULL DEFAULT 1 ); +USE partsltd_prod; --- File: 1005_tbl_Msg_Error_Type.sql +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'PH_Permission' +; --- Error Message Type - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Msg_Error_Type'; - -CREATE TABLE IF NOT EXISTS Shop_Msg_Error_Type ( - id_type INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - code VARCHAR(50) NOT NULL, - name VARCHAR(500) NOT NULL, - description VARCHAR(1000) +CREATE TABLE IF NOT EXISTS partsltd_prod.PH_Permission ( + id_permission INT NOT NULL AUTO_INCREMENT PRIMARY KEY + , code VARCHAR(50) + , name VARCHAR(255) + , id_permission_group INT NOT NULL + , CONSTRAINT FK_PH_Permission_id_permission_group + FOREIGN KEY (id_permission_group) + REFERENCES partsltd_prod.PH_Permission_Group(id_group) + , id_access_level_required INT NOT NULL + , CONSTRAINT FK_PH_Permission_id_access_level_required + FOREIGN KEY (id_access_level_required) + REFERENCES partsltd_prod.PH_Access_Level(id_access_level) + , display_order INT NOT NULL + , active BIT NOT NULL DEFAULT 1 ); - - --- File: 1010_tbl_File_Type.sql - --- File Types - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'File_Type'; - -CREATE TABLE IF NOT EXISTS File_Type ( - id_type INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - code VARCHAR(50), - name VARCHAR(100), - extension VARCHAR(50), - created_on DATETIME, - created_by INT, - updated_last_on DATETIME, - updated_last_by VARCHAR(100) -); - - --- File: 1011_tbl_File_Type_Audit.sql - --- File Type Audit - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'File_Type_Audit'; - -CREATE TABLE IF NOT EXISTS File_Type_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_type INT NOT NULL, - CONSTRAINT FK_File_Type_Audit_id_type - FOREIGN KEY (id_type) - REFERENCES File_Type(id_type) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - created_on DATETIME, - created_by INT, - updated_last_on DATETIME, - updated_last_by VARCHAR(100) -); - --- File: 1012_tbl_Shop_General.sql - --- Generic / shared properties - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_General'; - -CREATE TABLE IF NOT EXISTS Shop_General ( - id_general INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - quantity_max FLOAT, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT CHK_Shop_General_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - --- File: 1013_tbl_Shop_General_Audit.sql - --- Shop General Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_General_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_General_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_general INT NOT NULL, - CONSTRAINT FK_Shop_General_Audit_id_general - FOREIGN KEY (id_general) - REFERENCES Shop_General(id_general) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_General_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - --- File: 1014_tbl_Shop_Image_Type.sql - --- Image Types - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Image_Type'; - -CREATE TABLE IF NOT EXISTS Shop_Image_Type ( - id_type INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - /* - id_type_file INT NOT NULL, - CONSTRAINT FK_Shop_Image_Type_id_type_file - FOREIGN KEY (id_type_file) - REFERENCES File_Type(id_type), - */ - code VARCHAR(50), - name VARCHAR(255), - name_plural VARCHAR(256), - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Image_Type_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - - --- File: 1015_tbl_Shop_Image_Type_Audit.sql - --- Image Type Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Image_Type_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Image_Type_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_type INT NOT NULL, - CONSTRAINT FK_Shop_Image_Type_Audit_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Image_Type(id_type) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Image_Type_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - --- File: 1100_tbl_Shop_Region.sql - --- Regions - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Region'; - -CREATE TABLE IF NOT EXISTS Shop_Region ( - id_region INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - code VARCHAR(50) NOT NULL, - name VARCHAR(200) NOT NULL, - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Region_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - --- File: 1101_tbl_Shop_Region_Audit.sql - --- Region Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Region_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Region_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_region INT NOT NULL, - CONSTRAINT FK_Shop_Region_Audit_id_region - FOREIGN KEY (id_region) - REFERENCES Shop_Region(id_region) - ON UPDATE RESTRICT, - name_field VARCHAR(64) NOT NULL, - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Region_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - --- File: 1102_tbl_Shop_Region_Temp.sql - --- Region Temp - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Region_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Region_Temp ( - id_region INT NOT NULL PRIMARY KEY, - code VARCHAR(50) NOT NULL, - name VARCHAR(200) NOT NULL, - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Region_Temp_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - --- File: 1103_tbl_Shop_Region_Branch.sql - --- Region Branchs - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Region_Branch'; - -CREATE TABLE IF NOT EXISTS Shop_Region_Branch ( - id_branch INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_region_parent INT NOT NULL, - CONSTRAINT FK_Shop_Region_Branch_id_region_parent - FOREIGN KEY (id_region_parent) - REFERENCES Shop_Region(id_region) - ON UPDATE RESTRICT, - id_region_child INT NOT NULL, - CONSTRAINT FK_Shop_Region_Branch_id_region_child - FOREIGN KEY (id_region_child) - REFERENCES Shop_Region(id_region) - ON UPDATE RESTRICT, - -- depth INT NOT NULL, - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Region_Branch_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - --- File: 1104_tbl_Shop_Region_Branch_Audit.sql - --- Region Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Region_Branch_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Region_Branch_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_branch INT NOT NULL, - CONSTRAINT FK_Shop_Region_Branch_Audit_id_branch - FOREIGN KEY (id_branch) - REFERENCES Shop_Region_Branch(id_branch) - ON UPDATE RESTRICT, - name_field VARCHAR(64) NOT NULL, - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Region_Branch_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - --- File: 1105_tbl_Shop_Region_Branch_Temp.sql - --- Region Branch Temp - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Region_Branch_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Region_Branch_Temp ( - id_branch INT NOT NULL PRIMARY KEY, - id_region_parent INT NOT NULL, - id_region_child INT NOT NULL, - -- depth INT NOT NULL, - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL -); - --- File: 1106_tbl_Shop_Address.sql - --- Addresses - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Address'; - -CREATE TABLE Shop_Address ( - id_address INT NOT NULL AUTO_INCREMENT PRIMARY KEY - , id_region INT NOT NULL - , CONSTRAINT FK_Shop_Address_id_region - FOREIGN KEY (id_region) - REFERENCES partsltd_prod.Shop_Region(id_region) - /* - , id_supplier INT NULL - , CONSTRAINT FK_Shop_Address_id_supplier - FOREIGN KEY (id_supplier) - REFERENCES partsltd_prod.Shop_Supplier(id_supplier) - */ - , postcode VARCHAR(20) NOT NULL - , address_line_1 VARCHAR(256) NOT NULL - , address_line_2 VARCHAR(256) NOT NULL - , city VARCHAR(256) NOT NULL - , county VARCHAR(256) NOT NULL +USE partsltd_prod; + +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'PH_User' +; + +CREATE TABLE IF NOT EXISTS partsltd_prod.PH_User ( + id_user INT NOT NULL AUTO_INCREMENT PRIMARY KEY + , id_user_auth0 VARCHAR(200) + , firstname VARCHAR(255) + , surname VARCHAR(255) + , email VARCHAR(254) + , is_email_verified BIT NOT NULL DEFAULT 0 + , is_super_user BIT NOT NULL DEFAULT 0 , active BIT NOT NULL DEFAULT 1 , created_on DATETIME - , created_by INT + , id_user_created_by INT + , CONSTRAINT FK_PH_User_id_user_created_by + FOREIGN KEY (id_user_created_by) + REFERENCES partsltd_prod.PH_User(id_user) , id_change_set INT - , CONSTRAINT FK_Shop_Address_id_change_set + , CONSTRAINT FK_PH_User_id_change_set FOREIGN KEY (id_change_set) - REFERENCES partsltd_prod.Shop_User_Change_Set(id_change_set) + REFERENCES partsltd_prod.PH_User_Change_Set(id_change_set) ); --- File: 1106_tbl_Shop_Plant.sql +USE partsltd_prod; --- Plant +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'PH_User_Audit' +; -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Plant'; - -CREATE TABLE IF NOT EXISTS Shop_Plant ( - id_plant INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - code VARCHAR(50) NOT NULL, - name VARCHAR(500) NOT NULL, - id_address INT NOT NULL, - CONSTRAINT FK_Shop_Plant_id_address - FOREIGN KEY (id_address) - REFERENCES Shop_Address(id_address), - id_user_manager INT NOT NULL, - active BIT NOT NULL DEFAULT 1, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Plant_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - - --- File: 1107_tbl_Shop_Address_Audit.sql - --- Address Audits - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Address_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Address_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_address INT NOT NULL, - CONSTRAINT FK_Shop_Address_Audit_id_address - FOREIGN KEY (id_address) - REFERENCES Shop_Address(id_address) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Address_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - ON UPDATE RESTRICT -); - --- File: 1107_tbl_Shop_Plant_Audit.sql - --- Plant Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Plant_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Plant_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_plant INT NOT NULL, - CONSTRAINT FK_Shop_Plant_Audit_id_plant - FOREIGN KEY (id_plant) - REFERENCES Shop_Plant(id_plant) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Plant_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - - --- File: 1108_tbl_Shop_Plant_Temp.sql - --- Plant Temp - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Plant_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Plant_Temp ( - id_plant INT NOT NULL PRIMARY KEY - , code VARCHAR(50) NOT NULL - , name VARCHAR(500) NOT NULL - , id_address INT NOT NULL - , id_user_manager INT NOT NULL - , active BIT NOT NULL DEFAULT 1 - , guid BINARY(36) NOT NULL -); - - --- File: 1109_tbl_Shop_Storage_Location.sql - --- Storage Location - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Storage_Location'; - -CREATE TABLE IF NOT EXISTS Shop_Storage_Location ( - id_location INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_plant INT NOT NULL, - CONSTRAINT FK_Shop_Storage_Location_id_plant - FOREIGN KEY (id_plant) - REFERENCES Shop_Plant(id_plant), - code VARCHAR(50) NOT NULL, - name VARCHAR(500) NOT NULL, - active BIT NOT NULL DEFAULT 1, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Storage_Location_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - - --- File: 1110_tbl_Shop_Storage_Location_Audit.sql - --- Storage Location Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Storage_Location_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Storage_Location_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_location INT NOT NULL, - CONSTRAINT FK_Shop_Storage_Location_Audit_id_location - FOREIGN KEY (id_location) - REFERENCES Shop_Storage_Location(id_location) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Storage_Location_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - - --- File: 1111_tbl_Shop_Storage_Location_Temp.sql - --- Storage Location Temp - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Storage_Location_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Storage_Location ( - id_location INT NOT NULL PRIMARY KEY, - code VARCHAR(50) NOT NULL, - name VARCHAR(500) NOT NULL, - active BIT NOT NULL DEFAULT 1 -); - - --- File: 1112_tbl_Shop_Storage_Location_Branch.sql - --- Storage Location Branch - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Storage_Location_Branch'; - -CREATE TABLE IF NOT EXISTS Shop_Storage_Location_Branch ( - id_branch INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_location_parent INT NOT NULL, - CONSTRAINT FK_Shop_Storage_Location_Branch_id_location_parent - FOREIGN KEY (id_location_parent) - REFERENCES Shop_Storage_Location(id_location) - ON UPDATE RESTRICT, - id_location_child INT NOT NULL, - CONSTRAINT FK_Shop_Storage_Location_Branch_id_location_child - FOREIGN KEY (id_location_child) - REFERENCES Shop_Storage_Location(id_location) - ON UPDATE RESTRICT, - -- depth INT NOT NULL, - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Storage_Location_Branch_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - --- File: 1113_tbl_Shop_Storage_Location_Branch_Audit.sql - --- Storage Location Branch Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Storage_Location_Branch_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Storage_Location_Branch_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_branch INT NOT NULL, - CONSTRAINT FK_Shop_Storage_Location_Branch_Audit_id_branch - FOREIGN KEY (id_branch) - REFERENCES Shop_Storage_Location_Branch(id_branch) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Storage_Location_Branch_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - - --- File: 1114_tbl_Shop_Storage_Location_Branch_Temp.sql - --- Storage Location Branch Temp - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Storage_Location_Branch_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Storage_Location_Branch_Temp ( - id_branch INT NOT NULL PRIMARY KEY, - id_location_parent INT NOT NULL, - id_location_child INT NOT NULL, - -- depth INT NOT NULL, - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL -); - --- File: 1115_tbl_Shop_Currency.sql - --- Currencies - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Currency'; - -CREATE TABLE IF NOT EXISTS Shop_Currency ( - id_currency INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - code VARCHAR(50) NOT NULL, - name VARCHAR(255) NOT NULL, - symbol VARCHAR(50) NOT NULL, - factor_from_GBP FLOAT NOT NULL, - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Currency_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) - ON UPDATE RESTRICT -); - --- File: 1116_tbl_Shop_Currency_Audit.sql - --- Currency Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Currency_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Currency_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_currency INT NOT NULL, - CONSTRAINT FK_Shop_Currency_Audit_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Currency_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - ON UPDATE RESTRICT -); - --- File: 1117_tbl_Shop_Currency_Temp.sql - --- Currency Temp - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Currency_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Currency_Temp ( - id_currency INT NOT NULL PRIMARY KEY, - code VARCHAR(50) NOT NULL, - name VARCHAR(255) NOT NULL, - symbol VARCHAR(1) NOT NULL, - factor_from_GBP FLOAT NOT NULL, - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL -); - --- File: 1118_tbl_Shop_Tax_Or_Surcharge.sql - --- Taxes and Surcharges - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Tax_Or_Surcharge'; - -CREATE TABLE Shop_Tax_Or_Surcharge ( - id_tax INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - code VARCHAR(50) NOT NULL, - name VARCHAR(200) NOT NULL, - id_region_buyer INT NOT NULL, - CONSTRAINT FK_Shop_Tax_Or_Surcharge_id_region_buyer - FOREIGN KEY (id_region_buyer) - REFERENCES Shop_Region(id_region), - id_region_seller INT NOT NULL, - CONSTRAINT FK_Shop_Tax_Or_Surcharge_id_region_seller - FOREIGN KEY (id_region_seller) - REFERENCES Shop_Region(id_region), - id_currency INT, - CONSTRAINT FK_Shop_Tax_Or_Surcharge_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency) - ON UPDATE RESTRICT, - fixed_fee FLOAT NOT NULL DEFAULT 0, - multiplier FLOAT NOT NULL DEFAULT 1 CHECK (multiplier > 0), - apply_fixed_fee_before_multiplier BIT DEFAULT 1, - quantity_min FLOAT NOT NULL DEFAULT 0, - quantity_max FLOAT NOT NULL, - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Tax_Or_Surcharge_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - - --- File: 1119_tbl_Shop_Tax_Or_Surcharge_Audit.sql - --- Tax Or Surcharge Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Tax_Or_Surcharge_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Tax_Or_Surcharge_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_tax INT NOT NULL, - CONSTRAINT FK_Shop_Tax_Or_Surcharge_Audit_id_discount - FOREIGN KEY (id_tax) - REFERENCES Shop_Tax_Or_Surcharge(id_tax) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Tax_Or_Surcharge_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) - ON UPDATE RESTRICT -); - --- File: 1120_tbl_Shop_Tax_Or_Surcharge_Temp.sql - --- Taxes and Surcharges Temp - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Tax_Or_Surcharge_Temp'; - -CREATE TABLE Shop_Tax_Or_Surcharge_Temp ( - id_tax INT NOT NULL PRIMARY KEY, - code VARCHAR(50) NOT NULL, - name VARCHAR(200) NOT NULL, - id_region_buyer INT NOT NULL, - id_region_seller INT NOT NULL, - id_currency INT, - fixed_fee FLOAT NOT NULL DEFAULT 0, - multiplier FLOAT NOT NULL DEFAULT 1 CHECK (multiplier > 0), - apply_fixed_fee_before_multiplier BIT DEFAULT 1, - quantity_min FLOAT NOT NULL DEFAULT 0, - quantity_max FLOAT NOT NULL, - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL -); - - --- File: 1121_tbl_Shop_Unit_Measurement.sql - --- Unit of Measurement - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Unit_Measurement'; - -CREATE TABLE IF NOT EXISTS Shop_Unit_Measurement ( - id_unit_measurement INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - name_singular VARCHAR(255) NOT NULL, - name_plural VARCHAR(256) NOT NULL, - symbol VARCHAR(50) NOT NULL, - symbol_is_suffix_not_prefix BIT NOT NULL DEFAULT 1, - is_base_unit BIT NOT NULL DEFAULT 0, - is_unit_of_distance BIT NOT NULL DEFAULT 0, - is_unit_of_mass BIT NOT NULL DEFAULT 0, - is_unit_of_time BIT NOT NULL DEFAULT 0, - is_unit_of_volume BIT NOT NULL DEFAULT 0, - active BIT NOT NULL DEFAULT 1, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Unit_Measurement_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - - --- File: 1122_tbl_Shop_Unit_Measurement_Audit.sql - --- Unit of Measurement Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Unit_Measurement_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Unit_Measurement_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_unit_measurement INT NOT NULL, - CONSTRAINT FK_Shop_Unit_Measurement_Audit_id_unit_measurement - FOREIGN KEY (id_unit_measurement) - REFERENCES Shop_Unit_Measurement(id_unit_measurement) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Unit_Measurement_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - - --- File: 1124_tbl_Shop_Unit_Measurement_Conversion.sql - --- Unit of Measurement Conversion - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Unit_Measurement_Conversion'; - -CREATE TABLE IF NOT EXISTS Shop_Unit_Measurement_Conversion ( - id_conversion INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - id_unit_derived INT NOT NULL, - id_unit_base INT NOT NULL, - multiplier_unit_base FLOAT NOT NULL, - increment_unit_base FLOAT NOT NULL, - apply_multiplier_before_increment BIT NOT NULL DEFAULT 1, - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Unit_Measurement_Conversion_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - - --- File: 1125_tbl_Shop_Unit_Measurement_Conversion_Audit.sql - --- Unit of Measurement Conversion Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Unit_Measurement_Conversion_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Unit_Measurement_Conversion_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_conversion INT NOT NULL, - CONSTRAINT FK_Shop_Unit_Measurement_Conversion_Audit_id_conversion - FOREIGN KEY (id_conversion) - REFERENCES Shop_Unit_Measurement_Conversion(id_conversion) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Unit_Measurement_Conversion_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - - --- File: 1200_tbl_Shop_Product_Category.sql - --- Categories - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Category'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Category ( - id_category INT NOT NULL AUTO_INCREMENT PRIMARY KEY - , code VARCHAR(50) - , name VARCHAR(255) - , description VARCHAR(4000) - , active BIT NOT NULL DEFAULT 1 - , display_order INT NOT NULL - , id_access_level_required INT NOT NULL - , CONSTRAINT FK_Shop_Product_Category_id_access_level_required - FOREIGN KEY (id_access_level_required) - REFERENCES Shop_Access_Level(id_access_level) - , created_on DATETIME - , created_by INT NOT NULL - , id_change_set INT - , CONSTRAINT FK_Shop_Product_Category_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - - --- File: 1201_tbl_Shop_Product_Category_Audit.sql - --- Category Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Category_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Category_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_category INT NOT NULL, - CONSTRAINT FK_Shop_Product_Category_Audit_id_category - FOREIGN KEY (id_category) - REFERENCES Shop_Product_Category(id_category) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Product_Category_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - - --- File: 1202_tbl_Shop_Product_Category_Temp.sql - --- Categories Temp - --- DROP TABLE Shop_Product_Category_Temp; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Category_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Category_Temp ( - id_temp INT NOT NULL PRIMARY KEY AUTO_INCREMENT - , id_category INT NOT NULL - , code VARCHAR(50) NOT NULL - , name VARCHAR(255) NOT NULL - , description VARCHAR(4000) NULL - , id_access_level_required INT NOT NULL DEFAULT 1 - , display_order INT NOT NULL - , active BIT NULL - , can_view BIT NULL - , can_edit BIT NULL - , can_admin BIT NULL - , guid BINARY(36) NOT NULL -); - - --- File: 1203_tbl_Shop_Product.sql - --- Products - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product'; - -CREATE TABLE IF NOT EXISTS Shop_Product ( - id_product INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - name VARCHAR(255) NOT NULL, - -- description VARCHAR(4000), - id_category INT NOT NULL, - has_variations BIT NOT NULL, - /* - price_GBP_full FLOAT, - price_GBP_min FLOAT, - -- ratio_discount_overall FLOAT NOT NULL DEFAULT 0, - CONSTRAINT FK_Shop_Product_id_category - FOREIGN KEY (id_category) - REFERENCES Shop_Product_Category(id_category) - ON UPDATE RESTRICT, - latency_manuf INT, - quantity_min FLOAT, - quantity_max FLOAT, - quantity_step FLOAT, - quantity_stock FLOAT, - is_subscription BIT, - id_unit_measurement_interval_recurrence INT, - CONSTRAINT FK_Shop_Product_id_unit_measurement_interval_recurrence - FOREIGN KEY (id_unit_measurement_interval_recurrence) - REFERENCES Shop_Interval_Recurrence(id_interval), - count_interval_recurrence INT, - */ - id_access_level_required INT NOT NULL, - CONSTRAINT FK_Shop_Product_id_access_level_required - FOREIGN KEY (id_access_level_required) - REFERENCES Shop_Access_Level(id_access_level), - -- id_stripe_product VARCHAR(100), - -- id_stripe_price VARCHAR(100) NOT NULL, - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME NOT NULL, - created_by INT NOT NULL, - id_change_set INT, - CONSTRAINT FK_Shop_Product_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - - --- File: 1204_tbl_Shop_Product_Audit.sql - --- Products - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_product INT NOT NULL, - CONSTRAINT FK_Shop_Product_Audit_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Product_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - --- File: 1205_tbl_Shop_Product_Temp.sql - --- Products Temp - --- DROP TABLE IF EXISTS Shop_Product_Temp; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Temp ( - id_temp INT NOT NULL PRIMARY KEY AUTO_INCREMENT - , id_product INT NOT NULL - , name VARCHAR(255) NOT NULL - , id_category INT NOT NULL - , has_variations BIT NOT NULL - , id_access_level_required INT NOT NULL - , display_order INT NOT NULL - , active BIT NOT NULL DEFAULT 1 - , can_view BIT NULL DEFAULT NULL - , can_edit BIT NULL DEFAULT NULL - , can_admin BIT NULL DEFAULT NULL - , guid BINARY(36) NOT NULL -); - - --- File: 1206_tbl_Shop_Product_Permutation.sql - --- Product Permutation - --- DROP TABLE partsltd_prod.Shop_Product_Permutation; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Permutation'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Permutation ( - id_permutation INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_permutation_temp INT NOT NULL, - id_product INT NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product) - ON UPDATE RESTRICT, - -- name VARCHAR(255) NOT NULL, - description VARCHAR(4000) NOT NULL, - cost_local_VAT_excl FLOAT NULL, - cost_local_VAT_incl FLOAT NULL, - id_currency_cost INT NOT NULL, - profit_local_min FLOAT NULL, - -- id_currency_profit_min INT NOT NULL, - latency_manufacture INT NOT NULL, - id_unit_measurement_quantity INT NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_id_unit_quantity - FOREIGN KEY (id_unit_measurement_quantity) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - count_unit_measurement_per_quantity_step FLOAT NOT NULL, - quantity_min FLOAT NULL, - quantity_max FLOAT NULL, - quantity_stock FLOAT NOT NULL, - is_subscription BIT NOT NULL, - id_unit_measurement_interval_recurrence INT, - CONSTRAINT FK_Shop_Product_Permutation_id_unit_interval_recurrence - FOREIGN KEY (id_unit_measurement_interval_recurrence) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - /* - CONSTRAINT CHECK_FK_Shop_Product_Permutation_id_unit_measurement_interval_recurrence - CHECK (id_unit_measurement_interval_recurrence IN (SELECT id_unit_measurement FROM Shop_Unit_Measurement WHERE is_unit_of_time = 1)), - */ - count_interval_recurrence INT, - id_stripe_product VARCHAR(100) NULL, - does_expire_faster_once_unsealed BIT NOT NULL DEFAULT 0, - id_unit_measurement_interval_expiration_unsealed INT, - CONSTRAINT FK_Shop_Product_Permutation_id_unit_interval_expiration_unsealed - FOREIGN KEY (id_unit_measurement_interval_expiration_unsealed) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - /* - CONSTRAINT CHECK_FK_Shop_Product_Permutation_id_interval_expiration_unsealed - CHECK (id_interval_expiration_unsealed IN (SELECT id_unit_measurement FROM Shop_Unit_Measurement WHERE is_unit_of_time = 1)), - */ - count_interval_expiration_unsealed INT, - active BIT NOT NULL DEFAULT 1, - -- display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Product_Permutation_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - - --- File: 1207_tbl_Shop_Product_Permutation_Audit.sql - --- Product Permutation Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Permutation_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Permutation_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_permutation INT NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_Audit_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) - ON UPDATE RESTRICT -); - - --- File: 1208_tbl_Shop_Product_Permutation_Temp.sql - --- Product Permutation Temp - --- DROP TABLE IF EXISTS Shop_Product_Permutation_Temp; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Permutation_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Permutation_Temp ( - id_temp INT NOT NULL PRIMARY KEY AUTO_INCREMENT - , id_permutation INT NOT NULL - , id_product INT NOT NULL - , csv_id_pairs_variation VARCHAR(4000) NULL - , description VARCHAR(4000) NOT NULL - , cost_local_VAT_excl FLOAT NULL - , cost_local_VAT_incl FLOAT NULL - , id_currency_cost INT NOT NULL - , profit_local_min FLOAT NULL - , latency_manufacture INT NOT NULL - , id_unit_measurement_quantity INT NOT NULL - , count_unit_measurement_per_quantity_step FLOAT NOT NULL - , quantity_min FLOAT NULL - , quantity_max FLOAT NULL - , quantity_stock FLOAT NULL - , is_subscription BIT NOT NULL - , id_unit_measurement_interval_recurrence INT - , count_interval_recurrence INT - , id_stripe_product VARCHAR(100) NULL - , does_expire_faster_once_unsealed BIT NOT NULL DEFAULT 0 - , id_unit_measurement_interval_expiration_unsealed INT - , count_interval_expiration_unsealed INT - , active BIT NOT NULL DEFAULT 1 - -- display_order INT NOT NULL - , guid BINARY(36) - , can_view BIT NULL DEFAULT NULL - , can_edit BIT NULL DEFAULT NULL - , can_admin BIT NULL DEFAULT NULL -); - - --- File: 1209_tbl_Shop_Variation_Type.sql - --- Variation Types - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Variation_Type'; - -CREATE TABLE IF NOT EXISTS Shop_Variation_Type ( - id_type INT NOT NULL AUTO_INCREMENT PRIMARY KEY - , id_type_temp INT NULL - , code VARCHAR(50) - , name VARCHAR(255) - , name_plural VARCHAR(256) - , active BIT NOT NULL DEFAULT 1 - , display_order INT NOT NULL - , created_on DATETIME - , created_by INT - , id_change_set INT - , CONSTRAINT FK_Shop_Variation_Type_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - --- File: 1210_tbl_Shop_Variation_Type_Audit.sql - --- Variation Type Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Variation_Type_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Variation_Type_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_type INT NOT NULL, - CONSTRAINT FK_Shop_Variation_Type_Audit_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Variation_Type(id_type) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Variation_Type_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - - --- File: 1211_tbl_Shop_Variation_Type_Temp.sql - --- Variation Types Temp - --- DROP TABLE partsltd_prod.Shop_Variation_Type_Temp; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Variation_Type_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Variation_Type_Temp ( - id_temp INT NOT NULL PRIMARY KEY AUTO_INCREMENT - , id_type INT NOT NULL - -- , id_type_temp INT NOT NULL - , code VARCHAR(50) - , name VARCHAR(255) - , name_plural VARCHAR(256) - , active BIT NULL - , display_order INT NOT NULL - , created_on DATETIME - , created_by INT - , guid BINARY(36) NOT NULL -); - --- File: 1212_tbl_Shop_Variation.sql - --- Variations - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Variation'; - -CREATE TABLE Shop_Variation ( - id_variation INT NOT NULL AUTO_INCREMENT PRIMARY KEY - , id_type INT NOT NULL - , CONSTRAINT FK_Shop_Variation_id_type - FOREIGN KEY (id_type) - REFERENCES partsltd_prod.Shop_Variation_Type(id_type) - ON UPDATE RESTRICT - , id_unit_measurement INT NULL - , CONSTRAINT FK_Shop_Unit_Measurement_id_unit_measurement - FOREIGN KEY (id_unit_measurement) - REFERENCES partsltd_prod.Shop_Unit_Measurement(id_unit_measurement) - , count_unit_measurement INT NULL - , code VARCHAR(50) - , name VARCHAR(255) - , active BIT NOT NULL DEFAULT 1 - , display_order INT NOT NULL - , created_on DATETIME - , created_by INT - , id_change_set INT - , CONSTRAINT FK_Shop_Variation_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES partsltd_prod.Shop_Product_Change_Set(id_change_set) -); - - --- File: 1213_tbl_Shop_Variation_Audit.sql - --- Variation Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Variation_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Variation_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_variation INT NOT NULL, - CONSTRAINT FK_Shop_Variation_Audit_id_variation - FOREIGN KEY (id_variation) - REFERENCES Shop_Variation(id_variation) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Variation_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - - --- File: 1214_tbl_Shop_Variation_Temp.sql - --- Variations Temp - --- DROP TABLE partsltd_prod.Shop_Variation_Temp; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Variation_Temp'; - -CREATE TABLE Shop_Variation_Temp ( - id_temp INT NOT NULL PRIMARY KEY AUTO_INCREMENT - , id_variation INT NOT NULL - , id_type INT NOT NULL - , id_unit_measurement INT NULL - , count_unit_measurement INT NULL - , code VARCHAR(50) - , name VARCHAR(255) - , active BIT - , display_order INT NOT NULL - , created_on DATETIME - , created_by INT - , guid BINARY(36) -); - - --- File: 1215_tbl_Shop_Product_Permutation_Variation_Link.sql - --- Product Permutation Variation Link - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Permutation_Variation_Link'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Permutation_Variation_Link ( - id_link INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_permutation INT NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_Variation_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation) - ON UPDATE RESTRICT, - id_variation INT NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_Variation_Link_id_variation - FOREIGN KEY (id_variation) - REFERENCES Shop_Variation(id_variation) - ON UPDATE RESTRICT, - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Product_Permutation_Variation_Link_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - - --- File: 1216_tbl_Shop_Product_Permutation_Variation_Link_Audit.sql - --- Product Permutation Variation Link Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Permutation_Variation_Link_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Permutation_Variation_Link_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_link INT NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_Variation_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Product_Permutation_Variation_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_Variation_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) - ON UPDATE RESTRICT -); - --- File: 1217_tbl_Shop_Product_Permutation_Variation_Link_Temp.sql - --- Product Permutation Variation Link - --- DROP TABLE IF EXISTS Shop_Product_Permutation_Variation_Link_Temp; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Permutation_Variation_Link_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Permutation_Variation_Link_Temp ( - id_temp INT NOT NULL AUTO_INCREMENT PRIMARY KEY - , id_link INT NOT NULL - , id_permutation INT NOT NULL - , id_variation INT NOT NULL - , active BIT NOT NULL - , display_order INT NOT NULL - , GUID BINARY(36) NOT NULL -); - - --- File: 1221_tbl_Shop_Product_Price.sql - --- Product Price - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Price'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Price ( - id_price INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_permutation INT NULL, - CONSTRAINT FK_Shop_Product_Price_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - id_currency INT NOT NULL, - CONSTRAINT FK_Shop_Product_Price_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency), - id_region_purchase INT NOT NULL, - CONSTRAINT FK_Shop_Product_Price_id_region_purchase - FOREIGN KEY (id_region_purchase) - REFERENCES Shop_Region(id_region), - price_local_VAT_incl FLOAT NULL, - price_local_VAT_excl FLOAT NULL, - id_stripe_price VARCHAR(200), - active BIT NOT NULL DEFAULT 1, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Product_Price_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - --- File: 1222_tbl_Shop_Product_Price_Audit.sql - --- Product Price Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Price_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Price_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_price INT NOT NULL, - CONSTRAINT FK_Shop_Product_Price_Audit_id_price - FOREIGN KEY (id_price) - REFERENCES Shop_Product_Price(id_price) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Product_Price_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - - --- File: 1223_tbl_Shop_Product_Price_Temp.sql - --- Product Price Temp - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Price_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Price_Temp ( - id_price INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_permutation INT NULL, - id_currency INT NOT NULL, - id_region_purchase INT NOT NULL, - price_local_VAT_incl FLOAT NULL, - price_local_VAT_excl FLOAT NULL, - id_stripe_price VARCHAR(200), - active BIT NOT NULL DEFAULT 1 -); - --- File: 1224_tbl_Shop_Product_Image.sql - --- Product Permutation Images - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Image'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Image ( - id_image INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_type_image INT NOT NULL, - CONSTRAINT FK_Shop_Product_Image_id_type_image - FOREIGN KEY (id_type_image) - REFERENCES Shop_Image_Type(id_type), - id_permutation INT NULL, - CONSTRAINT FK_Shop_Product_Image_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - url VARCHAR(255), - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Product_Image_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - --- File: 1225_tbl_Shop_Product_Image_Audit.sql - --- Product Image Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Image_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Image_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_image INT NOT NULL, - CONSTRAINT FK_Shop_Product_Image_Audit_id_image - FOREIGN KEY (id_image) - REFERENCES Shop_Product_Image(id_image), - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Product_Image_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - --- File: 1227_tbl_Shop_Delivery_Option.sql - --- Delivery Options - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Delivery_Option'; - -CREATE TABLE IF NOT EXISTS Shop_Delivery_Option ( - id_option INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - code VARCHAR(50) NOT NULL, - name VARCHAR(100) NOT NULL, - description VARCHAR(4000), - latency_delivery_min INT NOT NULL, - latency_delivery_max INT NOT NULL, - /* - quantity_min INT NOT NULL, - quantity_max INT NOT NULL, - */ - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Delivery_Option_Type_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - - --- File: 1228_tbl_Shop_Delivery_Option_Audit.sql - --- Delivery Option Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Delivery_Option_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Delivery_Option_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_option INT NOT NULL, - CONSTRAINT FK_Shop_Delivery_Option_Audit_id_option - FOREIGN KEY (id_option) - REFERENCES Shop_Delivery_Option(id_option) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Delivery_Option_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - --- File: 1230_tbl_Shop_Product_Permutation_Delivery_Option_Link.sql - --- Delivery Option - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Permutation_Delivery_Option_Link'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Permutation_Delivery_Option_Link ( - id_link INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_product INT NOT NULL, - CONSTRAINT FK_Shop_Permutation_Delivery_Option_Link_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product) - ON UPDATE RESTRICT, - id_permutation INT, - CONSTRAINT FK_Shop_Permutation_Delivery_Option_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation) - ON UPDATE RESTRICT, - id_delivery_option INT NOT NULL, - CONSTRAINT FK_Shop_Permutation_Delivery_Option_Link_id_delivery_option - FOREIGN KEY (id_delivery_option) - REFERENCES Shop_Delivery_Option(id_option) - ON UPDATE RESTRICT, - id_region INT NOT NULL, - CONSTRAINT FK_Shop_Permutation_Delivery_Option_Link_id_region - FOREIGN KEY (id_region) - REFERENCES Shop_Region(id_region) - ON UPDATE RESTRICT, - id_currency INT NOT NULL, - CONSTRAINT FK_Shop_Permutation_Delivery_Option_Link_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency) - ON UPDATE RESTRICT, - price_local FLOAT NOT NULL, - quantity_min FLOAT NULL, - quantity_max FLOAT NULL, - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Permutation_Delivery_Option_Link_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - --- File: 1231_tbl_Shop_Product_Permutation_Delivery_Option_Link_Audit.sql - --- Delivery Option Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Permutation_Delivery_Option_Link_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Permutation_Delivery_Option_Link_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_link INT NOT NULL, - CONSTRAINT FK_Shop_Permutation_Delivery_Option_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Product_Permutation_Delivery_Option_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(64) NOT NULL, - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Permutation_Delivery_Option_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - --- File: 1233_tbl_Shop_Discount.sql - --- Discounts - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Discount'; - -CREATE TABLE Shop_Discount ( - id_discount INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - code VARCHAR(50) NOT NULL, - name VARCHAR(200) NOT NULL, - id_product INT NOT NULL, - CONSTRAINT FK_Shop_Discount_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - id_permutation INT, - CONSTRAINT FK_Shop_Discount_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation) - ON UPDATE RESTRICT, - /* - id_delivery_region INT, - CONSTRAINT FK_Shop_Discount_id_delivery_region - FOREIGN KEY (id_delivery_region) - REFERENCES Shop_Delivery_Region(id_region) - ON UPDATE RESTRICT, - id_currency INT, - CONSTRAINT FK_Shop_Discount_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency) - ON UPDATE RESTRICT, - */ - multiplier FLOAT NOT NULL DEFAULT 1 CHECK (multiplier > 0), - subtractor FLOAT NOT NULL DEFAULT 0, - apply_multiplier_first BIT DEFAULT 1, - quantity_min FLOAT NOT NULL DEFAULT 0, - quantity_max FLOAT NOT NULL, - date_start DATETIME NOT NULL, - date_end DATETIME NOT NULL, - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Discount_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - - --- File: 1234_tbl_Shop_Discount_Audit.sql - --- Discount Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Discount_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Discount_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_discount INT NOT NULL, - CONSTRAINT FK_Shop_Discount_Audit_id_discount - FOREIGN KEY (id_discount) - REFERENCES Shop_Discount(id_discount) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Discount_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) - ON UPDATE RESTRICT -); - --- File: 1236_tbl_Shop_Discount_Region_Currency_Link.sql - --- Discount Region Currency Link - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Discount_Region_Currency_Link'; - -CREATE TABLE IF NOT EXISTS Shop_Discount_Region_Currency_Link ( - id_link INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_discount INT NOT NULL, - CONSTRAINT FK_Shop_Discount_Region_Currency_Link_id_discount - FOREIGN KEY (id_discount) - REFERENCES Shop_Discount(id_discount) - ON UPDATE RESTRICT, - id_region INT NOT NULL, - CONSTRAINT FK_Shop_Discount_Region_Currency_Link_id_region - FOREIGN KEY (id_region) - REFERENCES Shop_Region(id_region) - ON UPDATE RESTRICT, - id_currency INT NOT NULL, - CONSTRAINT FK_Shop_Discount_Region_Currency_Link_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency) - ON UPDATE RESTRICT, - active BIT NOT NULL DEFAULT 1, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Discount_Region_Currency_Link_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - --- File: 1237_tbl_Shop_Discount_Region_Currency_Link_Audit.sql - --- Discount Region Currency Link Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Discount_Region_Currency_Link_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Discount_Region_Currency_Link_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_link INT NOT NULL, - CONSTRAINT FK_Shop_Discount_Region_Currency_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Discount_Region_Currency_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Discount_Region_Currency_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) - ON UPDATE RESTRICT -); - --- File: 1300_tbl_Shop_Permission_Group.sql - --- Permission Groups - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Permission_Group'; - -CREATE TABLE IF NOT EXISTS Shop_Permission_Group ( - id_group INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - code VARCHAR(50), - name VARCHAR(255), - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Permission_Group_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - ON UPDATE RESTRICT -); - --- File: 1301_tbl_Shop_Permission_Group_Audit.sql - --- Permission Group Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Permission_Group_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Permission_Group_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_group INT NOT NULL, - CONSTRAINT FK_Shop_Permission_Group_Audit_id_group - FOREIGN KEY (id_group) - REFERENCES Shop_Permission_Group(id_group) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Permission_Group_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - ON UPDATE RESTRICT -); - --- File: 1303_tbl_Shop_Permission.sql - --- Permissions - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Permission'; - -CREATE TABLE IF NOT EXISTS Shop_Permission ( - id_permission INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - code VARCHAR(50), - name VARCHAR(255), - id_permission_group INT NOT NULL, - CONSTRAINT FK_Shop_Permission_id_permission_group - FOREIGN KEY (id_permission_group) - REFERENCES Shop_Permission_Group(id_group) - ON UPDATE RESTRICT, - id_access_level_required INT NOT NULL, - CONSTRAINT FK_Shop_Permission_id_access_level_required - FOREIGN KEY (id_access_level_required) - REFERENCES Shop_Access_Level(id_access_level), - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Permission_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); - --- File: 1304_tbl_Shop_Permission_Audit.sql - --- Permission Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Permission_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Permission_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_permission INT NOT NULL, - CONSTRAINT FK_Shop_Permission_Audit_id_permission - FOREIGN KEY (id_permission) - REFERENCES Shop_Permission(id_permission) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Permission_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - ON UPDATE RESTRICT -); - --- File: 1306_tbl_Shop_Role.sql - --- Roles - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Role'; - -CREATE TABLE IF NOT EXISTS Shop_Role ( - id_role INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - code VARCHAR(50), - name VARCHAR(255), - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Role_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); - --- File: 1307_tbl_Shop_Role_Audit.sql - --- Role Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Role_Audit'; - -CREATE TABLE Shop_Role_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_role INT NOT NULL, - CONSTRAINT FK_Shop_Role_Audit_id_role - FOREIGN KEY (id_role) - REFERENCES Shop_Role(id_role) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Role_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - ON UPDATE RESTRICT -); - --- File: 1309_tbl_Shop_Role_Permission_Link.sql - --- Role Permission link - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Role_Permission_Link'; - -CREATE TABLE IF NOT EXISTS Shop_Role_Permission_Link ( - id_link INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_role INT, - CONSTRAINT FK_Shop_Role_Permission_Link_id_role - FOREIGN KEY (id_role) - REFERENCES Shop_Role(id_role) - ON UPDATE RESTRICT, - id_permission INT, - CONSTRAINT FK_Shop_Role_Permission_Link_id_permission - FOREIGN KEY (id_permission) - REFERENCES Shop_Permission(id_permission) - ON UPDATE RESTRICT, - id_access_level INT, - CONSTRAINT FK_Shop_Role_Permission_Link_id_access_level - FOREIGN KEY (id_access_level) - REFERENCES Shop_Access_Level(id_access_level), - active BIT NOT NULL DEFAULT 1, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Role_Permission_Link_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); - --- File: 1310_tbl_Shop_Role_Permission_Link_Audit.sql - --- Role Permission link Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Role_Permission_Link_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Role_Permission_Link_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_link INT NOT NULL, - CONSTRAINT FK_Shop_Role_Permission_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Role_Permission_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Role_Permission_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); - --- File: 1312_tbl_Shop_User.sql - --- Users - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User'; - -CREATE TABLE IF NOT EXISTS Shop_User ( - id_user INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_user_auth0 VARCHAR(200) NOT NULL, - firstname VARCHAR(255) NULL, - surname VARCHAR(255) NULL, - email VARCHAR(254) NULL, - is_email_verified BIT NOT NULL DEFAULT 0, - is_super_user BIT NOT NULL DEFAULT 0, - id_currency_default INT NULL, - id_region_default INT NULL, - is_included_VAT_default BIT NOT NULL DEFAULT 1, - active BIT NOT NULL DEFAULT 1, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_User_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); - - --- File: 1313_tbl_Shop_User_Audit.sql - --- User Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_User_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_user INT NOT NULL, - CONSTRAINT FK_Shop_User_Audit_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_User_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - ON UPDATE RESTRICT -); - --- File: 1314_tbl_Shop_User_Temp.sql - --- Users Temp - --- DROP TABLE IF EXISTS Shop_User_Temp; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_User_Temp ( - id_temp INT NOT NULL AUTO_INCREMENT PRIMARY KEY +CREATE TABLE IF NOT EXISTS partsltd_prod.PH_User_Audit ( + id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY , id_user INT NOT NULL - , id_user_auth0 VARCHAR(200) NOT NULL + , CONSTRAINT FK_PH_User_Audit_id_user + FOREIGN KEY (id_user) + REFERENCES partsltd_prod.PH_User(id_user) + , name_field VARCHAR(50) NOT NULL + , value_prev VARCHAR(500) + , value_new VARCHAR(500) + , id_change_set INT NOT NULL + , CONSTRAINT FK_PH_User_Audit_id_change_set + FOREIGN KEY (id_change_set) + REFERENCES partsltd_prod.PH_User_Change_Set(id_change_set) +); +USE partsltd_prod; + +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'PH_User_Temp' +; + +CREATE TABLE IF NOT EXISTS partsltd_prod.PH_User_Temp ( + id_temp INT NOT NULL AUTO_INCREMENT PRIMARY KEY + , id_user INT NOT NULL + , id_user_auth0 VARCHAR(200) , firstname VARCHAR(255) , surname VARCHAR(255) , email VARCHAR(254) , is_email_verified BIT , is_super_user BIT - , id_currency_default INT - , id_region_default INT - , is_included_VAT_default BIT , active BIT , guid BINARY(36) NOT NULL ); +USE partsltd_prod; --- File: 1315_tbl_Shop_User_Role_Link.sql +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'PH_Role' +; --- User Role link +CREATE TABLE IF NOT EXISTS partsltd_prod.PH_Role ( + id_role INT NOT NULL AUTO_INCREMENT PRIMARY KEY + , code VARCHAR(50) + , name VARCHAR(255) + , display_order INT NOT NULL + , active BIT NOT NULL DEFAULT 1 + , created_on DATETIME + , id_user_created_by INT + , CONSTRAINT FK_PH_Role_id_user_created_by + FOREIGN KEY (id_user_created_by) + REFERENCES partsltd_prod.PH_User(id_user) + , id_change_set INT + , CONSTRAINT FK_PH_Role_id_change_set + FOREIGN KEY (id_change_set) + REFERENCES partsltd_prod.PH_User_Change_Set(id_change_set) +); +USE partsltd_prod; +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'PH_Role_Audit' +; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Role_Link'; - -CREATE TABLE IF NOT EXISTS Shop_User_Role_Link ( - id_link INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_user INT NOT NULL, - CONSTRAINT FK_Shop_User_Role_Link_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user) - ON UPDATE RESTRICT, - id_role INT NOT NULL, - CONSTRAINT FK_Shop_User_Role_Link_id_role +CREATE TABLE IF NOT EXISTS partsltd_prod.PH_Role_Audit ( + id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY + , id_role INT NOT NULL + , CONSTRAINT FK_PH_Role_Audit_id_role FOREIGN KEY (id_role) - REFERENCES Shop_Role(id_role), - active BIT NOT NULL DEFAULT 1, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_User_Role_Link_id_change_set + REFERENCES partsltd_prod.PH_Role(id_role) + , name_field VARCHAR(50) NOT NULL + , value_prev VARCHAR(500) + , value_new VARCHAR(500) + , id_change_set INT NOT NULL + , CONSTRAINT FK_PH_Role_Audit_id_change_set FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) + REFERENCES partsltd_prod.PH_User_Change_Set(id_change_set) ); +USE partsltd_prod; --- File: 1316_tbl_Shop_User_Role_Link_Audit.sql +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'PH_Role_Permission_Link' +; --- User Role Link Audits +CREATE TABLE IF NOT EXISTS partsltd_prod.PH_Role_Permission_Link ( + id_link INT NOT NULL AUTO_INCREMENT PRIMARY KEY + , id_role INT NOT NULL + , CONSTRAINT FK_PH_Role_Permission_Link_id_role + FOREIGN KEY (id_role) + REFERENCES partsltd_prod.PH_Role(id_role) + , id_permission INT NOT NULL + , CONSTRAINT FK_PH_Role_Permission_Link_id_permission + FOREIGN KEY (id_permission) + REFERENCES partsltd_prod.PH_Permission(id_permission) + , id_access_level INT NOT NULL + , CONSTRAINT FK_PH_Role_Permission_Link_id_access_level + FOREIGN KEY (id_access_level) + REFERENCES partsltd_prod.PH_Access_Level(id_access_level) + , active BIT NOT NULL DEFAULT 1 + , created_on DATETIME + , id_user_created_by INT + , CONSTRAINT FK_PH_Role_Permission_Link_id_user_created_by + FOREIGN KEY (id_user_created_by) + REFERENCES partsltd_prod.PH_User(id_user) + , id_change_set INT + , CONSTRAINT FK_PH_Role_Permission_Link_id_change_set + FOREIGN KEY (id_change_set) + REFERENCES partsltd_prod.PH_User_Change_Set(id_change_set) +); +USE partsltd_prod; +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'PH_Role_Permission_Link_Audit'; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Role_Link_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_User_Role_Link_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_link INT NOT NULL, - CONSTRAINT FK_Shop_User_Role_Link_Audit_id_link +CREATE TABLE IF NOT EXISTS partsltd_prod.PH_Role_Permission_Link_Audit ( + id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY + , id_link INT NOT NULL + , CONSTRAINT FK_PH_Role_Permission_Link_Audit_id_link FOREIGN KEY (id_link) - REFERENCES Shop_User_Role_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_User_Role_Link_Audit_id_change_set + REFERENCES partsltd_prod.PH_Role_Permission_Link(id_link) + , name_field VARCHAR(50) NOT NULL + , value_prev VARCHAR(500) + , value_new VARCHAR(500) + , id_change_set INT NOT NULL + , CONSTRAINT FK_PH_Role_Permission_Link_Audit_id_change_set FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) + REFERENCES partsltd_prod.PH_User_Change_Set(id_change_set) ); +USE partsltd_prod; +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'PH_User_Role_Link' +; --- File: 1318_tbl_Shop_User_Address.sql - --- User Addresses - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Address'; - -CREATE TABLE Shop_User_Address ( - id_user_address INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_user INT NOT NULL, - CONSTRAINT FK_Shop_Address_id_user +CREATE TABLE IF NOT EXISTS partsltd_prod.PH_User_Role_Link ( + id_link INT NOT NULL AUTO_INCREMENT PRIMARY KEY + , id_user INT NOT NULL + , CONSTRAINT FK_PH_User_Role_Link_id_user FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user) - ON UPDATE RESTRICT, - -- region VARCHAR(100) NOT NULL, - id_region INT NOT NULL, - name_full VARCHAR(255) NOT NULL, - phone_number VARCHAR(20) NOT NULL, - postcode VARCHAR(20) NOT NULL, - address_line_1 VARCHAR(256) NOT NULL, - address_line_2 VARCHAR(256) NOT NULL, - city VARCHAR(256) NOT NULL, - county VARCHAR(256) NOT NULL, - active BIT NOT NULL DEFAULT 1, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_User_Address_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); - --- File: 1319_tbl_Shop_User_Address_Audit.sql - --- Address Audits - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Address_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_User_Address_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_user_address INT NOT NULL, - CONSTRAINT FK_Shop_User_Address_Audit_id_address - FOREIGN KEY (id_user_address) - REFERENCES Shop_User_Address(id_user_address) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_User_Address_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - ON UPDATE RESTRICT -); - --- File: 1321_tbl_Shop_User_Basket.sql - --- User Basket (Product Link) - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Basket'; - -CREATE TABLE IF NOT EXISTS Shop_User_Basket ( - id_item INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_user INT NOT NULL, - CONSTRAINT FK_Shop_User_Basket_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user) - ON UPDATE RESTRICT, - id_product INT NOT NULL, - CONSTRAINT FK_Shop_User_Basket_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product) - ON UPDATE RESTRICT, - id_permutation INT, - CONSTRAINT FK_Shop_User_Basket_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation) - ON UPDATE RESTRICT, - quantity INT NOT NULL, - active BIT NOT NULL DEFAULT 1, - created_on DATETIME, - created_by INT, - id_change_set_user INT, - CONSTRAINT FK_Shop_User_Basket_id_change_set_user - FOREIGN KEY (id_change_set_user) - REFERENCES Shop_User_Change_Set(id_change_set) - /* - id_change_set_product INT, - CONSTRAINT FK_Shop_User_Basket_id_change_set_product - FOREIGN KEY (id_change_set_product) - REFERENCES Shop_Product_Change_Set(id_change_set) - */ -); - - --- File: 1322_tbl_Shop_User_Basket_Audit.sql - --- Product Basket Audits - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Basket_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_User_Basket_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_item INT NOT NULL, - CONSTRAINT FK_Shop_User_Basket_Audit_id_link - FOREIGN KEY (id_item) - REFERENCES Shop_User_Basket(id_item) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set_user INT, - CONSTRAINT FK_Shop_User_Basket_Audit_id_change_set_user - FOREIGN KEY (id_change_set_user) - REFERENCES Shop_User_Change_Set(id_change_set) - /* - id_change_set_product INT, - CONSTRAINT FK_Shop_User_Basket_Audit_id_change_set_product - FOREIGN KEY (id_change_set_product) - REFERENCES Shop_Product_Change_Set(id_change_set) - */ -); - - --- File: 1397_tbl_Shop_Order_Status.sql - --- User Order Types - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Order_Status'; - -CREATE TABLE IF NOT EXISTS Shop_User_Order_Status ( - id_status INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - code VARCHAR(50), - name VARCHAR(255), - name_plural VARCHAR(256), - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_User_Order_Status_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); - - --- File: 1398_tbl_Shop_Order_Status_Audit.sql - --- Order Type Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Order_Status_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_User_Order_Status_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_status INT NOT NULL, - CONSTRAINT FK_Shop_User_Order_Status_Audit_id_status - FOREIGN KEY (id_status) - REFERENCES Shop_User_Order_Status(id_status) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_User_Order_Status_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - --- File: 1400_tbl_Shop_Supplier.sql - --- Supplier - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Supplier'; - -CREATE TABLE IF NOT EXISTS Shop_Supplier ( - id_supplier INT NOT NULL AUTO_INCREMENT PRIMARY KEY - , name_company VARCHAR(255) NOT NULL - , name_contact VARCHAR(255) NULL - , department_contact VARCHAR(255) NULL - /* - id_address INT NOT NULL, - CONSTRAINT FK_Shop_Supplier_id_address - FOREIGN KEY (id_address) - REFERENCES Shop_Address(id_address), - */ - , phone_number VARCHAR(50) NULL - , fax VARCHAR(50) NULL - , email VARCHAR(255) NOT NULL - , website VARCHAR(255) NULL - , id_currency INT NOT NULL - , CONSTRAINT FK_Shop_Supplier_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency) + REFERENCES partsltd_prod.PH_User(id_user) + , id_role INT NOT NULL + , CONSTRAINT FK_PH_User_Role_Link_id_role + FOREIGN KEY (id_role) + REFERENCES partsltd_prod.PH_Role(id_role) , active BIT NOT NULL DEFAULT 1 , created_on DATETIME - , created_by INT + , id_user_created_by INT + , CONSTRAINT FK_PH_User_Role_Link_id_user_created_by + FOREIGN KEY (id_user_created_by) + REFERENCES partsltd_prod.PH_User(id_user) , id_change_set INT - , CONSTRAINT FK_Shop_Supplier_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - , id_supplier_temp INT NOT NULL -); - - --- File: 1401_tbl_Shop_Supplier_Audit.sql - --- Supplier Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Supplier_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Supplier_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_supplier INT NOT NULL, - CONSTRAINT FK_Shop_Supplier_Audit_id_supplier - FOREIGN KEY (id_supplier) - REFERENCES Shop_Supplier(id_supplier) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Supplier_Audit_id_change_set + , CONSTRAINT FK_PH_User_Role_Link_id_change_set FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) + REFERENCES partsltd_prod.PH_User_Change_Set(id_change_set) ); +USE partsltd_prod; +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'PH_User_Role_Link_Audit' +; --- File: 1402_tbl_Shop_Supplier_Temp.sql - --- Supplier Staging - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Supplier_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Supplier_Temp ( - id_temp INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_supplier INT NOT NULL, - name_company VARCHAR(255) NOT NULL, - name_contact VARCHAR(255) NULL, - department_contact VARCHAR(255) NULL, - -- id_address INT NOT NULL, - phone_number VARCHAR(50) NULL, - fax VARCHAR(50) NULL, - email VARCHAR(255) NOT NULL, - website VARCHAR(255) NULL, - id_currency INT NOT NULL, - active BIT NULL, - GUID BINARY(36) NOT NULL -); - - --- File: 1403_tbl_Shop_Supplier_Address.sql - --- Supplier Addresses - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Supplier_Address'; - -CREATE TABLE Shop_Supplier_Address ( - id_address INT NOT NULL AUTO_INCREMENT PRIMARY KEY - , id_supplier INT NOT NULL - , CONSTRAINT FK_Shop_Supplier_Address_id_supplier - FOREIGN KEY (id_supplier) - REFERENCES partsltd_prod.Shop_Supplier(id_supplier) - ON UPDATE RESTRICT - , id_region INT NOT NULL - , CONSTRAINT FK_Shop_Supplier_Address_id_region - FOREIGN KEY (id_region) - REFERENCES partsltd_prod.Shop_Region(id_region) - , postcode VARCHAR(20) NOT NULL - , address_line_1 VARCHAR(256) NOT NULL - , address_line_2 VARCHAR(256) NOT NULL - , city VARCHAR(256) NOT NULL - , county VARCHAR(256) NOT NULL - , active BIT NOT NULL DEFAULT 1 - , created_on DATETIME - , created_by INT - , id_change_set INT - , CONSTRAINT FK_Shop_Supplier_Address_id_change_set +CREATE TABLE IF NOT EXISTS partsltd_prod.PH_User_Role_Link_Audit ( + id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY + , id_link INT NOT NULL + , CONSTRAINT FK_PH_User_Role_Link_Audit_id_link + FOREIGN KEY (id_link) + REFERENCES partsltd_prod.PH_User_Role_Link(id_link) + , name_field VARCHAR(50) NOT NULL + , value_prev VARCHAR(500) + , value_new VARCHAR(500) + , id_change_set INT NOT NULL + , CONSTRAINT FK_PH_User_Role_Link_Audit_id_change_set FOREIGN KEY (id_change_set) - REFERENCES partsltd_prod.Shop_User_Change_Set(id_change_set) + REFERENCES partsltd_prod.PH_User_Change_Set(id_change_set) ); --- File: 1404_tbl_Shop_Supplier_Address_Audit.sql +USE partsltd_prod; --- Supplier Address Audits +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'PH_Calc_User_Temp' +; -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Supplier_Address_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Supplier_Address_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_address INT NOT NULL, - CONSTRAINT FK_Shop_Supplier_Address_Audit_id_address - FOREIGN KEY (id_address) - REFERENCES Shop_Supplier_Address(id_address) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Supplier_Address_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - ON UPDATE RESTRICT +CREATE TABLE IF NOT EXISTS partsltd_prod.PH_Calc_User_Temp ( + guid BINARY(36) NOT NULL + , id_user INT + , id_permission_required INT NOT NULL + , CONSTRAINT FK_PH_Calc_User_Temp_id_permission_required + FOREIGN KEY (id_permission_required) + REFERENCES partsltd_prod.PH_Permission (id_permission) + , priority_access_level_required INT NOT NULL + , is_super_user BIT + , priority_access_level_user INT + , has_access BIT ); +USE partsltd_prod; --- File: 1405_tbl_Shop_Supplier_Address_Temp.sql +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'PH_Contact_Form_Change_Set' +; --- Supplier Addresses Staging - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Supplier_Address_Temp'; - -CREATE TABLE Shop_Supplier_Address_Temp ( - id_address INT NOT NULL AUTO_INCREMENT PRIMARY KEY - , id_supplier INT NOT NULL - , id_region INT NOT NULL - , postcode VARCHAR(20) NOT NULL - , address_line_1 VARCHAR(256) NOT NULL - , address_line_2 VARCHAR(256) NOT NULL - , city VARCHAR(256) NOT NULL - , county VARCHAR(256) NOT NULL - , active BIT NOT NULL DEFAULT 1 - , GUID BINARY(36) NOT NULL +CREATE TABLE IF NOT EXISTS partsltd_prod.PH_Contact_Form_Change_Set ( + id_change_set INT NOT NULL AUTO_INCREMENT PRIMARY KEY + , comment VARCHAR(500) + , updated_last_on DATETIME + , id_user_updated_last_by INT + , CONSTRAINT FK_PH_Role_id_user_updated_last_by + FOREIGN KEY (id_user_updated_last_by) + REFERENCES partsltd_prod.PH_User(id_user) ); - --- File: 1409_tbl_Shop_Supplier_Purchase_Order.sql - --- Supplier Purchase Order - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Supplier_Purchase_Order'; - -CREATE TABLE IF NOT EXISTS Shop_Supplier_Purchase_Order ( - id_order INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_order_temp INT NULL, - id_supplier_ordered INT NOT NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_id_supplier_ordered - FOREIGN KEY (id_supplier_ordered) - REFERENCES Shop_Supplier(id_supplier), - /* - id_supplier_fulfilled INT NOT NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_id_supplier_fulfilled - FOREIGN KEY (id_supplier_fulfilled) - REFERENCES Shop_Supplier(id_supplier), - */ - id_currency_cost INT NOT NULL, - cost_total_local_VAT_excl FLOAT NOT NULL, - cost_total_local_VAT_incl FLOAT NOT NULL, - /* - latency_delivery INT NOT NULL, - quantity_ordered FLOAT NOT NULL, - id_unit_quantity INT NOT NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit), - -- quantity_received INT NULL, - display_order INT NOT NULL, - */ - active BIT NOT NULL DEFAULT 1, - created_on DATETIME, - created_by INT, - updated_last_on DATETIME NULL, - created_last_by VARCHAR(100) NULL, - id_change_set INT NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); - - --- File: 1410_tbl_Shop_Supplier_Purchase_Order_Audit.sql - --- Supplier Purchase Order Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Supplier_Purchase_Order_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Supplier_Purchase_Order_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_order INT NOT NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_Audit_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Supplier_Purchase_Order(id_order) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); - - --- File: 1411_tbl_Shop_Supplier_Purchase_Order_Temp.sql - --- Supplier Purchase Order Staging - -DROP TABLE IF EXISTS Shop_Supplier_Purchase_Order_Temp; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Supplier_Purchase_Order_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Supplier_Purchase_Order_Temp ( - id_temp INT NOT NULL AUTO_INCREMENT PRIMARY KEY - , id_order INT NOT NULL - , id_supplier_ordered INT NOT NULL - , id_currency_cost INT NOT NULL - , active BIT NULL - , GUID BINARY(36) NOT NULL -); - - --- File: 1412_tbl_Shop_Manufacturing_Purchase_Order.sql - --- Manufacturing Purchase Order - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Manufacturing_Purchase_Order'; - -CREATE TABLE IF NOT EXISTS Shop_Manufacturing_Purchase_Order ( - id_order INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_order_temp INT NULL, - /* - cost_total_local FLOAT NOT NULL, - id_currency_cost INT NOT NULL, - */ - id_currency INT NOT NULL, - CONSTRAINT FK_Manufacturing_Purchase_Order_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency), - cost_total_local_VAT_excl FLOAT NULL, - cost_total_local_VAT_incl FLOAT NULL, - price_total_local_VAT_excl FLOAT NULL, - price_total_local_VAT_incl FLOAT NULL, - /* - latency_delivery INT NOT NULL, - quantity_ordered FLOAT NOT NULL, - id_unit_quantity INT NOT NULL, - CONSTRAINT FK_Shop_Manufacturing_Purchase_Order_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit), - quantity_received INT NULL, - display_order INT NOT NULL, - */ - active BIT NOT NULL DEFAULT 1, - created_on DATETIME, - created_by INT, - updated_last_on DATETIME NULL, - created_last_by VARCHAR(100) NULL, - id_change_set INT NULL, - CONSTRAINT FK_Shop_Manufacturing_Purchase_Order_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); - - --- File: 1413_tbl_Shop_Manufacturing_Purchase_Order_Audit.sql - --- Manufacturing Purchase Order Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Manufacturing_Purchase_Order_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Manufacturing_Purchase_Order_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_order INT NOT NULL, - CONSTRAINT FK_Shop_Manufacturing_Purchase_Order_Audit_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Manufacturing_Purchase_Order(id_order) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Manufacturing_Purchase_Order_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); - - --- File: 1414_tbl_Shop_Manufacturing_Purchase_Order_Temp.sql - --- Manufacturing Purchase Order Temp - --- DROP TABLE Shop_Manufacturing_Purchase_Order_Temp - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Manufacturing_Purchase_Order_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Manufacturing_Purchase_Order_Temp ( - id_temp INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_order INT NOT NULL, - /* - cost_total_local FLOAT NOT NULL, - */ - id_currency INT NOT NULL, - cost_total_local_VAT_excl FLOAT NULL, - cost_total_local_VAT_incl FLOAT NULL, - price_total_local_VAT_excl FLOAT NULL, - price_total_local_VAT_incl FLOAT NULL, - /* - latency_delivery INT NOT NULL, - quantity_ordered FLOAT NOT NULL, - id_unit_quantity INT NOT NULL, - CONSTRAINT FK_Shop_Manufacturing_Purchase_Order_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit), - quantity_received INT NULL, - display_order INT NOT NULL, - */ - active BIT NOT NULL DEFAULT 1, - GUID BINARY(36) NOT NULL -); - - --- File: 1415_tbl_Shop_Customer.sql --- Customer - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Customer'; - -CREATE TABLE IF NOT EXISTS Shop_Customer ( - id_customer INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - name_company VARCHAR(255) NOT NULL, - name_contact VARCHAR(255) NULL, - department_contact VARCHAR(255) NULL, - id_address INT NOT NULL, - CONSTRAINT FK_Shop_Customer_id_address - FOREIGN KEY (id_address) - REFERENCES Shop_Address(id_address), - phone_number VARCHAR(50) NULL, - email VARCHAR(255) NOT NULL, - id_currency INT NOT NULL, - CONSTRAINT FK_Shop_Customer_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency), - active BIT NOT NULL DEFAULT 1, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Customer_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); - - --- File: 1416_tbl_Shop_Customer_Audit.sql - --- Customer Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Customer_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Customer_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_customer INT NOT NULL, - CONSTRAINT FK_Shop_Customer_Audit_id_customer - FOREIGN KEY (id_customer) - REFERENCES Shop_Customer(id_customer) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Customer_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); - - --- File: 1418_tbl_Shop_Customer_Sales_Order.sql - --- Customer Sales Purchase Order - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Customer_Sales_Order'; - -CREATE TABLE IF NOT EXISTS Shop_Customer_Sales_Order ( - id_order INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_customer INT NOT NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_id_customer - FOREIGN KEY (id_customer) - REFERENCES Shop_Customer(id_customer), - price_total_local FLOAT NOT NULL, - id_currency_price INT NOT NULL, - /* - latency_delivery INT NOT NULL, - quantity_ordered FLOAT NOT NULL, - id_unit_quantity INT NOT NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit), - quantity_received INT NULL, - display_order INT NOT NULL, - */ - active BIT NOT NULL DEFAULT 1, - created_on DATETIME, - created_by INT, - updated_last_on DATETIME NULL, - created_last_by VARCHAR(100) NULL, - id_change_set INT NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); - - --- File: 1419_tbl_Shop_Customer_Sales_Order_Audit.sql - --- Customer Sales Order Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Customer_Sales_Order_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Customer_Sales_Order_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_order INT NOT NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_Audit_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Customer_Sales_Order(id_order) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); - - --- File: 1421_tbl_Shop_Stock_Item.sql - --- Stock Stock Item - --- DROP TABLE IF EXISTS Shop_Stock_Item_Audit; --- DROP TABLE IF EXISTS Shop_Stock_Item; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Stock_Item'; - -CREATE TABLE IF NOT EXISTS Shop_Stock_Item ( - id_stock INT NOT NULL AUTO_INCREMENT PRIMARY KEY - , id_permutation INT NOT NULL - , CONSTRAINT FK_Shop_Stock_Item_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES partsltd_prod.Shop_Product_Permutation(id_permutation) - , id_supplier_purchase_order INT NULL - , CONSTRAINT FK_Shop_Stock_Item_id_supplier_purchase_order - FOREIGN KEY (id_supplier_purchase_order) - REFERENCES partsltd_prod.Shop_Supplier_Purchase_Order(id_order) - , id_manufacturing_purchase_order INT NULL - , CONSTRAINT FK_Shop_Stock_Item_id_manufacturing_purchase_order - FOREIGN KEY (id_manufacturing_purchase_order) - REFERENCES partsltd_prod.Shop_Manufacturing_Purchase_Order(id_order) - , id_customer_sales_order INT NULL - , CONSTRAINT FK_Shop_Stock_Item_id_customer_sales_order - FOREIGN KEY (id_customer_sales_order) - REFERENCES partsltd_prod.Shop_Customer_Sales_Order(id_order) - , date_purchased DATETIME NOT NULL - , date_received DATETIME - , id_location_storage INT NOT NULL - , CONSTRAINT FK_Shop_Stock_Item_id_location_storage - FOREIGN KEY (id_location_storage) - REFERENCES partsltd_prod.Shop_Storage_Location(id_location) - , id_currency_cost INT NOT NULL - , CONSTRAINT FK_Shop_Stock_Item_id_currency - FOREIGN KEY (id_currency_cost) - REFERENCES partsltd_prod.Shop_Currency(id_currency) - , cost_local_VAT_incl FLOAT - , cost_local_VAT_excl FLOAT - , is_sealed BIT NOT NULL DEFAULT 1 - , date_unsealed DATETIME - , date_expiration DATETIME NOT NULL - , is_consumed BIT NOT NULL DEFAULT 0 - , date_consumed DATETIME +USE partsltd_prod; + +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'PH_Contact_Form' +; + +CREATE TABLE IF NOT EXISTS partsltd_prod.PH_Contact_Form ( + id_contact_form INT NOT NULL AUTO_INCREMENT PRIMARY KEY + , email VARCHAR(255) NOT NULL + , name_contact VARCHAR(255) NOT NULL + , name_company VARCHAR(255) NOT NULL + , message TEXT NOT NULL + , receive_marketing_communications BIT NOT NULL DEFAULT 0 , active BIT NOT NULL DEFAULT 1 , created_on DATETIME - , created_by INT + , id_user_created_by INT + , CONSTRAINT FK_PH_Contact_Form_id_user_created_by + FOREIGN KEY (id_user_created_by) + REFERENCES partsltd_prod.PH_User(id_user) , id_change_set INT - , CONSTRAINT FK_Shop_Stock_Item_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES partsltd_prod.Shop_Product_Change_Set(id_change_set) + , CONSTRAINT FK_PH_Contact_Form_id_change_set + FOREIGN KEY (id_change_set) + REFERENCES partsltd_prod.PH_Contact_Form_Change_Set(id_change_set) ); +USE partsltd_prod; --- File: 1422_tbl_Shop_Stock_Item_Audit.sql +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'PH_Contact_Form_Audit' +; --- Stock Item Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Stock_Item_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Stock_Item_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_stock INT NOT NULL, - CONSTRAINT FK_Shop_Stock_Item_Audit_id_stock - FOREIGN KEY (id_stock) - REFERENCES Shop_Stock_Item(id_stock) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Stock_Item_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) - ON UPDATE RESTRICT +CREATE TABLE IF NOT EXISTS partsltd_prod.PH_Contact_Form_Audit ( + id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY + , id_contact_form INT NOT NULL + , CONSTRAINT FK_PH_Contact_Form_Audit_id_contact_form + FOREIGN KEY (id_contact_form) + REFERENCES partsltd_prod.PH_Contact_Form(id_contact_form) + , name_field VARCHAR(50) NOT NULL + , value_prev TEXT + , value_new TEXT + , id_change_set INT NOT NULL + , CONSTRAINT FK_PH_Contact_Form_Audit_id_change_set + FOREIGN KEY (id_change_set) + REFERENCES partsltd_prod.PH_Contact_Form_Change_Set(id_change_set) ); +USE partsltd_prod; --- File: 1423_tbl_Shop_Stock_Item_Temp.sql +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'PH_Contact_Form_Temp' +; --- Stock Stock Item Temp - -DROP TABLE IF EXISTS Shop_Stock_Item_Temp; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Stock_Item_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Stock_Item_Temp ( - id_stock INT NULL - -- , id_category INT NULL - , id_product INT NOT NULL - , id_permutation INT NULL - , id_pairs_variations VARCHAR(4000) NULL - , date_purchased DATETIME NOT NULL - , date_received DATETIME NULL - , id_location_storage INT NOT NULL - , id_currency_cost INT NOT NULL - , cost_local_VAT_incl FLOAT NOT NULL - , cost_local_VAT_excl FLOAT NOT NULL - , is_sealed BIT NOT NULL - , date_unsealed DATETIME NULL - , date_expiration DATETIME NULL - , is_consumed BIT NOT NULL - , date_consumed DATETIME NULL - , active BIT NOT NULL - , guid BINARY(36) NOT NULL +CREATE TABLE IF NOT EXISTS partsltd_prod.PH_Contact_Form_Temp ( + id_temp INT NOT NULL PRIMARY KEY AUTO_INCREMENT + , id_contact_form INT + , email VARCHAR(255) + , name_contact VARCHAR(255) + , name_company VARCHAR(255) + , message TEXT + , receive_marketing_communications BIT + , active BIT + , guid BINARY(36) ); +USE partsltd_prod; - --- File: 1424_tbl_Shop_Supplier_Purchase_Order_Product_Link.sql - --- Supplier Purchase Order Product Link - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Supplier_Purchase_Order_Product_Link'; - -CREATE TABLE IF NOT EXISTS Shop_Supplier_Purchase_Order_Product_Link ( - id_link INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_order INT NOT NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_Product_Link_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Supplier_Purchase_Order(id_order), - id_permutation INT NOT NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_Product_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - -- id_currency_cost INT NOT NULL, - id_unit_quantity INT NOT NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_Product_Link_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - quantity_ordered FLOAT NOT NULL, - quantity_received FLOAT NULL, - latency_delivery_days INT NOT NULL, - display_order INT NOT NULL, - active BIT NOT NULL, - cost_total_local_VAT_excl FLOAT NOT NULL, - cost_total_local_VAT_incl FLOAT NOT NULL, - cost_unit_local_VAT_excl FLOAT NOT NULL, - cost_unit_local_VAT_incl FLOAT NOT NULL, - created_on DATETIME, - created_by INT, - updated_last_on DATETIME NULL, - created_last_by VARCHAR(100) NULL, - id_change_set INT NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_Product_Link_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); - - --- File: 1425_tbl_Shop_Supplier_Purchase_Order_Product_Link_Audit.sql - --- Supplier Purchase Order Product Link Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Supplier_Purchase_Order_Product_Link_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Supplier_Purchase_Order_Product_Link_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_link INT NOT NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_Product_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Supplier_Purchase_Order_Product_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_Product_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); - - --- File: 1426_tbl_Shop_Supplier_Purchase_Order_Product_Link_Temp.sql - --- Supplier Purchase Order Product Link Temp - - - --- drop table Shop_Supplier_Purchase_Order_Product_Link_Temp; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Supplier_Purchase_Order_Product_Link_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Supplier_Purchase_Order_Product_Link_Temp ( - id_temp INT NOT NULL AUTO_INCREMENT PRIMARY KEY - , id_link INT NOT NULL - , id_order INT NOT NULL - , id_product INT NULL - , id_permutation INT NULL - , csv_list_variations VARCHAR(4000) NULL - , id_unit_quantity INT NOT NULL - , quantity_ordered FLOAT NOT NULL - , quantity_received FLOAT NULL - , latency_delivery_days INT NOT NULL - , display_order INT NOT NULL - , active BIT NOT NULL - , cost_total_local_VAT_excl FLOAT NOT NULL - , cost_total_local_VAT_incl FLOAT NOT NULL - , GUID BINARY(36) NOT NULL -); - - --- File: 1427_tbl_Shop_Manufacturing_Purchase_Order_Product_Link.sql - --- Manufacturing Purchase Order Product Link - --- DROP TABLE partsltd_prod.Shop_Manufacturing_Purchase_Order_Product_Link_Audit --- DROP TABLE partsltd_prod.Shop_Manufacturing_Purchase_Order_Product_Link - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Manufacturing_Purchase_Order_Product_Link'; - -CREATE TABLE IF NOT EXISTS Shop_Manufacturing_Purchase_Order_Product_Link ( - id_link INT NOT NULL AUTO_INCREMENT PRIMARY KEY - , id_order INT NOT NULL - , CONSTRAINT FK_Manufacturing_Purchase_Order_Product_Link_id_order - FOREIGN KEY (id_order) - REFERENCES partsltd_prod.Shop_Manufacturing_Purchase_Order(id_order) - , id_permutation INT NOT NULL - , CONSTRAINT FK_Manufacturing_Purchase_Order_Product_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES partsltd_prod.Shop_Product_Permutation(id_permutation) - , cost_unit_local_VAT_excl FLOAT NULL - , cost_unit_local_VAT_incl FLOAT NULL - , price_unit_local_VAT_excl FLOAT NULL - , price_unit_local_VAT_incl FLOAT NULL - , id_unit_quantity INT NOT NULL - , CONSTRAINT FK_Manufacturing_Purchase_Order_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES partsltd_prod.Shop_Unit_Measurement(id_unit_measurement) - , quantity_used FLOAT NULL - , quantity_produced FLOAT NULL - , id_unit_latency_manufacture INT NULL - , CONSTRAINT FK_MPO_id_unit_latency_manufacture - FOREIGN KEY (id_unit_latency_manufacture) - REFERENCES partsltd_prod.Shop_Unit_Measurement(id_unit_measurement) - , latency_manufacture INT NULL - , display_order INT NOT NULL - , active BIT NOT NULL - , created_on DATETIME - , created_by INT - , updated_last_on DATETIME NULL - , created_last_by VARCHAR(100) NULL - , id_change_set INT NULL - , CONSTRAINT FK_Manufacturing_Purchase_Order_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES partsltd_prod.Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); - - --- File: 1428_tbl_Shop_Manufacturing_Purchase_Order_Product_Link_Audit.sql - --- Manufacturing Purchase Order Product Link Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Manufacturing_Purchase_Order_Product_Link_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Manufacturing_Purchase_Order_Product_Link_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_link INT NOT NULL, - CONSTRAINT FK_Manufacturing_Purchase_Order_Product_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Manufacturing_Purchase_Order_Product_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Manufacturing_Purchase_Order_Product_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); - - --- File: 1429_tbl_Shop_Manufacturing_Purchase_Order_Product_Link_Temp.sql - --- Manufacturing Purchase Order Product Link Temp - --- DROP TABLE Shop_Manufacturing_Purchase_Order_Product_Link_Temp; --- SELECT * FROM Shop_Manufacturing_Purchase_Order_Product_Link_Temp; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Manufacturing_Purchase_Order_Product_Link_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Manufacturing_Purchase_Order_Product_Link_Temp ( - id_temp INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_link INT NOT NULL, - id_order INT NOT NULL, - id_product INT NULL, - id_permutation INT NULL, - csv_list_variations VARCHAR(4000) NULL, - id_unit_quantity INT NOT NULL, - quantity_used FLOAT NULL, - quantity_produced FLOAT NULL, - id_unit_latency_manufacture INT NULL, - latency_manufacture INT NULL, - display_order INT NOT NULL, - active BIT NOT NULL, - cost_unit_local_VAT_excl FLOAT NULL, - cost_unit_local_VAT_incl FLOAT NULL, - price_unit_local_VAT_excl FLOAT NULL, - price_unit_local_VAT_incl FLOAT NULL, - GUID BINARY(36) NOT NULL -); - - --- File: 1430_tbl_Shop_Customer_Sales_Order_Product_Link.sql - --- Customer Sales Order Product Link - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Customer_Sales_Order_Product_Link'; - -CREATE TABLE IF NOT EXISTS Shop_Customer_Sales_Order_Product_Link ( - id_link INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_order INT NOT NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_Product_Link_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Customer_Sales_Order(id_order), - id_permutation INT NOT NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_Product_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - price_total_local FLOAT NOT NULL, - id_currency_price INT NOT NULL, - quantity_ordered FLOAT NOT NULL, - id_unit_quantity INT NOT NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_Product_Link_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - quantity_delivered FLOAT NOT NULL, - latency_delivery_days INT NOT NULL, - display_order INT NOT NULL, - - active BIT NOT NULL, - created_on DATETIME, - created_by INT, - updated_last_on DATETIME NULL, - created_last_by VARCHAR(100) NULL, - id_change_set INT NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_Product_Link_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); - - --- File: 1431_tbl_Shop_Customer_Sales_Order_Product_Link_Audit.sql - --- Customer Sales Order Product Link Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Customer_Sales_Order_Product_Link_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Customer_Sales_Order_Product_Link_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_link INT NOT NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_Product_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Customer_Sales_Order_Product_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_Product_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); - - --- File: 1432_tbl_Shop_Customer_Sales_Order_Product_Link_Temp.sql - --- Customer Sales Order Product Link Temp - - - --- DROP TABLE Shop_Customer_Sales_Order_Product_Link_Temp; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Customer_Sales_Order_Product_Link_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Customer_Sales_Order_Product_Link_Temp ( - id_link INT NOT NULL PRIMARY KEY, - GUID BINARY(36) NOT NULL, - id_order INT NOT NULL, - /* - CONSTRAINT FK_Customer_Sales_Order_Product_Link_Temp_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Customer_Sales_Order(id_order), - */ - id_permutation INT NOT NULL, - CONSTRAINT FK_Customer_Sales_Order_Product_Link_Temp_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - price_total_local FLOAT NOT NULL, - id_currency_price INT NOT NULL, - quantity_ordered FLOAT NOT NULL, - id_unit_quantity INT NOT NULL, - CONSTRAINT FK_Customer_Sales_Order_Product_Link_Temp_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - quantity_delivered FLOAT NULL, - latency_delivery_days INT NOT NULL, - display_order INT NOT NULL, - active BIT NOT NULL -); - - --- File: 1500_tbl_Shop_Calc_User_Temp.sql - --- Calc User Staging --- USE partsltd_prod; --- DROP TABLE IF EXISTS Shop_Calc_User_Temp; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Calc_User_Temp'; - -CREATE TABLE Shop_Calc_User_Temp ( - -- id_row INT PRIMARY KEY AUTO_INCREMENT NOT NULL, - guid BINARY(36) NOT NULL, - id_user INT NULL, - id_permission_required INT NOT NULL, - CONSTRAINT FK_Shop_Calc_User_Temp_id_permission_required - FOREIGN KEY (id_permission_required) - REFERENCES partsltd_prod.Shop_Permission (id_permission), - priority_access_level_required INT NOT NULL, - id_product INT NULL, - CONSTRAINT FK_Shop_Calc_User_Temp_id_product - FOREIGN KEY (id_product) - REFERENCES partsltd_prod.Shop_Product (id_product), - is_super_user BIT NULL, - priority_access_level_user INT NULL, - can_view BIT, - can_edit BIT, - can_admin BIT -); - --- File: 3000_tri_Shop_Access_Level.sql - --- Shop Access Level - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Access_Level; -DROP TRIGGER IF EXISTS before_update_Shop_Access_Level; - +DROP TRIGGER IF EXISTS partsltd_prod.before_insert_PH_User_Change_Set; DELIMITER // -CREATE TRIGGER before_insert_Shop_Access_Level -BEFORE INSERT ON Shop_Access_Level +CREATE TRIGGER partsltd_prod.before_insert_PH_User_Change_Set +BEFORE INSERT ON partsltd_prod.PH_User_Change_Set FOR EACH ROW BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Access_Level -BEFORE UPDATE ON Shop_Access_Level -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Access_Level_Audit ( - id_access_level, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_access_level, 'code', OLD.code, NEW.code, NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.code <=> NEW.code) - UNION - -- Changed name - SELECT NEW.id_access_level, 'name', OLD.name, NEW.name, NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.name <=> NEW.name) - UNION - -- Changed priority - SELECT NEW.id_access_level, 'priority', CONVERT(OLD.priority, CHAR), CONVERT(NEW.priority, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.priority <=> NEW.priority) - UNION - -- Changed active - SELECT NEW.id_access_level, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_access_level, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.display_order <=> NEW.display_order - ; -END // -DELIMITER ; - - --- File: 3000_tri_Shop_Product_Change_Set.sql - --- Product Change Set - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Product_Change_Set; - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Product_Change_Set -BEFORE INSERT ON Shop_Product_Change_Set -FOR EACH ROW -BEGIN - IF NEW.updated_last_on IS NULL THEN + IF NEW.updated_last_on <=> NULL THEN SET NEW.updated_last_on = NOW(); END IF; - IF NEW.updated_last_by IS NULL THEN - SET NEW.updated_last_by = CURRENT_USER(); +END // +DELIMITER ; + + +DELIMITER // +CREATE TRIGGER partsltd_prod.before_update_PH_User_Change_Set +BEFORE UPDATE ON partsltd_prod.PH_User_Change_Set +FOR EACH ROW +BEGIN + IF NOT EXISTS(SELECT * FROM partsltd_prod.PH_User WHERE id_user = NEW.id_user_updated_last_by) THEN + SIGNAL SQLSTATE '45000' + SET MESSAGE_TEXT = 'New Updated-Last-By User ID must be provided.'; END IF; END // DELIMITER ; +USE partsltd_prod; --- File: 3001_tri_Shop_User_Change_Set.sql - --- Shop User Change Set - - - -DROP TRIGGER IF EXISTS before_insert_Shop_User_Change_Set; +DROP TRIGGER IF EXISTS partsltd_prod.before_insert_PH_User; +DROP TRIGGER IF EXISTS partsltd_prod.before_update_PH_User; DELIMITER // -CREATE TRIGGER before_insert_Shop_User_Change_Set -BEFORE INSERT ON Shop_User_Change_Set -FOR EACH ROW -BEGIN - IF NEW.updated_last_on IS NULL THEN - SET NEW.updated_last_on = NOW(); - END IF; - IF NEW.updated_last_by IS NULL THEN - SET NEW.updated_last_by = CURRENT_USER(); - END IF; -END // -DELIMITER ; - --- File: 3002_tri_Shop_Sales_And_Purchasing_Change_Set.sql - --- Product Change Set - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Sales_And_Purchasing_Change_Set; - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Sales_And_Purchasing_Change_Set -BEFORE INSERT ON Shop_Sales_And_Purchasing_Change_Set -FOR EACH ROW -BEGIN - IF NEW.updated_last_on IS NULL THEN - SET NEW.updated_last_on = NOW(); - END IF; - IF NEW.updated_last_by IS NULL THEN - SET NEW.updated_last_by = CURRENT_USER(); - END IF; -END // -DELIMITER ; - - --- File: 3010_tri_File_Type.sql - --- File Type - - - -DROP TRIGGER IF EXISTS before_insert_File_Type; -DROP TRIGGER IF EXISTS before_update_File_Type; - -DELIMITER // - -CREATE TRIGGER before_insert_File_Type -BEFORE INSERT ON File_Type +CREATE TRIGGER partsltd_prod.before_insert_PH_User +BEFORE INSERT ON partsltd_prod.PH_User FOR EACH ROW BEGIN SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // - -DELIMITER ; - -DELIMITER // -CREATE TRIGGER before_update_File_Type -BEFORE UPDATE ON File_Type -FOR EACH ROW -BEGIN - INSERT INTO File_Type_Audit ( - id_type, - name_field, - value_prev, - value_new - ) - -- Changed code - SELECT NEW.id_type, 'code', OLD.code, NEW.code - FROM DUAL - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_type, 'name', OLD.name, NEW.name - FROM DUAL - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed extension - SELECT NEW.id_type, 'extension', CONVERT(OLD.extension, CHAR), CONVERT(NEW.extension, CHAR) - FROM DUAL - WHERE NOT OLD.extension <=> NEW.extension - ; END // DELIMITER ; --- File: 3011_tri_File_Type_Audit.sql - --- File Type Audits - - - -DROP TRIGGER IF EXISTS before_insert_File_Type_Audit; -DROP TRIGGER IF EXISTS before_update_File_Type_Audit; - - DELIMITER // -CREATE TRIGGER before_insert_File_Type_Audit -BEFORE INSERT ON File_Type_Audit -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - -DELIMITER // -CREATE TRIGGER before_update_File_Type_Audit -BEFORE UPDATE ON File_Type_Audit -FOR EACH ROW -BEGIN - SET NEW.updated_last_on = NOW(); - SET NEW.updated_last_by = CURRENT_USER(); -END // -DELIMITER ; - --- File: 3012_tri_Shop_General.sql - --- Shop General - - - -DROP TRIGGER IF EXISTS before_insert_Shop_General; -DROP TRIGGER IF EXISTS before_update_Shop_General; - -DELIMITER // -CREATE TRIGGER before_insert_Shop_General -BEFORE INSERT ON Shop_General -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - -DELIMITER // -CREATE TRIGGER before_update_Shop_General -BEFORE UPDATE ON Shop_General +CREATE TRIGGER partsltd_prod.before_update_PH_User +BEFORE UPDATE ON partsltd_prod.PH_User FOR EACH ROW BEGIN IF OLD.id_change_set <=> NEW.id_change_set THEN @@ -3881,2037 +589,7 @@ BEGIN SET MESSAGE_TEXT = 'New change Set ID must be provided.'; END IF; - INSERT INTO Shop_General_Audit ( - id_general, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed quantity max - SELECT NEW.id_general, 'quantity_max', CONVERT(OLD.quantity_max, CHAR), CONVERT(NEW.quantity_max, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - ; -END // -DELIMITER ; - --- File: 3014_tri_Shop_Image_Type.sql - --- Shop Image Type - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Image_Type; -DROP TRIGGER IF EXISTS before_update_Shop_Image_Type; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Image_Type -BEFORE INSERT ON Shop_Image_Type -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Image_Type -BEFORE UPDATE ON Shop_Image_Type -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Image_Type_Audit ( - id_type, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_type_file - SELECT NEW.id_type, 'id_type_file', OLD.id_type_file, NEW.id_type_file, NEW.id_change_set - WHERE NOT OLD.id_type_file <=> NEW.id_type_file - UNION - */ - -- Changed code - SELECT NEW.id_type, 'code', OLD.code, NEW.code, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_type, 'name', OLD.name, NEW.name, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed name_plural - SELECT NEW.id_type, 'name_plural', OLD.name_plural, NEW.name_plural, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.name_plural <=> NEW.name_plural - UNION - -- Changed active - SELECT NEW.id_type, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_type, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; -END // -DELIMITER ; - --- File: 3100_tri_Shop_Region.sql - --- Shop Delivery Region - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Region; -DROP TRIGGER IF EXISTS before_update_Shop_Region; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Region -BEFORE INSERT ON Shop_Region -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Region -BEFORE UPDATE ON Shop_Region -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Region_Audit ( - id_region, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_region, 'code', OLD.code, NEW.code, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_region, 'name', OLD.name, NEW.name, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed active - SELECT NEW.id_region, 'active', CONVERT(OLD.active, CHAR), CONVERT(NEW.active, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.active <=> NEW.active - UNION - -- Changed display_order - SELECT NEW.id_region, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.display_order <=> NEW.display_order - ; -END // -DELIMITER ; - - --- File: 3103_tri_Shop_Region_Branch.sql - --- Shop Region Branch - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Region_Branch; -DROP TRIGGER IF EXISTS before_update_Shop_Region_Branch; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Region_Branch -BEFORE INSERT ON Shop_Region_Branch -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Region_Branch -BEFORE UPDATE ON Shop_Region_Branch -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Region_Branch_Audit ( - id_branch, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed depth - SELECT NEW.id_branch, 'depth', CONVERT(OLD.depth, CHAR), CONVERT(NEW.depth, CHAR), NEW.id_change_set - WHERE NOT OLD.depth <=> NEW.depth - UNION - */ - -- Changed active - SELECT NEW.id_branch, 'active', CONVERT(OLD.active, CHAR), CONVERT(NEW.active, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.active <=> NEW.active - UNION - -- Changed display_order - SELECT NEW.id_branch, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.display_order <=> NEW.display_order - ; -END // -DELIMITER ; - - --- File: 3106_tri_Shop_Address.sql - --- Shop Address - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Address; -DROP TRIGGER IF EXISTS before_update_Shop_Address; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Address -BEFORE INSERT ON Shop_Address -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Address -BEFORE UPDATE ON Shop_Address -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Address_Audit ( - id_address, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed region - SELECT NEW.id_address, 'id_region', OLD.id_region, NEW.id_region, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_region <=> NEW.id_region - UNION - -- Changed postcode - SELECT NEW.id_address, 'postcode', OLD.postcode, NEW.postcode, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.postcode <=> NEW.postcode - UNION - -- Changed address_line_1 - SELECT NEW.id_address, 'address_line_1', OLD.address_line_1, NEW.address_line_1, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.address_line_1 <=> NEW.address_line_1 - UNION - -- Changed address_line_2 - SELECT NEW.id_address, 'address_line_2', OLD.address_line_2, NEW.address_line_2, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.address_line_2 <=> NEW.address_line_2 - UNION - -- Changed city - SELECT NEW.id_address, 'city', OLD.city, NEW.city, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.city <=> NEW.city - UNION - -- Changed county - SELECT NEW.id_address, 'county', OLD.county, NEW.county, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.county <=> NEW.county - UNION - -- Changed active - SELECT NEW.id_address, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.active <=> NEW.active) - ; -END // -DELIMITER ; - --- File: 3109_tri_Shop_Storage_Location.sql - --- Shop Storage Location - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Storage_Location; -DROP TRIGGER IF EXISTS before_update_Shop_Storage_Location; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Storage_Location -BEFORE INSERT ON Shop_Storage_Location -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Storage_Location -BEFORE UPDATE ON Shop_Storage_Location -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Storage_Location_Audit ( - id_location, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_plant - SELECT NEW.id_location, 'id_plant', OLD.id_plant, NEW.id_plant, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_plant <=> NEW.id_plant - UNION - -- Changed code - SELECT NEW.id_location, 'code', OLD.code, NEW.code, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_location, 'name', OLD.name, NEW.name, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed active - SELECT NEW.id_location, 'active', CONVERT(OLD.active, CHAR), CONVERT(NEW.active, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.active <=> NEW.active - ; -END // -DELIMITER ; - - --- File: 3115_tri_Shop_Currency.sql - --- Shop Currency - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Currency; -DROP TRIGGER IF EXISTS before_update_Shop_Currency; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Currency -BEFORE INSERT ON Shop_Currency -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Currency -BEFORE UPDATE ON Shop_Currency -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Currency_Audit ( - id_currency, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_currency, 'code', OLD.code, NEW.code, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_currency, 'name', OLD.name, NEW.name, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed symbol - SELECT NEW.id_currency, 'symbol', OLD.symbol, NEW.symbol, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.symbol <=> NEW.symbol - UNION - -- Changed ratio_2_GBP - SELECT NEW.id_currency, 'factor_from_GBP', OLD.factor_from_GBP, NEW.factor_from_GBP, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.factor_from_GBP <=> NEW.factor_from_GBP - UNION - -- Changed active - SELECT NEW.id_currency, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_currency, 'display_order', CONVERT(display_order, CHAR), CONVERT(display_order, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; -END // -DELIMITER ; - --- File: 3118_tri_Shop_Tax_Or_Surcharge.sql - --- Shop Tax_Or_Surcharge - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Tax_Or_Surcharge; -DROP TRIGGER IF EXISTS before_update_Shop_Tax_Or_Surcharge; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Tax_Or_Surcharge -BEFORE INSERT ON Shop_Tax_Or_Surcharge -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - -DELIMITER // -CREATE TRIGGER before_update_Shop_Tax_Or_Surcharge -BEFORE UPDATE ON Shop_Tax_Or_Surcharge -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Tax_Or_Surcharge_Audit ( - id_tax, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_tax, 'code', OLD.code, NEW.code, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_tax, 'name', OLD.name, NEW.name, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed fixed_fee - SELECT NEW.id_tax, 'fixed_fee', OLD.fixed_fee, NEW.fixed_fee, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.fixed_fee <=> NEW.fixed_fee - UNION - -- Changed multiplier - SELECT NEW.id_tax, 'multiplier', OLD.multiplier, NEW.multiplier, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.multiplier <=> NEW.multiplier - UNION - -- Changed apply_fixed_fee_before_multiplier - SELECT NEW.id_tax, 'apply_fixed_fee_before_multiplier', CONVERT(CONVERT(OLD.apply_fixed_fee_before_multiplier, SIGNED), CHAR), CONVERT(CONVERT(NEW.apply_fixed_fee_before_multiplier, SIGNED), CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.apply_fixed_fee_before_multiplier <=> NEW.apply_fixed_fee_before_multiplier - UNION - -- Changed quantity_min - SELECT NEW.id_tax, 'quantity_min', OLD.quantity_min, NEW.quantity_min, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.quantity_min <=> NEW.quantity_min - UNION - -- Changed quantity_max - SELECT NEW.id_tax, 'quantity_max', OLD.quantity_max, NEW.quantity_max, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - UNION - -- Changed display_order - SELECT NEW.id_tax, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.display_order <=> NEW.display_order - UNION - -- Changed active - SELECT NEW.id_tax, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.active <=> NEW.active - ; -END // -DELIMITER ; - - - --- File: 3200_tri_Shop_Category.sql - --- Shop Category - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Product_Category; -DROP TRIGGER IF EXISTS before_update_Shop_Product_Category; - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Product_Category -BEFORE INSERT ON Shop_Product_Category -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - -DELIMITER // -CREATE TRIGGER before_update_Shop_Product_Category -BEFORE UPDATE ON Shop_Product_Category -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Product_Category_Audit ( - id_category, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_category, 'code', OLD.code, NEW.code, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_category, 'name', OLD.name, NEW.name, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed description - SELECT NEW.id_category, 'description', OLD.description, NEW.description, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.description <=> NEW.description - UNION - -- Changed active - SELECT NEW.id_category, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_category, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.display_order <=> NEW.display_order - UNION - -- Changed id_access_level_required - SELECT NEW.id_category, 'id_access_level_required', CONVERT(OLD.id_access_level_required, CHAR), CONVERT(NEW.id_access_level_required, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_access_level_required <=> NEW.id_access_level_required - ; -END // -DELIMITER ; - - --- File: 3203_tri_Shop_Product.sql - --- Shop Product - - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Product; -DROP TRIGGER IF EXISTS before_update_Shop_Product; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Product -BEFORE INSERT ON Shop_Product -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Product -BEFORE UPDATE ON Shop_Product -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - /* - IF NOT NEW.has_variations THEN - IF ISNULL(NEW.price_GBP_full) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have price or variations (with prices).'; - END IF; - IF ISNULL(NEW.price_GBP_min) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have minimum price or variations (with prices).'; - END IF; - IF ISNULL(NEW.latency_manuf) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have manufacturing latency or variations (with manufacturing latencies).'; - END IF; - IF ISNULL(NEW.quantity_min) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have minimum quantity or variations (with minimum quantities).'; - END IF; - IF ISNULL(NEW.quantity_max) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have maximum quantity or variations (with maximum quantities).'; - END IF; - IF ISNULL(NEW.quantity_step) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have increment of quantity or variations (with increments of quantities).'; - END IF; - IF ISNULL(NEW.quantity_stock) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have stock quantity or variations (with stock quantities).'; - END IF; - IF ISNULL(NEW.is_subscription) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have subscription status or variations (with subscription statuses).'; - END IF; - IF ISNULL(NEW.id_unit_measurement_interval_recurrence) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have recurrence interval or variations (with recurrence intervals).'; - END IF; - IF ISNULL(NEW.count_interval_recurrence) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have recurrence interval count or variations (with recurrence interval counts).'; - END IF; - END IF; - */ - - INSERT INTO Shop_Product_Audit ( - id_product, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed name - SELECT NEW.id_product, 'name', OLD.name, NEW.name, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.name <=> NEW.name - /* - UNION - -- Changed description - SELECT NEW.id_product, 'description', OLD.description, NEW.description, NEW.id_change_set - WHERE NOT OLD.description <=> NEW.description - UNION - -- Changed price_GBP_full - SELECT NEW.id_product, 'price_GBP_full', CONVERT(OLD.price_GBP_full, CHAR), CONVERT(NEW.price_GBP_full, CHAR), NEW.id_change_set - WHERE NOT OLD.price_GBP_full <=> NEW.price_GBP_full - UNION - -- Changed price_GBP_min - SELECT NEW.id_product, 'price_GBP_min', CONVERT(OLD.price_GBP_min, CHAR), CONVERT(NEW.price_GBP_min, CHAR), NEW.id_change_set - WHERE NOT OLD.price_GBP_min <=> NEW.price_GBP_min - UNION - / * - -- Changed discount - SELECT NEW.id_product, 'discount', CONVERT(OLD.discount, CHAR), CONVERT(NEW.discount, CHAR), NEW.id_change_set - WHERE NOT OLD.discount <=> NEW.discount - */ - UNION - -- Changed id_category - SELECT NEW.id_product, 'id_category', CONVERT(OLD.id_category, CHAR), CONVERT(NEW.id_category, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_category <=> NEW.id_category - UNION - -- Changed has_variations - SELECT NEW.id_product, 'has_variations', CONVERT(CONVERT(NEW.has_variations, SIGNED), CHAR), CONVERT(CONVERT(NEW.has_variations, SIGNED), CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.has_variations <=> NEW.has_variations - /* - UNION - -- Changed latency_manuf - SELECT NEW.id_product, 'latency_manuf', CONVERT(OLD.latency_manuf, CHAR), CONVERT(NEW.latency_manuf, CHAR), NEW.id_change_set - WHERE NOT OLD.latency_manuf <=> NEW.latency_manuf - UNION - -- Changed quantity_min - SELECT NEW.id_product, 'quantity_min', CONVERT(OLD.quantity_min, CHAR), CONVERT(NEW.quantity_min, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_min <=> NEW.quantity_min - UNION - -- Changed quantity_max - SELECT NEW.id_product, 'quantity_max', CONVERT(OLD.quantity_max, CHAR), CONVERT(NEW.quantity_max, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - UNION - -- Changed quantity_step - SELECT NEW.id_product, 'quantity_step', CONVERT(OLD.quantity_step, CHAR), CONVERT(NEW.quantity_step, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_step <=> NEW.quantity_step - UNION - -- Changed quantity_stock - SELECT NEW.id_product, 'quantity_stock', CONVERT(OLD.quantity_stock, CHAR), CONVERT(NEW.quantity_stock, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_stock <=> NEW.quantity_stock - UNION - -- Changed is_subscription - SELECT NEW.id_product, 'is_subscription', CONVERT(CONVERT(OLD.is_subscription, SIGNED), CHAR), CONVERT(CONVERT(NEW.is_subscription, SIGNED), CHAR), NEW.id_change_set - WHERE NOT OLD.is_subscription <=> NEW.is_subscription - UNION - -- Changed id_unit_measurement_interval_recurrence - SELECT NEW.id_product, 'id_unit_measurement_interval_recurrence', CONVERT(OLD.id_unit_measurement_interval_recurrence, CHAR), CONVERT(NEW.id_unit_measurement_interval_recurrence, CHAR), NEW.id_change_set - WHERE NOT OLD.id_unit_measurement_interval_recurrence <=> NEW.id_unit_measurement_interval_recurrence - UNION - -- Changed count_interval_recurrence - SELECT NEW.id_product, 'count_interval_recurrence', CONVERT(OLD.count_interval_recurrence, CHAR), CONVERT(NEW.count_interval_recurrence, CHAR), NEW.id_change_set - WHERE NOT OLD.count_interval_recurrence <=> NEW.count_interval_recurrence - UNION - -- Changed id_stripe_product - SELECT NEW.id_product, 'id_stripe_product', OLD.id_stripe_product, NEW.id_stripe_product, NEW.id_change_set - WHERE NOT OLD.id_stripe_product <=> NEW.id_stripe_product - / * - UNION - -- Changed id_stripe_price - SELECT NEW.id_product, 'id_stripe_price', OLD.id_stripe_price, NEW.id_stripe_price, NEW.id_change_set - WHERE NOT OLD.id_stripe_price <=> NEW.id_stripe_price - */ - UNION - -- Changed id_access_level_required - SELECT NEW.id_product, 'id_access_level_required', CONVERT(OLD.id_access_level_required, CHAR), CONVERT(NEW.id_access_level_required, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_access_level_required <=> NEW.id_access_level_required - UNION - -- Changed active - SELECT NEW.id_product, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_product, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.display_order <=> NEW.display_order - ; -END // -DELIMITER ; - - --- File: 3206_tri_Shop_Product_Permutation.sql - --- Shop Product Permutation - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Product_Permutation; -DROP TRIGGER IF EXISTS before_update_Shop_Product_Permutation; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Product_Permutation -BEFORE INSERT ON Shop_Product_Permutation -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Product_Permutation -BEFORE UPDATE ON Shop_Product_Permutation -FOR EACH ROW -BEGIN - DECLARE v_msg VARCHAR(4000); - - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - IF (NOT ( - NEW.id_unit_measurement_interval_recurrence IS NULL - OR NEW.id_unit_measurement_interval_recurrence IN (SELECT id_unit_measurement FROM Shop_Unit_Measurement WHERE is_unit_of_time = 1) - )) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Recurrence interval ID must be a unit of time.'; - END IF; - - IF (NOT ( - NEW.id_unit_measurement_interval_expiration_unsealed IS NULL - OR NEW.id_unit_measurement_interval_expiration_unsealed IN (SELECT id_unit_measurement FROM Shop_Unit_Measurement WHERE is_unit_of_time = 1) - )) THEN - SET v_msg := CONCAT('Unsealed expiration interval ID must be a unit of time. Invalid value: ', CAST(NEW.id_unit_measurement_interval_expiration_unsealed AS CHAR)); - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = v_msg - ; - END IF; - - INSERT INTO Shop_Product_Permutation_Audit ( - id_permutation, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_product - SELECT NEW.id_permutation, 'id_product', OLD.id_product, NEW.id_product, NEW.id_change_set - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed id_variation - SELECT NEW.id_permutation, 'id_variation', OLD.id_variation, NEW.id_variation, NEW.id_change_set - WHERE NOT OLD.id_variation <=> NEW.id_variation - UNION - -- Changed name - SELECT NEW.id_permutation, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT (OLD.name <=> NEW.name) - UNION - */ - -- Changed description - SELECT NEW.id_permutation, 'description', OLD.description, NEW.description, NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.description <=> NEW.description) - UNION - -- Changed cost_local_VAT_excl - SELECT NEW.id_permutation, 'cost_local_VAT_excl', CONVERT(OLD.cost_local_VAT_excl, CHAR), CONVERT(NEW.cost_local_VAT_excl, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.cost_local_VAT_excl <=> NEW.cost_local_VAT_excl) - UNION - -- Changed cost_local_VAT_incl - SELECT NEW.id_permutation, 'cost_local_VAT_incl', CONVERT(OLD.cost_local_VAT_incl, CHAR), CONVERT(NEW.cost_local_VAT_incl, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.cost_local_VAT_incl <=> NEW.cost_local_VAT_incl) - UNION - -- Changed id_currency_cost - SELECT NEW.id_permutation, 'id_currency_cost', CONVERT(OLD.id_currency_cost, CHAR), CONVERT(NEW.id_currency_cost, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.id_currency_cost <=> NEW.id_currency_cost) - UNION - /* - -- Changed profit_local_min - SELECT NEW.id_permutation, 'profit_local_min', CONVERT(OLD.profit_local_min, CHAR), CONVERT(NEW.profit_local_min, CHAR), NEW.id_change_set - WHERE NOT (OLD.profit_local_min <=> NEW.profit_local_min) - UNION - -- Changed id_currency_profit_min - SELECT NEW.id_permutation, 'id_currency_profit_min', CONVERT(OLD.id_currency_profit_min, CHAR), CONVERT(NEW.id_currency_profit_min, CHAR), NEW.id_change_set - WHERE NOT (OLD.id_currency_profit_min <=> NEW.id_currency_profit_min) - UNION - */ - /* - -- Changed price_GBP_min - SELECT NEW.id_permutation, 'price_GBP_min', CONVERT(OLD.price_GBP_min, CHAR), CONVERT(NEW.price_GBP_min, CHAR), NEW.id_change_set - WHERE NOT (OLD.price_GBP_min <=> NEW.price_GBP_min) - UNION - */ - -- Changed latency_manufacture - SELECT NEW.id_permutation, 'latency_manufacture', CONVERT(OLD.latency_manufacture, CHAR), CONVERT(NEW.latency_manufacture, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.latency_manufacture <=> NEW.latency_manufacture - UNION - -- Changed id_unit_measurement_quantity - SELECT NEW.id_permutation, 'id_unit_measurement_quantity', CONVERT(OLD.id_unit_measurement_quantity, CHAR), CONVERT(NEW.id_unit_measurement_quantity, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_unit_measurement_quantity <=> NEW.id_unit_measurement_quantity - UNION - -- Changed count_unit_measurement_per_quantity_step - SELECT NEW.id_permutation, 'count_unit_measurement_per_quantity_step', CONVERT(OLD.count_unit_measurement_per_quantity_step, CHAR), CONVERT(NEW.count_unit_measurement_per_quantity_step, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.count_unit_measurement_per_quantity_step <=> NEW.count_unit_measurement_per_quantity_step - UNION - -- Changed quantity_min - SELECT NEW.id_permutation, 'quantity_min', CONVERT(OLD.quantity_min, CHAR), CONVERT(NEW.quantity_min, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.quantity_min <=> NEW.quantity_min - UNION - -- Changed quantity_max - SELECT NEW.id_permutation, 'quantity_max', CONVERT(OLD.quantity_max, CHAR), CONVERT(NEW.quantity_max, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - UNION - -- Changed quantity_stock - SELECT NEW.id_permutation, 'quantity_stock', CONVERT(OLD.quantity_stock, CHAR), CONVERT(NEW.quantity_stock, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.quantity_stock <=> NEW.quantity_stock - UNION - -- Changed is_subscription - SELECT NEW.id_permutation, 'is_subscription', CONVERT(CONVERT(OLD.is_subscription, SIGNED), CHAR), CONVERT(CONVERT(NEW.is_subscription, SIGNED), CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.is_subscription <=> NEW.is_subscription - UNION - -- Changed id_unit_measurement_interval_recurrence - SELECT NEW.id_permutation, 'id_unit_measurement_interval_recurrence', CONVERT(OLD.id_unit_measurement_interval_recurrence, CHAR), CONVERT(NEW.id_unit_measurement_interval_recurrence, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_unit_measurement_interval_recurrence <=> NEW.id_unit_measurement_interval_recurrence - UNION - -- Changed count_interval_recurrence - SELECT NEW.id_permutation, 'count_interval_recurrence', CONVERT(OLD.count_interval_recurrence, CHAR), CONVERT(NEW.count_interval_recurrence, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.count_interval_recurrence <=> NEW.count_interval_recurrence - UNION - -- Changed id_stripe_product - SELECT NEW.id_permutation, 'id_stripe_product', OLD.id_stripe_product, NEW.id_stripe_product, NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.id_stripe_product <=> NEW.id_stripe_product) - UNION - -- Changed does_expire_faster_once_unsealed - SELECT NEW.id_permutation, 'does_expire_faster_once_unsealed', CONVERT(OLD.does_expire_faster_once_unsealed, CHAR), CONVERT(NEW.does_expire_faster_once_unsealed, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.does_expire_faster_once_unsealed <=> NEW.does_expire_faster_once_unsealed - UNION - -- Changed id_unit_measurement_interval_expiration_unsealed - SELECT NEW.id_permutation, 'id_unit_measurement_interval_expiration_unsealed', CONVERT(OLD.id_unit_measurement_interval_expiration_unsealed, CHAR), CONVERT(NEW.id_unit_measurement_interval_expiration_unsealed, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_unit_measurement_interval_expiration_unsealed <=> NEW.id_unit_measurement_interval_expiration_unsealed - UNION - -- Changed count_interval_expiration_unsealed - SELECT NEW.id_permutation, 'count_interval_expiration_unsealed', CONVERT(OLD.count_interval_expiration_unsealed, CHAR), CONVERT(NEW.count_interval_expiration_unsealed, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.count_interval_expiration_unsealed <=> NEW.count_interval_expiration_unsealed - UNION - -- Changed active - SELECT NEW.id_permutation, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.active <=> NEW.active) - /* - UNION - -- Changed display_order - SELECT NEW.id_permutation, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - */ - ; -END // -DELIMITER ; - - --- File: 3209_tri_Shop_Variation_Type.sql - --- Shop Variation Type - - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Variation_Type; -DROP TRIGGER IF EXISTS before_update_Shop_Variation_Type; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Variation_Type -BEFORE INSERT ON Shop_Variation_Type -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Variation_Type -BEFORE UPDATE ON Shop_Variation_Type -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Variation_Type_Audit ( - id_type, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_type, 'code', OLD.code, NEW.code, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_type, 'name', OLD.name, NEW.name, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed name_plural - SELECT NEW.id_type, 'name_plural', OLD.name_plural, NEW.name_plural, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.name_plural <=> NEW.name_plural - UNION - -- Changed active - SELECT NEW.id_type, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_type, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; -END // -DELIMITER ; - - --- File: 3212_tri_Shop_Variation.sql - --- Shop Variation - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Variation; -DROP TRIGGER IF EXISTS before_update_Shop_Variation; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Variation -BEFORE INSERT ON Shop_Variation -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Variation -BEFORE UPDATE ON Shop_Variation -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Variation_Audit ( - id_variation, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_unit_measurement - SELECT NEW.id_variation, 'id_unit_measurement', OLD.id_unit_measurement, NEW.id_unit_measurement, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_unit_measurement <=> NEW.id_unit_measurement - UNION - -- Changed count_unit_measurement - SELECT NEW.id_variation, 'count_unit_measurement', OLD.count_unit_measurement, NEW.count_unit_measurement, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.count_unit_measurement <=> NEW.count_unit_measurement - UNION - -- Changed code - SELECT NEW.id_variation, 'code', OLD.code, NEW.code, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_variation, 'name', OLD.name, NEW.name, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed active - SELECT NEW.id_variation, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_variation, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; -END // -DELIMITER ; - - --- File: 3215_tri_Shop_Product_Permutation_Variation_Link.sql - --- Shop Product Permutation Variation Link - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Product_Permutation_Variation_Link; -DROP TRIGGER IF EXISTS before_update_Shop_Product_Permutation_Variation_Link; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Product_Permutation_Variation_Link -BEFORE INSERT ON Shop_Product_Permutation_Variation_Link -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Product_Permutation_Variation_Link -BEFORE UPDATE ON Shop_Product_Permutation_Variation_Link -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Product_Permutation_Variation_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_product - SELECT NEW.id_link, 'id_product', OLD.id_product, NEW.id_product, NEW.id_change_set - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed id_variation - SELECT NEW.id_link, 'id_variation', OLD.id_variation, NEW.id_variation, NEW.id_change_set - WHERE NOT OLD.id_variation <=> NEW.id_variation - UNION - */ - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_link, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; -END // -DELIMITER ; - --- File: 3218_tri_Shop_Stock_Item.sql - --- Shop Product Permutation - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Stock_Item; -DROP TRIGGER IF EXISTS before_update_Shop_Stock_Item; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Stock_Item -BEFORE INSERT ON Shop_Stock_Item -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Stock_Item -BEFORE UPDATE ON Shop_Stock_Item -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Stock_Item_Audit ( - id_stock, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_permutation - SELECT NEW.id_stock, 'id_permutation', OLD.id_permutation, NEW.id_permutation, NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.id_permutation <=> NEW.id_permutation) - UNION - -- Changed date_purchased - SELECT NEW.id_stock, 'date_purchased', OLD.date_purchased, NEW.date_purchased, NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.date_purchased <=> NEW.date_purchased) - UNION - -- Changed date_received - SELECT NEW.id_stock, 'date_received', OLD.date_received, NEW.date_received, NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.date_received <=> NEW.date_received) - UNION - -- Changed id_location_storage - SELECT NEW.id_stock, 'id_location_storage', OLD.id_location_storage, NEW.id_location_storage, NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.id_location_storage <=> NEW.id_location_storage) - UNION - -- Changed id_currency_cost - SELECT NEW.id_stock, 'id_currency_cost', OLD.id_currency_cost, NEW.id_currency_cost, NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.id_currency_cost <=> NEW.id_currency_cost) - UNION - -- Changed cost_local_VAT_incl - SELECT NEW.id_stock, 'cost_local_VAT_incl', OLD.cost_local_VAT_incl, NEW.cost_local_VAT_incl, NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.cost_local_VAT_incl <=> NEW.cost_local_VAT_incl) - UNION - -- Changed cost_local_VAT_excl - SELECT NEW.id_stock, 'cost_local_VAT_excl', OLD.cost_local_VAT_excl, NEW.cost_local_VAT_excl, NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.cost_local_VAT_excl <=> NEW.cost_local_VAT_excl) - UNION - -- Changed is_sealed - SELECT NEW.id_stock, 'is_sealed', OLD.is_sealed, NEW.is_sealed, NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.is_sealed <=> NEW.is_sealed) - UNION - -- Changed date_unsealed - SELECT NEW.id_stock, 'date_unsealed', OLD.date_unsealed, NEW.date_unsealed, NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.date_unsealed <=> NEW.date_unsealed) - UNION - -- Changed date_expiration - SELECT NEW.id_stock, 'date_expiration', OLD.date_expiration, NEW.date_expiration, NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.date_expiration <=> NEW.date_expiration) - UNION - -- Changed is_consumed - SELECT NEW.id_stock, 'is_consumed', OLD.is_consumed, NEW.is_consumed, NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.is_consumed <=> NEW.is_consumed) - UNION - -- Changed date_consumed - SELECT NEW.id_stock, 'date_consumed', OLD.date_consumed, NEW.date_consumed, NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.date_consumed <=> NEW.date_consumed) - UNION - -- Changed active - SELECT NEW.id_stock, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.active <=> NEW.active) - ; -END // -DELIMITER ; - - --- File: 3221_tri_Shop_Product_Price.sql - --- Shop Product Currency Link - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Product_Price; -DROP TRIGGER IF EXISTS before_update_Shop_Product_Price; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Product_Price -BEFORE INSERT ON Shop_Product_Price -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - /* - SET NEW.price_local = ( - SELECT PP.price_GBP_full * C.factor_from_GBP - FROM Shop_Product_Permutation PP - INNER JOIN Shop_Product P ON PP.id_product = P.id_product - INNER JOIN Shop_Currency C ON NEW.id_currency = C.id_currency - WHERE NEW.id_product = P.id_product - LIMIT 1 - ); - */ -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Product_Price -BEFORE UPDATE ON Shop_Product_Price -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - /* - SET NEW.price_local = ( - SELECT P.price_GBP_full * C.factor_from_GBP - FROM Shop_Product P - INNER JOIN Shop_Currency C ON NEW.id_currency = C.id_currency - WHERE NEW.id_product = P.id_product - LIMIT 1 - ); - */ - - INSERT INTO Shop_Product_Price_Audit ( - id_price, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_permutation - SELECT NEW.id_price, 'id_permutation', CONVERT(OLD.id_permutation, CHAR), CONVERT(NEW.id_permutation, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_permutation <=> NEW.id_permutation - UNION - -- Changed id_currency - SELECT NEW.id_price, 'id_currency', CONVERT(OLD.id_currency, CHAR), CONVERT(NEW.id_currency, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_currency <=> NEW.id_currency - UNION - -- Changed id_region_purchase - SELECT NEW.id_price, 'id_region_purchase', CONVERT(OLD.id_region_purchase, CHAR), CONVERT(NEW.id_region_purchase, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_region_purchase <=> NEW.id_region_purchase - UNION - -- Changed price_local_VAT_incl - SELECT NEW.id_price, 'price_local_VAT_incl', OLD.price_local_VAT_incl, NEW.price_local_VAT_incl, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.price_local_VAT_incl <=> NEW.price_local_VAT_incl - UNION - -- Changed price_local_VAT_excl - SELECT NEW.id_price, 'price_local_VAT_excl', OLD.price_local_VAT_excl, NEW.price_local_VAT_excl, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.price_local_VAT_excl <=> NEW.price_local_VAT_excl - UNION - -- Changed id_stripe_price - SELECT NEW.id_price, 'id_stripe_price', OLD.id_stripe_price, NEW.id_stripe_price, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_stripe_price <=> NEW.id_stripe_price - UNION - -- Changed active - SELECT NEW.id_price, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.active <=> NEW.active) - ; -END // -DELIMITER ; - - --- File: 3224_tri_Shop_Product_Image.sql - --- Shop Image - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Product_Image; -DROP TRIGGER IF EXISTS before_update_Shop_Product_Image; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Product_Image -BEFORE INSERT ON Shop_Product_Image -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Product_Image -BEFORE UPDATE ON Shop_Product_Image -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change set ID must be provided.'; - END IF; - IF ISNULL(NEW.id_permutation) THEN -- ISNULL(NEW.id_product) AND - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Image must NOT have ID for product AND product permutation.'; - END IF; - - INSERT INTO Shop_Product_Image_Audit ( - id_image, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_type_image - SELECT NEW.id_image, 'id_type_image', CONVERT(OLD.id_type_image, CHAR), CONVERT(NEW.id_type_image, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_type_image <=> NEW.id_type_image - UNION - /* - -- Changed id_type_file - SELECT NEW.id_image, 'id_type_file', CONVERT(OLD.id_type_file, CHAR), CONVERT(NEW.id_type_file, CHAR), NEW.id_change_set - WHERE NOT OLD.id_type_file <=> NEW.id_type_file - UNION - -- Changed id_product - SELECT NEW.id_image, 'id_product', CONVERT(OLD.id_product, CHAR), CONVERT(NEW.id_product, CHAR), NEW.id_change_set - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - */ - -- Changed id_permutation - SELECT NEW.id_image, 'id_permutation', CONVERT(OLD.id_permutation, CHAR), CONVERT(NEW.id_permutation, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_permutation <=> NEW.id_permutation - UNION - -- Changed url - SELECT NEW.id_image, 'url', OLD.url, NEW.url, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.url <=> NEW.url - UNION - -- Changed active - SELECT NEW.id_image, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_image, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; -END // -DELIMITER ; - --- File: 3227_tri_Shop_Delivery_Option.sql - --- Shop Delivery Option Type - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Delivery_Option; -DROP TRIGGER IF EXISTS before_update_Shop_Delivery_Option; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Delivery_Option -BEFORE INSERT ON Shop_Delivery_Option -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Delivery_Option -BEFORE UPDATE ON Shop_Delivery_Option -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Delivery_Option_Audit ( - id_option, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_option, 'code', OLD.code, NEW.code, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_option, 'name', OLD.name, NEW.name, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed latency_delivery_min - SELECT NEW.id_option, 'latency_delivery_min', CONVERT(OLD.latency_delivery_min, CHAR), CONVERT(NEW.latency_delivery_min, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.latency_delivery_min <=> NEW.latency_delivery_min - UNION - -- Changed latency_delivery_max - SELECT NEW.id_option, 'latency_delivery_max', CONVERT(OLD.latency_delivery_max, CHAR), CONVERT(NEW.latency_delivery_max, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.latency_delivery_max <=> NEW.latency_delivery_max - /* - UNION - -- Changed quantity_min - SELECT NEW.id_option, 'quantity_min', CONVERT(OLD.quantity_min, CHAR), CONVERT(NEW.quantity_min, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_min <=> NEW.quantity_min - UNION - -- Changed quantity_max - SELECT NEW.id_option, 'quantity_max', CONVERT(OLD.quantity_max, CHAR), CONVERT(NEW.quantity_max, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - */ - UNION - -- Changed active - SELECT NEW.id_option, 'active', CONVERT(OLD.active, CHAR), CONVERT(NEW.active, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.active <=> NEW.active - UNION - -- Changed display_order - SELECT NEW.id_option, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.display_order <=> NEW.display_order - ; -END // -DELIMITER ; - --- File: 3230_tri_Shop_Product_Permutation_Delivery_Option_Link.sql - --- Shop Product Delivery Option Link - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Product_Permutation_Delivery_Option_Link; -DROP TRIGGER IF EXISTS before_update_Shop_Product_Permutation_Delivery_Option_Link; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Product_Permutation_Delivery_Option_Link -BEFORE INSERT ON Shop_Product_Permutation_Delivery_Option_Link -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Product_Permutation_Delivery_Option_Link -BEFORE UPDATE ON Shop_Product_Permutation_Delivery_Option_Link -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Product_Permutation_Delivery_Option_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_product - SELECT NEW.id_link, 'id_product', CONVERT(OLD.id_product, CHAR), CONVERT(NEW.id_product, CHAR), NEW.id_change_set - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed id_permutation - SELECT NEW.id_link, 'id_permutation', CONVERT(OLD.id_permutation, CHAR), CONVERT(NEW.id_permutation, CHAR), NEW.id_change_set - WHERE NOT OLD.id_permutation <=> NEW.id_permutation - UNION - -- Changed id_option - SELECT NEW.id_link, 'id_option', CONVERT(OLD.id_option, CHAR), CONVERT(NEW.id_option, CHAR), NEW.id_change_set - WHERE NOT OLD.id_option <=> NEW.id_option - UNION - -- Changed id_region - SELECT NEW.id_link, 'id_region', CONVERT(OLD.id_region, CHAR), CONVERT(NEW.id_region, CHAR), NEW.id_change_set - WHERE NOT OLD.id_region <=> NEW.id_region - UNION - */ - -- Changed price_local - SELECT NEW.id_link, 'price_local', CONVERT(OLD.price_local, CHAR), CONVERT(NEW.price_local, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.price_local <=> NEW.price_local - /* - UNION - -- Changed quantity_min - SELECT NEW.id_link, 'quantity_min', CONVERT(OLD.quantity_min, CHAR), CONVERT(NEW.quantity_min, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_min <=> NEW.quantity_min - UNION - -- Changed quantity_max - SELECT NEW.id_link, 'quantity_max', CONVERT(OLD.quantity_max, CHAR), CONVERT(NEW.quantity_max, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - */ - UNION - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_link, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; -END // -DELIMITER ; - --- File: 3233_tri_Shop_Discount.sql - --- Shop Discount - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Discount; -DROP TRIGGER IF EXISTS before_update_Shop_Discount; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Discount -BEFORE INSERT ON Shop_Discount -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - -DELIMITER // -CREATE TRIGGER before_update_Shop_Discount -BEFORE UPDATE ON Shop_Discount -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Discount_Audit ( - id_discount, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_discount, 'code', OLD.code, NEW.code, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_discount, 'name', OLD.name, NEW.name, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed multiplier - SELECT NEW.id_discount, 'multiplier', OLD.multiplier, NEW.multiplier, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.multiplier <=> NEW.multiplier - UNION - -- Changed subtractor - SELECT NEW.id_discount, 'subtractor', OLD.subtractor, NEW.subtractor, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.subtractor <=> NEW.subtractor - UNION - -- Changed apply_multiplier_first - SELECT NEW.id_discount, 'apply_multiplier_first', CONVERT(CONVERT(OLD.apply_multiplier_first, SIGNED), CHAR), CONVERT(CONVERT(NEW.apply_multiplier_first, SIGNED), CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.apply_multiplier_first <=> NEW.apply_multiplier_first - UNION - -- Changed quantity_min - SELECT NEW.id_discount, 'quantity_min', OLD.quantity_min, NEW.quantity_min, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.quantity_min <=> NEW.quantity_min - UNION - -- Changed quantity_max - SELECT NEW.id_discount, 'quantity_max', OLD.quantity_max, NEW.quantity_max, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - UNION - -- Changed date_start - SELECT NEW.id_discount, 'date_start', OLD.date_start, NEW.date_start, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.date_start <=> NEW.date_start - UNION - -- Changed date_end - SELECT NEW.id_discount, 'date_end', OLD.date_end, NEW.date_end, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.date_end <=> NEW.date_end - UNION - -- Changed display_order - SELECT NEW.id_discount, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.display_order <=> NEW.display_order - UNION - -- Changed active - SELECT NEW.id_discount, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.active <=> NEW.active - ; -END // -DELIMITER ; - - - --- File: 3236_tri_Shop_Discount_Region_Currency_Link.sql - --- Shop Discount Region Currency Link - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Discount_Region_Currency_Link; -DROP TRIGGER IF EXISTS before_update_Shop_Discount_Region_Currency_Link; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Discount_Region_Currency_Link -BEFORE INSERT ON Shop_Discount_Region_Currency_Link -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Discount_Region_Currency_Link -BEFORE UPDATE ON Shop_Discount_Region_Currency_Link -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Discount_Region_Currency_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_discount - SELECT NEW.id_link, 'id_discount', CONVERT(OLD.id_discount, CHAR), CONVERT(NEW.id_discount, CHAR), NEW.id_change_set - WHERE NOT OLD.id_discount <=> NEW.id_discount - UNION - -- Changed id_region - SELECT NEW.id_link, 'id_region', CONVERT(OLD.id_region, CHAR), CONVERT(NEW.id_region, CHAR), NEW.id_change_set - WHERE NOT OLD.id_region <=> NEW.id_region - UNION - */ - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.active <=> NEW.active) - ; -END // -DELIMITER ; - --- File: 3300_tri_Shop_Permission_Group.sql - --- Shop Permission Group - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Permission_Group; -DROP TRIGGER IF EXISTS before_update_Shop_Permission_Group; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Permission_Group -BEFORE INSERT ON Shop_Permission_Group -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Permission_Group -BEFORE UPDATE ON Shop_Permission_Group -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Permission_Group_Audit ( - id_group, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_group, 'code', OLD.code, NEW.code, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_group, 'name', OLD.name, NEW.name, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed active - SELECT NEW.id_group, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_group, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.display_order <=> NEW.display_order - ; -END // -DELIMITER ; - --- File: 3303_tri_Shop_Permission.sql - --- Shop Permission - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Permission; -DROP TRIGGER IF EXISTS before_update_Shop_Permission; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Permission -BEFORE INSERT ON Shop_Permission -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Permission -BEFORE UPDATE ON Shop_Permission -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Permission_Audit ( - id_permission, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_permission, 'code', OLD.code, NEW.code, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_permission, 'name', OLD.name, NEW.name, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed id_permission_group - SELECT NEW.id_permission, 'id_permission_group', CONVERT(OLD.id_permission_group, CHAR), CONVERT(NEW.id_permission_group, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_permission_group <=> NEW.id_permission_group - UNION - -- Changed Id_access_level_required - SELECT NEW.id_permission, 'Id_access_level_required', CONVERT(OLD.Id_access_level_required, CHAR), CONVERT(NEW.Id_access_level_required, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.Id_access_level_required <=> NEW.Id_access_level_required - UNION - -- Changed active - SELECT NEW.id_permission, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_permission, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.display_order <=> NEW.display_order - ; -END // -DELIMITER ; - --- File: 3306_tri_Shop_Role.sql - --- Shop Role - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Role; -DROP TRIGGER IF EXISTS before_update_Shop_Role; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Role -BEFORE INSERT ON Shop_Role -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Role -BEFORE UPDATE ON Shop_Role -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Role_Audit ( - id_role, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_role, 'code', OLD.code, NEW.code, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_role, 'name', OLD.name, NEW.name, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed active - SELECT NEW.id_role, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_role, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.display_order <=> NEW.display_order - ; -END // -DELIMITER ; - - --- File: 3309_tri_Shop_Role_Permission_Link.sql - --- Shop Role Permission Link - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Role_Permission_Link; -DROP TRIGGER IF EXISTS before_update_Shop_Role_Permission_Link; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Role_Permission_Link -BEFORE INSERT ON Shop_Role_Permission_Link -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Role_Permission_Link -BEFORE UPDATE ON Shop_Role_Permission_Link -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Role_Permission_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_role - SELECT NEW.id_link, 'id_role', CONVERT(OLD.id_role, CHAR), CONVERT(NEW.id_role, CHAR), NEW.id_change_set - WHERE NOT OLD.id_role <=> NEW.id_role - UNION - -- Changed id_permission - SELECT NEW.id_link, 'id_permission', CONVERT(OLD.id_permission, CHAR), CONVERT(NEW.id_permission, CHAR), NEW.id_change_set - WHERE NOT OLD.id_permission <=> NEW.id_permission - UNION - */ - -- Changed id_access_level - SELECT NEW.id_link, 'id_access_level', CONVERT(OLD.id_access_level, CHAR), CONVERT(NEW.id_access_level, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_access_level <=> NEW.id_access_level - UNION - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.active <=> NEW.active) - ; -END // -DELIMITER ; - - --- File: 3312_tri_Shop_User.sql - --- Shop User - - - -DROP TRIGGER IF EXISTS before_insert_Shop_User; -DROP TRIGGER IF EXISTS before_update_Shop_User; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_User -BEFORE INSERT ON Shop_User -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_User -BEFORE UPDATE ON Shop_User -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_User_Audit ( + INSERT INTO partsltd_prod.PH_User_Audit ( id_user, name_field, value_prev, @@ -5920,81 +598,53 @@ BEGIN ) -- Changed id_user_auth0 SELECT NEW.id_user, 'id_user_auth0', OLD.id_user_auth0, NEW.id_user_auth0, NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.id_user_auth0 <=> NEW.id_user_auth0) + WHERE NOT (OLD.id_user_auth0 <=> NEW.id_user_auth0) UNION -- Changed firstname SELECT NEW.id_user, 'firstname', OLD.firstname, NEW.firstname, NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.firstname <=> NEW.firstname) + WHERE NOT (OLD.firstname <=> NEW.firstname) UNION -- Changed surname SELECT NEW.id_user, 'surname', OLD.surname, NEW.surname, NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.surname <=> NEW.surname) + WHERE NOT (OLD.surname <=> NEW.surname) UNION -- Changed email SELECT NEW.id_user, 'email', OLD.email, NEW.email, NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.email <=> NEW.email) + WHERE NOT (OLD.email <=> NEW.email) UNION -- Changed is_email_verified SELECT NEW.id_user, 'is_email_verified', CONVERT(CONVERT(OLD.is_email_verified, SIGNED), CHAR), CONVERT(CONVERT(NEW.is_email_verified, SIGNED), CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.is_email_verified <=> NEW.is_email_verified) + WHERE NOT (OLD.is_email_verified <=> NEW.is_email_verified) UNION -- Changed is_super_user SELECT NEW.id_user, 'is_super_user', CONVERT(CONVERT(OLD.is_super_user, SIGNED), CHAR), CONVERT(CONVERT(NEW.is_super_user, SIGNED), CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.is_super_user <=> NEW.is_super_user) + WHERE NOT (OLD.is_super_user <=> NEW.is_super_user) UNION -- Changed active SELECT NEW.id_user, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed id_currency_default - SELECT NEW.id_user, 'id_currency_default', CONVERT(OLD.id_currency_default, CHAR), CONVERT(NEW.id_currency_default, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.id_currency_default <=> NEW.id_currency_default) - UNION - -- Changed id_region_default - SELECT NEW.id_user, 'id_region_default', CONVERT(OLD.id_region_default, CHAR), CONVERT(NEW.id_region_default, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.id_region_default <=> NEW.id_region_default) - UNION - -- Changed is_included_VAT_default - SELECT NEW.id_user, 'is_included_VAT_default', CONVERT(CONVERT(OLD.is_included_VAT_default, SIGNED), CHAR), CONVERT(CONVERT(NEW.is_included_VAT_default, SIGNED), CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.is_included_VAT_default <=> NEW.is_included_VAT_default) + WHERE NOT (OLD.active <=> NEW.active) ; END // DELIMITER ; +USE partsltd_prod; --- File: 3315_tri_Shop_User_Role_Link.sql - --- Shop User Role Link - - - -DROP TRIGGER IF EXISTS before_insert_Shop_User_Role_Link; -DROP TRIGGER IF EXISTS before_update_Shop_User_Role_Link; +DROP TRIGGER IF EXISTS partsltd_prod.before_insert_PH_Role; +DROP TRIGGER IF EXISTS partsltd_prod.before_update_PH_Role; DELIMITER // -CREATE TRIGGER before_insert_Shop_User_Role_Link -BEFORE INSERT ON Shop_User_Role_Link +CREATE TRIGGER partsltd_prod.before_insert_PH_Role +BEFORE INSERT ON partsltd_prod.PH_Role FOR EACH ROW BEGIN SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); END // DELIMITER ; DELIMITER // -CREATE TRIGGER before_update_Shop_User_Role_Link -BEFORE UPDATE ON Shop_User_Role_Link +CREATE TRIGGER partsltd_prod.before_update_PH_Role +BEFORE UPDATE ON partsltd_prod.PH_Role FOR EACH ROW BEGIN IF OLD.id_change_set <=> NEW.id_change_set THEN @@ -6002,258 +652,51 @@ BEGIN SET MESSAGE_TEXT = 'New change Set ID must be provided.'; END IF; - INSERT INTO Shop_User_Role_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.active <=> NEW.active) - ; -END // -DELIMITER ; - --- File: 3318_tri_Shop_User_Address.sql - --- Shop Address - - - -DROP TRIGGER IF EXISTS before_insert_Shop_User_Address; -DROP TRIGGER IF EXISTS before_update_Shop_User_Address; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_User_Address -BEFORE INSERT ON Shop_User_Address -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_User_Address -BEFORE UPDATE ON Shop_User_Address -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_User_Address_Audit ( - id_user_address, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed region - SELECT NEW.id_user_address, 'id_region', OLD.id_region, NEW.id_region, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_region <=> NEW.id_region - UNION - -- Changed name_full - SELECT NEW.id_user_address, 'name_full', OLD.name_full, NEW.name_full, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.name_full <=> NEW.name_full - UNION - -- Changed phone_number - SELECT NEW.id_user_address, 'phone_number', OLD.phone_number, NEW.phone_number, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.phone_number <=> NEW.phone_number - UNION - -- Changed postcode - SELECT NEW.id_user_address, 'postcode', OLD.postcode, NEW.postcode, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.postcode <=> NEW.postcode - UNION - -- Changed address_line_1 - SELECT NEW.id_user_address, 'address_line_1', OLD.address_line_1, NEW.address_line_1, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.address_line_1 <=> NEW.address_line_1 - UNION - -- Changed address_line_2 - SELECT NEW.id_user_address, 'address_line_2', OLD.address_line_2, NEW.address_line_2, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.address_line_2 <=> NEW.address_line_2 - UNION - -- Changed city - SELECT NEW.id_user_address, 'city', OLD.city, NEW.city, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.city <=> NEW.city - UNION - -- Changed county - SELECT NEW.id_user_address, 'county', OLD.county, NEW.county, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.county <=> NEW.county - UNION - -- Changed active - SELECT NEW.id_user_address, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.active <=> NEW.active) - ; -END // -DELIMITER ; - --- File: 3321_tri_Shop_User_Basket.sql - --- Shop Product Variation Link - - - -DROP TRIGGER IF EXISTS before_insert_Shop_User_Basket; -DROP TRIGGER IF EXISTS before_update_Shop_User_Basket; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_User_Basket -BEFORE INSERT ON Shop_User_Basket -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_User_Basket -BEFORE UPDATE ON Shop_User_Basket -FOR EACH ROW -BEGIN - IF NEW.id_change_set_user <=> OLD.id_change_set_user THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_User_Basket_Audit ( - id_item, - name_field, - value_prev, - value_new, - id_change_set_user - ) - -- Changed id_user - SELECT NEW.id_item, 'id_user', OLD.id_user, NEW.id_user, NEW.id_change_set_user - FROM DUAL - WHERE NOT OLD.id_user <=> NEW.id_user - UNION - -- Changed id_product - SELECT NEW.id_item, 'id_product', OLD.id_product, NEW.id_product, NEW.id_change_set_user - FROM DUAL - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed quantity - SELECT NEW.id_item, 'quantity', CONVERT(OLD.quantity, CHAR), CONVERT(NEW.quantity, CHAR), NEW.id_change_set_user - FROM DUAL - WHERE NOT (OLD.quantity <=> NEW.quantity) - UNION - -- Changed active - SELECT NEW.id_item, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set_user - FROM DUAL - WHERE NOT (OLD.active <=> NEW.active) - ; -END // -DELIMITER ; - --- File: 3324_tri_Shop_User_Order_Status.sql - --- Shop User Order Type - - - -DROP TRIGGER IF EXISTS before_insert_Shop_User_Order_Status; -DROP TRIGGER IF EXISTS before_update_Shop_User_Order_Status; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_User_Order_Status -BEFORE INSERT ON Shop_User_Order_Status -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_User_Order_Status -BEFORE UPDATE ON Shop_User_Order_Status -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_User_Order_Status_Audit ( - id_Status, + INSERT INTO partsltd_prod.PH_Role_Audit ( + id_role, name_field, value_prev, value_new, id_change_set ) -- Changed code - SELECT NEW.id_Status, 'code', OLD.code, NEW.code, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_Status, 'name', OLD.name, NEW.name, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed name_plural - SELECT NEW.id_Status, 'name_plural', OLD.name_plural, NEW.name_plural, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.name_plural <=> NEW.name_plural + SELECT NEW.id_role, 'code', OLD.code, NEW.code, NEW.id_change_set + WHERE NOT OLD.code <=> NEW.code + UNION + -- Changed name + SELECT NEW.id_role, 'name', OLD.name, NEW.name, NEW.id_change_set + WHERE NOT OLD.name <=> NEW.name UNION -- Changed active - SELECT NEW.id_Status, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_Status, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.display_order <=> NEW.display_order) + SELECT NEW.id_role, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set + WHERE NOT (OLD.active <=> NEW.active) + UNION + -- Changed display_order + SELECT NEW.id_role, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set + WHERE NOT OLD.display_order <=> NEW.display_order ; END // DELIMITER ; --- File: 3400_tri_Shop_Supplier.sql +USE partsltd_prod; --- Shop Supplier - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Supplier; -DROP TRIGGER IF EXISTS before_update_Shop_Supplier; +DROP TRIGGER IF EXISTS partsltd_prod.before_insert_PH_Role_Permission_Link; +DROP TRIGGER IF EXISTS partsltd_prod.before_update_PH_Role_Permission_Link; DELIMITER // -CREATE TRIGGER before_insert_Shop_Supplier -BEFORE INSERT ON Shop_Supplier +CREATE TRIGGER partsltd_prod.before_insert_PH_Role_Permission_Link +BEFORE INSERT ON partsltd_prod.PH_Role_Permission_Link FOR EACH ROW BEGIN SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); END // DELIMITER ; DELIMITER // -CREATE TRIGGER before_update_Shop_Supplier -BEFORE UPDATE ON Shop_Supplier +CREATE TRIGGER partsltd_prod.before_update_PH_Role_Permission_Link +BEFORE UPDATE ON partsltd_prod.PH_Role_Permission_Link FOR EACH ROW BEGIN IF OLD.id_change_set <=> NEW.id_change_set THEN @@ -6261,855 +704,51 @@ BEGIN SET MESSAGE_TEXT = 'New change Set ID must be provided.'; END IF; - INSERT INTO Shop_Supplier_Audit ( - id_supplier, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed name_company - SELECT NEW.id_supplier, 'name_company', OLD.name_company, NEW.name_company, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.name_company <=> NEW.name_company - UNION - -- Changed name_contact - SELECT NEW.id_supplier, 'name_contact', OLD.name_contact, NEW.name_contact, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.name_contact <=> NEW.name_contact - UNION - -- Changed department_contact - SELECT NEW.id_supplier, 'department_contact', OLD.department_contact, NEW.department_contact, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.department_contact <=> NEW.department_contact - UNION - /* - -- Changed id_address - SELECT NEW.id_supplier, 'id_address', OLD.id_address, NEW.id_address, NEW.id_change_set - WHERE NOT OLD.id_address <=> NEW.id_address - UNION - */ - -- Changed phone_number - SELECT NEW.id_supplier, 'phone_number', OLD.phone_number, NEW.phone_number, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.phone_number <=> NEW.phone_number - UNION - -- Changed fax - SELECT NEW.id_supplier, 'fax', OLD.fax, NEW.fax, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.fax <=> NEW.fax - UNION - -- Changed email - SELECT NEW.id_supplier, 'email', OLD.email, NEW.email, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.email <=> NEW.email - UNION - -- Changed website - SELECT NEW.id_supplier, 'website', OLD.website, NEW.website, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.website <=> NEW.website - UNION - -- Changed id_currency - SELECT NEW.id_supplier, 'id_currency', OLD.id_currency, NEW.id_currency, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_currency <=> NEW.id_currency - UNION - -- Changed id_supplier_temp - SELECT NEW.id_supplier, 'id_supplier_temp', OLD.id_supplier_temp, NEW.id_supplier_temp, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_supplier_temp <=> NEW.id_supplier_temp - ; -END // -DELIMITER ; - - --- File: 3403_tri_Shop_Supplier_Address.sql - --- Shop Supplier Address - -DROP TRIGGER IF EXISTS before_insert_Shop_Supplier_Address; -DROP TRIGGER IF EXISTS before_update_Shop_Supplier_Address; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Supplier_Address -BEFORE INSERT ON Shop_Supplier_Address -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Supplier_Address -BEFORE UPDATE ON Shop_Supplier_Address -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Supplier_Address_Audit ( - id_address, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed region - SELECT NEW.id_address, 'id_region', OLD.id_region, NEW.id_region, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_region <=> NEW.id_region - UNION - -- Changed postcode - SELECT NEW.id_address, 'postcode', OLD.postcode, NEW.postcode, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.postcode <=> NEW.postcode - UNION - -- Changed address_line_1 - SELECT NEW.id_address, 'address_line_1', OLD.address_line_1, NEW.address_line_1, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.address_line_1 <=> NEW.address_line_1 - UNION - -- Changed address_line_2 - SELECT NEW.id_address, 'address_line_2', OLD.address_line_2, NEW.address_line_2, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.address_line_2 <=> NEW.address_line_2 - UNION - -- Changed city - SELECT NEW.id_address, 'city', OLD.city, NEW.city, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.city <=> NEW.city - UNION - -- Changed county - SELECT NEW.id_address, 'county', OLD.county, NEW.county, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.county <=> NEW.county - UNION - -- Changed active - SELECT NEW.id_address, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - FROM DUAL - WHERE NOT (OLD.active <=> NEW.active) - ; -END // -DELIMITER ; - --- File: 3403_tri_Shop_Unit_Measurement.sql - --- Shop Unit of Measurement - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Unit_Measurement; -DROP TRIGGER IF EXISTS before_update_Shop_Unit_Measurement; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Unit_Measurement -BEFORE INSERT ON Shop_Unit_Measurement -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Unit_Measurement -BEFORE UPDATE ON Shop_Unit_Measurement -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Unit_Measurement_Audit ( - id_unit_measurement, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed name_singular - SELECT NEW.id_unit_measurement, 'name_singular', OLD.name_singular, NEW.name_singular, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.name_singular <=> NEW.name_singular - UNION - -- Changed name_plural - SELECT NEW.id_unit_measurement, 'name_plural', OLD.name_plural, NEW.name_plural, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.name_plural <=> NEW.name_plural - UNION - -- Changed symbol - SELECT NEW.id_unit_measurement, 'symbol', OLD.symbol, NEW.symbol, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.symbol <=> NEW.symbol - UNION - -- Changed is_base_unit - SELECT NEW.id_unit_measurement, 'is_base_unit', OLD.is_base_unit, NEW.is_base_unit, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.is_base_unit <=> NEW.is_base_unit - UNION - -- Changed is_unit_of_distance - SELECT NEW.id_unit_measurement, 'is_unit_of_distance', OLD.is_unit_of_distance, NEW.is_unit_of_distance, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.is_unit_of_distance <=> NEW.is_unit_of_distance - UNION - -- Changed is_unit_of_mass - SELECT NEW.id_unit_measurement, 'is_unit_of_mass', OLD.is_unit_of_mass, NEW.is_unit_of_mass, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.is_unit_of_mass <=> NEW.is_unit_of_mass - UNION - -- Changed is_unit_of_time - SELECT NEW.id_unit_measurement, 'is_unit_of_time', OLD.is_unit_of_time, NEW.is_unit_of_time, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.is_unit_of_time <=> NEW.is_unit_of_time - UNION - -- Changed is_unit_of_volume - SELECT NEW.id_unit_measurement, 'is_unit_of_volume', OLD.is_unit_of_volume, NEW.is_unit_of_volume, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.is_unit_of_volume <=> NEW.is_unit_of_volume - UNION - -- Changed active - SELECT NEW.id_unit_measurement, 'active', OLD.active, NEW.active, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.active <=> NEW.active - ; -END // -DELIMITER ; - - - --- File: 3406_tri_Shop_Unit_Of_Measurement_Conversion.sql - --- Shop Unit of Measurement Conversion - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Unit_Measurement_Conversion; -DROP TRIGGER IF EXISTS before_update_Shop_Unit_Measurement_Conversion; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Unit_Measurement_Conversion -BEFORE INSERT ON Shop_Unit_Measurement_Conversion -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Unit_Measurement_Conversion -BEFORE UPDATE ON Shop_Unit_Measurement_Conversion -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Unit_Measurement_Conversion_Audit ( - id_conversion, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_unit_derived - SELECT NEW.id_conversion, 'id_unit_derived', OLD.id_unit_derived, NEW.id_unit_derived, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_unit_derived <=> NEW.id_unit_derived - UNION - -- Changed id_unit_base - SELECT NEW.id_conversion, 'id_unit_base', OLD.id_unit_base, NEW.id_unit_base, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_unit_base <=> NEW.id_unit_base - UNION - -- Changed multiplier_unit_base - SELECT NEW.id_conversion, 'multiplier_unit_base', OLD.multiplier_unit_base, NEW.multiplier_unit_base, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.multiplier_unit_base <=> NEW.multiplier_unit_base - UNION - -- Changed increment_unit_base - SELECT NEW.id_conversion, 'active', OLD.increment_unit_base, NEW.increment_unit_base, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.increment_unit_base <=> NEW.increment_unit_base - UNION - -- Changed apply_multiplier_before_increment - SELECT NEW.id_conversion, 'apply_multiplier_before_increment', OLD.apply_multiplier_before_increment, NEW.apply_multiplier_before_increment, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.apply_multiplier_before_increment <=> NEW.apply_multiplier_before_increment - UNION - -- Changed active - SELECT NEW.id_conversion, 'active', OLD.active, NEW.active, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.active <=> NEW.active - ; -END // -DELIMITER ; - - - --- File: 3409_tri_Shop_Supplier_Purchase_Order.sql - --- Shop Supplier Purchase Order - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Supplier_Purchase_Order; -DROP TRIGGER IF EXISTS before_update_Shop_Supplier_Purchase_Order; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Supplier_Purchase_Order -BEFORE INSERT ON Shop_Supplier_Purchase_Order -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Supplier_Purchase_Order -BEFORE UPDATE ON Shop_Supplier_Purchase_Order -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Supplier_Purchase_Order_Audit ( - id_order, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_order_temp - SELECT NEW.id_order, 'id_order_temp', OLD.id_order_temp, NEW.id_order_temp, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_order_temp <=> NEW.id_order_temp - UNION - -- Changed id_supplier_ordered - SELECT NEW.id_order, 'id_supplier_ordered', OLD.id_supplier_ordered, NEW.id_supplier_ordered, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_supplier_ordered <=> NEW.id_supplier_ordered - UNION - -- Changed id_currency_cost - SELECT NEW.id_order, 'id_currency_cost', OLD.id_currency_cost, NEW.id_currency_cost, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_currency_cost <=> NEW.id_currency_cost - UNION - -- Changed cost_total_local_VAT_excl - SELECT NEW.id_order, 'cost_total_local_VAT_excl', OLD.cost_total_local_VAT_excl, NEW.cost_total_local_VAT_excl, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.cost_total_local_VAT_excl <=> NEW.cost_total_local_VAT_excl - UNION - -- Changed cost_total_local_VAT_incl - SELECT NEW.id_order, 'cost_total_local_VAT_incl', OLD.cost_total_local_VAT_incl, NEW.cost_total_local_VAT_incl, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.cost_total_local_VAT_incl <=> NEW.cost_total_local_VAT_incl - /* - UNION - -- Changed latency_delivery - SELECT NEW.id_order, 'latency_delivery', OLD.latency_delivery, NEW.latency_delivery, NEW.id_change_set - WHERE NOT OLD.latency_delivery <=> NEW.latency_delivery - UNION - -- Changed quantity_ordered - SELECT NEW.id_order, 'quantity_ordered', OLD.quantity_ordered, NEW.quantity_ordered, NEW.id_change_set - WHERE NOT OLD.quantity_ordered <=> NEW.quantity_ordered - UNION - -- Changed id_unit_quantity - SELECT NEW.id_order, 'id_unit_quantity', OLD.id_unit_quantity, NEW.id_unit_quantity, NEW.id_change_set - WHERE NOT OLD.id_unit_quantity <=> NEW.id_unit_quantity - UNION - -- Changed quantity_received - SELECT NEW.id_order, 'quantity_received', OLD.quantity_received, NEW.quantity_received, NEW.id_change_set - WHERE NOT OLD.quantity_received <=> NEW.quantity_received - */ - ; -END // -DELIMITER ; - - - --- File: 3412_tri_Shop_Supplier_Purchase_Order_Product_Link.sql - --- Shop Supplier Purchase Order Product Link - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Supplier_Purchase_Order_Product_Link; -DROP TRIGGER IF EXISTS before_update_Shop_Supplier_Purchase_Order_Product_Link; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Supplier_Purchase_Order_Product_Link -BEFORE INSERT ON Shop_Supplier_Purchase_Order_Product_Link -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Supplier_Purchase_Order_Product_Link -BEFORE UPDATE ON Shop_Supplier_Purchase_Order_Product_Link -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Supplier_Purchase_Order_Product_Link_Audit ( + INSERT INTO partsltd_prod.PH_Role_Permission_Link_Audit ( id_link, name_field, value_prev, value_new, id_change_set ) - -- Changed id_order - SELECT NEW.id_link, 'id_order', OLD.id_order, NEW.id_order, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_order <=> NEW.id_order + -- Changed id_role + SELECT NEW.id_link, 'id_role', CONVERT(OLD.id_role, CHAR), CONVERT(NEW.id_role, CHAR), NEW.id_change_set + WHERE NOT OLD.id_role <=> NEW.id_role + UNION + -- Changed id_permission + SELECT NEW.id_link, 'id_permission', CONVERT(OLD.id_permission, CHAR), CONVERT(NEW.id_permission, CHAR), NEW.id_change_set + WHERE NOT OLD.id_permission <=> NEW.id_permission UNION - -- Changed id_permutation - SELECT NEW.id_link, 'id_permutation', OLD.id_permutation, NEW.id_permutation, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_permutation <=> NEW.id_permutation - UNION - /* - -- Changed id_currency_cost - SELECT NEW.id_link, 'id_currency_cost', OLD.id_currency_cost, NEW.id_currency_cost, NEW.id_change_set - WHERE NOT OLD.id_currency_cost <=> NEW.id_currency_cost - UNION - */ - -- Changed quantity_ordered - SELECT NEW.id_link, 'quantity_ordered', OLD.quantity_ordered, NEW.quantity_ordered, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.quantity_ordered <=> NEW.quantity_ordered - UNION - -- Changed id_unit_quantity - SELECT NEW.id_link, 'id_unit_quantity', OLD.id_unit_quantity, NEW.id_unit_quantity, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_unit_quantity <=> NEW.id_unit_quantity - UNION - -- Changed quantity_received - SELECT NEW.id_link, 'quantity_received', OLD.quantity_received, NEW.quantity_received, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.quantity_received <=> NEW.quantity_received - UNION - -- Changed latency_delivery_days - SELECT NEW.id_link, 'latency_delivery_days', OLD.latency_delivery_days, NEW.latency_delivery_days, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.latency_delivery_days <=> NEW.latency_delivery_days - UNION - -- Changed display_order - SELECT NEW.id_link, 'display_order', OLD.display_order, NEW.display_order, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.display_order <=> NEW.display_order - UNION - -- Changed active - SELECT NEW.id_link, 'active', OLD.active, NEW.active, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.active <=> NEW.active - UNION - -- Changed cost_total_local_VAT_excl - SELECT NEW.id_link, 'cost_total_local_VAT_excl', OLD.cost_total_local_VAT_excl, NEW.cost_total_local_VAT_excl, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.cost_total_local_VAT_excl <=> NEW.cost_total_local_VAT_excl - UNION - -- Changed cost_total_local_VAT_incl - SELECT NEW.id_link, 'cost_total_local_VAT_incl', OLD.cost_total_local_VAT_incl, NEW.cost_total_local_VAT_incl, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.cost_total_local_VAT_incl <=> NEW.cost_total_local_VAT_incl - UNION - -- Changed cost_unit_local_VAT_excl - SELECT NEW.id_link, 'cost_unit_local_VAT_excl', OLD.cost_unit_local_VAT_excl, NEW.cost_unit_local_VAT_excl, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.cost_unit_local_VAT_excl <=> NEW.cost_unit_local_VAT_excl - UNION - -- Changed cost_unit_local_VAT_incl - SELECT NEW.id_link, 'cost_unit_local_VAT_incl', OLD.cost_unit_local_VAT_incl, NEW.cost_unit_local_VAT_incl, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.cost_unit_local_VAT_incl <=> NEW.cost_unit_local_VAT_incl - ; -END // -DELIMITER ; - - --- File: 3415_tri_Shop_Manufacturing_Purchase_Order.sql - --- Shop Manufacturing Purchase Order - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Manufacturing_Purchase_Order; -DROP TRIGGER IF EXISTS before_update_Shop_Manufacturing_Purchase_Order; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Manufacturing_Purchase_Order -BEFORE INSERT ON Shop_Manufacturing_Purchase_Order -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - -- SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - IF NOT EXISTS (SELECT * FROM partsltd_prod.Shop_User U WHERE U.id_user = NEW.created_by LIMIT 1) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Valid created by User ID must be provided.'; - END IF; -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Manufacturing_Purchase_Order -BEFORE UPDATE ON Shop_Manufacturing_Purchase_Order -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Manufacturing_Purchase_Order_Audit ( - id_order, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_order_temp - SELECT NEW.id_order, 'id_order_temp', OLD.id_order_temp, NEW.id_order_temp, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_order_temp <=> NEW.id_order_temp - UNION - -- Changed id_currency - SELECT NEW.id_order, 'id_currency', OLD.id_currency, NEW.id_currency, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_currency <=> NEW.id_currency - UNION - -- Changed cost_total_local_VAT_excl - SELECT NEW.id_order, 'cost_total_local_VAT_excl', OLD.cost_total_local_VAT_excl, NEW.cost_total_local_VAT_excl, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.cost_total_local_VAT_excl <=> NEW.cost_total_local_VAT_excl - UNION - -- Changed cost_total_local_VAT_incl - SELECT NEW.id_order, 'cost_total_local_VAT_incl', OLD.cost_total_local_VAT_incl, NEW.cost_total_local_VAT_incl, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.cost_total_local_VAT_incl <=> NEW.cost_total_local_VAT_incl - UNION - -- Changed price_total_local_VAT_excl - SELECT NEW.id_order, 'price_total_local_VAT_excl', OLD.price_total_local_VAT_excl, NEW.price_total_local_VAT_excl, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.price_total_local_VAT_excl <=> NEW.price_total_local_VAT_excl - UNION - -- Changed price_total_local_VAT_incl - SELECT NEW.id_order, 'price_total_local_VAT_incl', OLD.price_total_local_VAT_incl, NEW.price_total_local_VAT_incl, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.price_total_local_VAT_incl <=> NEW.price_total_local_VAT_incl - UNION - -- Changed active - SELECT NEW.id_order, 'active', OLD.active, NEW.active, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.active <=> NEW.active - ; -END // -DELIMITER ; - - --- File: 3418_tri_Shop_Manufacturing_Purchase_Order_Product_Link.sql - --- Shop Manufacturing Purchase Order Product Link - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Manufacturing_Purchase_Order_Product_Link; -DROP TRIGGER IF EXISTS before_update_Shop_Manufacturing_Purchase_Order_Product_Link; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Manufacturing_Purchase_Order_Product_Link -BEFORE INSERT ON Shop_Manufacturing_Purchase_Order_Product_Link -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Manufacturing_Purchase_Order_Product_Link -BEFORE UPDATE ON Shop_Manufacturing_Purchase_Order_Product_Link -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Manufacturing_Purchase_Order_Product_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_order - SELECT NEW.id_link, 'id_order', OLD.id_order, NEW.id_order, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_order <=> NEW.id_order - UNION - -- Changed id_permutation - SELECT NEW.id_link, 'id_permutation', OLD.id_permutation, NEW.id_permutation, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_permutation <=> NEW.id_permutation - UNION - -- Changed id_unit_quantity - SELECT NEW.id_link, 'id_unit_quantity', OLD.id_unit_quantity, NEW.id_unit_quantity, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_unit_quantity <=> NEW.id_unit_quantity - UNION - -- Changed quantity_used - SELECT NEW.id_link, 'quantity_used', OLD.quantity_used, NEW.quantity_used, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.quantity_used <=> NEW.quantity_used - UNION - -- Changed quantity_produced - SELECT NEW.id_link, 'quantity_produced', OLD.quantity_produced, NEW.quantity_produced, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.quantity_produced <=> NEW.quantity_produced - UNION - -- Changed cost_unit_local_VAT_excl - SELECT NEW.id_order, 'cost_unit_local_VAT_excl', OLD.cost_unit_local_VAT_excl, NEW.cost_unit_local_VAT_excl, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.cost_unit_local_VAT_excl <=> NEW.cost_unit_local_VAT_excl - UNION - -- Changed cost_unit_local_VAT_incl - SELECT NEW.id_order, 'cost_unit_local_VAT_incl', OLD.cost_unit_local_VAT_incl, NEW.cost_unit_local_VAT_incl, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.cost_unit_local_VAT_incl <=> NEW.cost_unit_local_VAT_incl - UNION - -- Changed price_unit_local_VAT_excl - SELECT NEW.id_order, 'price_unit_local_VAT_excl', OLD.price_unit_local_VAT_excl, NEW.price_unit_local_VAT_excl, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.price_unit_local_VAT_excl <=> NEW.price_unit_local_VAT_excl - UNION - -- Changed price_unit_local_VAT_incl - SELECT NEW.id_order, 'price_unit_local_VAT_incl', OLD.price_unit_local_VAT_incl, NEW.price_unit_local_VAT_incl, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.price_unit_local_VAT_incl <=> NEW.price_unit_local_VAT_incl - UNION - -- Changed id_unit_latency_manufacture - SELECT NEW.id_link, 'id_unit_latency_manufacture', OLD.id_unit_latency_manufacture, NEW.id_unit_latency_manufacture, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_unit_latency_manufacture <=> NEW.id_unit_latency_manufacture - UNION - -- Changed latency_manufacture - SELECT NEW.id_link, 'latency_manufacture', OLD.latency_manufacture, NEW.latency_manufacture, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.latency_manufacture <=> NEW.latency_manufacture - UNION - -- Changed display_order - SELECT NEW.id_link, 'display_order', OLD.display_order, NEW.display_order, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.display_order <=> NEW.display_order - UNION - -- Changed active - SELECT NEW.id_link, 'active', OLD.active, NEW.active, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.active <=> NEW.active - ; -END // -DELIMITER ; - - - --- File: 3421_tri_Shop_Customer.sql - --- Shop Customer - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Customer; -DROP TRIGGER IF EXISTS before_update_Shop_Customer; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Customer -BEFORE INSERT ON Shop_Customer -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Customer -BEFORE UPDATE ON Shop_Customer -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Customer_Audit ( - id_customer, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed name_company - SELECT NEW.id_customer, 'name_company', OLD.name_company, NEW.name_company, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.name_company <=> NEW.name_company - UNION - -- Changed name_contact - SELECT NEW.id_customer, 'name_contact', OLD.name_contact, NEW.name_contact, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.name_contact <=> NEW.name_contact - UNION - -- Changed department_contact - SELECT NEW.id_customer, 'department_contact', OLD.department_contact, NEW.department_contact, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.department_contact <=> NEW.department_contact - UNION - -- Changed id_address - SELECT NEW.id_customer, 'id_address', OLD.id_address, NEW.id_address, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_address <=> NEW.id_address - UNION - -- Changed phone_number - SELECT NEW.id_customer, 'phone_number', OLD.phone_number, NEW.phone_number, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.phone_number <=> NEW.phone_number - UNION - -- Changed email - SELECT NEW.id_customer, 'email', OLD.email, NEW.email, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.email <=> NEW.email - UNION - -- Changed id_currency - SELECT NEW.id_customer, 'id_currency', OLD.id_currency, NEW.id_currency, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_currency <=> NEW.id_currency - UNION - -- Changed active - SELECT NEW.id_customer, 'active', OLD.active, NEW.active, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.active <=> NEW.active - ; -END // -DELIMITER ; - - - --- File: 3424_tri_Shop_Customer_Sales_Order.sql - --- Shop Customer Sales Order - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Customer_Sales_Order; -DROP TRIGGER IF EXISTS before_update_Shop_Customer_Sales_Order; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Customer_Sales_Order -BEFORE INSERT ON Shop_Customer_Sales_Order -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Customer_Sales_Order -BEFORE UPDATE ON Shop_Customer_Sales_Order -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Customer_Sales_Order_Audit ( - id_order, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_customer - SELECT NEW.id_order, 'id_customer', OLD.id_customer, NEW.id_customer, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_customer <=> NEW.id_customer - UNION - -- Changed price_total_local - SELECT NEW.id_order, 'price_total_local', OLD.price_total_local, NEW.price_total_local, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.price_total_local <=> NEW.price_total_local - UNION - -- Changed id_currency_price - SELECT NEW.id_order, 'id_currency_price', OLD.id_currency_price, NEW.id_currency_price, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_currency_price <=> NEW.id_currency_price + -- Changed id_access_level + SELECT NEW.id_link, 'id_access_level', CONVERT(OLD.id_access_level, CHAR), CONVERT(NEW.id_access_level, CHAR), NEW.id_change_set + WHERE NOT OLD.id_access_level <=> NEW.id_access_level UNION -- Changed active - SELECT NEW.id_order, 'active', OLD.active, NEW.active, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.active <=> NEW.active + SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set + WHERE NOT (OLD.active <=> NEW.active) ; END // DELIMITER ; +USE partsltd_prod; --- File: 3427_tri_Shop_Customer_Sales_Order_Product_Link.sql - --- Shop Customer Sales Order Product Link - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Customer_Sales_Order_Product_Link; -DROP TRIGGER IF EXISTS before_update_Shop_Customer_Sales_Order_Product_Link; +DROP TRIGGER IF EXISTS partsltd_prod.before_insert_PH_User_Role_Link; +DROP TRIGGER IF EXISTS partsltd_prod.before_update_PH_User_Role_Link; DELIMITER // -CREATE TRIGGER before_insert_Shop_Customer_Sales_Order_Product_Link -BEFORE INSERT ON Shop_Customer_Sales_Order_Product_Link +CREATE TRIGGER partsltd_prod.before_insert_PH_User_Role_Link +BEFORE INSERT ON partsltd_prod.PH_User_Role_Link FOR EACH ROW BEGIN SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); END // DELIMITER ; DELIMITER // -CREATE TRIGGER before_update_Shop_Customer_Sales_Order_Product_Link -BEFORE UPDATE ON Shop_Customer_Sales_Order_Product_Link +CREATE TRIGGER partsltd_prod.before_update_PH_User_Role_Link +BEFORE UPDATE ON partsltd_prod.PH_User_Role_Link FOR EACH ROW BEGIN IF OLD.id_change_set <=> NEW.id_change_set THEN @@ -7117,80 +756,138 @@ BEGIN SET MESSAGE_TEXT = 'New change Set ID must be provided.'; END IF; - INSERT INTO Shop_Customer_Sales_Order_Product_Link_Audit ( + INSERT INTO partsltd_prod.PH_User_Role_Link_Audit ( id_link, name_field, value_prev, value_new, id_change_set ) - -- Changed id_order - SELECT NEW.id_link, 'id_order', OLD.id_order, NEW.id_order, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_order <=> NEW.id_order - UNION - -- Changed id_permutation - SELECT NEW.id_link, 'id_permutation', OLD.id_permutation, NEW.id_permutation, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_permutation <=> NEW.id_permutation - UNION - -- Changed price_total_local - SELECT NEW.id_link, 'price_total_local', OLD.price_total_local, NEW.price_total_local, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.price_total_local <=> NEW.price_total_local - UNION - -- Changed id_currency_price - SELECT NEW.id_link, 'id_currency_price', OLD.id_currency_price, NEW.id_currency_price, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_currency_price <=> NEW.id_currency_price - UNION - -- Changed quantity_ordered - SELECT NEW.id_link, 'quantity_ordered', OLD.quantity_ordered, NEW.quantity_ordered, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.quantity_ordered <=> NEW.quantity_ordered - UNION - -- Changed id_unit_quantity - SELECT NEW.id_link, 'id_unit_quantity', OLD.id_unit_quantity, NEW.id_unit_quantity, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.id_unit_quantity <=> NEW.id_unit_quantity - UNION - -- Changed quantity_delivered - SELECT NEW.id_link, 'quantity_delivered', OLD.quantity_delivered, NEW.quantity_delivered, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.quantity_delivered <=> NEW.quantity_delivered - UNION - -- Changed latency_delivery_days - SELECT NEW.id_link, 'latency_delivery_days', OLD.latency_delivery_days, NEW.latency_delivery_days, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.latency_delivery_days <=> NEW.latency_delivery_days - UNION - -- Changed display_order - SELECT NEW.id_link, 'display_order', OLD.display_order, NEW.display_order, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.display_order <=> NEW.display_order + -- Changed id_user + SELECT NEW.id_link, 'id_user', CONVERT(OLD.id_user, CHAR), CONVERT(NEW.id_user, CHAR), NEW.id_change_set + WHERE NOT OLD.id_user <=> NEW.id_user UNION + -- Changed id_role + SELECT NEW.id_link, 'id_role', CONVERT(OLD.id_role, CHAR), CONVERT(NEW.id_role, CHAR), NEW.id_change_set + WHERE NOT OLD.id_role <=> NEW.id_role + UNION -- Changed active - SELECT NEW.id_link, 'active', OLD.active, NEW.active, NEW.id_change_set - FROM DUAL - WHERE NOT OLD.active <=> NEW.active + SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set + WHERE NOT (OLD.active <=> NEW.active) + ; +END // +DELIMITER ;USE partsltd_prod; + +DROP TRIGGER IF EXISTS partsltd_prod.before_insert_PH_Contact_Form_Change_Set; + +DELIMITER // +CREATE TRIGGER partsltd_prod.before_insert_PH_Contact_Form_Change_Set +BEFORE INSERT ON partsltd_prod.PH_Contact_Form_Change_Set +FOR EACH ROW +BEGIN + IF NEW.updated_last_on <=> NULL THEN + SET NEW.updated_last_on = NOW(); + END IF; +END // +DELIMITER ; + +USE partsltd_prod; + +DROP TRIGGER IF EXISTS partsltd_prod.before_insert_PH_Contact_Form; +DROP TRIGGER IF EXISTS partsltd_prod.before_update_PH_Contact_Form; + +DELIMITER // +CREATE TRIGGER partsltd_prod.before_insert_PH_Contact_Form +BEFORE INSERT ON partsltd_prod.PH_Contact_Form +FOR EACH ROW +BEGIN + SET NEW.created_on := IFNULL(NEW.created_on, NOW()); +END // +DELIMITER ; + +DELIMITER // +CREATE TRIGGER partsltd_prod.before_update_PH_Contact_Form +BEFORE UPDATE ON partsltd_prod.PH_Contact_Form +FOR EACH ROW +BEGIN + IF OLD.id_change_set <=> NEW.id_change_set THEN + SIGNAL SQLSTATE '45000' + SET MESSAGE_TEXT = 'New change Set ID must be provided.'; + END IF; + + INSERT INTO partsltd_prod.PH_Contact_Form_Audit ( + id_contact_form, + name_field, + value_prev, + value_new, + id_change_set + ) + -- Changed email + SELECT NEW.id_contact_form, 'email', OLD.email, NEW.email, NEW.id_change_set + WHERE NOT OLD.email <=> NEW.email + UNION + -- Changed name_contact + SELECT NEW.id_contact_form, 'name_contact', OLD.name_contact, NEW.name_contact, NEW.id_change_set + WHERE NOT OLD.name_contact <=> NEW.name_contact + UNION + -- Changed name_company + SELECT NEW.id_contact_form, 'name_company', OLD.name_company, NEW.name_company, NEW.id_change_set + WHERE NOT OLD.name_company <=> NEW.name_company + UNION + -- Changed message + SELECT NEW.id_contact_form, 'message', OLD.message, NEW.message, NEW.id_change_set + WHERE NOT OLD.message <=> NEW.message + UNION + -- Changed receive_marketing_communications + SELECT NEW.id_contact_form, 'receive_marketing_communications', CONVERT(CONVERT(OLD.receive_marketing_communications, SIGNED), CHAR), CONVERT(CONVERT(NEW.receive_marketing_communications, SIGNED), CHAR), NEW.id_change_set + WHERE NOT (OLD.receive_marketing_communications <=> NEW.receive_marketing_communications) + UNION + -- Changed active + SELECT NEW.id_contact_form, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set + WHERE NOT (OLD.active <=> NEW.active) ; END // DELIMITER ; +USE partsltd_prod; --- File: 6000_p_debug_timing_reporting.sql --- USE partsltd_prod; - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_debug_timing_reporting; +DROP PROCEDURE IF EXISTS partsltd_prod.p_core_validate_guid; +DROP PROCEDURE IF EXISTS partsltd_prod.p_core_validate_guid_test; DELIMITER // -CREATE PROCEDURE p_debug_timing_reporting ( +CREATE PROCEDURE partsltd_prod.p_core_validate_guid ( + IN a_guid BINARY(36) +) +BEGIN + IF ISNULL(a_guid) THEN + SIGNAL SQLSTATE '45000' + SET MESSAGE_TEXT = 'GUID is required.' + ; + END IF; +END // +DELIMITER ; + + +DELIMITER // +CREATE PROCEDURE partsltd_prod.p_core_validate_guid_test () +BEGIN + CALL partsltd_prod.p_core_validate_guid ( 'nips' ); + CALL partsltd_prod.p_core_validate_guid ( NULL ); +END // +DELIMITER ; + +-- CALL partsltd_prod.p_core_validate_guid_test(); +USE partsltd_prod; + +DROP PROCEDURE IF EXISTS partsltd_prod.p_core_debug_timing_reporting; + +DELIMITER // +CREATE PROCEDURE partsltd_prod.p_core_debug_timing_reporting ( IN a_time_start TIMESTAMP(6) ) BEGIN /* - PROCEDURE p_debug_timing_reporting + PROCEDURE partsltd_prod.p_core_debug_timing_reporting Shared method timing reporting */ DECLARE v_time_end TIMESTAMP(6); @@ -7218,19 +915,17 @@ END // DELIMITER ; /* -CALL partsltd_prod.p_debug_timing_reporting ( +CALL partsltd_prod.p_core_debug_timing_reporting ( CURRENT_TIMESTAMP(6) ); */ +USE partsltd_prod; --- File: 6000_p_split.sql - - -DROP PROCEDURE IF EXISTS p_split; +DROP PROCEDURE IF EXISTS partsltd_prod.p_core_split; DELIMITER // -CREATE PROCEDURE p_split ( - IN a_guid BINARY(36) +CREATE PROCEDURE partsltd_prod.p_core_split ( + IN a_guid BINARY(36) , IN a_string LONGTEXT , IN a_separator VARCHAR(1000) -- IN a_allow_empty BIT @@ -7252,14 +947,14 @@ BEGIN IF a_debug = 1 THEN SELECT - a_guid + a_guid , a_string , a_separator , a_debug ; END IF; - CALL p_validate_guid ( a_guid ); + CALL partsltd_prod.p_core_validate_guid ( a_guid ); DROP TABLE IF EXISTS tmp_Split_Split; @@ -7290,13 +985,13 @@ BEGIN IF EXISTS (SELECT * FROM tmp_Split_Split LIMIT 1) THEN START TRANSACTION; - INSERT INTO Split_Temp ( - guid - , display_order + INSERT INTO partsltd_prod.CORE_Split_Temp ( + guid + , display_order , substring ) SELECT - a_guid + a_guid , display_order , substring FROM tmp_Split_Split @@ -7307,15 +1002,15 @@ BEGIN DROP TABLE IF EXISTS tmp_Split_Split; IF a_debug = 1 THEN - CALL p_debug_timing_reporting ( v_time_start ); + CALL partsltd_prod.p_core_debug_timing_reporting ( v_time_start ); END IF; END // DELIMITER ; /* -CALL p_split ( - 'nips' +CALL partsltd_prod.p_core_split ( + 'nips' , 'noods, cheese ' -- a_string , ',' -- a_separator -- '0', -- a_allow_empty @@ -7323,30 +1018,28 @@ CALL p_split ( ); SELECT * -FROM Split_Temp +FROM partsltd_prod.CORE_Split_Temp WHERE GUID = 'nips'; -CALL p_clear_split_temp( 'nips' ); +CALL partsltd_prod.p_core_clear_split_temp( 'nips' ); */ +USE partsltd_prod; --- File: 6001_p_clear_split_temp.sql - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_clear_split_temp; +DROP PROCEDURE IF EXISTS partsltd_prod.p_core_clear_split; DELIMITER // -CREATE PROCEDURE p_clear_split_temp ( +CREATE PROCEDURE partsltd_prod.p_core_clear_split ( IN a_guid BINARY(36) ) BEGIN - CALL p_validate_guid( a_guid ); + CALL partsltd_prod.p_core_validate_guid( a_guid ); START TRANSACTION; -- DROP TABLE IF EXISTS - DELETE FROM Split_Temp + DELETE FROM partsltd_prod.CORE_Split_Temp WHERE GUID = a_guid ; @@ -7356,80 +1049,17 @@ DELIMITER ; /* -CALL p_clear_split_temp ( 'nips' ); +CALL partsltd_prod.p_core_clear_split ( 'nips' ); */ +USE partsltd_prod; --- File: 6001_p_validate_guid.sql - - -DROP PROCEDURE IF EXISTS p_validate_guid; -DROP PROCEDURE IF EXISTS p_validate_guid_test; +DROP PROCEDURE IF EXISTS partsltd_prod.p_core_split_key_value_pair_csv; DELIMITER // -CREATE PROCEDURE p_validate_guid ( - IN a_guid BINARY(36) - -- , IN a_debug BIT -) -BEGIN - /* - DECLARE v_code_type_error_bad_data VARCHAR(200); - DECLARE v_id_type_error_bad_data INT; - - IF ISNULL(a_guid) THEN - SET v_code_type_error_bad_data := (SELECT code FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA'); - SET v_id_type_error_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_type_error_bad_data); - - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , 'GUID is required.' - ; - END IF; - */ - IF ISNULL(a_guid) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'GUID is required.' - ; - END IF; -END // -DELIMITER ; - - -DELIMITER // -CREATE PROCEDURE p_validate_guid_test () -BEGIN - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - id_type INT - , code VARCHAR(200) - , msg TEXT - ); - - CALL p_validate_guid ( 'nips' ); - CALL p_validate_guid ( NULL ); - - SELECT * FROM tmp_Msg_Error; - - DROP TABLE tmp_Msg_Error; -END // -DELIMITER ; - --- CALL p_validate_guid_test(); - --- File: 6003_p_split_key_value_pair_csv.sql - - -DROP PROCEDURE IF EXISTS p_split_key_value_pair_csv; - -DELIMITER // -CREATE PROCEDURE p_split_key_value_pair_csv ( +CREATE PROCEDURE partsltd_prod.p_core_split_key_value_pair_csv ( IN a_guid BINARY(36) , IN a_string LONGTEXT , IN a_debug BIT @@ -7453,29 +1083,29 @@ BEGIN ; END IF; - CALL p_validate_guid ( a_guid ); + CALL partsltd_prod.p_core_validate_guid ( a_guid ); - DROP TEMPORARY TABLE IF EXISTS tmp_Split_Input; - DROP TEMPORARY TABLE IF EXISTS tmp_Split_Split; + DROP TABLE IF EXISTS tmp_Input_Split_Key_Value_Pair_Csv; + DROP TABLE IF EXISTS tmp_Split_Split_Key_Value_Pair_Csv; - CREATE TEMPORARY TABLE tmp_Split_Input ( + CREATE TEMPORARY TABLE tmp_Input_Split_Key_Value_Pair_Csv ( input_string TEXT ); - CREATE TEMPORARY TABLE tmp_Split_Split ( + CREATE TEMPORARY TABLE tmp_Split_Split_Key_Value_Pair_Csv ( id INT AUTO_INCREMENT PRIMARY KEY , key_column VARCHAR(4000) , value_column VARCHAR(4000) ); - INSERT INTO tmp_Split_Input ( + INSERT INTO tmp_Input_Split_Key_Value_Pair_Csv ( input_string ) VALUES ( a_string ); - INSERT INTO tmp_Split_Split (key_column, value_column) + INSERT INTO tmp_Split_Split_Key_Value_Pair_Csv (key_column, value_column) SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(t.pair, ':', 1), ',', -1) AS key_column, SUBSTRING_INDEX(t.pair, ':', -1) AS value_column @@ -7491,9 +1121,9 @@ BEGIN WHERE n <= 1 + (LENGTH(input_string) - LENGTH(REPLACE(input_string, ',', ''))) ) t; - IF EXISTS (SELECT * FROM tmp_Split_Split LIMIT 1) THEN + IF EXISTS (SELECT * FROM tmp_Split_Split_Key_Value_Pair_Csv LIMIT 1) THEN START TRANSACTION; - INSERT INTO Split_Key_Value_Pair_Csv_Temp ( + INSERT INTO partsltd_prod.CORE_Split_Key_Value_Pair_Csv_Temp ( guid , id , key_column @@ -7504,55 +1134,53 @@ BEGIN , id , key_column , value_column - FROM tmp_Split_Split + FROM tmp_Split_Split_Key_Value_Pair_Csv ; COMMIT; END IF; - DROP TEMPORARY TABLE IF EXISTS tmp_Split_Input; - DROP TEMPORARY TABLE IF EXISTS tmp_Split_Split; + DROP TEMPORARY TABLE IF EXISTS tmp_Input_Split_Key_Value_Pair_Csv; + DROP TEMPORARY TABLE IF EXISTS tmp_Split_Split_Key_Value_Pair_Csv; IF a_debug = 1 THEN - CALL p_debug_timing_reporting ( v_time_start ); + CALL partsltd_prod.p_core_debug_timing_reporting ( v_time_start ); END IF; END // DELIMITER ; /* -CALL p_split_key_value_pair_csv ( +CALL partsltd_prod.p_core_split_key_value_pair_csv ( 'nipsnipsnipsnipsnipsnipsnipsnipsnips' , '1:100,2:200,3:300,4:400' -- a_string , 1 ); SELECT * -FROM Split_key_value_pair_csv_Temp +FROM partsltd_prod.CORE_Split_key_value_pair_csv_Temp WHERE GUID = 'nipsnipsnipsnipsnipsnipsnipsnipsnips'; -CALL p_clear_split_key_value_pair_csv_temp( 'nipsnipsnipsnipsnipsnipsnipsnipsnips' ); +CALL partsltd_prod.p_core_clear_split_key_value_pair_csv_temp( 'nipsnipsnipsnipsnipsnipsnipsnipsnips' ); */ +USE partsltd_prod; --- File: 6004_p_clear_split_key_value_pair_csv_temp.sql - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_clear_split_key_value_pair_csv_temp; +DROP PROCEDURE IF EXISTS partsltd_prod.p_core_clear_split_key_value_pair_csv; DELIMITER // -CREATE PROCEDURE p_clear_split_key_value_pair_csv_temp ( +CREATE PROCEDURE partsltd_prod.p_core_clear_split_key_value_pair_csv ( IN a_guid BINARY(36) ) BEGIN - CALL p_validate_guid( a_guid ); + CALL partsltd_prod.p_core_validate_guid( a_guid ); START TRANSACTION; - -- DROP TABLE IF EXISTS - DELETE FROM Split_Key_Value_Pair_Csv_Temp - WHERE GUID = a_guid - ; + -- DROP TABLE IF EXISTS + DELETE FROM partsltd_prod.CORE_Split_Key_Value_Pair_Csv_Temp + WHERE GUID = a_guid + ; COMMIT; END // @@ -7560,531 +1188,71 @@ DELIMITER ; /* -CALL p_clear_split_key_value_pair_csv_temp ( 'nipsnipsnipsnipsnipsnipsnipsnipsnips' ); +CALL partsltd_prod.p_core_clear_split_key_value_pair_csv ( 'nips' ); */ +USE partsltd_prod; --- File: 6206_fn_shop_get_product_permutation_name.sql - -DROP FUNCTION IF EXISTS fn_shop_get_product_permutation_name; +DROP PROCEDURE IF EXISTS partsltd_prod.p_ph_user_eval; +DROP PROCEDURE IF EXISTS partsltd_prod.p_ph_calc_user; DELIMITER // - -CREATE FUNCTION fn_shop_get_product_permutation_name(id_product_permutation INT) -RETURNS VARCHAR(4000) -DETERMINISTIC -BEGIN - DECLARE name VARCHAR(4000); - - SET name := ( - SELECT - CONCAT( - IFNULL(PC.name, '(No Category)') - , ' - ' - , IFNULL(P.name, '(No Product)') - , CASE WHEN P.has_variations = 1 THEN - CONCAT(' - ', GROUP_CONCAT(CONCAT(VT.name, ': ', V.name) SEPARATOR ', ')) - ELSE '' END - ) - FROM Shop_Product_Permutation PP - LEFT JOIN Shop_Product P ON PP.id_product = P.id_product - LEFT JOIN Shop_Product_Category PC ON P.id_category = PC.id_category - LEFT JOIN Shop_Product_Permutation_Variation_Link PPVL ON PP.id_permutation = PPVL.id_permutation - LEFT JOIN Shop_Variation V ON PPVL.id_variation = V.id_variation - LEFT JOIN Shop_Variation_Type VT ON V.id_type = VT.id_type - WHERE PP.id_permutation = id_product_permutation - GROUP BY PC.id_category, PC.name, P.id_product, P.name, P.has_variations, VT.display_order, VT.name, V.display_order, V.name - LIMIT 1 - ); - - RETURN name; -END // - -DELIMITER ; - -/* -SELECT - fn_shop_get_product_permutation_name( - 3 -- id_product_permutation - ) -; -*/ - --- File: 6210_fn_shop_get_id_product_permutation_from_variation_csv_list.sql - -DROP FUNCTION IF EXISTS fn_shop_get_id_product_permutation_from_variation_csv_list; - -DELIMITER // - -CREATE FUNCTION fn_shop_get_id_product_permutation_from_variation_csv_list ( - a_id_product INT - , a_variation_csv TEXT -) -RETURNS INT -DETERMINISTIC -READS SQL DATA -BEGIN - DECLARE v_id_permutation INT; - DECLARE done INT DEFAULT FALSE; - DECLARE v_id_variation_type INT; - DECLARE v_id_variation INT; - DECLARE v_id_permutation_tmp INT; - DECLARE cur CURSOR FOR - SELECT - CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(t.pair, ':', 1), ',', -1) AS UNSIGNED) AS id_variation_type, - CAST(SUBSTRING_INDEX(t.pair, ':', -1) AS UNSIGNED) AS id_variation - FROM ( - SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(a_variation_csv, ',', n), ',', -1) pair - FROM ( - SELECT a.N + b.N * 10 + 1 n - FROM (SELECT 0 AS N UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) a - CROSS JOIN (SELECT 0 AS N UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) b - ORDER BY n - ) numbers - WHERE n <= 1 + (LENGTH(a_variation_csv) - LENGTH(REPLACE(a_variation_csv, ',', ''))) - ) t; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; - - SET v_id_permutation = NULL; - - OPEN cur; - - read_loop: LOOP - FETCH cur INTO v_id_variation_type, v_id_variation; - IF done THEN - LEAVE read_loop; - END IF; - - IF v_id_permutation IS NULL THEN - -- First iteration: find initial v_id_permutations - SELECT PPVL.id_permutation INTO v_id_permutation - FROM partsltd_prod.Shop_Product_Permutation_Variation_Link PPVL - INNER JOIN partsltd_prod.Shop_Product_Permutation PP ON PPVL.id_permutation = PP.id_permutation - INNER JOIN partsltd_prod.Shop_Variation PV ON PPVL.id_variation = PV.id_variation - WHERE 1=1 - AND PP.id_product = a_id_product - AND PPVL.id_variation = v_id_variation - AND PV.id_type = v_id_variation_type - ; - ELSE - -- Subsequent iterations: narrow down the v_id_permutation - SELECT PPVL.id_permutation INTO v_id_permutation_tmp - FROM partsltd_prod.Shop_Product_Permutation_Variation_Link PPVL - INNER JOIN partsltd_prod.Shop_Product_Permutation PP ON PPVL.id_permutation = PP.id_permutation - INNER JOIN partsltd_prod.Shop_Variation PV ON PPVL.id_variation = PV.id_variation - WHERE 1=1 - AND PP.id_product = a_id_product - AND PPVL.v_id_permutation = v_id_permutation - AND PPVL.id_variation = v_id_variation - AND PV.id_type = v_id_variation_type - ; - - IF v_id_permutation_tmp IS NULL THEN - -- If no match found, exit the loop - SET v_id_permutation := NULL; - LEAVE read_loop; - ELSE - SET v_id_permutation := v_id_permutation_tmp; - END IF; - END IF; - END LOOP; - - CLOSE cur; - - RETURN v_id_permutation; -END // - -DELIMITER ; - -/* -SELECT fn_shop_get_id_product_permutation_from_variation_csv_list ( 1, '1:1' ) AS id_permutation; -SELECT fn_shop_get_id_product_permutation_from_variation_csv_list ( 3, '' ) AS id_permutation; -*/ - - -/* --- Update the table using the function -UPDATE product_permutation_input -SET v_id_permutation = find_v_id_permutation(variation_csv) -WHERE v_id_permutation IS NULL; -*/ - -/* -select * from partsltd_prod.Shop_Variation - -DROP PROCEDURE IF EXISTS p_shop_get_id_product_permutation_from_variation_csv_list; - -DELIMITER // -CREATE PROCEDURE p_shop_get_id_product_permutation_from_variation_csv_list ( - IN a_guid BINARY(36) - , IN a_debug BIT -) -BEGIN - DECLARE done INT DEFAULT FALSE; - DECLARE v_id INT; - DECLARE v_row_id INT; - DECLARE v_variation_csv TEXT; - DECLARE v_id_permutation INT; - DECLARE v_time_start TIMESTAMP(6); - - -- Cursor to iterate through unprocessed rows - DECLARE cur CURSOR FOR - SELECT id, session_guid, row_id, variation_csv - FROM product_permutation_input - WHERE v_id_permutation IS NULL; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET a_debug := IFNULL(a_debug, 0); - - IF a_debug = 1 THEN - SELECT - a_guid - , a_debug - ; - END IF; - - CALL p_validate_guid ( a_guid ); - - OPEN cur; - - read_loop: LOOP - FETCH cur INTO v_id, v_session_guid, v_row_id, v_variation_csv; - IF done THEN - LEAVE read_loop; - END IF; - - -- Find matching v_id_permutation - SET v_id_permutation = NULL; - - SELECT ppvl.v_id_permutation INTO v_id_permutation - FROM ( - SELECT - SUBSTRING_INDEX(SUBSTRING_INDEX(t.pair, ':', 1), ',', -1) AS id_variation_type, - SUBSTRING_INDEX(t.pair, ':', -1) AS id_variation - FROM ( - SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(v_variation_csv, ',', numbers.n), ',', -1) pair - FROM ( - SELECT 1 n UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 -- add more if needed - ) numbers - WHERE CHAR_LENGTH(v_variation_csv) - CHAR_LENGTH(REPLACE(v_variation_csv, ',', '')) >= numbers.n - 1 - ) t - ) parsed - INNER JOIN product_permutation_variation_link ppvl - ON parsed.id_variation_type = ppvl.id_variation_type - AND parsed.id_variation = ppvl.id_variation - GROUP BY ppvl.v_id_permutation - HAVING COUNT(*) = (LENGTH(v_variation_csv) - LENGTH(REPLACE(v_variation_csv, ',', '')) + 1) - LIMIT 1; - - -- Update the v_id_permutation in the input table - UPDATE product_permutation_input - SET v_id_permutation = v_id_permutation - WHERE id = v_id; - - END LOOP; - - CLOSE cur; - - - IF EXISTS ( SELECT * FROM Shop_Get_Id_Product_Permutation_From_Variation_Csv_List_Temp WHERE GUID = a_guid LIMIT 1 ) THEN - IF EXISTS (SELECT * FROM tmp_Split_Split LIMIT 1) THEN - START TRANSACTION; - INSERT INTO Split_Key_Value_Pair_Csv_Temp ( - guid - , id - , key_column - , value_column - ) - SELECT - a_guid - , id - , key_column - , value_column - FROM tmp_Split_Split - ; - COMMIT; - END IF; - END IF; - - DROP TEMPORARY TABLE IF EXISTS tmp_Split_Input; - DROP TEMPORARY TABLE IF EXISTS tmp_Split_Split; - - IF a_debug = 1 THEN - CALL p_debug_timing_reporting ( v_time_start ); - END IF; -END // -DELIMITER ; -*/ - -/* -CALL p_shop_get_id_product_permutation_from_variation_csv_list ( - 'nipsnipsnipsnipsnipsnipsnipsnipsnips' - , '1:100,2:200,3:300,4:400' -- a_string - , 1 -); - -SELECT * -FROM Split_key_value_pair_csv_Temp -WHERE GUID = 'nipsnipsnipsnipsnipsnipsnipsnipsnips'; - -CALL p_clear_split_key_value_pair_csv_temp( 'nipsnipsnipsnipsnipsnipsnipsnipsnips' ); -*/ - - --- File: 6211_fn_shop_get_product_variations_from_id_csv_list.sql - -DROP FUNCTION IF EXISTS fn_shop_get_product_variations_from_id_csv_list; - -DELIMITER // - -CREATE FUNCTION fn_shop_get_product_variations_from_id_csv_list ( - a_id_permutation INT - , a_variation_csv TEXT - , a_guid BINARY(36) -) -RETURNS INT -DETERMINISTIC -READS SQL DATA -BEGIN - DECLARE v_csv_pairs VARCHAR(4000); - DECLARE v_current_pair VARCHAR(50); - DECLARE v_id_variation_type INT; - DECLARE v_id_variation INT; - DECLARE v_rank_counter INT; - - CALL p_validate_guid( a_guid ); - - SET v_csv_pairs := a_variation_csv; - SET v_rank_counter := 1; - - DROP TEMPORARY TABLE IF EXISTS tmp_Get_Variation_From_Csv_Variations; - CREATE TEMPORARY TABLE tmp_Get_Variation_From_Csv_Variations ( - id_variation_type INT NULL - , id_variation INT NOT NULL - ); - - WHILE LENGTH(v_csv_pairs) > 0 DO - IF LOCATE(',', v_csv_pairs) > 0 THEN - SET v_current_pair := SUBSTRING_INDEX(v_csv_pairs, ',', 1); - SET v_csv_pairs := SUBSTRING(v_csv_pairs, LOCATE(',', v_csv_pairs) + 1); - ELSE - SET v_current_pair := v_csv_pairs; - SET v_csv_pairs := ''; - END IF; - - SET v_id_variation_type := SUBSTRING_INDEX(v_current_pair, ':', 1); - SET v_id_variation := SUBSTRING_INDEX(v_current_pair, ':', -1); - - IF NOT ISNULL(v_id_variation) THEN - INSERT INTO tmp_Get_Variation_From_Csv_Variations ( - id_variation_type - , id_variation - ) - SELECT - v_id_variation_type AS id_variation_type - , v_id_variation AS id_variation - ; - - SET v_rank_counter := v_rank_counter + 1; - END IF; - END WHILE; - - INSERT INTO partsltd_prod.Shop_Product_Permutation_Variation_Link_Temp ( - id_link - , id_permutation - , id_variation - , display_order - , active - , GUID - ) - SELECT - IFNULL(PPVL.id_link, -v_rank_counter) AS id_link - , a_id_permutation - , t_V.id_variation - , v_rank_counter AS display_order - , 1 AS active - , a_guid - FROM tmp_Get_Variation_From_Csv_Variations t_V - LEFT JOIN partsltd_prod.Shop_Product_Permutation_Variation_Link PPVL ON t_V.id_variation = PPVL.id_variation - ; - - DROP TEMPORARY TABLE tmp_Get_Variation_From_Csv_Variations; - - RETURN v_rank_counter; -END // - -DELIMITER ; - - -/* - -SELECT - partsltd_prod.fn_shop_get_product_variations_from_id_csv_list( - 1 -- a_id_permutation - , '1:1' -- a_variation_csv - , 'NIPPLENIPPLENIPPLENIPPLENIPPLENIPPLE' -- a_guid - ) -; -SELECT * -FROM partsltd_prod.Shop_Product_Permutation_Variation_Link_Temp -WHERE GUID = 'NIPPLENIPPLENIPPLENIPPLENIPPLENIPPLE' -; -DELETE -FROM partsltd_prod.Shop_Product_Permutation_Variation_Link_Temp -WHERE GUID = 'NIPPLENIPPLENIPPLENIPPLENIPPLENIPPLE' -; -*/ - - --- File: 6212_fn_shop_get_product_permutation_variations_csv.sql - -DROP FUNCTION IF EXISTS fn_shop_get_product_permutation_variations_csv; - -DELIMITER // - -CREATE FUNCTION fn_shop_get_product_permutation_variations_csv(id_product_permutation INT) -RETURNS VARCHAR(4000) -DETERMINISTIC -BEGIN - DECLARE csv VARCHAR(4000); - - SET csv := ( - SELECT - CASE WHEN P.has_variations = 0 THEN - '' - ELSE - GROUP_CONCAT( - CONCAT( - PV.id_type - , ':' - , PV.id_variation - ) - SEPARATOR ',' - ) - END - FROM partsltd_prod.Shop_Product_Permutation PP - LEFT JOIN partsltd_prod.Shop_Product P ON PP.id_product = P.id_product - LEFT JOIN partsltd_prod.Shop_Product_Permutation_Variation_Link PPVL ON PP.id_permutation = PPVL.id_permutation - LEFT JOIN partsltd_prod.Shop_Variation PV ON PPVL.id_variation = PV.id_variation - LEFT JOIN partsltd_prod.Shop_Variation_Type PVT ON PV.id_type = PVT.id_type - WHERE PP.id_permutation = id_product_permutation - GROUP BY P.id_product, P.has_variations, PVT.display_order, PVT.name, PV.display_order, PV.name - LIMIT 1 - ); - - RETURN csv; -END // - -DELIMITER ; -SELECT - fn_shop_get_product_permutation_variations_csv( - 3 -- id_product_permutation - ) - , fn_shop_get_product_permutation_variations_csv( - 1 -- id_product_permutation - ) -; -/* -*/ - --- File: 6500_p_shop_calc_user.sql - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_user_eval; -DROP PROCEDURE IF EXISTS p_shop_calc_user; - -DELIMITER // -CREATE PROCEDURE p_shop_calc_user ( - IN a_guid BINARY(36) +CREATE PROCEDURE partsltd_prod.p_ph_calc_user ( + IN a_guid BINARY(36) , IN a_ids_user TEXT , IN a_get_inactive_user BIT , IN a_ids_permission VARCHAR(4000) - , IN a_ids_access_level VARCHAR(4000) - , IN a_ids_product TEXT , IN a_debug BIT ) BEGIN - -- Variable declaration DECLARE v_has_filter_permission BIT; DECLARE v_has_filter_user BIT; - DECLARE v_has_filter_access_level BIT; - -- DECLARE v_has_filter_permutation BIT; - DECLARE v_has_filter_product BIT; - DECLARE v_id_permission_product INT; DECLARE v_id_permission INT; - -- DECLARE v_ids_product VARCHAR(500); - DECLARE v_id_access_level_view INT; - -- DECLARE v_id_access_level_product_required INT; - DECLARE v_priority_access_level_view INT; - DECLARE v_priority_access_level_edit INT; - DECLARE v_priority_access_level_admin INT; - DECLARE v_id_access_level INT; - DECLARE v_priority_access_level INT; DECLARE v_time_start TIMESTAMP(6); DECLARE v_ids_row_delete VARCHAR(500); DECLARE v_code_type_error_bad_data VARCHAR(200); DECLARE v_id_type_error_bad_data INT; DECLARE v_code_error_permission VARCHAR(200); DECLARE v_id_permission_required INT; + DECLARE v_priority_access_level_required INT; + DECLARE v_priority_access_level_view INT; SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_code_type_error_bad_data := (SELECT code FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA'); - SET v_id_type_error_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_type_error_bad_data); + SET v_code_type_error_bad_data := (SELECT code FROM partsltd_prod.CORE_Msg_Error_Type WHERE code = 'BAD_DATA'); + SET v_id_type_error_bad_data := (SELECT id_type FROM partsltd_prod.CORE_Msg_Error_Type WHERE code = v_code_type_error_bad_data); + SET v_code_error_permission := (SELECT code FROM partsltd_prod.CORE_Msg_Error_Type WHERE id_type = 2); + SET v_priority_access_level_view := (SELECT priority FROM partsltd_prod.PH_Access_Level WHERE code = 'VIEW' LIMIT 1); - SET v_code_error_permission := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 2); - - CALL partsltd_prod.p_validate_guid ( a_guid ); + CALL partsltd_prod.p_core_validate_guid ( a_guid ); SET a_ids_user := TRIM(IFNULL(a_ids_user, '')); SET a_get_inactive_user := IFNULL(a_get_inactive_user, 0); SET a_ids_permission := TRIM(IFNULL(a_ids_permission, '')); - SET a_ids_access_level := TRIM(IFNULL(a_ids_access_level, '')); - SET a_ids_product := TRIM(IFNULL(a_ids_product, '')); SET a_debug := IFNULL(a_debug, 0); IF a_debug = 1 THEN SELECT - a_guid + a_guid , a_ids_user , a_get_inactive_user , a_ids_permission - , a_ids_access_level - , a_ids_product , a_debug ; END IF; - -- Clear previous proc results DROP TABLE IF EXISTS tmp_Calc_User; DROP TABLE IF EXISTS tmp_User_Calc_User; - DROP TABLE IF EXISTS tmp_Product_Calc_User; - DROP TABLE IF EXISTS tmp_Split; + DROP TABLE IF EXISTS tmp_Split_Calc_User; - -- Permanent Table CREATE TEMPORARY TABLE tmp_Calc_User ( - id_row INT PRIMARY KEY AUTO_INCREMENT NOT NULL, - id_user INT NULL, - id_permission_required INT NOT NULL, - priority_access_level_required INT NOT NULL, - id_product INT NULL, - is_super_user BIT NULL, - priority_access_level_user INT NULL, - can_view BIT, - can_edit BIT, - can_admin BIT - ); - - CREATE TEMPORARY TABLE tmp_Product_Calc_User ( - -- id_row INT PRIMARY KEY AUTO_INCREMENT NOT NULL - id_product INT NULL - , id_access_level_required INT NOT NULL - , priority_access_level_required INT NOT NULL - -- guid BINARY(36) NOT NULL, - -- rank_product INT NOT NULL + id_row INT PRIMARY KEY AUTO_INCREMENT NOT NULL + , id_user INT NULL + , id_permission_required INT NOT NULL + , priority_access_level_required INT NOT NULL + , is_super_user BIT NULL + , priority_access_level_user INT NULL + , has_access BIT ); CREATE TEMPORARY TABLE tmp_User_Calc_User ( @@ -8095,455 +1263,234 @@ BEGIN ); CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - -- guid BINARY(36) NOT NULL, - id_type INT NULL, - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL + display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT + , id_type INT NULL + , code VARCHAR(50) NOT NULL + , msg VARCHAR(4000) NOT NULL ); - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Split ( + CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Split_Calc_User ( substring VARCHAR(4000) NOT NULL , as_int INT NULL ); - DELETE FROM tmp_Split; - + DELETE FROM tmp_Split_Calc_User; + SET v_has_filter_user = CASE WHEN a_ids_user = '' THEN 0 ELSE 1 END; SET a_ids_permission = REPLACE(a_ids_permission, '|', ','); SET v_has_filter_permission = CASE WHEN a_ids_permission = '' THEN 0 ELSE 1 END; - SET a_ids_access_level = REPLACE(a_ids_access_level, '|', ','); - SET v_has_filter_access_level = CASE WHEN a_ids_access_level = '' THEN 0 ELSE 1 END; - /* - SET a_ids_permutation = REPLACE(a_ids_permutation, '|', ','); - SET v_has_filter_permutation = CASE WHEN a_ids_permutation = '' THEN 0 ELSE 1 END; - */ - SET a_ids_product = REPLACE(a_ids_product, '|', ','); - SET v_has_filter_product = CASE WHEN a_ids_product = '' THEN 0 ELSE 1 END; - SET v_id_access_level_view = (SELECT id_access_level FROM partsltd_prod.Shop_Access_Level WHERE code = 'VIEW' LIMIT 1); - SET v_priority_access_level_view = (SELECT priority FROM partsltd_prod.Shop_Access_Level WHERE id_access_level = v_id_access_level_view); - SET v_priority_access_level_edit = (SELECT priority FROM partsltd_prod.Shop_Access_Level WHERE code = 'EDIT' LIMIT 1); - SET v_priority_access_level_admin = (SELECT priority FROM partsltd_prod.Shop_Access_Level WHERE code = 'ADMIN' LIMIT 1); - - IF a_debug = 1 THEN - SELECT - v_priority_access_level_view - , v_priority_access_level_edit - , v_priority_access_level_admin - ; - END IF; - - -- Access levels - IF v_has_filter_access_level THEN - CALL partsltd_prod.p_split(a_guid, a_ids_access_level, ',', a_debug); - - INSERT INTO tmp_Split ( - substring - , as_int - ) - SELECT - substring - , CONVERT(substring, DECIMAL(10,0)) -- AS as_int - FROM Split_Temp - WHERE 1=1 - AND GUID = a_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( a_guid ); - - -- Invalid IDs - IF EXISTS ( - SELECT t_S.substring - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Access_Level AL ON t_S.as_int = AL.id_access_level - WHERE - ISNULL(t_S.as_int) - OR ISNULL(AL.id_access_level) - OR AL.active = 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - -- guid, - id_type, - code, - msg - ) - SELECT - -- a_guid, - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Invalid or inactive access level IDs: ', GROUP_CONCAT(t_S.substring SEPARATOR ', ')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Access_Level AL ON t_S.as_int = AL.id_access_level - WHERE - ISNULL(t_S.as_int) - OR ISNULL(AL.id_access_level) - OR AL.active = 0 - ; - ELSE - IF v_has_filter_access_level THEN - SET v_id_access_level := ( - SELECT AL.id_access_level - FROM tmp_Split t_S - INNER JOIN partsltd_prod.Shop_Access_Level AL - ON t_S.as_int = AL.id_access_level - AND AL.active - ORDER BY AL.priority ASC - LIMIT 1 - ); - ELSE - SET v_id_access_level = v_id_access_level_view; - END IF; - SET v_priority_access_level := (SELECT priority FROM partsltd_prod.Shop_Access_Level WHERE id_access_level = v_id_access_level LIMIT 1); - END IF; - END IF; - DELETE FROM tmp_Split; - + -- SET v_id_access_level_view = (SELECT id_access_level FROM partsltd_prod.PH_Access_Level WHERE code = 'VIEW' LIMIT 1); + + -- Permission IDs - IF v_has_filter_permission THEN - CALL partsltd_prod.p_split(a_guid, a_ids_permission, ',', a_debug); + IF NOT v_has_filter_permission THEN + INSERT INTO tmp_Msg_Error ( + id_type + , code + , msg + ) + SELECT + v_id_type_error_bad_data + , v_code_type_error_bad_data + , 'Permission ID required.' + ; + ELSE + CALL partsltd_prod.p_core_split(a_guid, a_ids_permission, ',', a_debug); - INSERT INTO tmp_Split ( - substring + INSERT INTO tmp_Split_Calc_User ( + substring , as_int ) SELECT - substring + substring , CONVERT(substring, DECIMAL(10,0)) AS as_int - FROM Split_Temp - WHERE 1=1 - AND GUID = a_guid + FROM partsltd_prod.CORE_Split_Temp + WHERE + GUID = a_guid AND NOT ISNULL(substring) AND substring != '' ; - CALL partsltd_prod.p_clear_split_temp( a_guid ); + CALL partsltd_prod.p_core_clear_split( a_guid ); -- Invalid or inactive - IF EXISTS (SELECT PERM.id_permission FROM tmp_Split t_S LEFT JOIN partsltd_prod.Shop_Permission PERM ON t_S.as_int = PERM.id_permission WHERE ISNULL(t_S.as_int) OR ISNULL(PERM.id_permission) OR PERM.active = 0) THEN + IF EXISTS ( + SELECT PERM.id_permission + FROM tmp_Split_Calc_User t_S + LEFT JOIN partsltd_prod.PH_Permission PERM ON t_S.as_int = PERM.id_permission + WHERE + ISNULL(t_S.as_int) + OR ISNULL(PERM.id_permission) + OR PERM.active = 0 + ) THEN INSERT INTO tmp_Msg_Error ( - -- guid, - id_type, - code, - msg + id_type + , code + , msg ) SELECT - -- a_guid, - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Invalid or inactive permission IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Permission PERM ON t_S.as_int = PERM.id_permission + v_id_type_error_bad_data + , v_code_type_error_bad_data + , CONCAT('Invalid or inactive permission IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) + FROM tmp_Split_Calc_User t_S + LEFT JOIN partsltd_prod.PH_Permission PERM ON t_S.as_int = PERM.id_permission WHERE - ISNULL(t_S.as_int) - OR ISNULL(PERM.id_permission) - OR PERM.active = 0 + ISNULL(t_S.as_int) + OR ISNULL(PERM.id_permission) + OR PERM.active = 0 ; ELSE - SET v_id_permission_required := ( - SELECT PERM.id_permission - FROM partsltd_prod.Shop_Permission PERM - INNER JOIN partsltd_prod.Shop_Access_Level AL ON PERM.id_access_level_required = AL.id_access_level - ORDER BY AL.priority ASC - LIMIT 1 - ); + SELECT + PERM.id_permission + , PERM.id_access_level_required + INTO + v_id_permission_required + , v_priority_access_level_required + FROM tmp_Split_Calc_User t_S + LEFT JOIN partsltd_prod.PH_Permission PERM ON t_S.as_int = PERM.id_permission + INNER JOIN partsltd_prod.PH_Access_Level AL ON PERM.id_access_level_required = AL.id_access_level + ORDER BY AL.priority ASC + LIMIT 1 + ; + + IF ISNULL(v_id_permission_required) THEN + INSERT INTO tmp_Msg_Error ( + id_type + , code + , msg + ) + SELECT + v_id_type_error_bad_data + , v_code_type_error_bad_data + , 'Valid Permission ID required.' + ; + END IF; END IF; END IF; - DELETE FROM tmp_Split; + DELETE FROM tmp_Split_Calc_User; -- Users - CALL partsltd_prod.p_split(a_guid, a_ids_user, ',', a_debug); + CALL partsltd_prod.p_core_split(a_guid, a_ids_user, ',', a_debug); - INSERT INTO tmp_Split ( - substring + INSERT INTO tmp_Split_Calc_User ( + substring , as_int ) SELECT substring , CONVERT(substring, DECIMAL(10,0)) AS as_int - FROM Split_Temp - WHERE 1=1 - AND GUID = a_guid + FROM partsltd_prod.CORE_Split_Temp + WHERE + GUID = a_guid AND NOT ISNULL(substring) AND substring != '' ; - CALL partsltd_prod.p_clear_split_temp( a_guid ); + CALL partsltd_prod.p_core_clear_split( a_guid ); -- Invalid or inactive - IF EXISTS (SELECT U.id_user FROM tmp_Split t_S LEFT JOIN partsltd_prod.Shop_User U ON t_S.as_int = U.id_user WHERE ISNULL(t_S.as_int) OR ISNULL(U.id_user) OR (a_get_inactive_user = 0 AND U.active = 0)) THEN + IF EXISTS (SELECT U.id_user FROM tmp_Split_Calc_User t_S LEFT JOIN partsltd_prod.PH_User U ON t_S.as_int = U.id_user WHERE ISNULL(t_S.as_int) OR ISNULL(U.id_user) OR (a_get_inactive_user = 0 AND U.active = 0)) THEN INSERT INTO tmp_Msg_Error ( - -- guid, - id_type, - code, - msg + id_type + , code + , msg ) SELECT - -- a_guid, - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Invalid or inactive user IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_User U ON t_S.as_int = U.id_user + v_id_type_error_bad_data + , v_code_type_error_bad_data + , CONCAT('Invalid or inactive user IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) + FROM tmp_Split_Calc_User t_S + LEFT JOIN partsltd_prod.PH_User U ON t_S.as_int = U.id_user WHERE - ISNULL(t_S.as_int) - OR ISNULL(U.id_user) - OR ( - a_get_inactive_user = 0 + ISNULL(t_S.as_int) + OR ISNULL(U.id_user) + OR ( + a_get_inactive_user = 0 AND U.active = 0 ) ; ELSE - /* - SET a_ids_user = ( - SELECT U.id_user - FROM tmp_Split t_S - INNER JOIN partsltd_prod.Shop_User U ON t_S.as_int = U.id_user - ); - SET v_has_filter_user = ISNULL(a_ids_user); - */ - IF NOT EXISTS (SELECT * FROM tmp_Split) THEN - INSERT INTO tmp_Split (substring, as_int) + IF NOT EXISTS (SELECT * FROM tmp_Split_Calc_User) THEN + INSERT INTO tmp_Split_Calc_User (substring, as_int) VALUES ( '', NULL ); END IF; IF a_debug = 1 THEN SELECT * - FROM tmp_Split; + FROM tmp_Split_Calc_User; END IF; INSERT INTO tmp_User_Calc_User ( - id_user - -- , id_access_level + id_user , is_super_user , priority_access_level ) SELECT - U.id_user - , U.is_super_user - -- , IFNULL(AL_U.id_access_level, v_id_access_level_view) AS id_access_level + U.id_user + , IFNULL(U.is_super_user, 0) AS is_super_user , IFNULL(MIN(AL_U.priority), v_priority_access_level_view) AS priority_access_level - FROM tmp_Split t_S - INNER JOIN partsltd_prod.Shop_User U ON t_S.as_int = U.id_user - LEFT JOIN partsltd_prod.Shop_User_Role_Link URL + FROM tmp_Split_Calc_User t_S + INNER JOIN partsltd_prod.PH_User U ON t_S.as_int = U.id_user + LEFT JOIN partsltd_prod.PH_User_Role_Link URL ON U.id_user = URL.id_user AND URL.active - LEFT JOIN partsltd_prod.Shop_Role_Permission_Link RPL + LEFT JOIN partsltd_prod.PH_Role_Permission_Link RPL ON URL.id_role = RPL.id_role AND RPL.active - LEFT JOIN partsltd_prod.Shop_Access_Level AL_U + LEFT JOIN partsltd_prod.PH_Access_Level AL_U ON RPL.id_access_level = AL_U.id_access_level AND AL_U.active GROUP BY U.id_user ; INSERT INTO tmp_Calc_User ( - id_user + id_user , id_permission_required , priority_access_level_required - , id_product - , is_super_user , priority_access_level_user + , is_super_user ) SELECT - t_UCU.id_user + t_UCU.id_user , v_id_permission_required - , v_priority_access_level AS priority_access_level_required - , NULL + , v_priority_access_level_required , t_UCU.priority_access_level AS priority_access_level_user , t_UCU.is_super_user AS is_super_user FROM tmp_User_Calc_User t_UCU ; - - /* - INSERT INTO tmp_Calc_User ( - id_user - , id_permission_required - , priority_access_level_required - -- , id_product - , priority_access_level_user - , is_super_user - ) - SELECT - U.id_user - , v_id_permission_required - , v_priority_access_level AS priority_access_level_required - -- , t_P.id_product - , CASE WHEN MIN(IFNULL(AL_U.priority, 0)) = 0 THEN v_priority_access_level_view ELSE MIN(IFNULL(AL_U.priority, 0)) END AS priority_access_level_user - , IFNULL(U.is_super_user, 0) AS is_super_user - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_User U - ON t_S.as_int = U.id_user - AND U.active - LEFT JOIN partsltd_prod.Shop_User_Role_Link URL - ON U.id_user = URL.id_user - AND URL.active - LEFT JOIN partsltd_prod.Shop_Role_Permission_Link RPL - ON URL.id_role = RPL.id_role - AND RPL.active - LEFT JOIN partsltd_prod.Shop_Access_Level AL_U - ON RPL.id_access_level = AL_U.id_access_level - AND AL_U.active - * - CROSS JOIN tmp_Product_Calc_User t_P - LEFT JOIN partsltd_prod.Shop_Access_Level AL_P - ON t_P.id_access_level_required = AL_P.id_access_level - AND AL_P.active - * - GROUP BY t_S.as_int, U.id_user - ; - */ - - -- SET v_has_filter_user = EXISTS ( SELECT * FROM tmp_User_Calc_User LIMIT 1 ); END IF; - DELETE FROM tmp_Split; - - -- Products - IF v_has_filter_product = 1 THEN - CALL partsltd_prod.p_split(a_guid, a_ids_product, ',', a_debug); - - INSERT INTO tmp_Split ( - substring - , as_int - ) - SELECT - substring - , CONVERT(substring, DECIMAL(10,0)) AS as_int - FROM Split_Temp - WHERE 1=1 - AND GUID = a_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( a_guid ); - - -- Invalid product IDs - IF EXISTS (SELECT * FROM tmp_Split t_S LEFT JOIN partsltd_prod.Shop_Product P ON t_S.as_int = P.id_product WHERE ISNULL(t_S.as_int) OR ISNULL(P.id_product)) THEN - INSERT INTO tmp_Msg_Error ( - -- guid, - id_type, - code, - msg - ) - SELECT - -- a_guid, - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Invalid Product IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Product P ON t_S.as_int = P.id_product - WHERE - ISNULL(t_S.as_int) - OR ISNULL(P.id_product) - OR P.active = 0 - ; - END IF; - IF (EXISTS (SELECT * FROM tmp_Split)) THEN - INSERT INTO tmp_Product_Calc_User ( - id_product, - -- id_permutation, - id_access_level_required, - priority_access_level_required - ) - SELECT - DISTINCT P.id_product, - -- PP.id_permutation, - CASE WHEN AL_P.priority < AL_C.priority THEN AL_P.id_access_level ELSE AL_C.id_access_level END AS id_access_level_required, - CASE WHEN AL_P.priority < AL_C.priority THEN AL_P.priority ELSE AL_C.priority END AS priority_access_level_required - FROM tmp_Split t_S - INNER JOIN partsltd_prod.Shop_Product P ON t_S.as_int = P.id_product -- Shop_Product_Permutation PP - INNER JOIN partsltd_prod.Shop_Access_Level AL_P - ON P.id_access_level_required = AL_P.id_access_level - AND AL_P.active - INNER JOIN partsltd_prod.Shop_Product_Category C ON P.id_category = C.id_category - INNER JOIN partsltd_prod.Shop_Access_Level AL_C - ON C.id_access_level_required = AL_C.id_access_level - AND AL_C.active - ; - - SET v_has_filter_product = EXISTS (SELECT * FROM tmp_Product_Calc_User); - /* - UPDATE tmp_Product_Calc_User t_P - INNER JOIN partsltd_prod.Shop_Product P ON t_P.id_product = P.id_product - INNER JOIN partsltd_prod.Shop_Product_Category PC ON P.id_category = PC.id_category - INNER JOIN partsltd_prod.Shop_Access_Level AL ON PC.id_access_level_required = AL.id_access_level - SET - t_P.id_access_level_required = CASE WHEN t_P.priority_access_level_required <= AL.priority THEN t_P.id_access_level_required ELSE AL.id_access_level END - , t_P.priority_access_level_required = LEAST(t_P.priority_access_level_required, AL.priority) - ; - */ - ELSE - INSERT INTO tmp_Product_Calc_User ( - id_product, - -- id_permutation, - id_access_level_required, - priority_access_level_required - ) - VALUES ( - NULL - , v_id_access_level_view - , v_priority_access_level_view - ); - END IF; - END IF; - DELETE FROM tmp_Split; - - INSERT INTO tmp_Calc_User ( - id_user - , id_permission_required - , priority_access_level_required - , id_product - , is_super_user - , priority_access_level_user - ) - SELECT - t_U.id_user - , v_id_permission_required - , CASE WHEN AL.priority < v_priority_access_level THEN AL.priority ELSE v_priority_access_level END AS priority_access_level_required - , t_P.id_product - , t_U.priority_access_level AS priority_access_level_user - , t_U.is_super_user AS is_super_user - FROM tmp_User_Calc_User t_U - CROSS JOIN tmp_Product_Calc_User t_P - LEFT JOIN partsltd_prod.Shop_Access_Level AL ON t_P.id_access_level_required = AL.id_access_level - ; + DELETE FROM tmp_Split_Calc_User; + -- Calculated fields UPDATE tmp_Calc_User t_CU SET - t_CU.can_view = t_CU.is_super_user = 1 OR (t_CU.priority_access_level_user <= v_priority_access_level_view AND t_CU.priority_access_level_user <= t_CU.priority_access_level_required) - , t_CU.can_edit = t_CU.is_super_user = 1 OR (t_CU.priority_access_level_user <= v_priority_access_level_edit AND t_CU.priority_access_level_user <= t_CU.priority_access_level_required) - , t_CU.can_admin = t_CU.is_super_user = 1 OR (t_CU.priority_access_level_user <= v_priority_access_level_admin AND t_CU.priority_access_level_user <= t_CU.priority_access_level_required) + t_CU.has_access = ( + (t_CU.is_super_user = 1) + OR (t_CU.priority_access_level_user <= t_CU.priority_access_level_required) + ) ; -- Export data to staging table IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN START TRANSACTION; - INSERT INTO partsltd_prod.Shop_Calc_User_Temp ( - guid + INSERT INTO partsltd_prod.PH_Calc_User_Temp ( + guid , id_user , id_permission_required , priority_access_level_required - , id_product - , is_super_user , priority_access_level_user - , can_view - , can_edit - , can_admin + , is_super_user + , has_access ) SELECT - a_guid - , id_user - , id_permission_required - , priority_access_level_required - , id_product - , is_super_user - , priority_access_level_user - , can_view - , can_edit - , can_admin - FROM tmp_Calc_User + a_guid + , t_CU.id_user + , t_CU.id_permission_required + , t_CU.priority_access_level_required + , t_CU.priority_access_level_user + , t_CU.is_super_user + , t_CU.has_access + FROM tmp_Calc_User t_CU ; COMMIT; END IF; @@ -8552,18 +1499,14 @@ BEGIN SELECT * FROM tmp_Msg_Error; SELECT * FROM tmp_Calc_User; SELECT * FROM tmp_User_Calc_User; - SELECT * FROM tmp_Product_Calc_User; - SELECT * FROM partsltd_prod.Shop_Calc_User_Temp WHERE GUID = a_guid; - CALL partsltd_prod.p_shop_clear_calc_user ( a_guid, a_debug ); + SELECT * FROM partsltd_prod.PH_Calc_User_Temp WHERE GUID = a_guid; + CALL partsltd_prod.p_ph_clear_calc_user ( a_guid, a_debug ); END IF; -- Clean up DROP TABLE IF EXISTS tmp_Calc_User; DROP TABLE IF EXISTS tmp_User_Calc_User; - DROP TABLE IF EXISTS tmp_Product_Calc_User; - -- Don't destroy common tables in nested Stored Procedures! - -- DROP TABLE IF EXISTS tmp_Split; - DELETE FROM tmp_Split; + DELETE FROM tmp_Split_Calc_User; IF a_debug = 1 THEN CALL partsltd_prod.p_debug_timing_reporting( v_time_start ); @@ -8573,74 +1516,41 @@ DELIMITER ; /* -CALL partsltd_prod.p_shop_calc_user ( - 'chips ' - , 1 - , 0 - , '2' - , '1' - , '1,2,3,4,5' - , 0 +CALL partsltd_prod.p_ph_calc_user ( + 'chips ' -- a_guid + , 1 -- a_ids_user + , 0 -- a_get_inactive_user + , '2' -- a_ids_permission + , '1' -- a_ids_access_level + , 0 -- a_debug ); -CALL partsltd_prod.p_shop_calc_user ( - 'chips ' - , 1 - , 0 - , '2' - , '1' - , NULL - , 0 +CALL partsltd_prod.p_ph_calc_user ( + 'chips ' -- a_guid + , 1 -- a_ids_user + , 0 -- a_get_inactive_user + , '2' -- a_ids_permission + , '1' -- a_ids_access_level + , 0 -- a_debug ); -SELECT * FROM partsltd_prod.Shop_Calc_User_Temp WHERE GUID = 'chips '; -DELETE FROM partsltd_prod.Shop_Calc_User_Temp WHERE GUID = 'chips '; - - --- SELECT * FROM partsltd_prod.Shop_Calc_User_Temp; -SELECT * FROM partsltd_prod.Shop_Calc_User_Temp WHERE GUID = 'chips '; -CALL partsltd_prod.p_shop_clear_calc_user ( 'chips ', 0 ); --- SELECT * FROM partsltd_prod.Shop_Calc_User_Temp; -DROP TABLE IF EXISTS tmp_Msg_Error; - - CALL p_shop_calc_user( - 'chips ' - , 1 - , FALSE -- a_get_inactive_users - , 2 - , 1 - , '' -- a_ids_product - , 0 -- a_debug - ); -SELECT * FROM partsltd_prod.Shop_Calc_User_Temp WHERE GUID = 'chips '; -CALL partsltd_prod.p_shop_clear_calc_user ( 'chips ', 0 ); -DROP TABLE IF EXISTS tmp_Msg_Error; - -SELECT * FROM partsltd_prod.shop_user_role_link; -SELECT * FROM partsltd_prod.shop_role_permission_link; - */ +USE partsltd_prod; --- File: 6501_p_shop_clear_calc_user.sql - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_clear_Shop_Calc_User_Temp; -DROP PROCEDURE IF EXISTS p_clear_Shop_Calc_User_Temp; -DROP PROCEDURE IF EXISTS p_shop_clear_calc_user; - +DROP PROCEDURE IF EXISTS partsltd_prod.p_ph_clear_calc_user; DELIMITER // -CREATE PROCEDURE p_shop_clear_calc_user ( - IN a_guid BINARY(36) +CREATE PROCEDURE partsltd_prod.p_ph_clear_calc_user ( + IN a_guid BINARY(36) , IN a_debug BIT ) BEGIN DECLARE v_time_start TIMESTAMP(6); SET v_time_start := CURRENT_TIMESTAMP(6); - CALL p_validate_guid ( a_guid ); + CALL partsltd_prod.p_core_validate_guid ( a_guid ); START TRANSACTION; - DELETE FROM Shop_Calc_User_Temp + DELETE FROM partsltd_prod.PH_Calc_User_Temp WHERE GUID = a_guid ; @@ -8654,7703 +1564,24 @@ DELIMITER ; /* -CALL p_shop_clear_calc_user ( - 'noods, cheese ' -- a_guid +CALL partsltd_prod.p_ph_clear_calc_user ( + 'chips ' -- a_guid , 1 -- debug ); SELECT * -FROM Shop_Calc_User_Temp -WHERE GUID = 'noods, cheese ' +FROM partsltd_prod.PH_Calc_User_Temp +WHERE GUID = 'chips ' ; */ - --- File: 7003_p_shop_get_many_access_level.sql - - - -/* - -CALL p_shop_get_many_access_level ( - 0 -- a_get_inactive_access_level -) - -*/ - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_get_many_access_level; - - -DELIMITER // -CREATE PROCEDURE p_shop_get_many_access_level ( - IN a_get_inactive_access_level BIT -) -BEGIN - SET a_get_inactive_access_level = IFNULL(a_get_inactive_access_level, 0); - - SELECT - AL.id_access_level - , AL.code - , AL.name - , AL.priority - , AL.display_order - , AL.active - FROM Shop_Access_Level AL - WHERE - a_get_inactive_access_level = 1 - OR AL.active = 1 - ORDER BY AL.display_order - ; -END // -DELIMITER ; - - -/* -CALL p_shop_get_many_access_level ( - 0 -- a_get_inactive_access_level -); -*/ - - --- File: 7101_p_shop_get_many_region.sql - - - -/* - -CALL p_shop_get_many_region ( - 0 -- a_get_inactive_region -) - -*/ - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_get_many_region; - - -DELIMITER // -CREATE PROCEDURE p_shop_get_many_region ( - IN a_get_inactive_region BIT -) -BEGIN - IF a_get_inactive_region IS NULL THEN - SET a_get_inactive_region = 0; - END IF; - - SELECT - R.id_region, - R.code, - R.name, - R.active, - R.display_order - FROM Shop_Region R - WHERE a_get_inactive_region - OR R.active - ORDER BY R.display_order - ; -END // -DELIMITER ; - - -/* -CALL p_shop_get_many_region ( - 0 -- a_get_inactive_region -); -*/ - - --- File: 7106_p_shop_get_many_plant.sql - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_get_many_plant; - - -DELIMITER // -CREATE PROCEDURE p_shop_get_many_plant ( - IN a_get_inactive_plant BIT -) -BEGIN - SET a_get_inactive_plant = IFNULL(a_get_inactive_plant, 0); - - SELECT - P.id_plant - , P.id_address - , A.id_region - , P.id_user_manager - , P.code - , P.name - , P.active - FROM Shop_Plant P - INNER JOIN Shop_Address A ON P.id_address = A.id_address - WHERE - a_get_inactive_plant = 1 - OR P.active = 1 - ; -END // -DELIMITER ; - - -/* -CALL p_shop_get_many_plant ( - 0 -- a_get_inactive_plant -); -*/ - - --- File: 7109_p_shop_get_many_storage_location.sql - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_get_many_storage_location; - - -DELIMITER // -CREATE PROCEDURE p_shop_get_many_storage_location ( - IN a_get_inactive_storage_location BIT -) -BEGIN - SET a_get_inactive_storage_location = IFNULL(a_get_inactive_storage_location, 0); - - SELECT - SL.id_location - , P.id_plant - , P.id_address - , A.id_region - , SL.code - , SL.name - , P.active - FROM Shop_Storage_Location SL - INNER JOIN Shop_Plant P ON SL.id_plant = P.id_plant - INNER JOIN Shop_Address A ON P.id_address = A.id_address - WHERE - a_get_inactive_storage_location = 1 - OR SL.active = 1 - ; -END // -DELIMITER ; - - -/* -CALL p_shop_get_many_storage_location ( - 0 -- a_get_inactive_storage_location -); -*/ - - --- File: 7116_p_shop_get_many_currency.sql - - - -/* - -CALL p_shop_get_many_currency ( - 0 -- a_get_inactive_currency -) - -*/ - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_get_many_currency; - - -DELIMITER // -CREATE PROCEDURE p_shop_get_many_currency ( - IN a_get_inactive_currency BIT -) -BEGIN - IF a_get_inactive_currency IS NULL THEN - SET a_get_inactive_currency = 0; - END IF; - - SELECT - C.id_currency, - C.code, - C.name, - C.symbol, - C.factor_from_GBP, - C.display_order, - C.active - FROM Shop_Currency C - WHERE a_get_inactive_currency - OR C.active - ORDER BY C.display_order - ; -END // -DELIMITER ; - - -/* -CALL p_shop_get_many_currency ( - 0 -- a_get_inactive_currency -); -*/ - - --- File: 7122_p_shop_get_many_unit_measurement.sql - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_get_many_unit_measurement; - - -DELIMITER // -CREATE PROCEDURE p_shop_get_many_unit_measurement ( - IN a_get_inactive_unit_measurement BIT -) -BEGIN - SET a_get_inactive_unit_measurement := IFNULL(a_get_inactive_unit_measurement, 0); - - SELECT - UM.id_unit_measurement, - UM.name_singular, - UM.name_plural, - UM.symbol, - UM.symbol_is_suffix_not_prefix, - UM.is_base_unit, - UM.is_unit_of_distance, - UM.is_unit_of_mass, - UM.is_unit_of_time, - UM.is_unit_of_volume, - UM.active - FROM Shop_Unit_Measurement UM - WHERE - a_get_inactive_unit_measurement = 1 - OR UM.active = 1 - ; -END // -DELIMITER ; - - -/* -CALL p_shop_get_many_unit_measurement ( - 0 -- a_get_inactive_unit_measurement -); - -select * -from shop_unit_measurement -*/ - - --- File: 7200_p_shop_save_product_category.sql - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_save_category; -DROP PROCEDURE IF EXISTS p_shop_save_category; -DROP PROCEDURE IF EXISTS p_shop_save_product_category; - - -DELIMITER // -CREATE PROCEDURE p_shop_save_product_category ( - IN a_comment VARCHAR(500), - IN a_guid BINARY(36), - IN a_id_user INT, - IN a_debug BIT -) -BEGIN - DECLARE v_code_type_error_bad_data VARCHAR(100); - DECLARE v_id_type_error_bad_data INT; - DECLARE v_id_permission_product INT; - DECLARE v_ids_product_permission LONGTEXT; - DECLARE v_id_change_set INT; - DECLARE v_id_access_level_edit INT; - DECLARE v_time_start TIMESTAMP(6); - - DECLARE exit handler for SQLEXCEPTION - BEGIN - GET DIAGNOSTICS CONDITION 1 - @sqlstate = RETURNED_SQLSTATE - , @errno = MYSQL_ERRNO - , @text = MESSAGE_TEXT - ; - - ROLLBACK; - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT - , id_type INT NULL - , code VARCHAR(50) NOT NULL - , msg VARCHAR(4000) NOT NULL - ); - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - MET.id_type - , @errno - , @text - FROM partsltd_prod.Shop_Msg_Error_Type MET - WHERE MET.code = 'MYSQL_ERROR' - ; - SELECT * - FROM tmp_Msg_Error; - DROP TABLE IF EXISTS tmp_Msg_Error; - END; - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_code_type_error_bad_data := 'BAD_DATA'; - SET v_id_type_error_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_type_error_bad_data LIMIT 1); - SET v_id_access_level_edit := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'EDIT' LIMIT 1); - - CALL p_validate_guid ( a_guid ); - - DROP TABLE IF EXISTS tmp_Category; - - CREATE TEMPORARY TABLE tmp_Category ( - id_category INT NOT NULL - , code VARCHAR(50) NOT NULL - , name VARCHAR(255) NOT NULL - , description VARCHAR(4000) NULL - , id_access_level_required INT NOT NULL - , active BIT NOT NULL - , display_order INT NOT NULL - , can_view BIT NULL - , can_edit BIT NULL - , can_admin BIT NULL - , name_error VARCHAR(255) NOT NULL - , is_new BIT NOT NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT - , id_type INT NULL - , code VARCHAR(50) NOT NULL - , msg VARCHAR(4000) NOT NULL - ); - - - -- Get data from Temp table - INSERT INTO tmp_Category ( - id_category - , code - , name - , description - , id_access_level_required - , active - , display_order - , name_error - , is_new - ) - SELECT - PC_T.id_category AS id_category - , IFNULL(PC_T.code, PC.code) AS code - , IFNULL(PC_T.name, PC.code) AS name - , IFNULL(PC_T.description, PC.description) AS description - , IFNULL(PC_T.id_access_level_required, PC.id_access_level_required) AS id_access_level_required - , IFNULL(IFNULL(PC_T.active, PC.active), 1) AS active - , IFNULL(PC_T.display_order, PC.display_order) AS display_order - , IFNULL(PC_T.name, IFNULL(PC.name, IFNULL(PC_T.code, IFNULL(PC.code, IFNULL(PC_T.id_category, '(No Product Category)'))))) AS name_error - , CASE WHEN IFNULL(PC_T.id_category, 0) < 1 THEN 1 ELSE 0 END AS is_new - FROM partsltd_prod.Shop_Product_Category_Temp PC_T - LEFT JOIN partsltd_prod.Shop_Product_Category PC ON PC_T.id_category = PC.id_category - WHERE PC_T.guid = a_guid - ; - - -- Validation - -- Missing mandatory fields - -- code - IF EXISTS (SELECT * FROM tmp_Category t_C WHERE ISNULL(t_C.code) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following Product Category(s) do not have a code: ', GROUP_CONCAT(t_C.name_error SEPARATOR ', ')) AS msg - FROM tmp_Category t_C - WHERE ISNULL(t_C.code) - ; - END IF; - -- name - IF EXISTS (SELECT * FROM tmp_Category t_C WHERE ISNULL(t_C.name) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following Product Category(s) do not have a name: ', GROUP_CONCAT(t_C.name_error SEPARATOR ', ')) AS msg - FROM tmp_Category t_C - WHERE ISNULL(t_C.name) - ; - END IF; - -- display_order - IF EXISTS (SELECT * FROM tmp_Category t_C WHERE ISNULL(t_C.display_order) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following Product Category(s) do not have a display order: ', GROUP_CONCAT(t_C.name_error SEPARATOR ', ')) AS msg - FROM tmp_Category t_C - WHERE ISNULL(t_C.display_order) - ; - END IF; - - -- Permissions - SET v_ids_product_permission := ( - SELECT GROUP_CONCAT(P.id_product SEPARATOR ',') - FROM partsltd_prod.Shop_Product P - INNER JOIN tmp_Category t_C - ON P.id_category = t_C.id_category - AND t_C.is_new = 0 - WHERE P.active = 1 - ); - SET v_id_permission_product = (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_PRODUCT' LIMIT 1); - - IF a_debug = 1 THEN - SELECT - a_guid - , a_id_user - , FALSE -- a_get_inactive_user - , v_id_permission_product - , v_id_access_level_edit - , v_ids_product_permission - , 0 -- a_debug - ; - END IF; - - CALL partsltd_prod.p_shop_calc_user( - a_guid - , a_id_user - , FALSE -- a_get_inactive_user - , v_id_permission_product - , v_id_access_level_edit - , v_ids_product_permission - , 0 -- a_debug - ); - - UPDATE tmp_Category t_C - INNER JOIN partsltd_prod.Shop_Product P ON t_C.id_category = P.id_product - INNER JOIN partsltd_prod.Shop_Calc_User_Temp UE_T - ON P.id_product = UE_T.id_product - AND UE_T.GUID = a_guid - SET - t_C.can_view = UE_T.can_view - , t_C.can_edit = UE_T.can_edit - , t_C.can_admin = UE_T.can_admin - ; - - IF EXISTS (SELECT * FROM tmp_Category WHERE IFNULL(can_edit, 0) = 0 AND is_new = 0 LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_no_permission - , v_code_type_error_no_permission - , CONCAT('You do not have permission to edit the following Product Catogory(s): ', IFNULL(GROUP_CONCAT(IFNULL(t_C.name_error, 'NULL') SEPARATOR ', '), 'NULL')) - FROM tmp_Category t_C - WHERE - IFNULL(can_edit, 0) = 0 - AND is_new = 0 - ; - END IF; - - IF EXISTS (SELECT * FROM partsltd_prod.Shop_Calc_User_Temp WHERE ISNULL(id_product) AND GUID = a_guid AND can_edit = 0 LIMIT 1) THEN - DELETE t_ME - FROM tmp_Msg_Error t_ME - WHERE t_ME.id_type <> v_id_type_error_no_permission - ; - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - VALUES ( - v_id_type_error_no_permission - , v_code_type_error_no_permission - , 'You do not have permission to edit Product Catogories.' - ) - ; - END IF; - - CALL partsltd_prod.p_shop_clear_calc_user( - a_guid - , 0 -- a_debug - ); - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - START TRANSACTION; - - INSERT INTO partsltd_prod.Shop_Product_Change_Set ( comment ) - VALUES ( a_comment ) - ; - - SET v_id_change_set := LAST_INSERT_ID(); - - UPDATE partsltd_prod.Shop_Product_Category PC - INNER JOIN tmp_Category t_C - ON PC.id_category = t_C.id_category - AND t_C.is_new = 0 - SET - PC.id_category = t_C.id_category - , PC.code = t_C.code - , PC.name = t_C.name - , PC.description = t_C.description - , PC.id_access_level_required = t_C.id_access_level_required - , PC.active = t_C.active - , PC.display_order = t_C.display_order - , PC.id_change_set = v_id_change_set - ; - - INSERT INTO partsltd_prod.Shop_Product_Category ( - code - , name - , description - , id_access_level_required - , active - , display_order - , created_by - , created_on - ) - SELECT - -- t_C.id_category AS id_category - t_C.code AS code - , t_C.name AS name - , t_C.description AS description - , t_C.id_access_level_required AS id_access_level_required - , t_C.active AS active - , t_C.display_order AS display_order - , a_id_user AS created_by - , v_time_start AS created_on - FROM tmp_Category t_C - WHERE - t_C.is_new = 1 - AND t_C.active = 1 - ; - - COMMIT; - END IF; - - START TRANSACTION; - - DELETE FROM partsltd_prod.Shop_Product_Category_Temp - WHERE GUID = a_guid; - - COMMIT; - - -- Errors - SELECT * - FROM tmp_Msg_Error t_ME - INNER JOIN partsltd_prod.Shop_Msg_Error_Type MET ON t_ME.id_type = MET.id_type - ; - - IF a_debug = 1 THEN - SELECT * from tmp_Category; - END IF; - - DROP TEMPORARY TABLE tmp_Category; - DROP TEMPORARY TABLE tmp_Msg_Error; - - IF a_debug = 1 THEN - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); - END IF; -END // -DELIMITER ; - -/* -select - * - -- COUNT(*) --- delete -from partsltd_prod.Shop_Product_Category_Temp -; - - -CALL partsltd_prod.p_shop_save_product_category ( - 'nipples' - , (SELECT GUID FROM partsltd_prod.Shop_Product_Category_Temp ORDER BY id_temp DESC LIMIT 1) - , 1 - , 1 -); - -select - * - -- COUNT(*) --- delete -from partsltd_prod.Shop_Product_Category_Temp -; - -*/ - - --- File: 7200_p_shop_save_product_category_test.sql - --- Clear previous proc -DROP PROCEDURE IF EXISTS partsltd_prod.p_shop_save_product_category_test; - - -DELIMITER // -CREATE PROCEDURE p_shop_save_product_category_test () -BEGIN - - DECLARE v_guid BINARY(36); - DECLARE v_time_start TIMESTAMP(6); - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_guid := 'nips'; - - SELECT * - FROM partsltd_prod.Shop_Product_Category - ; - SELECT * - FROM partsltd_prod.Shop_Product_Category_Temp - ; - - START TRANSACTION; - - INSERT INTO partsltd_prod.Shop_Product_Category_Temp ( - id_category - , name - , code - , description - , id_access_level_required - , display_order - , guid - ) - VALUES ( - -5 -- id_category - , 'Nips' -- name - , 'Lips' -- code - , 'Chips' -- description - , 2 -- id_access_level_required - , 25 -- display_order - , v_guid - ); - - COMMIT; - - SELECT * - FROM partsltd_prod.Shop_Product_Category_Temp - WHERE GUID = v_guid - ; - - CALL partsltd_prod.p_shop_save_product_category ( - 'Test save product category' -- comment - , v_guid -- guid - , 1 -- id_user - , 1 -- debug - ); - - SELECT * - FROM partsltd_prod.Shop_Product_Category - ; - SELECT * - FROM partsltd_prod.Shop_Product_Category_Temp - ; - - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); -END // -DELIMITER ; - -/* -CALL partsltd_prod.p_shop_save_product_category_test (); - -DELETE FROM partsltd_prod.Shop_Product_Category_Temp; - -DROP TABLE IF EXISTS tmp_Msg_Error; -*/ - - --- File: 7202_p_shop_clear_calc_product_permutation.sql - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_clear_calc_product_permutation; - - -DELIMITER // -CREATE PROCEDURE p_shop_clear_calc_product_permutation ( - IN a_guid BINARY(36) -) -BEGIN - IF ISNULL(a_guid) THEN - - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'GUID is required.'; - - ELSE - - START TRANSACTION; - - DELETE FROM Shop_Product_Category_Temp - WHERE GUID = a_guid - ; - DELETE FROM Shop_Product_Temp - WHERE GUID = a_guid - ; - DELETE FROM Shop_Product_Permutation_Temp - WHERE GUID = a_guid - ; - - COMMIT; - END IF; - -END // -DELIMITER ; - -/* - -CALL p_shop_clear_calc_product_permutation ( - 'noods, cheese ' -- a_guid -); - -SELECT * FROM Shop_Product_Category_Temp -WHERE GUID = a_guid -; -SELECT * FROM Shop_Product_Temp -WHERE GUID = a_guid -; -SELECT * FROM Shop_Product_Permutation_Temp -WHERE GUID = a_guid -; - -*/ - - --- File: 7203_p_shop_save_product.sql - - - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_save_product; -DROP PROCEDURE IF EXISTS p_shop_save_product; - - -DELIMITER // -CREATE PROCEDURE p_shop_save_product ( - IN a_comment VARCHAR(500), - IN a_guid BINARY(36), - IN a_id_user INT, - IN a_debug BIT -) -BEGIN - DECLARE v_code_type_error_bad_data VARCHAR(100); - DECLARE v_id_access_level_edit INT; - DECLARE v_id_type_error_bad_data INT; - DECLARE v_id_permission_product INT; - DECLARE v_ids_product_permission LONGTEXT; - DECLARE v_id_change_set INT; - DECLARE v_time_start TIMESTAMP(6); - - DECLARE exit handler for SQLEXCEPTION - BEGIN - -- Get diagnostic information - GET DIAGNOSTICS CONDITION 1 - @sqlstate = RETURNED_SQLSTATE - , @errno = MYSQL_ERRNO - , @text = MESSAGE_TEXT - ; - - -- Rollback the transaction - ROLLBACK; - - -- Select the error information - -- SELECT 'Error' AS status, @errno AS error_code, @sqlstate AS sql_state, @text AS message; - INSERT INTO tmp_Msg_Error ( - -- guid - id_type - , code - , msg - ) - SELECT - -- a_guid - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'MYSQL_ERROR' LIMIT 1) - , @errno - , IFNULL(@text, 'NULL') - ; - - SELECT * - FROM tmp_Msg_Error t_ME - INNER JOIN partsltd_prod.Shop_Msg_Error_Type MET ON t_ME.id_type = MET.id_type - ; - - DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error; - DROP TEMPORARY TABLE IF EXISTS tmp_Product; - END; - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_code_type_error_bad_data := (SELECT code FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1); - SET v_id_type_error_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_type_error_bad_data LIMIT 1); - SET v_id_access_level_edit := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'EDIT' LIMIT 1); - - CALL p_validate_guid ( a_guid ); - SET a_debug := IFNULL(a_debug, 0); - - IF a_debug = 1 THEN - SELECT - v_code_type_error_bad_data - , v_id_type_error_bad_data - ; - END IF; - - DROP TEMPORARY TABLE IF EXISTS tmp_Product; - DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error; - - CREATE TEMPORARY TABLE tmp_Product ( - id_category INT NOT NULL - , id_product INT NOT NULL - , name VARCHAR(255) NOT NULL - , has_variations BIT NOT NULL - , id_access_level_required INT NOT NULL - , active BIT NOT NULL - , display_order INT NOT NULL - , can_view BIT NULL - , can_edit BIT NULL - , can_admin BIT NULL - , name_error VARCHAR(255) NOT NULL - , is_new BIT NOT NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT - -- , guid BINARY(36) NOT NULL - , id_type INT NOT NULL - /* - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type (id_type), - */ - , code VARCHAR(50) NOT NULL - , msg VARCHAR(4000) NOT NULL - ); - - - -- Get data from Temp table - INSERT INTO tmp_Product ( - id_category - , id_product - , name - , has_variations - , id_access_level_required - , active - , display_order - , name_error - , is_new - ) - SELECT - IFNULL(P_T.id_category, P.id_category) AS id_category - , IFNULL(P_T.id_product, 0) AS id_product - , IFNULL(P_T.name, P.name) AS name - , IFNULL(P_T.has_variations, P.has_variations) AS has_variations - , IFNULL(P_T.id_access_level_required, P.id_access_level_required) AS id_access_level_required - , IFNULL(P_T.active, P.active) AS active - , IFNULL(P_T.display_order, P.display_order) AS display_order - , IFNULL(P_T.name, IFNULL(P.name, IFNULL(P_T.id_product, '(No Product)'))) AS name_error - , CASE WHEN IFNULL(P_T.id_product, 0) < 1 THEN 1 ELSE 0 END AS is_new - FROM partsltd_prod.Shop_Product_Temp P_T - LEFT JOIN partsltd_prod.Shop_Product P ON P_T.id_product = P.id_product - ; - - -- Validation - -- Missing mandatory fields - -- id_category - IF EXISTS (SELECT * FROM tmp_Product t_P WHERE ISNULL(t_P.id_category) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , IFNULL(CONCAT('The following product(s) do not have a category: ', GROUP_CONCAT(IFNULL(t_P.name_error, 'NULL') SEPARATOR ', ')), 'NULL') - FROM tmp_Product t_P - WHERE ISNULL(t_P.id_category) - ; - END IF; - - -- name - IF EXISTS (SELECT * FROM tmp_Product t_P WHERE ISNULL(t_P.name) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , IFNULL(CONCAT('The following product(s) do not have a name: ', GROUP_CONCAT(IFNULL(t_P.name_error, 'NULL') SEPARATOR ', ')), 'NULL') - FROM tmp_Product t_P - WHERE ISNULL(t_P.name) - ; - END IF; - - -- has_variations - IF EXISTS (SELECT * FROM tmp_Product t_P WHERE ISNULL(t_P.has_variations) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , IFNULL(CONCAT('The following product(s) do not have a has-variations setting: ', GROUP_CONCAT(IFNULL(t_P.name_error, 'NULL') SEPARATOR ', ')), 'NULL') - FROM tmp_Product t_P - WHERE ISNULL(t_P.has_variations) - ; - END IF; - - -- id_access_level_required - IF EXISTS (SELECT * FROM tmp_Product t_P WHERE ISNULL(t_P.id_access_level_required) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , IFNULL(CONCAT('The following product(s) do not have a required access level ID: ', GROUP_CONCAT(IFNULL(t_P.name_error, 'NULL') SEPARATOR ', ')), 'NULL') - FROM tmp_Product t_P - WHERE ISNULL(t_P.id_access_level_required) - ; - END IF; - - -- display_order - IF EXISTS (SELECT * FROM tmp_Product t_P WHERE ISNULL(t_P.display_order) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , IFNULL(CONCAT('The following product(s) do not have a display order: ', GROUP_CONCAT(IFNULL(t_P.name_error, 'NULL') SEPARATOR ', ')), 'NULL') - FROM tmp_Product t_P - WHERE ISNULL(t_P.display_order) - ; - END IF; - - - -- Permissions - SET v_ids_product_permission := (SELECT GROUP_CONCAT(id_product SEPARATOR ',') FROM tmp_Product WHERE is_new = 0); - - SET v_id_permission_product = (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_PRODUCT' LIMIT 1); - - CALL partsltd_prod.p_shop_calc_user( - a_guid - , a_id_user - , FALSE -- get_inactive_users - , v_id_permission_product - , v_id_access_level_edit - , v_ids_product_permission - , 0 -- debug - ); - - UPDATE tmp_Product t_P - INNER JOIN partsltd_prod.Shop_Calc_User_Temp UE_T - ON t_P.id_product = UE_T.id_product - AND UE_T.GUID = a_guid - SET - t_P.can_view = UE_T.can_view - , t_P.can_edit = UE_T.can_edit - , t_P.can_admin = UE_T.can_admin - ; - - IF EXISTS (SELECT * FROM tmp_Product WHERE IFNULL(can_edit, 0) = 0 AND is_new = 0 LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_no_permission - , v_code_type_error_no_permission - , CONCAT('You do not have permission to edit the following Product(s): ', IFNULL(GROUP_CONCAT(IFNULL(t_P.name_error, 'NULL') SEPARATOR ', '), 'NULL')) - FROM tmp_Product t_P - WHERE - IFNULL(can_edit, 0) = 0 - AND is_new = 0 - ; - END IF; - - IF EXISTS (SELECT * FROM partsltd_prod.Shop_Calc_User_Temp WHERE ISNULL(id_product) AND GUID = a_guid AND can_edit = 0) THEN - DELETE t_ME - FROM tmp_Msg_Error t_ME - WHERE t_ME.id_type <> v_id_type_error_no_permission - ; - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - VALUES ( - v_id_type_error_no_permission - , v_code_type_error_no_permission - , 'You do not have permission to edit Products' - ) - ; - END IF; - - CALL partsltd_prod.p_shop_clear_calc_user( - a_guid - , 0 -- debug - ); - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - START TRANSACTION; - - INSERT INTO partsltd_prod.Shop_Product_Change_Set ( comment ) - VALUES ( a_comment ) - ; - - SET v_id_change_set := LAST_INSERT_ID(); - - UPDATE partsltd_prod.Shop_Product P - INNER JOIN tmp_Product t_P ON P.id_product = t_P.id_product - SET - P.id_category = t_P.id_category - , P.name = t_P.name - , P.has_variations = t_P.has_variations - , P.id_access_level_required = t_P.id_access_level_required - , P.display_order = t_P.display_order - , P.active = t_P.active - , P.id_change_set = v_id_change_set - ; - - INSERT INTO partsltd_prod.Shop_Product ( - id_category - , name - , has_variations - , id_access_level_required - , display_order - , created_by - , created_on - ) - SELECT - t_P.id_category AS id_category - , t_P.name AS name - , t_P.has_variations AS has_variations - , t_P.id_access_level_required AS id_access_level_required - , t_P.display_order AS display_order - , a_id_user AS created_by - , v_time_start AS created_on - FROM tmp_Product t_P - WHERE is_new = 1 - ; - - COMMIT; - END IF; - - START TRANSACTION; - - DELETE FROM partsltd_prod.Shop_Product_Temp - WHERE GUID = a_guid; - - COMMIT; - - SELECT * - FROM tmp_Msg_Error t_ME - INNER JOIN partsltd_prod.Shop_Msg_Error_Type MET ON t_ME.id_type = MET.id_type - ; - - DROP TEMPORARY TABLE IF EXISTS tmp_Product; - DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error; - - IF a_debug = 1 THEN - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); - END IF; -END // -DELIMITER ; - - - --- File: 7203_p_shop_save_product_test.sql - - --- Clear previous proc -DROP PROCEDURE IF EXISTS partsltd_prod.p_shop_save_product_test; - - -DELIMITER // -CREATE PROCEDURE p_shop_save_product_test () -BEGIN - - DECLARE v_guid BINARY(36); - DECLARE v_time_start TIMESTAMP(6); - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_guid := 'nips'; - - SELECT * - FROM partsltd_prod.Shop_Product - ; - SELECT * - FROM partsltd_prod.Shop_Product_Temp - ; - - START TRANSACTION; - - INSERT INTO partsltd_prod.Shop_Product_Temp ( - id_product - , id_category - , name - , has_variations - , id_access_level_required - , display_order - , active - , guid - ) - VALUES - /* Test 1 - Update - ( - 4 -- id_product - , 1 -- id_category - , 'Laptops' -- name - , 0 -- has_variations - , 2 -- id_access_level_required - , 2 -- display_order - , 1 -- active - , v_guid - ) - */ - /* Test 2 - Insert */ - ( - -14 -- id_product - , 5 -- id_category - , 'Clip' -- name - , 0 -- has_variations - , 1 -- id_access_level_required - , 1 -- display_order - , 1 -- active - , v_guid - ) - ; - - COMMIT; - - SELECT * - FROM partsltd_prod.Shop_Product_Temp - WHERE GUID = v_guid - ; - - CALL partsltd_prod.p_shop_save_product ( - 'Test save product' -- comment - , v_guid -- guid - , 1 -- id_user - , 1 -- debug - ); - - SELECT * - FROM partsltd_prod.Shop_Product - ; - SELECT * - FROM partsltd_prod.Shop_Product_Temp - ; - - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); -END // -DELIMITER ; - -/* -CALL partsltd_prod.p_shop_save_product_test (); - -DELETE FROM partsltd_prod.Shop_Product_Temp; - -DROP TABLE IF EXISTS tmp_Msg_Error; -*/ - --- File: 7204_p_shop_calc_product_permutation.sql --- USE partsltd_prod; - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_calc_product_permutation; - -DELIMITER // -CREATE PROCEDURE p_shop_calc_product_permutation ( - IN a_id_user INT - , IN a_get_all_product_category BIT - , IN a_get_inactive_product_category BIT - , IN a_ids_product_category TEXT - , IN a_get_all_product BIT - , IN a_get_inactive_product BIT - , IN a_ids_product TEXT - , IN a_get_all_product_permutation BIT - , IN a_get_inactive_permutation BIT - , IN a_ids_permutation TEXT - , IN a_get_products_quantity_stock_below_min BIT - , IN a_guid BINARY(36) - , IN a_debug BIT -) -BEGIN -/* - PROCEDURE p_shop_calc_product_permutation - Shared filtering for product permutations - - select * FROM partsltd_prod.Shop_msg_error_type; -*/ - DECLARE v_has_filter_product_category BIT; - DECLARE v_has_filter_product BIT; - DECLARE v_has_filter_permutation BIT; - DECLARE v_id_permission_product INT; - DECLARE v_ids_product_permission TEXT; - DECLARE v_id_access_level_view INT; - DECLARE v_id_minimum INT; - DECLARE v_ids_product_invalid TEXT; - DECLARE v_ids_category_invalid TEXT; - DECLARE v_time_start TIMESTAMP(6); - DECLARE v_id_type_error_bad_data INT; - DECLARE v_code_type_error_bad_data VARCHAR(50); - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_id_access_level_view := (SELECT id_access_level FROM partsltd_prod.Shop_Access_Level WHERE code = 'VIEW'); - - SELECT - MET.id_type - , MET.code - INTO - v_id_type_error_bad_data - , v_code_type_error_bad_data - FROM partsltd_prod.Shop_Msg_Error_Type MET - WHERE MET.code = 'BAD_DATA' - ; - - SET a_id_user := IFNULL(a_id_user, 0); - SET a_get_all_product_category := IFNULL(a_get_all_product_category, 0); - SET a_get_inactive_product_category := IFNULL(a_get_inactive_product_category, 0); - SET a_ids_product_category := TRIM(IFNULL(a_ids_product_category, '')); - SET a_get_all_product := IFNULL(a_get_all_product, 0); - SET a_get_inactive_product := IFNULL(a_get_inactive_product, 0); - SET a_ids_product := TRIM(IFNULL(a_ids_product, '')); - SET a_get_all_product_permutation := IFNULL(a_get_all_product_permutation, 0); - SET a_get_inactive_permutation := IFNULL(a_get_inactive_permutation, 0); - SET a_ids_permutation := TRIM(IFNULL(a_ids_permutation, '')); - SET a_get_products_quantity_stock_below_min := IFNULL(a_get_products_quantity_stock_below_min, 0); - -- SET a_guid := IFNULL(a_guid, UUID()); - SET a_debug := IFNULL(a_debug, 0); - - IF a_debug = 1 THEN - SELECT - a_id_user - , a_get_all_product_category, a_ids_product_category, a_get_inactive_product_category - , a_get_all_product, a_get_inactive_product, a_ids_product - , a_get_all_product_permutation, a_get_inactive_permutation, a_ids_permutation - , a_get_products_quantity_stock_below_min - , a_debug - ; - END IF; - - -- Temporary tables - -- DROP TEMPORARY TABLE IF EXISTS tmp_Split; - DROP TEMPORARY TABLE IF EXISTS tmp_Category_calc; - DROP TEMPORARY TABLE IF EXISTS tmp_Product_calc; - DROP TEMPORARY TABLE IF EXISTS tmp_Permutation_calc; - - - CREATE TEMPORARY TABLE tmp_Category_calc ( - id_category INT NOT NULL - -- , active BIT NOT NULL - -- display_order INT NOT NULL - ); - - CREATE TEMPORARY TABLE tmp_Product_calc ( - id_category INT NOT NULL - , id_product INT NOT NULL - -- active BIT NOT NULL - -- display_order INT NOT NULL - , can_view BIT - , can_edit BIT - , can_admin BIT - ); - - CREATE TEMPORARY TABLE tmp_Permutation_calc ( - id_permutation INT NULL - -- id_category INT NOT NULL - , id_product INT NOT NULL - -- , active BIT NOT NULL - -- , display_order INT NOT NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT - -- , guid BINARY(36) NOT NULL - , id_type INT NULL - , code VARCHAR(50) NOT NULL - , msg VARCHAR(4000) NOT NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Split ( - substring VARCHAR(4000) NOT NULL - , as_int INT NULL - ); - DELETE FROM tmp_Split; - - -- Parse filters - SET v_has_filter_product_category = CASE WHEN a_ids_product_category = '' THEN 0 ELSE 1 END; - SET v_has_filter_product = CASE WHEN a_ids_product = '' THEN 0 ELSE 1 END; - SET v_has_filter_permutation = CASE WHEN a_ids_permutation = '' THEN 0 ELSE 1 END; - - CALL p_validate_guid ( a_guid ); - - IF a_debug = 1 THEN - SELECT - v_has_filter_product_category - , v_has_filter_product - , v_has_filter_permutation - ; - END IF; - - -- Categories - IF TRUE THEN -- NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - CALL partsltd_prod.p_split(a_guid, a_ids_product_category, ',', a_debug); - - INSERT INTO tmp_Split ( - substring - , as_int - ) - SELECT - substring - , CONVERT(substring, DECIMAL(10,0)) AS as_int - FROM partsltd_prod.Split_Temp - WHERE 1=1 - AND GUID = a_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( a_guid ); - END IF; - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Product_Category PC ON t_S.as_int = PC.id_category - WHERE - ISNULL(t_S.as_int) - OR ISNULL(PC.id_category) - OR ( - PC.active = 0 - AND a_get_inactive_product_category = 0 - ) - ) THEN - INSERT INTO tmp_Msg_Error ( - -- guid, - id_type, - code, - msg - ) - SELECT - -- a_guid, - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Invalid or inactive category IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Product_Category PC ON t_S.as_int = PC.id_category - WHERE - ISNULL(t_S.as_int) - OR ISNULL(PC.id_category) - OR ( - PC.active = 0 - AND a_get_inactive_product_category = 0 - ) - ; - ELSE - INSERT INTO tmp_Category_calc ( - id_category - ) - SELECT - PC.id_category - FROM tmp_Split t_S - RIGHT JOIN partsltd_prod.Shop_Product_Category PC ON t_S.as_int = PC.id_category - WHERE ( - a_get_all_product_category = 1 - OR ( - v_has_filter_product_category = 1 - AND NOT ISNULL(t_S.as_int) - ) - ) - AND ( - a_get_inactive_product_category = 1 - OR PC.active = 1 - ) - ; - END IF; - END IF; - - DELETE FROM tmp_Split; - - -- Products - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - CALL partsltd_prod.p_split(a_guid, a_ids_product, ',', a_debug); - - INSERT INTO tmp_Split ( - substring - , as_int - ) - SELECT - substring - , CONVERT(substring, DECIMAL(10,0)) AS as_int - FROM partsltd_prod.Split_Temp - WHERE 1=1 - AND GUID = a_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( a_guid ); - END IF; - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Product P ON t_S.as_int = P.id_product - WHERE - ISNULL(t_S.as_int) - OR ISNULL(P.id_product) - OR ( - P.active = 0 - AND a_get_inactive_product = 0 - ) - ) THEN - INSERT INTO tmp_Msg_Error ( - -- guid, - id_type, - code, - msg - ) - SELECT - -- a_guid, - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Invalid or inactive product IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Product P ON t_S.as_int = P.id_product - WHERE - ISNULL(t_S.as_int) - OR ISNULL(P.id_product) - OR ( - P.active = 0 - AND a_get_inactive_product = 0 - ) - ; - ELSE - INSERT INTO tmp_Product_calc ( - id_category - , id_product - ) - SELECT - P.id_category - , P.id_product - FROM tmp_Split t_S - RIGHT JOIN partsltd_prod.Shop_Product P ON t_S.as_int = P.id_product - INNER JOIN tmp_Category_calc t_C ON P.id_category = t_C.id_category - WHERE ( - a_get_all_product = 1 - OR ( - v_has_filter_product = 1 - AND NOT ISNULL(t_S.as_int) - ) - ) - AND ( - a_get_inactive_product = 1 - OR P.active = 1 - ) - ; - END IF; - END IF; - - DELETE FROM tmp_Split; - - -- Permutations - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - CALL partsltd_prod.p_split(a_guid, a_ids_product, ',', a_debug); - - INSERT INTO tmp_Split ( - substring - , as_int - ) - SELECT - substring - , CONVERT(substring, DECIMAL(10,0)) AS as_int - FROM partsltd_prod.Split_Temp - WHERE 1=1 - AND GUID = a_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( a_guid ); - END IF; - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Product_Permutation PP ON t_S.as_int = PP.id_permutation - WHERE - ISNULL(t_S.as_int) - OR ISNULL(PP.id_permutation) - ) THEN - INSERT INTO tmp_Msg_Error ( - -- guid, - id_type, - code, - msg - ) - SELECT - -- a_guid, - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Invalid or inactive permutation IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Product_Permutation PP ON t_S.as_int = PP.id_permutation - WHERE - ISNULL(t_S.as_int) - OR ISNULL(PP.id_permutation) - OR ( - PP.active = 0 - AND a_get_inactive_product_permutation = 0 - ) - ; - ELSE - INSERT INTO tmp_Permutation_calc ( - id_permutation - -- id_category, - , id_product - ) - SELECT - PP.id_permutation - -- P.id_category, - , PP.id_product - FROM tmp_Split t_S - RIGHT JOIN partsltd_prod.Shop_Product_Permutation PP ON t_S.as_int = PP.id_permutation - INNER JOIN tmp_Product_calc t_P ON PP.id_product = t_P.id_product - WHERE 1=1 - AND ( - a_get_all_product_permutation = 1 - OR ( - v_has_filter_permutation = 1 - AND NOT ISNULL(t_S.as_int) - ) - ) - AND ( - a_get_products_quantity_stock_below_min = 0 - OR PP.quantity_stock < PP.quantity_min - ) - AND ( - a_get_inactive_permutation = 1 - OR PP.active = 1 - ) - ; - END IF; - END IF; - - DELETE FROM tmp_Split; - - -- Permissions - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF EXISTS (SELECT * FROM tmp_Product_calc LIMIT 1) THEN - SET v_id_permission_product := (SELECT id_permission FROM partsltd_prod.Shop_Permission WHERE code = 'STORE_PRODUCT' LIMIT 1); - SET v_ids_product_permission := (SELECT GROUP_CONCAT(id_product SEPARATOR ',') FROM tmp_Product_calc WHERE NOT ISNULL(id_product)); - - IF a_debug = 1 THEN - SELECT - a_guid AS a_guid - , a_id_user - , false AS a_get_inactive_user - , v_id_permission_product AS a_ids_permission - , v_id_access_level_view AS a_ids_access_level - , v_ids_product_permission AS a_ids_product - ; - END IF; - - CALL p_shop_calc_user( - a_guid - , a_id_user - , false -- a_get_inactive_user - , v_id_permission_product -- a_ids_permission - , v_id_access_level_view -- a_ids_access_level - , v_ids_product_permission -- a_ids_permutation - , false -- a_debug - ); - - - UPDATE tmp_Product_calc t_P - INNER JOIN partsltd_prod.Shop_Calc_User_Temp UE_T - ON t_P.id_product = UE_T.id_product - AND UE_T.GUID = a_guid - SET t_P.can_view = UE_T.can_view, - t_P.can_edit = UE_T.can_edit, - t_P.can_admin = UE_T.can_admin - ; - - IF a_debug = 1 THEN - SELECT * - FROM partsltd_prod.Shop_Calc_User_Temp - WHERE GUID = a_guid - ; - END IF; - - SET v_ids_product_invalid := ( - SELECT GROUP_CONCAT(t_P.id_product SEPARATOR ',') - FROM tmp_Product_calc t_P - WHERE ISNULL(t_P.can_view) - ); - SET v_ids_category_invalid := ( - SELECT GROUP_CONCAT(t_P.id_category SEPARATOR ',') - FROM (SELECT DISTINCT id_category, id_product, can_view FROM tmp_Product_calc) t_P - WHERE ISNULL(t_P.can_view) - ); - - DELETE t_C - FROM tmp_Category_calc t_C - WHERE FIND_IN_SET(t_C.id_category, v_ids_category_invalid) > 0 - ; - - DELETE t_P - FROM tmp_Product_calc t_P - WHERE FIND_IN_SET(t_P.id_product, v_ids_product_invalid) > 0 - ; - - DELETE t_PP - FROM tmp_Permutation_calc t_PP - WHERE FIND_IN_SET(t_PP.id_product, v_ids_product_invalid) > 0 - ; - - CALL p_shop_clear_calc_user( a_guid, a_debug ); - END IF; - END IF; - - IF a_debug = 1 THEN - SELECT * FROM tmp_Category_calc; - SELECT * FROM tmp_Product_calc; - SELECT * FROM tmp_Permutation_calc; - END IF; - - -- Transaction - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - /* - DELETE FROM tmp_Category_calc; - DELETE FROM tmp_Product_calc; - DELETE FROM tmp_Permutation_calc; - ELSE - SELECT * FROM Shop_Product_Category_Temp; - SELECT * FROM Shop_Product_Temp; - SELECT * FROM Shop_Product_Permutation_Temp; - */ - START TRANSACTION; - - -- Categories - INSERT INTO Shop_Product_Category_Temp ( - id_category - , code - , name - , description - , id_access_level_required - , display_order - , active - , can_view - , can_edit - , can_admin - , guid - ) - SELECT - t_C.id_category - , PC.code - , PC.name - , PC.description - , PC.id_access_level_required - , PC.display_order - , PC.active - , MIN(IFNULL(t_P.can_view, 0)) AS can_view - , MIN(IFNULL(t_P.can_edit, 0)) AS can_edit - , MIN(IFNULL(t_P.can_admin, 0)) AS can_admin - , a_guid - FROM tmp_Category_calc t_C - INNER JOIN partsltd_prod.Shop_Product_Category PC ON t_C.id_category = PC.id_category - LEFT JOIN tmp_Product_calc t_P ON t_C.id_category = t_P.id_product - GROUP BY PC.id_category - ; - - -- Products - INSERT INTO Shop_Product_Temp ( - id_product - , id_category - , name - , has_variations - , id_access_level_required - , display_order - , active - , can_view - , can_edit - , can_admin - , guid - ) - SELECT - t_P.id_product - , P.id_category - , P.name - , P.has_variations - , P.id_access_level_required - , P.display_order - , P.active - , t_P.can_view - , t_P.can_edit - , t_P.can_admin - , a_guid - FROM tmp_Product_calc t_P - INNER JOIN partsltd_prod.Shop_Product P ON t_P.id_product = P.id_product - INNER JOIN tmp_Category_calc t_C ON t_P.id_category = t_C.id_category - INNER JOIN partsltd_prod.Shop_Access_Level AL ON P.id_access_level_required = AL.id_access_level - GROUP BY P.id_product, t_P.can_view, t_P.can_edit, t_P.can_admin - ; - - -- Product Permutations - INSERT INTO Shop_Product_Permutation_Temp ( - id_permutation - , id_product - , description - , cost_local_VAT_excl - , cost_local_VAT_incl - , id_currency_cost - , profit_local_min - , latency_manufacture - , id_unit_measurement_quantity - , count_unit_measurement_per_quantity_step - , quantity_min - , quantity_max - , quantity_stock - , is_subscription - , id_unit_measurement_interval_recurrence - , count_interval_recurrence - , id_stripe_product - , does_expire_faster_once_unsealed - , id_unit_measurement_interval_expiration_unsealed - , count_interval_expiration_unsealed - , active - , can_view - , can_edit - , can_admin - , guid - ) - SELECT - t_PP.id_permutation - , PP.id_product - , PP.description - , PP.cost_local_VAT_excl - , PP.cost_local_VAT_incl - , PP.id_currency_cost - , PP.profit_local_min - , PP.latency_manufacture - , PP.id_unit_measurement_quantity - , PP.count_unit_measurement_per_quantity_step - , PP.quantity_min - , PP.quantity_max - , PP.quantity_stock - , PP.is_subscription - , PP.id_unit_measurement_interval_recurrence - , PP.count_interval_recurrence - , PP.id_stripe_product - , PP.does_expire_faster_once_unsealed - , PP.id_unit_measurement_interval_expiration_unsealed - , PP.count_interval_expiration_unsealed - , PP.active - , IFNULL(t_P.can_view, 0) AS can_view - , IFNULL(t_P.can_edit, 0) AS can_edit - , IFNULL(t_P.can_admin, 0) AS can_admin - , a_guid - FROM tmp_Permutation_calc t_PP - INNER JOIN partsltd_prod.Shop_Product_Permutation PP ON t_PP.id_permutation = PP.id_permutation - INNER JOIN tmp_Product_calc t_P ON t_PP.id_product = t_P.id_product - INNER JOIN partsltd_prod.Shop_Product P ON t_PP.id_product = P.id_product - INNER JOIN partsltd_prod.Shop_Product_Category PC ON P.id_category = PC.id_category - LEFT JOIN partsltd_prod.Shop_Product_Permutation_Variation_Link PPVL ON PP.id_permutation = PPVL.id_permutation - LEFT JOIN partsltd_prod.Shop_Unit_Measurement UM_Q ON PP.id_unit_measurement_quantity = UM_Q.id_unit_measurement - LEFT JOIN partsltd_prod.Shop_Unit_Measurement UM_R ON PP.id_unit_measurement_interval_recurrence = UM_R.id_unit_measurement - LEFT JOIN partsltd_prod.Shop_Unit_Measurement UM_X ON PP.id_unit_measurement_interval_expiration_unsealed = UM_X.id_unit_measurement - INNER JOIN partsltd_prod.Shop_Currency C ON PP.id_currency_cost = C.id_currency - GROUP BY PP.id_permutation, t_P.can_view, t_P.can_edit, t_P.can_admin - ; - - COMMIT; - END IF; - - /* - -- Errors - SELECT - t_ME.display_order, - t_ME.guid, - t_ME.id_type, - t_ME.msg, - MET.code, - MET.name, - MET.description - FROM tmp_Msg_Error t_ME - INNER JOIN partsltd_prod.Shop_Msg_Error_Type MET - ON t_ME.id_type = MET.id_type - WHERE guid = a_guid - ; - */ - - IF a_debug = 1 THEN - SELECT * - FROM tmp_Msg_Error - ; - - SELECT * - FROM partsltd_prod.Shop_Product_Category_Temp - WHERE GUID = a_guid - ; - SELECT * - FROM partsltd_prod.Shop_Product_Temp - WHERE GUID = a_guid - ; - SELECT * - FROM partsltd_prod.Shop_Product_Permutation_Temp - WHERE GUID = a_guid - ; - - CALL p_shop_clear_calc_product_permutation ( a_guid ); - END IF; - - -- Clean up - -- DROP TEMPORARY TABLE IF EXISTS tmp_Split; - DROP TEMPORARY TABLE IF EXISTS tmp_Permutation_calc; - DROP TEMPORARY TABLE IF EXISTS tmp_Product_calc; - DROP TEMPORARY TABLE IF EXISTS tmp_Category_calc; - - IF a_debug = 1 THEN - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); - END IF; -END // -DELIMITER ; - - -/* - -CALL partsltd_prod.p_shop_calc_product_permutation ( - 1 --'auth0|6582b95c895d09a70ba10fef', -- a_id_user - , 1 -- a_get_all_product_category - , 0 -- a_get_inactive_product_category - , '' -- a_ids_product_category - , 1 -- a_get_all_product - , 0 -- a_get_inactive_product - , '' -- a_ids_product - , 1 -- a_get_all_product_permutation - , 0 -- a_get_inactive_permutation - , '' -- a_ids_permutation - , 0 -- a_get_products_quantity_stock_below_minimum - , 'NIPS ' -- a_guid - , 0 -- a_debug -); - - - SELECT * - FROM partsltd_prod.Shop_Product_Category_Temp - WHERE GUID = 'NIPS ' - ; - SELECT * - FROM partsltd_prod.Shop_Product_Temp - WHERE GUID = 'NIPS ' - ; - SELECT * - FROM partsltd_prod.Shop_Product_Permutation_Temp - WHERE GUID = 'NIPS ' - ; - - CALL p_shop_clear_calc_product_permutation ( 'NIPS ' ); - - SELECT * - FROM partsltd_prod.Shop_Product_Category_Temp - WHERE GUID = 'NIPS ' - ; - SELECT * - FROM partsltd_prod.Shop_Product_Temp - WHERE GUID = 'NIPS ' - ; - SELECT * - FROM partsltd_prod.Shop_Product_Permutation_Temp - WHERE GUID = 'NIPS ' - ; - -*/ - --- File: 7204_p_shop_get_many_product.sql --- USE partsltd_prod; --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_get_many_product; +DROP PROCEDURE IF EXISTS partsltd_prod.p_ph_save_contact_form; DELIMITER // -CREATE PROCEDURE p_shop_get_many_product ( - IN a_id_user INT - , IN a_get_all_product_category BIT - , IN a_get_inactive_product_category BIT - , IN a_ids_product_category VARCHAR(500) - , IN a_get_all_product BIT - , IN a_get_inactive_product BIT - , IN a_ids_product VARCHAR(500) - , IN a_get_all_product_permutation BIT - , IN a_get_inactive_permutation BIT - , IN a_ids_permutation VARCHAR(4000) - , IN a_get_all_image BIT - , IN a_get_inactive_image BIT - , IN a_ids_image VARCHAR(4000) - , IN a_get_products_quantity_stock_below_min BIT - , IN a_debug BIT -) -BEGIN - - -- Argument redeclaration - -- Variable declaration - -- DECLARE v_has_filter_product_category BIT; - -- DECLARE v_has_filter_product BIT; - -- DECLARE v_has_filter_permutation BIT; - DECLARE v_has_filter_image BIT; - DECLARE v_guid BINARY(36); - -- DECLARE v_id_user VARCHAR(100); - -- DECLARE v_ids_permutation_unavailable VARCHAR(4000); - DECLARE v_id_permission_product INT; - DECLARE v_ids_product_permission VARCHAR(4000); - -- DECLARE v_ids_permutation_permission VARCHAR(4000); - DECLARE v_id_access_level_view INT; - -- DECLARE v_now DATETIME; - DECLARE v_id_minimum INT; - DECLARE v_ids_product_invalid VARCHAR(4000); - DECLARE v_time_start TIMESTAMP(6); - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_guid := UUID(); - SET v_id_access_level_view := (SELECT id_access_level FROM partsltd_prod.Shop_Access_Level WHERE code = 'VIEW'); - - - -- Argument validation + default values - SET a_id_user := IFNULL(a_id_user, 0); - SET a_get_all_product_category := IFNULL(a_get_all_product_category, 0); - SET a_get_inactive_product_category := IFNULL(a_get_inactive_product_category, 0); - SET a_ids_product_category := TRIM(IFNULL(a_ids_product_category, '')); - SET a_get_all_product := IFNULL(a_get_all_product, 0); - SET a_get_inactive_product := IFNULL(a_get_inactive_product, 0); - SET a_ids_product := TRIM(IFNULL(a_ids_product, '')); - SET a_get_all_product_permutation := IFNULL(a_get_all_product_permutation, 0); - SET a_get_inactive_permutation := IFNULL(a_get_inactive_permutation, 0); - SET a_ids_permutation := TRIM(IFNULL(a_ids_permutation, '')); - SET a_get_all_image := IFNULL(a_get_all_image, 0); - SET a_get_inactive_image := IFNULL(a_get_inactive_image, 0); - SET a_ids_image := TRIM(IFNULL(a_ids_image, '')); - SET a_get_products_quantity_stock_below_min := IFNULL(a_get_products_quantity_stock_below_min, 0); - SET a_debug := IFNULL(a_debug, 0); - - IF a_debug = 1 THEN - SELECT - a_id_user - , a_get_all_product_category, a_ids_product_category, a_get_inactive_product_category - , a_get_all_product, a_get_inactive_product, a_ids_product - , a_get_all_product_permutation, a_get_inactive_permutation, a_ids_permutation - , a_get_all_image, a_get_inactive_image, a_ids_image - , a_get_products_quantity_stock_below_min - , a_debug - ; - END IF; - - -- Temporary tables - DROP TEMPORARY TABLE IF EXISTS tmp_Split; - DROP TEMPORARY TABLE IF EXISTS tmp_Image; - DROP TEMPORARY TABLE IF EXISTS tmp_Category; - DROP TEMPORARY TABLE IF EXISTS tmp_Permutation; - DROP TEMPORARY TABLE IF EXISTS tmp_Product; - - CREATE TEMPORARY TABLE tmp_Category ( - id_category INT NOT NULL - /* - active BIT NOT NULL - */ - , display_order INT NOT NULL - ); - - CREATE TEMPORARY TABLE tmp_Product ( - id_category INT NOT NULL - , id_product INT NOT NULL - , display_order INT NOT NULL - /* - active BIT NOT NULL, - */ - , can_view BIT - , can_edit BIT - , can_admin BIT - ); - - CREATE TEMPORARY TABLE tmp_Permutation ( - id_permutation INT NULL - -- id_category INT NOT NULL, - , id_product INT NOT NULL - -- , active BIT NOT NULL - -- , display_order INT NOT NULL - ); - - CREATE TEMPORARY TABLE tmp_Image ( - id_image INT NOT NULL - -- id_product INT NOT NULL, - , id_permutation INT NULL - /* - active BIT NOT NULL - display_order INT NOT NULL - -- rank_in_product_permutation INT NOT NULL - */ - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - -- guid BINARY(36) NOT NULL, - id_type INT NULL, - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Split ( - substring VARCHAR(4000) NOT NULL - , as_int INT NULL - ); - DELETE FROM tmp_Split; - - - -- Parse filters - -- CALL p_validate_guid ( v_guid ); - -- SET v_has_filter_product_category = CASE WHEN a_ids_product_category = '' THEN 0 ELSE 1 END; - -- SET v_has_filter_product = CASE WHEN a_ids_product = '' THEN 0 ELSE 1 END; - -- SET v_has_filter_permutation = CASE WHEN a_ids_permutation = '' THEN 0 ELSE 1 END; - SET v_has_filter_image = CASE WHEN a_ids_image = '' THEN 0 ELSE 1 END; - - -- select v_has_filter_product, v_has_filter_permutation; - - CALL partsltd_prod.p_shop_calc_product_permutation ( - a_id_user - , a_get_all_product_category - , a_get_inactive_product_category - , a_ids_product_category - , a_get_all_product - , a_get_inactive_product - , a_ids_product - , a_get_all_product_permutation - , a_get_inactive_permutation - , a_ids_permutation - , a_get_products_quantity_stock_below_min - , v_guid -- a_guid - , 0 -- a_debug - ); - - INSERT INTO tmp_Category ( - id_category - /* - active, - */ - , display_order - ) - SELECT - PC.id_category - /* - PC.active, - */ - , PC.display_order - FROM (SELECT * FROM partsltd_prod.Shop_Product_Category_Temp WHERE GUID = v_guid) PC_T - INNER JOIN partsltd_prod.Shop_Product_Category PC ON PC_T.id_category = PC.id_category - ; - - INSERT INTO tmp_Product ( - id_product - , id_category - /* - active - */ - , display_order - ) - SELECT - P.id_product - , P.id_category - -- P.active, - , P.display_order - FROM (SELECT * FROM partsltd_prod.Shop_Product_Temp WHERE GUID = v_guid) P_T - INNER JOIN partsltd_prod.Shop_Product P ON P.id_product = P_T.id_product - ; - - INSERT INTO tmp_Permutation ( - id_permutation - -- id_category, - , id_product - -- , active - -- , display_order - ) - SELECT - PP.id_permutation - -- P.id_category, - , PP.id_product - -- , PP.active - -- , RANK() OVER (ORDER BY VT.display_order, V.display_order) - FROM (SELECT * FROM partsltd_prod.Shop_Product_Permutation_Temp WHERE GUID = v_guid) PP_T - INNER JOIN partsltd_prod.Shop_Product_Permutation PP ON PP_T.id_permutation = PP.id_permutation - ; - - -- Product Images - IF (v_has_filter_image = 1 AND NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1)) THEN - CALL partsltd_prod.p_split(v_guid, a_ids_image, ',', a_debug); - - INSERT INTO tmp_Split ( - substring - , as_int - ) - SELECT - substring - , CONVERT(substring, DECIMAL(10,0)) AS as_int - FROM partsltd_prod.Split_Temp - WHERE 1=1 - AND GUID = v_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( v_guid ); - END IF; - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Product_Image I ON t_S.as_int = I.id_image - WHERE - ISNULL(t_S.as_int) - OR ISNULL(I.id_image) - ) THEN - INSERT INTO tmp_Msg_Error ( - -- guid, - id_type, - code, - msg - ) - SELECT - -- v_guid, - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Invalid or inactive image IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Product_Image I ON t_S.as_int = I.id_image - WHERE - ISNULL(t_S.as_int) - OR ISNULL(I.id_image) - -- OR PC.active = 0 - ; - ELSE - INSERT INTO tmp_Image ( - id_image - , id_permutation - ) - SELECT - I.id_image - , I.id_permutation - FROM tmp_Split t_S - RIGHT JOIN partsltd_prod.Shop_Product_Image I ON t_S.as_int = I.id_image - INNER JOIN tmp_Permutation t_PP ON I.id_permutation = t_PP.id_permutation - WHERE - ( - a_get_all_image = 1 - OR NOT ISNULL(t_S.as_int) - ) - AND ( - a_get_inactive_image = 1 - OR I.active = 1 - ) - ; - END IF; - END IF; - - DELETE FROM tmp_Split; - - -- Outputs - -- Categories - SELECT - -- DISTINCT - t_C.id_category - , PC.code - , PC.name - , PC.description - , PC.id_access_level_required - , AL.name AS name_access_level_required - , PC.display_order - , PC.active - , MIN(t_P.can_view) AS can_view - , MIN(t_P.can_edit) AS can_edit - , MIN(t_P.can_admin) AS can_admin - FROM tmp_Category t_C - INNER JOIN partsltd_prod.Shop_Product_Category PC ON t_C.id_category = PC.id_category - LEFT JOIN tmp_Product t_P ON t_C.id_category = t_P.id_product - INNER JOIN partsltd_prod.Shop_Access_Level AL ON PC.id_access_level_required = AL.id_access_level - GROUP BY t_C.id_category -- , t_P.id_product - ORDER BY PC.display_order - ; - - -- Products - SELECT - t_P.id_product, - P.id_category, - P.name, - P.has_variations, - P.id_access_level_required, - AL.name AS name_access_level_required, - P.active, - P.display_order, - t_P.can_view, - t_P.can_edit, - t_P.can_admin - FROM tmp_Product t_P - INNER JOIN partsltd_prod.Shop_Product P ON t_P.id_product = P.id_product - INNER JOIN tmp_Category t_C ON t_P.id_category = t_C.id_category - INNER JOIN partsltd_prod.Shop_Access_Level AL ON P.id_access_level_required = AL.id_access_level - GROUP BY t_P.id_category, t_C.display_order, t_P.id_product, t_P.can_view, t_P.can_edit, t_P.can_admin - ORDER BY t_C.display_order, P.display_order - ; - - -- Product Permutations - SELECT - t_PP.id_permutation, - PP.id_product, - P.id_category, - PP.description, - PP.cost_local_VAT_excl, - PP.cost_local_VAT_incl, - PP.id_currency_cost, - C.code AS code_currency_cost, - C.symbol AS symbol_currency_cost, - PP.profit_local_min, - PP.latency_manufacture, - PP.id_unit_measurement_quantity, - UM_Q.symbol AS symbol_unit_measurement_quantity, - UM_Q.symbol_is_suffix_not_prefix AS symbol_is_suffix_not_prefix_unit_measurement_quantity, - UM_Q.name_singular AS name_singular_unit_measurement_quantity, - UM_Q.name_plural AS name_plural_unit_measurement_quantity, - PP.count_unit_measurement_per_quantity_step, - PP.quantity_min, - PP.quantity_max, - PP.quantity_stock, - PP.is_subscription, - PP.id_unit_measurement_interval_recurrence, - UM_R.symbol AS symbol_unit_measurement_interval_recurrence, - UM_R.symbol_is_suffix_not_prefix AS symbol_is_suffix_not_prefix_unit_measurement_interval_recurrence, - UM_R.name_singular AS name_singular_unit_measurement_interval_recurrence, - UM_R.name_plural AS name_plural_unit_measurement_interval_recurrence, - PP.count_interval_recurrence, - PP.id_stripe_product, - PP.does_expire_faster_once_unsealed, - PP.id_unit_measurement_interval_expiration_unsealed, - UM_X.symbol AS symbol_unit_measurement_interval_expiration_unsealed, - UM_X.symbol_is_suffix_not_prefix AS symbol_is_suffix_not_prefix_unit_interval_expiration_unsealed, - UM_X.name_singular AS name_singular_unit_measurement_interval_expiration_unsealed, - UM_X.name_plural AS name_plural_unit_measurement_interval_expiration_unsealed, - PP.count_interval_expiration_unsealed, - NOT ISNULL(PPVL.id_permutation) AS has_variations, - PP.active, - -- PP.display_order, - IFNULL(t_P.can_view, 0) AS can_view, - IFNULL(t_P.can_edit, 0) AS can_edit, - IFNULL(t_P.can_admin, 0) AS can_admin - FROM tmp_Permutation t_PP - INNER JOIN partsltd_prod.Shop_Product_Permutation PP ON t_PP.id_permutation = PP.id_permutation - INNER JOIN tmp_Product t_P ON t_PP.id_product = t_P.id_product - INNER JOIN partsltd_prod.Shop_Product P ON t_PP.id_product = P.id_product - INNER JOIN partsltd_prod.Shop_Product_Category PC ON P.id_category = PC.id_category - LEFT JOIN partsltd_prod.Shop_Product_Permutation_Variation_Link PPVL ON PP.id_permutation = PPVL.id_permutation - LEFT JOIN partsltd_prod.Shop_Unit_Measurement UM_Q ON PP.id_unit_measurement_quantity = UM_Q.id_unit_measurement - LEFT JOIN partsltd_prod.Shop_Unit_Measurement UM_R ON PP.id_unit_measurement_interval_recurrence = UM_R.id_unit_measurement - LEFT JOIN partsltd_prod.Shop_Unit_Measurement UM_X ON PP.id_unit_measurement_interval_expiration_unsealed = UM_X.id_unit_measurement - INNER JOIN partsltd_prod.Shop_Currency C ON PP.id_currency_cost = C.id_currency - GROUP BY PC.id_category, P.id_product, PP.id_permutation, t_P.can_view, t_P.can_edit, t_P.can_admin - ORDER BY PC.display_order, P.display_order -- , t_PP.display_order - ; - - -- Variations - SELECT - V.id_variation - , V.id_type - , V.code AS code_variation - , V.name AS name_variation - , V.display_order AS display_order_variation - , V.active AS active_variation - , VT.code AS code_variation_type - , VT.name AS name_variation_type - , VT.name_plural AS name_plural_variation_type - , VT.display_order AS display_order_variation_type - , VT.active AS active_variation_type - , t_P.id_product - , t_PP.id_permutation - , t_C.id_category - FROM partsltd_prod.Shop_Variation V - INNER JOIN partsltd_prod.Shop_Variation_Type VT ON V.id_type = VT.id_type - INNER JOIN partsltd_prod.Shop_Product_Permutation_Variation_Link PPVL ON V.id_variation = PPVL.id_variation - INNER JOIN tmp_Permutation t_PP ON PPVL.id_permutation = t_PP.id_permutation - INNER JOIN tmp_Product t_P ON t_PP.id_product = t_P.id_product - INNER JOIN tmp_Category t_C ON t_P.id_category = t_C.id_category - WHERE - V.active - AND PPVL.active - ; - - -- Images - SELECT - t_I.id_image, - t_PP.id_product, - t_I.id_permutation, - t_C.id_category, - I.url, - I.active, - I.display_order - FROM tmp_Image t_I - INNER JOIN partsltd_prod.Shop_Product_Image I ON t_I.id_image = I.id_image - INNER JOIN tmp_Permutation t_PP ON t_I.id_permutation = t_PP.id_permutation - INNER JOIN tmp_Product t_P ON t_PP.id_product = t_P.id_product - INNER JOIN tmp_Category t_C ON t_P.id_category = t_C.id_category - ORDER BY t_C.display_order, t_P.display_order, I.display_order - ; - - -- Errors - SELECT * - /* - t_ME.display_order, - t_ME.guid, - t_ME.id_type, - t_ME.msg, - MET.code, - MET.name, - MET.description - */ - FROM tmp_Msg_Error t_ME - INNER JOIN partsltd_prod.Shop_Msg_Error_Type MET ON t_ME.id_type = MET.id_type - -- WHERE guid = v_guid - ; - - IF a_debug = 1 THEN - SELECT * FROM tmp_Category; - SELECT * FROM tmp_Product; - SELECT * FROM tmp_Permutation; - SELECT * FROM tmp_Image; - END IF; - - DROP TEMPORARY TABLE IF EXISTS tmp_Split; - DROP TEMPORARY TABLE IF EXISTS tmp_Image; - DROP TEMPORARY TABLE IF EXISTS tmp_Category; - DROP TEMPORARY TABLE IF EXISTS tmp_Permutation; - DROP TEMPORARY TABLE IF EXISTS tmp_Product; - - CALL partsltd_prod.p_shop_clear_calc_product_permutation ( v_guid ); - - IF a_debug = 1 THEN - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); - END IF; -END // -DELIMITER ; - - -/* - -CALL partsltd_prod.p_shop_get_many_product ( - 1 --'auth0|6582b95c895d09a70ba10fef', -- a_id_user - , 1 -- a_get_all_product_category - , 0 -- a_get_inactive_product_category - , '' -- a_ids_product_category - , 1 -- a_get_all_product - , 0 -- a_get_inactive_product - , '' -- a_ids_product - , 1 -- a_get_all_product_permutation - , 0 -- a_get_inactive_permutation - , '' -- a_ids_permutation - , 1 -- a_get_all_image - , 0 -- a_get_inactive_image - , '' -- a_ids_image - , 0 -- a_get_products_quantity_stock_below_minimum - , 0 -- a_debug -); - -select * FROM partsltd_prod.Shop_Calc_User_Temp; - -select * FROM partsltd_prod.Shop_Product_Category; -select * FROM partsltd_prod.Shop_Product_Permutation; -select * FROM partsltd_prod.Shop_product_change_set; -insert into shop_product_change_set ( comment ) values ('set stock quantities below minimum for testing'); -update shop_product_permutation -set quantity_stock = 0, - id_change_set = (select id_change_set FROM partsltd_prod.Shop_product_change_set order by id_change_set desc limit 1) -where id_permutation < 5 - -DROP TABLE IF EXISTS tmp_Msg_Error; - -select * FROM partsltd_prod.Shop_image; -select * FROM partsltd_prod.Shop_product; -select * from TMP_MSG_ERROR; -DROP TABLE TMP_MSG_ERROR; - -insert into shop_product_change_set (comment) - values ('set product not subscription - test bool output to python'); - update shop_product - set is_subscription = 0, - id_change_set = (select id_change_set FROM partsltd_prod.Shop_product_change_set order by id_change_set desc limit 1) - where id_product = 1 - -select * FROM partsltd_prod.Shop_Calc_User_Temp; -select distinct guid --- DELETE -FROM partsltd_prod.Shop_Calc_User_Temp; -*/ - - --- File: 7205_p_shop_get_many_stripe_product_new.sql - - - -/* - -CALL p_shop_get_many_stripe_product_new ( - '' -) - -*/ - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_get_many_stripe_product_new; - - -DELIMITER // -CREATE PROCEDURE p_shop_get_many_stripe_product_new ( - IN a_id_user INT -) -BEGIN - DECLARE v_has_filter_user BIT; - DECLARE v_code_error_data VARCHAR(200); - DECLARE v_code_error_permission VARCHAR(200); - DECLARE v_guid BINARY(36); - - SET v_code_error_data := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 1); - SET v_code_error_permission := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 2); - SET v_guid = UUID(); - - - IF a_id_user IS NULL THEN - SET a_id_user = ''; - ELSE - SET a_id_user = TRIM(a_id_user); - END IF; - - - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Shop_Product; - DROP TABLE IF EXISTS tmp_Shop_User; - - CREATE TABLE tmp_Shop_User( - id_user INT NOT NULL PRIMARY KEY, - CONSTRAINT FK_tmp_Shop_User_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user), - active BIT NOT NULL - ); - - CREATE TABLE tmp_Shop_Product ( - id_product INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - id_permutation INT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - active BIT NOT NULL, - display_order_product INT NOT NULL, - display_order_permutation INT NOT NULL, - name VARCHAR(200) NOT NULL, - description VARCHAR(4000) NOT NULL - ); - - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( -- IF NOT EXISTS - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - guid BINARY(36) NOT NULL, - code VARCHAR(50) NOT NULL, - -- CONSTRAINT chk_tmp_Msg_Error_code CHECK (code IN (SELECT code FROM Shop_Msg_Error_Type)), - /* - id_type INT NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type(id_type), - */ - msg VARCHAR(4000) NOT NULL - ); - - - - -- Parse filters - SET v_has_filter_user = CASE WHEN a_id_user = '' THEN 0 ELSE 1 END; - - - - -- User - IF v_has_filter_user THEN - INSERT INTO tmp_Shop_User ( - id_user, - active - ) - SELECT id_user, - active - FROM Shop_User - WHERE id_user LIKE CONCAT('%', a_id_user, '%') - AND active - LIMIT 1 - ; - - SET v_has_filter_user = EXISTS (SELECT id_user FROM tmp_Shop_User LIMIT 1); - SET a_id_user := (SELECT id_user FROM tmp_Shop_User LIMIT 1); - END IF; - - IF NOT v_has_filter_user THEN - INSERT INTO tmp_Msg_Error ( - guid, - code, - msg - ) - VALUES ( - v_guid, - v_code_error_data, - 'User ID not valid.' - ) - ; - END IF; - - -- Get products - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - INSERT INTO tmp_Shop_Product ( - id_product, - id_permutation, - active, - display_order_product, - display_order_permutation, - name, - description - ) - SELECT id_product, - id_permutation, - active, - display_order_product, - display_order_permutation, - name, - description - FROM ( - SELECT id_product, - NULL AS id_permutation, - active, - display_order AS display_order_product, - NULL AS display_order_permutation, - name, - description, - id_stripe_product - FROM Shop_Product P - UNION - SELECT t_PPPV.id_product, - id_permutation, - t_PPPV.active, - display_order_product, - display_order_permutation, - CONCAT(P.name, ': ', names_variation) AS name, - CONCAT(P.description, ' With variations: ', type_name_pairs_variation) AS description, - t_PPPV.id_stripe_product - FROM ( - SELECT P.id_product, - PP.id_permutation, - PP.active, - P.display_order AS display_order_product, - PP.display_order AS display_order_permutation, - GROUP_CONCAT(V.name SEPARATOR ' ') AS names_variation, - GROUP_CONCAT(CONCAT(VT.name, ': ', V.name) SEPARATOR ', ') AS type_name_pairs_variation, - PP.id_stripe_product - FROM Shop_Product_Permutation PP - INNER JOIN Shop_Product P - ON PP.id_product = P.id_product - AND P.active - INNER JOIN Shop_Product_Permutation_Variation_Link PPVL - ON PP.id_permutation = PPVL.id_permutation - AND PPVL.active - INNER JOIN Shop_Variation V - ON PPVL.id_variation = V.id_variation - AND V.active - INNER JOIN Shop_Variation_Type VT - ON V.id_type = VT.id_type - AND VT.active - GROUP BY id_product, id_permutation -- , VT.id_type, V.id_variation - ) t_PPPV - INNER JOIN Shop_Product P - ON t_PPPV.id_product = P.id_product - ) t_PPP - WHERE ISNULL(id_stripe_product) - AND active - ; - END IF; - - -- Permissions - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - CALL p_shop_calc_user ( - v_guid, -- a_guid - a_id_user, -- a_id_user - 0, -- a_get_inactive_users - CONVERT((SELECT id_permission FROM Shop_Permission WHERE 'STORE_ADMIN' = code), CHAR), -- a_ids_permission - (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'ADMIN' AND active), -- a_ids_access_level - (SELECT GROUP_CONCAT(id_product SEPARATOR ',') From tmp_Shop_Product), -- a_ids_product - (SELECT GROUP_CONCAT(id_permutation SEPARATOR ',') From tmp_Shop_Product) -- a_ids_permutation -- WHERE NOT ISNULL(id_permutation) - ); - - IF EXISTS (SELECT can_admin FROM Shop_Calc_User_Temp WHERE guid = v_guid AND NOT can_admin) THEN - INSERT INTO tmp_Msg_Error ( - guid, - code, - msg - ) - VALUES ( - v_guid, - v_code_error_permission, - 'User ID does not have permission to get all new stripe products.' - ) - ; - END IF; - - DELETE FROM Shop_Calc_User_Temp - WHERE guid = v_guid - ; - END IF; - - - - - -- Returns - /* - SELECT * - FROM tmp_Shop_User - ; - */ - - IF EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - DELETE FROM tmp_Shop_Product; - END IF; - - SELECT id_product, - id_permutation, - name, - description - FROM tmp_Shop_Product - ORDER BY display_order_product, display_order_permutation - ; - SELECT PP.id_permutation, - V.id_variation, - V.name AS name_variation, - VT.id_type AS id_type_variation, - VT.name as name_variation_type - FROM tmp_Shop_Product t_P - INNER JOIN Shop_Product_Permutation PP - ON t_P.id_permutation = PP.id_permutation - INNER JOIN Shop_Product_Permutation_Variation_Link PPVL - ON PP.id_permutation = PPVL.id_permutation - AND PPVL.active - INNER JOIN Shop_Variation V - ON PPVL.id_variation = V.id_variation - AND V.active - INNER JOIN Shop_Variation_Type VT - ON V.id_type = VT.id_type - AND VT.active - ; - - - -- Errors - SELECT * - FROM tmp_Msg_Error - WHERE guid = v_guid - ; - - - /* - -- Return arguments for test - SELECT - a_id_user - ; - */ - - -- Clean up - DROP TABLE IF EXISTS tmp_Shop_Product; - DROP TABLE IF EXISTS tmp_Shop_User; -END // -DELIMITER ; - - -/* -CALL p_shop_get_many_stripe_product_new ( - '' -); - -CALL p_shop_get_many_stripe_product_new ( - 'auth0|6582b95c895d09a70ba10fef' -); - - - -select * from shop_product; -select * from shop_product_permutation_variation_link; - -CALL p_shop_calc_user ( - 'ead789a1-c7ac-11ee-a256-b42e9986184a', -- a_guid - 'auth0|6582b95c895d09a70ba10fef', -- a_id_user - 0, -- a_get_inactive_users - '4', -- a_ids_permission - '3', -- a_ids_access_level - '1', -- a_ids_product - '1' -- a_ids_permutation -- WHERE NOT ISNULL(id_permutation) - ); - -*/ - - --- File: 7206_p_shop_save_product_permutation.sql - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_save_permutation; -DROP PROCEDURE IF EXISTS p_shop_save_product_permutation; - -DELIMITER // -CREATE PROCEDURE p_shop_save_product_permutation ( - IN a_comment VARCHAR(500), - IN a_guid BINARY(36), - IN a_id_user INT, - IN a_debug BIT -) -BEGIN - - DECLARE v_code_type_error_bad_data VARCHAR(100); - DECLARE v_id_type_error_bad_data INT; - DECLARE v_id_permission_product INT; - DECLARE v_ids_product_permission LONGTEXT; - DECLARE v_id_change_set INT; - DECLARE v_id_access_level_edit INT; - DECLARE v_time_start TIMESTAMP(6); - - DECLARE exit handler for SQLEXCEPTION - BEGIN - -- Get diagnostic information - GET DIAGNOSTICS CONDITION 1 - @sqlstate = RETURNED_SQLSTATE - , @errno = MYSQL_ERRNO - , @text = MESSAGE_TEXT - ; - - -- Rollback the transaction - ROLLBACK; - - -- Select the error information - -- SELECT 'Error' AS status, @errno AS error_code, @sqlstate AS sql_state, @text AS message; - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT - , id_type INT NULL - , code VARCHAR(50) NOT NULL - , msg VARCHAR(4000) NOT NULL - ); - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - MET.id_type - , @errno - , @text - FROM partsltd_prod.Shop_Msg_Error_Type MET - WHERE MET.code = 'MYSQL_ERROR' - LIMIT 1 - ; - SELECT * - FROM tmp_Msg_Error; - DROP TABLE IF EXISTS tmp_Msg_Error; - END; - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_code_type_error_bad_data := 'BAD_DATA'; - SET v_id_type_error_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_type_error_bad_data LIMIT 1); - SET v_id_access_level_edit := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'EDIT' LIMIT 1); - - CALL p_validate_guid ( a_guid ); - - DROP TEMPORARY TABLE IF EXISTS tmp_Permutation_Variation_Link; - DROP TEMPORARY TABLE IF EXISTS tmp_Permutation; - - CREATE TEMPORARY TABLE tmp_Permutation ( - id_permutation INT NOT NULL - , id_permutation_temp INT NOT NULL - , id_product INT NOT NULL - , csv_id_pairs_variation VARCHAR(4000) NULL - , description VARCHAR(4000) NOT NULL - , cost_local_VAT_excl FLOAT NULL - , cost_local_VAT_incl FLOAT NULL - , id_currency_cost INT NOT NULL - , profit_local_min FLOAT NULL - , latency_manufacture INT NOT NULL - , id_unit_measurement_quantity INT NOT NULL - , count_unit_measurement_per_quantity_step FLOAT NOT NULL - , quantity_min FLOAT NULL - , quantity_max FLOAT NULL - , quantity_stock FLOAT NOT NULL - , is_subscription BIT NOT NULL - , id_unit_measurement_interval_recurrence INT - , count_interval_recurrence INT - , id_stripe_product VARCHAR(100) NULL - , does_expire_faster_once_unsealed BIT NOT NULL - , id_unit_measurement_interval_expiration_unsealed INT - , count_interval_expiration_unsealed INT - , active BIT NOT NULL DEFAULT 1 - , can_view BIT NULL - , can_edit BIT NULL - , can_admin BIT NULL - , name_error VARCHAR(255) NOT NULL - , is_new BIT NOT NULL - ); - - CREATE TEMPORARY TABLE tmp_Permutation_Variation_Link ( - id_link INT NOT NULL - , id_permutation INT NOT NULL - , id_variation INT NOT NULL - , active BIT NOT NULL - , display_order INT NOT NULL - , is_new BIT NOT NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT - , id_type INT NULL - , code VARCHAR(50) NOT NULL - , msg VARCHAR(4000) NOT NULL - ); - - - -- Get data from Temp table - INSERT INTO tmp_Permutation ( - id_permutation - , id_permutation_temp - , id_product - , csv_id_pairs_variation - , description - , cost_local_VAT_excl - , cost_local_VAT_incl - , id_currency_cost - , profit_local_min - , latency_manufacture - , id_unit_measurement_quantity - , count_unit_measurement_per_quantity_step - , quantity_min - , quantity_max - , quantity_stock - , is_subscription - , id_unit_measurement_interval_recurrence - , count_interval_recurrence - , id_stripe_product - , does_expire_faster_once_unsealed - , id_unit_measurement_interval_expiration_unsealed - , count_interval_expiration_unsealed - , active - , name_error - , is_new - ) - SELECT - PP_T.id_permutation - , PP_T.id_permutation - , IFNULL(PP_T.id_product, PP.id_product) AS id_product - , PP_T.csv_id_pairs_variation - , IFNULL(PP_T.description, PP.description) AS description - , IFNULL(PP_T.cost_local_VAT_excl, PP.cost_local_VAT_excl) AS cost_local_VAT_excl - , IFNULL(PP_T.cost_local_VAT_incl, PP.cost_local_VAT_incl) AS cost_local_VAT_incl - , IFNULL(PP_T.id_currency_cost, PP.id_currency_cost) AS a_id_currency_cost - , IFNULL(PP_T.profit_local_min, PP.profit_local_min) AS profit_local_min - , IFNULL(PP_T.latency_manufacture, PP.latency_manufacture) AS latency_manufacture - , IFNULL(PP_T.id_unit_measurement_quantity, PP.id_unit_measurement_quantity) AS id_unit_measurement_quantity - , IFNULL(PP_T.count_unit_measurement_per_quantity_step, PP.count_unit_measurement_per_quantity_step) AS count_unit_measurement_per_quantity_step - , IFNULL(PP_T.quantity_min, PP.quantity_min) AS quantity_min - , IFNULL(PP_T.quantity_max, PP.quantity_max) AS quantity_max - , IFNULL(PP_T.quantity_stock, PP.quantity_stock) AS quantity_stock - , IFNULL(PP_T.is_subscription, PP.is_subscription) AS is_subscription - , IFNULL(PP_T.id_unit_measurement_interval_recurrence, PP.id_unit_measurement_interval_recurrence) AS id_unit_measurement_interval_recurrence - , IFNULL(PP_T.count_interval_recurrence, PP.count_interval_recurrence) AS count_interval_recurrence - , IFNULL(PP_T.id_stripe_product, PP.id_stripe_product) AS id_stripe_product - , IFNULL(PP_T.does_expire_faster_once_unsealed, PP.does_expire_faster_once_unsealed) AS does_expire_faster_once_unsealed - , IFNULL(PP_T.id_unit_measurement_interval_expiration_unsealed, PP.id_unit_measurement_interval_expiration_unsealed) AS id_unit_measurement_interval_expiration_unsealed - , IFNULL(PP_T.count_interval_expiration_unsealed, PP.count_interval_expiration_unsealed) AS count_interval_expiration_unsealed - , IFNULL(PP_T.active, PP.active) AS active - , IFNULL(fn_shop_get_product_permutation_name(PP_T.id_permutation), '(No Permutation)') AS name_error - , CASE WHEN IFNULL(PP_T.id_permutation, 0) < 1 THEN 1 ELSE 0 END AS is_new - FROM Shop_Product_Permutation_Temp PP_T - LEFT JOIN Shop_Product_Permutation PP ON PP_T.id_permutation = PP.id_permutation - WHERE PP_T.guid = a_guid - ; - - SELECT - partsltd_prod.fn_shop_get_product_variations_from_id_csv_list( - t_PP.id_permutation -- a_id_permutation - , t_PP.csv_id_pairs_variation -- a_variation_csv - , a_guid -- a_guid - ) - FROM tmp_Permutation t_PP - WHERE NOT ISNULL(t_PP.csv_id_pairs_variation) - ; - - INSERT INTO tmp_Permutation_Variation_Link ( - id_link - , id_permutation - , id_variation - , display_order - , active - , is_new - ) - SELECT - PPVL_T.id_link - , PPVL_T.id_permutation - , PPVL_T.id_variation - , PPVL_T.display_order - , NOT ISNULL(PPVL_T.id_link) AS active - , IFNULL(PPVL_T.id_link, 0) < 1 AS is_new - FROM partsltd_prod.Shop_Product_Permutation_Variation_Link_Temp PPVL_T - LEFT JOIN partsltd_prod.Shop_Product_Permutation_Variation_Link PPVL ON PPVL_T.id_link = PPVL.id_variation - LEFT JOIN tmp_Permutation t_PP ON PPVL_T.id_permutation = t_PP.id_permutation - WHERE PPVL_T.GUID = a_guid - ; - - IF a_debug = 1 THEN - SELECT * - FROM tmp_Permutation - ; - SELECT * - FROM tmp_Permutation_Variation_Link - ; - END IF; - - -- Validation - -- Missing mandatory fields - -- id_product - IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.id_product) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following product permutation(s) do not have a product: ', GROUP_CONCAT(t_P.name_error SEPARATOR ', ')) AS msg - FROM tmp_Permutation t_P - WHERE ISNULL(t_P.id_product) - ; - END IF; - -- cost_local_VAT_excl - IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE NOT ISNULL(t_P.cost_local_VAT_excl) AND t_P.cost_local_VAT_excl < 0 LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following product permutation(s) do not have a valid local cost excluding VAT: ', GROUP_CONCAT(t_P.name_error SEPARATOR ', ')) AS msg - FROM tmp_Permutation t_P - WHERE NOT ISNULL(t_P.cost_local_VAT_excl) AND t_P.cost_local_VAT_excl < 0 - ; - END IF; - -- cost_local_VAT_incl - IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE NOT ISNULL(t_P.cost_local_VAT_incl) AND t_P.cost_local_VAT_incl < 0 LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following product permutation(s) do not have a valid local cost including VAT: ', GROUP_CONCAT(t_P.name_error SEPARATOR ', ')) AS msg - FROM tmp_Permutation t_P - WHERE NOT ISNULL(t_P.cost_local_VAT_incl) AND t_P.cost_local_VAT_incl < 0 - ; - END IF; - -- profit_local_min - IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE NOT ISNULL(t_P.profit_local_min) AND t_P.profit_local_min < 0 LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following product permutation(s) do not have a local minimum profit: ', GROUP_CONCAT(t_P.name_error SEPARATOR ', ')) AS msg - FROM tmp_Permutation t_P - WHERE NOT ISNULL(t_P.profit_local_min) AND t_P.profit_local_min < 0 - ; - END IF; - - -- latency_manufacture - IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.latency_manufacture) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following product permutation(s) do not have a manufacturing latency: ', GROUP_CONCAT(t_P.name_error SEPARATOR ', ')) AS msg - FROM tmp_Permutation t_P - WHERE ISNULL(t_P.latency_manufacture) - ; - END IF; - -- id_unit_measurement_quantity - IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.id_unit_measurement_quantity) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following product permutation(s) do not have a unit measurement for stock quantities: ', GROUP_CONCAT(t_P.name_error SEPARATOR ', ')) AS msg - FROM tmp_Permutation t_P - WHERE ISNULL(t_P.id_unit_measurement_quantity) - ; - END IF; - -- count_unit_measurement_per_quantity_step - IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.count_unit_measurement_per_quantity_step) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following product permutation(s) do not have a count unit measurement per quantity step: ', GROUP_CONCAT(t_P.name_error SEPARATOR ', ')) AS msg - FROM tmp_Permutation t_P - WHERE ISNULL(t_P.count_unit_measurement_per_quantity_step) - ; - END IF; - -- quantity_min - IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.quantity_min) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following product permutation(s) do not have a minimum quantity: ', GROUP_CONCAT(t_P.name_error SEPARATOR ', ')) AS msg - FROM tmp_Permutation t_P - WHERE ISNULL(t_P.quantity_min) - ; - END IF; - -- quantity_max - IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.quantity_max) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following product permutation(s) do not have a maximum quantity: ', GROUP_CONCAT(t_P.name_error SEPARATOR ', ')) AS msg - FROM tmp_Permutation t_P - WHERE ISNULL(t_P.quantity_max) - ; - END IF; - -- is_subscription - IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.is_subscription) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following product permutation(s) do not have an is subscription?: ', GROUP_CONCAT(t_P.name_error SEPARATOR ', ')) AS msg - FROM tmp_Permutation t_P - WHERE ISNULL(t_P.is_subscription) - ; - END IF; - -- does_expire_faster_once_unsealed - IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.does_expire_faster_once_unsealed) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following product permutation(s) do not have a does expire faster once unsealed: ', GROUP_CONCAT(t_P.name_error SEPARATOR ', ')) AS msg - FROM tmp_Permutation t_P - WHERE ISNULL(t_P.does_expire_faster_once_unsealed) - ; - END IF; - - -- Permissions - SET v_ids_product_permission := ( - SELECT GROUP_CONCAT(P.id_product SEPARATOR ',') - FROM Shop_Product P - INNER JOIN tmp_Permutation t_P - ON P.id_product = t_P.id_product - -- AND t_P.is_new = 0 - ); - - SET v_id_permission_product = (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_PRODUCT' LIMIT 1); - - IF a_debug = 1 THEN - SELECT - a_guid - , a_id_user - , FALSE AS a_get_inactive_user - , v_id_permission_product - , v_id_access_level_edit - , v_ids_product_permission - , 0 AS a_debug - ; - END IF; - - CALL p_shop_calc_user( - a_guid - , a_id_user - , FALSE -- a_get_inactive_user - , v_id_permission_product - , v_id_access_level_edit - , v_ids_product_permission - , 0 -- a_debug - ); - - UPDATE tmp_Permutation t_P - INNER JOIN Shop_Product P ON t_P.id_product = P.id_product - INNER JOIN Shop_Calc_User_Temp UE_T - ON P.id_product = UE_T.id_product - AND UE_T.GUID = a_guid - SET - t_P.can_view = UE_T.can_view - , t_P.can_edit = UE_T.can_edit - , t_P.can_admin = UE_T.can_admin - ; - - IF a_debug = 1 THEN - SELECT * - FROM partsltd_prod.Shop_Calc_User_Temp - WHERE GUID = a_guid - ; - SELECT * - FROM tmp_Permutation t_PP - LEFT JOIN Shop_Product P ON t_PP.id_product = P.id_product - ; - END IF; - - IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.can_edit) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following product permutation(s) do not have product edit permission: ', GROUP_CONCAT(t_P.name_error SEPARATOR ', ')) AS msg - FROM tmp_Permutation t_P - WHERE - ISNULL(t_P.can_edit) - ; - END IF; - - IF EXISTS (SELECT * FROM partsltd_prod.Shop_Calc_User_Temp WHERE ISNULL(id_product) AND GUID = a_guid AND can_edit = 0) THEN - DELETE FROM tmp_Msg_Error - WHERE id_type <> v_id_type_error_no_permission - ; - - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - VALUES ( - v_id_type_error_bad_data - , v_code_type_error_bad_data - , 'You do not have permission to edit Product Permutations' - ) - ; - END IF; - - CALL p_shop_clear_calc_user( - a_guid - , 0 -- a_debug - ); - - IF a_debug = 1 THEN - SELECT * - FROM partsltd_prod.Shop_Product_Permutation_Variation_Link_Temp - WHERE GUID = a_guid - ; - END IF; - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - START TRANSACTION; - - INSERT INTO Shop_Product_Change_Set ( comment ) - VALUES ( a_comment ) - ; - - SET v_id_change_set := LAST_INSERT_ID(); - - INSERT INTO Shop_Product_Permutation ( - id_permutation_temp - , id_product - , description - , cost_local_VAT_excl - , cost_local_VAT_incl - , id_currency_cost - , profit_local_min - , latency_manufacture - , id_unit_measurement_quantity - , count_unit_measurement_per_quantity_step - , quantity_min - , quantity_max - , quantity_stock - , is_subscription - , id_unit_measurement_interval_recurrence - , count_interval_recurrence - , id_stripe_product - , does_expire_faster_once_unsealed - , id_unit_measurement_interval_expiration_unsealed - , count_interval_expiration_unsealed - , active - , created_by - , created_on - , id_change_set - ) - SELECT - t_P.id_permutation - , t_P.id_product AS id_product - , t_P.description AS description - , t_P.cost_local_VAT_excl AS cost_local_VAT_excl - , t_P.cost_local_VAT_incl AS cost_local_VAT_incl - , t_P.id_currency_cost AS id_currency_cost - , t_P.profit_local_min AS profit_local_min - , t_P.latency_manufacture AS latency_manufacture - , t_P.id_unit_measurement_quantity AS id_unit_measurement_quantity - , t_P.count_unit_measurement_per_quantity_step AS count_unit_measurement_per_quantity_step - , t_P.quantity_min AS quantity_min - , t_P.quantity_max AS quantity_max - , t_P.quantity_stock AS quantity_stock - , t_P.is_subscription AS is_subscription - , t_P.id_unit_measurement_interval_recurrence AS id_unit_measurement_interval_recurrence - , t_P.count_interval_recurrence AS count_interval_recurrence - , t_P.id_stripe_product AS id_stripe_product - , t_P.does_expire_faster_once_unsealed AS does_expire_faster_once_unsealed - , t_P.id_unit_measurement_interval_expiration_unsealed AS id_unit_measurement_interval_expiration_unsealed - , t_P.count_interval_expiration_unsealed AS count_interval_expiration_unsealed - , t_P.active AS active - , a_id_user AS created_by - , v_time_start AS created_on - , v_id_change_set AS id_change_set - FROM tmp_Permutation t_P - WHERE - is_new = 1 - AND active = 1 - ; - - UPDATE Shop_Product_Permutation PP - INNER JOIN tmp_Permutation t_P - ON PP.id_permutation = t_P.id_permutation - AND t_P.is_new = 0 - SET - PP.id_product = t_P.id_product - , PP.description = t_P.description - , PP.cost_local_VAT_excl = t_P.cost_local_VAT_excl - , PP.cost_local_VAT_incl = t_P.cost_local_VAT_incl - , PP.id_currency_cost = t_P.id_currency_cost - , PP.profit_local_min = t_P.profit_local_min - , PP.latency_manufacture = t_P.latency_manufacture - , PP.id_unit_measurement_quantity = t_P.id_unit_measurement_quantity - , PP.count_unit_measurement_per_quantity_step = t_P.count_unit_measurement_per_quantity_step - , PP.quantity_min = t_P.quantity_min - , PP.quantity_max = t_P.quantity_max - , PP.quantity_stock = t_P.quantity_stock - , PP.is_subscription = t_P.is_subscription - , PP.id_unit_measurement_interval_recurrence = t_P.id_unit_measurement_interval_recurrence - , PP.count_interval_recurrence = t_P.count_interval_recurrence - , PP.id_stripe_product = t_P.id_stripe_product - , PP.does_expire_faster_once_unsealed = t_P.does_expire_faster_once_unsealed - , PP.id_unit_measurement_interval_expiration_unsealed = t_P.id_unit_measurement_interval_expiration_unsealed - , PP.count_interval_expiration_unsealed = t_P.count_interval_expiration_unsealed - , PP.active = t_P.active - , PP.id_change_set = v_id_change_set - ; - - UPDATE tmp_Permutation t_PP - INNER JOIN partsltd_prod.Shop_Product_Permutation PP - ON t_PP.id_permutation_temp = PP.id_permutation_temp - AND PP.id_change_set = v_id_change_set - SET - t_PP.id_permutation = PP.id_permutation - ; - UPDATE tmp_Permutation_Variation_Link t_PPVL - INNER JOIN tmp_Permutation t_PP ON t_PPVL.id_permutation = t_PP.id_permutation_temp - SET - t_PPVL.id_permutation = t_PP.id_permutation - ; - - INSERT INTO partsltd_prod.Shop_Product_Permutation_Variation_Link ( - id_permutation - , id_variation - , display_order - , active - ) - SELECT - t_PPVL.id_permutation - , t_PPVL.id_variation - , t_PPVL.display_order - , t_PPVL.active - FROM tmp_Permutation_Variation_Link t_PPVL - WHERE - t_PPVL.is_new = 1 - AND t_PPVL.active = 1 - ; - - UPDATE partsltd_prod.Shop_Product_Permutation_Variation_Link PPVL - INNER JOIN tmp_Permutation_Variation_Link t_PPVL - ON PPVL.id_link = t_PPVL.id_link - AND t_PPVL.is_new = 1 - SET - PPVL.id_permutation = t_PPVL.id_permutation - , PPVL.id_variation = t_PPVL.id_variation - , PPVL.display_order = t_PPVL.display_order - , PPVL.active = t_PPVL.active - , PPVL.id_change_set = v_id_change_set - ; - - COMMIT; - END IF; - - START TRANSACTION; - - DELETE FROM Shop_Product_Permutation_Temp - WHERE GUID = a_guid - ; - - DELETE FROM partsltd_prod.Shop_Product_Permutation_Variation_Link_Temp - WHERE GUID = a_guid - ; - - COMMIT; - - -- Errors - SELECT * - FROM tmp_Msg_Error t_ME - INNER JOIN partsltd_prod.Shop_Msg_Error_Type MET ON t_ME.id_type = MET.id_type - ; - - IF a_debug = 1 THEN - SELECT * FROM tmp_Permutation; - SELECT * FROM tmp_Permutation_Variation_Link; - END IF; - - DROP TEMPORARY TABLE tmp_Permutation_Variation_Link; - DROP TEMPORARY TABLE tmp_Permutation; - DROP TEMPORARY TABLE tmp_Msg_Error; - - IF a_debug = 1 THEN - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); - END IF; -END // -DELIMITER ; - - -/* - -DELETE FROM Shop_Product_Permutation_Temp -WHERE id_permutation = 1 -; - -INSERT INTO Shop_Product_Permutation_Temp ( - id_permutation, - id_product, - description, - cost_local, - id_currency_cost, - profit_local_min, - latency_manufacture, - id_unit_measurement_quantity, - count_unit_measurement_per_quantity_step, - quantity_min, - quantity_max, - quantity_stock, - is_subscription, - id_unit_measurement_interval_recurrence, - count_interval_recurrence, - id_stripe_product, - does_expire_faster_once_unsealed, - id_unit_measurement_interval_expiration_unsealed, - count_interval_expiration_unsealed, - active, - guid -) -VALUES - ( - 1 -- id_permutation, - , 1 -- id_product, - , 'Good Reddy Teddy' -- description, - , 5.0 -- cost_local, - , 1 -- id_currency_cost, - , 3.0 -- profit_local_min, - , 14 -- latency_manufacture, - , 1 -- id_unit_measurement_quantity, - , 1.0 -- count_unit_measurement_quantity, - , 3.0 -- quantity_min, - , 99.0 -- quantity_max, - , 1.0 -- quantity_stock, - , False -- is_subscription, - , null -- id_unit_measurement_interval_recurrence, - , null -- count_interval_recurrence, - , null -- id_stripe_product, - , False -- does_expire_faster_once_unsealed, - , null -- id_unit_measurement_interval_expiration_unsealed, - , null -- count_interval_expiration_unsealed, - , True -- active, - , 'NIPS' -- guid - ) -; - -select 'Shop_Product_Permutation_Temp before call'; -SELECT * FROM Shop_Product_Permutation_Temp; - -SELECT 'Shop_Product_Permutation before call' AS result_name; -select * FROM Shop_Product_Permutation; - -CALL p_shop_save_product_permutation ( - 1, -- 'auth0|6582b95c895d09a70ba10fef', -- a_id_user - 'Initial data', -- a_comment - 'NIPS' -- a_guid -); - -SELECT 'Shop_Product_Permutation_Temp after call' AS result_name; -select * FROM Shop_Product_Permutation_Temp; - -SELECT 'Shop_Product_Permutation after call' AS result_name; -select * FROM Shop_Product_Permutation; - - -DELETE FROM Shop_Product_Permutation_Temp -WHERE id_permutation = 1; - - -select * from shop_unit_measurement; - -*/ - - - --- File: 7206_p_shop_save_product_permutation_test.sql - - --- Clear previous proc -DROP PROCEDURE IF EXISTS partsltd_prod.p_shop_save_product_permutation_test; - - -DELIMITER // -CREATE PROCEDURE p_shop_save_product_permutation_test () -BEGIN - - DECLARE v_guid BINARY(36); - DECLARE v_time_start TIMESTAMP(6); - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_guid := 'nips'; - - SELECT * - FROM partsltd_prod.Shop_Product_Permutation - ; - SELECT * - FROM partsltd_prod.Shop_Product_Permutation_Variation_Link - ; - SELECT * - FROM partsltd_prod.Shop_Product_Permutation_Temp - ; - - START TRANSACTION; - - INSERT INTO partsltd_prod.Shop_Product_Permutation_Temp ( - id_permutation - , id_product - , csv_id_pairs_variation - , description - , cost_local_VAT_excl - , cost_local_VAT_incl - , id_currency_cost - , profit_local_min - , latency_manufacture - , id_unit_measurement_quantity - , count_unit_measurement_per_quantity_step - , quantity_min - , quantity_max - , quantity_stock - , is_subscription - , id_unit_measurement_interval_recurrence - , count_interval_recurrence - , id_stripe_product - , does_expire_faster_once_unsealed - , id_unit_measurement_interval_expiration_unsealed - , count_interval_expiration_unsealed - , active - , guid - ) - VALUES - /* Test 1 - Insert - ( - -1 -- id_permutation - , 5 -- id_product - , '' -- csv_id_pairs_variation - , 'Hair clip' -- description - , NULL -- cost_local_VAT_excl - , NULL -- cost_local_VAT_incl - , 1 -- id_currency_cost - , NULL -- profit_local_min - , 1 -- latency_manufacture - , 3 -- id_unit_measurement_quantity - , 1 -- count_unit_measurement_per_quantity_step - , 0 -- quantity_min - , 0 -- quantity_max - , 2 -- quantity_stock - , FALSE -- is_subscription - , NULL -- id_unit_measurement_interval_recurrence - , NULL -- count_interval_recurrence - , NULL -- id_stripe_product - , FALSE -- does_expire_faster_once_unsealed - , NULL -- id_unit_measurement_interval_expiration_unsealed - , NULL -- count_interval_expiration_unsealed - , 1 -- active - , v_guid - ) - */ - /* Test 2 - Update - ( - 4 -- id_product - , 1 -- id_category - , 'Laptops' -- name - , 0 -- has_variations - , 2 -- id_access_level_required - , 2 -- display_order - , 1 -- active - , v_guid - ) - */ - /* Test 3 - Insert with Variations */ - ( - -1 -- id_permutation - , 1 -- id_product - , '1:3' -- csv_id_pairs_variation - , 'Good Green' -- description - , NULL -- cost_local_VAT_excl - , NULL -- cost_local_VAT_incl - , 1 -- id_currency_cost - , NULL -- profit_local_min - , 1 -- latency_manufacture - , 3 -- id_unit_measurement_quantity - , 1 -- count_unit_measurement_per_quantity_step - , 0 -- quantity_min - , 0 -- quantity_max - , 2 -- quantity_stock - , FALSE -- is_subscription - , NULL -- id_unit_measurement_interval_recurrence - , NULL -- count_interval_recurrence - , NULL -- id_stripe_product - , TRUE -- does_expire_faster_once_unsealed - , 8 -- id_unit_measurement_interval_expiration_unsealed - , 2 -- count_interval_expiration_unsealed - , 1 -- active - , v_guid - ) - ; - - COMMIT; - - SELECT * - FROM partsltd_prod.Shop_Product_Permutation_Temp - WHERE GUID = v_guid - ; - - CALL partsltd_prod.p_shop_save_product_permutation ( - 'Test save product' -- comment - , v_guid -- guid - , 1 -- id_user - , 1 -- debug - ); - - SELECT * - FROM partsltd_prod.Shop_Product_Permutation - ; - SELECT * - FROM partsltd_prod.Shop_Product_Permutation_Variation_Link - ; - SELECT * - FROM partsltd_prod.Shop_Product_Permutation_Temp - ; - - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); -END // -DELIMITER ; - -CALL partsltd_prod.p_shop_save_product_permutation_test (); - -DELETE FROM partsltd_prod.Shop_Product_Permutation_Temp; - -DROP TABLE IF EXISTS tmp_Msg_Error; - - -/* -DELETE FROM partsltd_prod.Shop_Product_Permutation_Variation_Link -WHERE id_link >= 3 -; -DELETE FROM partsltd_prod.Shop_Product_Permutation -WHERE id_permutation >= 7 -; - - SELECT * - FROM partsltd_prod.Shop_Product_Permutation_Variation_Link_Temp - ; - SELECT * - FROM partsltd_prod.Shop_Variation - ; -*/ - --- File: 7210_p_shop_get_many_product_variation.sql - -DROP PROCEDURE IF EXISTS p_shop_get_many_product_variation; - -DELIMITER // -CREATE PROCEDURE p_shop_get_many_product_variation ( - IN a_id_user INT - , IN a_get_all_variation_type BIT - , IN a_get_inactive_variation_type BIT - , IN a_ids_variation_type VARCHAR(4000) - , IN a_get_all_variation BIT - , IN a_get_inactive_variation BIT - , IN a_ids_variation TEXT - , IN a_debug BIT -) -BEGIN - -- Argument redeclaration - -- Variable declaration - DECLARE v_has_filter_variation BIT; - DECLARE v_has_filter_variation_type BIT; - DECLARE v_guid BINARY(36); - -- DECLARE v_id_user VARCHAR(100); - -- DECLARE v_ids_permutation_unavailable VARCHAR(4000); - DECLARE v_id_permission_variation INT; - -- DECLARE v_ids_product_permission VARCHAR(4000); - -- DECLARE v_ids_permutation_permission VARCHAR(4000); - DECLARE v_id_access_level_view INT; - DECLARE v_time_start TIMESTAMP(6); - DECLARE v_id_minimum INT; - DECLARE v_code_error_bad_data VARCHAR(50); - DECLARE v_id_type_error_bad_data INT; - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_guid := UUID(); - SET v_id_access_level_view := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW' LIMIT 1); - SET v_code_error_bad_data := (SELECT code FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1); - SET v_id_type_error_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_bad_data LIMIT 1); - - -- Argument validation + default values - SET a_id_user = IFNULL(a_id_user, 0); - SET a_get_all_variation = IFNULL(a_get_all_variation, 1); - SET a_get_inactive_variation = IFNULL(a_get_inactive_variation, 0); - SET a_ids_variation = TRIM(REPLACE(IFNULL(a_ids_variation, ''), '|', ',')); - SET a_get_all_variation_type = IFNULL(a_get_all_variation_type, 1); - SET a_get_inactive_variation_type = IFNULL(a_get_inactive_variation_type, 0); - SET a_ids_variation_type = TRIM(REPLACE(IFNULL(a_ids_variation_type, ''), '|', ',')); - - IF a_debug = 1 THEN - SELECT - a_id_user - , a_get_all_variation_type - , a_get_inactive_variation_type - , a_ids_variation_type - , a_get_all_variation - , a_get_inactive_variation - , a_ids_variation - , a_debug - ; - END IF; - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Variation; - DROP TABLE IF EXISTS tmp_Variation_Type; - - CREATE TEMPORARY TABLE tmp_Variation_Type ( - id_type INT NOT NULL - ); - - CREATE TEMPORARY TABLE tmp_Variation ( - id_variation INT NOT NULL - , id_type INT NOT NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - -- guid BINARY(36) NOT NULL, - id_type INT NULL, - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Split ( - substring VARCHAR(4000) NOT NULL - , as_int INT NULL - ); - DELETE FROM tmp_Split; - - - -- Parse filters - SET v_has_filter_variation = CASE WHEN a_ids_variation = '' THEN 0 ELSE 1 END; - SET v_has_filter_variation_type = CASE WHEN a_ids_variation_type = '' THEN 0 ELSE 1 END; - - -- select v_has_filter_product, v_has_filter_permutation; - - IF v_has_filter_variation_type THEN -- NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - CALL partsltd_prod.p_split(v_guid, a_ids_variation_type, ',', a_debug); - - DELETE FROM tmp_Split; - - INSERT INTO tmp_Split ( - substring - , as_int - ) - SELECT - substring - , CONVERT(substring, DECIMAL(10,0)) AS as_int - FROM partsltd_prod.Split_Temp - WHERE 1=1 - AND GUID = v_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( v_guid ); - END IF; - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Variation_Type VT ON t_S.as_int = VT.id_type - WHERE - ISNULL(t_S.as_int) - OR ISNULL(VT.id_type) - ) THEN - INSERT INTO tmp_Msg_Error ( - -- guid, - id_type, - code, - msg - ) - SELECT - -- v_guid, - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Invalid or inactive variation type IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Variation_Type VT ON t_S.as_int = VT.id_type - WHERE - ISNULL(t_S.as_int) - OR ISNULL(VT.id_type) - ; - ELSE - INSERT INTO tmp_Variation_Type ( - id_type - ) - SELECT - DISTINCT VT.id_type - FROM tmp_Split t_S - RIGHT JOIN partsltd_prod.Shop_Variation_Type VT ON t_S.as_int = VT.id_type - WHERE - ( - a_get_all_variation_type = 1 - OR ( - v_has_filter_variation_type = 1 - AND NOT ISNULL(t_S.as_int) - ) - ) - AND ( - a_get_inactive_variation_type = 1 - OR VT.active = 1 - ) - ; - END IF; - END IF; - - DELETE FROM tmp_Split; - - IF (v_has_filter_variation AND NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1)) THEN -- NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - CALL partsltd_prod.p_split(v_guid, a_ids_variation, ',', a_debug); - - DELETE FROM tmp_Split; - - INSERT INTO tmp_Split ( - substring - , as_int - ) - SELECT - substring - , CONVERT(substring, DECIMAL(10,0)) AS as_int - FROM partsltd_prod.Split_Temp - WHERE 1=1 - AND GUID = v_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( v_guid ); - END IF; - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Variation V ON t_S.as_int = V.id_variation - WHERE - ISNULL(t_S.as_int) - OR ISNULL(V.id_variation) - ) THEN - INSERT INTO tmp_Msg_Error ( - -- guid, - id_type, - code, - msg - ) - SELECT - -- v_guid, - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Invalid or inactive variation IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Variation V ON t_S.as_int = V.id_variation - WHERE - ISNULL(t_S.as_int) - OR ISNULL(VT.id_type) - ; - ELSE - INSERT INTO tmp_Variation ( - id_variation - , id_type - ) - SELECT - DISTINCT V.id_variation - , V.id_type - FROM tmp_Split t_S - RIGHT JOIN partsltd_prod.Shop_Variation V ON t_S.as_int = V.id_variation - WHERE - ( - a_get_all_variation = 1 - OR ( - v_has_filter_variation = 1 - AND NOT ISNULL(t_S.as_int) - ) - ) - AND ( - a_get_inactive_variation = 1 - OR V.active = 1 - ) - ; - END IF; - END IF; - - DELETE FROM tmp_Split; - - -- Permissions - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - -- SET v_id_user := (SELECT id_user FROM Shop_User WHERE name = CURRENT_USER()); - SET v_id_permission_variation := (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_PRODUCT' LIMIT 1); - - IF a_debug = 1 THEN - SELECT - v_guid - , a_id_user - , FALSE AS a_get_inactive_users - , v_id_permission_variation - , v_id_access_level_view - , '' AS a_ids_product - , 0 AS a_debug - ; - -- select * from Shop_Calc_User_Temp; - END IF; - - CALL p_shop_calc_user( - v_guid - , a_id_user - , FALSE -- a_get_inactive_users - , v_id_permission_variation - , v_id_access_level_view - , '' -- a_ids_product - , 0 -- a_debug - ); - - IF a_debug = 1 THEN - select * from Shop_Calc_User_Temp; - END IF; - - IF NOT EXISTS (SELECT can_view FROM Shop_Calc_User_Temp UE_T WHERE UE_T.GUID = v_guid) THEN - INSERT INTO tmp_Msg_Error ( - -- guid, - id_type, - code, - msg - ) - VALUES ( - -- v_guid, - v_id_type_error_bad_data, - v_code_error_bad_data, - CONCAT('You do not have view permissions for ', (SELECT name FROM Shop_Permission WHERE id_permission = v_id_permission_variation LIMIT 1)) - ) - ; - END IF; - - CALL p_shop_clear_calc_user( v_guid, 0 ); - END IF; - - IF EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - DELETE FROM tmp_Variation; - DELETE FROM tmp_Variation_Type; - END IF; - - -- Returns - -- Variation Types - SELECT - t_VT.id_type - , VT.code - , VT.name - , VT.name_plural - , VT.display_order - , VT.active - FROM tmp_Variation_Type t_VT - INNER JOIN Shop_Variation_Type VT ON t_VT.id_type = VT.id_type - ; - - -- Variations - SELECT - t_V.id_variation - , t_V.id_type - , V.code AS code_variation - , V.name AS name_variation - , V.display_order - , V.active AS active_variation - /* - , VT.code AS code_variation_type - , VT.name AS name_variation_type - , VT.name_plural AS name_plural_variation_type - , VT.active AS active_variation_type - , VT.display_order - */ - FROM tmp_Variation t_V - INNER JOIN Shop_Variation V ON t_V.id_variation = V.id_variation - INNER JOIN tmp_Variation_Type t_VT ON V.id_type = t_VT.id_type - INNER JOIN Shop_Variation_Type VT ON t_VT.id_type = VT.id_type - ORDER BY VT.display_order, V.display_order - ; - - -- Errors - SELECT - * - FROM tmp_Msg_Error t_ME - INNER JOIN Shop_Msg_Error_Type MET ON t_ME.id_type = MET.id_type - -- WHERE guid = v_guid - ; - - - -- Clean up - DROP TABLE IF EXISTS tmp_Variation; - DROP TABLE IF EXISTS tmp_Variation_Type; - - CALL partsltd_prod.p_shop_clear_calc_product_permutation ( v_guid ); - - IF a_debug = 1 THEN - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); - END IF; -END // -DELIMITER ; - -/* - -CALL p_shop_get_many_product_variation ( - 1 -- 'auth0|6582b95c895d09a70ba10fef', -- a_id_user - , 1 -- a_get_all_variation_type - , 1 -- a_get_inactive_variation_type - , '' -- a_ids_variation_type - , 1 -- a_get_all_variation - , 1 -- a_get_inactive_variation - , '' -- a_ids_variation - , 0 -- a_debug -); - - -select * from TMP_MSG_ERROR; -DROP TABLE TMP_MSG_ERROR; - -select * from shop_variation; -select * from shop_variation_type; -*/ -/* -select * from shop_supplier; -select * from shop_product; - -insert into shop_product_change_set (comment) - values ('set product not subscription - test bool output to python'); - update shop_product - set is_subscription = 0, - id_change_set = (select id_change_set from shop_product_change_set order by id_change_set desc limit 1) - where id_product = 1 - - INSERT INTO tmp_Variation_Type ( - id_type, - active, - rank_type - ) - SELECT - VT.id_type, - S.active, - RANK() OVER (ORDER BY id_type ASC) AS rank_type - FROM Shop_Variation_Type VT - LEFT JOIN Split_Temp S_T ON VT.id_type = S_T.substring - WHERE - ( - a_get_all_variation_type = 1 - OR NOT ISNULL(S_T.substring) - ) - AND ( - a_get_inactive_variation_type - OR VT.active = 1 - ) - ; - END IF; - - - IF a_get_first_variation_type_only THEN - DELETE t_VT - FROM tmp_Shop_Variation_Type t_VT - WHERE t_VT.rank_type > 1 - ; - END IF; -*/ - --- File: 7212_p_shop_save_product_variation.sql - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_save_product_variation; - -DROP TABLE IF EXISTS tmp_Variation_Type; -DROP TABLE IF EXISTS tmp_Variation; -DROP TABLE IF EXISTS tmp_Msg_Error; - -DELIMITER // -CREATE PROCEDURE p_shop_save_product_variation ( - IN a_comment VARCHAR(500) - , IN a_guid BINARY(36) - , IN a_id_user INT - , IN a_debug BIT -) -BEGIN - DECLARE v_code_type_error_bad_data VARCHAR(50); - DECLARE v_code_type_error_no_permission VARCHAR(50); - DECLARE v_code_type_error_warning VARCHAR(50); - DECLARE v_id_access_level_edit INT; - DECLARE v_id_change_set INT; - DECLARE v_ids_permission_product_variation VARCHAR(100); - DECLARE v_id_type_error_bad_data INT; - DECLARE v_id_type_error_no_permission INT; - DECLARE v_id_type_error_warning INT; - DECLARE v_ids_product_permission TEXT; - DECLARE v_time_start TIMESTAMP(6); - - DECLARE exit handler for SQLEXCEPTION - BEGIN - GET DIAGNOSTICS CONDITION 1 - @sqlstate = RETURNED_SQLSTATE - , @errno = MYSQL_ERRNO - , @text = MESSAGE_TEXT - ; - - ROLLBACK; - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT - , id_type INT NULL - , code VARCHAR(50) NOT NULL - , msg VARCHAR(4000) NOT NULL - ); - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - MET.id_type - , @errno - , @text - FROM partsltd_prod.Shop_Msg_Error_Type MET - WHERE code = 'MYSQL_ERROR' - LIMIT 1 - ; - SELECT * - FROM tmp_Msg_Error; - DROP TABLE IF EXISTS tmp_Msg_Error; - END; - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_code_type_error_bad_data := (SELECT code FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1); - SET v_id_type_error_bad_data := (SELECT id_type FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = v_code_type_error_bad_data LIMIT 1); - SET v_code_type_error_no_permission := (SELECT code FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = 'NO_PERMISSION' LIMIT 1); - SET v_id_type_error_no_permission := (SELECT id_type FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = v_code_type_error_no_permission LIMIT 1); - SET v_code_type_error_warning := (SELECT code FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = 'WARNING' LIMIT 1); - SET v_id_type_error_warning := (SELECT id_type FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = v_code_type_error_warning LIMIT 1); - SET v_ids_permission_product_variation := (SELECT GROUP_CONCAT(id_permission SEPARATOR ',') FROM partsltd_prod.Shop_Permission WHERE code IN ('STORE_PRODUCT')); - SET v_id_access_level_edit := (SELECT id_access_level FROM partsltd_prod.Shop_Access_Level WHERE code = 'EDIT' LIMIT 1); - - CALL p_validate_guid ( a_guid ); - SET a_comment := TRIM(IFNULL(a_comment, '')); - - DROP TEMPORARY TABLE IF EXISTS tmp_Variation_Type; - DROP TEMPORARY TABLE IF EXISTS tmp_Variation; - DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error; - - -- Temporary tables - CREATE TEMPORARY TABLE tmp_Variation_Type ( - id_type INT NOT NULL PRIMARY KEY - , id_type_temp INT NOT NULL - , code VARCHAR(50) - , name VARCHAR(255) - , name_plural VARCHAR(256) - , active BIT NULL - , display_order INT NOT NULL - , created_on DATETIME - , created_by INT - , is_new BIT NOT NULL - , name_error VARCHAR(1000) NOT NULL - ); - -- CREATE TEMPORARY TABLE tmp_Variation_Type_Count - - CREATE TEMPORARY TABLE tmp_Variation ( - id_variation INT NOT NULL PRIMARY KEY - , id_type INT NOT NULL - , code VARCHAR(50) - , name VARCHAR(255) - , active BIT - , display_order INT NOT NULL - , created_on DATETIME - , created_by INT - , has_type BIT NULL - , is_new BIT NOT NULL - , name_error VARCHAR(1000) NOT NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT - , id_type INT NOT NULL - , code VARCHAR(50) NOT NULL - , msg VARCHAR(4000) NOT NULL - ); - - INSERT INTO tmp_Variation_Type ( - id_type - , id_type_temp - , code - , name - , name_plural - , active - , display_order - , created_on - , created_by - , is_new - , name_error - ) - SELECT - VT_T.id_type - , VT_T.id_type - , VT_T.code - , VT_T.name - , VT_T.name_plural - , VT_T.active - , VT_T.display_order - , IFNULL(VT_T.created_on, VT.created_on) AS created_on - , IFNULL(VT_T.created_by, VT.created_by) AS created_by - , IFNULL(VT_T.id_type, 0) < 1 AS is_new - , CASE WHEN IFNULL(VT_T.id_type, 0) < 1 THEN - CONCAT( - 'New Variation Type: ' - , VT_T.display_order - , ' - ' - , IFNULL(VT_T.code, '(No Code)') - , ' - ' - , IFNULL(VT_T.name, '(No Name)') - ) - ELSE - CONCAT( - VT_T.display_order - , ' - ' - , IFNULL(VT_T.code, '(No Code)') - , ' - ' - , IFNULL(VT_T.name, '(No Name)') - ) - END AS name_error - FROM partsltd_prod.Shop_Variation_Type_Temp VT_T - LEFT JOIN partsltd_prod.Shop_Variation_Type VT ON VT_T.id_type = VT.id_type - WHERE VT_T.GUID = a_guid - ; - - INSERT INTO tmp_Variation ( - id_variation - , id_type - , code - , name - , active - , display_order - , created_on - , created_by - , has_type - , is_new - , name_error - ) - SELECT - V_T.id_variation - , IFNULL(V_T.id_type, V.id_type) AS id_type - , V_T.code - , V_T.name - , V_T.active - , V_T.display_order - , IFNULL(V_T.created_on, V.created_on) AS created_on - , IFNULL(V_T.created_by, V.created_by) AS created_by - , NOT ISNULL(t_VT.id_type) AS has_type - , IFNULL(V_T.id_variation, 0) < 1 AS is_new - , CASE WHEN IFNULL(V_T.id_variation, 0) < 1 THEN - CONCAT( - 'New Variation: ' - , V_T.display_order - , ' - ' - , IFNULL(V_T.code, '(No Code)') - , ' - ' - , IFNULL(V_T.name, '(No Name)') - ) - ELSE - CONCAT( - V_T.display_order - , ' - ' - , IFNULL(V_T.code, '(No Code)') - , ' - ' - , IFNULL(V_T.name, '(No Name)') - ) - END AS name_error - FROM partsltd_prod.Shop_Variation_Temp V_T - LEFT JOIN partsltd_prod.Shop_Variation V ON V_T.id_variation = V.id_variation - -- LEFT JOIN partsltd_prod.Shop_Variation_Type VT ON V_T.id_type = VT.id_type - LEFT JOIN tmp_Variation_Type t_VT ON V_T.id_type = t_VT.id_type - WHERE V_T.GUID = a_guid - ; - - -- Insert missing order records - INSERT INTO tmp_Variation_Type ( - id_type - , id_type_temp - , code - , name - , name_plural - , active - , display_order - , created_on - , created_by - , is_new - , name_error - ) - SELECT - VT.id_type - , VT.id_type - , VT.code - , VT.name - , VT.name_plural - , VT.active - , VT.display_order - , VT.created_on - , VT.created_by - , 0 AS is_new - , CONCAT( - VT.display_order - , ' - ' - , IFNULL(VT.code, '(No Code)') - , ' - ' - , IFNULL(VT.name, '(No Name)') - ) AS name_error - FROM partsltd_prod.Shop_Variation_Type VT - INNER JOIN tmp_Variation t_V - ON VT.id_type = t_V.id_type - AND t_V.has_type = 0 - AND NOT ISNULL(t_V.id_type) - ; - - UPDATE tmp_Variation t_V - INNER JOIN tmp_Variation_Type t_VT ON t_V.id_type = t_V.id_type - SET t_V.has_type = 1 - WHERE t_V.has_type = 0 - ; - - -- Validation - -- Variation Type - -- id_type - IF EXISTS ( - SELECT * - FROM tmp_Variation_Type t_VT - INNER JOIN partsltd_prod.Shop_Variation_Type VT ON t_VT.id_type = VT.id_type - WHERE 1=1 - AND t_VT.id_type > 0 - AND ISNULL(VT.id_type) - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT( - 'A valid ID is required for the following Product Variation Type(s): ' - , GROUP_CONCAT(t_VT.name_error SEPARATOR ', ') - ) AS msg - FROM tmp_Variation_Type t_VT - INNER JOIN partsltd_prod.Shop_Variation_Type VT ON t_VT.id_type = VT.id_type - WHERE 1=1 - AND t_VT.id_type > 0 - AND ISNULL(VT.id_type) - ; - END IF; - -- Variation - -- id_variation - IF EXISTS ( - SELECT * - FROM tmp_Variation t_V - INNER JOIN partsltd_prod.Shop_Variation V ON t_V.id_variation = V.id_variation - WHERE 1=1 - AND t_V.id_variation > 0 - AND ISNULL(V.id_variation) - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT( - 'A valid ID is required for the following Product Variation(s): ' - , GROUP_CONCAT(t_V.name_error SEPARATOR ', ') - ) AS msg - FROM tmp_Variation t_V - INNER JOIN partsltd_prod.Shop_Variation V ON t_V.id_variation = V.id_variation - WHERE 1=1 - AND t_V.id_variation > 0 - AND ISNULL(V.id_variation) - ; - END IF; - -- id_type - IF EXISTS ( SELECT * FROM tmp_Variation t_V WHERE t_V.has_type = 0 LIMIT 1 ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT( - 'A valid ID is required for the following Product Variation(s): ' - , GROUP_CONCAT(t_V.name_error SEPARATOR ', ') - ) AS msg - FROM tmp_Variation t_V - WHERE t_V.has_type = 0 - ; - END IF; - - -- Duplicate Variation Type Ids - -- Duplicate Variation Ids - -- Duplicate Variation Type Codes - -- Duplicate Variation Codes - -- Variation unit measurement with no count unit measurement - - -- Permissions - IF a_debug = 1 THEN - SELECT - a_guid - , a_id_user - , FALSE -- get inactive users - , v_ids_permission_product_variation - , v_id_access_level_edit - , NULL -- ids_product - , 0 -- a_debug - ; - SELECT * - FROM partsltd_prod.Shop_Calc_User_Temp - WHERE GUID = a_guid - ; - END IF; - - CALL p_shop_calc_user( - a_guid - , a_id_user - , FALSE -- get inactive users - , v_ids_permission_product_variation - , v_id_access_level_edit - , NULL -- ids_product - , 0 -- a_debug - ); - - IF a_debug = 1 THEN - SELECT * from partsltd_prod.Shop_Calc_User_Temp WHERE GUID = a_guid; - END IF; - - IF EXISTS (SELECT * FROM partsltd_prod.Shop_Calc_User_Temp UE_T WHERE UE_T.GUID = a_guid AND IFNULL(UE_T.can_view, 0) = 0) THEN - DELETE FROM tmp_Msg_Error; - - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_no_permission - , v_code_type_error_no_permission - , CONCAT( - 'You do not have edit permissions for ' - , GROUP_CONCAT(name SEPARATOR ', ') - ) - FROM partsltd_prod.Shop_Permission PERM - INNER JOIN partsltd_prod.Shop_Calc_User_Temp UE_T - ON PERM.id_permission = UE_T.id_permission - AND UE_T.GUID = a_guid - AND IFNULL(UE_T.can_view, 0) = 0 - ; - END IF; - - CALL partsltd_prod.p_shop_clear_calc_user( - a_guid - , 0 -- a_debug - ); - - IF EXISTS ( SELECT * FROM tmp_Msg_Error WHERE id_type <> v_id_type_error_warning LIMIT 1 ) THEN - DELETE FROM tmp_Variation_Type; - DELETE FROM tmp_Variation; - END IF; - - -- Transaction - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - START TRANSACTION; - INSERT INTO Shop_Product_Change_Set ( - comment - , updated_last_by - , updated_last_on - ) - VALUES ( - a_comment - , a_id_user - , v_time_start - ); - - SET v_id_change_set := LAST_INSERT_ID(); - - INSERT INTO partsltd_prod.Shop_Variation_Type ( - id_type_temp - , code - , name - , name_plural - , active - , display_order - , created_on - , created_by - ) - SELECT - t_VT.id_type - , t_VT.code - , t_VT.name - , t_VT.name_plural - , t_VT.active - , t_VT.display_order - , t_VT.created_on - , t_VT.created_by - FROM tmp_Variation_Type t_VT - WHERE t_VT.is_new = 1 - ; - - UPDATE tmp_Variation_Type t_VT - INNER JOIN partsltd_prod.Shop_Variation_Type VT ON t_VT.id_type_temp = VT.id_type_temp - SET - t_VT.id_type = VT.id_type - WHERE t_VT.is_new = 1 - ; - - UPDATE tmp_Variation t_V - INNER JOIN tmp_Variation_Type t_VT - ON t_V.id_type = t_VT.id_type_temp - AND t_VT.is_new = 1 - SET - t_V.id_type = t_VT.id_type - ; - - INSERT INTO partsltd_prod.Shop_Variation ( - id_type - , code - , name - , active - , display_order - , created_on - , created_by - ) - SELECT - t_V.id_type - , t_V.code - , t_V.name - , t_V.active - , t_V.display_order - , t_V.created_on - , t_V.created_by - FROM tmp_Variation t_V - WHERE t_V.is_new = 1 - ; - - UPDATE partsltd_prod.Shop_Variation_Type VT - INNER JOIN tmp_Variation_Type t_VT - ON VT.id_type = t_VT.id_type - AND t_VT.is_new = 0 - INNER JOIN tmp_Variation t_V ON t_VT.id_type = t_V.id_type - SET - VT.code = t_VT.code - , VT.name = t_VT.name - , VT.name_plural = t_VT.name_plural - , VT.active = t_VT.active - , VT.display_order = t_VT.display_order - , VT.created_on = t_VT.created_on - , VT.created_by = t_VT.created_by - , VT.id_change_set = v_id_change_set - ; - - UPDATE partsltd_prod.Shop_Variation V - INNER JOIN tmp_Variation t_V - ON V.id_variation = t_V.id_variation - AND t_V.is_new = 0 - SET - V.code = t_V.code - , V.name = t_V.name - , V.active = t_V.active - , V.display_order = t_V.display_order - , V.created_on = t_V.created_on - , V.created_by = t_V.created_by - , V.id_change_set = v_id_change_set - ; - - COMMIT; - END IF; - - START TRANSACTION; - - DELETE VT_T - FROM partsltd_prod.Shop_Variation_Type_Temp VT_T - WHERE VT_T.GUID = a_guid - ; - DELETE V_T - FROM partsltd_prod.Shop_Variation_Temp V_T - WHERE V_T.GUID = a_guid - ; - - COMMIT; - - -- Errors - SELECT * - FROM tmp_Msg_Error t_ME - INNER JOIN partsltd_prod.Shop_Msg_Error_Type MET ON t_ME.id_type = MET.id_type - ; - - IF a_debug = 1 THEN - SELECT * from tmp_Variation_Type; - SELECT * from tmp_Variation; - END IF; - - DROP TEMPORARY TABLE tmp_Variation_Type; - DROP TEMPORARY TABLE tmp_Variation; - DROP TEMPORARY TABLE tmp_Msg_Error; - - IF a_debug = 1 THEN - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); - END IF; -END // -DELIMITER ; - - - - --- File: 7212_p_shop_save_product_variation_test.sql - - --- Clear previous proc -DROP PROCEDURE IF EXISTS partsltd_prod.p_shop_save_product_variation_test; - - -DELIMITER // -CREATE PROCEDURE p_shop_save_product_variation_test () -BEGIN - - DECLARE v_guid BINARY(36); - DECLARE v_time_start TIMESTAMP(6); - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_guid := 'nips'; - - SELECT * - FROM partsltd_prod.Shop_Variation_Type - ; - SELECT * - FROM partsltd_prod.Shop_Variation_Type_Temp - ; - SELECT * - FROM partsltd_prod.Shop_Variation - ; - SELECT * - FROM partsltd_prod.Shop_Variation_Temp - ; - - START TRANSACTION; - - DELETE FROM partsltd_prod.Shop_Variation_Type_Temp; - DELETE FROM partsltd_prod.Shop_Variation_Temp; - - INSERT INTO partsltd_prod.Shop_Variation_Type_Temp ( - id_type - -- , id_type_temp - , code - , name - , name_plural - , display_order - , active - , GUID - ) - /* Test 1 - Insert - VALUES ( - -1 - -- , -1 - , 'SIZE' - , 'Size' - , 'Sizes' - , 2 - , 1 - , v_guid - ) - */ - /* Test 2: Alter */ - SELECT - id_type - -- , id_type AS id_type_temp - , code - , name - , name_plural - , display_order - , active - , v_guid AS GUID - FROM partsltd_prod.Shop_Variation_Type - WHERE id_type = 1 - ; - - INSERT INTO partsltd_prod.Shop_Variation_Temp ( - id_variation - , id_type - , code - , name - , display_order - , active - , GUID - ) - /* Test 1 - Insert - VALUES ( - -1 -- id_variation - , -1 -- id_type - , '300 mL' -- code - , '300 millilitres' -- name - , 1 -- display_order - , 1 -- active - , v_guid -- - ) - */ - /* Test 3 - Insert - VALUES ( - -1 -- id_variation - , 1 -- id_type - , 'SILVER' -- code - , 'Silver' -- name - , 10 -- display_order - , 1 -- active - , 'NIPS' -- v_guid -- - ); - */ - /* Test 2: Alter */ - SELECT - id_variation - , id_type - , code - , name - , display_order - , active - , v_guid AS GUID - FROM partsltd_prod.Shop_Variation - WHERE id_variation = 2 - UNION - SELECT - -1 -- id_variation - , 1 -- id_type - , 'GREEN' -- code - , 'Green' -- name - , 3 -- display_order - , 1 -- active - , v_guid -- - ; - - COMMIT; - - SELECT * - FROM partsltd_prod.Shop_Variation_Type_Temp - WHERE GUID = v_guid - ; - - SELECT * - FROM partsltd_prod.Shop_Variation_Temp - WHERE GUID = v_guid - ; - - CALL partsltd_prod.p_shop_save_product_variation ( - 'Test save Variations - add + edit' -- comment - , v_guid -- guid - , 1 -- id_user - , 1 -- debug - ); - - SELECT * - FROM partsltd_prod.Shop_Variation_Type_Temp - ; - SELECT * - FROM partsltd_prod.Shop_Variation_Temp - ; - SELECT * - FROM partsltd_prod.Shop_Variation_Type - ; - SELECT * - FROM partsltd_prod.Shop_Variation - ; - - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); -END // -DELIMITER ; - -/* -CALL partsltd_prod.p_shop_save_product_variation_test (); - -DELETE FROM partsltd_prod.Shop_Variation_Type_Temp; -DELETE FROM partsltd_prod.Shop_Variation_Temp; - -DROP TABLE IF EXISTS tmp_Msg_Error; - - -delete from shop_variation_audit -where id_variation = 3 -; -delete from shop_variation_audit -where id_variation = 3 -; -delete from shop_variation_type_audit -where id_type = -1 -; -delete --- select * - from shop_variation_type -where id_type = -1 -; - -Cannot add or update a child row: a foreign key constraint fails (`partsltd_prod`.`shop_variation_type`, CONSTRAINT `FK_Shop_Variation_Type_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`)) - -*/ - --- File: 7219_p_shop_get_many_stock_item.sql - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_get_many_stock_item; - - -DELIMITER // -CREATE PROCEDURE p_shop_get_many_stock_item ( - IN a_id_user INT, - IN a_get_all_product_permutation BIT, - IN a_get_inactive_product_permutation BIT, - IN a_ids_product_permutation TEXT, - IN a_get_all_stock_item BIT, - IN a_get_inactive_stock_item BIT, - IN a_ids_stock_item LONGTEXT, - IN a_get_all_region_storage BIT, - IN a_get_inactive_region_storage BIT, - IN a_ids_region_storage TEXT, - IN a_get_all_plant_storage BIT, - IN a_get_inactive_plant_storage BIT, - IN a_ids_plant_storage TEXT, - IN a_get_all_location_storage BIT, - IN a_get_inactive_location_storage BIT, - IN a_ids_location_storage TEXT, - IN a_date_received_to DATETIME, - IN a_get_sealed_stock_item_only BIT, - IN a_get_unsealed_stock_item_only BIT, - IN a_get_expired_stock_item_only BIT, - IN a_get_nonexpired_stock_item_only BIT, - IN a_get_consumed_stock_item_only BIT, - IN a_get_nonconsumed_stock_item_only BIT, - IN a_debug BIT -) -BEGIN - DECLARE v_has_filter_permutation BIT; - DECLARE v_has_filter_stock_item BIT; - DECLARE v_has_filter_region_storage BIT; - DECLARE v_has_filter_plant_storage BIT; - DECLARE v_has_filter_location_storage BIT; - DECLARE v_guid BINARY(36); - -- DECLARE v_ids_permutation_unavailable LONGTEXT; - DECLARE v_id_permission_product INT; - DECLARE v_ids_product_permission LONGTEXT; - -- DECLARE v_ids_permutation_permission VARCHAR(4000); - DECLARE v_id_access_level_view INT; - -- DECLARE v_now DATETIME; - -- DECLARE v_id_minimum INT; - DECLARE v_time_start TIMESTAMP(6); - - SET v_guid := UUID(); - SET v_id_access_level_view := (SELECT id_access_level FROM partsltd_prod.Shop_Access_Level WHERE code = 'VIEW'); - SET v_time_start := CURRENT_TIMESTAMP(6); - - - -- Argument validation + default values - SET a_id_user := TRIM(IFNULL(a_id_user, '')); - SET a_get_all_product_permutation := IFNULL(a_get_all_product_permutation, 0); - -- SET a_guid_permutations := IFNULL(a_guid_permutations, ''); - SET a_get_inactive_product_permutation := IFNULL(a_get_inactive_product_permutation, 0); - SET a_ids_product_permutation := IFNULL(a_ids_product_permutation, ''); - SET a_get_all_stock_item := IFNULL(a_get_all_stock_item, 0); - SET a_get_inactive_stock_item := IFNULL(a_get_inactive_stock_item, 0); - SET a_ids_stock_item := TRIM(IFNULL(a_ids_stock_item, '')); - SET a_get_all_region_storage := IFNULL(a_get_all_region_storage, 0); - SET a_get_inactive_region_storage := IFNULL(a_get_inactive_region_storage, 0); - SET a_ids_region_storage := TRIM(IFNULL(a_ids_region_storage, '')); - SET a_get_all_plant_storage := IFNULL(a_get_all_plant_storage, 0); - SET a_get_inactive_plant_storage := IFNULL(a_get_inactive_plant_storage, 0); - SET a_ids_plant_storage := TRIM(IFNULL(a_ids_plant_storage, '')); - SET a_get_all_location_storage := IFNULL(a_get_all_location_storage, 0); - SET a_get_inactive_location_storage := IFNULL(a_get_inactive_location_storage, 0); - SET a_ids_location_storage := TRIM(IFNULL(a_ids_location_storage, '')); - SET a_date_received_to := a_date_received_to; -- IFNULL(a_date_received_to, NOW()); - SET a_get_sealed_stock_item_only := IFNULL(a_get_sealed_stock_item_only, 0); - SET a_get_unsealed_stock_item_only := IFNULL(a_get_unsealed_stock_item_only, 0); - SET a_get_expired_stock_item_only := IFNULL(a_get_expired_stock_item_only, 0); - SET a_get_nonexpired_stock_item_only := IFNULL(a_get_nonexpired_stock_item_only, 0); - SET a_get_consumed_stock_item_only := IFNULL(a_get_consumed_stock_item_only, 0); - SET a_get_nonconsumed_stock_item_only := IFNULL(a_get_nonconsumed_stock_item_only, 0); - - -- Temporary tables - DROP TEMPORARY TABLE IF EXISTS tmp_Region_Storage; - DROP TEMPORARY TABLE IF EXISTS tmp_Plant_Storage; - DROP TEMPORARY TABLE IF EXISTS tmp_Location_Storage; - DROP TEMPORARY TABLE IF EXISTS tmp_Stock_Item; - DROP TEMPORARY TABLE IF EXISTS tmp_Permutation; - -- DROP TABLE IF EXISTS tmp_Msg_Error; - DROP TEMPORARY TABLE IF EXISTS tmp_Category; - DROP TEMPORARY TABLE IF EXISTS tmp_Permutation; - DROP TEMPORARY TABLE IF EXISTS tmp_Product; - - CREATE TEMPORARY TABLE tmp_Category ( - id_category INT NOT NULL - , display_order INT NOT NULL - ); - - CREATE TEMPORARY TABLE tmp_Product ( - id_category INT NOT NULL - , id_product INT NOT NULL - , display_order INT NOT NULL - ); - - CREATE TEMPORARY TABLE tmp_Permutation ( - id_permutation INT NULL - , id_product INT NOT NULL - , can_view BIT - , can_edit BIT - , can_admin BIT - ); - - CREATE TEMPORARY TABLE tmp_Stock_Item ( - id_stock INT NOT NULL PRIMARY KEY - , id_permutation INT NOT NULL - , id_product INT NOT NULL - , id_location_storage INT NOT NULL - , can_view BIT NULL - , can_edit BIT NULL - , can_admin BIT NULL - ); - - CREATE TEMPORARY TABLE tmp_Region_Storage ( - id_region INT NOT NULL PRIMARY KEY - /* - CONSTRAINT FK_tmp_Region_Storage_id_region - FOREIGN KEY (id_region) - REFERENCES Shop_Region(id_region) - */ - -- , rank_region INT NOT NULL - ); - - CREATE TEMPORARY TABLE tmp_Plant_Storage ( - id_plant INT NOT NULL PRIMARY KEY - /* - CONSTRAINT FK_tmp_Plant_Storage_id_plant - FOREIGN KEY (id_plant) - REFERENCES Shop_Plant(id_plant) - */ - -- , rank_plant INT NOT NULL - , id_region INT NOT NULL - ); - - CREATE TEMPORARY TABLE tmp_Location_Storage ( - id_location INT NOT NULL PRIMARY KEY - /* - CONSTRAINT FK_tmp_Location_Storage_id_location - FOREIGN KEY (id_location) - REFERENCES Shop_Location_Storage(id_location) - */ - -- , rank_location INT NOT NULL - , id_plant INT NOT NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - -- guid BINARY(36) NOT NULL, - id_type INT NULL, - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Split ( - substring VARCHAR(4000) NOT NULL - , as_int INT NULL - ); - DELETE FROM tmp_Split; - - - -- Parse filters - SET v_has_filter_permutation = CASE WHEN a_ids_product_permutation = '' THEN 0 ELSE 1 END; -- CASE WHEN a_guid_permutations = '' THEN 0 ELSE 1 END; - SET v_has_filter_stock_item = CASE WHEN a_ids_stock_item = '' THEN 0 ELSE 1 END; - SET v_has_filter_region_storage = CASE WHEN a_ids_region_storage = '' THEN 0 ELSE 1 END; - SET v_has_filter_plant_storage = CASE WHEN a_ids_plant_storage = '' THEN 0 ELSE 1 END; - SET v_has_filter_location_storage = CASE WHEN a_ids_location_storage = '' THEN 0 ELSE 1 END; - - -- select v_has_filter_product, v_has_filter_permutation; - - CALL partsltd_prod.p_shop_calc_product_permutation ( - a_id_user - , 1 -- a_get_all_product_category - , 0 -- a_get_inactive_product_category - , '' -- a_ids_product_category - , 1 -- a_get_all_product - , 0 -- a_get_inactive_product - , '' -- a_ids_product - , a_get_all_product_permutation - , a_get_inactive_product_permutation - , a_ids_product_permutation - , 0 - , v_guid -- a_guid - , 0 -- a_debug - ); - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - INSERT INTO tmp_Category ( - id_category - , display_order - ) - SELECT - PC.id_category - , PC.display_order - FROM (SELECT * FROM partsltd_prod.Shop_Product_Category_Temp WHERE GUID = v_guid) PC_T - INNER JOIN partsltd_prod.Shop_Product_Category PC ON PC_T.id_category = PC.id_category - ; - - INSERT INTO tmp_Product ( - id_product - , id_category - , display_order - ) - SELECT - P.id_product - , P.id_category - , P.display_order - FROM (SELECT * FROM partsltd_prod.Shop_Product_Temp WHERE GUID = v_guid) P_T - INNER JOIN partsltd_prod.Shop_Product P ON P.id_product = P_T.id_product - ; - - INSERT INTO tmp_Permutation ( - id_permutation - , id_product - , can_view - , can_edit - , can_admin - ) - SELECT - PP.id_permutation - , PP.id_product - , PP_T.can_view - , PP_T.can_edit - , PP_T.can_admin - FROM (SELECT * FROM partsltd_prod.Shop_Product_Permutation_Temp WHERE GUID = v_guid) PP_T - INNER JOIN partsltd_prod.Shop_Product_Permutation PP ON PP_T.id_permutation = PP.id_permutation - ; - - -- Stock Items - CALL partsltd_prod.p_split(v_guid, a_ids_stock_item, ',', a_debug); - - DELETE FROM tmp_Split; - - INSERT INTO tmp_Split ( - substring - , as_int - ) - SELECT - substring - , CONVERT(substring, DECIMAL(10,0)) AS as_int - FROM partsltd_prod.Split_Temp - WHERE 1=1 - AND GUID = v_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( v_guid ); - END IF; - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Stock_Item SI ON t_S.as_int = SI.id_stock - WHERE - ISNULL(t_S.as_int) - OR ISNULL(SI.id_stock) - ) THEN - INSERT INTO tmp_Msg_Error ( - -- guid, - id_type, - code, - msg - ) - SELECT - -- v_guid, - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Invalid or inactive stock item IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Stock_Item SI ON t_S.as_int = SI.id_stock - WHERE - ISNULL(t_S.as_int) - OR ISNULL(SI.id_stock) - ; - ELSE - INSERT INTO tmp_Stock_Item ( - id_stock - , id_permutation - , id_product - , id_location_storage - ) - SELECT - SI.id_stock - , SI.id_permutation - , t_PP.id_product - , SI.id_location_storage - FROM tmp_Split t_S - RIGHT JOIN partsltd_prod.Shop_Stock_Item SI ON t_S.as_int = SI.id_stock - INNER JOIN tmp_Permutation t_PP ON SI.id_permutation = t_PP.id_permutation - WHERE - ( - a_get_all_stock_item = 1 - OR ( - v_has_filter_stock_item = 1 - AND NOT ISNULL(t_S.as_int) - ) - ) - AND ( - a_get_inactive_stock_item = 1 - OR SI.active = 1 - ) - AND ( - ISNULL(a_date_received_to) - OR SI.date_received <= a_date_received_to - ) - AND ( - a_get_unsealed_stock_item_only = 0 - OR SI.is_sealed = 0 - ) - AND ( - a_get_sealed_stock_item_only = 0 - OR SI.is_sealed = 1 - ) - AND ( - a_get_nonexpired_stock_item_only = 0 - OR SI.date_expiration > v_time_start - ) - AND ( - a_get_expired_stock_item_only = 0 - OR SI.date_expiration <= v_time_start - ) - AND ( - a_get_consumed_stock_item_only = 0 - OR SI.is_consumed = 1 - ) - AND ( - a_get_nonconsumed_stock_item_only = 0 - OR SI.is_consumed = 0 - ) - ; - END IF; - END IF; - - DELETE FROM tmp_Split; - - -- Storage Regions - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - CALL partsltd_prod.p_split(v_guid, a_ids_region_storage, ',', a_debug); - - DELETE FROM tmp_Split; - - INSERT INTO tmp_Split ( - substring - , as_int - ) - SELECT - substring - , CONVERT(substring, DECIMAL(10,0)) AS as_int - FROM partsltd_prod.Split_Temp - WHERE 1=1 - AND GUID = v_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( v_guid ); - END IF; - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Region R ON t_S.as_int = R.id_region - WHERE - ISNULL(t_S.as_int) - OR ISNULL(R.id_region) - ) THEN - INSERT INTO tmp_Msg_Error ( - -- guid, - id_type, - code, - msg - ) - SELECT - -- v_guid, - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Invalid or inactive region IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Region R ON t_S.as_int = R.id_region - WHERE - ISNULL(t_S.as_int) - OR ISNULL(R.id_region) - ; - ELSE - INSERT INTO tmp_Region_Storage ( - id_region - ) - WITH RECURSIVE Recursive_CTE_Region_Storage AS ( - SELECT - R.id_region AS id_region_parent, - NULL AS id_region_child - FROM tmp_Split t_S - RIGHT JOIN partsltd_prod.Shop_Region R - ON t_S.as_int = R.id_region - AND ( - a_get_all_region_storage = 1 - OR NOT ISNULL(t_S.as_int) - ) - AND ( - a_get_inactive_region_storage = 1 - OR R.active = 1 - ) - INNER JOIN ( - SELECT - A.id_region - FROM tmp_Stock_Item t_SI - -- INNER JOIN tmp_Stock_Item t_SI ON SL.id_location = t_SI.id_location_storage - INNER JOIN partsltd_prod.Shop_Storage_Location SL ON t_SI.id_location_storage = SL.id_location - INNER JOIN partsltd_prod.Shop_Plant P ON SL.id_plant = P.id_plant - INNER JOIN partsltd_prod.Shop_Address A ON P.id_address = A.id_address - ) A_SI ON R.id_region = A_SI.id_region - UNION - SELECT - RB.id_region_parent, - RB.id_region_child - FROM partsltd_prod.Shop_Region_Branch RB - INNER JOIN Recursive_CTE_Region_Storage r_RS - ON RB.id_region_parent = r_RS.id_region_child - AND ( - a_get_inactive_region_storage = 1 - OR RB.active = 1 - ) - ) - SELECT - DISTINCT R.id_region - FROM partsltd_prod.Shop_Region R - INNER JOIN Recursive_CTE_Region_Storage r_RS - ON R.id_region = r_RS.id_region_parent - OR R.id_region = r_RS.id_region_child - ; - END IF; - END IF; - - DELETE FROM tmp_Split; - - -- Plants - INSERT INTO tmp_Plant_Storage ( - id_plant - , id_region - ) - SELECT - DISTINCT P.id_plant - , A.id_region - FROM tmp_Stock_Item t_SI - INNER JOIN partsltd_prod.Shop_Storage_Location SL ON t_SI.id_location_storage = SL.id_location - INNER JOIN partsltd_prod.Shop_Plant P ON SL.id_plant = P.id_plant - INNER JOIN partsltd_prod.Shop_Address A ON P.id_address = A.id_address - ; - - -- Storage Locations - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - CALL partsltd_prod.p_split(v_guid, a_ids_location_storage, ',', a_debug); - - DELETE FROM tmp_Split; - - INSERT INTO tmp_Split ( - substring - , as_int - ) - SELECT - substring - , CONVERT(substring, DECIMAL(10,0)) AS as_int - FROM partsltd_prod.Split_Temp - WHERE 1=1 - AND GUID = v_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( v_guid ); - END IF; - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Region R ON t_S.as_int = R.id_region - WHERE - ISNULL(t_S.as_int) - OR ISNULL(R.id_region) - ) THEN - INSERT INTO tmp_Msg_Error ( - -- guid, - id_type, - code, - msg - ) - SELECT - -- v_guid, - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Invalid or inactive region IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Region R ON t_S.as_int = R.id_region - WHERE - ISNULL(t_S.as_int) - OR ISNULL(R.id_region) - ; - ELSE - INSERT INTO tmp_Location_Storage ( - id_location - , id_plant - ) - WITH RECURSIVE Recursive_CTE_Location_Storage AS ( - SELECT - SL.id_location AS id_location_parent, - NULL AS id_location_child - FROM tmp_Split t_S - RIGHT JOIN partsltd_prod.Shop_Storage_Location SL - ON t_S.as_int = SL.id_location - AND ( - a_get_all_location_storage = 1 - OR NOT ISNULL(t_S.as_int) - ) - AND ( - a_get_inactive_location_storage = 1 - OR SL.active = 1 - ) - INNER JOIN tmp_Stock_Item t_SI ON SL.id_location = t_SI.id_location_storage - UNION - SELECT - SLB.id_location_parent, - SLB.id_location_child - FROM partsltd_prod.Shop_Storage_Location_Branch SLB - INNER JOIN Recursive_CTE_Location_Storage r_LS - ON SLB.id_location_parent = r_LS.id_location_child - AND ( - a_get_inactive_location_storage - OR SLB.active = 1 - ) - ) - SELECT - DISTINCT SL.id_location - , SL.id_plant - FROM partsltd_prod.Shop_Storage_Location SL - INNER JOIN Recursive_CTE_Location_Storage r_LS - ON SL.id_location = r_LS.id_location_parent - OR SL.id_location = r_LS.id_location_child - ; - END IF; - END IF; - - DELETE FROM tmp_Split; - - /* - -- Permissions - IF EXISTS (SELECT * FROM tmp_Stock_Item LIMIT 1) THEN - SET v_id_permission_product := (SELECT id_permission FROM partsltd_prod.Shop_Permission WHERE code = 'STORE_PRODUCT' LIMIT 1); - SET v_ids_product_permission := (SELECT GROUP_CONCAT(id_product SEPARATOR ',') FROM tmp_Permutation WHERE NOT ISNULL(id_product)); - -- SET v_ids_permutation_permission := (SELECT GROUP_CONCAT(id_permutation SEPARATOR ',') FROM tmp_Shop_Product WHERE NOT ISNULL(id_permutation)); - - -- SELECT v_guid, a_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_product_permission; - -- select * FROM partsltd_prod.Shop_Calc_User_Temp; - - CALL p_shop_calc_user( - v_guid - , a_id_user - , false -- a_get_inactive_users - , v_id_permission_product - , v_id_access_level_view - , v_ids_product_permission - , 0 -- a_debug - ); - - -- select * FROM partsltd_prod.Shop_Calc_User_Temp; - - UPDATE tmp_Stock_Item t_SI - INNER JOIN partsltd_prod.Shop_Calc_User_Temp UE_T - ON t_SI.id_product = UE_T.id_product - AND UE_T.GUID = v_guid - SET t_SI.can_view = UE_T.can_view, - t_SI.can_edit = UE_T.can_edit, - t_SI.can_admin = UE_T.can_admin - ; - - DELETE t_SI - FROM tmp_Stock_Item t_SI - / * - LEFT JOIN partsltd_prod.Shop_Calc_User_Temp UE_T - ON t_SI.id_product = UE_T.id_product - AND UE_T.GUID = v_guid - * / - WHERE - / * - FIND_IN_SET(t_SI.id_product, ( - SELECT GROUP_CONCAT(UET.id_product SEPARATOR ',') - FROM partsltd_prod.Shop_Calc_User_Temp UET) - ) = 0 -- id_product NOT LIKE CONCAT('%', (SELECT GROUP_CONCAT(id_product SEPARATOR '|') FROM partsltd_prod.Shop_Calc_User_Temp), '%'); - * / - / * - ISNULL(UE_T.id_product) - OR IFNULL(UE_T.can_view, 0) = 0 - * / - t_SI.id_product NOT IN ( - SELECT id_product - FROM partsltd_prod.Shop_Calc_User_Temp UE_T - WHERE - GUID = v_guid - AND IFNULL(can_view, 0) = 1 - ) - ; - - -- CALL p_shop_clear_calc_user(v_guid); - -- DROP TABLE IF EXISTS Shop_Calc_User_Temp; - DELETE FROM partsltd_prod.Shop_Calc_User_Temp - WHERE GUID = v_guid - ; - END IF; - */ - - /* - select * FROM partsltd_prod.Shop_stock_item; - select * from tmp_Stock_Item; - select * from tmp_Permutation; - select * from tmp_Location_Storage; - select * from Shop_Storage_Location; - select * from tmp_Plant_Storage; - select * from tmp_Region_Storage; - */ - - -- Returns - -- SET v_now := NOW(); - -- Stock Items - SELECT - t_SI.id_stock, - t_SI.id_permutation, - P.id_product, - P.id_category, - t_SI.id_location_storage, - t_PS.id_plant, - PLANT.id_address AS id_address_plant, - t_RS.id_region AS id_region_plant, - SL.code AS code_storage_location, - SL.name AS name_storage_location, - PLANT.code AS code_plant, - PLANT.name AS name_plant, - SI.id_currency_cost, - CURRENCY.symbol AS symbol_currency_cost, - CURRENCY.code AS code_currency_cost, - SI.cost_local_VAT_excl, - SI.cost_local_VAT_incl, - SI.date_purchased, - SI.date_received, - SI.is_sealed, - SI.date_unsealed, - SI.date_expiration, - SI.is_consumed, - SI.date_consumed, - SI.active, - /* - t_SI.active_permutation, - t_SI.active_product, - t_SI.active_category, - */ - t_PP.can_view, - t_PP.can_edit, - t_PP.can_admin - FROM tmp_Stock_Item t_SI - INNER JOIN partsltd_prod.Shop_Stock_Item SI ON t_SI.id_stock = SI.id_stock - INNER JOIN tmp_Permutation t_PP ON t_SI.id_permutation = t_PP.id_permutation - INNER JOIN partsltd_prod.Shop_Product P ON t_PP.id_product = P.id_product - INNER JOIN tmp_Location_Storage t_LS ON t_SI.id_location_storage = t_LS.id_location - INNER JOIN tmp_Plant_Storage t_PS ON t_LS.id_plant = t_PS.id_plant - INNER JOIN partsltd_prod.Shop_Plant PLANT ON t_PS.id_plant = PLANT.id_plant - INNER JOIN partsltd_prod.Shop_Address A ON PLANT.id_address = A.id_address - INNER JOIN tmp_Region_Storage t_RS ON A.id_region = t_RS.id_region - INNER JOIN partsltd_prod.Shop_Storage_Location SL ON t_LS.id_location = SL.id_location - INNER JOIN partsltd_prod.Shop_Currency CURRENCY ON SI.id_currency_cost = CURRENCY.id_currency - WHERE - IFNULL(t_PP.can_view, 0) = 1 - ; - - -- Errors - SELECT - t_ME.display_order, - -- t_ME.guid, - t_ME.id_type, - t_ME.msg, - MET.code, - MET.name, - MET.description - FROM tmp_Msg_Error t_ME - INNER JOIN partsltd_prod.Shop_Msg_Error_Type MET - ON t_ME.id_type = MET.id_type - -- WHERE guid = v_guid - ; - - /* - -- Return arguments for test - SELECT - a_ids_category, - a_get_inactive_category, - a_ids_product, - a_get_inactive_product, - a_get_first_product_only, - a_get_all_product, - a_ids_image, - a_get_inactive_image, - a_get_first_image_only, - a_get_all_image - ; - */ - - - -- Clean up - DROP TEMPORARY TABLE IF EXISTS tmp_Region_Storage; - DROP TEMPORARY TABLE IF EXISTS tmp_Plant_Storage; - DROP TEMPORARY TABLE IF EXISTS tmp_Location_Storage; - DROP TEMPORARY TABLE IF EXISTS tmp_Stock_Item; - DROP TEMPORARY TABLE IF EXISTS tmp_Permutation; - -- DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error; - - CALL partsltd_prod.p_shop_clear_calc_product_permutation ( v_guid ); - - IF a_debug = 1 THEN - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); - END IF; -END // -DELIMITER ; - - -/* -CALL p_shop_get_many_stock_item ( - 1, -- a_id_user - 1, -- a_get_all_product_permutation - -- 'nips', -- a_guid_permutations - 0, -- a_get_inactive_product_permutation - '', -- a_ids_product_permutation - 1, -- a_get_all_stock_item - 0, -- a_get_inactive_stock_item - '', -- a_ids_stock_item - 1, -- a_get_all_region_storage - 0, -- a_get_inactive_delivery_region - '', -- a_ids_region_storage - 1, -- a_get_all_plant_storage - 0, -- a_get_inactive_plant_storage - '', -- a_ids_plant_storage - 1, -- a_get_all_location_storage - 0, -- a_get_inactive_location_storage - '', -- a_ids_location_storage - NULL, -- a_date_received_to - 0, -- a_get_sealed_stock_item_only - 0, -- a_get_unsealed_stock_item_only - 0, -- a_get_expired_stock_item_only - 0, -- a_get_nonexpired_stock_item_only - 0, -- a_get_consumed_stock_item_only - 0 -- a_get_nonconsumed_stock_item_only - , 0 -- a_debug -); - - - -DROP TABLE IF EXISTS tmp_Msg_Error; - -select * FROM partsltd_prod.Shop_Storage_Location; -select * FROM partsltd_prod.Shop_product; -select * from TMP_MSG_ERROR; -DROP TABLE TMP_MSG_ERROR; - -insert into shop_product_change_set (comment) - values ('set product not subscription - test bool output to python'); - update shop_product - set is_subscription = 0, - id_change_set = (select id_change_set FROM partsltd_prod.Shop_product_change_set order by id_change_set desc limit 1) - where id_product = 1 -*/ - - --- File: 7220_p_shop_save_stock_item.sql - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_save_stock_item; - -DELIMITER // -CREATE PROCEDURE p_shop_save_stock_item ( - IN a_comment VARCHAR(500) - , IN a_guid BINARY(36) - , IN a_id_user INT - , IN a_debug BIT -) -BEGIN - - DECLARE v_code_type_error_bad_data VARCHAR(100); - DECLARE v_id_access_level_edit INT; - DECLARE v_id_change_set INT; - DECLARE v_id_permission_product INT; - DECLARE v_id_type_error_bad_data INT; - DECLARE v_ids_product_permission LONGTEXT; - DECLARE v_time_start TIMESTAMP(6); - DECLARE v_time_expire DATETIME; - - DECLARE exit handler for SQLEXCEPTION - BEGIN - -- Get diagnostic information - GET DIAGNOSTICS CONDITION 1 - @sqlstate = RETURNED_SQLSTATE - , @errno = MYSQL_ERRNO - , @text = MESSAGE_TEXT - ; - - -- Rollback the transaction - ROLLBACK; - - -- Select the error information - -- SELECT 'Error' AS status, @errno AS error_code, @sqlstate AS sql_state, @text AS message; - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT - , id_type INT NULL - , code VARCHAR(50) NOT NULL - , msg VARCHAR(4000) NOT NULL - ); - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - NULL - , @errno - , @text - ; - SELECT * - FROM tmp_Msg_Error; - DROP TABLE IF EXISTS tmp_Msg_Error; - END; - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_time_expire := DATE_ADD(v_time_start, INTERVAL 1000 YEAR); - SET v_code_type_error_bad_data := 'BAD_DATA'; - SET v_id_type_error_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_type_error_bad_data LIMIT 1); - SET v_id_access_level_edit := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'EDIT' LIMIT 1); - - CALL partsltd_prod.p_validate_guid ( a_guid ); - - DROP TEMPORARY TABLE IF EXISTS tmp_Stock_Item; - DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error; - - CREATE TEMPORARY TABLE tmp_Stock_Item ( - id_stock INT NOT NULL - , id_category INT NULL - , id_product INT NOT NULL - , id_permutation INT NULL - , id_pairs_variations VARCHAR(4000) NULL - , has_variations BIT NULL - , date_purchased DATETIME NOT NULL - , date_received DATETIME NULL - , id_location_storage INT NOT NULL - , id_currency_cost INT NOT NULL - , cost_local_VAT_incl FLOAT NOT NULL - , cost_local_VAT_excl FLOAT NOT NULL - , is_sealed BIT NOT NULL - , date_unsealed DATETIME NULL - , date_expiration DATETIME NOT NULL - , is_consumed BIT NOT NULL - , date_consumed DATETIME NULL - , active BIT NOT NULL - , can_view BIT NULL - , can_edit BIT NULL - , can_admin BIT NULL - , name_error VARCHAR(1000) NULL - , is_new BIT NOT NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT - , id_type INT NULL - , code VARCHAR(50) NOT NULL - , msg VARCHAR(4000) NOT NULL - ); - - - -- Get data from Temp table - INSERT INTO tmp_Stock_Item ( - id_stock - -- , id_category - , id_product - , id_permutation - , id_pairs_variations - , has_variations - , date_purchased - , date_received - , id_location_storage - , id_currency_cost - , cost_local_VAT_incl - , cost_local_VAT_excl - , is_sealed - , date_unsealed - , date_expiration - , is_consumed - , date_consumed - , active - -- , name_error - , is_new - ) - SELECT - SI_T.id_stock - -- , IFNULL(SI_T.id_category, P.id_category) AS id_category - , IFNULL(IFNULL(SI_T.id_product, PP.id_product), 0) AS id_product - , IFNULL(IFNULL(SI_T.id_permutation, SI.id_permutation), 0) AS id_permutation - , TRIM(IFNULL(SI_T.id_pairs_variations, '')) - , CASE WHEN TRIM(IFNULL(SI_T.id_pairs_variations, '')) = '' THEN 0 ELSE 1 END AS has_variations - , IFNULL(IFNULL(SI_T.date_purchased, SI.date_purchased), v_time_start) AS date_purchased - , IFNULL(SI_T.date_received, SI.date_received) AS date_received - , IFNULL(IFNULL(SI_T.id_location_storage, SI.id_location_storage), 0) AS id_location_storage - , IFNULL(IFNULL(SI_T.id_currency_cost, SI.id_currency_cost), 0) AS id_currency_cost - , IFNULL(SI_T.cost_local_VAT_incl, SI.cost_local_VAT_incl) AS cost_local_VAT_incl - , IFNULL(SI_T.cost_local_VAT_excl, SI.cost_local_VAT_excl) AS cost_local_VAT_excl - , IFNULL(IFNULL(SI_T.is_sealed, SI.is_sealed), 1) AS is_sealed - , IFNULL(SI_T.date_unsealed, SI.date_unsealed) AS date_unsealed - , IFNULL(IFNULL(SI_T.date_expiration, SI.date_expiration), v_time_expire) AS date_expiration - , IFNULL(IFNULL(SI_T.is_consumed, SI.is_consumed), 0) AS is_consumed - , IFNULL(SI_T.date_consumed, SI.date_consumed) AS date_consumed - , IFNULL(IFNULL(SI_T.active, SI.active), 1) AS active - -- , fn_shop_get_product_permutation_name(SI_T.id_permutation) - , CASE WHEN IFNULL(SI_T.id_stock, 0) < 1 THEN 1 ELSE 0 END AS is_new - FROM partsltd_prod.Shop_Stock_Item_Temp SI_T - LEFT JOIN partsltd_prod.Shop_Stock_Item SI ON SI_T.id_stock = SI.id_stock - LEFT JOIN partsltd_prod.Shop_Product_Permutation PP ON SI_T.id_permutation = PP.id_permutation - -- LEFT JOIN Shop_Product P ON PP.id_product = P.id_product - WHERE SI_T.guid = a_guid - ; - - -- Missing Permutation IDs for setting new permutation for stock item - -- With variations - UPDATE tmp_Stock_Item t_SI - INNER JOIN partsltd_prod.Shop_Product P ON t_SI.id_product = P.id_product - SET t_SI.id_permutation = IFNULL(fn_shop_get_id_product_permutation_from_variation_csv_list ( t_SI.id_product, t_SI.id_pairs_variations ), 0) - WHERE 1=1 - AND t_SI.id_permutation = 0 - AND t_SI.has_variations = 1 - ; - -- Without variations - UPDATE tmp_Stock_Item t_SI - -- INNER JOIN Shop_Product P ON t_SI.id_product = P.id_product - INNER JOIN partsltd_prod.Shop_Product_Permutation PP ON t_SI.id_product = PP.id_product - SET t_SI.id_permutation = IFNULL(PP.id_permutation, 0) - WHERE 1=1 - AND t_SI.id_permutation = 0 - AND t_SI.has_variations = 0 - ; - - -- Add stock item error names - UPDATE tmp_Stock_Item t_SI - INNER JOIN partsltd_prod.Shop_Product P ON t_SI.id_product = P.id_product - INNER JOIN partsltd_prod.Shop_Product_Category PC ON P.id_category = PC.id_category - -- INNER JOIN Shop_Product_Permutation PP ON t_SI.id_product = PP.id_product - SET t_SI.name_error = CONCAT( - PC.name, - ' - ', - P.name, - ' - ', - CASE WHEN IFNULL(t_SI.id_permutation, 0) = 0 THEN '(No permutation)' ELSE fn_shop_get_product_permutation_name ( t_SI.id_permutation ) END - ) - ; - - IF a_debug = 1 THEN - sElect * from tmp_Stock_Item; - END IF; - - -- Validation - -- id_stock - IF EXISTS ( - SELECT * - FROM tmp_Stock_Item t_SI - LEFT JOIN partsltd_prod.Shop_Stock_Item SI ON t_SI.id_stock = SI.id_stock - WHERE 1=1 - AND t_SI.id_stock > 0 - AND ISNULL(SI.id_stock) - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT( - 'Invalid stock item(s): ' - , GROUP_CONCAT( - CONCAT( - IFNULL(t_SI.id_stock, '(No Stock Item)') - , ' - ' - , IFNULL(t_SI.name_error, '(No Product)') - ) SEPARATOR ', ' - ) - ) AS msg - FROM tmp_Stock_Item t_SI - LEFT JOIN partsltd_prod.Shop_Product_Permutation PP ON t_SI.id_permutation = PP.id_permutation - WHERE 1=1 - AND t_SI.id_stock > 0 - AND ISNULL(SI.id_stock) - ; - END IF; - -- id_product - IF EXISTS (SELECT * FROM tmp_Stock_Item t_SI WHERE t_SI.id_product = 0 LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following stock item(s) do not have a product: ', GROUP_CONCAT(IFNULL(t_SI.name_error, 'NULL') SEPARATOR ', ')) AS msg - FROM tmp_Stock_Item t_SI - WHERE t_SI.id_product = 0 - ; - END IF; - -- id_permutation - IF EXISTS ( - SELECT * - FROM tmp_Stock_Item t_SI - LEFT JOIN partsltd_prod.Shop_Product_Permutation PP ON t_SI.id_permutation = PP.id_permutation - WHERE 1=1 - AND ( - t_SI.id_permutation = 0 - OR PP.active = 0 - ) - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('A valid permutation could not be found for the variations selected for the following stock item(s): ', GROUP_CONCAT(IFNULL(t_SI.name_error, 'NULL') SEPARATOR ', ')) AS msg - FROM tmp_Stock_Item t_SI - LEFT JOIN partsltd_prod.Shop_Product_Permutation PP ON t_SI.id_permutation = PP.id_permutation - WHERE 1=1 - AND ( - t_SI.id_permutation = 0 - OR PP.active = 0 - ) - ; - END IF; - -- date_purchased - IF EXISTS (SELECT * FROM tmp_Stock_Item t_SI WHERE ISNULL(t_SI.date_purchased) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following stock item(s) do not have an purchase date: ', GROUP_CONCAT(IFNULL(t_SI.name_error, 'NULL') SEPARATOR ', ')) AS msg - FROM tmp_Stock_Item t_SI - WHERE ISNULL(t_SI.date_purchased) - ; - END IF; - -- id_location_storage - IF EXISTS ( - SELECT * - FROM tmp_Stock_Item t_SI - INNER JOIN partsltd_prod.Shop_Storage_Location SL - ON t_SI.id_location_storage = SL.id_location - AND SL.active = 1 - WHERE ISNULL(SL.id_location) - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following stock item(s) do not have a valid storage location: ', GROUP_CONCAT(IFNULL(t_SI.name_error, 'NULL') SEPARATOR ', ')) AS msg - FROM tmp_Stock_Item t_SI - INNER JOIN partsltd_prod.Shop_Storage_Location SL - ON t_SI.id_location_storage = SL.id_location - AND SL.active = 1 - WHERE ISNULL(SL.id_location) - ; - END IF; - -- id_currency_cost - IF EXISTS ( - SELECT * - FROM tmp_Stock_Item t_SI - INNER JOIN partsltd_prod.Shop_Currency C - ON t_SI.id_currency_cost = C.id_currency - AND C.active = 1 - WHERE ISNULL(C.id_currency) - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following stock item(s) do not have a valid cost currency: ', GROUP_CONCAT(IFNULL(t_SI.name_error, 'NULL') SEPARATOR ', ')) AS msg - FROM tmp_Stock_Item t_SI - INNER JOIN partsltd_prod.Shop_Currency C - ON t_SI.id_currency_cost = C.id_currency - AND C.active = 1 - WHERE ISNULL(C.id_currency) - ; - END IF; - -- cost_local_VAT_excl - IF EXISTS ( - SELECT * - FROM tmp_Stock_Item t_SI - WHERE 1=1 - AND ( - ISNULL(t_SI.cost_local_VAT_excl) - OR t_SI.cost_local_VAT_excl < 0 - ) - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following stock item(s) do not have a valid cost excluding VAT: ', GROUP_CONCAT(IFNULL(t_SI.name_error, 'NULL') SEPARATOR ', ')) AS msg - FROM tmp_Stock_Item t_SI - WHERE 1=1 - AND ( - ISNULL(t_SI.cost_local_VAT_excl) - OR t_SI.cost_local_VAT_excl < 0 - ) - ; - END IF; - -- cost_local_VAT_incl - IF EXISTS ( - SELECT * - FROM tmp_Stock_Item t_SI - WHERE 1=1 - AND ( - ISNULL(t_SI.cost_local_VAT_incl) - OR t_SI.cost_local_VAT_incl < 0 - ) - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following stock item(s) do not have a valid cost including VAT: ', GROUP_CONCAT(IFNULL(t_SI.name_error, 'NULL') SEPARATOR ', ')) AS msg - FROM tmp_Stock_Item t_SI - WHERE 1=1 - AND ( - ISNULL(t_SI.cost_local_VAT_incl) - OR t_SI.cost_local_VAT_incl < t_SI.cost_local_VAT_excl - ) - ; - END IF; - -- date_received - IF EXISTS (SELECT * FROM tmp_Stock_Item t_SI WHERE NOT ISNULL(t_SI.date_received) AND t_SI.date_received < t_SI.date_purchased LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following stock item(s) do not have a valid received date: ', GROUP_CONCAT(IFNULL(t_SI.name_error, 'NULL') SEPARATOR ', ')) AS msg - FROM tmp_Stock_Item t_SI - WHERE 1=1 - AND NOT ISNULL(t_SI.date_received) - AND t_SI.date_received < t_SI.date_purchased - ; - END IF; - -- date_unsealed - IF EXISTS (SELECT * FROM tmp_Stock_Item t_SI WHERE NOT ISNULL(t_SI.date_unsealed) AND t_SI.date_unsealed < t_SI.date_purchased LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following stock item(s) do not have a valid unsealed date: ', GROUP_CONCAT(IFNULL(t_SI.name_error, 'NULL') SEPARATOR ', ')) AS msg - FROM tmp_Stock_Item t_SI - WHERE 1=1 - AND NOT ISNULL(t_SI.date_received) - AND t_SI.date_received < t_SI.date_purchased - ; - END IF; - -- date_expiration - IF EXISTS (SELECT * FROM tmp_Stock_Item t_SI WHERE NOT ISNULL(t_SI.date_expiration) AND t_SI.date_expiration < t_SI.date_purchased LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following stock item(s) do not have a valid expiration date: ', GROUP_CONCAT(IFNULL(t_SI.name_error, 'NULL') SEPARATOR ', ')) AS msg - FROM tmp_Stock_Item t_SI - WHERE 1=1 - AND NOT ISNULL(t_SI.date_expiration) - AND t_SI.date_expiration < t_SI.date_purchased - ; - END IF; - -- date_consumed - IF EXISTS (SELECT * FROM tmp_Stock_Item t_SI WHERE NOT ISNULL(t_SI.date_consumed) AND t_SI.date_consumed < t_SI.date_purchased LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following stock item(s) do not have a valid consumed date: ', GROUP_CONCAT(IFNULL(t_SI.name_error, 'NULL') SEPARATOR ', ')) AS msg - FROM tmp_Stock_Item t_SI - WHERE 1=1 - AND NOT ISNULL(t_SI.date_consumed) - AND t_SI.date_consumed < t_SI.date_purchased - ; - END IF; - - -- Permissions - SET v_ids_product_permission := ( SELECT GROUP_CONCAT(t_SI.id_product SEPARATOR ',') FROM tmp_Stock_Item t_SI ); - - IF NOT ISNULL(v_ids_product_permission) THEN - SET v_id_permission_product = (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_PRODUCT' LIMIT 1); - - CALL p_shop_calc_user( - a_guid - , a_id_user - , FALSE -- a_get_inactive_users - , v_id_permission_product - , v_id_access_level_edit - , v_ids_product_permission - , 0 -- a_debug - ); - - UPDATE tmp_Stock_Item t_SI - INNER JOIN Shop_Product P ON t_SI.id_product = P.id_product - INNER JOIN Shop_Calc_User_Temp UE_T - ON P.id_product = UE_T.id_product - AND UE_T.GUID = a_guid - SET - t_SI.can_view = UE_T.can_view - , t_SI.can_edit = UE_T.can_edit - , t_SI.can_admin = UE_T.can_admin - ; - - CALL p_shop_clear_calc_user( - a_guid - , 0 -- a_debug - ); - - IF EXISTS (SELECT * FROM tmp_Stock_Item t_SI WHERE IFNULL(t_SI.can_edit, 0) = 0 LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - guid - , id_type - , code - , msg - ) - SELECT - a_guid AS GUID - , v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following stock item(s) do not have product edit permission: ', GROUP_CONCAT(IFNULL(t_SI.name_error, 'NULL') SEPARATOR ', ')) AS msg - FROM tmp_Stock_Item t_SI - WHERE IFNULL(t_SI.can_edit, 0) = 0 - ; - END IF; - END IF; - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - START TRANSACTION; - - IF NOT ISNULL(v_ids_product_permission) THEN - INSERT INTO Shop_Product_Change_Set ( - comment - , updated_last_by - ) - VALUES ( - a_comment, - a_id_user - ) - ; - - SET v_id_change_set := LAST_INSERT_ID(); - - -- select * from partsltd_prod.Shop_Stock_Item - UPDATE partsltd_prod.Shop_Stock_Item SI - INNER JOIN tmp_Stock_Item t_SI - ON SI.id_stock = t_SI.id_stock - SET - SI.id_permutation = t_SI.id_permutation - , SI.date_purchased = t_SI.date_purchased - , SI.date_received = t_SI.date_received - , SI.id_location_storage = t_SI.id_location_storage - , SI.id_currency_cost = t_SI.id_currency_cost - , SI.cost_local_VAT_excl = t_SI.cost_local_VAT_excl - , SI.cost_local_VAT_incl = t_SI.cost_local_VAT_incl - , SI.is_sealed = t_SI.is_sealed - , SI.date_unsealed = t_SI.date_unsealed - , SI.date_expiration = t_SI.date_expiration - , SI.is_consumed = t_SI.is_consumed - , SI.date_consumed = t_SI.date_consumed - , SI.active = t_SI.active - , SI.id_change_set = v_id_change_set - ; - END IF; - - INSERT INTO partsltd_prod.Shop_Stock_Item ( - id_permutation - , date_purchased - , date_received - , id_location_storage - , id_currency_cost - , cost_local_VAT_excl - , cost_local_VAT_incl - , is_sealed - , date_unsealed - , date_expiration - , is_consumed - , date_consumed - , active - , created_by - , created_on - ) - SELECT - t_SI.id_permutation - , t_SI.date_purchased - , t_SI.date_received - , t_SI.id_location_storage - , t_SI.id_currency_cost - , t_SI.cost_local_VAT_excl - , t_SI.cost_local_VAT_incl - , t_SI.is_sealed - , t_SI.date_unsealed - , t_SI.date_expiration - , t_SI.is_consumed - , t_SI.date_consumed - , t_SI.active - , a_id_user AS created_by - , v_time_start AS created_on - FROM tmp_Stock_Item t_SI - WHERE - is_new = 1 - AND active = 1 - ; - - COMMIT; - END IF; - - START TRANSACTION; - - DELETE FROM partsltd_prod.Shop_Stock_Item_Temp - WHERE GUID = a_guid; - - COMMIT; - - -- Errors - SELECT * - FROM tmp_Msg_Error t_ME - INNER JOIN partsltd_prod.Shop_Msg_Error_Type MET ON t_ME.id_type = MET.id_type - ; - - IF a_debug = 1 THEN - SELECT * from tmp_Stock_Item; - END IF; - - DROP TEMPORARY TABLE IF EXISTS tmp_Stock_Item; - DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error; - - IF a_debug = 1 THEN - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); - END IF; -END // -DELIMITER ; - - -/* - -DELETE FROM Shop_Product_Permutation_Temp -WHERE id_permutation = 1 -; - -INSERT INTO Shop_Product_Permutation_Temp ( - id_permutation, - id_product, - description, - cost_local, - id_currency_cost, - profit_local_min, - latency_manufacture, - id_unit_measurement_quantity, - count_unit_measurement_per_quantity_step, - quantity_min, - quantity_max, - quantity_stock, - is_subscription, - id_unit_measurement_interval_recurrence, - count_interval_recurrence, - id_stripe_product, - does_expire_faster_once_unsealed, - id_unit_measurement_interval_expiration_unsealed, - count_interval_expiration_unsealed, - active, - guid -) -VALUES - ( - 1 -- id_permutation, - , 1 -- id_product, - , 'Good Reddy Teddy' -- description, - , 5.0 -- cost_local, - , 1 -- id_currency_cost, - , 3.0 -- profit_local_min, - , 14 -- latency_manufacture, - , 1 -- id_unit_measurement_quantity, - , 1.0 -- count_unit_measurement_quantity, - , 3.0 -- quantity_min, - , 99.0 -- quantity_max, - , 1.0 -- quantity_stock, - , False -- is_subscription, - , null -- id_unit_measurement_interval_recurrence, - , null -- count_interval_recurrence, - , null -- id_stripe_product, - , False -- does_expire_faster_once_unsealed, - , null -- id_unit_measurement_interval_expiration_unsealed, - , null -- count_interval_expiration_unsealed, - , True -- active, - , 'NIPS' -- guid - ) -; - -select 'Shop_Product_Permutation_Temp before call'; -SELECT * FROM Shop_Product_Permutation_Temp; - -SELECT 'Shop_Product_Permutation before call' AS result_name; -select * FROM Shop_Product_Permutation; - -CALL p_shop_save_product_permutation ( - 1, -- 'auth0|6582b95c895d09a70ba10fef', -- a_id_user - 'Initial data', -- a_comment - 'NIPS' -- a_guid -); - -SELECT 'Shop_Product_Permutation_Temp after call' AS result_name; -select * FROM Shop_Product_Permutation_Temp; - -SELECT 'Shop_Product_Permutation after call' AS result_name; -select * FROM Shop_Product_Permutation; - - -DELETE FROM Shop_Product_Permutation_Temp -WHERE id_permutation = 1; - - -*/ - - - --- File: 7220_p_shop_save_stock_item_test.sql - - --- Clear previous proc -DROP PROCEDURE IF EXISTS partsltd_prod.p_shop_save_stock_item_test; - - -DELIMITER // -CREATE PROCEDURE p_shop_save_stock_item_test () -BEGIN - - DECLARE v_guid BINARY(36); - DECLARE v_time_start TIMESTAMP(6); - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_guid := 'nips'; - - SELECT * - FROM partsltd_prod.Shop_Stock_Item - ; - SELECT * - FROM partsltd_prod.Shop_Stock_Item_Temp - ; - - START TRANSACTION; - - INSERT INTO partsltd_prod.Shop_Stock_Item_Temp ( - id_stock - -- id_category - , id_product - , id_permutation - , id_pairs_variations - -- , has_variations - , date_purchased - , date_received - , id_location_storage - , id_currency_cost - , cost_local_VAT_excl - , cost_local_VAT_incl - , is_sealed - , date_unsealed - , date_expiration - , is_consumed - , date_consumed - , active - , guid - ) - VALUES ( - -1 -- id_stock - -- 1 -- id_category - , 4 -- id_product - , NULL -- id_permutation - , NULL -- id_pairs_variations - -- , FALSE -- 0 -- has_variations - , '2025-09-05 00:00' -- date_purchased - , NULL -- date_received - , 1 -- id_location_storage - , 1 -- id_currency_cost - , 10 -- cost_local_VAT_excl - , 12 -- cost_local_VAT_incl - , 1 -- is_sealed - , NULL -- date_unsealed - , NULL -- date_expiration - , FALSE -- 0 -- is_consumed - , NULL -- date_consumed - , 1 -- active - , v_guid - ); - - COMMIT; - - SELECT * - FROM partsltd_prod.Shop_Stock_Item_Temp - WHERE GUID = v_guid - ; - - CALL partsltd_prod.p_shop_save_Stock_Item ( - 'Test save Stock_Item' -- comment - , v_guid -- guid - , 1 -- id_user - , 0 -- debug - ); - - SELECT * - FROM partsltd_prod.Shop_Stock_Item - ; - SELECT * - FROM partsltd_prod.Shop_Stock_Item_Temp - ; - - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); -END // -DELIMITER ; - -CALL partsltd_prod.p_shop_save_stock_item_test (); - -DELETE FROM partsltd_prod.Shop_Stock_Item_Temp; - -/* -update shop_product p set p.has_variations = 0 where id_product = 4 -DROP TABLE IF EXISTS tmp_Msg_Error; -*/ - --- File: 7221_p_get_many_shop_product_price_and_discount_and_delivery_option.sql --- USE partsltd_prod; - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_get_many_product_price_and_discount_and_delivery_option; - -DELIMITER // -CREATE PROCEDURE p_shop_get_many_product_price_and_discount_and_delivery_option ( - IN a_id_user INT - , IN a_get_all_product_permutation BIT - , IN a_get_inactive_product_permutation BIT - , IN a_ids_product_permutation TEXT - , IN a_get_all_product_price BIT - , IN a_get_inactive_product_price BIT - , IN a_ids_product_price TEXT - , IN a_product_price_min FLOAT - , IN a_product_price_max FLOAT - , IN a_get_all_currency BIT - , IN a_get_inactive_currency BIT - , IN a_ids_currency VARCHAR(4000) - , IN a_get_all_discount BIT - , IN a_get_inactive_discount BIT - , IN a_ids_discount TEXT - , IN a_get_all_delivery_option BIT - , IN a_get_inactive_delivery_option BIT - , IN a_ids_delivery_option TEXT - , IN a_get_all_delivery_region BIT - , IN a_get_inactive_delivery_region BIT - , IN a_ids_delivery_region TEXT - , IN a_debug BIT -) -BEGIN - -- Argument redeclaration - -- Variable declaration - DECLARE v_has_filter_product_permutation BIT; - DECLARE v_has_filter_product_price BIT; - DECLARE v_has_filter_currency BIT; - DECLARE v_has_filter_discount BIT; - DECLARE v_has_filter_delivery_option BIT; - DECLARE v_has_filter_delivery_region BIT; - DECLARE v_guid BINARY(36); - -- DECLARE v_id_user VARCHAR(100); - DECLARE v_ids_permutation_unavailable VARCHAR(4000); - DECLARE v_id_permission_product INT; - DECLARE v_ids_product_permission VARCHAR(4000); - -- DECLARE v_ids_permutation_permission VARCHAR(4000); - DECLARE v_id_access_level_view INT; - -- DECLARE v_now DATETIME; - DECLARE v_id_minimum INT; - DECLARE v_time_start TIMESTAMP(6); - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_guid := UUID(); - SET v_id_access_level_view := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW'); - - - -- Argument validation + default values - SET a_id_user := TRIM(IFNULL(a_id_user, '')); - SET a_get_all_product_permutation := TRIM(IFNULL(a_get_all_product_permutation, 1)); - SET a_get_inactive_product_permutation := TRIM(IFNULL(a_get_inactive_product_permutation, 0)); - SET a_ids_product_permutation := TRIM(IFNULL(a_ids_product_permutation, '')); - SET a_get_all_delivery_region := TRIM(IFNULL(a_get_all_delivery_region, 1)); - SET a_get_inactive_delivery_region := TRIM(IFNULL(a_get_inactive_delivery_region, 0)); - SET a_ids_delivery_region := TRIM(IFNULL(a_ids_delivery_region, '')); - SET a_get_all_currency := TRIM(IFNULL(a_get_all_currency, 1)); - SET a_get_inactive_currency := TRIM(IFNULL(a_get_inactive_currency, 0)); - SET a_ids_currency := TRIM(IFNULL(a_ids_currency, '')); - SET a_get_all_discount := TRIM(IFNULL(a_get_all_discount, 1)); - SET a_get_inactive_discount := TRIM(IFNULL(a_get_inactive_discount, 0)); - SET a_ids_discount := TRIM(IFNULL(a_ids_discount, '')); - SET a_debug := IFNULL(a_debug, 0); - - IF a_debug = 1 THEN - SELECT - a_id_user - , a_get_all_variation_type - , a_get_inactive_variation_type - , a_get_first_variation_type_only - , a_ids_variation_type - , a_get_all_variation - , a_get_inactive_variation - , a_get_first_variation_only - , a_ids_variation - , a_debug - ; - END IF; - - -- Temporary tables - DROP TEMPORARY TABLE IF EXISTS tmp_Discount; - DROP TEMPORARY TABLE IF EXISTS tmp_Currency; - DROP TEMPORARY TABLE IF EXISTS tmp_Delivery_Region; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Image; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Variation; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Product; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Product_2; - DROP TEMPORARY TABLE IF EXISTS tmp_Category; - DROP TEMPORARY TABLE IF EXISTS tmp_Permutation; - DROP TEMPORARY TABLE IF EXISTS tmp_Product; - - CREATE TEMPORARY TABLE tmp_Category ( - id_category INT NOT NULL - , display_order INT NOT NULL - ); - - CREATE TEMPORARY TABLE tmp_Product ( - id_category INT NOT NULL - , id_product INT NOT NULL - , display_order INT NOT NULL - ); - - CREATE TEMPORARY TABLE tmp_Permutation ( - id_permutation INT NULL - , id_product INT NOT NULL - , can_view BIT - , can_edit BIT - , can_admin BIT - ); - - CREATE TEMPORARY TABLE tmp_Price ( - id_price INT - , id_permutation INT - ); - - CREATE TEMPORARY TABLE tmp_Currency ( - id_currency INT NOT NULl - /* - active BIT NOT NULL - display_order INT NOT NULL - */ - ); - - CREATE TEMPORARY TABLE tmp_Discount ( - id_discount INT NOT NULL - /* - active BIT NOT NULL, - display_order INT NOT NULL - */ - ); - - CREATE TEMPORARY TABLE tmp_Delivery_Option ( - id_option INT NOT NULL - /* - active BIT NOT NULL, - display_order INT NOT NULL, - requires_delivery_option BIT NOT NULL DEFAULT 0 - */ - ); - - CREATE TEMPORARY TABLE tmp_Delivery_Region ( - id_region INT NOT NULL - /* - active BIT NOT NULL, - display_order INT NOT NULL, - requires_delivery_option BIT NOT NULL DEFAULT 0 - */ - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - -- guid BINARY(36) NOT NULL, - id_type INT NULL, - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Split ( - substring VARCHAR(4000) NOT NULL - , as_int INT NULL - ); - DELETE FROM tmp_Split; - - - -- Parse filters - SET v_has_filter_product_permutation = CASE WHEN a_ids_product_permutation = '' THEN 0 ELSE 1 END; - SET v_has_filter_product_price = CASE WHEN a_ids_product_price = '' THEN 0 ELSE 1 END; - SET v_has_filter_currency = CASE WHEN a_ids_currency = '' THEN 0 ELSE 1 END; - SET v_has_filter_discount = CASE WHEN a_ids_discount = '' THEN 0 ELSE 1 END; - SET v_has_filter_delivery_option = CASE WHEN a_ids_delivery_option = '' THEN 0 ELSE 1 END; - SET v_has_filter_delivery_region = CASE WHEN a_ids_delivery_region = '' THEN 0 ELSE 1 END; - - IF a_debug = 1 THEN - SELECT - v_has_filter_product_permutation - , v_has_filter_product_price - , v_has_filter_currency - , v_has_filter_discount - , v_has_filter_delivery_option - , v_has_filter_delivery_region - ; - END IF; - - CALL partsltd_prod.p_shop_calc_product_permutation ( - a_id_user - , 1 -- a_get_all_product_category - , 0 -- a_get_inactive_product_category - , '' -- a_ids_product_category - , 1 -- a_get_all_product - , 0 -- a_get_inactive_product - , '' -- a_ids_product - , a_get_all_product_permutation - , a_get_inactive_product_permutation - , a_ids_product_permutation - , 0 - , v_guid -- a_guid - , 0 -- a_debug - ); - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - INSERT INTO tmp_Category ( - id_category - , display_order - ) - SELECT - PC.id_category - , PC.display_order - FROM (SELECT * FROM partsltd_prod.Shop_Product_Category_Temp WHERE GUID = v_guid) PC_T - INNER JOIN partsltd_prod.Shop_Product_Category PC ON PC_T.id_category = PC.id_category - ; - - INSERT INTO tmp_Product ( - id_product - , id_category - , display_order - ) - SELECT - P.id_product - , P.id_category - , P.display_order - FROM (SELECT * FROM partsltd_prod.Shop_Product_Temp WHERE GUID = v_guid) P_T - INNER JOIN partsltd_prod.Shop_Product P ON P.id_product = P_T.id_product - ; - - INSERT INTO tmp_Permutation ( - id_permutation - , id_product - , can_view - , can_edit - , can_admin - ) - SELECT - PP.id_permutation - , PP.id_product - , PP_T.can_view - , PP_T.can_edit - , PP_T.can_admin - FROM (SELECT * FROM partsltd_prod.Shop_Product_Permutation_Temp WHERE GUID = v_guid) PP_T - INNER JOIN partsltd_prod.Shop_Product_Permutation PP ON PP_T.id_permutation = PP.id_permutation - ; - - -- Product Prices - CALL partsltd_prod.p_split(v_guid, a_ids_product_price, ',', a_debug); - - DELETE FROM tmp_Split; - - INSERT INTO tmp_Split ( - substring - , as_int - ) - SELECT - substring - , CONVERT(substring, DECIMAL(10,0)) AS as_int - FROM partsltd_prod.Split_Temp - WHERE 1=1 - AND GUID = v_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( v_guid ); - END IF; - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Product_Price PRICE ON t_S.as_int = PRICE.id_price - WHERE - ISNULL(t_S.as_int) - OR ISNULL(PRICE.id_price) - ) THEN - INSERT INTO tmp_Msg_Error ( - -- guid, - id_type, - code, - msg - ) - SELECT - -- v_guid, - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Invalid or inactive product price IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Product_Price PRICE ON t_S.as_int = PRICE.id_price - WHERE - ISNULL(t_S.as_int) - OR ISNULL(PRICE.id_price) - ; - ELSE - INSERT INTO tmp_Price ( - id_price - , id_permutation - ) - SELECT - PRICE.id_price - , PRICE.id_permutation - FROM tmp_Split t_S - RIGHT JOIN partsltd_prod.Shop_Product_Price PRICE ON t_S.as_int = PRICE.id_price - INNER JOIN tmp_Permutation t_PP ON SI.id_permutation = t_PP.id_permutation - WHERE - ( - a_get_all_stock_item = 1 - OR ( - v_has_filter_stock_item = 1 - AND NOT ISNULL(t_S.as_int) - ) - ) - AND ( - a_get_inactive_stock_item = 1 - OR SI.active = 1 - ) - ; - END IF; - END IF; - - DELETE FROM tmp_Split; - - - INSERT INTO tmp_Shop_Product ( - id_permutation, - active_permutation, - display_order_permutation - ) - SELECT - PP.id_permutation, - PP.active AS active_permutation, - PP.display_order AS display_order_permutation - FROM Shop_Product P - INNER JOIN Shop_Product_Permutation PP - ON P.id_product = PP.id_product - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - WHERE - -- permutations - ( - a_get_all_product_permutation - OR ( - v_has_filter_product_permutation - AND FIND_IN_SET(PP.id_permutation, a_ids_product_permutation) > 0 - ) - OR ( - a_get_products_quantity_stock_below_min = 1 - AND PP.quantity_stock < PP.quantity_min - ) - ) - AND ( - a_get_inactive_product_permutation - OR PP.active - ) - ; - - -- Delivery Regions - INSERT INTO tmp_Delivery_Region ( - id_region, - active, - display_order, - requires_delivery_option - ) - WITH RECURSIVE Recursive_CTE_Delivery_Region AS ( - SELECT - DR.id_region AS id_region_parent, - NULL AS id_region_child, - CASE WHEN FIND_IN_SET(DR.id_region, a_ids_delivery_region) > 0 THEN 1 ELSE 0 END AS requires_delivery_option - FROM Shop_Product_Currency_Region_Link PCRL - INNER JOIN Shop_Currency C ON PCRL.id_currency = C.id_currency - INNER JOIN tmp_Shop_Product t_P - ON PCRL.id_product <=> t_P.id_product - AND PCRL.id_permutation <=> t_P.id_permutation - INNER JOIN Shop_Region DR ON PCRL.id_region_purchase = DR.id_region - WHERE - ( - a_get_all_delivery_region - OR FIND_IN_SET(DR.id_region, a_ids_delivery_region) > 0 - ) - AND ( - a_get_inactive_delivery_region - OR DR.active = 1 - ) - UNION - SELECT - DRB.id_region_parent, - DRB.id_region_child, - 0 AS requires_delivery_option - FROM Shop_Region_Branch DRB - INNER JOIN Recursive_CTE_Delivery_Region r_DR - ON DRB.id_region_parent = r_DR.id_region_child - AND ( - a_get_inactive_delivery_region - OR DRB.active = 1 - ) - ) - SELECT - DR.id_region, - DR.active, - DR.display_order, - requires_delivery_option - FROM Shop_Region DR - INNER JOIN Recursive_CTE_Delivery_Region r_DR - ON DR.id_region = r_DR.id_region_parent - OR DR.id_region = r_DR.id_region_child - ; - /* - select * from tmp_delivery_region; - SELECT * - FROM tmp_Shop_Product t_P - WHERE - *( - a_get_all_category - OR a_get_all_product - OR a_get_all_product_permutation - )* - FIND_IN_SET(t_P.id_category, a_ids_category) > 0 - OR FIND_IN_SET(t_P.id_product, a_ids_product) > 0 - OR FIND_IN_SET(t_P.id_permutation, a_ids_product_permutation) > 0 - ; - */ - - IF v_has_filter_delivery_region THEN - SET v_ids_permutation_unavailable = ( - SELECT GROUP_CONCAT(t_P.id_permutation SEPARATOR ', ') - FROM ( - SELECT * - FROM tmp_Shop_Product t_P - WHERE - /*( - a_get_all_category - OR a_get_all_produc - OR a_get_all_product_permutation - )*/ - FIND_IN_SET(t_P.id_category, a_ids_category) > 0 - OR FIND_IN_SET(t_P.id_product, a_ids_product) > 0 - OR FIND_IN_SET(t_P.id_permutation, a_ids_product_permutation) > 0 - ) t_P - LEFT JOIN ( - SELECT * - FROM Shop_Product_Currency_Region_Link PCRL - WHERE - ( - a_get_all_delivery_region - OR FIND_IN_SET(PCRL.id_region_purchase, a_ids_delivery_region) > 0 - ) - ) PCRL - ON t_P.id_product <=> PCRL.id_product - AND t_P.id_permutation <=> PCRL.id_permutation - LEFT JOIN tmp_Delivery_Region t_DR - ON PCRL.id_region_purchase = t_DR.id_region - AND t_DR.requires_delivery_option = 1 - WHERE - ISNULL(t_DR.id_region) - ); - IF NOT ISNULL(v_ids_permutation_unavailable) THEN - INSERT INTO tmp_Msg_Error ( - guid, - id_type, - code, - msg - ) - VALUES ( - v_guid, - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'PRODUCT_AVAILABILITY' LIMIT 1), - 'PRODUCT_AVAILABILITY', - CONCAT('Error: The following permutation IDs are not available in this region: ', IFNULL(v_ids_permutation_unavailable, 'NULL')) - ); - END IF; - /* - DELETE FROM tmp_Shop_Product t_P - WHERE t_P.id_permutation NOT IN ( - SELECT - id_permutation - FROM Shop_Product_Currency_Region_Link PCL - INNER JOIN tmp_Delivery_Region t_DR - ON PCRL.id_region_purchase = t_DR.id_region - ); - */ - END IF; - - -- select * from tmp_Shop_Product; - - -- Currencies - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid) THEN - INSERT INTO tmp_Currency ( - id_currency, - active, - display_order - ) - SELECT - C.id_currency, - C.active, - C.display_order - FROM Shop_Product_Currency_Region_Link PCRL - INNER JOIN Shop_Currency C ON PCRL.id_currency = C.id_currency - INNER JOIN tmp_Shop_Product t_P - ON PCRL.id_product <=> t_P.id_product - AND PCRL.id_permutation <=> t_P.id_permutation - INNER JOIN tmp_Delivery_Region t_DR ON PCRL.id_region_purchase = t_DR.id_region - WHERE - ( - a_get_all_currency - OR FIND_IN_SET(C.id_currency, a_ids_currency) > 0 - ) - AND ( - a_get_inactive_currency - OR ( - C.active - AND PCRL.active - ) - ) - ; - - -- select * from tmp_Currency; - - IF v_has_filter_currency THEN - SET v_ids_permutation_unavailable = ( - SELECT GROUP_CONCAT(t_P.id_permutation SEPARATOR ', ') - FROM ( - SELECT * - FROM tmp_Shop_Product t_P - WHERE - /*( - a_get_all_category - OR a_get_all_product - OR a_get_all_product_permutation - )*/ - FIND_IN_SET(t_P.id_category, a_ids_category) > 0 - OR FIND_IN_SET(t_P.id_product, a_ids_product) > 0 - OR FIND_IN_SET(t_P.id_permutation, a_ids_product_permutation) > 0 - ) t_P - INNER JOIN ( - SELECT * - FROM Shop_Product_Currency_Region_Link PCRL - WHERE - ( - a_get_all_currency - OR FIND_IN_SET(PCRL.id_currency, a_ids_currency) > 0 - ) - ) PCRL - ON t_P.id_permutation = PCRL.id_permutation - LEFT JOIN tmp_Currency t_C - ON PCRL.id_currency = t_C.id_currency - WHERE ISNULL(t_C.id_currency) - ); - IF NOT ISNULL(v_ids_permutation_unavailable) THEN - INSERT INTO tmp_Msg_Error ( - guid, - id_type, - code, - msg - ) - VALUES ( - v_guid, - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'PRODUCT_AVAILABILITY' LIMIT 1), - 'PRODUCT_AVAILABILITY', - CONCAT('Error: The following permutation IDs are not available in this currency: ', IFNULL(v_ids_permutation_unavailable, 'NULL')) - ); - END IF; - /* - DELETE FROM tmp_Shop_Product t_P - WHERE t_P.id_permutation NOT IN ( - SELECT - id_permutation - FROM Shop_Product_Currency_Region_Link PCL - INNER JOIN tmp_Currency t_C - ON PCRL.id_currency = t_C.id_currency - ); - */ - END IF; - END IF; - - -- Discounts - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid) THEN - INSERT INTO tmp_Discount ( - id_discount, - active, - display_order - ) - SELECT - D.id_discount, - D.active, - D.display_order - FROM Shop_Discount D - INNER JOIN tmp_Shop_Product t_P - ON D.id_product = t_P.id_product - AND D.id_permutation <=> t_P.id_permutation - WHERE - ( - a_get_all_discount - OR FIND_IN_SET(D.id_discount, a_ids_discount) > 0 - ) - AND ( - a_get_inactive_discount - OR D.active - ) - ; - END IF; - -- select 'pre-permission results'; - -- select * from tmp_Shop_Product; - - -- Permissions - IF EXISTS (SELECT * FROM tmp_Shop_Product_Category LIMIT 1) THEN - -- SET v_id_user := (SELECT id_user FROM Shop_User WHERE name = CURRENT_USER()); - SET v_id_permission_product := (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_PRODUCT' LIMIT 1); - SET v_ids_product_permission := (SELECT GROUP_CONCAT(id_product SEPARATOR ',') FROM tmp_Shop_Product WHERE NOT ISNULL(id_product)); - -- SET v_ids_permutation_permission := (SELECT GROUP_CONCAT(id_permutation SEPARATOR ',') FROM tmp_Shop_Product WHERE NOT ISNULL(id_permutation)); - - -- SELECT v_guid, a_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_product_permission; - -- select * from Shop_Calc_User_Temp; - - CALL p_shop_calc_user(v_guid, a_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_product_permission); - - -- select * from Shop_Calc_User_Temp; - - UPDATE tmp_Shop_Product t_P - INNER JOIN Shop_Calc_User_Temp UE_T - ON t_P.id_product = UE_T.id_product - AND UE_T.GUID = v_guid - SET t_P.can_view = UE_T.can_view, - t_P.can_edit = UE_T.can_edit, - t_P.can_admin = UE_T.can_admin - ; - -- select * from Shop_Calc_User_Temp; - -- select * from tmp_Shop_Product; - - DELETE t_P - FROM tmp_Shop_Product t_P - WHERE - FIND_IN_SET(t_P.id_product, (SELECT GROUP_CONCAT(UET.id_product SEPARATOR ',') FROM Shop_Calc_User_Temp UET)) = 0 -- id_product NOT LIKE CONCAT('%', (SELECT GROUP_CONCAT(id_product SEPARATOR '|') FROM Shop_Calc_User_Temp), '%'); - OR ( - ISNULL(t_P.can_view) - AND ( - NOT v_has_filter_category - OR FIND_IN_SET(t_P.id_category, a_ids_category) = 0 - ) - AND ( - NOT v_has_filter_product - OR FIND_IN_SET(t_P.id_product, a_ids_product) = 0 - ) - AND ( - NOT v_has_filter_product_permutation - OR FIND_IN_SET(t_P.id_permutation, a_ids_product_permutation) = 0 - ) - ) - ; - - CALL p_shop_clear_calc_user(v_guid); - -- DROP TABLE IF EXISTS Shop_Calc_User_Temp; - /* - DELETE FROM Shop_Calc_User_Temp UE_T - WHERE UE_T.GUID = v_guid - ; - */ - END IF; - - - -- select * from tmp_Shop_Product; - - -- Returns - -- SET v_now := NOW(); - - -- Categories - SELECT - DISTINCT t_C.id_category, - C.name, - C.description, - C.display_order - FROM tmp_Shop_Product_Category t_C - INNER JOIN Shop_Product_Category C - ON t_C.id_category = C.id_category - INNER JOIN tmp_Shop_Product t_P - ON t_C.id_category = t_P.id_category - ORDER BY C.display_order - ; - - -- Products - SELECT - t_P.id_product, - t_P.id_permutation, - t_P.name, - t_P.description, - P.has_variations, - P.id_category, - PP.cost_local, - PP.id_currency_cost, - CURRENCY.code AS code_currency_cost, - CURRENCY.symbol AS symbol_currency_cost, - PP.profit_local_min, - t_P.latency_manufacture, - t_P.quantity_min, - t_P.quantity_max, - t_P.quantity_step, - t_P.quantity_stock, - t_P.id_stripe_product, - t_P.is_subscription, - UM.name_singular AS name_interval_recurrence, - UM.name_plural AS name_plural_interval_recurrence, - PP.count_interval_recurrence, - t_P.display_order_category, - t_P.display_order_product, - t_P.display_order_permutation, - IFNULL(t_P.can_view, 0) AS can_view, - IFNULL(t_P.can_edit, 0) AS can_edit, - IFNULL(t_P.can_admin, 0) AS can_admin - FROM tmp_Shop_Product t_P - INNER JOIN Shop_Product P ON t_P.id_product = P.id_product - INNER JOIN Shop_Product_Permutation PP ON t_P.id_permutation = PP.id_permutation - -- LEFT JOIN Shop_Interval_Recurrence RI ON t_P.id_unit_measurement_interval_recurrence = RI.id_interval - LEFT JOIN Shop_Unit_Measurement UM ON PP.id_unit_measurement_interval_recurrence = UM.id_unit_measurement - INNER JOIN Shop_Currency CURRENCY ON PP.id_currency_cost = CURRENCY.id_currency - ORDER BY t_P.rank_permutation - ; - - -- Variations - SELECT - V.id_variation - , V.code AS code_variation - , V.name AS name_variation - , V.active AS active_variation - , V.display_order - , V.id_type - , VT.code AS code_variation_type - , VT.name AS name_variation_type - , VT.name_plural AS name_plural_variation_type - , VT.active AS active_variation_type - , VT.display_order - , t_P.id_product - , t_P.id_permutation - , t_P.id_category - FROM Shop_Variation V - INNER JOIN Shop_Variation_Type VT ON V.id_type = VT.id_type - INNER JOIN Shop_Product_Permutation_Variation_Link PPVL ON V.id_variation = PPVL.id_variation - INNER JOIN tmp_Shop_Product t_P ON PPVL.id_permutation <=> t_P.id_permutation - WHERE V.active - AND PPVL.active - ; - - /* - -- Permutation variations output - SELECT t_P.id_permutation, - t_P.id_product, - t_P.id_category, - id_variation - FROM Shop_Product_Permutation_Variation_Link PPVL - INNER JOIN tmp_Shop_Product t_P - ON t_P.id_permutation = PPVL.id_permutation - ORDER BY t_P.display_order - ; - */ - -- select * from Shop_Product_Currency_Region_Link; - -- select * from shop_currency; - /* - select * from tmp_Currency; - select * from tmp_delivery_region; - select * from tmp_shop_product; - */ - - -- Product Price - SELECT - PCRL.id_link AS id_price, - t_P.id_permutation, - t_P.id_product, - t_P.id_category, - t_C.id_currency, - C.code AS code_currency, - C.name AS name_currency, - C.symbol AS symbol_currency, - t_DR.id_region, - PCRL.price_local_VAT_incl, - PCRL.price_local_VAT_excl, - ROW_NUMBER() OVER(ORDER BY t_P.rank_permutation, C.display_order) AS display_order - FROM Shop_Product_Currency_Region_Link PCRL - INNER JOIN tmp_Shop_Product t_P - ON PCRL.id_product <=> t_P.id_product - AND PCRL.id_permutation <=> t_P.id_permutation - -- INNER JOIN Shop_Product P ON PCRL.id_product = P.id_product - INNER JOIN tmp_Currency t_C ON PCRL.id_currency = t_C.id_currency - INNER JOIN Shop_Currency C ON t_C.id_currency = C.id_currency - INNER JOIN tmp_Delivery_Region t_DR ON PCRL.id_region_purchase = t_DR.id_region - WHERE ( - a_get_inactive_product - AND a_get_inactive_product_permutation - AND a_get_inactive_currency - AND a_get_inactive_delivery_region - OR PCRL.active - ) - ORDER BY t_P.rank_permutation - ; - - /* - -- Currency - SELECT - DISTINCT C.id_currency, - C.code, - C.name, - C.factor_from_GBP, - t_C.display_order - FROM Shop_Currency C - INNER JOIN tmp_Currency t_C ON C.id_currency = t_C.id_currency - GROUP BY C.id_currency, t_C.display_order - ORDER BY t_C.display_order - ; - */ - - -- Images - SELECT - t_I.id_image, - t_I.id_product, - t_I.id_permutation, - t_P.id_category, - I.url, - I.active, - I.display_order - FROM tmp_Shop_Image t_I - INNER JOIN Shop_Product_Image I - ON t_I.id_image = I.id_image - INNER JOIN tmp_Shop_Product t_P - ON t_I.id_product = t_P.id_product - AND t_I.id_permutation <=> t_P.id_permutation - ORDER BY t_P.rank_permutation, I.display_order - ; - - -- Delivery options - SELECT - _DO.id_option, - PDOL.id_product, - PDOL.id_permutation, - t_P.id_category, - _DO.code, - _DO.name, - _DO.latency_delivery_min, - _DO.latency_delivery_max, - _DO.quantity_min, - _DO.quantity_max, - GROUP_CONCAT(DR.code SEPARATOR ',') AS codes_region, - GROUP_CONCAT(DR.name SEPARATOR ',') AS names_region, - PDOL.price_local, - PDOL.display_order - FROM Shop_Delivery_Option _DO - INNER JOIN Shop_Product_Permutation_Delivery_Option_Link PDOL - ON _DO.id_option = PDOL.id_delivery_option - AND ( - a_get_inactive_delivery_region - OR PDOL.active - ) - INNER JOIN tmp_Shop_Product t_P - ON PDOL.id_product = t_P.id_product - AND PDOL.id_permutation <=> t_P.id_permutation - INNER JOIN tmp_Delivery_Region t_DR ON PDOL.id_region = t_DR.id_region - INNER JOIN Shop_Region DR ON t_DR.id_region = DR.id_region - WHERE ( - a_get_inactive_delivery_region - OR _DO.active - ) - GROUP BY t_P.id_category, t_P.id_product, PDOL.id_permutation, t_P.rank_permutation, DR.id_region, _DO.id_option, PDOL.id_link - ORDER BY t_P.rank_permutation, PDOL.display_order - ; - - -- Discounts - SELECT - D.id_discount, - P.id_category, - D.id_product, - D.id_permutation, - DR.id_region, - C.id_currency, - D.code AS code_discount, - D.name AS name_discount, - D.multiplier, - D.subtractor, - D.apply_multiplier_first, - D.quantity_min, - D.quantity_max, - D.date_start, - D.date_end, - GROUP_CONCAT(DR.code) AS codes_region, - GROUP_CONCAT(DR.name) AS names_region, - GROUP_CONCAT(C.code) AS codes_currency, - GROUP_CONCAT(C.name) AS names_currency, - ROW_NUMBER() OVER(ORDER BY D.display_order) AS display_order - FROM tmp_Discount t_D - INNER JOIN Shop_Discount D ON t_D.id_discount = D.id_discount - INNER JOIN Shop_Product P ON D.id_product = P.id_product - INNER JOIN tmp_Shop_Product t_P - ON D.id_product = t_P.id_product - -- AND D.id_permutation <=> t_P.id_permutation - INNER JOIN Shop_Discount_Region_Currency_Link DRCL - ON D.id_discount = DRCL.id_discount - INNER JOIN tmp_Delivery_Region t_DR ON DRCL.id_region = t_DR.id_region - INNER JOIN Shop_Region DR ON t_DR.id_region = DR.id_region - INNER JOIN tmp_Currency t_C ON DRCL.id_currency = t_C.id_currency - INNER JOIN Shop_Currency C ON t_C.id_currency = C.id_currency - GROUP BY D.id_discount, DR.id_region, C.id_currency - ORDER BY D.display_order, DR.display_order, C.display_order - ; - - /* - -- Delivery Regions - SELECT - t_DR.id_region, - t_P.id_category, - t_P.id_product, - t_P.id_permutation, - DR.code, - DR.name - FROM tmp_Delivery_Region t_DR - INNER JOIN Shop_Delivery_Region DR ON t_DR.id_region = DR.id_region - INNER JOIN Shop_Product_Region_Currency_Link PDRL - ON DR.id_region = PDRL.id_region - AND ( - a_get_inactive_delivery_region - OR PDRL.active - ) - INNER JOIN tmp_Shop_Product t_P - ON PDRL.id_product = t_P.id_product - AND PDRL.id_permutation <=> t_P.id_permutation - INNER JOIN tmp_Currency t_C ON PDRL.id_currency = t_C.id_currency - ORDER BY t_DR.display_order - ; - */ - - -- Errors - SELECT - * - FROM tmp_Msg_Error t_ME - INNER JOIN Shop_Msg_Error_Type MET ON t_ME.id_type = MET.id_type - -- WHERE guid = v_guid - ; - - - -- Clean up - DROP TEMPORARY TABLE IF EXISTS tmp_Discount; - DROP TEMPORARY TABLE IF EXISTS tmp_Currency; - DROP TEMPORARY TABLE IF EXISTS tmp_Delivery_Region; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Image; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Variation; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Product; - DROP TEMPORARY TABLE IF EXISTS tmp_Product; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Product_2; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Product_Category; - DROP TEMPORARY TABLE IF EXISTS tmp_Category; - DROP TEMPORARY TABLE IF EXISTS tmp_Permutation; - DROP TEMPORARY TABLE IF EXISTS tmp_Product; - - - CALL partsltd_prod.p_shop_clear_calc_product_permutation ( v_guid ); - - IF a_debug = 1 THEN - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); - END IF; -END // -DELIMITER ; - - -/* - -CALL partsltd_prod.p_shop_get_many_product_price_and_discount_and_delivery_option ( - IN a_id_user INT, - IN a_get_all_product_permutation BIT, - IN a_get_inactive_product_permutation BIT, - IN a_ids_product_permutation VARCHAR(4000), - IN a_get_all_delivery_region BIT, - IN a_get_inactive_delivery_region BIT, - IN a_ids_delivery_region VARCHAR(4000), - IN a_get_all_currency BIT, - IN a_get_inactive_currency BIT, - IN a_ids_currency VARCHAR(4000), - IN a_get_all_discount BIT, - IN a_get_inactive_discount BIT, - IN a_ids_discount VARCHAR(4000) -); - -select * FROM Shop_Calc_User_Temp; - -select * from Shop_Product_Permutation; -select * from shop_product_change_set; -insert into shop_product_change_set ( comment ) values ('set stock quantities below minimum for testing'); -update shop_product_permutation -set quantity_stock = 0, - id_change_set = (select id_change_set from shop_product_change_set order by id_change_set desc limit 1) -where id_permutation < 5 - -DROP TABLE IF EXISTS tmp_Msg_Error; - -select * from shop_image; -select * from shop_product; -select * from TMP_MSG_ERROR; -DROP TABLE TMP_MSG_ERROR; - -insert into shop_product_change_set (comment) - values ('set product not subscription - test bool output to python'); - update shop_product - set is_subscription = 0, - id_change_set = (select id_change_set from shop_product_change_set order by id_change_set desc limit 1) - where id_product = 1 - -select * FROM Shop_Calc_User_Temp; -select distinct guid --- DELETE -FROM Shop_Calc_User_Temp; -*/ - - --- File: 7223_p_shop_get_many_stripe_price_new.sql - - - -/* - -CALL p_shop_get_many_stripe_price_new ( - '' -) - -*/ - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_get_many_stripe_price_new; - - -DELIMITER // -CREATE PROCEDURE p_shop_get_many_stripe_price_new ( - IN a_id_user INT -) -BEGIN - DECLARE v_has_filter_user BIT; - DECLARE v_code_error_data VARCHAR(200); - DECLARE v_code_error_permission VARCHAR(200); - DECLARE v_guid BINARY(36); - - SET v_code_error_data := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 1); - SET v_code_error_permission := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 2); - SET v_guid = UUID(); - - - - IF a_id_user IS NULL THEN - SET a_id_user = ''; - ELSE - SET a_id_user = TRIM(a_id_user); - END IF; - - - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Shop_Product_Currency_Link; - DROP TABLE IF EXISTS tmp_Shop_User; - - CREATE TABLE tmp_Shop_User( - id_user INT NOT NULL PRIMARY KEY, - CONSTRAINT FK_tmp_Shop_User_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user), - active BIT NOT NULL - ); - - CREATE TABLE tmp_Shop_Product_Currency_Link ( - id_link INT NOT NULL PRIMARY KEY, - CONSTRAINT FK_tmp_Shop_Product_Currency_Link_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Product_Currency_Link(id_link), - id_product INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_Currency_Link_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - id_permutation INT NULL, - CONSTRAINT FK_tmp_Shop_Product_Currency_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - id_currency INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_Currency_Link_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency), - active BIT NOT NULL - ); - - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( -- IF NOT EXISTS - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - guid BINARY(36) NOT NULL, - code VARCHAR(50) NOT NULL, - -- CONSTRAINT chk_tmp_Msg_Error_code CHECK (code IN (SELECT code FROM Shop_Msg_Error_Type)), - /* - id_type INT NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type(id_type), - */ - msg VARCHAR(4000) NOT NULL - ); - - - - -- Parse filters - SET v_has_filter_user = CASE WHEN a_id_user = '' THEN 0 ELSE 1 END; - - - - -- User permissions - IF v_has_filter_user THEN - INSERT INTO tmp_Shop_User ( - id_user, - active - ) - SELECT id_user, - active - FROM Shop_User - WHERE id_user LIKE CONCAT('%', a_id_user, '%') - AND active - LIMIT 1 - ; - - SET v_has_filter_user = EXISTS (SELECT id_user FROM tmp_Shop_User LIMIT 1); - SET a_id_user := (SELECT id_user FROM tmp_Shop_User LIMIT 1); - END IF; - IF NOT v_has_filter_user THEN - INSERT INTO tmp_Msg_Error ( - guid, - code, - msg - ) - VALUES ( - v_guid, - v_code_error_data, - 'Valid user ID not provided.' - ) - ; - END IF; - - -- Get products - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - INSERT INTO tmp_Shop_Product_Currency_Link ( - id_link, - id_product, - id_permutation, - id_currency, - active - ) - SELECT id_link, - id_product, - id_permutation, - id_currency, - active - FROM Shop_Product_Currency_Link - WHERE ISNULL(id_stripe_price) - AND active - ; - END IF; - - -- Permissions - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - -- SELECT * FROM tmp_Msg_Error LIMIT 1; - CALL p_shop_calc_user ( - v_guid, -- a_guid - a_id_user, -- a_id_user - 0, -- a_get_inactive_users - CONVERT((SELECT id_permission FROM Shop_Permission WHERE 'STORE_ADMIN' = code), CHAR), -- a_ids_permission - (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'ADMIN' AND active), -- a_ids_access_level - (SELECT GROUP_CONCAT(DISTINCT id_product SEPARATOR ',') FROM tmp_Shop_Product_Currency_Link), -- (SELECT DISTINCT id_product FROM tmp_Shop_Product_Currency_Link) calc_PCL) -- a_ids_product - (SELECT GROUP_CONCAT(DISTINCT id_permutation SEPARATOR ',') FROM tmp_Shop_Product_Currency_Link) -- a_ids_permutation - ); - -- SELECT * FROM tmp_Msg_Error LIMIT 1; - - IF EXISTS (SELECT can_admin FROM Shop_Calc_User_Temp WHERE guid = v_guid AND NOT can_admin LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - guid, - code, - msg - ) - VALUES ( - v_guid, - v_code_error_permission, - 'User ID does not have permission to get all new stripe prices.' - ) - ; - END IF; - - DELETE FROM Shop_Calc_User_Temp - WHERE guid = v_guid - ; - END IF; - - - - -- Returns - IF EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - DELETE FROM tmp_Shop_Product_Currency_Link; - END IF; - /* - SELECT * - FROM tmp_Shop_User - ; - */ - - - SELECT t_PCL.id_product, - t_PCL.id_permutation, - P.price_GBP_full * C.factor_from_GBP AS unit_price, - C.code AS code_currency, - P.id_stripe_product, - P.is_subscription, - LOWER(RI.code) AS name_recurring_interval, - P.count_interval_recurrence - FROM tmp_Shop_Product_Currency_Link t_PCL - INNER JOIN Shop_Product P - ON t_PCL.id_product = P.id_product - AND P.active - INNER JOIN Shop_Interval_Recurrence RI - ON P.id_unit_measurement_interval_recurrence = RI.id_interval - AND RI.active - INNER JOIN Shop_Currency C - ON t_PCL.id_currency = C.id_currency - AND C.active - WHERE t_PCL.active - ; - - - -- Errors - SELECT * - FROM tmp_Msg_Error - WHERE guid = v_guid - ; - - - /* - -- Return arguments for test - SELECT - a_id_user - ; - */ - - -- Clean up - DROP TABLE IF EXISTS tmp_Shop_User; - DROP TABLE IF EXISTS tmp_Shop_Product_Currency_Link; -END // -DELIMITER ; - - -/* -CALL p_shop_get_many_stripe_price_new ( - '' -); - -CALL p_shop_get_many_stripe_price_new ( - 'auth0|6582b95c895d09a70ba10fef' -); - -*/ - - --- File: 7312_p_shop_save_user.sql - - -DROP PROCEDURE IF EXISTS p_shop_save_user; - - -DELIMITER // -CREATE PROCEDURE p_shop_save_user ( +CREATE PROCEDURE partsltd_prod.p_ph_save_contact_form ( IN a_comment VARCHAR(500), IN a_guid BINARY(36), IN a_id_user INT, @@ -16359,12 +1590,12 @@ CREATE PROCEDURE p_shop_save_user ( BEGIN DECLARE v_code_type_error_bad_data VARCHAR(100); DECLARE v_id_type_error_bad_data INT; - DECLARE v_id_permission_product INT; - DECLARE v_id_permission_user_admin LONGTEXT; + DECLARE v_id_permission_contact_form_admin INT; + DECLARE v_id_permission_contact_form_new INT; DECLARE v_id_change_set INT; - DECLARE v_id_access_level_edit INT; - DECLARE v_can_admin_user BIT; DECLARE v_time_start TIMESTAMP(6); + DECLARE v_can_admin BIT; + DECLARE v_can_create BIT; DECLARE exit handler for SQLEXCEPTION BEGIN @@ -16377,2644 +1608,706 @@ BEGIN ROLLBACK; CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT + display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT , id_type INT NULL , code VARCHAR(50) NOT NULL , msg VARCHAR(4000) NOT NULL ); + INSERT INTO tmp_Msg_Error ( - id_type + id_type , code , msg ) SELECT - MET.id_type + MET.id_type , @errno , @text - FROM partsltd_prod.Shop_Msg_Error_Type MET + FROM partsltd_prod.CORE_Msg_Error_Type MET WHERE MET.code = 'MYSQL_ERROR' ; + SELECT * FROM tmp_Msg_Error; - DROP TABLE IF EXISTS tmp_Msg_Error; + DROP TABLE IF EXISTS tmp_Msg_Error + ; END; SET v_time_start := CURRENT_TIMESTAMP(6); SET v_code_type_error_bad_data := 'BAD_DATA'; - SET v_id_type_error_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_type_error_bad_data LIMIT 1); - SET v_id_access_level_edit := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'EDIT' LIMIT 1); - SET v_id_permission_user_admin := (SELECT GROUP_CONCAT(id_permission SEPARATOR ',') FROM Shop_Permission WHERE code = 'STORE_USER_ADMIN' LIMIT 1); - CALL p_validate_guid ( a_guid ); + SET v_id_type_error_bad_data := (SELECT id_type FROM partsltd_prod.CORE_Msg_Error_Type WHERE code = v_code_type_error_bad_data LIMIT 1); + SET v_id_permission_contact_form_admin := (SELECT id_permission FROM partsltd_prod.PH_Permission P WHERE P.code = 'CONTACT_FORM_ADMIN' LIMIT 1); + SET v_id_permission_contact_form_new := (SELECT id_permission FROM partsltd_prod.PH_Permission P WHERE P.code = 'CONTACT_FORM_NEW' LIMIT 1); - DROP TABLE IF EXISTS tmp_Msg_Error; - DROP TABLE IF EXISTS tmp_User; + CALL partsltd_prod.p_core_validate_guid ( a_guid ); - CREATE TABLE tmp_User ( - id_user INT NOT NULL - , id_user_auth0 VARCHAR(200) NOT NULL - , firstname VARCHAR(255) - , surname VARCHAR(255) - , email VARCHAR(254) - , is_email_verified BIT NOT NULL - , is_super_user BIT NOT NULL - , id_currency_default INT - , id_region_default INT - , is_included_VAT_default BIT + DROP TABLE IF EXISTS tmp_Contact_Form; + + CREATE TEMPORARY TABLE tmp_Contact_Form ( + id_contact_form INT NOT NULL + , email VARCHAR(255) NOT NULL + , name_contact VARCHAR(255) NOT NULL + , name_company VARCHAR(255) NOT NULL + , message TEXT NOT NULL + , receive_marketing_communications BIT NOT NULL , active BIT NOT NULL - , name_error VARCHAR(1000) - ); - - CREATE TABLE tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - id_type INT NOT NULL, - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL + , name_error VARCHAR(255) + , is_new BIT NOT NULL ); + + CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( + display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT + , id_type INT NULL + , code VARCHAR(50) NOT NULL + , msg VARCHAR(4000) NOT NULL + ); + -- Get data from Temp table - INSERT INTO tmp_User ( - id_user - , id_user_auth0 - , firstname - , surname + INSERT INTO tmp_Contact_Form ( + id_contact_form , email - , is_email_verified - , is_super_user - , id_currency_default - , id_region_default - , is_included_VAT_default + , name_contact + , name_company + , message + , receive_marketing_communications , active + , is_new ) SELECT - U_T.id_user - , U_T.id_user_auth0 - , IFNULL(U_T.firstname, U.firstname) AS firstname - , IFNULL(U_T.surname, U.surname) AS surname - , IFNULL(U_T.email, U.email) AS email - , IFNULL(U_T.is_email_verified, U.is_email_verified) AS is_email_verified - , IFNULL(U_T.is_super_user, U.is_super_user) AS is_super_user - , IFNULL(U_T.id_currency_default, U.id_currency_default) AS id_currency_default - , IFNULL(U_T.id_region_default, U.id_region_default) AS id_region_default - , IFNULL(U_T.is_included_VAT_default, U.is_included_VAT_default) AS is_included_VAT_default - , IFNULL(IFNULL(U_T.active, U.active), 1) AS active - , IFNULL(U_T.display_order, PC.display_order) AS display_order - FROM partsltd_prod.Shop_User_Temp U_T - LEFT JOIN Shop_User U ON U_T.id_user = U.id_user - WHERE U_T.guid = a_guid + CF_T.id_contact_form AS id_contact_form + , IFNULL(CF_T.email, CF.email) AS code + , IFNULL(CF_T.name_contact, CF.name_contact) AS name_contact + , IFNULL(CF_T.name_company, CF.name_company) AS name_company + , IFNULL(CF_T.message, CF.message) AS message + , COALESCE(CF_T.receive_marketing_communications, CF.receive_marketing_communications, 0) AS receive_marketing_communications + , COALESCE(CF_T.active, CF.active, 1) AS active + , CASE WHEN IFNULL(CF_T.id_contact_form, 0) < 1 THEN 1 ELSE 0 END AS is_new + FROM partsltd_prod.PH_Contact_Form_Temp CF_T + LEFT JOIN partsltd_prod.PH_Contact_Form CF ON CF_T.id_contact_form = CF.id_contact_form + WHERE CF_T.guid = a_guid ; - UPDATE tmp_User t_U - SET - t_U.name_error = IFNULL(t_U.email, t_U.id_user_auth0) + UPDATE tmp_Contact_Form t_CF + SET name_error = COALESCE(t_CF.email, t_CF.name_company, t_CF.name_contact, t_CF.message, '(No Contact Form)') ; -- Validation -- Missing mandatory fields -- email - IF EXISTS (SELECT * FROM tmp_User t_U WHERE ISNULL(t_U.email) LIMIT 1) THEN + IF EXISTS (SELECT * FROM tmp_Contact_Form t_CF WHERE ISNULL(t_CF.email) LIMIT 1) THEN INSERT INTO tmp_Msg_Error ( - id_type + id_type , code , msg ) SELECT - v_id_type_error_bad_data + v_id_type_error_bad_data , v_code_type_error_bad_data - , CONCAT('The following User(s) do not have an email: ', GROUP_CONCAT(t_U.name_error SEPARATOR ', ')) AS msg - FROM tmp_User t_U - WHERE ISNULL(t_U.email) + , CONCAT('The following Contact Form(s) do not have an Email: ', GROUP_CONCAT(t_CF.name_error SEPARATOR ', ')) AS msg + FROM tmp_Contact_Form t_CF + WHERE ISNULL(t_CF.email) ; END IF; - -- is_super_user - IF EXISTS (SELECT * FROM tmp_User t_U WHERE ISNULL(t_U.is_super_user) LIMIT 1) THEN + -- name_contact + IF EXISTS (SELECT * FROM tmp_Contact_Form t_CF WHERE ISNULL(t_CF.name_contact) LIMIT 1) THEN INSERT INTO tmp_Msg_Error ( - id_type + id_type , code , msg ) SELECT - v_id_type_error_bad_data + v_id_type_error_bad_data , v_code_type_error_bad_data - , CONCAT('The following User(s) do not have an is super user field: ', GROUP_CONCAT(t_U.name_error SEPARATOR ', ')) AS msg - FROM tmp_User t_U - WHERE ISNULL(t_U.is_super_user) + , CONCAT('The following Contact Form(s) do not have a Contact Name: ', GROUP_CONCAT(t_CF.name_error SEPARATOR ', ')) AS msg + FROM tmp_Contact_Form t_CF + WHERE ISNULL(t_CF.name_contact) ; END IF; - -- is_email_verified - IF EXISTS (SELECT * FROM tmp_User t_U WHERE ISNULL(t_U.is_email_verified) LIMIT 1) THEN + -- name_company + IF EXISTS (SELECT * FROM tmp_Contact_Form t_CF WHERE ISNULL(t_CF.name_company) LIMIT 1) THEN INSERT INTO tmp_Msg_Error ( - id_type + id_type , code , msg ) SELECT - v_id_type_error_bad_data + v_id_type_error_bad_data , v_code_type_error_bad_data - , CONCAT('The following User(s) do not have an is email verified: ', GROUP_CONCAT(t_U.name_error SEPARATOR ', ')) AS msg - FROM tmp_User t_U - WHERE ISNULL(t_U.is_email_verified) + , CONCAT('The following Contact Form(s) do not have a Company Name: ', GROUP_CONCAT(t_CF.name_error SEPARATOR ', ')) AS msg + FROM tmp_Contact_Form t_CF + WHERE ISNULL(t_CF.name) + ; + END IF; + -- message + IF EXISTS (SELECT * FROM tmp_Contact_Form t_CF WHERE ISNULL(t_CF.message) LIMIT 1) THEN + INSERT INTO tmp_Msg_Error ( + id_type + , code + , msg + ) + SELECT + v_id_type_error_bad_data + , v_code_type_error_bad_data + , CONCAT('The following Contact Form(s) do not have a Message: ', GROUP_CONCAT(t_CF.name_error SEPARATOR ', ')) AS msg + FROM tmp_Contact_Form t_CF + WHERE ISNULL(t_CF.message) ; END IF; - -- Permissions IF a_debug = 1 THEN - SELECT - a_guid -- GUID - , a_id_user -- ID User - , FALSE -- get inactive Users - , v_id_permission_user_admin -- IDs Permission - , v_id_access_level_edit -- ID Access Level - , NULL -- IDs Product + SELECT + a_guid + , a_id_user + , FALSE -- a_get_inactive_user + , v_id_permission_contact_form_admin + , v_id_permission_contact_form_new + , 0 -- a_debug ; END IF; - - CALL p_shop_calc_user( - a_guid -- GUID - , a_id_user -- ID User - , FALSE -- get inactive Users - , v_id_permission_user_admin -- IDs Permission - , v_id_access_level_edit -- ID Access Level - , NULL -- IDs Product + + CALL partsltd_prod.p_ph_calc_user( + a_guid + , a_id_user + , FALSE -- a_get_inactive_user + , v_id_permission_contact_form_admin + , 0 -- a_debug ); - - SET v_can_admin_user := ( - SELECT IFNULL(UE_T.can_edit, 0) = 1 - FROM partsltd_prod.Shop_User_Eval_Temp UE_T - WHERE - UE_T.GUID = a_guid - AND UE_T.id_user = a_id_user - AND UE_T.id_permission = v_id_permission_user_admin + + SELECT + IFNULL(CU_T.has_access, 0) + INTO + v_can_admin + FROM partsltd_prod.PH_Calc_User_Temp CU_T + WHERE CU_T.GUID = a_guid + LIMIT 1 + ; + + CALL partsltd_prod.p_ph_clear_calc_user( + a_guid + , 0 -- a_debug + ); + + CALL partsltd_prod.p_ph_calc_user( + a_guid + , a_id_user + , FALSE -- a_get_inactive_user + , v_id_permission_contact_form_new + , 0 -- a_debug ); - - IF (v_can_admin_user = 0 AND EXISTS ( - SELECT * - FROM tmp_User t_U - WHERE - t_U.id_user <> a_id_user - )) THEN - DELETE FROM tmp_Msg_Error; - INSERT INTO tmp_Msg_Error ( - id_type + + SELECT + IFNULL(CU_T.has_access, 0) + INTO + v_can_create + FROM partsltd_prod.PH_Calc_User_Temp CU_T + WHERE CU_T.GUID = a_guid + LIMIT 1 + ; + + CALL partsltd_prod.p_ph_clear_calc_user( + a_guid + , 0 -- a_debug + ); + + IF (v_can_create = 0 AND EXISTS(SELECT * FROM tmp_Contact_Form WHERE is_new = 1)) THEN + DELETE t_ME + FROM tmp_Msg_Error t_ME + WHERE t_ME.id_type <> v_id_type_error_no_permission + ; + INSERT INTO tmp_Msg_Error ( + id_type , code , msg ) VALUES ( - v_id_type_error_no_permission + v_id_type_error_no_permission , v_code_type_error_no_permission - , 'You do not have permission to edit other Users.' - ) + , 'You do not have permission to create new Contact Forms.' + ) ; END IF; - CALL p_shop_clear_calc_user(a_guid); - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - START TRANSACTION; - - INSERT INTO Shop_User_Change_Set ( comment ) - VALUES ( a_comment ) - ; - - SET v_id_change_set := LAST_INSERT_ID(); - - UPDATE Shop_User U - INNER JOIN tmp_User t_U ON U.id_user = t_U.id_user - SET - U.id_user_auth0 = t_U.id_user_auth0 - , U.firstname = t_U.firstname - , U.surname = t_U.surname - , U.email = t_U.email - , U.is_email_verified = t_U.is_email_verified - , U.is_super_user = t_U.is_super_user - , U.id_currency_default = t_U.id_currency_default - , U.id_region_default = t_U.id_region_default - , U.is_included_VAT_default = t_U.is_included_VAT_default - , U.active = t_U.active - , U.id_change_set = v_id_change_set - ; - - COMMIT; + IF (v_can_admin = 0 AND EXISTS(SELECT * FROM tmp_Contact_Form WHERE is_new = 0)) THEN + DELETE t_ME + FROM tmp_Msg_Error t_ME + WHERE t_ME.id_type <> v_id_type_error_no_permission + ; + INSERT INTO tmp_Msg_Error ( + id_type + , code + , msg + ) + VALUES ( + v_id_type_error_no_permission + , v_code_type_error_no_permission + , 'You do not have permission to admin Contact Forms.' + ) + ; END IF; - START TRANSACTION; + IF EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN + IF a_debug = 1 THEN + SELECT * from tmp_Contact_Form; + END IF; + + DELETE FROM tmp_Contact_Form; + END IF; + + IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN + START TRANSACTION; - DELETE FROM Shop_User_Temp - WHERE GUID = a_guid; + INSERT INTO partsltd_prod.PH_Contact_Form_Change_Set ( + comment + , id_user_updated_last_by + , updated_last_on + ) + VALUES ( + a_comment + , a_id_user + , v_time_start + ) + ; + + SET v_id_change_set := LAST_INSERT_ID(); + + UPDATE partsltd_prod.PH_Contact_Form CF + INNER JOIN tmp_Contact_Form t_CF + ON CF.id_contact_form = t_CF.id_contact_form + AND t_CF.is_new = 0 + SET + CF.email = t_CF.email + , CF.name_contact = t_CF.name_contact + , CF.name_company = t_CF.name_company + , CF.message = t_CF.message + , CF.receive_marketing_communications = t_CF.receive_marketing_communications + , CF.active = t_CF.active + , CF.id_change_set = v_id_change_set + ; + + INSERT INTO partsltd_prod.PH_Contact_Form ( + email + , name_contact + , name_company + , message + , receive_marketing_communications + , active + , id_user_created_by + , created_on + ) + SELECT + t_CF.email AS email + , t_CF.name_contact AS name_contact + , t_CF.name_company AS name_company + , t_CF.message AS message + , t_CF.receive_marketing_communications AS receive_marketing_communications + , t_CF.active AS active + , a_id_user AS created_by + , v_time_start AS created_on + FROM tmp_Contact_Form t_CF + WHERE + t_CF.is_new = 1 + AND t_CF.active = 1 + ; + + COMMIT; + END IF; + + START TRANSACTION; + + DELETE FROM partsltd_prod.PH_Contact_Form_Temp + WHERE GUID = a_guid + ; COMMIT; - + -- Errors SELECT * FROM tmp_Msg_Error t_ME - INNER JOIN partsltd_prod.Shop_Msg_Error_Type MET ON t_ME.id_type = MET.id_type + INNER JOIN partsltd_prod.CORE_Msg_Error_Type MET ON t_ME.id_type = MET.id_type ; IF a_debug = 1 THEN - SELECT * from tmp_User; + SELECT * from tmp_Contact_Form; END IF; - DROP TABLE IF EXISTS tmp_Msg_Error; - DROP TABLE IF EXISTS tmp_User; + DROP TEMPORARY TABLE tmp_Contact_Form; + DROP TEMPORARY TABLE tmp_Msg_Error; IF a_debug = 1 THEN - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); + CALL partsltd_prod.p_core_debug_timing_reporting ( v_time_start ); END IF; END // DELIMITER ; +/* +select + * + -- COUNT(*) +-- delete +from partsltd_prod.PH_Contact_Form_Temp +; --- File: 7313_p_get_many_user.sql +CALL partsltd_prod.p_ph_save_product_CFategory ( + 'nipples' + , (SELECT GUID FROM partsltd_prod.PH_Contact_Form_Temp ORDER BY id_temp DESC LIMIT 1) + , 1 + , 1 +); +select + * + -- COUNT(*) +-- delete +from partsltd_prod.PH_Contact_Form_Temp +; --- Clear previous proc -DROP PROCEDURE IF EXISTS p_get_many_user; +*/ +USE partsltd_prod; + +DROP PROCEDURE IF EXISTS partsltd_prod.p_ph_test_save_contact_form; DELIMITER // -CREATE PROCEDURE p_get_many_user ( - IN a_id_user INT - , IN a_id_user_auth0 VARCHAR(200) - , IN a_get_all_user BIT - , IN a_get_inactive_user BIT - , IN a_ids_user LONGTEXT - , IN a_ids_user_auth0 LONGTEXT +CREATE PROCEDURE partsltd_prod.p_ph_test_save_contact_form () +BEGIN + + DECLARE v_guid BINARY(36); + DECLARE v_time_start TIMESTAMP(6); + + SET v_time_start := CURRENT_TIMESTAMP(6); + SET v_guid := 'nipple_ripple_chipple_spittle_pickle'; -- 123456789012345678901234567890123456 + + SELECT 'Start of Test'; + + SELECT * + FROM partsltd_prod.PH_Contact_Form + ; + SELECT * + FROM partsltd_prod.PH_Contact_Form_Temp + ; + + START TRANSACTION; + + INSERT INTO partsltd_prod.PH_Contact_Form_Temp ( + id_contact_form + , email + , name_contact + , name_company + , message + , guid + , active + ) + /* + VALUES ( + -1 -- id_contact_form + , 'edward.middletonsmith@gmail.com' -- email + , 'Teddy' -- name_contact + , 'PARTS Ltd' -- name_company + , 'Sa dude' -- message + , v_guid + ) + */ + VALUES ( + -1 -- id_contact_form + , 'edward.middletonsmith@gmail.com' -- email + , 'Teddy' -- name_contact + , 'PARTS Ltd' -- name_company + , 'hegrodorf is good' -- message + , v_guid + , 1 -- active + ) + ; + + COMMIT; + + SELECT * + FROM partsltd_prod.PH_Contact_Form_Temp + -- WHERE GUID = v_guid + ; + + CALL partsltd_prod.p_ph_save_contact_form ( + 'Test save Contact Form' -- comment + , v_guid -- guid + , 3 -- 1 -- id_user + , 1 -- debug + ); + + SELECT * + FROM partsltd_prod.PH_Contact_Form + ; + SELECT * + FROM partsltd_prod.PH_Contact_Form_Temp + ; + + CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); +END // +DELIMITER ; + + +/* +SELECT 'Before Test'; +SELECT * +FROM partsltd_prod.PH_Contact_Form +; +SELECT * +FROM partsltd_prod.PH_Contact_Form_Temp +; + + +CALL partsltd_prod.p_ph_test_save_contact_form (); + +SELECT 'After Test'; +SELECT * +FROM partsltd_prod.PH_Contact_Form +; +SELECT * +FROM partsltd_prod.PH_Contact_Form_Temp +; + +DELETE FROM partsltd_prod.PH_Contact_Form_Temp; + +DROP TABLE IF EXISTS tmp_Msg_Error; + + +*/ + +USE partsltd_prod; + +DROP PROCEDURE IF EXISTS partsltd_prod.p_ph_get_many_contact_form; + +DELIMITER // +CREATE PROCEDURE partsltd_prod.p_ph_get_many_contact_form ( + IN a_id_user INT + , IN a_get_all_contact_form BIT + , IN a_get_inactive_contact_form BIT + , IN a_ids_contact_form VARCHAR(500) , IN a_debug BIT ) BEGIN - DECLARE v_id_access_level_admin INT; - DECLARE v_id_access_level_view INT; - DECLARE v_id_permission_store_admin INT; - DECLARE v_id_permission_user INT; - DECLARE v_id_permission_user_admin INT; - DECLARE v_ids_permission_required VARCHAR(4000); - DECLARE v_id_minimum INT; - DECLARE v_code_error_bad_data VARCHAR(50); - DECLARE v_id_type_error_bad_data INT; - DECLARE v_has_filter_user BIT; - DECLARE v_has_filter_user_auth0 BIT; + DECLARE v_has_filter_contact_form BIT; DECLARE v_guid BINARY(36); - DECLARE v_rank_max INT; + DECLARE v_id_permission_contact_form_view INT; + DECLARE v_id_minimum INT; DECLARE v_time_start TIMESTAMP(6); - DECLARE v_is_new BIT; + DECLARE v_can_view BIT; SET v_time_start := CURRENT_TIMESTAMP(6); SET v_guid := UUID(); - SET v_id_access_level_admin := (SELECT id_access_level FROM partsltd_prod.Shop_Access_Level WHERE code = 'ADMIN' LIMIT 1); - SET v_id_access_level_view := (SELECT id_access_level FROM partsltd_prod.Shop_Access_Level WHERE code = 'VIEW' LIMIT 1); - SET v_id_permission_store_admin := (SELECT id_permission FROM partsltd_prod.Shop_Permission WHERE code = 'STORE_ADMIN' LIMIT 1); - SET v_id_permission_user := (SELECT id_permission FROM partsltd_prod.Shop_Permission WHERE code = 'STORE_USER' LIMIT 1); - SET v_id_permission_user_admin := (SELECT id_permission FROM partsltd_prod.Shop_Permission WHERE code = 'STORE_USER_ADMIN' LIMIT 1); - SET v_code_error_bad_data := (SELECT code FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1); - SET v_id_type_error_bad_data := (SELECT id_type FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = v_code_error_bad_data LIMIT 1); - SET v_ids_permission_required := CONCAT(v_id_permission_user, ',', v_id_permission_user_admin, ',', v_id_permission_store_admin); - SET v_is_new := FALSE; + SET v_id_permission_contact_form_view := (SELECT id_permission FROM partsltd_prod.PH_Permission WHERE code = 'CONTACT_FORM_ADMIN' LIMIT 1); - SET a_get_all_user := IFNULL(a_get_all_user, 1); - SET a_get_inactive_user := IFNULL(a_get_inactive_user, 0); - -- SET a_get_first_user_only := IFNULL(a_get_first_user_only, 0); - SET a_ids_user := TRIM(IFNULL(a_ids_user, '')); - SET a_ids_user_auth0 := TRIM(IFNULL(a_ids_user_auth0, '')); + SET a_id_user := IFNULL(a_id_user, 0); + SET a_get_all_contact_form := IFNULL(a_get_all_contact_form, 0); + SET a_get_inactive_contact_form := IFNULL(a_get_inactive_contact_form, 0); + SET a_ids_contact_form := TRIM(IFNULL(a_ids_contact_form, '')); SET a_debug := IFNULL(a_debug, 0); IF a_debug = 1 THEN - SELECT - a_id_user - , a_id_user_auth0 - , a_get_all_user - , a_get_inactive_user - -- , a_get_first_user_only - , a_ids_user - , a_ids_user_auth0 - , a_debug - ; - END IF; - - DROP TEMPORARY TABLE IF EXISTS tmp_User; - DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error; - - CREATE TEMPORARY TABLE tmp_User ( - id_user INT NULL - , rank_user INT NULL - , can_admin_store BIT NULL - , can_admin_user BIT NULL - ); - - CREATE TEMPORARY TABLE tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - -- guid BINARY(36) NOT NULL, - id_type INT NOT NULL, - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Split ( - substring VARCHAR(4000) NOT NULL - , as_int INT NULL - ); - - IF ISNULL(a_id_user) AND NOT ISNULL(a_id_user_auth0) THEN - SET a_id_user := (SELECT U.id_user FROM partsltd_prod.Shop_User U WHERE U.id_user_auth0 = a_id_user_auth0 LIMIT 1); -- LIKE CONCAT('%', a_id_user_auth0, '%') LIMIT 1); - END IF; - - IF ISNULL(a_id_user) THEN - IF NOT ISNULL(a_id_user_auth0) THEN - INSERT INTO partsltd_prod.Shop_User ( - id_user_auth0 - , is_super_user - , active - ) - VALUES ( - a_id_user_auth0 - , 0 -- is_super_user - , 1 -- active - ) - ; - SET a_id_user := (SELECT U.id_user FROM partsltd_prod.Shop_User U WHERE U.id_user_auth0 = a_id_user_auth0 LIMIT 1); - SET v_is_new := TRUE; - ELSE - INSERT INTO tmp_Msg_Error ( - id_type, - code, - msg - ) - VALUES ( - v_id_type_error_bad_data, - v_code_error_bad_data, - CONCAT('User ID required for authorisation.') - ) - ; - END IF; - END IF; - - SET v_has_filter_user := CASE WHEN a_ids_user = '' THEN 0 ELSE 1 END; - SET v_has_filter_user_auth0 := CASE WHEN a_ids_user_auth0 = '' THEN 0 ELSE 1 END; - - IF a_debug = 1 THEN - SELECT - v_has_filter_user - , v_has_filter_user_auth0 - ; - END IF; - - -- User IDs - IF (NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) AND v_has_filter_user = 1) THEN - CALL partsltd_prod.p_split(v_guid, a_ids_user, ',', FALSE); - - DELETE FROM tmp_Split; - - INSERT INTO tmp_Split ( - substring - , as_int - ) SELECT - substring - , CONVERT(substring, DECIMAL(10,0)) AS as_int - FROM partsltd_prod.Split_Temp - WHERE 1=1 - AND GUID = v_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( v_guid ); - END IF; - - IF (NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) AND v_has_filter_user = 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_User U ON t_S.as_int = U.id_user - WHERE - ISNULL(t_S.as_int) - OR ISNULL(U.id_user) - ) THEN - INSERT INTO tmp_Msg_Error ( - -- guid, - id_type, - code, - msg - ) - SELECT - -- v_guid, - v_id_type_error_bad_data, - v_code_error_bad_data, - CONCAT('Invalid or inactive User IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_User U ON t_S.as_int = U.id_user - WHERE - ISNULL(t_S.as_int) - OR ISNULL(U.id_user) - ; - ELSE - INSERT INTO tmp_User ( - id_user - , rank_user - ) - SELECT - U.id_user - , RANK() OVER (ORDER BY U.id_user DESC) AS rank_user - FROM tmp_Split t_S - RIGHT JOIN partsltd_prod.Shop_User U ON t_S.as_int = U.id_user - WHERE - ( - a_get_all_user = 1 - OR ( - v_has_filter_user = 1 - AND NOT ISNULL(t_S.as_int) - ) - ) - AND ( - a_get_inactive_user = 1 - OR U.active = 1 - ) - ; - END IF; - END IF; - - -- Auth0 User IDs - IF (NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) AND v_has_filter_user_auth0 = 1) THEN - CALL partsltd_prod.p_split(v_guid, a_ids_user_auth0, ',', FALSE); - - DELETE FROM tmp_Split; - - INSERT INTO tmp_Split ( - substring - ) - SELECT - substring - FROM partsltd_prod.Split_Temp - WHERE 1=1 - AND GUID = v_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( v_guid ); - END IF; - - IF (NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) AND v_has_filter_user_auth0 = 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_User U ON t_S.substring = U.id_user_auth0 - WHERE - ISNULL(t_S.substring) - OR ISNULL(U.id_user_auth0) - ) THEN - INSERT INTO tmp_Msg_Error ( - -- guid, - id_type, - code, - msg - ) - SELECT - -- v_guid, - v_id_type_error_bad_data, - v_code_error_bad_data, - CONCAT('Invalid or inactive Auth0 User IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_User U ON t_S.substring = U.id_user_auth0 - WHERE - ISNULL(t_S.substring) - OR ISNULL(U.id_user_auth0) - ; - ELSE - SET v_rank_max := IFNULL((SELECT rank_user FROM tmp_User ORDER BY rank_user DESC LIMIT 1), 0); - - INSERT INTO tmp_User ( - id_user - , rank_user - ) - SELECT - U.id_user - , v_rank_max + (RANK() OVER (ORDER BY U.id_user DESC)) AS rank_user - FROM tmp_Split t_S - RIGHT JOIN partsltd_prod.Shop_User U ON t_S.substring = U.id_user_auth0 - WHERE - ( - a_get_all_user = 1 - OR ( - v_has_filter_user_auth0 = 1 - AND NOT ISNULL(t_S.substring) - ) - ) - AND ( - a_get_inactive_user = 1 - OR U.active = 1 - ) - ; - END IF; - END IF; - - IF a_debug = 1 THEN - SELECT * FROM tmp_User; - END IF; - - /* - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF a_get_first_user_only THEN - DELETE t_U - FROM tmp_User t_U - WHERE t_U.rank_user > 1 - ; - END IF; - END IF; - */ - - IF a_debug = 1 THEN - SELECT * FROM tmp_User; - END IF; - - -- Can admin store - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF a_debug = 1 THEN - SELECT - v_guid -- guid - , a_id_user -- ids_user - , FALSE -- get_inactive_user - , v_id_permission_store_admin -- ids_permission - , v_id_access_level_admin -- ids_access_level - , '' -- ids_product - , 0 -- a_debug - ; - SELECT * FROM partsltd_prod.Shop_Calc_User_Temp; - END IF; - - CALL partsltd_prod.p_shop_calc_user( - v_guid -- guid - , a_id_user -- ids_user - , FALSE -- get_inactive_user - , v_id_permission_store_admin -- ids_permission - , v_id_access_level_admin -- ids_access_level - , '' -- ids_product - , 0 -- a_debug - ); - - IF a_debug = 1 THEN - SELECT * FROM partsltd_prod.Shop_Calc_User_Temp WHERE GUID = v_guid; - END IF; - - UPDATE tmp_User t_U - INNER JOIN partsltd_prod.Shop_Calc_User_Temp CUT - ON CUT.GUID = v_guid - AND t_U.id_user = CUT.id_user - SET t_U.can_admin_store = CUT.can_admin - ; - - CALL partsltd_prod.p_shop_clear_calc_user( v_guid, FALSE ); - END IF; - - -- Can admin user - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF a_debug = 1 THEN - SELECT - v_guid -- guid - , a_id_user -- ids_user - , FALSE -- get_inactive_user - , v_id_permission_user_admin -- ids_permission - , v_id_access_level_admin -- ids_access_level - , '' -- ids_product - , 0 -- a_debug - ; - SELECT * FROM partsltd_prod.Shop_Calc_User_Temp; - END IF; - - CALL partsltd_prod.p_shop_calc_user( - v_guid -- guid - , a_id_user -- ids_user - , FALSE -- get_inactive_user - , v_id_permission_user_admin -- ids_permission - , v_id_access_level_admin -- ids_access_level - , '' -- ids_product - , 0 -- a_debug - ); - - IF a_debug = 1 THEN - SELECT * FROM partsltd_prod.Shop_Calc_User_Temp WHERE GUID = v_guid; - END IF; - - UPDATE tmp_User t_U - INNER JOIN partsltd_prod.Shop_Calc_User_Temp CUT - ON CUT.GUID = v_guid - AND t_U.id_user = CUT.id_user - SET t_U.can_admin_user = CUT.can_admin - ; - - CALL partsltd_prod.p_shop_clear_calc_user( v_guid, FALSE ); - END IF; - - -- Permissions - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF a_debug = 1 THEN - SELECT - v_guid -- guid - , a_id_user -- ids_user - , FALSE -- get_inactive_user - , v_ids_permission_required -- ids_permission - , v_id_access_level_view -- ids_access_level - , '' -- ids_product - , 0 -- a_debug - ; - SELECT * FROM partsltd_prod.Shop_Calc_User_Temp; - END IF; - - CALL partsltd_prod.p_shop_calc_user( - v_guid -- guid - , a_id_user -- ids_user - , FALSE -- get_inactive_user - , v_ids_permission_required -- ids_permission - , v_id_access_level_view -- ids_access_level - , '' -- ids_product - , 0 -- a_debug - ); - - IF a_debug = 1 THEN - SELECT * FROM partsltd_prod.Shop_Calc_User_Temp WHERE GUID = v_guid; - END IF; - - IF NOT EXISTS ( - SELECT can_view - FROM partsltd_prod.Shop_Calc_User_Temp CUT - WHERE 1=1 - AND CUT.GUID = v_guid - AND can_view = 1 - -- AND FIND_IN_SET(v_ids_permission_required, CUT.id_permission_required) > 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - code, - msg - ) - VALUES ( - v_id_type_error_bad_data, - v_code_error_bad_data, - -- CONCAT('You do not have view permissions for ', (SELECT name FROM partsltd_prod.Shop_Permission WHERE id_permission = v_id_permission_user LIMIT 1)) - -- CONCAT('You do not have view permissions for ', (SELECT GROUP_CONCAT(name SEPARATOR ', ') FROM partsltd_prod.Shop_Permission WHERE FIND_IN_SET(v_id_permission_user, id_permission) > 0)) - CONCAT('You do not have view permissions for ', (SELECT name FROM partsltd_prod.Shop_Permission P INNER JOIN partsltd_prod.Shop_Calc_User_Temp CUT ON P.id_permission = CUT.id_permission_required WHERE GUID = v_guid AND IFNULL(can_view, 0) = 0 LIMIT 1)) -- WHERE IFNULL(CUT.can_view, 0) = 0 - ) - ; - ELSE - -- INSERT INTO - SET a_debug := a_debug; - END IF; - - CALL partsltd_prod.p_shop_clear_calc_user( v_guid, FALSE ); - END IF; - - - -- Returns - /* NULL record required for flask sql_alchemy to detect result set */ - IF EXISTS (SELECT * FROM tmp_Msg_Error) THEN - DELETE FROM tmp_User; - INSERT INTO tmp_User ( id_user ) - VALUES ( NULL ); - END IF; - - - SELECT - U.id_user - , U.id_user_auth0 - , U.firstname - , U.surname - , U.email - , U.is_email_verified - , U.id_currency_default - , U.id_region_default - , U.is_included_VAT_default - , U.is_super_user - , t_U.can_admin_store - , t_U.can_admin_user - , v_is_new AS is_new - FROM tmp_User t_U - INNER JOIN partsltd_prod.Shop_User U ON t_U.id_user = U.id_user - ; - - -- Errors - SELECT - t_ME.display_order, - MET.code, - t_ME.msg, - MET.name, - MET.description - FROM tmp_Msg_Error t_ME - INNER JOIN partsltd_prod.Shop_Msg_Error_Type MET - ON t_ME.id_type = MET.id_type - ; - - - IF a_debug = 1 THEN - SELECT * FROM tmp_User; - END IF; - - -- Clean up - DROP TEMPORARY TABLE IF EXISTS tmp_User; - DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error; - - /* - DELETE FROM partsltd_prod.Shop_Calc_User_Temp - WHERE GUID = v_guid; - */ - - IF a_debug = 1 THEN - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); - END IF; -END // -DELIMITER ; - - - -/* -CALL p_get_many_user ( - NULL - , 'google-oauth2|109567376920138999933' - , False - , False - -- , False - , NULL - , 'google-oauth2|109567376920138999933' - , 0 -); - NULL -- a_id_user - , 'auth0|6582b95c895d09a70ba10fef' -- a_id_user_auth0 - , 0 -- a_get_all_user - , 0 -- a_get_inactive_user - -- , 0 -- a_get_first_user_only - , NULL -- a_ids_user - , 'auth0|6582b95c895d09a70ba10fef' -- a_ids_user_auth0 - , 0 -- a_debug -);*/ - -/* -select * FROM partsltd_prod.Shop_Calc_User_Temp; -delete FROM partsltd_prod.Shop_Calc_User_Temp; - -SELECT * -FROM partsltd_prod.Shop_USER; - -CALL p_get_many_user( - NULL -- :a_id_user, - , 'auth0|6582b95c895d09a70ba10fef' -- :a_id_user_auth0, - , 1 -- :a_get_all_user, - , 0 -- :a_get_inactive_user, - -- , 0 -- :a_get_first_user_only, - , NULL -- :a_ids_user, - , 'auth0|6582b95c895d09a70ba10fef' -- :a_ids_user_auth0 -); - -*/ - - --- File: 7321_p_shop_save_user_basket.sql - - - -/* - -CALL p_shop_edit_user_basket ( - '', -- a_id_user - '', -- a_ids_permutation_basket - '', -- a_quantities_permutation_basket - 1, -- a_id_permutation_edit - NULL, -- a_quantity_permutation_edit - 1, -- a_sum_not_edit - 1, -- a_id_currency_edit - 1 -- a_id_region_purchase -) - -*/ - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_edit_user_basket; - - -DELIMITER // -CREATE PROCEDURE p_shop_edit_user_basket ( - IN a_id_user INT, - IN a_ids_permutation_basket VARCHAR(4000), - IN a_quantities_permutation_basket VARCHAR(4000), - IN a_id_permutation_edit INT, - IN a_quantity_permutation_edit INT, - IN a_sum_not_edit BIT, - IN a_id_currency INT, - IN a_id_region_purchase INT -) -BEGIN - -- Argument redeclaration - -- Variable declaration - DECLARE v_has_filter_user BIT; - DECLARE v_has_filter_permutation_basket BIT; - DECLARE v_has_filter_permutation_edit BIT; - DECLARE v_has_filter_region BIT; - DECLARE v_has_filter_currency BIT; - DECLARE v_n_id_permutation_basket INT; - DECLARE v_n_quantity_permutation_basket INT; - DECLARE v_row_number INT; - DECLARE v_guid BINARY(36); - -- DECLARE v_id_user VARCHAR(100); - DECLARE v_id_permission_product INT; - DECLARE v_ids_permutation_permission VARCHAR(4000); - DECLARE v_now DATETIME; - -- DECLARE v_quantity_new INT; - DECLARE v_change_set_used BIT; - DECLARE v_id_change_set INT; - - SET v_guid = UUID(); - - -- Argument validation + default values - IF a_id_user IS NULL THEN - SET a_id_user = ''; - ELSE - SET a_id_user = TRIM(a_id_user); - END IF; - IF a_ids_permutation_basket IS NULL THEN - SET a_ids_permutation_basket = ''; - ELSE - SET a_ids_permutation_basket = TRIM(a_ids_permutation_basket); - END IF; - IF a_quantities_permutation_basket IS NULL THEN - SET a_quantities_permutation_basket = ''; - ELSE - SET a_quantities_permutation_basket = TRIM(a_quantities_permutation_basket); - END IF; - IF a_sum_not_edit IS NULL THEN - SET a_sum_not_edit = 1; - END IF; - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Msg_Error; - DROP TABLE IF EXISTS tmp_Shop_Basket; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Quantity; - DROP TABLE IF EXISTS tmp_Shop_Product; - DROP TABLE IF EXISTS tmp_Shop_User; - - CREATE TABLE tmp_Shop_User ( - id_user INT NOT NULL, - CONSTRAINT FK_tmp_Shop_User_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user), - active BIT NOT NULL - ); - - CREATE TABLE tmp_Shop_Product ( - id_product INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - id_permutation INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - display_order INT NOT NULL, - active INT NOT NULL DEFAULT 1 - ); - - CREATE TEMPORARY TABLE tmp_Shop_Quantity( - quantity INT NOT NULL, - display_order INT NOT NULL, - active INT NOT NULL DEFAULT 1 - ); - - CREATE TABLE tmp_Shop_Basket ( - id_category INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Basket_id_category - FOREIGN KEY (id_category) - REFERENCES Shop_Product_Category(id_category), - id_product INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Basket_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - id_permutation INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Basket_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - id_region_purchase INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Basket_id_region_purchase - FOREIGN KEY (id_region_purchase) - REFERENCES Shop_Region(id_region), - id_currency INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Basket_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency), - quantity INT NOT NULL, - active BIT NOT NULL DEFAULT 1 - /* - display_order_category INT NOT NULL, - display_order_product INT NOT NULL - */ - ); - - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - guid BINARY(36) NOT NULL, - id_type INT NOT NULL, - -- code VARCHAR(50) NOT NULL, - -- CONSTRAINT chk_tmp_Msg_Error_code CHECK (code IN (SELECT code FROM Shop_Msg_Error_Type)), - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type(id_type), - msg VARCHAR(4000) NOT NULL - ); - - - -- Parse filters - SET v_has_filter_user = NOT (a_id_user = ''); - SET v_has_filter_permutation_basket = NOT (a_ids_permutation_basket = ''); - SET v_has_filter_permutation_edit = NOT ISNULL(a_id_permutation_edit); - SET v_has_filter_currency = NOT ISNULL(a_id_currency); - SET v_has_filter_region = NOT ISNULL(a_id_region_purchase); - -- SET v_quantity_new = CASE WHEN a_sum_not_edit THEN quantity + a_quantity_product_edit ELSE a_quantity_product_edit END; - /* - SELECT v_has_filter_user, v_has_filter_basket - ; - - */ - - -- Currency - IF NOT v_has_filter_currency THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - 'Currency ID not provided.' - ) + a_id_user + , a_get_all_contact_form + , a_get_inactive_contact_form + , a_ids_contact_form + , a_debug ; END IF; - IF v_has_filter_currency AND NOT EXISTS ( SELECT * FROM Shop_Currency WHERE id_currency = a_id_currency) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('Currency ID not found: ', a_id_currency, '.') - ) - ; - END IF; - - -- Region - IF NOT v_has_filter_region THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - 'Region ID not provided.' - ) - ; - END IF; - IF v_has_filter_region AND NOT EXISTS ( SELECT * FROM Shop_Region WHERE id_region = a_id_region_purchase) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('Region ID not found: ', a_id_region_purchase, '.') - ) - ; - END IF; - - -- User - IF v_has_filter_user THEN - INSERT INTO tmp_Shop_User ( - id_user, - active - ) - SELECT id_user, - active - FROM Shop_User - WHERE id_user LIKE CONCAT('%', a_id_user, '%') - AND active - LIMIT 1 - ; - - IF NOT EXISTS (SELECT id_user FROM tmp_Shop_User LIMIT 1) THEN - SET v_has_filter_user = 0; - - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('User ID not found: ', a_id_user, '.') - ) - ; - END IF; - - SET a_id_user := (SELECT id_user FROM tmp_Shop_User LIMIT 1); - END IF; - - IF v_has_filter_user AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - SET v_change_set_used = 0; - INSERT INTO Shop_User_Change_Set ( - comment - ) - VALUES ( - 'edit basket' - ); - SET v_id_change_set := (SELECT id_change_set FROM Shop_User_Change_Set ORDER BY id_change_set DESC LIMIT 1); - END IF; - - -- Get basket - -- User - IF v_has_filter_user AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - INSERT INTO tmp_Shop_Basket ( - id_category, - id_product, - id_permutation, - id_region_purchase, - id_currency, - quantity, - active - /* - display_order_category, - display_order_product - */ - ) - SELECT - C.id_category, - UB.id_product, - UB.id_permutation, - UB.id_region_purchase, - UB.id_currency, - UB.quantity, - UB.active - /* - C.display_order, - P.display_order - */ - FROM Shop_User_Basket UB - /* - INNER JOIN tmp_Shop_User t_U - ON UB.id_user = t_U.id_user - */ - INNER JOIN Shop_Product_Permutation PP - ON UB.id_product = PP.id_product - AND PP.active - INNER JOIN Shop_Product P - ON PP.id_product = P.id_product - AND P.active - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - AND C.active - WHERE UB.id_user = a_id_user - ; - END IF; - - -- Currency - IF EXISTS (SELECT * FROM tmp_Shop_Basket WHERE active LIMIT 1) - AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - IF EXISTS (SELECT * FROM tmp_Shop_Basket WHERE active AND id_currency != a_id_currency) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT( - 'Currency ID does not match currency of other items in basket. Basket currency: ', - (SELECT code FROM Shop_Currency WHERE id_currency = ( - SELECT - id_currency - FROM tmp_Shop_Basket - WHERE active - AND id_currency != a_id_currency - LIMIT 1 - )), - ', new currency: ', - (SELECT code FROM Shop_Currency WHERE id_currency = a_id_currency), - '.' - ) - ) - ; - END IF; - END IF; - - -- Region - IF EXISTS (SELECT * FROM tmp_Shop_Basket WHERE active LIMIT 1) - AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Shop_Basket - WHERE - active - AND id_region_purchase != a_id_region_purchase - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('Purchase region ID does not match region of other items in basket. Basket currency: ', - (SELECT code FROM Shop_Region WHERE id_region = ( - SELECT - id_region_purchase - FROM tmp_Shop_Basket - WHERE active - AND id_region != a_id_region_purchase - LIMIT 1 - )), - ', new currency: ', - (SELECT code FROM Shop_Region WHERE id_region = a_id_region_purchase), - '.' - ) - ) - ; - END IF; - END IF; - - -- String product id, permutation id, quantity list - IF NOT EXISTS (SELECT * FROM tmp_Shop_Basket WHERE active LIMIT 1) AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN -- NOT v_has_filter_user AND - -- Get product ids - CALL p_split(v_guid, a_ids_permutation_basket, ','); - INSERT INTO tmp_Shop_Product ( - id_product, id_permutation, display_order - ) - SELECT PP.id_product, ST.substring, ST.display_order - FROM Split_Temp ST - INNER JOIN Shop_Product_Permutation PP - ON ST.substring = PP.id_permutation - -- AND PP.active - ; - /* - SELECT substring as id_product, display_order - FROM Split_Temp - ; - */ - DROP TABLE Split_Temp; - - -- Get product quantities - CALL p_split(v_guid, a_quantities_permutation_basket, ','); - INSERT INTO tmp_Shop_Quantity ( - quantity, display_order - ) - SELECT substring, display_order - FROM Split_Temp - ; - /* - SELECT substring AS quantity_product, display_order - FROM Split_Temp - ; - */ - DROP TABLE Split_Temp; - - -- Compare number of product ids to number of quantities - SET v_n_id_permutation_basket := (SELECT display_order FROM tmp_Shop_Product ORDER BY display_order DESC LIMIT 1); - SET v_n_quantity_permutation_basket := (SELECT display_order FROM tmp_Shop_Quantity ORDER BY display_order DESC LIMIT 1); - IF NOT v_n_id_permutation_basket = v_n_quantity_permutation_basket THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('Number of permutations (', v_n_id_permutation_basket, ') does not equal number of quantities (', v_n_quantity_permutation_basket, ') for basket.') - ) - ; - ELSE - INSERT INTO tmp_Shop_Basket ( - id_category, - id_product, - id_permutation, - id_region_purchase, - id_currency, - quantity - ) - SELECT - C.id_category, - P.id_product, - t_P.id_permutation, - a_id_region_purchase, - a_id_currency, - t_Q.quantity - FROM tmp_Shop_Product t_P - INNER JOIN tmp_Shop_Quantity t_Q - ON t_P.display_order = t_Q.display_order - INNER JOIN Shop_Product_Permutation PP - ON t_P.id_permutation = PP.id_permutation - AND PP.active - INNER JOIN Shop_Product P - ON PP.id_product = P.id_product - AND P.active - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - AND C.active - -- RIGHT JOIN tmp_Shop_Basket t_UB ON ISNULL(t_UB.id_product) - -- WHERE t_P.id_product NOT IN (SELECT id_product FROM tmp_Shop_Basket) - ; - - /* - IF EXISTS( - SELECT * - FROM Shop_Product P - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - INNER JOIN tmp_Shop_Basket t_B - ON P.id_product = t_B.id_product - WHERE C.active = 0 OR P.active = 0 LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('No valid product IDs in list: ', a_ids_permutation_basket, '.') - ) - ; - END IF; - */ - END IF; - END IF; - - /* - select v_has_filter_edit; - select * from tmp_Shop_Basket; - select * from tmp_Msg_Error; - */ - - - -- Edit basket product - IF v_has_filter_permutation_edit AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM Shop_Product_Permutation PP - INNER JOIN Shop_Product P - ON PP.id_product = P.id_product - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - WHERE - ( - C.active = 0 - OR P.active = 0 - OR PP.active = 0 - ) - AND PP.id_permutation = a_id_permutation_edit - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('Invalid product ID to edit: ', a_id_product_edit, '.') - ) - ; - END IF; - END IF; - IF v_has_filter_permutation_edit AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Shop_Basket - WHERE - id_permutation = a_id_permutation_edit - ) THEN - UPDATE tmp_Shop_Basket - SET quantity = CASE WHEN a_sum_not_edit = 1 THEN IFNULL(quantity, 0) + a_quantity_permutation_edit ELSE a_quantity_permutation_edit END, - active = CASE WHEN CASE WHEN a_sum_not_edit = 1 THEN IFNULL(quantity, 0) + a_quantity_permutation_edit ELSE a_quantity_permutation_edit END = 0 THEN 0 ELSE 1 END - WHERE id_permutation = a_id_permutation_edit - ; - - IF EXISTS ( - SELECT * - FROM tmp_Shop_Basket t_B - WHERE t_B.quantity < 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - 'Invalid basket quantity.' - ) - ; - END IF; - - IF v_has_filter_user AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - SET v_change_set_used = 1; - - UPDATE Shop_User_Basket UB - INNER JOIN tmp_Shop_Basket t_UB - ON UB.id_permutation = a_id_permutation_edit - SET UB.quantity = t_UB.quantity, - UB.active = t_UB.active, - UB.id_change_set_user = v_id_change_set - WHERE UB.id_permutation = a_id_permutation_edit - AND id_user = a_id_user - ; - END IF; - ELSE - IF a_quantity_permutation_edit < 0 THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - 'Invalid basket quantity.' - ) - ; - ELSE - INSERT INTO tmp_Shop_Basket ( - id_category, - id_product, - id_permutation, - id_region_purchase, - id_currency, - quantity, - active - ) - SELECT - P.id_category, - P.id_product, - PP.id_permutation, - a_id_region_purchase, - a_id_currency, - a_quantity_permutation_edit, - CASE WHEN a_quantity_permutation_edit > 0 THEN 1 ELSE 0 END - FROM Shop_Product_Permutation PP - INNER JOIN Shop_Product P - ON PP.id_product = P.id_product - WHERE id_permutation = a_id_permutation_edit - ; - IF v_has_filter_user THEN - IF EXISTS ( - SELECT * - FROM Shop_User_Basket UB - WHERE - UB.id_permutation = a_id_permutation_edit - ) THEN - SET v_change_set_used = 1; - - UPDATE Shop_User_Basket - INNER JOIN tmp_Shop_Basket t_UB ON UB.id_permutation = t_UB.id_permutation - SET UB.quantity = t_UB.quantity, - UB.active = t_UB.active, - UB.id_change_set_user = v_id_change_set - WHERE UB.id_permutation = a_id_permutation_edit - AND id_user = a_id_user - ; - ELSE - INSERT INTO Shop_User_Basket ( - id_user, - id_product, - id_permutation, - id_region_purchase, - id_currency, - quantity, - active - ) - SELECT a_id_user, - t_UB.id_product, - t_UB.id_permutation, - t_UB.id_region_purchase, - t_UB.id_currency, - t_UB.quantity, - t_UB.active - FROM tmp_Shop_Basket t_UB - WHERE id_permutation = a_id_permutation_edit - ; - END IF; - END IF; - END IF; - END IF; - END IF; - - - -- Checks - /* - SELECT * FROM tmp_Shop_Basket; - SELECT - GROUP_CONCAT(t_UB.id_product SEPARATOR ',') AS basket_product_ids - FROM tmp_Shop_Basket t_UB - -- WHERE ISNULL(t_UB.id_permutation) - ; - SELECT - GROUP_CONCAT(t_UB.id_permutation SEPARATOR ',') AS basket_permutation_ids - FROM tmp_Shop_Basket t_UB - WHERE NOT ISNULL(t_UB.id_permutation) - ; - */ - -- Returns - CALL p_shop_get_many_product ( - a_id_user, -- a_id_user - 1, -- a_get_all_categories - '', -- a_ids_category - 0, -- a_get_inactive_categories - 0, -- a_get_all_products - ( - SELECT - GROUP_CONCAT(t_B.id_product SEPARATOR ',') - FROM tmp_Shop_Basket t_B - WHERE active = 1 - ), -- a_ids_product - 0, -- a_get_inactive_products - 0, -- a_get_first_product_only - 0, -- a_get_all_product_permutations - ( - SELECT - GROUP_CONCAT(t_B.id_permutation SEPARATOR ',') - FROM tmp_Shop_Basket t_B - WHERE NOT ISNULL(t_B.id_permutation) - AND active = 1 - ), -- a_ids_permutation - 0, -- a_get_inactive_permutations - 0, -- a_get_all_images - '', -- a_ids_image - 0, -- a_get_inactive_images - 1, -- a_get_first_image_only - 0, -- a_get_all_delivery_region - a_id_region_purchase, -- a_ids_delivery_region - 0, -- a_get_inactive_delivery_region - 0, -- a_get_all_currency - a_id_currency, -- a_ids_currency - 0, -- a_get_inactive_currency - 1, -- a_get_all_discount - '', -- a_ids_discount - 0 -- a_get_inactive_discount - ); - - -- Basket - SELECT t_UB.id_category, - t_UB.id_product, - t_UB.id_permutation, - P.name, - PCL.price_local_VAT_incl, - PCL.price_local_VAT_excl, - PCL.id_currency, - t_UB.quantity - FROM tmp_Shop_Basket t_UB - INNER JOIN Shop_Product_Permutation PP - ON t_UB.id_permutation = PP.id_permutation - INNER JOIN Shop_Product P - ON PP.id_product = P.id_product - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - INNER JOIN Shop_Product_Currency_Link PCL - ON PP.id_permutation = PCL.id_permutation - AND PCL.id_region_purchase = a_id_region_purchase - AND PCL.id_currency = a_id_currency - WHERE t_UB.active = 1 - ORDER BY C.display_order, P.display_order - ; - - -- Errors - /* Completed by product get many */ - SELECT - t_ME.display_order, - t_ME.guid, - t_ME.id_type, - t_ME.msg, - MET.code, - MET.name, - MET.description - FROM tmp_Msg_Error t_ME - INNER JOIN Shop_Msg_Error_Type MET - ON t_ME.id_type = MET.id_type - WHERE GUID = v_guid - ; - - /* - -- Return arguments for test - SELECT - a_ids_category, - a_get_inactive_categories, - a_ids_product, - a_get_inactive_products, - a_get_first_product_only, - a_get_all_products, - a_ids_image, - a_get_inactive_images, - a_get_first_image_only, - a_get_all_images - ; - */ - - -- Clean up - IF NOT v_change_set_used THEN - DELETE FROM Shop_User_Change_Set - WHERE id_change_set = v_id_change_set - ; - END IF; - - -- DROP TABLE IF EXISTS tmp_Msg_Error; - DELETE FROM tmp_Msg_Error WHERE guid = v_guid; - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - DROP TABLE tmp_Msg_Error; - END IF; - DROP TABLE IF EXISTS tmp_Shop_Basket; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Quantity; - DROP TABLE IF EXISTS tmp_Shop_Product; - DROP TABLE IF EXISTS tmp_Shop_User; -END // -DELIMITER ; - -/* - -CALL p_shop_edit_user_basket ( - '', -- a_id_user - '', -- a_ids_permutation_basket - '', -- a_quantities_permutation_basket - 2, -- a_id_permutation_edit - 1, -- a_quantity_permutation_edit - 1, -- a_sum_not_edit - 2, -- a_id_currency_edit - 1 -- a_id_region_purchase -); - -CALL p_shop_edit_user_basket ( - '', -- a_id_user - '1', -- a_ids_permutation_basket - '9', -- a_quantities_permutation_basket - 1, -- a_id_permutation_edit - 69, -- a_quantity_permutation_edit - 1, -- a_sum_not_edit - 1, -- a_id_currency_edit - 1 -- a_id_region_purchase -); -CALL p_shop_edit_user_basket ( - 'auth0|6582b95c895d09a70ba10feF', -- a_id_user - '2', -- a_ids_permutation_basket - '7', -- a_quantities_permutation_basket - 2, -- a_id_permutation_edit - NULL, -- a_quantity_permutation_edit - 1, -- a_sum_not_edit - 1, -- a_id_currency_edit - 1 -- a_id_region_purchase -); - - - {'a_id_user': 'auth0|6582b95c895d09a70ba10fef', - 'a_ids_permutation_basket': '1', - '7', -- a_quantities_permutation_basket - 'a_id_permutation_edit': 1, - 'a_quantity_permutation_edit': 1, - 'a_sum_not_edit': 1} - - select * from shop_user_basket; - insert into shop_user_change_set (comment) - values( 'deactivate duplicates'); - update SHOP_USER_BASKET - set active = 0, - id_change_set_user = (select id_change_set from shop_user_change_set order by id_change_set desc limit 1) - where id_user = 'auth0|6582b95c895d09a70ba10fef' - and id_product = 1 - ; - select * from shop_user_basket; -*/ - - --- File: 7400_p_shop_save_supplier.sql - - - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_save_supplier; - - -DELIMITER // -CREATE PROCEDURE p_shop_save_supplier ( - IN a_comment VARCHAR(500) - , IN a_guid BINARY(36) - , IN a_id_user INT - , IN a_debug BIT -) -BEGIN - DECLARE v_code_type_error_bad_data VARCHAR(50); - DECLARE v_code_type_error_no_permission VARCHAR(50); - DECLARE v_id_access_level_edit INT; - DECLARE v_id_change_set INT; - DECLARE v_id_permission_supplier INT; - DECLARE v_id_type_error_bad_data INT; - DECLARE v_id_type_error_no_permission INT; - DECLARE v_time_start TIMESTAMP(6); - - DECLARE exit handler for SQLEXCEPTION - BEGIN - GET DIAGNOSTICS CONDITION 1 - @sqlstate = RETURNED_SQLSTATE - , @errno = MYSQL_ERRNO - , @text = MESSAGE_TEXT - ; - - ROLLBACK; - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT - , id_type INT NULL - , code VARCHAR(50) NOT NULL - , msg VARCHAR(4000) NOT NULL - ); - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - id_type - , @errno - , @text - FROM partsltd_prod.Shop_Msg_Error_Type MET - WHERE code = 'MYSQL_ERROR' - ; - SELECT * - FROM tmp_Msg_Error; - DROP TABLE IF EXISTS tmp_Msg_Error; - END; - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_code_type_error_bad_data := (SELECT code FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1); - SET v_id_type_error_bad_data := (SELECT id_type FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = v_code_type_error_bad_data LIMIT 1); - SET v_code_type_error_no_permission := (SELECT code FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = 'NO_PERMISSION' LIMIT 1); - SET v_id_type_error_no_permission := (SELECT id_type FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = v_code_type_error_no_permission LIMIT 1); - SET v_id_permission_supplier := (SELECT id_permission FROM partsltd_prod.Shop_Permission WHERE code = 'STORE_SUPPLIER' LIMIT 1); - SET v_id_access_level_EDIT := (SELECT id_access_level FROM partsltd_prod.Shop_Access_Level WHERE code = 'EDIT' LIMIT 1); + DROP TEMPORARY TABLE IF EXISTS tmp_Split; + DROP TEMPORARY TABLE IF EXISTS tmp_Contact_Form; - CALL p_validate_guid ( a_guid ); - SET a_comment := TRIM(IFNULL(a_comment, '')); - - DROP TEMPORARY TABLE IF EXISTS tmp_Supplier; - DROP TEMPORARY TABLE IF EXISTS tmp_Supplier_Address; - DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error; - - CREATE TEMPORARY TABLE tmp_Supplier ( - id_supplier_temp INT NOT NULL - , id_supplier INT NULL - , id_currency INT NOT NULL - , name_company VARCHAR(255) NOT NULL - , name_contact VARCHAR(255) NULL - , department_contact VARCHAR(255) NULL - , phone_number VARCHAR(50) NULL - , fax VARCHAR(50) NULL - , email VARCHAR(255) NOT NULL - , website VARCHAR(255) NULL - , active BIT NOT NULL - , name_error VARCHAR(1000) NOT NULL - , is_new BIT NOT NULL - ); - - CREATE TEMPORARY TABLE tmp_Supplier_Address ( - id_address INT NOT NULL - , id_supplier INT NOT NULL - , id_region INT NOT NULL - , postcode VARCHAR(20) NOT NULL - , address_line_1 VARCHAR(256) NOT NULL - , address_line_2 VARCHAR(256) NOT NULL - , city VARCHAR(256) NOT NULL - , county VARCHAR(256) NOT NULL - , active BIT NOT NULL - , name_error VARCHAR(1000) NOT NULL - , is_new BIT NOT NULL + CREATE TEMPORARY TABLE tmp_Contact_Form ( + id_contact_form INT NOT NULL ); CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT - , id_type INT NOT NULL + display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT + , id_type INT NULL , code VARCHAR(50) NOT NULL , msg VARCHAR(4000) NOT NULL ); + CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Split ( + substring VARCHAR(4000) NOT NULL + , as_int INT NULL + ); + DELETE FROM tmp_Split; - INSERT INTO tmp_Supplier ( - id_supplier_temp - , id_supplier - , id_currency - , name_company - , name_contact - , department_contact - , phone_number - , fax - , email - , website - , active - , name_error - , is_new - ) - SELECT - S_T.id_supplier - , S_T.id_supplier - , S_T.id_currency - , S_T.name_company - , S_T.name_contact - , S_T.department_contact - , S_T.phone_number - , S_T.fax - , S_T.email - , S_T.website - , S_T.active - , IFNULL(S_T.name_company, IFNULL(S_T.email, IFNULL(S_T.website, IFNULL(S_T.name_contact, '(No Supplier)')))) - , IFNULL(S_T.id_supplier, 0) < 1 - FROM partsltd_prod.Shop_Supplier_Temp S_T - WHERE GUID = a_guid - ; + CALL partsltd_prod.p_core_validate_guid ( v_guid ); - INSERT INTO tmp_Supplier_Address ( - id_address - , id_supplier - , id_region - , postcode - , address_line_1 - , address_line_2 - , city - , county - , active - , name_error - , is_new - ) - SELECT - SA_T.id_address - , SA_T.id_supplier - , SA_T.id_region - , SA_T.postcode - , SA_T.address_line_1 - , SA_T.address_line_2 - , SA_T.city - , SA_T.county - , SA_T.active - , IFNULL(SA_T.postcode, IFNULL(SA_T.city, IFNULL(SA_T.county, IFNULL(SA_T.address_line_1, IFNULL(SA_T.address_line_2, '(No Supplier)'))))) AS name_error - , IFNULL(SA_T.id_address, 0) < 1 AS is_new - FROM partsltd_prod.Shop_Supplier_Address_Temp SA_T - WHERE GUID = a_guid - ; + SET v_has_filter_contact_form = CASE WHEN a_ids_contact_form = '' THEN 0 ELSE 1 END; - -- Validation - -- Suppliers - /* - -- id_address - IF EXISTS ( - SELECT * - FROM tmp_Supplier t_S - LEFT JOIN partsltd_prod.Shop_Address A ON t_S.id_address = A.id_address - WHERE 1=1 - AND ( - t_S.id_address = 0 - OR A.active = 0 - ) - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg + -- Contact Forms + IF v_has_filter_contact_form = 1 THEN + CALL partsltd_prod.p_split(v_guid, a_ids_contact_form, ',', a_debug); + + INSERT INTO tmp_Split ( + substring + , as_int ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT( - 'The following supplier(s) have an invalid or inactive Address: ' - , GROUP_CONCAT(t_S.name_error SEPARATOR ', ') - ) AS msg - FROM tmp_Supplier t_S - LEFT JOIN partsltd_prod.Shop_Address A ON t_S.id_address = A.id_address - WHERE 1=1 - AND ( - t_S.id_address = 0 - OR A.active = 0 - ) + SELECT + substring + , CONVERT(substring, DECIMAL(10,0)) AS as_int + FROM partsltd_prod.CORE_Split_Temp + WHERE + GUID = v_guid + AND NOT ISNULL(substring) + AND substring != '' ; - END IF; - */ - -- id_currency - IF EXISTS ( - SELECT * - FROM tmp_Supplier t_S - LEFT JOIN partsltd_prod.Shop_Currency C ON t_S.id_currency = C.id_currency - WHERE 1=1 - AND ( - t_S.id_currency = 0 - OR C.active = 0 - ) - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT( - 'The following supplier(s) have an invalid or inactive Currency: ' - , GROUP_CONCAT(t_S.name_error SEPARATOR ', ') - ) AS msg - FROM tmp_Supplier t_S - LEFT JOIN partsltd_prod.Shop_Currency C ON t_S.id_currency = C.id_currency - WHERE 1=1 - AND ( - t_S.id_currency = 0 - OR C.active = 0 - ) - ; - END IF; - -- name_company - IF EXISTS (SELECT * FROM tmp_Supplier t_S WHERE ISNULL(t_S.name_company) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following supplier(s) do not have a name: ', GROUP_CONCAT(IFNULL(t_S.name_error, 'NULL') SEPARATOR ', ')) AS msg - FROM tmp_Supplier t_S - WHERE ISNULL(t_S.name_company) - ; - END IF; - -- email - IF EXISTS (SELECT * FROM tmp_Supplier t_S WHERE ISNULL(t_S.email) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following supplier(s) do not have an email: ', GROUP_CONCAT(IFNULL(t_S.name_error, 'NULL') SEPARATOR ', ')) AS msg - FROM tmp_Supplier t_S - WHERE ISNULL(t_S.email) - ; - END IF; - -- duplicate - IF EXISTS (SELECT COUNT(*) FROM tmp_Supplier t_S GROUP BY t_S.id_supplier HAVING COUNT(*) > 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following supplier(s) are duplicates: ', GROUP_CONCAT(IFNULL(t_S.name_error, 'NULL') SEPARATOR ', ')) AS msg - FROM tmp_Supplier t_S - GROUP BY t_S.id_supplier - HAVING COUNT(*) > 1 - ; - END IF; + + CALL partsltd_prod.p_clear_split_temp( v_guid ); + END IF; - -- Addresses - -- id_supplier - IF EXISTS ( - SELECT * - FROM tmp_Supplier_Address t_SA - LEFT JOIN partsltd_prod.Shop_Supplier S ON t_SA.id_supplier = S.id_supplier - WHERE 1=1 - AND ( - t_SA.id_supplier = 0 - OR S.active = 0 + IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN + IF EXISTS ( + SELECT * + FROM tmp_Split t_S + LEFT JOIN partsltd_prod.PH_Contact_Form CF ON t_S.as_int = CF.id_contact_form + WHERE + ISNULL(t_S.as_int) + OR ISNULL(CF.id_contact_form) + OR ( + CF.active = 0 + AND a_get_inactive_contact_form = 0 + ) + ) THEN + INSERT INTO tmp_Msg_Error ( + id_type + , code + , msg ) - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT( - 'The following supplier address(es) have an invalid or inactive Supplier: ' - , GROUP_CONCAT(t_S.name_error SEPARATOR ', ') - ) AS msg - FROM tmp_Supplier t_S - LEFT JOIN partsltd_prod.Shop_Supplier S ON t_SA.id_supplier = S.id_supplier - WHERE 1=1 - AND ( - t_SA.id_supplier = 0 - OR S.active = 0 + SELECT + v_id_type_error_bad_data + , v_code_type_error_bad_data + , CONCAT('Invalid or inactive Contact Form IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) + FROM tmp_Split t_S + LEFT JOIN partsltd_prod.PH_Contact_Form CF ON t_S.as_int = CF.id_contact_form + WHERE + ISNULL(t_S.as_int) + OR ISNULL(CF.id_contact_form) + OR ( + CF.active = 0 + AND a_get_inactive_contact_form = 0 + ) + ; + ELSE + INSERT INTO tmp_Contact_Form ( + id_contact_form ) - ; - END IF; - -- id_region - IF EXISTS ( - SELECT * - FROM tmp_Supplier_Address t_SA - LEFT JOIN partsltd_prod.Shop_Region R ON t_SA.id_region = R.id_region - WHERE 1=1 - AND ( - t_SA.id_region = 0 - OR R.active = 0 - ) - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT( - 'The following supplier address(es) have an invalid or inactive Supplier: ' - , GROUP_CONCAT(t_S.name_error SEPARATOR ', ') - ) AS msg - FROM tmp_Supplier t_S - LEFT JOIN partsltd_prod.Shop_Region R ON t_SA.id_region = R.id_region - WHERE 1=1 - AND ( - t_SA.id_region = 0 - OR R.active = 0 - ) - ; - END IF; - -- duplicate - IF EXISTS (SELECT COUNT(*) FROM tmp_Supplier_Address t_SA GROUP BY t_SA.id_address HAVING COUNT(*) > 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following supplier address(es) are duplicates: ', GROUP_CONCAT(IFNULL(t_S.name_error, 'NULL') SEPARATOR ', ')) AS msg - FROM tmp_Supplier_Address t_SA - GROUP BY t_SA.id_address - HAVING COUNT(*) > 1 - ; - END IF; + SELECT + CF.id_contact_form + FROM tmp_Split t_S + RIGHT JOIN partsltd_prod.PH_Contact_Form CF ON t_S.as_int = CF.id_contact_form + WHERE + ( + a_get_all_contact_form = 1 + OR ( + v_has_filter_contact_form = 1 + AND NOT ISNULL(t_S.as_int) + ) + ) + AND ( + a_get_inactive_contact_form = 1 + OR CF.active = 1 + ) + ; + END IF; + END IF; + + DELETE FROM tmp_Split; + -- Permissions - IF a_debug = 1 THEN + IF a_debug = 1 THEN SELECT - a_guid + v_guid , a_id_user - , FALSE -- get inactive users - , v_id_permission_supplier - , v_id_access_level_edit - , '' -- ids_product + , FALSE -- a_get_inactive_user + , v_id_permission_contact_form_view , 0 -- a_debug - ; - SELECT * from partsltd_prod.Shop_Calc_User_Temp; - END IF; + ; + END IF; + + CALL partsltd_prod.p_ph_calc_user( + v_guid + , a_id_user + , FALSE -- a_get_inactive_user + , v_id_permission_contact_form_view + , 0 -- a_debug + ); - CALL p_shop_calc_user( - a_guid - , a_id_user - , FALSE -- get inactive users - , v_id_permission_supplier - , v_id_access_level_edit - , '' -- ids_product - , 0 -- a_debug - ); - - IF a_debug = 1 THEN - SELECT * from partsltd_prod.Shop_Calc_User_Temp WHERE GUID = a_guid; - END IF; - - IF NOT EXISTS (SELECT can_view FROM partsltd_prod.Shop_Calc_User_Temp UE_T WHERE UE_T.GUID = a_guid) THEN - DELETE FROM tmp_Msg_Error; - + SELECT + IFNULL(CU_T.has_access, 0) + INTO + v_can_view + FROM partsltd_prod.PH_Calc_User_Temp CU_T + WHERE CU_T.GUID = v_guid + LIMIT 1 + ; + + IF (v_can_view = 0) THEN + DELETE t_ME + FROM tmp_Msg_Error t_ME + WHERE t_ME.id_type <> v_id_type_error_no_permission + ; INSERT INTO tmp_Msg_Error ( - id_type + id_type , code , msg ) VALUES ( v_id_type_error_no_permission , v_code_type_error_no_permission - , CONCAT('You do not have view permissions for ', (SELECT name FROM partsltd_prod.Shop_Permission WHERE id_permission = v_id_permission_supplier LIMIT 1)) + , 'You do not have permission to view Contact Forms.' ) - ; - END IF; - - CALL partsltd_prod.p_shop_clear_calc_user( - a_guid + ; + END IF; + + CALL partsltd_prod.p_ph_clear_calc_user( + v_guid , 0 -- a_debug ); - IF EXISTS ( SELECT * FROM tmp_Msg_Error LIMIT 1 ) THEN - DELETE FROM tmp_Supplier; - END IF; - - - -- Transaction - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - START TRANSACTION; - INSERT INTO partsltd_prod.Shop_User_Change_Set ( - comment - , updated_last_by - , updated_last_on - ) - VALUES ( - a_comment - , a_id_user - , v_time_start - ); - - SET v_id_change_set := LAST_INSERT_ID(); - - INSERT INTO partsltd_prod.Shop_Supplier ( - id_supplier_temp - , id_currency - , name_company - , name_contact - , department_contact - , phone_number - , fax - , email - , website - , active - , id_change_set - ) - SELECT - t_S.id_supplier - , t_S.id_currency - , t_S.name_company - , t_S.name_contact - , t_S.department_contact - , t_S.phone_number - , t_S.fax - , t_S.email - , t_S.website - , t_S.active - , v_id_change_set - FROM tmp_Supplier t_S - WHERE t_S.is_new = 1 - ; - - UPDATE tmp_Supplier t_S - INNER JOIN partsltd_prod.Shop_Supplier S ON t_S.id_supplier_temp = S.id_supplier_temp - SET - t_S.id_supplier = S.id_supplier - WHERE t_S.is_new = 1 - ; - - UPDATE tmp_Supplier_Address t_SA - INNER JOIN tmp_Supplier t_S ON t_SA.id_supplier = t_S.id_supplier_temp - SET - t_SA.id_supplier = t_S.id_supplier - WHERE t_S.is_new = 1 - ; - - UPDATE partsltd_prod.Shop_Supplier S - INNER JOIN tmp_Supplier t_S - ON S.id_supplier = t_S.id_supplier - AND t_S.is_new = 0 - SET - S.id_currency = t_S.id_currency - , S.name_company = t_S.name_company - , S.name_contact = t_S.name_contact - , S.department_contact = t_S.department_contact - , S.phone_number = t_S.phone_number - , S.fax = t_S.fax - , S.email = t_S.email - , S.website = t_S.website - , S.active = t_S.active - , S.id_change_set = v_id_change_set - /* - S.name_company = a_name_company, - S.name_contact = a_name_contact, - S.department_contact = a_department_contact, - S.id_address = a_id_address, - S.phone_number = a_phone_number, - S.fax = a_fax, - S.email = a_email, - S.website = a_website, - S.id_currency = a_id_currency, - S.active = a_active, - S.id_change_set = v_id_change_set - */ - ; - - INSERT INTO partsltd_prod.Shop_Supplier_Address ( - id_supplier - , id_region - , postcode - , address_line_1 - , address_line_2 - , city - , county - , active - , id_change_set - ) - SELECT - t_SA.id_supplier - , t_SA.id_region - , t_SA.postcode - , t_SA.address_line_1 - , t_SA.address_line_2 - , t_SA.city - , t_SA.county - , t_SA.active - , v_id_change_set - FROM tmp_Supplier_Address t_SA - WHERE t_SA.is_new = 1 - ; - - UPDATE partsltd_prod.Shop_Supplier_Address SA - INNER JOIN tmp_Supplier_Address t_SA - ON SA.id_address = t_SA.id_address - AND t_SA.is_new = 0 - SET - SA.id_supplier = t_SA.id_supplier - , SA.id_region = t_SA.id_region - , SA.postcode = t_SA.postcode - , SA.address_line_1 = t_SA.address_line_1 - , SA.address_line_2 = t_SA.address_line_2 - , SA.city = t_SA.city - , SA.county = t_SA.county - , SA.active = t_SA.active - , SA.id_change_set = v_id_change_set - ; - COMMIT; + IF v_can_view = 0 THEN + IF a_debug = 1 THEN + SELECT * FROM tmp_Contact_Form; + END IF; + + DELETE FROM tmp_Contact_Form; END IF; - - START TRANSACTION; - DELETE FROM partsltd_prod.Shop_Supplier_Temp - WHERE GUID = a_guid; - DELETE FROM partsltd_prod.Shop_Supplier_Address_Temp - WHERE GUID = a_guid; - COMMIT; + + -- Outputs + -- Contact Forms + SELECT + t_CF.id_contact_form + , CF.email + , CF.name_contact + , CF.name_company + , CF.message + , CF.active + , v_can_view + FROM tmp_Contact_Form t_CF + INNER JOIN partsltd_prod.PH_Contact_Form CF ON t_CF.id_contact_form = CF.id_contact_form + GROUP BY t_CF.id_contact_form + ORDER BY CF.created_on DESC + ; -- Errors SELECT * FROM tmp_Msg_Error t_ME - INNER JOIN partsltd_prod.Shop_Msg_Error_Type MET ON t_ME.id_type = MET.id_type - ; - - IF a_debug = 1 THEN - SELECT 'A_DEBUG'; - SELECT * from tmp_Supplier; - SELECT * from tmp_Supplier_Address; - END IF; - - DROP TEMPORARY TABLE IF EXISTS tmp_Supplier; - DROP TEMPORARY TABLE IF EXISTS tmp_Supplier_Address; - DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error; - - IF a_debug = 1 THEN - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); - END IF; -END // -DELIMITER ; - - --- SELECT * FROM Shop_Supplier; -/* -delete from shop_supplier_audit where id_supplier = 9; -delete from shop_supplier where id_supplier = 9; -delete from shop_supplier_address_audit where id_address = -4; -delete from shop_supplier_address where id_address = -4; -*/ - --- File: 7400_p_shop_save_supplier_temp.sql - - --- Clear previous proc -DROP PROCEDURE IF EXISTS partsltd_prod.p_shop_save_supplier_test; - - -DELIMITER // -CREATE PROCEDURE p_shop_save_supplier_test () -BEGIN - - DECLARE v_guid BINARY(36); - DECLARE v_time_start TIMESTAMP(6); - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_guid := 'nips'; - - SELECT * - FROM partsltd_prod.Shop_Supplier - ; - SELECT * - FROM partsltd_prod.Shop_Supplier_Temp - ; - SELECT * - FROM partsltd_prod.Shop_Supplier_Address - ; - SELECT * - FROM partsltd_prod.Shop_Supplier_Address_Temp - ; - - START TRANSACTION; - - INSERT INTO partsltd_prod.Shop_Supplier_Temp ( - id_supplier - , id_currency - , name_company - , name_contact - , department_contact - , phone_number - , fax - , email - , website - , active - , guid - ) - /* Test 1 - Insert - VALUES ( - -3 - , 1 - , 'Asda' - , '' - , NULL - , '' - , '123' - , 'test mail' - , 'test url' - , 1 -- active - , v_guid - ) - */ - /* Test 2 - Update */ - SELECT - id_supplier - , id_currency - , name_company - , 'Nat' AS name_contact - , 'Butchery' AS department_contact - , phone_number - , fax - , email - , website - , active - , v_guid - FROM partsltd_prod.Shop_Supplier S - WHERE S.id_supplier = 2 - ; - - /* - INSERT INTO partsltd_prod.Shop_Supplier_Address_Temp ( - id_address - , id_supplier - , id_region - , postcode - , address_line_1 - , address_line_2 - , city - , county - , active - , GUID - ) - / Test 1 - Insert - VALUES ( - -4 - , -3 - , 1 - , 'test postcode' - , 'test' - , 'test' - , 'test' - , 'cunty' - , 1 - , v_guid - ) - / - / Test 2 - Update / - SELECT - id_address - , id_supplier - , id_region - , postcode - , address_line_1 - , address_line_2 - , city - , county - , active - , v_guid - FROM partsltd_prod.Shop_Supplier_Address SA - WHERE SA.id_supplier = 2 - ; - */ - - COMMIT; - - SELECT * - FROM partsltd_prod.Shop_Supplier_Temp - WHERE GUID = v_guid + INNER JOIN partsltd_prod.CORE_Msg_Error_Type MET ON t_ME.id_type = MET.id_type ; - SELECT * - FROM partsltd_prod.Shop_Supplier_Address_Temp - WHERE GUID = v_guid - ; + IF a_debug = 1 AND v_can_view = 1 THEN + SELECT * FROM tmp_Contact_Form; + END IF; - CALL partsltd_prod.p_shop_save_supplier ( - 'Test save Supplier' -- comment - , v_guid -- guid - , 1 -- id_user - , 1 -- debug - ); - - SELECT * - FROM partsltd_prod.Shop_Supplier_Temp - ; - SELECT * - FROM partsltd_prod.Shop_Supplier_Address_Temp - ; - SELECT * - FROM partsltd_prod.Shop_Supplier - ; - SELECT * - FROM partsltd_prod.Shop_Supplier_Address - ; - - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); -END // -DELIMITER ; - -/* -CALL partsltd_prod.p_shop_save_supplier_test (); - -DELETE FROM partsltd_prod.Shop_Supplier_Temp; -DELETE FROM partsltd_prod.Shop_Supplier_Address_Temp; - -DROP TABLE IF EXISTS tmp_Msg_Error; - -Cannot add or update a child row: a foreign key constraint fails (`partsltd_prod`.`shop_supplier`, CONSTRAINT `FK_Shop_Supplier_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_sales_and_purchasing_change_set` (`id_change_set`)) - -*/ - --- File: 7401_p_shop_get_many_supplier.sql - - -DROP PROCEDURE IF EXISTS p_shop_get_many_supplier; - -DELIMITER // -CREATE PROCEDURE p_shop_get_many_supplier ( - IN a_id_user INT - , IN a_get_all_supplier BIT - , IN a_get_inactive_supplier BIT - , IN a_ids_supplier TEXT - , IN a_debug BIT -) -BEGIN - DECLARE v_code_type_error_bad_data VARCHAR(50); - DECLARE v_code_type_error_no_permission VARCHAR(50); - DECLARE v_guid BINARY(36); - DECLARE v_has_filter_supplier BIT; - DECLARE v_id_access_level_view INT; - DECLARE v_id_permission_supplier INT; - DECLARE v_id_type_error_bad_data INT; - DECLARE v_id_type_error_no_permission INT; - DECLARE v_time_start TIMESTAMP(6); - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_guid := UUID(); - SET v_id_access_level_view := (SELECT id_access_level FROM partsltd_prod.Shop_Access_Level WHERE code = 'VIEW' LIMIT 1); - SET v_code_type_error_bad_data := (SELECT code FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1); - SET v_id_type_error_bad_data := (SELECT id_type FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = v_code_type_error_bad_data LIMIT 1); - SET v_code_type_error_no_permission := (SELECT code FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = 'NO_PERMISSION'); - SET v_id_type_error_no_permission := (SELECT id_type FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = v_code_type_error_no_permission); - SET v_id_permission_supplier := (SELECT id_permission FROM partsltd_prod.Shop_Permission WHERE code = 'STORE_SUPPLIER' LIMIT 1); - - SET a_get_all_supplier := IFNULL(a_get_all_supplier, 0); - SET a_get_inactive_supplier := IFNULL(a_get_inactive_supplier, 0); - SET a_ids_supplier := TRIM(IFNULL(a_ids_supplier, '')); - - DROP TEMPORARY TABLE IF EXISTS tmp_Supplier; - DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error; DROP TEMPORARY TABLE IF EXISTS tmp_Split; - - CREATE TEMPORARY TABLE tmp_Supplier ( - id_supplier INT NOT NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - id_type INT NOT NULL, - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Split ( - substring VARCHAR(4000) NOT NULL - , as_int INT NULL - ); - DELETE FROM tmp_Split; - - - -- Parse filters - SET v_has_filter_supplier = CASE WHEN a_ids_supplier = '' THEN 0 ELSE 1 END; - - IF a_debug = 1 THEN - SELECT - v_has_filter_supplier - ; - END IF; - - -- Suppliers - IF v_has_filter_supplier = 1 THEN - CALL partsltd_prod.p_split(v_guid, a_ids_supplier, ',', a_debug); - - INSERT INTO tmp_Split ( - substring - , as_int - ) - SELECT - substring - , CONVERT(substring, DECIMAL(10,0)) AS as_int - FROM partsltd_prod.Split_Temp - WHERE 1=1 - AND GUID = v_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( v_guid ); - END IF; - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Supplier S ON t_S.as_int = S.id_supplier - WHERE - ISNULL(t_S.as_int) - OR ISNULL(S.id_supplier) - OR ( - S.active = 0 - AND a_get_inactive_supplier = 0 - ) - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - code, - msg - ) - SELECT - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Invalid or inactive Supplier IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Supplier S ON t_S.as_int = S.id_supplier - WHERE - ISNULL(t_S.as_int) - OR ISNULL(S.id_supplier) - OR ( - S.active = 0 - AND a_get_inactive_supplier = 0 - ) - ; - ELSE - INSERT INTO tmp_Supplier ( - id_supplier - ) - SELECT - S.id_supplier - FROM tmp_Split t_S - RIGHT JOIN partsltd_prod.Shop_Supplier S ON t_S.as_int = S.id_supplier - WHERE ( - a_get_all_supplier = 1 - OR ( - v_has_filter_supplier = 1 - AND NOT ISNULL(t_S.as_int) - ) - ) - AND ( - a_get_inactive_supplier = 1 - OR S.active = 1 - ) - ; - END IF; - END IF; - - DELETE FROM tmp_Split; - - -- Permissions - IF a_debug = 1 THEN - SELECT - v_guid - , a_id_user - , FALSE -- get inactive users - , v_id_permission_supplier - , v_id_access_level_view - , '' -- ids_product - , 0 -- a_debug - ; - SELECT * from Shop_Calc_User_Temp; - END IF; - - CALL p_shop_calc_user( - v_guid - , a_id_user - , FALSE -- get inactive users - , v_id_permission_supplier - , v_id_access_level_view - , '' -- ids_product - , 0 -- a_debug - ); - - IF a_debug = 1 THEN - SELECT * from Shop_Calc_User_Temp; - END IF; - - IF NOT EXISTS (SELECT can_view FROM Shop_Calc_User_Temp UE_T WHERE UE_T.GUID = v_guid) THEN - DELETE FROM tmp_Msg_Error; - - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - VALUES ( - v_id_type_error_no_permission - , v_code_type_error_no_permission - , CONCAT('You do not have view permissions for ', (SELECT name FROM Shop_Permission WHERE id_permission = v_id_permission_supplier LIMIT 1)) - ) - ; - END IF; - - IF EXISTS ( SELECT * FROM tmp_Msg_Error LIMIT 1 ) THEN - DELETE FROM tmp_Supplier; - END IF; - - -- Returns - -- Suppliers - SELECT - t_S.id_supplier, - S.id_currency, - C.code AS code_currency, - C.symbol AS symbol_currency, - S.name_company, - S.name_contact, - S.department_contact, - S.phone_number, - S.fax, - S.email, - S.website, - S.active - FROM tmp_Supplier t_S - INNER JOIN partsltd_prod.Shop_Supplier S ON t_S.id_supplier = S.id_supplier - LEFT JOIN partsltd_prod.Shop_Currency C ON S.id_currency = C.id_currency - ; - - -- Supplier Addresses - SELECT - t_S.id_supplier - , SA.id_address - , SA.id_region - , R.name AS name_region - , SA.postcode - , SA.address_line_1 - , SA.address_line_2 - , SA.city - , SA.county - , SA.active - FROM tmp_Supplier t_S - INNER JOIN partsltd_prod.Shop_Supplier S ON t_S.id_supplier = S.id_supplier - INNER JOIN partsltd_prod.Shop_Supplier_Address SA ON S.id_supplier = SA.id_supplier - LEFT JOIN partsltd_prod.Shop_Region R ON SA.id_region = R.id_region - ; - - -- Errors - SELECT * - FROM tmp_Msg_Error t_ME - INNER JOIN partsltd_prod.Shop_Msg_Error_Type MET ON t_ME.id_type = MET.id_type - ; + DROP TEMPORARY TABLE IF EXISTS tmp_Contact_Form; IF a_debug = 1 THEN - SELECT * from tmp_Supplier; - END IF; - - DROP TEMPORARY TABLE IF EXISTS tmp_Supplier; - DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error; - DROP TEMPORARY TABLE IF EXISTS tmp_Split; - - IF a_debug = 1 THEN - CALL p_debug_timing_reporting( v_time_start ); + CALL partsltd_prod.p_core_debug_timing_reporting ( v_time_start ); END IF; END // DELIMITER ; @@ -19022,5958 +2315,130 @@ DELIMITER ; /* -CALL p_shop_get_many_supplier ( - 1 -- 'auth0|6582b95c895d09a70ba10fef' -- a_id_user - , 1 -- a_get_all_supplier - , 0 -- a_get_inactive_supplier - , '' -- a_ids_supplier - , 0 -- a_debug +CALL partsltd_prod.p_ph_get_many_contact_form ( + 1 -- 'auth0|6582b95c895d09a70ba10fef', -- a_id_user + , 1 -- a_get_all_contact_form + , 0 -- a_get_inactive_contact_form + , '' -- a_ids_contact_form + , 0 -- a_debug ); */ --- File: 7403_p_shop_save_supplier_purchase_order.sql +USE partsltd_prod; - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_save_supplier_purchase_order; - -DROP TABLE IF EXISTS tmp_Supplier_Purchase_Order_Product_Link; -DROP TABLE IF EXISTS tmp_Msg_Error; - -DELIMITER // -CREATE PROCEDURE p_shop_save_supplier_purchase_order ( - IN a_comment VARCHAR(500) - , IN a_guid BINARY(36) - , IN a_id_user INT - , IN a_debug BIT -) -BEGIN - DECLARE v_code_type_error_bad_data VARCHAR(50); - DECLARE v_code_type_error_no_permission VARCHAR(50); - DECLARE v_code_type_error_warning VARCHAR(50); - DECLARE v_id_access_level_edit INT; - DECLARE v_id_change_set INT; - DECLARE v_id_permission_supplier_purchase_order VARCHAR(100); - DECLARE v_id_type_error_bad_data INT; - DECLARE v_id_type_error_no_permission INT; - DECLARE v_id_type_error_warning INT; - DECLARE v_ids_product_permission TEXT; - DECLARE v_time_start TIMESTAMP(6); - - DECLARE exit handler for SQLEXCEPTION - BEGIN - GET DIAGNOSTICS CONDITION 1 - @sqlstate = RETURNED_SQLSTATE - , @errno = MYSQL_ERRNO - , @text = MESSAGE_TEXT - ; - - ROLLBACK; - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT - , id_type INT NULL - , code VARCHAR(50) NOT NULL - , msg VARCHAR(4000) NOT NULL - ); - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - MET.id_type - , @errno - , @text - FROM partsltd_prod.Shop_Msg_Error_Type MET - WHERE code = 'MYSQL_ERROR' - ; - SELECT * - FROM tmp_Msg_Error; - DROP TABLE IF EXISTS tmp_Msg_Error; - END; - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_code_type_error_bad_data := (SELECT code FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1); - SET v_id_type_error_bad_data := (SELECT id_type FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = v_code_type_error_bad_data LIMIT 1); - SET v_code_type_error_no_permission := (SELECT code FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = 'NO_PERMISSION' LIMIT 1); - SET v_id_type_error_no_permission := (SELECT id_type FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = v_code_type_error_no_permission LIMIT 1); - SET v_code_type_error_warning := (SELECT code FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = 'WARNING' LIMIT 1); - SET v_id_type_error_warning := (SELECT id_type FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = v_code_type_error_warning LIMIT 1); - SET v_id_permission_supplier_purchase_order := (SELECT GROUP_CONCAT(id_permission SEPARATOR ',') FROM partsltd_prod.Shop_Permission WHERE code IN ('STORE_SUPPLIER', 'STORE_SUPPLIER_PURCHASE_ORDER', 'STORE_PRODUCT')); - SET v_id_access_level_edit := (SELECT id_access_level FROM partsltd_prod.Shop_Access_Level WHERE code = 'EDIT' LIMIT 1); - - CALL p_validate_guid ( a_guid ); - SET a_comment := TRIM(IFNULL(a_comment, '')); - - DROP TEMPORARY TABLE IF EXISTS tmp_Supplier_Purchase_Order; - DROP TEMPORARY TABLE IF EXISTS tmp_Supplier_Purchase_Order_Product_Link; - DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error; - - -- Temporary tables - CREATE TEMPORARY TABLE tmp_Supplier_Purchase_Order ( - id_order INT NOT NULL PRIMARY KEY - , id_order_temp INT NOT NULL - , id_supplier_ordered INT NOT NULL - , id_currency_cost INT NOT NULL - , cost_total_local_VAT_excl FLOAT NULL - , cost_total_local_VAT_incl FLOAT NULL - , active BIT NOT NULL - , is_new BIT NOT NULL - , name_error VARCHAR(1000) NOT NULL - ); - - CREATE TEMPORARY TABLE tmp_Supplier_Purchase_Order_Product_Link ( - id_link INT NOT NULL PRIMARY KEY - , id_order INT NOT NULL - , id_permutation INT NOT NULL - , id_product INT - -- , id_currency_cost INT NOT NULL - , quantity_ordered FLOAT NOT NULL - , id_unit_quantity INT NOT NULL - , quantity_received FLOAT NULL - , latency_delivery_days INT NOT NULL - , display_order INT NOT NULL - , active BIT NOT NULL - , cost_total_local_VAT_excl FLOAT NOT NULL - , cost_total_local_VAT_incl FLOAT NOT NULL - , cost_unit_local_VAT_excl FLOAT NOT NULL - , cost_unit_local_VAT_incl FLOAT NOT NULL - , has_order BIT NULL - , is_new BIT NOT NULL - , name_error VARCHAR(1000) NULL - , can_edit BIT - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT - , id_type INT NOT NULL - , code VARCHAR(50) NOT NULL - , msg VARCHAR(4000) NOT NULL - ); - - INSERT INTO tmp_Supplier_Purchase_Order ( - id_order - , id_order_temp - , id_supplier_ordered - , id_currency_cost - , active - , is_new - , name_error - ) - SELECT - SPO_T.id_order - , SPO_T.id_order - , IFNULL(IFNULL(SPO_T.id_supplier_ordered, SPO.id_supplier_ordered), 0) AS id_supplier_ordered - , IFNULL(IFNULL(SPO_T.id_currency_cost, SPO.id_currency_cost), 0) AS id_currency_cost - , IFNULL(IFNULL(SPO_T.active, SPO.active), 1) AS active - , ISNULL(SPO.id_order) AS is_new - , CONCAT( - IFNULL(S.name_company, '(No Supplier)') - , ' - ' - , IFNULL(SPO.created_on, '(No creation date)') - , ' - ' - , IFNULL(C.symbol, '(No Currency)') - , ' ' - , IFNULL(IFNULL(SPO.cost_total_local_vat_excl, SPO.cost_total_local_vat_incl), '(No cost)') - ) AS name_error - FROM partsltd_prod.Shop_Supplier_Purchase_Order_Temp SPO_T - LEFT JOIN partsltd_prod.Shop_Supplier_Purchase_Order SPO ON SPO_T.id_order = SPO.id_order - LEFT JOIN partsltd_prod.Shop_Supplier S ON SPO_T.id_supplier_ordered = S.id_supplier - LEFT JOIN partsltd_prod.Shop_Currency C ON SPO_T.id_currency_cost = C.id_currency - WHERE SPO_T.GUID = a_guid - ; - - INSERT INTO tmp_Supplier_Purchase_Order_Product_Link ( - id_link - , id_order - , id_permutation - -- , id_currency_cost - , id_unit_quantity - , quantity_ordered - , quantity_received - , latency_delivery_days - , display_order - , cost_total_local_VAT_excl - , cost_total_local_VAT_incl - , cost_unit_local_VAT_excl - , cost_unit_local_VAT_incl - , active - , has_order - , is_new - ) - SELECT - IFNULL(SPOPL_T.id_link, 0) AS id_link - , IFNULL(IFNULL(SPOPL_T.id_order, SPOPL.id_order), 0) AS id_order - , IFNULL( - IFNULL( - IFNULL( - SPOPL_T.id_permutation - , CASE WHEN NOT ISNULL(SPOPL_T.id_product) AND NOT ISNULL(SPOPL_T.csv_list_variations) THEN - partsltd_prod.fn_shop_get_id_product_permutation_from_variation_csv_list(SPOPL_T.id_product, SPOPL_T.csv_list_variations) - ELSE NULL END - ) - , SPOPL.id_permutation - ) - , 0 - ) AS id_permutation - -- , IFNULL(IFNULL(SPOPL_T.id_currency_cost, SPOPL.id_currency_cost), 0) AS id_currency_cost - , IFNULL(IFNULL(SPOPL_T.id_unit_quantity, SPOPL.id_unit_quantity), 0) AS id_unit_quantity - , IFNULL(IFNULL(SPOPL_T.quantity_ordered, SPOPL.quantity_ordered), 0) AS quantity_ordered - , IFNULL(SPOPL_T.quantity_received, SPOPL.quantity_received) AS quantity_received - , IFNULL(SPOPL_T.latency_delivery_days, SPOPL.latency_delivery_days) AS latency_delivery_days - , RANK() OVER (PARTITION BY IFNULL(IFNULL(SPOPL_T.id_order, SPOPL.id_order), 0) ORDER BY IFNULL(IFNULL(SPOPL_T.display_order, SPOPL.display_order), 0)) AS display_order - , IFNULL(IFNULL(SPOPL_T.cost_total_local_VAT_excl, SPOPL.cost_total_local_VAT_excl), 0) AS cost_total_local_VAT_excl - , IFNULL(IFNULL(SPOPL_T.cost_total_local_VAT_incl, SPOPL.cost_total_local_VAT_incl), 0) AS cost_total_local_VAT_incl - /* - , IFNULL(SPOPL_T.cost_total_local_VAT_excl / SPOPL_T.quantity_ordered, SPOPL.cost_unit_local_VAT_excl) AS cost_unit_local_VAT_excl - , IFNULL(SPOPL_T.cost_total_local_VAT_incl / SPOPL_T.quantity_ordered, SPOPL.cost_unit_local_VAT_incl) AS cost_unit_local_VAT_incl - */ - , IFNULL(IFNULL(SPOPL_T.active, SPOPL.active), 1) AS active - , NOT ISNULL(t_SPO.id_order) AS has_order - , IFNULL(SPOPL_T.id_link, 0) < 1 AS is_new - FROM partsltd_prod.Shop_Supplier_Purchase_Order_Product_Link_Temp SPOPL_T - LEFT JOIN partsltd_prod.Shop_Supplier_Purchase_Order_Product_Link SPOPL ON SPOPL_T.id_link = SPOPL.id_link - LEFT JOIN tmp_Supplier_Purchase_Order t_SPO ON SPOPL_T.id_order = t_SPO.id_order - WHERE SPOPL_T.GUID = a_guid - ; - - UPDATE tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - LEFT JOIN partsltd_prod.Shop_Supplier_Purchase_Order_Product_Link_Temp SPOPL_T - ON t_SPOPL.id_link = SPOPL_T.id_link - AND t_SPOPL.GUID = a_guid - LEFT JOIN partsltd_prod.Shop_Supplier_Purchase_Order_Product_Link SPOPL ON t_SPOPL.id_link = SPOPL.id_link - LEFT JOIN partsltd_prod.Shop_Product_Permutation PP ON t_SPOPL.id_permutation = PP.id_permutation - LEFT JOIN partsltd_prod.Shop_Product P ON SPOPL_T.id_product = P.id_product - LEFT JOIN partsltd_prod.Shop_Product_Category PC ON P.id_category = PC.id_category - SET - t_SPOPL.id_product = IFNULL(P.id_product, SPOPL_T.id_product) - , t_SPOPL.name_error = CONCAT( - CASE WHEN ISNULL(t_SPOPL.id_permutation) THEN - CASE WHEN ISNULL(P.id_product) THEN - '(No Product Permutation)' - ELSE - CONCAT( - PC.name - , ' - ' - , P.name - ) - END - ELSE - fn_shop_get_product_permutation_name(t_SPOPL.id_permutation) - END - , ' - x' - , IFNULL(t_SPOPL.quantity_ordered, '(No Quantity)') - ) - , t_SPOPL.cost_unit_local_VAT_excl = t_SPOPL.cost_total_local_VAT_excl / t_SPOPL.quantity_ordered - , t_SPOPL.cost_unit_local_VAT_incl = t_SPOPL.cost_total_local_VAT_incl / t_SPOPL.quantity_ordered - , t_SPOPL.delta_quantity_ordered = t_SPOPL.quantity_ordered - IFNULL(SPOPL.quantity_ordered, 0) - , t_SPOPL.delta_quantity_received = t_SPOPL.quantity_received - IFNULL(SPOPL.quantity_received, 0) - ; - - INSERT INTO tmp_Supplier_Purchase_Order ( - id_order - , id_order_temp - , id_supplier_ordered - , id_currency_cost - , active - , is_new - ) - SELECT - SPO.id_order - , SPO.id_order - , IFNULL(SPO.id_supplier_ordered, 0) AS id_supplier_ordered - , IFNULL(SPO.id_currency_cost, 0) AS id_currency_cost - , SPO.active AS active - , 0 AS is_new - FROM partsltd_prod.Shop_Supplier_Purchase_Order SPO - INNER JOIN tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - ON SPO.id_order = t_SPOPL.id_order - AND t_SPOPL.has_order = 0 - ; - - UPDATE tmp_Supplier_Purchase_Order t_SPO - INNER JOIN ( - SELECT - t_SPOPL.id_order - , SUM(t_SPOPL.cost_total_local_VAT_excl) AS cost_total_local_VAT_excl - , SUM(t_SPOPL.cost_total_local_VAT_incl) AS cost_total_local_VAT_incl - FROM tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - GROUP BY t_SPOPL.id_order - ) SUM_t_SPOPL ON t_SPO.id_order = SUM_t_SPOPL.id_order - SET - t_SPO.cost_total_local_VAT_excl = SUM_t_SPOPL.cost_total_local_VAT_excl - , t_SPO.cost_total_local_VAT_incl = SUM_t_SPOPL.cost_total_local_VAT_incl - ; - - -- Validation - -- Supplier Purchase Order - -- id_order - IF EXISTS ( - SELECT * - FROM tmp_Supplier_Purchase_Order t_SPO - LEFT JOIN partsltd_prod.Shop_Supplier_Purchase_Order SPO ON t_SPO.id_order = SPO.id_order - WHERE 1=1 - AND t_SPO.id_order > 0 - AND ISNULL(SPO.id_order) - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT( - 'A valid ID is required for the following Supplier Purchase Order(s): ' - , GROUP_CONCAT(CONCAT(IFNULL(t_SPO.id_stock, '(No Supplier Purchase Order)')) SEPARATOR ', ') - ) AS msg - FROM tmp_Supplier_Purchase_Order t_SPO - LEFT JOIN partsltd_prod.Shop_Supplier_Purchase_Order SPO ON t_SPO.id_order = SPO.id_order - WHERE 1=1 - AND t_SPO.id_stock > 0 - AND ISNULL(SPO.id_stock) - ; - END IF; - -- id_supplier_ordered - IF EXISTS ( - SELECT * - FROM tmp_Supplier_Purchase_Order t_SPO - LEFT JOIN partsltd_prod.Shop_Supplier S ON t_SPO.id_supplier_ordered = S.id_supplier - WHERE 1=1 - AND ( - ISNULL(S.id_supplier) - OR S.active = 0 - ) - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT( - 'A valid supplier is required for the following Supplier Purchase Order(s): ' - , GROUP_CONCAT(CONCAT(IFNULL(t_SPO.id_stock, '(No Supplier Purchase Order)'), ' - ', t_SPO.id_supplier_ordered) SEPARATOR ', ') - ) AS msg - FROM tmp_Supplier_Purchase_Order t_SPO - LEFT JOIN partsltd_prod.Shop_Supplier S ON t_SPO.id_supplier_ordered = S.id_supplier - WHERE 1=1 - AND ( - ISNULL(S.id_supplier) - OR S.active = 0 - ) - ; - END IF; - -- id_currency_cost - IF EXISTS ( - SELECT * - FROM tmp_Supplier_Purchase_Order t_SPO - LEFT JOIN partsltd_prod.Shop_Currency C ON t_SPO.id_currency_cost = C.id_currency - WHERE 1=1 - AND ( - ISNULL(C.id_currency) - OR C.active = 0 - ) - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT( - 'A valid currency is required for the following Supplier Purchase Order(s): ' - , GROUP_CONCAT(CONCAT(IFNULL(t_SPO.id_stock, '(No Supplier Purchase Order)'), ' - ', t_SPO.id_currency_cost) SEPARATOR ', ') - ) AS msg - FROM tmp_Supplier_Purchase_Order t_SPO - LEFT JOIN partsltd_prod.Shop_Currency C ON t_SPO.id_currency_cost = C.id_currency - WHERE 1=1 - AND ( - ISNULL(C.id_currency) - OR C.active = 0 - ) - ; - END IF; - -- id_unit_quantity - IF EXISTS ( - SELECT * - FROM tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - LEFT JOIN partsltd_prod.Shop_Unit_Measurement UM ON t_SPOPL.id_unit_quantity = UM.id_unit_measurement - WHERE 1=1 - AND ( - ISNULL(UM.id_unit_measurement) - OR UM.active = 0 - ) - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT( - 'A valid unit measurement of quantity is required for the following Supplier Purchase Order(s): ' - , GROUP_CONCAT(CONCAT(IFNULL(t_SPO.id_stock, '(No Supplier Purchase Order)'), ' - ', t_SPO.id_currency_cost) SEPARATOR ', ') - ) AS msg - FROM tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - LEFT JOIN partsltd_prod.Shop_Unit_Measurement UM ON t_SPOPL.id_unit_quantity = UM.id_unit_measurement - WHERE 1=1 - AND ( - ISNULL(UM.id_unit_measurement) - OR UM.active = 0 - ) - ; - END IF; - -- Invalid quantity ordered - IF EXISTS ( - SELECT * - FROM tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - WHERE - ISNULL(t_SPOPL.quantity_ordered) - OR t_SPOPL.quantity_ordered <= 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, code, msg - ) - SELECT - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT( - 'A valid quantity ordered is required for the following Supplier Purchase Order Item(s): ' - , GROUP_CONCAT(t_SPOPL.name_error SEPARATOR ', ') - ) - FROM tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - WHERE - ISNULL(t_SPOPL.quantity_ordered) - OR t_SPOPL.quantity_ordered <= 0 - ; - END IF; - -- Invalid quantity received - IF EXISTS ( - SELECT * - FROM tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - WHERE t_SPOPL.quantity_received < 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, code, msg - ) - SELECT - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT( - 'A valid quantity received is required for the following Supplier Purchase Order Item(s): ' - , GROUP_CONCAT(t_SPOPL.name_error, ' - ', t_SPOPL.quantity_received SEPARATOR ', ') - ) - FROM tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - WHERE t_SPOPL.quantity_received < 0 - ; - END IF; - -- Invalid delivery latency - IF EXISTS ( - SELECT * - FROM tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - WHERE t_SPOPL.latency_delivery_days < 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, code, msg - ) - SELECT - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT( - 'A valid delivery latency is required for the following Supplier Purchase Order Item(s): ' - , GROUP_CONCAT(t_SPOPL.name_error, ' - ', t_SPOPL.latency_delivery_days SEPARATOR ', ') - ) - FROM tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - WHERE t_SPOPL.latency_delivery_days < 0 - ; - END IF; - - -- Duplicates - IF EXISTS ( - SELECT - id_permutation - , name_error - , COUNT(*) - FROM tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - GROUP BY id_permutation, name_error - HAVING COUNT(*) > 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, code, msg - ) - SELECT - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Duplicate records: ', GROUP_CONCAT(t_SPOPLC.name_error SEPARATOR ', ')) - FROM ( - SELECT - id_permutation - , name_error - , COUNT(*) - FROM tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - GROUP BY id_permutation, name_error - HAVING COUNT(*) > 1 - ) t_SPOPLC - ; - END IF; - -- Empty Supplier Purchase Order - IF EXISTS ( SELECT * FROM tmp_Supplier_Purchase_Order t_SPO LEFT JOIN tmp_Supplier_Purchase_Order_Product_Link t_SPOPL ON t_SPO.id_order = t_SPOPL.id_order WHERE ISNULL(t_SPOPL.id_order) ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, code, msg - ) - SELECT - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT( - 'There are no items in the following Supplier Purchase Order(s): ' - , GROUP_CONCAT(t_SPO.name_error SEPARATOR ', ') - ) AS msg - FROM tmp_Supplier_Purchase_Order t_SPO - LEFT JOIN tmp_Supplier_Purchase_Order_Product_Link t_SPOPL ON t_SPO.id_order = t_SPOPL.id_order - WHERE ISNULL(t_SPOPL.id_order) - ; - END IF; - - -- Supplier Purchase Order Items without Order - IF EXISTS ( - SELECT * - FROM tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - LEFT JOIN tmp_Supplier_Purchase_Order t_SPO ON t_SPOPL.id_order = t_SPO.id_order - WHERE ISNULL(t_SPO.id_order) - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, code, msg - ) - SELECT - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT( - 'There is no order for the following Supplier Purchase Order Item(s): ' - , GROUP_CONCAT(t_SPOPL.name_error SEPARATOR ', ') - ) AS msg - FROM tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - LEFT JOIN tmp_Supplier_Purchase_Order t_SPO ON t_SPOPL.id_order = t_SPO.id_order - WHERE ISNULL(t_SPO.id_order) - ; - END IF; - - -- Permissions - SET v_ids_product_permission := ( - SELECT - GROUP_CONCAT(DISTINCT PP.id_product SEPARATOR ',') - FROM tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - INNER JOIN partsltd_prod.Shop_Product_Permutation PP ON t_SPOPL.id_permutation = PP.id_permutation - ); - IF a_debug = 1 THEN - SELECT - a_guid - , a_id_user - , FALSE -- get inactive users - , v_id_permission_supplier_purchase_order - , v_id_access_level_edit - , v_ids_product_permission -- ids_product - , 0 -- a_debug - ; - SELECT * from partsltd_prod.Shop_Calc_User_Temp; - END IF; - - CALL p_shop_calc_user( - a_guid - , a_id_user - , FALSE -- get inactive users - , v_id_permission_supplier_purchase_order - , v_id_access_level_edit - , v_ids_product_permission -- ids_product - , 0 -- a_debug - ); - - IF a_debug = 1 THEN - SELECT * from partsltd_prod.Shop_Calc_User_Temp WHERE GUID = a_guid; - END IF; - - UPDATE tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - INNER JOIN partsltd_prod.Shop_Calc_User_Temp CUT - ON t_SPOPL.id_product = t_SPOPL.id_product - AND CUT.GUID = a_guid - SET - t_SPOPL.can_edit = CUT.can_edit - ; - - IF EXISTS (SELECT * FROM tmp_Supplier_Purchase_Order_Product_Link WHERE can_edit = 0) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_no_permission - , v_code_type_error_no_permission - , CONCAT( - 'You do not permissions to edit the following Product(s): ' - , GROUP_CONCAT(P.name SEPARATOR ', ') - ) AS msg - FROM tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - INNER JOIN partsltd_prod.Shop_Product P ON t_SPOPL.id_product = P.id_product - WHERE - t_SPOPL.is_new = 0 - AND t_SPOPL.can_view = 0 - ; - END IF; - - IF EXISTS (SELECT * FROM tmp_Supplier_Purchase_Order_Product_Link WHERE is_new = 0 AND can_edit = 0 LIMIT 1) THEN - DELETE FROM tmp_Msg_Error; - - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_no_permission - , v_code_type_error_no_permission - , CONCAT( - 'You are missing the following permissions with access level ' - , AL.name - , ': ' - , GROUP_CONCAT(PERM.name SEPARATOR ', ') - ) AS msg - FROM partsltd_prod.Shop_Access_Level AL - CROSS JOIN partsltd_prod.Shop_Calc_User_Temp CU_T - ON CU_T.GUID = a_guid - AND ISNULL(CU_T.id_product) - AND IFNULL(CU_T.can_edit, 0) = 0 - ; - END IF; - - CALL partsltd_prod.p_shop_clear_calc_user( - a_guid - , 0 -- a_debug - ); - - IF EXISTS ( - SELECT * - FROM tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - INNER JOIN partsltd_prod.Shop_Supplier_Purchase_Order_Product_Link SPOPL ON t_SPOPL.id_link = SPOPL.id_link - INNER JOIN partsltd_prod.Shop_Stock_Item SI ON SPOPL.id_permutation = SI.id_permutation - WHERE - t_SPOPL.is_new = 0 - AND t_SPOPL.quantity_received <> SPOPL.quantity_received - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_warning - , v_code_type_error_warning - , CONCAT( - 'The quantity received has changed on the following orders. Please update the stock items appropriately.' - , GROUP_CONCAT( - CONCAT( - t_SPOPL.name_error - , ' - from ' - , SPOPL.quantity_received - , ' to ' - , t_SPOPL.quantity_received - ) SEPARATOR ', ' - ) - ) AS msg - ; - END IF; - - IF EXISTS ( SELECT * FROM tmp_Msg_Error LIMIT 1 ) THEN - DELETE FROM tmp_Supplier_Purchase_Order; - DELETE FROM tmp_Supplier_Purchase_Order_Product_Link; - END IF; - - -- Transaction - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - START TRANSACTION; - INSERT INTO Shop_Sales_And_Purchasing_Change_Set ( - comment - , updated_last_by - , updated_last_on - ) - VALUES ( - a_comment - , a_id_user - , v_time_start - ); - - SET v_id_change_set := LAST_INSERT_ID(); - - INSERT INTO partsltd_prod.Shop_Supplier_Purchase_Order ( - id_order_temp - , id_supplier_ordered - , id_currency_cost - , cost_total_local_VAT_excl - , cost_total_local_VAT_incl - , active - , created_by - , created_on - , id_change_set - ) - SELECT - t_SPO.id_order_temp - , t_SPO.id_supplier_ordered - , t_SPO.id_currency_cost - , t_SPO.cost_total_local_VAT_excl - , t_SPO.cost_total_local_VAT_incl - , t_SPO.active - , a_id_user - , v_time_start - , v_id_change_set - FROM tmp_Supplier_Purchase_Order t_SPO - INNER JOIN tmp_Supplier_Purchase_Order_Product_Link t_SPOPL ON t_SPO.id_order = t_SPOPL.id_order - WHERE t_SPOPL.is_new = 1 - GROUP BY t_SPO.id_order - ; - - UPDATE partsltd_prod.Shop_Supplier_Purchase_Order SPO - INNER JOIN tmp_Supplier_Purchase_Order t_SPO - ON SPO.id_order = t_SPO.id_order - AND t_SPO.is_new = 0 - INNER JOIN tmp_Supplier_Purchase_Order_Product_Link t_SPOPL ON t_SPO.id_order = t_SPOPL.id_order - SET - SPO.id_supplier_ordered = t_SPO.id_supplier_ordered - , SPO.id_currency_cost = t_SPO.id_currency_cost - , SPO.cost_total_local_VAT_excl = t_SPO.cost_total_local_VAT_excl - , SPO.cost_total_local_VAT_incl = t_SPO.cost_total_local_VAT_incl - , SPO.active = t_SPO.active - , SPO.id_change_set = v_id_change_set - ; - - - UPDATE tmp_Supplier_Purchase_Order t_SPO - INNER JOIN partsltd_prod.Shop_Supplier_Purchase_Order SPO - ON t_SPO.id_order_temp = SPO.id_order_temp - AND SPO.id_change_set = v_id_change_set - SET - t_SPO.id_order = SPO.id_order - WHERE t_SPO.is_new = 1 - ; - - UPDATE tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - INNER JOIN tmp_Supplier_Purchase_Order t_SPO ON t_SPOPL.id_order = t_SPO.id_order_temp - SET - t_SPOPL.id_order = t_SPO.id_order - WHERE t_SPO.is_new = 1 - ; - - - INSERT INTO Shop_Supplier_Purchase_Order_Product_Link ( - id_order - , id_permutation - , id_unit_quantity - , quantity_ordered - , quantity_received - , latency_delivery_days - , display_order - , active - , cost_total_local_VAT_excl - , cost_total_local_VAT_incl - , cost_unit_local_VAT_excl - , cost_unit_local_VAT_incl - , created_by - , created_on - , id_change_set - ) - SELECT - t_SPOPL.id_order - , t_SPOPL.id_permutation - , t_SPOPL.id_unit_quantity - , t_SPOPL.quantity_ordered - , t_SPOPL.quantity_received - , t_SPOPL.latency_delivery_days - , t_SPOPL.display_order - , t_SPOPL.active - , t_SPOPL.cost_total_local_VAT_excl - , t_SPOPL.cost_total_local_VAT_incl - , t_SPOPL.cost_unit_local_VAT_excl - , t_SPOPL.cost_unit_local_VAT_incl - , a_id_user - , v_time_start - , v_id_change_set - FROM tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - WHERE t_SPOPL.is_new = 1 - ; - - UPDATE partsltd_prod.Shop_Supplier_Purchase_Order_Product_Link SPOPL - INNER JOIN tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - ON SPOPL.id_link = t_SPOPL.id_link - AND t_SPOPL.is_new = 0 - SET - SPOPL.id_order = t_SPOPL.id_order - , SPOPL.id_permutation = t_SPOPL.id_permutation - , SPOPL.id_unit_quantity = t_SPOPL.id_unit_quantity - , SPOPL.quantity_ordered = t_SPOPL.quantity_ordered - , SPOPL.quantity_received = t_SPOPL.quantity_received - , SPOPL.latency_delivery_days = t_SPOPL.latency_delivery_days - , SPOPL.display_order = t_SPOPL.display_order - , SPOPL.active = t_SPOPL.active - , SPOPL.cost_total_local_VAT_excl = t_SPOPL.cost_total_local_VAT_excl - , SPOPL.cost_total_local_VAT_incl = t_SPOPL.cost_total_local_VAT_incl - , SPOPL.cost_unit_local_VAT_excl = t_SPOPL.cost_unit_local_VAT_excl - , SPOPL.cost_unit_local_VAT_incl = t_SPOPL.cost_unit_local_VAT_incl - , SPOPL.id_change_set = v_id_change_set - ; - - COMMIT; - END IF; - - START TRANSACTION; - - DELETE SPO_T - FROM Shop_Supplier_Purchase_Order_Temp SPO_T - WHERE SPO_T.GUID = a_guid - ; - DELETE SPOPL_T - FROM Shop_Supplier_Purchase_Order_Product_Link_Temp SPOPL_T - WHERE SPOPL_T.GUID = a_guid - ; - - COMMIT; - - -- Errors - SELECT * - FROM tmp_Msg_Error t_ME - INNER JOIN partsltd_prod.Shop_Msg_Error_Type MET ON t_ME.id_type = MET.id_type - ; - - IF a_debug = 1 THEN - SELECT * from tmp_Supplier_Purchase_Order; - SELECT * from tmp_Supplier_Purchase_Order_Product_Link; - END IF; - - DROP TEMPORARY TABLE tmp_Supplier_Purchase_Order; - DROP TEMPORARY TABLE tmp_Supplier_Purchase_Order_Product_Link; - DROP TEMPORARY TABLE tmp_Msg_Error; - - IF a_debug = 1 THEN - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); - END IF; -END // -DELIMITER ; - - -/* - -DELETE FROM Shop_Supplier_Purchase_Order_Product_Link_Audit; -DELETE FROM Shop_Supplier_Purchase_Order_Product_Link; -DELETE FROM Shop_Supplier_Purchase_Order_Product_Link_Temp; -DELETE FROM Shop_Supplier_Purchase_Order_Audit; -DELETE FROM Shop_Supplier_Purchase_Order; - -INSERT INTO Shop_Supplier_Purchase_Order_Product_Link_Temp ( - guid, - id_link, - id_order, - id_permutation, - cost_total_local, - id_currency_cost, - quantity_ordered, - id_unit_quantity, - quantity_received, - latency_delivery_days, - display_order, - active -) -VALUES - ( - 'NIPS', -- guid - -1, -- id_link, - -1, -- id_order, - 1, -- id_permutation, - 100, -- cost_total_local, - 1, -- id_currency_cost, - 1, -- quantity_ordered, - 1, -- id_unit_quantity, - 1, -- quantity_received, - 14, -- latency_delivery_days , - 1, -- display_order - 1 -- active - ) -; - -SELECT * FROM Shop_Supplier_Purchase_Order_Product_Link_Temp; - -CALL p_shop_save_supplier_purchase_order ( - 'NIPS', -- a_guid - 'auth0|6582b95c895d09a70ba10fef', -- a_id_user - -1, -- a_id_order - 1, -- a_id_supplier_ordered - 1 -- a_id_currency_cost -); - -SELECT * FROM Shop_Supplier_Purchase_Order_Product_Link_Temp; - -DELETE FROM Shop_Supplier_Purchase_Order_Product_Link_Audit; -DELETE FROM Shop_Supplier_Purchase_Order_Product_Link; -DELETE FROM Shop_Supplier_Purchase_Order_Product_Link_Temp; -DELETE FROM Shop_Supplier_Purchase_Order_Audit; -DELETE FROM Shop_Supplier_Purchase_Order; - - -*/ - - - --- File: 7403_p_shop_save_supplier_purchase_order_test.sql - - --- Clear previous proc -DROP PROCEDURE IF EXISTS partsltd_prod.p_shop_save_supplier_purchase_order_test; - - -DELIMITER // -CREATE PROCEDURE p_shop_save_supplier_purchase_order_test () -BEGIN - - DECLARE v_guid BINARY(36); - DECLARE v_time_start TIMESTAMP(6); - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_guid := 'nips'; - - SELECT * - FROM partsltd_prod.Shop_Supplier_Purchase_Order - ; - SELECT * - FROM partsltd_prod.Shop_Supplier_Purchase_Order_Temp - ; - SELECT * - FROM partsltd_prod.Shop_Supplier_Purchase_Order_Product_Link - ; - SELECT * - FROM partsltd_prod.Shop_Supplier_Purchase_Order_Product_Link_Temp - ; - - START TRANSACTION; - - DELETE FROM partsltd_prod.Shop_Supplier_Purchase_Order_Temp; - DELETE FROM partsltd_prod.Shop_Supplier_Purchase_Order_Product_Link_Temp; - - INSERT INTO partsltd_prod.Shop_Supplier_Purchase_Order_Temp ( - id_order - , id_supplier_ordered - , id_currency_cost - , active - , GUID - ) - /* Test 1 - Insert */ - VALUES ( - -1 - , 1 - , 1 - , 1 - , v_guid - ) - /* Test 2 - Update - SELECT - id_order - , id_supplier_ordered - , id_currency_cost - , active - , v_guid - FROM partsltd_prod.Shop_Supplier_Purchase_Order - WHERE id_order = 6 - */ - ; - INSERT INTO partsltd_prod.Shop_Supplier_Purchase_Order_Product_Link_Temp ( - id_link - , id_order - , id_permutation - , id_unit_quantity - , quantity_ordered - , quantity_received - , latency_delivery_days - , display_order - , active - , cost_total_local_VAT_excl - , cost_total_local_VAT_incl - , GUID - ) - /* Test 1 - Insert */ - VALUES ( - -1 - , -1 - , 3 - , 3 - , 3 - , 1 - , 7 - , 1 - , 1 - , 5 - , 6 - , v_guid - ) - /* Test 2 - Update - SELECT - id_link - , id_order - , id_permutation - , id_unit_quantity - , 5 AS quantity_ordered - , quantity_received - , latency_delivery_days - , display_order - , active - , cost_total_local_VAT_excl - , cost_total_local_VAT_incl - , v_guid - FROM partsltd_prod.Shop_Supplier_Purchase_Order_Product_Link - WHERE id_order = 6 - */ - ; - - COMMIT; - - SELECT * - FROM partsltd_prod.Shop_Supplier_Purchase_Order_Temp - WHERE GUID = v_guid - ; - - SELECT * - FROM partsltd_prod.Shop_Supplier_Purchase_Order_Product_Link_Temp - WHERE GUID = v_guid - ; - - CALL partsltd_prod.p_shop_save_supplier_purchase_order ( - 'Test save Supplier Purchase Order' -- comment - , v_guid -- guid - , 1 -- id_user - , 1 -- debug - ); - - SELECT * - FROM partsltd_prod.Shop_Supplier_Purchase_Order_Temp - ; - SELECT * - FROM partsltd_prod.Shop_Supplier_Purchase_Order_Product_Link_Temp - ; - SELECT * - FROM partsltd_prod.Shop_Supplier_Purchase_Order - ; - SELECT * - FROM partsltd_prod.Shop_Supplier_Purchase_Order_Product_Link - ; - - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); -END // -DELIMITER ; - -/* -CALL partsltd_prod.p_shop_save_supplier_purchase_order_test (); - -DELETE FROM partsltd_prod.Shop_Supplier_Purchase_Order_Temp; -DELETE FROM partsltd_prod.Shop_Supplier_Purchase_Order_Product_Link_Temp; - -DROP TABLE IF EXISTS tmp_Msg_Error; - -Cannot add or update a child row: a foreign key constraint fails (`partsltd_prod`.`shop_supplier_address`, CONSTRAINT `FK_Shop_Supplier_Address_id_supplier` FOREIGN KEY (`id_supplier`) REFERENCES `shop_supplier` (`id_supplier`) ON UPDATE RESTRICT) - -*/ - --- File: 7404_p_shop_get_many_supplier_purchase_order.sql - - -DROP PROCEDURE IF EXISTS p_shop_get_many_supplier_purchase_order; - -DELIMITER // -CREATE PROCEDURE p_shop_get_many_supplier_purchase_order ( - IN a_id_user INT, - IN a_get_all_supplier BIT, - IN a_get_inactive_supplier BIT, - IN a_ids_supplier TEXT, - IN a_get_all_order BIT, - IN a_get_inactive_order BIT, - IN a_ids_order TEXT, - IN a_ids_permutation TEXT, - IN a_date_from DATETIME, - IN a_date_to DATETIME, - IN a_debug BIT -) -BEGIN - DECLARE v_code_type_error_bad_data VARCHAR(50); - DECLARE v_code_type_error_no_permission VARCHAR(50); - DECLARE v_guid BINARY(36); - DECLARE v_has_filter_supplier BIT; - DECLARE v_has_filter_order BIT; - DECLARE v_has_filter_permutation BIT; - DECLARE v_has_filter_date_from BIT; - DECLARE v_has_filter_date_to BIT; - DECLARE v_id_access_level_view INT; - DECLARE v_ids_permission_supplier_purchase_order VARCHAR(100); - DECLARE v_id_type_error_bad_data INT; - DECLARE v_id_type_error_no_permission INT; - DECLARE v_time_start TIMESTAMP(6); - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_guid := UUID(); - SET v_id_access_level_view := (SELECT id_access_level FROM partsltd_prod.Shop_Access_Level WHERE code = 'VIEW' LIMIT 1); - SET v_code_type_error_bad_data := (SELECT code FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1); - SET v_id_type_error_bad_data := (SELECT id_type FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = v_code_type_error_bad_data LIMIT 1); - SET v_code_type_error_no_permission := (SELECT code FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = 'NO_PERMISSION' LIMIT 1); - SET v_id_type_error_no_permission := (SELECT id_type FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = v_code_type_error_no_permission LIMIT 1); - SET v_ids_permission_supplier_purchase_order := (SELECT GROUP_CONCAT(id_permission SEPARATOR ',') FROM partsltd_prod.Shop_Permission WHERE code IN ('STORE_SUPPLIER', 'STORE_SUPPLIER_PURCHASE_ORDER', 'STORE_PRODUCT')); - - SET a_get_all_supplier := IFNULL(a_get_all_supplier, 1); - SET a_get_inactive_supplier := IFNULL(a_get_inactive_supplier, 0); - SET a_ids_supplier := TRIM(IFNULL(a_ids_supplier, '')); - SET a_get_all_order := IFNULL(a_get_all_order, 1); - SET a_get_inactive_order := IFNULL(a_get_inactive_order, 0); - SET a_ids_order := TRIM(IFNULL(a_ids_order, '')); - SET a_ids_permutation := TRIM(IFNULL(a_ids_permutation, '')); - SET a_date_from := IFNULL(a_date_from, NULL); - SET a_date_to := IFNULL(a_date_to, NULL); - SET a_debug := IFNULL(a_debug, 0); - - DROP TEMPORARY TABLE IF EXISTS tmp_Supplier_Purchase_Order_Product_Link; - DROP TEMPORARY TABLE IF EXISTS tmp_Supplier_Purchase_Order; - DROP TEMPORARY TABLE IF EXISTS tmp_Supplier; - DROP TEMPORARY TABLE IF EXISTS tmp_Permutation; - DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error; - DROP TEMPORARY TABLE IF EXISTS tmp_Split; - - CREATE TEMPORARY TABLE tmp_Supplier ( - id_supplier INT NOT NULL PRIMARY KEY - ); - - CREATE TEMPORARY TABLE tmp_Supplier_Purchase_Order ( - id_order INT NOT NULL PRIMARY KEY - ); - - CREATE TEMPORARY TABLE tmp_Permutation ( - id_permutation INT NOT NULL PRIMARY KEY - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - id_type INT NOT NULL, - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Split ( - substring VARCHAR(4000) NOT NULL - , as_int INT NULL - ); - DELETE FROM tmp_Split; - - SET v_has_filter_supplier = CASE WHEN a_ids_supplier = '' THEN 0 ELSE 1 END; - SET v_has_filter_order = CASE WHEN a_ids_order = '' THEN 0 ELSE 1 END; - SET v_has_filter_permutation = CASE WHEN a_ids_permutation = '' THEN 0 ELSE 1 END; - SET v_has_filter_date_from = CASE WHEN ISNULL(a_date_from) THEN 0 ELSE 1 END; - SET v_has_filter_date_to = CASE WHEN ISNULL(a_date_to) THEN 0 ELSE 1 END; - - IF a_debug = 1 THEN - SELECT - v_has_filter_supplier, - v_has_filter_order, - v_has_filter_permutation, - v_has_filter_date_from, - v_has_filter_date_to - ; - END IF; - - -- Permutations - IF v_has_filter_permutation = 1 THEN - CALL partsltd_prod.p_split(v_guid, a_ids_permutation, ',', a_debug); - - INSERT INTO tmp_Split ( - substring - , as_int - ) - SELECT - substring - , CONVERT(substring, DECIMAL(10,0)) AS as_int - FROM partsltd_prod.Split_Temp - WHERE 1=1 - AND GUID = v_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( v_guid ); - END IF; - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Product_Permutation PP ON t_S.as_int = PP.id_permutation - WHERE - ISNULL(t_S.as_int) - OR ISNULL(PP.id_permutation) - OR PP.active = 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - code, - msg - ) - SELECT - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Invalid or inactive permutation IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Product_Permutation PP ON t_S.as_int = PP.id_permutation - WHERE - ISNULL(t_S.as_int) - OR ISNULL(PP.id_permutation) - OR PP.active = 0 - ; - ELSE - INSERT INTO tmp_Permutation ( - id_permutation - ) - SELECT - PP.id_permutation - FROM tmp_Split t_S - RIGHT JOIN partsltd_prod.Shop_Product_Permutation PP ON t_S.as_int = PP.id_permutation - WHERE ( - v_has_filter_permutation = 0 - OR NOT ISNULL(t_S.as_int) - ) - ; - END IF; - END IF; - - DELETE FROM tmp_Split; - - -- Suppliers - IF v_has_filter_supplier = 1 THEN - CALL partsltd_prod.p_split(v_guid, a_ids_supplier, ',', a_debug); - - INSERT INTO tmp_Split ( - substring - , as_int - ) - SELECT - substring - , CONVERT(substring, DECIMAL(10,0)) AS as_int - FROM partsltd_prod.Split_Temp - WHERE 1=1 - AND GUID = v_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( v_guid ); - END IF; - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Supplier S ON t_S.as_int = S.id_supplier - WHERE - ISNULL(t_S.as_int) - OR ISNULL(S.id_supplier) - OR ( - S.active = 0 - AND a_get_inactive_supplier = 0 - ) - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - code, - msg - ) - SELECT - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Invalid or inactive Supplier IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Supplier S ON t_S.as_int = S.id_supplier - WHERE - ISNULL(t_S.as_int) - OR ISNULL(S.id_supplier) - OR ( - S.active = 0 - AND a_get_inactive_supplier = 0 - ) - ; - ELSE - INSERT INTO tmp_Supplier ( - id_supplier - ) - SELECT - S.id_supplier - FROM tmp_Split t_S - RIGHT JOIN partsltd_prod.Shop_Supplier S ON t_S.as_int = S.id_supplier - WHERE ( - a_get_all_supplier = 1 - OR ( - v_has_filter_supplier = 1 - AND NOT ISNULL(t_S.as_int) - ) - ) - AND ( - a_get_inactive_supplier = 1 - OR S.active = 1 - ) - ; - END IF; - END IF; - - DELETE FROM tmp_Split; - - -- Supplier Purchase Orders - IF v_has_filter_order = 1 THEN - CALL partsltd_prod.p_split(v_guid, a_ids_order, ',', a_debug); - - INSERT INTO tmp_Split ( - substring - , as_int - ) - SELECT - substring - , CONVERT(substring, DECIMAL(10,0)) AS as_int - FROM partsltd_prod.Split_Temp - WHERE 1=1 - AND GUID = v_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( v_guid ); - END IF; - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Supplier_Purchase_Order SPO ON t_S.as_int = SPO.id_order - WHERE - ISNULL(t_S.as_int) - OR ISNULL(SPO.id_order) - OR ( - SPO.active = 0 - AND a_get_inactive_order = 0 - ) - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - code, - msg - ) - SELECT - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Invalid or inactive Supplier Purchase Order IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Supplier_Purchase_Order SPO ON t_S.as_int = SPO.id_order - WHERE - ISNULL(t_S.as_int) - OR ISNULL(SPO.id_order) - OR ( - SPO.active = 0 - AND a_get_inactive_order = 0 - ) - ; - ELSE - INSERT INTO tmp_Supplier_Purchase_Order ( - id_order - ) - SELECT - SPO.id_order - FROM tmp_Split t_S - RIGHT JOIN partsltd_prod.Shop_Supplier_Purchase_Order SPO ON t_S.as_int = SPO.id_order - INNER JOIN tmp_Supplier t_SUPP ON SPO.id_supplier_ordered = t_SUPP.id_supplier - INNER JOIN partsltd_prod.Shop_Supplier_Purchase_Order_Product_Link SPOPL ON SPO.id_order = SPOPL.id_order - INNER JOIN tmp_Permutation t_PP ON SPOPL.id_permutation = t_PP.id_permutation - WHERE ( - a_get_all_order = 1 - OR ( - v_has_filter_order = 1 - AND NOT ISNULL(t_S.as_int) - ) - OR ( - v_has_filter_supplier = 1 - AND NOT ISNULL(t_SUPP.id_supplier) - ) - OR ( - v_has_filter_permutation = 1 - AND NOT ISNULL(t_PP.id_permutation) - ) - ) - AND ( - a_get_inactive_order = 1 - OR SPO.active = 1 - ) - AND ( - v_has_filter_date_from = 0 - OR SPO.created_on > a_date_from - ) - AND ( - v_has_filter_date_to = 0 - OR SPO.created_on < a_date_to - ) - - ; - END IF; - END IF; - - DELETE FROM tmp_Split; - - -- Permissions - IF a_debug = 1 THEN - SELECT - v_guid - , a_id_user - , FALSE -- get inactive users - , v_ids_permission_supplier_purchase_order - , v_id_access_level_view - , '' -- ids_product - , 0 -- a_debug - ; - SELECT * from partsltd_prod.Shop_Calc_User_Temp; - END IF; - - CALL p_shop_calc_user( - v_guid - , a_id_user - , FALSE -- get inactive users - , v_ids_permission_supplier_purchase_order - , v_id_access_level_view - , '' -- ids_product - , 0 -- a_debug - ); - - IF a_debug = 1 THEN - SELECT * from partsltd_prod.Shop_Calc_User_Temp; - END IF; - - IF NOT EXISTS (SELECT can_view FROM partsltd_prod.Shop_Calc_User_Temp UE_T WHERE UE_T.GUID = v_guid) THEN - DELETE FROM tmp_Msg_Error; - - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - VALUES ( - v_id_type_error_no_permission - , v_code_type_error_no_permission - , CONCAT('You do not have view permissions for ', (SELECT name FROM partsltd_prod.Shop_Permission WHERE id_permission = v_ids_permission_supplier_purchase_order LIMIT 1)) - ) - ; - END IF; - - IF EXISTS ( SELECT * FROM tmp_Msg_Error LIMIT 1 ) THEN - DELETE FROM tmp_Permutation; - DELETE FROM tmp_Supplier_Purchase_Order; - END IF; - - -- Returns - /* - -- Suppliers - SELECT - t_S.id_supplier, - S.name_company, - S.name_contact, - S.department_contact, - S.id_address, - S.phone_number, - S.fax, - S.email, - S.website, - S.id_currency, - t_S.active - FROM tmp_Supplier t_S - INNER JOIN partsltd_prod.Shop_Supplier S - ON t_S.id_supplier = S.id_supplier - ; - */ - - -- Supplier Purchase Order - SELECT - t_SPO.id_order - , SPO.id_supplier_ordered - , S.name_company - , SPO.id_currency_cost - , C.symbol - , C.code - , SPO.cost_total_local_VAT_excl - , SPO.cost_total_local_VAT_incl - , SPO.active - , SPO.created_on - , CONCAT( - SPO.cost_total_local_VAT_excl - , ' on ' - , SPO.created_on - ) AS name - FROM tmp_Supplier_Purchase_Order t_SPO - INNER JOIN partsltd_prod.Shop_Supplier_Purchase_Order SPO ON SPO.id_order = t_SPO.id_order - LEFT JOIN partsltd_prod.Shop_Supplier S ON SPO.id_supplier_ordered = S.id_supplier - LEFT JOIN partsltd_prod.Shop_Currency C ON SPO.id_currency_cost = C.id_currency - ; - - -- Supplier Purchase Order Product Link - SELECT - SPOPL.id_link - , SPOPL.id_order - , P.id_category - , P.id_product - , SPOPL.id_permutation - , fn_shop_get_product_permutation_name(SPOPL.id_permutation) AS name_permutation - , fn_shop_get_product_permutation_variations_csv(SPOPL.id_permutation) AS csv_id_pairs_variation - -- , SPOPL.id_currency_cost - , SPOPL.id_unit_quantity - , SPOPL.quantity_ordered - , SPOPL.quantity_received - , SPOPL.latency_delivery_days - , SPOPL.display_order - , SPOPL.cost_total_local_VAT_excl - , SPOPL.cost_total_local_VAT_incl - , SPOPL.cost_unit_local_VAT_excl - , SPOPL.cost_unit_local_VAT_incl - , SPOPL.active - FROM tmp_Supplier_Purchase_Order t_SPO - INNER JOIN partsltd_prod.Shop_Supplier_Purchase_Order_Product_Link SPOPL ON t_SPO.id_order = SPOPL.id_order - LEFT JOIN partsltd_prod.Shop_Product_Permutation PP ON SPOPL.id_permutation = PP.id_permutation - LEFT JOIN partsltd_prod.Shop_Product P ON PP.id_product = P.id_product - ; - - -- Errors - SELECT * - FROM tmp_Msg_Error t_ME - INNER JOIN partsltd_prod.Shop_Msg_Error_Type MET ON t_ME.id_type = MET.id_type - ; - - IF a_debug = 1 THEN - SELECT * from tmp_Supplier_Purchase_Order_Product_Link; - SELECT * from tmp_Supplier_Purchase_Order; - SELECT * from tmp_Supplier; - END IF; - - DROP TEMPORARY TABLE IF EXISTS tmp_Supplier_Purchase_Order_Product_Link; - DROP TEMPORARY TABLE IF EXISTS tmp_Supplier_Purchase_Order; - DROP TEMPORARY TABLE IF EXISTS tmp_Supplier; - DROP TEMPORARY TABLE IF EXISTS tmp_Permutation; - DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error; - DROP TEMPORARY TABLE IF EXISTS tmp_Split; - - IF a_debug = 1 THEN - CALL p_debug_timing_reporting( v_time_start ); - END IF; -END // -DELIMITER ; - - -/* - -CALL p_shop_get_many_supplier_purchase_order ( - 1, -- a_id_user - 1, -- a_get_all_supplier - 0, -- a_get_inactive_supplier - '', -- a_ids_supplier - 1, -- a_get_all_order - 0, -- a_get_inactive_order - '', -- a_ids_order - '', -- a_ids_permutation - NULL, -- a_date_from - NULL -- a_date_to - , 0 -- a_debug -); - -*/ - - --- File: 7415_p_shop_save_manufacturing_purchase_order.sql - - - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_save_manufacturing_purchase_order; - -DROP TABLE IF EXISTS tmp_Manufacturing_Purchase_Order_Product_Link; -DROP TABLE IF EXISTS tmp_Msg_Error; - -DELIMITER // -CREATE PROCEDURE p_shop_save_manufacturing_purchase_order ( - IN a_comment VARCHAR(500) - , IN a_guid BINARY(36) - , IN a_id_user INT - , IN a_debug BIT -) -BEGIN - DECLARE v_code_type_error_bad_data VARCHAR(50); - DECLARE v_code_type_error_no_permission VARCHAR(50); - DECLARE v_code_type_error_warning VARCHAR(50); - DECLARE v_id_access_level_edit INT; - DECLARE v_id_change_set INT; - DECLARE v_ids_permission_manufacturing_purchase_order VARCHAR(100); - DECLARE v_id_type_error_bad_data INT; - DECLARE v_id_type_error_no_permission INT; - DECLARE v_id_type_error_warning INT; - DECLARE v_ids_product_permission TEXT; - DECLARE v_time_start TIMESTAMP(6); - - DECLARE exit handler for SQLEXCEPTION - BEGIN - GET DIAGNOSTICS CONDITION 1 - @sqlstate = RETURNED_SQLSTATE - , @errno = MYSQL_ERRNO - , @text = MESSAGE_TEXT - ; - - ROLLBACK; - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT - , id_type INT NULL - , code VARCHAR(50) NOT NULL - , msg VARCHAR(4000) NOT NULL - ); - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - MET.id_type - , @errno - , @text - FROM partsltd_prod.Shop_Msg_Error_Type MET - WHERE code = 'MYSQL_ERROR' - ; - SELECT * - FROM tmp_Msg_Error; - DROP TABLE IF EXISTS tmp_Msg_Error; - END; - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_code_type_error_bad_data := (SELECT code FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1); - SET v_id_type_error_bad_data := (SELECT id_type FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = v_code_type_error_bad_data LIMIT 1); - SET v_code_type_error_no_permission := (SELECT code FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = 'NO_PERMISSION' LIMIT 1); - SET v_id_type_error_no_permission := (SELECT id_type FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = v_code_type_error_no_permission LIMIT 1); - SET v_code_type_error_warning := (SELECT code FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = 'WARNING' LIMIT 1); - SET v_id_type_error_warning := (SELECT id_type FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = v_code_type_error_warning LIMIT 1); - SET v_ids_permission_manufacturing_purchase_order := (SELECT GROUP_CONCAT(id_permission SEPARATOR ',') FROM partsltd_prod.Shop_Permission WHERE code IN ('STORE_MANUFACTURING_PURCHASE_ORDER', 'STORE_PRODUCT')); - SET v_id_access_level_edit := (SELECT id_access_level FROM partsltd_prod.Shop_Access_Level WHERE code = 'EDIT' LIMIT 1); - - CALL p_validate_guid ( a_guid ); - SET a_comment := TRIM(IFNULL(a_comment, '')); - - DROP TEMPORARY TABLE IF EXISTS tmp_Manufacturing_Purchase_Order; - DROP TEMPORARY TABLE IF EXISTS tmp_Manufacturing_Purchase_Order_Product_Link; - DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error; - - -- Temporary tables - CREATE TEMPORARY TABLE tmp_Manufacturing_Purchase_Order ( - id_order INT NOT NULL PRIMARY KEY - , id_order_temp INT NOT NULL - , id_currency INT NOT NULL - , active BIT NOT NULL - , is_new BIT NOT NULL - , name_error VARCHAR(1000) NOT NULL - , cost_total_local_VAT_excl FLOAT NULL - , cost_total_local_VAT_incl FLOAT NULL - , price_total_local_VAT_excl FLOAT NULL - , price_total_local_VAT_incl FLOAT NULL - ); - - CREATE TEMPORARY TABLE tmp_Manufacturing_Purchase_Order_Product_Link ( - id_link INT NOT NULL PRIMARY KEY - , id_order INT NOT NULL - , id_product INT NULL - , id_permutation INT NULL - , id_unit_quantity INT NOT NULL - , quantity_used FLOAT NOT NULL - , quantity_produced FLOAT NULL - , id_unit_latency_manufacture INT NULL - , latency_manufacture INT NULL - , display_order INT NOT NULL - , active BIT NOT NULL - , cost_unit_local_VAT_excl FLOAT NULL - , cost_unit_local_VAT_incl FLOAT NULL - , cost_total_local_VAT_excl FLOAT NULL - , cost_total_local_VAT_incl FLOAT NULL - , price_unit_local_VAT_excl FLOAT NULL - , price_unit_local_VAT_incl FLOAT NULL - , price_total_local_VAT_excl FLOAT NULL - , price_total_local_VAT_incl FLOAT NULL - , has_order BIT NULL - , is_new BIT NOT NULL - , name_error VARCHAR(1000) NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT - , id_type INT NOT NULL - , code VARCHAR(50) NOT NULL - , msg VARCHAR(4000) NOT NULL - ); - - INSERT INTO tmp_Manufacturing_Purchase_Order ( - id_order - , id_order_temp - , id_currency - , active - , is_new - , name_error - ) - SELECT - MPO_T.id_order - , MPO_T.id_order - , IFNULL(IFNULL(MPO_T.id_currency, MPO.id_currency), 0) AS id_currency - , IFNULL(IFNULL(MPO_T.active, MPO.active), 1) AS active - , IFNULL(MPO_T.id_order, 0) < 1 AS is_new - , CASE WHEN IFNULL(MPO_T.id_order, -1) < 0 THEN - CONCAT('New Manufacturing Purchase Order ', MPO_T.id_order) - ELSE - CONCAT( - IFNULL(IFNULL(MPO_T.id_order, MPO.id_order), '(No Manufacturing Purchase Order)') - , ' - ' - , IFNULL(IFNULL(MPO_T.id_currency, MPO.id_currency), '(No Currency)') - ) - END AS name_error - FROM partsltd_prod.Shop_Manufacturing_Purchase_Order_Temp MPO_T - LEFT JOIN partsltd_prod.Shop_Manufacturing_Purchase_Order MPO ON MPO_T.id_order = MPO.id_order - WHERE MPO_T.GUID = a_guid - ; - - INSERT INTO tmp_Manufacturing_Purchase_Order_Product_Link ( - id_link - , id_order - , id_product - , id_permutation - , id_unit_quantity - , quantity_used - , quantity_produced - , id_unit_latency_manufacture - , latency_manufacture - , display_order - , active - , cost_unit_local_VAT_excl - , cost_unit_local_VAT_incl - , price_unit_local_VAT_excl - , price_unit_local_VAT_incl - , has_order - , is_new - ) - SELECT - IFNULL(MPOPL_T.id_link, 0) AS id_link - , IFNULL(IFNULL(MPOPL_T.id_order, MPOPL.id_order), 0) AS id_order - , IFNULL(MPOPL_T.id_product, PP.id_product) AS id_product - , IFNULL( - IFNULL( - IFNULL( - MPOPL_T.id_permutation - , CASE WHEN NOT ISNULL(MPOPL_T.id_product) AND NOT ISNULL(MPOPL_T.csv_list_variations) THEN - partsltd_prod.fn_shop_get_id_product_permutation_from_variation_csv_list(MPOPL_T.id_product, MPOPL_T.csv_list_variations) - ELSE NULL END - ) - , MPOPL.id_permutation - ) - , 0 - ) AS id_permutation - , IFNULL(IFNULL(MPOPL_T.id_unit_quantity, MPOPL.id_unit_quantity), 0) AS id_unit_quantity - , MPOPL_T.quantity_used AS quantity_used - , MPOPL_T.quantity_produced AS quantity_produced - , MPOPL_T.id_unit_latency_manufacture AS id_unit_latency_manufacture - , MPOPL_T.latency_manufacture AS latency_manufacture - , IFNULL(MPOPL_T.display_order, RANK() OVER (PARTITION BY IFNULL(IFNULL(MPOPL_T.id_order, MPOPL.id_order), 0) ORDER BY IFNULL(IFNULL(MPOPL_T.display_order, MPOPL.display_order), 0))) AS display_order - , IFNULL(IFNULL(MPOPL_T.active, MPOPL.active), 1) AS active - -- , MPOPL_T.cost_total_local_VAT_excl / MPOPL_T.quantity_used AS cost_unit_local_VAT_excl - -- , MPOPL_T.cost_total_local_VAT_incl / MPOPL_T.quantity_used AS cost_unit_local_VAT_incl - , IFNULL(MPOPL_T.cost_unit_local_VAT_excl, MPOPL.cost_unit_local_VAT_excl) AS cost_unit_local_VAT_excl - , IFNULL(MPOPL_T.cost_unit_local_VAT_incl, MPOPL.cost_unit_local_VAT_incl) AS cost_unit_local_VAT_incl - , IFNULL(MPOPL_T.price_unit_local_VAT_excl, MPOPL.price_unit_local_VAT_excl) AS price_unit_local_VAT_excl - , IFNULL(MPOPL_T.price_unit_local_VAT_incl, MPOPL.price_unit_local_VAT_incl) AS price_unit_local_VAT_incl - , NOT ISNULL(t_MPO.id_order) AS has_order - , IFNULL(MPOPL_T.id_link, 0) < 1 AS is_new - FROM partsltd_prod.Shop_Manufacturing_Purchase_Order_Product_Link_Temp MPOPL_T - LEFT JOIN partsltd_prod.Shop_Manufacturing_Purchase_Order_Product_Link MPOPL ON MPOPL_T.id_link = MPOPL.id_link - LEFT JOIN tmp_Manufacturing_Purchase_Order t_MPO ON MPOPL_T.id_order = t_MPO.id_order - LEFT JOIN partsltd_prod.Shop_Product_Permutation PP ON MPOPL.id_permutation = PP.id_permutation - WHERE MPOPL_T.GUID = a_guid - ; - - UPDATE tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - -- INNER JOIN partsltd_prod.Shop_Manufacturing_Purchase_Order_Product_Link_Temp MPOPL_T ON t_MPOPL.id_order = MPOPL_T.id_order - LEFT JOIN partsltd_prod.Shop_Product_Permutation PP ON t_MPOPL.id_permutation = PP.id_permutation - LEFT JOIN partsltd_prod.Shop_Product P ON PP.id_product = P.id_product - LEFT JOIN partsltd_prod.Shop_Product_Category PC ON P.id_category = PC.id_category - SET - name_error = CONCAT( - CASE WHEN ISNULL(t_MPOPL.id_permutation) THEN - CASE WHEN ISNULL(PP.id_product) THEN - '(No Product Permutation)' - ELSE - CONCAT( - PC.name - , ' - ' - , P.name - ) - END - ELSE - fn_shop_get_product_permutation_name(PP.id_permutation) - END - , ' - x' - , IFNULL(t_MPOPL.quantity_used, '(No Quantity)') - , ' Used - x' - , IFNULL(t_MPOPL.quantity_produced, '(No Quantity)') - , ' Produced' - ) - , cost_total_local_VAT_excl = t_MPOPL.quantity_used * t_MPOPL.cost_unit_local_VAT_excl - , cost_total_local_VAT_incl = t_MPOPL.quantity_used * t_MPOPL.cost_unit_local_VAT_incl - , price_total_local_VAT_excl = t_MPOPL.quantity_produced * t_MPOPL.price_unit_local_VAT_excl - , price_total_local_VAT_incl = t_MPOPL.quantity_produced * t_MPOPL.price_unit_local_VAT_incl - ; - - -- Insert missing order records - INSERT INTO tmp_Manufacturing_Purchase_Order ( - id_order - , id_order_temp - , id_currency - , active - , is_new - , name_error - ) - SELECT - MPO.id_order - , MPO.id_order_temp - , MPO.id_currency - , MPO.active - , FALSE AS is_new - , CONCAT( - IFNULL(MPO.id_order, '(No Manufacturing Purchase Order)') - , ' - ' - , IFNULL(MPO.id_currency, '(No Currency)') - ) AS name_error - FROM partsltd_prod.Shop_Manufacturing_Purchase_Order MPO - INNER JOIN tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - ON MPO.id_order = t_MPOPL.id_order - AND t_MPOPL.has_order = 0 - ; - - UPDATE tmp_Manufacturing_Purchase_Order t_MPO - INNER JOIN ( - SELECT - t_MPOPL.id_order - , SUM(t_MPOPL.cost_total_local_VAT_excl) AS cost_total_local_VAT_excl - , SUM(t_MPOPL.cost_total_local_VAT_incl) AS cost_total_local_VAT_incl - , SUM(t_MPOPL.price_total_local_VAT_excl) AS price_total_local_VAT_excl - , SUM(t_MPOPL.price_total_local_VAT_incl) AS price_total_local_VAT_incl - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - GROUP BY t_MPOPL.id_order - ) SUM_t_MPOPL ON t_MPO.id_order = SUM_t_MPOPL.id_order - SET - t_MPO.cost_total_local_VAT_excl = SUM_t_MPOPL.cost_total_local_VAT_excl - , t_MPO.cost_total_local_VAT_incl = SUM_t_MPOPL.cost_total_local_VAT_incl - , t_MPO.price_total_local_VAT_excl = SUM_t_MPOPL.price_total_local_VAT_excl - , t_MPO.price_total_local_VAT_incl = SUM_t_MPOPL.price_total_local_VAT_incl - ; - - -- Validation - -- Manufacturing Purchase Order - -- id_order - IF EXISTS ( - SELECT * - FROM tmp_Manufacturing_Purchase_Order t_MPO - LEFT JOIN partsltd_prod.Shop_Manufacturing_Purchase_Order MPO ON t_MPO.id_order = MPO.id_order - WHERE 1=1 - AND t_MPO.id_order > 0 - AND ISNULL(MPO.id_order) - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT( - 'A valid ID is required for the following Manufacturing Purchase Order(s): ' - , GROUP_CONCAT(t_MPO.name_error SEPARATOR ', ') - ) AS msg - FROM tmp_Manufacturing_Purchase_Order t_MPO - LEFT JOIN partsltd_prod.Shop_Manufacturing_Purchase_Order MPO ON t_MPO.id_order = MPO.id_order - WHERE 1=1 - AND t_MPO.id_order > 0 - AND ISNULL(MPO.id_order) - ; - END IF; - -- id_currency - IF EXISTS ( - SELECT * - FROM tmp_Manufacturing_Purchase_Order t_MPO - LEFT JOIN partsltd_prod.Shop_Currency C ON t_MPO.id_currency = C.id_currency - WHERE 1=1 - AND ( - ISNULL(C.id_currency) - OR C.active = 0 - ) - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT( - 'A valid currency is required for the following Manufacturing Purchase Order(s): ' - , GROUP_CONCAT(CONCAT(t_MPO.name_error, ' - ', t_MPO.id_currency) SEPARATOR ', ') - ) AS msg - FROM tmp_Manufacturing_Purchase_Order t_MPO - LEFT JOIN partsltd_prod.Shop_Currency C ON t_MPO.id_currency = C.id_currency - WHERE 1=1 - AND ( - ISNULL(C.id_currency) - OR C.active = 0 - ) - ; - END IF; - -- id_unit_quantity - IF EXISTS ( - SELECT * - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - LEFT JOIN partsltd_prod.Shop_Unit_Measurement UM ON t_MPOPL.id_unit_quantity = UM.id_unit_measurement - WHERE 1=1 - AND ( - ISNULL(UM.id_unit_measurement) - OR UM.active = 0 - ) - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT( - 'A valid unit measurement of quantity is required for the following Manufacturing Purchase Order(s): ' - , GROUP_CONCAT(CONCAT(t_MPOPL.name_error, ' - ', t_MPO.id_unit_quantity) SEPARATOR ', ') - ) AS msg - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - LEFT JOIN partsltd_prod.Shop_Unit_Measurement UM ON t_MPOPL.id_unit_quantity = UM.id_unit_measurement - WHERE 1=1 - AND ( - ISNULL(UM.id_unit_measurement) - OR UM.active = 0 - ) - ; - END IF; - -- Invalid quantity used - IF EXISTS ( - SELECT * - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE - ISNULL(t_MPOPL.quantity_used) - OR t_MPOPL.quantity_used <= 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, code, msg - ) - SELECT - v_id_error_type_bad_data, - v_code_error_type_bad_data, - CONCAT( - 'A valid quantity used is required for the following Manufacturing Purchase Order Item(s): ' - , GROUP_CONCAT(CONCAT(t_MPOPL.name_error, ' - ', t_MPOPL.quantity_used) SEPARATOR ', ') - ) - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE - NOT ISNULL(t_MPOPL.quantity_used) - AND t_MPOPL.quantity_used <= 0 - ; - END IF; - -- Invalid quantity produced - IF EXISTS ( - SELECT * - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE - NOT ISNULL(t_MPOPL.quantity_produced) - AND t_MPOPL.quantity_produced < 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, code, msg - ) - SELECT - v_id_error_type_bad_data, - v_code_error_type_bad_data, - CONCAT( - 'A valid quantity produced is required for the following Manufacturing Purchase Order Item(s): ' - , GROUP_CONCAT(CONCAT(t_MPOPL.name_error, ' - ', t_MPOPL.quantity_produced) SEPARATOR ', ') - ) - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE - NOT ISNULL(t_MPOPL.quantity_produced) - AND t_MPOPL.quantity_produced < 0 - ; - END IF; - -- id_unit_latency_manufacture - IF EXISTS ( - SELECT * - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - LEFT JOIN partsltd_prod.Shop_Unit_Measurement UM ON t_MPOPL.id_unit_latency_manufacture = UM.id_unit_measurement - WHERE - ISNULL(t_MPOPL.id_unit_latency_manufacture) - OR ISNULL(UM.id_unit_measurement) - OR UM.active = 0 - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT( - 'A valid unit measurement of manufacture latency is required for the following Manufacturing Purchase Order(s): ' - , GROUP_CONCAT(CONCAT(t_MPOPL.name_error, ' - ', t_MPOPL.id_unit_latency_manufacture) SEPARATOR ', ') - ) AS msg - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - LEFT JOIN partsltd_prod.Shop_Unit_Measurement UM ON t_MPOPL.id_unit_latency_manufacture = UM.id_unit_measurement - WHERE - ISNULL(t_MPOPL.id_unit_latency_manufacture) - OR ISNULL(UM.id_unit_measurement) - OR UM.active = 0 - ; - END IF; - -- Invalid manufacture latency - IF EXISTS ( - SELECT * - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE t_MPOPL.latency_manufacture < 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, code, msg - ) - SELECT - v_id_error_type_bad_data, - v_code_error_type_bad_data, - CONCAT( - 'A valid manufacture latency is required for the following Manufacturing Purchase Order Item(s): ' - , GROUP_CONCAT(CONCAT(t_MPOPL.name_error, ' - ', t_MPOPL.latency_manufacture) SEPARATOR ', ') - ) - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE t_MPOPL.latency_manufacture < 0 - ; - END IF; - - -- Invalid costs excl VAT - IF EXISTS ( - SELECT * - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE - NOT ISNULL(t_MPOPL.cost_unit_local_VAT_excl) - AND t_MPOPL.cost_unit_local_VAT_excl < 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, code, msg - ) - SELECT - v_id_error_type_bad_data, - v_code_error_type_bad_data, - CONCAT( - 'A valid cost excluding VAT is required for the following Manufacturing Purchase Order Item(s): ' - , GROUP_CONCAT(CONCAT(t_MPOPL.name_error, ' - ', t_MPOPL.cost_unit_local_VAT_excl) SEPARATOR ', ') - ) - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE - NOT ISNULL(t_MPOPL.cost_unit_local_VAT_excl) - AND t_MPOPL.cost_unit_local_VAT_excl < 0 - ; - END IF; - -- Invalid costs incl VAT - IF EXISTS ( - SELECT * - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE - NOT ISNULL(t_MPOPL.cost_unit_local_VAT_incl) - AND t_MPOPL.cost_unit_local_VAT_incl < 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, code, msg - ) - SELECT - v_id_error_type_bad_data, - v_code_error_type_bad_data, - CONCAT( - 'A valid cost including VAT is required for the following Manufacturing Purchase Order Item(s): ' - , GROUP_CONCAT(CONCAT(t_MPOPL.name_error, ' - ', t_MPOPL.cost_unit_local_VAT_incl) SEPARATOR ', ') - ) - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE - NOT ISNULL(t_MPOPL.cost_unit_local_VAT_incl) - AND t_MPOPL.cost_unit_local_VAT_incl < 0 - ; - END IF; - - -- Invalid prices excl VAT - IF EXISTS ( - SELECT * - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE - NOT ISNULL(t_MPOPL.price_unit_local_VAT_excl) - AND t_MPOPL.price_unit_local_VAT_excl < 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, code, msg - ) - SELECT - v_id_error_type_bad_data, - v_code_error_type_bad_data, - CONCAT( - 'A valid price excluding VAT is required for the following Manufacturing Purchase Order Item(s): ' - , GROUP_CONCAT(CONCAT(t_MPOPL.name_error, ' - ', t_MPOPL.price_unit_local_VAT_excl) SEPARATOR ', ') - ) - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE - NOT ISNULL(t_MPOPL.price_unit_local_VAT_excl) - AND t_MPOPL.price_unit_local_VAT_excl < 0 - ; - END IF; - -- Invalid prices incl VAT - IF EXISTS ( - SELECT * - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE - NOT ISNULL(t_MPOPL.price_unit_local_VAT_incl) - AND t_MPOPL.price_unit_local_VAT_incl < 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, code, msg - ) - SELECT - v_id_error_type_bad_data, - v_code_error_type_bad_data, - CONCAT( - 'A valid price including VAT is required for the following Manufacturing Purchase Order Item(s): ' - , GROUP_CONCAT(CONCAT(t_MPOPL.name_error, ' - ', t_MPOPL.price_unit_local_VAT_incl) SEPARATOR ', ') - ) - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE - NOT ISNULL(t_MPOPL.price_unit_local_VAT_incl) - AND t_MPOPL.price_unit_local_VAT_incl < 0 - ; - END IF; - - -- Duplicates - /* - IF EXISTS ( - SELECT - t_MPOPL.id_permutation - , t_MPOPL.name_error - , COUNT(*) - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - GROUP BY t_MPOPL.id_permutation, t_MPOPL.name_error - HAVING COUNT(*) > 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, code, msg - ) - SELECT - v_id_error_type_bad_data, - v_code_error_type_bad_data, - CONCAT('Duplicate records: ', GROUP_CONCAT(t_MPOPLC.name_error SEPARATOR ', ')) - FROM ( - SELECT - t_MPOPL.id_permutation - , t_MPOPL.name_error - , COUNT(*) - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - GROUP BY t_MPOPL.id_permutation, t_MPOPL.name_error - HAVING COUNT(*) > 1 - ) t_MPOPLC - ; - END IF; - */ - -- Empty Manufacturing Purchase Order - IF EXISTS ( SELECT * FROM tmp_Manufacturing_Purchase_Order t_MPO LEFT JOIN tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL ON t_MPO.id_order = t_MPOPL.id_order WHERE ISNULL(t_MPOPL.id_order) ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, code, msg - ) - SELECT - v_id_error_type_bad_data, - v_code_error_type_bad_data, - CONCAT( - 'There are no items in the following Manufacturing Purchase Order(s): ' - , GROUP_CONCAT(t_MPO.name_error SEPARATOR ', ') - ) AS msg - FROM tmp_Manufacturing_Purchase_Order t_MPO - LEFT JOIN tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL ON t_MPO.id_order = t_MPOPL.id_order - WHERE ISNULL(t_MPOPL.id_order) - ; - END IF; - - -- Manufacturing Purchase Order Items without Order - IF EXISTS ( - SELECT * - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - LEFT JOIN tmp_Manufacturing_Purchase_Order t_MPO ON t_MPOPL.id_order = t_MPO.id_order - WHERE ISNULL(t_MPO.id_order) - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, code, msg - ) - SELECT - v_id_error_type_bad_data, - v_code_error_type_bad_data, - CONCAT( - 'There is no order for the following Manufacturing Purchase Order Item(s): ' - , GROUP_CONCAT(t_MPOPL.name_error SEPARATOR ', ') - ) AS msg - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - LEFT JOIN tmp_Manufacturing_Purchase_Order t_MPO ON t_MPOPL.id_order = t_MPO.id_order - WHERE ISNULL(t_MPO.id_order) - ; - END IF; - - -- Permissions - SET v_ids_product_permission := ( - SELECT - GROUP_CONCAT(DISTINCT PP.id_product SEPARATOR ',') - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - INNER JOIN partsltd_prod.Shop_Product_Permutation PP ON t_MPOPL.id_permutation = PP.id_permutation - ); - IF a_debug = 1 THEN - SELECT - a_guid - , a_id_user - , FALSE -- get inactive users - , v_ids_permission_manufacturing_purchase_order - , v_id_access_level_edit - , v_ids_product_permission -- ids_product - , 0 -- a_debug - ; - SELECT * - FROM partsltd_prod.Shop_Calc_User_Temp - WHERE GUID = a_guid - ; - END IF; - - CALL p_shop_calc_user( - a_guid - , a_id_user - , FALSE -- get inactive users - , v_ids_permission_manufacturing_purchase_order - , v_id_access_level_edit - , v_ids_product_permission -- ids_product - , 0 -- a_debug - ); - - IF a_debug = 1 THEN - SELECT * from partsltd_prod.Shop_Calc_User_Temp WHERE GUID = a_guid; - END IF; - - IF EXISTS (SELECT * FROM partsltd_prod.Shop_Calc_User_Temp UE_T WHERE UE_T.GUID = a_guid AND IFNULL(UE_T.can_view, 0) = 0) THEN - DELETE FROM tmp_Msg_Error; - - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_no_permission - , v_code_type_error_no_permission - , CONCAT( - 'You do not have edit permissions for ' - , GROUP_CONCAT(name SEPARATOR ', ') - ) - FROM partsltd_prod.Shop_Permission PERM - INNER JOIN partsltd_prod.Shop_Calc_User_Temp UE_T - ON PERM.id_permission = UE_T.id_permission - AND UE_T.GUID = a_guid - AND IFNULL(UE_T.can_view, 0) = 0 - ; - END IF; - - CALL partsltd_prod.p_shop_clear_calc_user( - a_guid - , 0 -- a_debug - ); - - -- Changed quantity used - IF EXISTS ( - SELECT * - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - INNER JOIN partsltd_prod.Shop_Manufacturing_Purchase_Order_Product_Link MPOPL ON t_MPOPL.id_link = MPOPL.id_link - INNER JOIN partsltd_prod.Shop_Stock_Item SI ON MPOPL.id_permutation = SI.id_permutation - WHERE - t_MPOPL.is_new = 0 - AND t_MPOPL.quantity_used <> MPOPL.quantity_used - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_warning - , v_code_type_error_warning - , CONCAT( - 'The quantity used has changed on the following orders. Please update the stock items appropriately.' - , GROUP_CONCAT( - CONCAT( - t_MPOPL.name_error - , ' - from ' - , MPOPL.quantity_used - , ' to ' - , t_MPOPL.quantity_used - ) SEPARATOR ', ' - ) - ) AS msg - ; - END IF; - -- Changed quantity produced - IF EXISTS ( - SELECT * - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - INNER JOIN partsltd_prod.Shop_Manufacturing_Purchase_Order_Product_Link MPOPL ON t_MPOPL.id_link = MPOPL.id_link - INNER JOIN partsltd_prod.Shop_Stock_Item SI ON MPOPL.id_permutation = SI.id_permutation - WHERE - t_MPOPL.is_new = 0 - AND t_MPOPL.quantity_produced <> MPOPL.quantity_produced - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_warning - , v_code_type_error_warning - , CONCAT( - 'The quantity produced has changed on the following orders. Please update the stock items appropriately.' - , GROUP_CONCAT( - CONCAT( - t_MPOPL.name_error - , ' - from ' - , MPOPL.quantity_produced - , ' to ' - , t_MPOPL.quantity_produced - ) SEPARATOR ', ' - ) - ) AS msg - ; - END IF; - - IF EXISTS ( SELECT * FROM tmp_Msg_Error WHERE id_type <> v_id_type_error_warning LIMIT 1 ) THEN - DELETE FROM tmp_Manufacturing_Purchase_Order_Product_Link; - DELETE FROM tmp_Manufacturing_Purchase_Order; - END IF; - - -- Transaction - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - START TRANSACTION; - INSERT INTO Shop_Sales_And_Purchasing_Change_Set ( - comment - , updated_last_by - , updated_last_on - ) - VALUES ( - a_comment - , a_id_user - , v_time_start - ); - - SET v_id_change_set := LAST_INSERT_ID(); - - INSERT INTO partsltd_prod.Shop_Manufacturing_Purchase_Order ( - id_order_temp - , id_currency - , cost_total_local_VAT_excl - , cost_total_local_VAT_incl - , price_total_local_VAT_excl - , price_total_local_VAT_incl - , active - , created_by - , created_on - , id_change_set - ) - SELECT - t_MPO.id_order_temp - , t_MPO.id_currency - , t_MPO.cost_total_local_VAT_excl - , t_MPO.cost_total_local_VAT_incl - , t_MPO.price_total_local_VAT_excl - , t_MPO.price_total_local_VAT_incl - , t_MPO.active - , a_id_user - , v_time_start - , v_id_change_set - FROM tmp_Manufacturing_Purchase_Order t_MPO - INNER JOIN tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL ON t_MPO.id_order = t_MPOPL.id_order - WHERE t_MPO.is_new = 1 - ; - - UPDATE tmp_Manufacturing_Purchase_Order t_MPO - INNER JOIN partsltd_prod.Shop_Manufacturing_Purchase_Order MPO - ON t_MPO.id_order_temp = MPO.id_order_temp - AND MPO.id_change_set = v_id_change_set - SET - t_MPO.id_order = MPO.id_order - WHERE t_MPO.is_new = 1 - ; - - UPDATE tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - INNER JOIN tmp_Manufacturing_Purchase_Order t_MPO ON t_MPOPL.id_order = t_MPO.id_order_temp - SET - t_MPOPL.id_order = t_MPO.id_order - WHERE t_MPO.is_new = 1 - ; - - INSERT INTO Shop_Manufacturing_Purchase_Order_Product_Link ( - id_order - , id_permutation - , id_unit_quantity - , quantity_used - , quantity_produced - , id_unit_latency_manufacture - , latency_manufacture - , display_order - , active - , cost_unit_local_VAT_excl - , cost_unit_local_VAT_incl - , price_unit_local_VAT_excl - , price_unit_local_VAT_incl - , created_by - , created_on - , id_change_set - ) - SELECT - t_MPOPL.id_order - , t_MPOPL.id_permutation - , t_MPOPL.id_unit_quantity - , t_MPOPL.quantity_used - , t_MPOPL.quantity_produced - , t_MPOPL.id_unit_latency_manufacture - , t_MPOPL.latency_manufacture - , t_MPOPL.display_order - , t_MPOPL.active - , t_MPOPL.cost_unit_local_VAT_excl - , t_MPOPL.cost_unit_local_VAT_incl - , t_MPOPL.price_unit_local_VAT_excl - , t_MPOPL.price_unit_local_VAT_incl - , a_id_user - , v_time_start - , v_id_change_set - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE t_MPOPL.is_new = 1 - ; - - UPDATE partsltd_prod.Shop_Manufacturing_Purchase_Order MPO - INNER JOIN tmp_Manufacturing_Purchase_Order t_MPO - ON MPO.id_order = t_MPO.id_order - AND t_MPO.is_new = 0 - INNER JOIN tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL ON t_MPO.id_order = t_MPOPL.id_order - SET - MPO.id_currency = t_MPO.id_currency - , MPO.cost_total_local_VAT_excl = t_MPO.cost_total_local_VAT_excl - , MPO.cost_total_local_VAT_incl = t_MPO.cost_total_local_VAT_incl - , MPO.price_total_local_VAT_excl = t_MPO.price_total_local_VAT_excl - , MPO.price_total_local_VAT_incl = t_MPO.price_total_local_VAT_incl - , MPO.active = t_MPO.active - , MPO.id_change_set = v_id_change_set - ; - - UPDATE partsltd_prod.Shop_Manufacturing_Purchase_Order_Product_Link MPOPL - INNER JOIN tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - ON MPOPL.id_link = t_MPOPL.id_link - AND t_MPOPL.is_new = 0 - SET - MPOPL.id_order = t_MPOPL.id_order - , MPOPL.id_permutation = t_MPOPL.id_permutation - , MPOPL.id_unit_quantity = t_MPOPL.id_unit_quantity - , MPOPL.quantity_used = t_MPOPL.quantity_used - , MPOPL.quantity_produced = t_MPOPL.quantity_produced - , MPOPL.id_unit_latency_manufacture = t_MPOPL.id_unit_latency_manufacture - , MPOPL.latency_manufacture = t_MPOPL.latency_manufacture - , MPOPL.display_order = t_MPOPL.display_order - , MPOPL.active = t_MPOPL.active - , MPOPL.cost_unit_local_VAT_excl = t_MPOPL.cost_unit_local_VAT_excl - , MPOPL.cost_unit_local_VAT_incl = t_MPOPL.cost_unit_local_VAT_incl - , MPOPL.price_unit_local_VAT_excl = t_MPOPL.price_unit_local_VAT_excl - , MPOPL.price_unit_local_VAT_incl = t_MPOPL.price_unit_local_VAT_incl - , MPOPL.id_change_set = v_id_change_set - ; - - COMMIT; - END IF; - - START TRANSACTION; - - DELETE MPO_T - FROM partsltd_prod.Shop_Manufacturing_Purchase_Order_Temp MPO_T - WHERE MPO_T.GUID = a_guid - ; - DELETE MPOPL_T - FROM partsltd_prod.Shop_Manufacturing_Purchase_Order_Product_Link_Temp MPOPL_T - WHERE MPOPL_T.GUID = a_guid - ; - - COMMIT; - - -- Errors - SELECT * - FROM tmp_Msg_Error t_ME - INNER JOIN partsltd_prod.Shop_Msg_Error_Type MET ON t_ME.id_type = MET.id_type - ; - - IF a_debug = 1 THEN - SELECT * from tmp_Manufacturing_Purchase_Order; - SELECT * from tmp_Manufacturing_Purchase_Order_Product_Link; - END IF; - - DROP TEMPORARY TABLE tmp_Manufacturing_Purchase_Order; - DROP TEMPORARY TABLE tmp_Manufacturing_Purchase_Order_Product_Link; - DROP TEMPORARY TABLE tmp_Msg_Error; - - IF a_debug = 1 THEN - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); - END IF; -END // -DELIMITER ; - - -/* - -DELETE FROM Shop_Manufacturing_Purchase_Order_Product_Link_Audit; -DELETE FROM Shop_Manufacturing_Purchase_Order_Product_Link; -DELETE FROM Shop_Manufacturing_Purchase_Order_Product_Link_Temp; -DELETE FROM Shop_Manufacturing_Purchase_Order_Audit; -DELETE FROM Shop_Manufacturing_Purchase_Order; - -INSERT INTO Shop_Manufacturing_Purchase_Order_Product_Link_Temp ( - guid, - id_link, - id_order, - id_permutation, - cost_total_local, - id_currency, - quantity_used, - id_unit_quantity, - quantity_produced, - latency_manufacture, - display_order, - active -) -VALUES - ( - 'NIPS', -- guid - -1, -- id_link, - -1, -- id_order, - 1, -- id_permutation, - 100, -- cost_total_local, - 1, -- id_currency, - 1, -- quantity_used, - 1, -- id_unit_quantity, - 1, -- quantity_produced, - 14, -- latency_manufacture , - 1, -- display_order - 1 -- active - ) -; - -SELECT * FROM Shop_Manufacturing_Purchase_Order_Product_Link_Temp; - -CALL p_shop_save_manufacturing_purchase_order ( - 'TEST SAVE' - , 'NIPS' -- a_guid - , 1 -- 'auth0|6582b95c895d09a70ba10fef', -- a_id_user - , 1 -- a_debug -); - -SELECT * FROM Shop_Manufacturing_Purchase_Order_Product_Link_Temp; - -DELETE FROM Shop_Manufacturing_Purchase_Order_Product_Link_Audit; -DELETE FROM Shop_Manufacturing_Purchase_Order_Product_Link; -DELETE FROM Shop_Manufacturing_Purchase_Order_Product_Link_Temp; -DELETE FROM Shop_Manufacturing_Purchase_Order_Audit; -DELETE FROM Shop_Manufacturing_Purchase_Order; - - -*/ - - - --- File: 7415_p_shop_save_Manufacturing_purchase_order_test.sql - - --- Clear previous proc -DROP PROCEDURE IF EXISTS partsltd_prod.p_shop_save_Manufacturing_purchase_order_test; - - -DELIMITER // -CREATE PROCEDURE p_shop_save_Manufacturing_purchase_order_test () -BEGIN - - DECLARE v_guid BINARY(36); - DECLARE v_time_start TIMESTAMP(6); - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_guid := 'nips'; - - SELECT * - FROM partsltd_prod.Shop_Manufacturing_Purchase_Order - ; - SELECT * - FROM partsltd_prod.Shop_Manufacturing_Purchase_Order_Temp - ; - SELECT * - FROM partsltd_prod.Shop_Manufacturing_Purchase_Order_Product_Link - ; - SELECT * - FROM partsltd_prod.Shop_Manufacturing_Purchase_Order_Product_Link_Temp - ; - - START TRANSACTION; - - DELETE FROM partsltd_prod.Shop_Manufacturing_Purchase_Order_Temp; - DELETE FROM partsltd_prod.Shop_Manufacturing_Purchase_Order_Product_Link_Temp; - - INSERT INTO partsltd_prod.Shop_Manufacturing_Purchase_Order_Temp ( - id_order - , id_currency - , active - , GUID - ) - /* Test 1 - Insert */ - VALUES ( - -1 - , 1 - , 1 - , v_guid - ) - /* Test 2: Alter - SELECT - id_order - , id_currency - , active - , v_guid - FROM partsltd_prod.Shop_Manufacturing_Purchase_Order - WHERE id_order = 6 - */ - ;-- SELECT * FROM partsltd_prod.Shop_Unit_Measurement; - - INSERT INTO partsltd_prod.Shop_Manufacturing_Purchase_Order_Product_Link_Temp ( - id_link - , id_order - , id_permutation - , id_unit_quantity - , quantity_used - , quantity_produced - , id_unit_latency_manufacture - , latency_manufacture - , display_order - , active - , GUID - ) - /* Test 1 - Insert */ - VALUES ( - -1 -- id_link - , -1 -- id_order - , 3 -- id_permutation - , 3 -- id_unit_quantity - , 3 -- quantity_used - , 0 -- quantity_produced - , 4 -- id_unit_latency_manufacture - , 4 -- latency_manufacture - , 1 -- display_order - , 1 -- active - , v_guid -- - ) - /* Test 2: Alter - SELECT - id_link - , id_order - , id_permutation - , id_unit_quantity - , quantity_used - , quantity_produced - , id_unit_latency_manufacture - , latency_manufacture - , display_order - , active - , v_guid - FROM partsltd_prod.Shop_Manufacturing_Purchase_Order_Product_Link - WHERE id_order = 6 - */ - ; - - COMMIT; - - SELECT * - FROM partsltd_prod.Shop_Manufacturing_Purchase_Order_Temp - WHERE GUID = v_guid - ; - - SELECT * - FROM partsltd_prod.Shop_Manufacturing_Purchase_Order_Product_Link_Temp - WHERE GUID = v_guid - ; - - CALL partsltd_prod.p_shop_save_Manufacturing_purchase_order ( - 'Test save Manufacturing Purchase Order' -- comment - , v_guid -- guid - , 1 -- id_user - , 1 -- debug - ); - - SELECT * - FROM partsltd_prod.Shop_Manufacturing_Purchase_Order_Temp - ; - SELECT * - FROM partsltd_prod.Shop_Manufacturing_Purchase_Order_Product_Link_Temp - ; - SELECT * - FROM partsltd_prod.Shop_Manufacturing_Purchase_Order - ; - SELECT * - FROM partsltd_prod.Shop_Manufacturing_Purchase_Order_Product_Link - ; - - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); -END // -DELIMITER ; - -/* -CALL partsltd_prod.p_shop_save_Manufacturing_purchase_order_test (); - -DELETE FROM partsltd_prod.Shop_Manufacturing_Purchase_Order_Temp; -DELETE FROM partsltd_prod.Shop_Manufacturing_Purchase_Order_Product_Link_Temp; - -DROP TABLE IF EXISTS tmp_Msg_Error; - -select * from partsltd_prod.Shop_User; -Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'partsltd_prod.t_MPOPL.name_error' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by -*/ - --- File: 7416_p_shop_get_many_manufacturing_purchase_order.sql - - -DROP PROCEDURE IF EXISTS p_shop_get_many_manufacturing_purchase_order; - -DELIMITER // -CREATE PROCEDURE p_shop_get_many_manufacturing_purchase_order ( - IN a_id_user INT, - IN a_get_all_order BIT, - IN a_get_inactive_order BIT, - IN a_ids_order TEXT, - IN a_ids_permutation TEXT, - IN a_date_from DATETIME, - IN a_date_to DATETIME, - IN a_debug BIT -) -BEGIN - DECLARE v_code_type_error_bad_data VARCHAR(50); - DECLARE v_code_type_error_no_permission VARCHAR(50); - DECLARE v_guid BINARY(36); - DECLARE v_has_filter_order BIT; - DECLARE v_has_filter_permutation BIT; - DECLARE v_has_filter_date_from BIT; - DECLARE v_has_filter_date_to BIT; - DECLARE v_id_access_level_view INT; - DECLARE v_ids_permission_manufacturing_purchase_order VARCHAR(100); - DECLARE v_id_type_error_bad_data INT; - DECLARE v_id_type_error_no_permission INT; - DECLARE v_time_start TIMESTAMP(6); - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_guid := UUID(); - SET v_id_access_level_view := (SELECT id_access_level FROM partsltd_prod.Shop_Access_Level WHERE code = 'VIEW' LIMIT 1); - SET v_code_type_error_bad_data := (SELECT code FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1); - SET v_id_type_error_bad_data := (SELECT id_type FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = v_code_type_error_bad_data LIMIT 1); - SET v_code_type_error_no_permission := (SELECT code FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = 'NO_PERMISSION'); - SET v_id_type_error_no_permission := (SELECT id_type FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = v_code_type_error_no_permission); - SET v_ids_permission_manufacturing_purchase_order := (SELECT GROUP_CONCAT(id_permission SEPARATOR ',') FROM partsltd_prod.Shop_Permission WHERE code IN ('STORE_MANUFACTURING_PURCHASE_ORDER', 'STORE_PRODUCT')); - - SET a_get_all_order := IFNULL(a_get_all_order, 1); - SET a_get_inactive_order := IFNULL(a_get_inactive_order, 0); - SET a_ids_order := TRIM(IFNULL(a_ids_order, '')); - SET a_ids_permutation := TRIM(IFNULL(a_ids_permutation, '')); - SET a_date_from := IFNULL(a_date_from, NULL); - SET a_date_to := IFNULL(a_date_to, NULL); - SET a_debug := IFNULL(a_debug, 0); - - DROP TEMPORARY TABLE IF EXISTS tmp_Manufacturing_Purchase_Order_Product_Link; - DROP TEMPORARY TABLE IF EXISTS tmp_Manufacturing_Purchase_Order; - DROP TEMPORARY TABLE IF EXISTS tmp_Permutation; - DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error; - DROP TEMPORARY TABLE IF EXISTS tmp_Split; - - CREATE TEMPORARY TABLE tmp_Manufacturing_Purchase_Order ( - id_order INT NOT NULL PRIMARY KEY - ); - - CREATE TEMPORARY TABLE tmp_Permutation ( - id_permutation INT NOT NULL PRIMARY KEY - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - id_type INT NOT NULL, - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Split ( - substring VARCHAR(4000) NOT NULL - , as_int INT NULL - ); - DELETE FROM tmp_Split; - - SET v_has_filter_order = CASE WHEN a_ids_order = '' THEN 0 ELSE 1 END; - SET v_has_filter_permutation = CASE WHEN a_ids_permutation = '' THEN 0 ELSE 1 END; - SET v_has_filter_date_from = CASE WHEN ISNULL(a_date_from) THEN 0 ELSE 1 END; - SET v_has_filter_date_to = CASE WHEN ISNULL(a_date_to) THEN 0 ELSE 1 END; - - IF a_debug = 1 THEN - SELECT - v_has_filter_order - , v_has_filter_permutation - , v_has_filter_date_from - , v_has_filter_date_to - ; - END IF; - - -- Permutations - IF v_has_filter_permutation = 1 THEN - CALL partsltd_prod.p_split(v_guid, a_ids_permutation, ',', a_debug); - - INSERT INTO tmp_Split ( - substring - , as_int - ) - SELECT - substring - , CONVERT(substring, DECIMAL(10,0)) AS as_int - FROM partsltd_prod.Split_Temp - WHERE 1=1 - AND GUID = v_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( v_guid ); - END IF; - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Product_Permutation PP ON t_S.as_int = PP.id_permutation - WHERE - ISNULL(t_S.as_int) - OR ISNULL(PP.id_permutation) - OR PP.active = 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - code, - msg - ) - SELECT - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Invalid or inactive permutation IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Product_Permutation PP ON t_S.as_int = PP.id_permutation - WHERE - ISNULL(t_S.as_int) - OR ISNULL(PP.id_permutation) - OR PP.active = 0 - ; - ELSE - INSERT INTO tmp_Permutation ( - id_permutation - ) - SELECT - PP.id_permutation - FROM tmp_Split t_S - RIGHT JOIN partsltd_prod.Shop_Product_Permutation PP ON t_S.as_int = PP.id_permutation - WHERE ( - v_has_filter_permutation = 0 - OR NOT ISNULL(t_S.as_int) - ) - ; - END IF; - END IF; - - DELETE FROM tmp_Split; - - -- Manufacturing Purchase Orders - IF v_has_filter_order = 1 THEN - CALL partsltd_prod.p_split(v_guid, a_ids_order, ',', a_debug); - - INSERT INTO tmp_Split ( - substring - , as_int - ) - SELECT - substring - , CONVERT(substring, DECIMAL(10,0)) AS as_int - FROM partsltd_prod.Split_Temp - WHERE 1=1 - AND GUID = v_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( v_guid ); - END IF; - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Manufacturing_Purchase_Order MPO ON t_S.as_int = MPO.id_order - WHERE - ISNULL(t_S.as_int) - OR ISNULL(MPO.id_order) - OR ( - MPO.active = 0 - AND a_get_inactive_order = 0 - ) - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - code, - msg - ) - SELECT - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Invalid or inactive Manufacturing Purchase Order IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Manufacturing_Purchase_Order MPO ON t_S.as_int = MPO.id_order - WHERE - ISNULL(t_S.as_int) - OR ISNULL(MPO.id_order) - OR ( - MPO.active = 0 - AND a_get_inactive_order = 0 - ) - ; - ELSE - INSERT INTO tmp_Manufacturing_Purchase_Order ( - id_order - ) - SELECT - MPO.id_order - FROM tmp_Split t_S - RIGHT JOIN partsltd_prod.Shop_Manufacturing_Purchase_Order MPO ON t_S.as_int = MPO.id_order - INNER JOIN partsltd_prod.Shop_Manufacturing_Purchase_Order_Product_Link MPOPL ON MPO.id_order = MPOPL.id_order - INNER JOIN tmp_Permutation t_PP ON MPOPL.id_permutation = t_PP.id_permutation - WHERE ( - a_get_all_order = 1 - OR ( - v_has_filter_order = 1 - AND NOT ISNULL(t_S.as_int) - ) - OR ( - v_has_filter_permutation = 1 - AND NOT ISNULL(t_PP.id_permutation) - ) - ) - AND ( - a_get_inactive_order = 1 - OR MPO.active = 1 - ) - AND ( - v_has_filter_date_from = 0 - OR MPO.created_on > a_date_from - ) - AND ( - v_has_filter_date_to = 0 - OR MPO.created_on < a_date_to - ) - - ; - END IF; - END IF; - - DELETE FROM tmp_Split; - - -- Permissions - IF a_debug = 1 THEN - SELECT - v_guid - , a_id_user - , FALSE -- get inactive users - , v_ids_permission_manufacturing_purchase_order - , v_id_access_level_view - , '' -- ids_product - , 0 -- a_debug - ; - SELECT * FROM partsltd_prod.Shop_Calc_User_Temp; - END IF; - - CALL p_shop_calc_user( - v_guid - , a_id_user - , FALSE -- get inactive users - , v_ids_permission_manufacturing_purchase_order - , v_id_access_level_view - , '' -- ids_product - , 0 -- a_debug - ); - - IF a_debug = 1 THEN - SELECT * FROM partsltd_prod.Shop_Calc_User_Temp; - END IF; - - IF NOT EXISTS (SELECT can_view FROM partsltd_prod.Shop_Calc_User_Temp UE_T WHERE UE_T.GUID = v_guid) THEN - DELETE FROM tmp_Msg_Error; - - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - VALUES ( - v_id_type_error_no_permission - , v_code_type_error_no_permission - , CONCAT('You do not have view permissions for ', IFNULL((SELECT IFNULL(name, '(No Permission Name)') FROM partsltd_prod.Shop_Permission WHERE FIND_IN_SET(id_permission, v_ids_permission_manufacturing_purchase_order) > 0 LIMIT 1), '(No Permissions Found)')) - ) - ; - END IF; - - IF EXISTS ( SELECT * FROM tmp_Msg_Error LIMIT 1 ) THEN - -- DELETE FROM tmp_Manufacturing_Purchase_Order_Product_Link; - DELETE FROM tmp_Manufacturing_Purchase_Order; - END IF; - - -- Returns - /* - -- Manufacturings - SELECT - t_S.id_manufacturing, - S.name_company, - S.name_contact, - S.department_contact, - S.id_address, - S.phone_number, - S.fax, - S.email, - S.website, - S.id_currency, - t_S.active - FROM tmp_Manufacturing t_S - INNER JOIN partsltd_prod.Shop_Manufacturing S - ON t_S.id_manufacturing = S.id_manufacturing - ; - */ - - -- Manufacturing Purchase Order - SELECT - t_MPO.id_order - , MPO.id_currency - , C.code - , C.symbol - , MPO.cost_total_local_VAT_excl - , MPO.cost_total_local_VAT_incl - , MPO.price_total_local_VAT_excl - , MPO.price_total_local_VAT_incl - , MPO.active - , MPO.created_on - , CONCAT( - MPO.cost_total_local_VAT_excl - , ' on ' - , MPO.created_on - ) AS name - FROM tmp_Manufacturing_Purchase_Order t_MPO - INNER JOIN partsltd_prod.Shop_Manufacturing_Purchase_Order MPO ON MPO.id_order = t_MPO.id_order - LEFT JOIN partsltd_prod.Shop_Currency C ON MPO.id_currency = C.id_currency - ; - - -- Manufacturing Purchase Order Product Link - SELECT - MPOPL.id_link - , MPOPL.id_order - , P.id_category - , P.id_product - , MPOPL.id_permutation - , fn_shop_get_product_permutation_name(MPOPL.id_permutation) AS name_permutation - , fn_shop_get_product_permutation_variations_csv(MPOPL.id_permutation) AS csv_id_pairs_variation - , MPOPL.id_unit_quantity - , MPOPL.quantity_used - , MPOPL.quantity_produced - , MPOPL.id_unit_latency_manufacture - , MPOPL.latency_manufacture - , MPOPL.display_order - , MPOPL.cost_unit_local_VAT_excl - , MPOPL.cost_unit_local_VAT_incl - , MPOPL.price_unit_local_VAT_excl - , MPOPL.price_unit_local_VAT_incl - , MPOPL.active - FROM tmp_Manufacturing_Purchase_Order t_MPO - INNER JOIN partsltd_prod.Shop_Manufacturing_Purchase_Order_Product_Link MPOPL ON t_MPO.id_order = MPOPL.id_order - LEFT JOIN partsltd_prod.Shop_Product_Permutation PP ON MPOPL.id_permutation = PP.id_permutation - LEFT JOIN partsltd_prod.Shop_Product P ON PP.id_product = P.id_product - ; - - -- Errors - SELECT * - FROM tmp_Msg_Error t_ME - INNER JOIN partsltd_prod.Shop_Msg_Error_Type MET ON t_ME.id_type = MET.id_type - ; - - IF a_debug = 1 THEN - SELECT * from tmp_Manufacturing_Purchase_Order; - SELECT * from tmp_Permutation; - END IF; - - DROP TEMPORARY TABLE IF EXISTS tmp_Manufacturing_Purchase_Order_Product_Link; - DROP TEMPORARY TABLE IF EXISTS tmp_Manufacturing_Purchase_Order; - DROP TEMPORARY TABLE IF EXISTS tmp_Permutation; - DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error; - DROP TEMPORARY TABLE IF EXISTS tmp_Split; - - IF a_debug = 1 THEN - CALL p_debug_timing_reporting( v_time_start ); - END IF; -END // -DELIMITER ; - - -/* - -CALL p_shop_get_many_manufacturing_purchase_order ( - 0 -- a_id_user - , 1 -- a_get_all_order - , 1 -- a_get_inactive_order - , '' -- a_ids_order - , '' -- a_ids_permutation - , NULL -- a_date_from - , NULL -- a_date_to - , 0 -- a_debug -); - - -select * -from partsltd_prod.shop_manufacturing_purchase_order -; -select * -from partsltd_prod.shop_manufacturing_purchase_order_product_link -; -*/ - - --- File: 7421_p_shop_save_customer.sql - - - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_save_customer; - - -DELIMITER // -CREATE PROCEDURE p_shop_save_customer ( - IN a_guid VARCHAR(500), - IN a_id_user INT, - IN a_comment VARCHAR(500), - IN a_id_customer INT, - IN a_name_company VARCHAR(256), - IN a_name_contact VARCHAR(256), - IN a_department_contact VARCHAR(256), - IN a_id_address INT, - IN a_phone_number VARCHAR(20), - IN a_email VARCHAR(515), - IN a_id_currency INT, - IN a_active BIT -) -BEGIN - DECLARE v_id_error_type_bad_data INT; - DECLARE v_id_error_type_no_permission INT; - DECLARE v_guid_permission BINARY(36); - DECLARE v_id_permission_customer INT; - DECLARE v_id_access_level_EDIT INT; - DECLARE v_has_permission BIT; - DECLARE v_id_change_set INT; - DECLARE v_is_new_customer BIT; - - SET v_id_error_type_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA'); - SET v_guid_permission = UUID(); - SET v_id_permission_customer = (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_CUSTOMER' LIMIT 1); - SET v_id_access_level_EDIT = (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'EDIT'); - - -- Argument default values - IF a_guid IS NULL THEN - SET a_guid = UUID(); - END IF; - - - -- Temporary tables - /* - CREATE TABLE tmp_Shop_Customer ( - id_customer INT NOT NULL, - name_company VARCHAR(255) NOT NULL, - name_contact VARCHAR(255) NULL, - department_contact VARCHAR(255) NULL, - id_address INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Customer_id_address - FOREIGN KEY (id_address) - REFERENCES Shop_Address(id_address), - phone_number VARCHAR(50) NULL, - fax VARCHAR(50) NULL, - email VARCHAR(255) NOT NULL, - website VARCHAR(255) NULL, - id_currency INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Customer_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency), - active BIT NOT NULL, - can_view BIT NOT NULL, - can_edit BIT NOT NULL, - can_admin BIT NOT NULL - ); - */ - - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - guid BINARY(36) NOT NULL, - id_type INT NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type (id_type), - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - - - -- Argument validation - IF a_id_customer IS NULL THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, msg - ) - VALUES - (a_guid, v_id_error_type_bad_data, 'Customer ID must not be null') - ; - END IF; - IF a_name_company IS NULL THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, msg - ) - VALUES - (a_guid, v_id_error_type_bad_data, 'Customer company name must not be null') - ; - END IF; - IF a_id_address IS NULL THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, msg - ) - VALUES - (a_guid, v_id_error_type_bad_data, 'Customer address ID must not be null') - ; - END IF; - IF a_email IS NULL THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, msg - ) - VALUES - (a_guid, v_id_error_type_bad_data, 'Customer email must not be null') - ; - END IF; - IF a_active IS NULL THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, msg - ) - VALUES - (a_guid, v_id_error_type_bad_data, 'Customer active status must not be null') - ; - END IF; - - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - SET v_is_new_customer := CASE WHEN a_id_customer <= 0 THEN 1 ELSE 0 END; - - IF (v_is_new_customer = 0 AND NOT EXISTS (SELECT * FROM Shop_Customer C WHERE C.id_customer = a_id_customer)) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, msg - ) - VALUES - (a_guid, v_id_error_type_bad_data, CONCAT('Invalid customer ID: ', a_id_customer)) - ; - END IF; - END IF; - - /* - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - INSERT INTO tmp_Shop_Customer ( - id_customer, name_company, name_contact, department_contact, id_address, phone_number, fax, email, website, id_currency, active - ) - VALUES - (a_id_customer, a_name_company, a_name_contact, a_department_contact, a_id_address, a_phone_number, a_fax, a_email, a_website, a_id_currency, a_active) - /* - FROM Shop_Customer S - WHERE (NOT v_has_filter_category OR C.id_category LIKE '%' || a_ids_category || '%') - AND (a_get_inactive_categories OR C.active) - * - ; - END IF; - */ - - -- Permissions - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - CALL p_shop_calc_user(v_guid_permission, a_id_user, 0, v_id_permission_customer, v_id_access_level_edit, ''); - - /* - UPDATE tmp_Shop_Customer t_S - INNER JOIN Shop_Calc_User_Temp TP - ON TP.GUID = v_guid_permission - SET tP.can_view = TP.can_view, - tP.can_edit = TP.can_edit, - tP.can_admin = TP.can_admin; - */ - SET v_has_permission := (SELECT can_edit FROM Shop_Calc_User_Temp WHERE GUID = v_guid_permission); - - IF v_has_permission = 0 THEN - SET v_id_error_type_no_permission := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'NO_PERMISSION'); - INSERT INTO tmp_Msg_Error ( - guid, id_type, msg - ) - SELECT - a_guid, - v_id_error_type_no_permission, - CONCAT('You do not have ', name, ' permissions.') - FROM Shop_Permission - WHERE id_permission = v_id_permission_customer - ; - END IF; - - -- CALL p_shop_clear_calc_user(v_guid_permission); - - DELETE FROM Shop_Calc_User_Temp - WHERE GUID = a_guid; - END IF; - - - -- Transaction - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - INSERT INTO Shop_Sales_And_Purchasing_Change_Set ( - comment, - updated_last_by, - updated_last_on - ) - VALUES ( - CONCAT( - 'Save ', - CASE WHEN v_is_new_customer = 1 THEN 'new ' ELSE '' END, - 'Customer - ', - a_comment - ), - a_id_user, - CURRENT_TIME() - ); - - SET v_id_change_set := (SELECT id_change_set FROM Shop_Sales_And_Purchasing_Change_Set ORDER BY id_change_set DESC LIMIT 1); - - START TRANSACTION; - IF (v_is_new_customer = 1) THEN - INSERT INTO Shop_Customer ( - -- id_customer, - name_company, name_contact, department_contact, id_address, phone_number, email, id_currency, active, id_change_set - ) - VALUES - ( - -- a_id_customer, - a_name_company, a_name_contact, a_department_contact, a_id_address, a_phone_number, a_email, a_id_currency, a_active, v_id_change_set - ) - /* - FROM Shop_Customer S - WHERE (NOT v_has_filter_category OR C.id_category LIKE '%' || a_ids_category || '%') - AND (a_get_inactive_categories OR C.active) - */ - ; - ELSE - UPDATE Shop_Customer C - -- INNER JOIN tmp_Shop_Customer t_S ON S.id_customer = t_S.id_customer - SET - /* - S.name_company = t_S.name_company, - S.name_contact = t_S.name_contact, - S.department_contact = t_S.department_contact, - S.id_address = t_S.id_address, - S.phone_number = t_S.phone_number, - S.fax = t_S.fax, - S.email = t_S.email, - S.website = t_S.website, - S.id_currency = t_S.id_currency, - S.active = t_S.active - */ - C.name_company = a_name_company, - C.name_contact = a_name_contact, - C.department_contact = a_department_contact, - C.id_address = a_id_address, - C.phone_number = a_phone_number, - C.email = a_email, - C.website = a_website, - C.id_currency = a_id_currency, - C.active = a_active, - C.id_change_set = v_id_change_set - ; - END IF; - - IF EXISTS (SELECT * FROM tmp_Msg_Error) THEN - ROLLBACK; - ELSE - COMMIT; - END IF; - END IF; - - -- Returns - -- SET v_now = NOW(); - - -- Errors - SELECT * - FROM tmp_Msg_Error - ; - - -- DROP TABLE tmp_Shop_Customer; - DROP TABLE tmp_Msg_Error; -END // -DELIMITER ; - - -/* - -CALL p_shop_save_customer ( - 'NIPS', -- a_guid - 'auth0|6582b95c895d09a70ba10fef', -- a_id_user - 'Initial Customer', -- a_comment - '-1', -- a_id_customer - 'good co', -- a_name_company - 'teddy', -- a_name_contact - 'manufacturing', -- a_department_contact - 1, -- a_id_address - 'BRING BRING', -- a_phone_number - 'e@mail.com', -- a_email - 1, -- a_id_currency_cost - 1 -- a_active -); - -SELECT * FROM Shop_Customer -; - -DELETE FROM Shop_Customer -; - -*/ - - --- File: 7422_p_shop_get_many_customer.sql - - - -/* - -CALL p_shop_get_many_customer ( - '', -- a_id_user - 1, -- a_get_all_customer - 0, -- a_get_inactive_customer - 0, -- a_get_first_customer_only - '', -- a_ids_customer -); - -*/ - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_get_many_customer; - - -DELIMITER // -CREATE PROCEDURE p_shop_get_many_customer ( - IN a_id_user INT, - IN a_get_all_customer BIT, - IN a_get_inactive_customer BIT, - IN a_get_first_customer_only BIT, - IN a_ids_customer VARCHAR(4000) -) -BEGIN - -- Argument redeclaration - -- Variable declaration - DECLARE v_id_error_type_bad_data INT; - DECLARE v_code_error_type_bad_data VARCHAR(50); - DECLARE v_has_filter_customer BIT; - DECLARE v_guid BINARY(36); - -- DECLARE v_id_user VARCHAR(100); - -- DECLARE v_ids_permutation_unavailable VARCHAR(4000); - DECLARE v_id_permission_customer INT; - -- DECLARE v_ids_product_permission VARCHAR(4000); - -- DECLARE v_ids_permutation_permission VARCHAR(4000); - DECLARE v_id_access_level_view INT; - DECLARE v_now DATETIME; - DECLARE v_id_minimum INT; - - SET v_code_error_type_bad_data = 'BAD_DATA'; - SET v_id_error_type_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_type_bad_data LIMIT 1); - SET v_guid := UUID(); - SET v_id_access_level_view := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW'); - - - -- Argument validation + default values - IF a_id_user IS NULL THEN - SET a_id_user = ''; - ELSE - SET a_id_user = TRIM(a_id_user); - END IF; - IF a_get_inactive_customer IS NULL THEN - SET a_get_inactive_customer = 0; - END IF; - IF a_get_first_customer_only IS NULL THEN - SET a_get_first_customer_only = 0; - END IF; - IF a_ids_customer IS NULL THEN - SET a_ids_customer = ''; - ELSE - SET a_ids_customer = TRIM(REPLACE(a_ids_customer, '|', ',')); - END IF; - - SET v_has_filter_customer = CASE WHEN a_ids_customer = '' THEN 0 ELSE 1 END; - - IF a_get_all_customer IS NULL THEN - SET a_get_all_customer = NOT v_has_filter_customer; - END IF; - - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Shop_Customer; - - CREATE TABLE tmp_Shop_Customer ( - id_customer INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Customer_id_customer - FOREIGN KEY (id_customer) - REFERENCES Shop_Customer(id_customer), - active BIT NOT NULL, - rank_customer INT NULL, - can_view BIT, - can_edit BIT, - can_admin BIT - ); - - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - guid BINARY(36) NOT NULL, - id_type INT NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type (id_type), - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - - - -- Parse filters - SET v_has_filter_customer = CASE WHEN a_ids_customer = '' THEN 0 ELSE 1 END; - - -- select v_has_filter_product, v_has_filter_permutation; - - IF v_has_filter_customer = 1 OR a_get_all_customer = 1 THEN - CALL p_split(v_guid, a_ids_customer, ','); - - IF EXISTS (SELECT * FROM Split_Temp S_T LEFT JOIN Shop_Customer C ON S_T.substring = C.id_customer WHERE ISNULL(C.id_customer)) THEN - INSERT INTO tmp_Msg_Error ( - guid, - id_type, - code, - msg - ) - VALUES ( - v_guid, - v_id_error_type_bad_data, - v_code_error_type_bad_data, - CONCAT('Invalid customer IDs: ', (SELECT GROUP_CONCAT(C.id_customer) FROM Split_Temp S_T LEFT JOIN Shop_Customer C ON S_T.substring = C.id_customer WHERE ISNULL(C.id_customer))) - ) - ; - ELSE - INSERT INTO tmp_Shop_Customer ( - id_customer, - active, - rank_customer - ) - SELECT - C.id_customer, - C.active, - RANK() OVER (ORDER BY C.id_customer ASC) AS rank_customer - FROM Shop_Customer C - LEFT JOIN Split_Temp S_T ON C.id_customer = S_T.substring - WHERE - ( - a_get_all_customer = 1 - OR NOT ISNULL(S_T.substring) - ) - AND ( - a_get_inactive_customer = 1 - OR C.active = 1 - ) - ; - END IF; - - DROP TABLE Split_Temp; - - IF a_get_first_customer_only = 1 THEN - DELETE t_C - FROM tmp_Shop_Customer t_C - WHERE t_C.rank_customer > ( - SELECT MIN(t_C.rank_customer) - FROM tmp_Shop_Customer t_C - ) - ; - END IF; - END IF; - - -- Permissions - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - -- SET v_id_user := (SELECT id_user FROM Shop_User WHERE name = CURRENT_USER()); - SET v_id_permission_customer := (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_CUSTOMER' LIMIT 1); - - -- SELECT v_guid, a_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_permutation_permission; - -- select * from Shop_Calc_User_Temp; - - CALL p_shop_calc_user(v_guid, a_id_user, FALSE, v_id_permission_customer, v_id_access_level_view, ''); - - -- select * from Shop_Calc_User_Temp; - - IF NOT EXISTS (SELECT can_view FROM Shop_Calc_User_Temp UE_T WHERE UE_T.GUID = v_guid) THEN - INSERT INTO tmp_Msg_Error ( - guid, - id_type, - code, - msg - ) - VALUES ( - v_guid, - v_id_error_type_bad_data, - v_code_error_type_bad_data, - CONCAT('You do not have view permissions for ', IFNULL((SELECT name FROM Shop_Permission WHERE id_permission = v_id_permission_customer LIMIT 1), 'Permission not found')) - ) - ; - END IF; - END IF; - - - -- select * from tmp_Shop_Product; - - -- Returns - -- SET v_now := NOW(); - - -- customers - SELECT - t_C.id_customer, - C.name_company, - C.name_contact, - C.department_contact, - C.id_address, - C.phone_number, - C.email, - C.id_currency, - C.active - FROM tmp_Shop_Customer t_C - INNER JOIN Shop_Customer C ON t_C.id_customer = C.id_customer - ; - - -- Errors - SELECT - /* - t_ME.display_order, - t_ME.guid, - t_ME.id_type, - t_ME.msg, - MET.code, - MET.name, - MET.description - */ - * - FROM tmp_Msg_Error t_ME - INNER JOIN Shop_Msg_Error_Type MET - ON t_ME.id_type = MET.id_type - WHERE guid = v_guid - ; - - /* - -- Return arguments for test - SELECT - a_ids_category, - a_get_inactive_category, - a_ids_product, - a_get_inactive_product, - a_get_first_product_only, - a_get_all_product, - a_ids_image, - a_get_inactive_image, - a_get_first_image_only, - a_get_all_image - ; - */ - - -- select 'other outputs'; - -- select * from tmp_Shop_Product; - - -- Clean up - DROP TABLE IF EXISTS tmp_Shop_Customer; - - DELETE FROM Shop_Calc_User_Temp - WHERE GUID = v_guid - ; -END // -DELIMITER ; - - -/* -CALL p_shop_get_many_customer ( - '', -- a_id_user - 1, -- a_get_all_customer - 0, -- a_get_inactive_customer - 0, -- a_get_first_customer_only - '' -- a_ids_customer -); - -SELECT * -FROM Shop_Customer; - -*/ - - --- File: 7424_p_shop_save_customer_sales_order.sql - - - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_save_customer_sales_order; - -DROP TABLE IF EXISTS tmp_Shop_Customer_Sales_Order_Product_Link; -DROP TABLE IF EXISTS tmp_Msg_Error; - -DELIMITER // -CREATE PROCEDURE p_shop_save_customer_sales_order ( - IN a_guid VARCHAR(500), - IN a_id_user INT, - IN a_comment VARCHAR(500), - IN a_id_order INT, - IN a_id_customer INT, - IN a_id_currency_price INT, - IN a_active BIT -) -BEGIN - DECLARE v_id_error_type_bad_data INT; - DECLARE v_code_error_type_bad_data VARCHAR(50); - DECLARE v_id_error_type_no_permission INT; - DECLARE v_code_error_type_no_permission VARCHAR(50); - DECLARE v_guid_permission BINARY(36); - -- DECLARE v_id_user VARCHAR(100); - DECLARE v_id_permission_Customer_Sales_order INT; - DECLARE v_id_access_level_EDIT INT; - DECLARE v_ids_product VARCHAR(4000); - DECLARE v_ids_product_no_permission VARCHAR(4000); - -- DECLARE v_id_order_new INT; - DECLARE v_id_change_set INT; - DECLARE v_is_new_Customer_Sales_order BIT; - - SET SESSION sql_mode = sys.list_drop(@@session.sql_mode, 'ONLY_FULL_GROUP_BY'); - - SET v_code_error_type_bad_data = 'BAD_DATA'; - SET v_id_error_type_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_type_bad_data LIMIT 1); - SET v_code_error_type_no_permission = 'NO_PERMISSION'; - SET v_id_error_type_no_permission := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_type_no_permission LIMIT 1); - SET v_guid_permission = UUID(); - -- SET v_id_user = CURRENT_USER(); - SET v_id_permission_Customer_Sales_order := (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_CUSTOMER_SALES_ORDER' LIMIT 1); - SET v_id_access_level_EDIT := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'EDIT'); - - -- Argument default values - IF a_guid IS NULL THEN - SET a_guid = UUID(); - END IF; - IF a_active IS NULL THEN - SET a_active = 0; - END IF; - - -- Temporary tables - /* - CREATE TABLE tmp_Shop_Customer_Sales_Order ( - id_order INT NOT NULL PRIMARY KEY, - id_supplier_ordered INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Customer_Sales_Order_id_supplier_ordered - FOREIGN KEY (id_supplier_ordered) - REFERENCES Shop_Supplier(id_supplier), - price_total_local FLOAT NOT NULL, - id_currency_price INT NOT NULL - ); - */ - - CREATE TABLE tmp_Shop_Customer_Sales_Order_Product_Link ( - id_link INT NOT NULL PRIMARY KEY, - id_order INT NOT NULL, - /* - CONSTRAINT FK_tmp_Supplier_Purchase_Order_Product_Link_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Customer_Sales_Order(id_order), - */ - id_permutation INT NOT NULL, - CONSTRAINT FK_tmp_Supplier_Purchase_Order_Product_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - price_total_local FLOAT NOT NULL, - id_currency_price INT NOT NULL, - quantity_ordered FLOAT NOT NULL, - id_unit_quantity INT NOT NULL, - CONSTRAINT FK_tmp_Supplier_Purchase_Order_Product_Link_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - quantity_delivered FLOAT NULL, - latency_delivery_days INT NOT NULL, - display_order INT NOT NULL, - active BIT NOT NULL, - name_error VARCHAR(200) NOT NULL - ); - - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - guid BINARY(36) NOT NULL, - id_type INT NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type (id_type), - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - - - -- Argument validation - -- User ID - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF ISNULL(a_id_user) OR NOT EXISTS (SELECT * FROM Shop_User WHERE id_user = a_id_user) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES - (a_guid, v_id_error_type_bad_data, v_code_error_type_bad_data, CONCAT('Invalid User ID: ', IFNULL(a_id_user, 'NULL'))) - ; - END IF; - END IF; - - -- Order ID - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF ISNULL(a_id_order) OR ((a_id_order > 0) AND NOT EXISTS (SELECT * FROM Shop_Customer_Sales_Order WHERE id_order = a_id_order)) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES - (a_guid, v_id_error_type_bad_data, v_code_error_type_bad_data, CONCAT('Invalid Customer Sales Order ID: ', IFNULL(a_id_order, 'NULL'))) - ; - END IF; - END IF; - - -- Customer ID - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF ISNULL(a_id_customer) OR NOT EXISTS (SELECT * FROM Shop_Customer WHERE id_customer = a_id_customer) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES - (a_guid, v_id_error_type_bad_data, v_code_error_type_bad_data, CONCAT('Invalid Customer ID: ', IFNULL(a_id_customer, 'NULL'))) - ; - END IF; - END IF; - - -- Currency ID - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF ISNULL(a_id_currency_price) OR NOT EXISTS (SELECT * FROM Shop_Currency WHERE id_currency = a_id_currency_price) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES - (a_guid, v_id_error_type_bad_data, v_code_error_type_bad_data, CONCAT('Invalid currency ID: ', IFNULL(a_id_currency, 'NULL'))) - ; - END IF; - END IF; - - -- Comment - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF ISNULL(a_comment) OR TRIM(a_comment) = '' THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES - (a_guid, v_id_error_type_bad_data, v_code_error_type_bad_data, 'A comment must be provided.') - ; - END IF; - END IF; - - - -- Get data from Temp table - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - SET v_is_new_Customer_Sales_order := CASE WHEN a_id_order <= 0 THEN 1 ELSE 0 END; - - INSERT INTO tmp_Shop_Customer_Sales_Order_Product_Link ( - id_link, - id_order, - id_permutation, - price_total_local, - id_currency_price, - quantity_ordered, - id_unit_quantity, - quantity_delivered, - latency_delivery_days, - display_order, - active, - name_error - ) - /* - VALUES - (a_id_supplier, a_name_company, a_name_contact, a_department_contact, a_id_address, a_phone_number, a_fax, a_email, a_website, a_id_currency, a_active) - */ - SELECT - CSOPL_T.id_link, - CSOPL_T.id_order, - CSOPL_T.id_permutation, - (PP.cost_local + PP.profit_local_min) * quantity_ordered AS price_total_local, - CSOPL_T.id_currency_price, - CSOPL_T.quantity_ordered, - CSOPL_T.id_unit_quantity, - CSOPL_T.quantity_delivered, - CSOPL_T.latency_delivery_days, - CSOPL_T.display_order, - CSOPL_T.active, - CONCAT(PP.id_permutation, ' - ', IFNULL(P.name ,'')) AS name_error - FROM Shop_Customer_Sales_Order_Product_Link_Temp CSOPL_T - INNER JOIN Shop_Product_Permutation PP ON CSOPL_T.id_permutation = PP.id_permutation - INNER JOIN Shop_Product P ON PP.id_product = P.id_product - WHERE CSOPL_T.GUID = a_guid - ; - DELETE CSOPL_T - FROM Shop_Customer_Sales_Order_Product_Link_Temp CSOPL_T - WHERE CSOPL_T.GUID = a_guid - ; - - /* - UPDATE tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL - SET - price_total_local - */ - END IF; - - -- Invalid quantity ordered - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF EXISTS ( - SELECT * - FROM tmp_Shop_Customer_Sales_Order_Product_Link - WHERE - NOT ISNULL(quantity_ordered) - AND quantity_ordered < 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - SELECT - a_guid, - v_id_error_type_bad_data, - v_code_error_type_bad_data, - CONCAT('Invalid quantity ordered property for the following permutations: ', GROUP_CONCAT(t_CSOPL.name_error SEPARATOR ', ')) - FROM tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL - -- INNER JOIN Shop_Product_Permutation PP ON t_CSOPL.id_permutation = PP.id_permutation - WHERE t_CSOPL.quantity_ordered < 0 - ; - END IF; - END IF; - - -- Duplicates - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF EXISTS (SELECT id_permutation, name_error, COUNT(*) FROM tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL GROUP BY id_permutation HAVING COUNT(*) > 1) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - SELECT - a_guid, - v_id_error_type_bad_data, - v_code_error_type_bad_data, - CONCAT('Duplicate records: ', GROUP_CONCAT(t_CSOPLC.name_error SEPARATOR ', ')) - FROM (SELECT id_permutation, name_error, COUNT(*) FROM tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL GROUP BY id_permutation HAVING COUNT(*) > 1) t_CSOPLC - ; - END IF; - END IF; - - - - -- Permissions - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - SET v_ids_product := ( - SELECT GROUP_CONCAT(G.id_product SEPARATOR ',') - FROM ( - SELECT DISTINCT PP.id_product - FROM tmp_Shop_Customer_Sales_Order_Product_Link t_SPO - INNER JOIN Shop_Product_Permutation PP ON t_SPO.id_permutation = PP.id_permutation - ) G - ); - - CALL p_shop_calc_user(v_guid_permission, a_id_user, 0, v_id_permission_Customer_Sales_order, v_id_access_level_edit, v_ids_product); - - /* - UPDATE tmp_Shop_Supplier t_S - INNER JOIN Shop_Calc_User_Temp TP - ON TP.GUID = v_guid_permission - SET tP.can_view = TP.can_view, - tP.can_edit = TP.can_edit, - tP.can_admin = TP.can_admin; - */ - /* - SET v_has_permission := ( - SELECT can_edit - FROM Shop_Calc_User_Temp - WHERE - GUID = v_guid_permission - AND can_edit = 0 - ); - - IF v_has_permission = 0 THEN - SET v_id_error_type_no_permission := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'NO_PERMISSION'); - INSERT INTO tmp_Msg_Error ( - guid, id_type, msg - ) - SELECT - a_guid, - v_id_error_type_no_permission, - CONCAT('You do not have ', name, ' permissions.') - FROM Shop_Permission - WHERE id_permission = v_id_permission_Customer_Sales_order - ; - END IF; - */ - SET v_ids_product_no_permission := ( - SELECT GROUP_CONCAT(PT.id_product SEPARATOR ',') - FROM Shop_Calc_User_Temp PT - WHERE - PT.can_edit = 0 - AND NOT ISNULL(PT.id_product) - ); - IF NOT ISNULL(v_ids_product_no_permission) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES ( - a_guid, - v_id_error_type_no_permission, - v_code_error_type_no_permission, - CONCAT('You do not have permission to edit the following product IDs: ', v_ids_product_no_permission) - ) - ; - END IF; - - DELETE FROM Shop_Calc_User_Temp - WHERE GUID = a_guid; - END IF; - - -- Transaction - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - START TRANSACTION; - INSERT INTO Shop_Sales_And_Purchasing_Change_Set ( - comment, - updated_last_by, - updated_last_on - ) - VALUES ( - CONCAT( - 'Save ', - CASE WHEN v_is_new_Customer_Sales_order = 1 THEN 'new ' ELSE '' END, - 'Customer Sales Order - ', - a_comment - ), - a_id_user, - CURRENT_TIME() - ); - - SET v_id_change_set := (SELECT id_change_set FROM Shop_Sales_And_Purchasing_Change_Set ORDER BY id_change_set DESC LIMIT 1); - - IF (v_is_new_Customer_Sales_order = 1) THEN - INSERT INTO Shop_Customer_Sales_Order ( - id_customer, - price_total_local, - id_currency_price, - created_by, - id_change_set, - active - ) - SELECT - a_id_customer, - SUM(t_CSOPL.price_total_local), - a_id_currency_price, - a_id_user, - v_id_change_set, - a_active - FROM tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL - ; - -- SET v_id_order_new - SET a_id_order := (SELECT id_order FROM Shop_Customer_Sales_Order ORDER BY id_order DESC LIMIT 1); - INSERT INTO Shop_Customer_Sales_Order_Product_Link ( - id_order, - id_permutation, - price_total_local, - id_currency_price, - quantity_ordered, - id_unit_quantity, - quantity_delivered, - latency_delivery_days, - display_order, - active, - created_by, - id_change_set - ) - SELECT - a_id_order, -- v_id_order_new, - id_permutation, - price_total_local, - id_currency_price, - quantity_ordered, - id_unit_quantity, - quantity_delivered, - latency_delivery_days, - display_order, - active, - a_id_user, - v_id_change_set - FROM tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL - ; - ELSE - UPDATE Shop_Customer_Sales_Order CSO - INNER JOIN tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL ON CSO.id_order = t_CSOPL.id_order - SET - CSO.id_customer = a_id_customer, - CSO.price_total_local = SUM(t_CSOPL.price_total_local), - CSO.id_currency = a_id_currency_price, - CSO.id_change_set = v_id_change_set, - CSO.active = a_active - WHERE SPO.id_order = a_id_order - ; - IF EXISTS (SELECT * FROM tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL INNER JOIN Shop_Customer_Sales_Order_Product_Link CSOPL ON t_CSOPL.id_link = CSOPL.id_link) THEN - UPDATE Shop_Customer_Sales_Order_Product_Link CSOPL - INNER JOIN tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL - ON CSOPL.id_link = t_CSOPL.id_link - SET - CSOPL.id_order = t_CSOPL.id_order, - CSOPL.id_permutation = t_CSOPL.id_permutation, - CSOPL.price_total_local = t_CSOPL.price_total_local, - CSOPL.id_currency_price = t_CSOPL.id_currency_price, - CSOPL.quantity_ordered = t_CSOPL.quantity_ordered, - CSOPL.id_unit_quantity = t_CSOPL.id_unit_quantity, - CSOPL.quantity_delivered = t_CSOPL.quantity_delivered, - CSOPL.latency_delivery_days = t_CSOPL.latency_delivery_days, - CSOPL.display_order = t_CSOPL.display_order, - CSOPL.active = t_CSOPL.active, - CSOPL.id_change_set = v_id_change_set - ; - ELSE - INSERT INTO Shop_Customer_Sales_Order_Product_Link ( - id_order, - id_permutation, - price_total_local, - id_currency_price, - quantity_ordered, - id_unit_quantity, - quantity_delivered, - latency_delivery_days, - display_order, - active, - created_by, - id_change_set - ) - SELECT - id_order, - id_permutation, - price_total_local, - id_currency_price, - quantity_ordered, - id_unit_quantity, - quantity_delivered, - latency_delivery_days, - display_order, - active, - a_id_user, - v_id_change_set - FROM tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL - WHERE t_CSOPL.id_link < 0 - ; - END IF; - END IF; - - IF EXISTS (SELECT * FROM tmp_Msg_Error) THEN - ROLLBACK; - ELSE - COMMIT; - END IF; - END IF; - - -- Returns - -- SET v_now = NOW(); - - -- Supplier Purchase Orders - SELECT * - FROM Shop_Customer_Sales_Order - WHERE id_order = a_id_order - ; - - -- Supplier Purchase Order Product Links - SELECT * - FROM Shop_Customer_Sales_Order_Product_Link - WHERE id_order = a_id_order - ; - - -- Errors - SELECT * - FROM tmp_Msg_Error - ; - - -- DROP TABLE tmp_Shop_Customer_Sales_Order; - DROP TABLE tmp_Shop_Customer_Sales_Order_Product_Link; - DROP TABLE tmp_Msg_Error; -END // -DELIMITER ; - - -/* - -DELETE FROM Shop_Customer_Sales_Order_Product_Link_Audit; -DELETE FROM Shop_Customer_Sales_Order_Product_Link; -DELETE FROM Shop_Customer_Sales_Order_Product_Link_Temp; -DELETE FROM Shop_Customer_Sales_Order_Audit; -DELETE FROM Shop_Customer_Sales_Order; - -INSERT INTO Shop_Customer_Sales_Order_Product_Link_Temp ( - guid, - id_link, - id_order, - id_permutation, - price_total_local, - id_currency_price, - quantity_ordered, - id_unit_quantity, - quantity_delivered, - latency_delivery_days, - display_order, - active -) -VALUES - ( - 'NIPS', -- guid - -1, -- id_link, - -1, -- id_order, - 1, -- id_permutation, - 100, -- price_total_local, - 1, -- id_currency_price, - 1, -- quantity_ordered, - 1, -- id_unit_quantity, - 1, -- quantity_delivered, - 14, -- latency_delivery_days , - 1, -- display_order - 1 -- active - ) -; - -SELECT * FROM Shop_Customer_Sales_Order_Product_Link_Temp; - -CALL p_shop_save_customer_sales_order ( - 'NIPS', -- a_guid - 'auth0|6582b95c895d09a70ba10fef', -- a_id_user - 'Initial customer', -- a_comment - -1, -- a_id_order - 4, -- a_id_customer - 1, -- a_id_currency_price - 1 -- a_active -); - -SELECT * FROM Shop_Customer_Sales_Order_Product_Link_Temp; - -DELETE FROM Shop_Customer_Sales_Order_Product_Link_Audit; -DELETE FROM Shop_Customer_Sales_Order_Product_Link; -DELETE FROM Shop_Customer_Sales_Order_Product_Link_Temp; -DELETE FROM Shop_Customer_Sales_Order_Audit; -DELETE FROM Shop_Customer_Sales_Order; - - -*/ - - - --- File: 7425_p_shop_get_many_customer_sales_order.sql - - - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_get_many_customer_sales_order; - - -DELIMITER // -CREATE PROCEDURE p_shop_get_many_customer_sales_order ( - IN a_id_user INT, - IN a_get_all_customer BIT, - IN a_get_inactive_customer BIT, - IN a_get_first_customer_only BIT, - IN a_ids_customer VARCHAR(4000), - IN a_get_all_order BIT, - IN a_get_inactive_order BIT, - IN a_get_first_order_only BIT, - IN a_ids_order VARCHAR(4000), - IN a_get_inactive_category BIT, - IN a_ids_category VARCHAR(4000), - IN a_get_inactive_product BIT, - IN a_ids_product VARCHAR(4000), - IN a_get_inactive_permutation BIT, - IN a_ids_permutation VARCHAR(4000), - IN a_date_from DATETIME, - IN a_date_to DATETIME -) -BEGIN - -- Argument redeclaration - -- Variable declaration - DECLARE v_has_filter_customer BIT; - DECLARE v_has_filter_order BIT; - DECLARE v_has_filter_category BIT; - DECLARE v_has_filter_product BIT; - DECLARE v_has_filter_permutation BIT; - DECLARE v_has_filter_date_from BIT; - DECLARE v_has_filter_date_to BIT; - DECLARE v_guid BINARY(36); - -- DECLARE v_id_user VARCHAR(100); - -- DECLARE v_ids_permutation_unavailable VARCHAR(4000); - DECLARE v_ids_permission_customer_purchase_order VARCHAR(4000); - DECLARE v_ids_product_permission VARCHAR(4000); - -- DECLARE v_ids_permutation_permission VARCHAR(4000); - DECLARE v_id_access_level_view INT; - -- DECLARE v_now DATETIME; - -- DECLARE v_id_minimum INT; - DECLARE v_code_error_data VARCHAR(50); - DECLARE v_id_type_error_data INT; - - SET v_guid := UUID(); - SET v_id_access_level_view := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW' LIMIT 1); - -- SET v_ids_permission_customer_purchase_order := (SELECT id_permission FROM Shop_Permission WHERE code = 'Shop_Customer_Sales_ORDER' LIMIT 1); - SET v_code_error_data = 'BAD_DATA'; - SET v_id_type_error_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_data); - - -- Argument validation + default values - IF a_id_user IS NULL THEN - SET a_id_user = ''; - ELSE - SET a_id_user = TRIM(a_id_user); - END IF; - IF a_get_inactive_customer IS NULL THEN - SET a_get_inactive_customer = 0; - END IF; - IF a_get_first_customer_only IS NULL THEN - SET a_get_first_customer_only = 0; - END IF; - IF a_ids_customer IS NULL THEN - SET a_ids_customer = ''; - ELSE - SET a_ids_customer = TRIM(REPLACE(a_ids_customer, '|', ',')); - END IF; - - SET v_has_filter_customer = CASE WHEN a_ids_customer = '' THEN 0 ELSE 1 END; - - IF a_get_all_customer IS NULL THEN - SET a_get_all_customer = NOT v_has_filter_customer; - END IF; - IF a_get_inactive_order IS NULL THEN - SET a_get_inactive_order = 0; - END IF; - IF a_get_first_order_only IS NULL THEN - SET a_get_first_order_only = 0; - END IF; - IF a_ids_order IS NULL THEN - SET a_ids_order = ''; - ELSE - SET a_ids_order = TRIM(REPLACE(a_ids_order, '|', ',')); - END IF; - - SET v_has_filter_order = CASE WHEN a_ids_order = '' THEN 0 ELSE 1 END; - - IF a_get_all_order IS NULL THEN - SET a_get_all_order = NOT v_has_filter_customer; - END IF; - IF a_get_inactive_category IS NULL THEN - SET a_get_inactive_category = 0; - END IF; - IF a_ids_category IS NULL THEN - SET a_ids_category = ''; - ELSE - SET a_ids_category = TRIM(REPLACE(a_ids_category, '|', ',')); - END IF; - IF a_get_inactive_product IS NULL THEN - SET a_get_inactive_product = 0; - END IF; - IF a_ids_product IS NULL THEN - SET a_ids_product = ''; - ELSE - SET a_ids_product = TRIM(REPLACE(a_ids_product, '|', ',')); - END IF; - IF a_get_inactive_permutation IS NULL THEN - SET a_get_inactive_permutation = 0; - END IF; - IF a_ids_permutation IS NULL THEN - SET a_ids_permutation = ''; - ELSE - SET a_ids_permutation = TRIM(REPLACE(a_ids_permutation, '|', ',')); - END IF; - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Shop_Customer_Sales_Order_Product_Link; - DROP TABLE IF EXISTS tmp_Shop_Customer_Sales_Order; - DROP TABLE IF EXISTS tmp_Shop_Customer; - DROP TABLE IF EXISTS tmp_Shop_Product; - - CREATE TABLE tmp_Shop_Customer ( - id_customer INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Customer_id_customer - FOREIGN KEY (id_customer) - REFERENCES Shop_Customer(id_customer), - active BIT NOT NULL, - rank_customer INT NULL, - can_view BIT, - can_edit BIT, - can_admin BIT - ); - - CREATE TABLE tmp_Shop_Customer_Sales_Order ( - id_order INT NOT NULL PRIMARY KEY, - /* - id_customer INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Customer_Sales_Order_id_customer - FOREIGN KEY (id_customer) - REFERENCES Shop_Customer(id_customer), - price_total_local FLOAT NOT NULL, - id_currency_price INT NOT NULL, - */ - active BIT NOT NULL, - rank_order INT NOT NULL - ); - - /* - CREATE TABLE tmp_Shop_Customer_Sales_Order_Product_Link ( - id_link INT NOT NULL PRIMARY KEY, - id_order INT NOT NULL, - CONSTRAINT FK_tmp_customer_Purchase_Order_Product_Link_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Customer_Sales_Order(id_order), - id_permutation INT NOT NULL, - CONSTRAINT FK_tmp_customer_Purchase_Order_Product_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - price_total_local FLOAT NOT NULL, - id_currency_price INT NOT NULL, - quantity_ordered FLOAT NOT NULL, - id_unit_quantity INT NOT NULL, - CONSTRAINT FK_tmp_customer_Purchase_Order_Product_Link_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - quantity_received FLOAT NULL, - latency_delivery_days INT NOT NULL, - display_order INT NOT NULL - ); - */ - - CREATE TABLE tmp_Shop_Product ( - id_category INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_category - FOREIGN KEY (id_category) - REFERENCES Shop_Product_Category(id_category), - id_product INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - -- product_has_variations BIT NOT NULL, - id_permutation INT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - active_category BIT NOT NULL, - active_product BIT NOT NULL, - active_permutation BIT NULL, - display_order_category INT NOT NULL, - display_order_product INT NOT NULL, - display_order_permutation INT NULL, - rank_permutation INT NOT NULL, -- _in_category - -- name VARCHAR(255) NOT NULL, - -- description VARCHAR(4000) NOT NULL, - /* - price_GBP_full FLOAT NOT NULL, - price_GBP_min FLOAT NOT NULL, - */ - /* - latency_manufacture INT NOT NULL, - quantity_min FLOAT NOT NULL, - quantity_max FLOAT NOT NULL, - quantity_step FLOAT NOT NULL, - quantity_stock FLOAT NOT NULL, - is_subscription BIT NOT NULL, - id_unit_measurement_interval_recurrence INT, - CONSTRAINT FK_tmp_Shop_Product_id_unit_measurement_interval_recurrence - FOREIGN KEY (id_unit_measurement_interval_recurrence) - REFERENCES Shop_Interval_Recurrence(id_interval), - count_interval_recurrence INT, - id_stripe_product VARCHAR(100), - product_has_variations INT NOT NULL, - */ - can_view BIT, - can_edit BIT, - can_admin BIT - ); - - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - guid BINARY(36) NOT NULL, - id_type INT NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type (id_type), - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - - - -- Parse filters - SET v_has_filter_category = CASE WHEN a_ids_category = '' THEN 0 ELSE 1 END; - SET v_has_filter_product = CASE WHEN a_ids_product = '' THEN 0 ELSE 1 END; - SET v_has_filter_permutation = CASE WHEN a_ids_permutation = '' THEN 0 ELSE 1 END; - SET v_has_filter_date_from = CASE WHEN ISNULL(a_date_from) THEN 0 ELSE 1 END; - SET v_has_filter_date_to = CASE WHEN ISNULL(a_date_to) THEN 0 ELSE 1 END; - - -- select v_has_filter_product, v_has_filter_permutation; - - IF v_has_filter_customer = 1 OR a_get_all_customer = 1 THEN - CALL p_split(v_guid, a_ids_customer, ','); - - IF EXISTS (SELECT * FROM Split_Temp TS LEFT JOIN Shop_Customer S ON TS.substring = S.id_customer WHERE ISNULL(S.id_customer)) THEN - INSERT INTO tmp_Msg_Error ( - guid, - id_type, - code, - msg - ) - SELECT - v_guid, - v_id_type_error_data, - v_code_error_data, - CONCAT('Invalid customer IDs: ', IFNULL(GROUP_CONCAT(TS.substring SEPARATOR ', '), 'NULL')) - FROM Split_Temp TS - LEFT JOIN Shop_Customer C ON TS.substring = C.id_customer - WHERE ISNULL(C.id_customer) - ; - ELSE - INSERT INTO tmp_Shop_Customer ( - id_customer, - active, - rank_customer - ) - SELECT - C.id_customer, - C.active, - RANK() OVER (ORDER BY id_customer ASC) AS rank_customer - FROM Shop_Customer C - LEFT JOIN Split_Temp S_T ON C.id_customer = S_T.substring - WHERE - ( - a_get_all_customer = 1 - OR NOT ISNULL(S_T.substring) - ) - AND ( - a_get_inactive_customer - OR C.active = 1 - ) - ; - END IF; - - DROP TABLE Split_Temp; - - IF a_get_first_customer_only THEN - DELETE t_C - FROM tmp_Shop_Customer t_C - WHERE t_C.rank_customer > ( - SELECT MIN(t_C.rank_customer) - FROM tmp_Shop_Customer t_C - ) - ; - END IF; - END IF; - - IF v_has_filter_category = 1 THEN - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - CALL p_split(v_guid, a_ids_category, ','); - - IF EXISTS (SELECT * FROM Split_Temp TS LEFT JOIN Shop_Product_Category C ON TS.substring = C.id_category WHERE ISNULL(C.id_category)) THEN - INSERT INTO tmp_Msg_Error ( - guid, - id_type, - code, - msg - ) - SELECT - v_guid, - v_id_type_error_data, - v_code_error_data, - CONCAT('Invalid category IDs: ', IFNULL(GROUP_CONCAT(TS.substring SEPARATOR ', ') ,'NULL')) - FROM Split_Temp TS - LEFT JOIN Shop_Product_Category C ON TS.substring = C.id_category - WHERE ISNULL(C.id_category) - ; - END IF; - - DROP TABLE Temp_Split; - END IF; - END IF; - - IF v_has_filter_product = 1 THEN - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - CALL p_split(v_guid, a_ids_product, ','); - - IF EXISTS (SELECT * FROM Split_Temp TS LEFT JOIN Shop_Product ON TS.substring = P.id_product WHERE ISNULL(P.id_product)) THEN - INSERT INTO tmp_Msg_Error ( - guid, - id_type, - code, - msg - ) - SELECT - v_guid, - v_id_type_error_data, - v_code_error_data, - CONCAT('Invalid product IDs: ', IFNULL(GROUP_CONCAT(TS.substring SEPARATOR ', ') ,'NULL')) - FROM Split_Temp TS - LEFT JOIN Shop_Product ON TS.substring = P.id_product - WHERE ISNULL(P.id_product) - ; - END IF; - - DROP TABLE Temp_Split; - END IF; - END IF; - - IF v_has_filter_permutation = 1 THEN - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - CALL p_split(v_guid, a_ids_permutation, ','); - - IF EXISTS (SELECT * FROM Split_Temp TS LEFT JOIN Shop_Product_Permutation PP ON TS.substring = PP.id_permutation WHERE ISNULL(PP.id_permutation)) THEN - INSERT INTO tmp_Msg_Error ( - guid, - id_type, - code, - msg - ) - SELECT - v_guid, - v_id_type_error_data, - v_code_error_data, - CONCAT('Invalid permutation IDs: ', IFNULL(GROUP_CONCAT(TS.substring SEPARATOR ', ') ,'NULL')) - FROM Split_Temp TS - LEFT JOIN Shop_Product_Permutation PP ON TS.substring = PP.id_permutation - WHERE ISNULL(PP.id_permutation) - ; - END IF; - - DROP TABLE Temp_Split; - END IF; - END IF; - - IF v_has_filter_category = 1 OR v_has_filter_product = 1 OR v_has_filter_permutation = 1 THEN - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - INSERT INTO tmp_Shop_Product ( - id_category, - id_product, - id_permutation, - active_category, - active_product, - active_permutation, - display_order_category, - display_order_product, - display_order_permutation - -- rank_permutation, - /* - name, - description, - / * - price_GBP_VAT_incl, - price_GBP_VAT_excl, - price_GBP_min, - * - latency_manufacture, - quantity_min, - quantity_max, - quantity_step, - quantity_stock, - is_subscription, - id_unit_measurement_interval_recurrence, - count_interval_recurrence, - id_stripe_product, - product_has_variations - */ - ) - SELECT - P.id_category, - P.id_product, - -- P.has_variations AS product_has_variations, - PP.id_permutation, - C.active AS active_category, - P.active AS active_product, - PP.active AS active_permutation, - C.display_order AS display_order_category, - P.display_order AS display_order_product, - PP.display_order AS display_order_permutation - -- RANK() OVER (ORDER BY C.display_order, P.display_order, PP.display_order) AS rank_permutation, --PARTITION BY P.id_category -- _in_category - /* - P.name, - PP.description, - / * - PP.price_GBP_VAT_incl, - PP.price_GBP_VAT_excl, - PP.price_GBP_min, - * - PP.latency_manufacture, - PP.quantity_min, - PP.quantity_max, - PP.quantity_step, - PP.quantity_stock, - PP.is_subscription, - PP.id_unit_measurement_interval_recurrence, - PP.count_interval_recurrence, - PP.id_stripe_product, - P.has_variations - */ - FROM Shop_Product P - INNER JOIN Shop_Product_Permutation PP - ON P.id_product = PP.id_product - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - WHERE - -- permutations - ( - ( - NOT v_has_filter_permutation - OR FIND_IN_SET(PP.id_permutation, a_ids_permutation) > 0 - ) - AND ( - a_get_inactive_permutation - OR PP.active = 1 - ) - ) - -- categories - AND ( - ( - NOT v_has_filter_category - OR FIND_IN_SET(P.id_category, a_ids_category) > 0 - ) - AND ( - a_get_inactive_category - OR C.active = 1 - ) - ) - -- products - AND ( - ( - NOT v_has_filter_product - OR FIND_IN_SET(P.id_product, a_ids_product) > 0 - ) - AND ( - a_get_inactive_product - OR P.active = 1 - ) - ) - ; - END IF; - END IF; - - -- Get orders - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - CALL p_split(v_guid, a_ids_order, ','); - - IF v_has_filter_order AND EXISTS (SELECT * FROM Split_Temp TS LEFT JOIN Shop_Customer_Sales_Order CSO ON TS.substring = CSO.id_order WHERE ISNULL(CSO.id_order)) THEN - INSERT INTO tmp_Msg_Error ( - guid, - id_type, - code, - msg - ) - SELECT - v_guid, - v_id_type_error_data, - v_code_error_data, - CONCAT('Invalid order IDs: ', IFNULL(GROUP_CONCAT(TS.substring SEPARATOR ', '), 'NULL')) - FROM Split_Temp TS - LEFT JOIN Shop_Customer_Sales_Order CSO ON TS.substring = CSO.id_order - WHERE ISNULL(CSO.id_order) - ; - END IF; - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - INSERT INTO tmp_Shop_Customer_Sales_Order ( -- _Product_Link - id_order, - active, - rank_order - ) - SELECT - CSO.id_order, - CSO.active, - RANK() OVER (ORDER BY CSO.id_order ASC) AS rank_order - FROM Shop_Customer_Sales_Order CSO - LEFT JOIN Split_Temp S_T ON CSO.id_order = S_T.substring - INNER JOIN Shop_Customer_Sales_Order_Product_Link CSOPL ON CSO.id_order = CSOPL.id_order - INNER JOIN Shop_Customer S ON CSO.id_customer = S.id_customer - INNER JOIN Shop_Product_Permutation PP ON CSOPL.id_permutation = PP.id_permutation - INNER JOIN Shop_Product P ON PP.id_product = P.id_product - INNER JOIN Shop_Product_Category C ON P.id_category = C.id_category - LEFT JOIN tmp_Shop_Product t_P ON CSOPL.id_permutation = t_P.id_permutation - LEFT JOIN tmp_Shop_Customer t_S ON CSO.id_customer = t_S.id_customer - WHERE - -- customer - /* - ( - a_get_all_customer = 1 - OR NOT ISNULL(t_S.id_customer) -- CSO.id_customer IN (SELECT DISTINCT id_customer FROM tmp_Shop_Customer) - ) - */ - NOT ISNULL(t_S.id_customer) - -- order - AND ( - ( - a_get_all_order = 1 - OR ( - -- ID - -- FIND_IN_SET(CSO.id_order, a_ids_order) > 0 - NOT ISNULL(S_T.substring) - -- date - AND ( - ( - v_has_filter_date_from = 0 - OR CSO.created_on > a_date_from - ) - AND ( - v_has_filter_date_to = 0 - OR CSO.created_on < a_date_to - ) - ) - ) - ) - -- active - AND ( - a_get_inactive_order - OR CSO.active = 1 - ) - ) - -- permutations - AND ( - ( - v_has_filter_category = 0 - AND v_has_filter_product = 0 - AND v_has_filter_permutation = 0 - ) - OR NOT ISNULL(t_P.id_permutation) -- CSO.id_permutation IN (SELECT DISTINCT id_permutation FROM tmp_Shop_Product) - ) - ; - END IF; - - DROP TABLE Split_Temp; - - IF a_get_first_order_only THEN - DELETE t_CSO - FROM tmp_Shop_Customer_Sales_Order t_CSO - WHERE t_CSO.rank_order > ( - SELECT MIN(t_CSO.rank_order) - FROM tmp_Shop_Customer_Sales_Order t_CSO - ) - ; - END IF; - END IF; - - -- Permissions - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - -- SET v_id_user := (SELECT id_user FROM Shop_User WHERE name = CURRENT_USER()); - SET v_ids_permission_customer_purchase_order := (SELECT GROUP_CONCAT(id_permission SEPARATOR ',') FROM Shop_Permission WHERE code IN ('STORE_customer', 'STORE_customer_PURCHASE_ORDER')); - -- SET v_ids_permutation_permission := (SELECT GROUP_CONCAT(id_permutation SEPARATOR ',') FROM tmp_Shop_Product WHERE NOT ISNULL(id_permutation)); - SET v_ids_product_permission := (SELECT GROUP_CONCAT(P.id_product SEPARATOR ',') FROM (SELECT DISTINCT id_product FROM tmp_Shop_Product WHERE NOT ISNULL(id_product)) P); - - -- SELECT v_guid, a_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_permutation_permission; - -- select * from Shop_Calc_User_Temp; - - CALL p_shop_calc_user(v_guid, a_id_user, FALSE, v_ids_permission_customer_purchase_order, v_id_access_level_view, v_ids_product_permission); - - -- select * from Shop_Calc_User_Temp; - - IF NOT EXISTS (SELECT can_view FROM Shop_Calc_User_Temp UE_T WHERE UE_T.GUID = v_guid) THEN - INSERT INTO tmp_Msg_Error ( - guid, - id_type, - code, - msg - ) - SELECT - v_guid, - v_id_type_error_data, - v_code_error_data, - CONCAT('You do not have view permissions for ', GROUP_CONCAT(name SEPARATOR ', ')) - FROM Shop_Permission - WHERE id_permission = v_ids_permission_customer_purchase_order - ; - END IF; - - - UPDATE tmp_Shop_Product t_P - INNER JOIN Shop_Calc_User_Temp UE_T - ON t_P.id_product = UE_T.id_product -- t_P.id_permutation = UE_T.id_permutation - AND UE_T.GUID = v_guid - SET t_P.can_view = UE_T.can_view, - t_P.can_edit = UE_T.can_edit, - t_P.can_admin = UE_T.can_admin - ; - - -- CALL p_shop_clear_calc_user(v_guid); - -- DROP TABLE IF EXISTS Shop_Calc_User_Temp; - DELETE FROM Shop_Calc_User_Temp - WHERE GUID = v_guid - ; - END IF; - - - -- select * from tmp_Shop_Customer; - -- select * from tmp_Shop_Product; - - -- Returns - -- SET v_now := NOW(); - - -- customers - SELECT - t_S.id_customer, - S.name_company, - S.name_contact, - S.department_contact, - S.id_address, - S.phone_number, - S.email, - S.id_currency, - t_S.active - FROM tmp_Shop_Customer t_S - INNER JOIN Shop_Customer S - ON t_S.id_customer = S.id_customer - ; - - -- Customer Sales Order - SELECT -- * - t_CSO.id_order, - CSO.id_customer, - CSO.price_total_local, - CSO.id_currency_price, - t_CSO.active - FROM Shop_Customer_Sales_Order CSO - INNER JOIN tmp_Shop_Customer_Sales_Order t_CSO ON CSO.id_order = t_CSO.id_order - ; - - -- Customer Sales Order Product Link - SELECT - CSOPL.id_link, - CSOPL.id_order, - CSOPL.id_permutation, - P.name as name_product, - CSOPL.price_total_local, - CSOPL.id_currency_price, - CSOPL.quantity_ordered, - CSOPL.id_unit_quantity, - CSOPL.quantity_delivered, - CSOPL.latency_delivery_days, - CSOPL.display_order - FROM Shop_Customer_Sales_Order_Product_Link CSOPL - -- INNER JOIN tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL ON CSOPL.id_link = t_CSOPL.id_link - INNER JOIN tmp_Shop_Customer_Sales_Order t_CSO ON CSOPL.id_order = t_CSO.id_order - INNER JOIN Shop_Product_Permutation PP ON CSOPL.id_permutation = PP.id_permutation - INNER JOIN Shop_Product P ON PP.id_product = P.id_product - INNER JOIN Shop_Product_Category C ON P.id_category = C.id_category - ORDER BY CSOPL.id_order, C.display_order, P.display_order, PP.display_order - ; - - -- Errors - SELECT - /* - t_ME.display_order, - t_ME.guid, - t_ME.id_type, - t_ME.msg, - MET.code, - MET.name, - MET.description - */ - * - FROM tmp_Msg_Error t_ME - INNER JOIN Shop_Msg_Error_Type MET - ON t_ME.id_type = MET.id_type - WHERE guid = v_guid - ; - - /* - -- Return arguments for test - SELECT - a_ids_category, - a_get_inactive_category, - a_ids_product, - a_get_inactive_product, - a_get_first_product_only, - a_get_all_product, - a_ids_image, - a_get_inactive_image, - a_get_first_image_only, - a_get_all_image - ; - */ - - -- select 'other outputs'; - -- select * from tmp_Shop_Product; - - -- Clean up - DROP TABLE IF EXISTS tmp_Shop_Customer_Sales_Order_Product_Link; - DROP TABLE IF EXISTS tmp_Shop_Customer_Sales_Order; - DROP TABLE IF EXISTS tmp_Shop_Customer; - DROP TABLE IF EXISTS tmp_Shop_Product; - - DELETE FROM Shop_Calc_User_Temp - WHERE GUID = v_guid - ; -END // -DELIMITER ; - - -/* - -CALL p_shop_get_many_customer_sales_order ( - '', -- a_id_user - 1, -- a_get_all_customer - 0, -- a_get_inactive_customer - 0, -- a_get_first_customer_only - '', -- a_ids_customer - 1, -- a_get_all_order - 0, -- a_get_inactive_order - 0, -- a_get_first_order_only - '', -- a_ids_order - 0, -- a_get_inactive_category - '', -- a_ids_category - 0, -- a_get_inactive_product - '', -- a_ids_product - 0, -- a_get_inactive_permutation - '', -- a_ids_permutation - NULL, -- a_date_from - NULL -- a_date_to -); - -select * from shop_image; -select * from shop_product; -select * from TMP_MSG_ERROR; -DROP TABLE TMP_MSG_ERROR; - -insert into shop_product_change_set (comment) - values ('set product not subscription - test bool output to python'); - update shop_product - set is_subscription = 0, - id_change_set = (select id_change_set from shop_product_change_set order by id_change_set desc limit 1) - where id_product = 1 -*/ - - --- File: 9000_populate.sql - - - -/* - -CALL p_populate_database () - -*/ - -/* --- Remove previous proc -DROP PROCEDURE IF EXISTS p_populate_database; - - -DELIMITER // -CREATE PROCEDURE p_populate_database () -BEGIN -*/ - - --- Access Levels -INSERT INTO Shop_Access_Level ( - display_order, code, name, priority -) -VALUES - (1, 'VIEW', 'View', 3), - (2, 'EDIT', 'Edit', 2), - (3, 'ADMIN', 'Admin', 1) -; - -- Error Message Types -INSERT INTO Shop_Msg_Error_Type ( - code, name, description -) -VALUES - ('BAD_DATA', 'Invalid data', 'Rubbish data') - , ('NO_PERMISSION', 'No permission', 'Not authorised') - , ('PRODUCT_AVAILABILITY', 'Product not available', 'Product not available') - , ('MYSQL_ERROR', 'MySQL error', 'MySQL execution error.') - , ('WARNING', 'Warning', 'Non-breaking error.') -; - --- File Types -INSERT INTO File_Type ( - code, name, extension -) -VALUES - ('JPEG', 'Joint Photographic Export Group', 'jpg'), - ('PNG', 'Portable Network Graphic', 'png'), - ('GIF', 'GIF', 'gif'), - ('MPEG-4', 'Multimedia Photographic Export Group 4', 'mp4') -; - --- Generic / shared properties -INSERT INTO Shop_General ( - quantity_max -) -VALUES ( - 10 -); - --- Image types -INSERT INTO Shop_Image_Type ( - display_order, code, name, name_plural -) -VALUES - (1, 'FULL', 'Full Quality Image', 'Full Quality Images'), - (2, 'LOW', 'Low Quality Image', 'Low Quality Images'), - (3, 'THUMBNAIL', 'Thumbnail Image', 'Thumbnail Images') -; - --- Regions -INSERT INTO Shop_Region ( - display_order, code, name -) -VALUES - (1, 'UK', 'United Kingdom') -; - -/* --- Region Branches -INSERT INTO Shop_Region_Branch ( - display_order, id_region_parent, id_region_child -) -VALUES - (1, 1, 2) -; -*/ - --- Addresses -INSERT INTO Shop_Address ( - id_region, postcode, address_line_1, address_line_2, city, county -) -VALUES ( - 1, 'CV22 6DN', '53 Alfred Green Close', '', 'Rugby', 'Warwickshire' -); - --- Plants -INSERT INTO Shop_Plant ( - code, name, id_address, id_user_manager -) -VALUES - ('MAIN', 'Main Plant', 1, 1) -; - --- Storage Locations -INSERT INTO Shop_Storage_Location ( - id_plant, code, name -) -VALUES - (1, 'K-F-1', 'Kitchen Fridge 1') - , (1, 'K-AHL-M-B', 'Kitchen - Above Hob Left Medial - Bottom') - , (1, 'K-AHL-M-M', 'Kitchen - Above Hob Left Medial - Middle') - , (1, 'K-AHL-M-T', 'Kitchen - Above Hob Left Medial - Top') - , (1, 'K-AHL-L-B', 'Kitchen - Above Hob Left Lateral - Bottom') - , (1, 'K-AHL-L-M', 'Kitchen - Above Hob Left Lateral - Middle') - , (1, 'K-AHL-L-T', 'Kitchen - Above Hob Left Lateral - Top') - , (1, 'K-AHR-M-B', 'Kitchen - Above Hob Left Medial - Bottom') - , (1, 'K-AHR-M-M', 'Kitchen - Above Hob Left Medial - Middle') - , (1, 'K-AHR-M-T', 'Kitchen - Above Hob Left Medial - Top') - , (1, 'K-AHL-M-B', 'Kitchen - Above Hob Left Medial - Bottom') - , (1, 'K-AHL-M-M', 'Kitchen - Above Hob Left Medial - Middle') - , (1, 'K-AHL-M-T', 'Kitchen - Above Hob Left Medial - Top') - , (1, 'K-AHL-L-B', 'Kitchen - Above Hob Left Lateral - Bottom') - , (1, 'K-AHL-L-M', 'Kitchen - Above Hob Left Lateral - Middle') - , (1, 'K-AHL-L-T', 'Kitchen - Above Hob Left Lateral - Top') - , (1, 'K-AHL-XL-B', 'Kitchen - Above Hob Left Extra Lateral - Bottom') - , (1, 'K-AHL-XL-M', 'Kitchen - Above Hob Left Extra Lateral - Middle') - , (1, 'K-AHL-XL-T', 'Kitchen - Above Hob Left Extra Lateral - Top') - , (1, 'K-BS-B', 'Kitchen - Below Sink - Bottom') - , (1, 'K-BS-T', 'Kitchen - Below Sink - Top') - , (1, 'K-LO-B', 'Kitchen - Left of Oven - Bottom') - , (1, 'K-LO-T', 'Kitchen - Left of Oven - Top') - , (1, 'K-RO-M-B', 'Kitchen - Right of Oven - Medial - Bottom') - , (1, 'K-RO-M-M', 'Kitchen - Right of Oven - Medial - Middle') - , (1, 'K-RO-M-T', 'Kitchen - Right of Oven - Medial - Top') - , (1, 'K-RO-L-B', 'Kitchen - Right of Oven - Lateral - Bottom') - , (1, 'K-RO-L-T', 'Kitchen - Right of Oven - Lateral - Top') - , (1, 'K-BBB-B', 'Kitchen - Below Breakfast Bar - Bottom') - , (1, 'K-BBB-T', 'Kitchen - Below Breakfast Bar - Top') - , (1, 'K-BSL-M-B', 'Kitchen - Bekow Sink Left - Medial - Bottom') - , (1, 'K-BSL-M-T', 'Kitchen - Bekow Sink Left - Medial - Top') - , (1, 'K-BSL-L-B', 'Kitchen - Bekow Sink Left - Lateral - Bottom') - , (1, 'K-BSL-L-T', 'Kitchen - Bekow Sink Left - Lateral - Top') - , (1, 'K-ASL-M-B', 'Kitchen - Above Sink Left - Medial - Bottom') - , (1, 'K-ASL-M-M', 'Kitchen - Above Sink Left - Medial - Middle') - , (1, 'K-ASL-M-T', 'Kitchen - Above Sink Left - Medial - Top') - , (1, 'K-ASL-L-B', 'Kitchen - Above Sink Left - Lateral - Bottom') - , (1, 'K-ASL-L-M', 'Kitchen - Above Sink Left - Lateral - Middle') - , (1, 'K-ASL-L-T', 'Kitchen - Above Sink Left - Lateral - Top') - , (1, 'K-ASL-XL-B', 'Kitchen - Above Sink Left - Extra Lateral - Bottom') - , (1, 'K-ASL-XL-M', 'Kitchen - Above Sink Left - Extra Lateral - Middle') - , (1, 'K-ASL-XL-T', 'Kitchen - Above Sink Left - Extra Lateral - Top') - , (1, 'K-T-B', 'Kitchen - Tower - Bottom') - , (1, 'K-T-LM', 'Kitchen - Tower - Lower Middle') - , (1, 'K-T-UM', 'Kitchen - Tower - Upper Middle') - , (1, 'K-T-T', 'Kitchen - Tower - Top') - , (1, 'K-FJ-MEAT', 'Kitchen - Fridge - Meat Drawer') - , (1, 'K-FJ-VEG', 'Kitchen - Fridge - Vegetables Drawer') - , (1, 'K-FJ-CHEESE', 'Kitchen - Fridge - Cheese Drawer') - , (1, 'K-FJ-S-B', 'Kitchen - Fridge - Shelf - Bottom') - , (1, 'K-FJ-S-LM', 'Kitchen - Fridge - Shelf - Lower Middle') - , (1, 'K-FJ-S-UM', 'Kitchen - Fridge - Shelf - Upper Middle') - , (1, 'K-FJ-S-T', 'Kitchen - Fridge - Shelf - Top') - , (1, 'K-FJ-DG-B', 'Kitchen - Door Shelf (Guarded) - Bottom') - , (1, 'K-FJ-DG-LM', 'Kitchen - Door Shelf (Guarded) - Lower Middle') - , (1, 'K-FJ-DG-UM', 'Kitchen - Door Shelf (Guarded) - Upper Middle') - , (1, 'K-FJ-DG-T', 'Kitchen - Door Shelf (Guarded) - Top') - , (1, 'K-FJ-DU', 'Kitchen - Door Shelf (Unguarded)') - , (1, 'K-FZ-DRAWER-B', 'Kitchen - Freezer - Drawer - Bottom') - , (1, 'K-FZ-DRAWER-T', 'Kitchen - Freezer - Drawer - Top') - , (1, 'K-FZ-DRAWER-I', 'Kitchen - Freezer - Drawer - Ice') - , (1, 'K-FZ-S-B', 'Kitchen - Freezer - Shelf - Bottom') - , (1, 'K-FZ-S-M', 'Kitchen - Freezer - Shelf - Middle') - , (1, 'K-FZ-S-T', 'Kitchen - Freezer - Shelf - Top') - , (1, 'K-FZ-DOOR-XL', 'Kitchen - Freezer - Door - Extra Low') - , (1, 'K-FZ-DOOR-L', 'Kitchen - Freezer - Door - Lower') - , (1, 'K-FZ-DOOR-LM', 'Kitchen - Freezer - Door - Lower Middle') - , (1, 'K-FZ-DOOR-UM', 'Kitchen - Freezer - Door - Upper Middle') - , (1, 'K-FZ-DOOR-U', 'Kitchen - Freezer - Door - Upper') - , (1, 'K-FZ-DOOR-XU', 'Kitchen - Freezer - Door - Extra Up') - , (1, 'K-AFF', 'Kitchen - Above Fridge-Freezer') - , (1, 'K-CT', 'Kitchen - Counter Top') -; - -/* --- Storage Location Branches -INSERT INTO Shop_Storage_Location_Branch ( - id_location_parent, id_location_child -) -VALUES - (1, 2) -; -*/ - --- Currency -INSERT INTO Shop_Currency ( - display_order, code, name, symbol, factor_from_GBP -) -VALUES - (1, 'GBP', 'Great British Pound', '£', 1), - (2, 'EUR', 'Euro', '€', 1.17) -; - --- Taxes and Surcharges -INSERT INTO Shop_Tax_Or_Surcharge ( - display_order, - id_tax, - code, - name, - id_region_buyer, - id_region_seller, - fixed_fee, - multiplier, - apply_fixed_fee_before_multiplier, - quantity_min, - quantity_max -) -VALUES - (1, 1, 'VAT', 'Value Added Tax', 1, 1, 0, 0.2, 1, 0, 1) -; - --- Unit of Measurement -INSERT INTO Shop_Unit_Measurement ( - name_singular, name_plural, symbol, is_base_unit, is_unit_of_distance, is_unit_of_mass, is_unit_of_time, is_unit_of_volume -) -VALUES - ('metre', 'metres', 'm', 1, 1, 0, 0, 0) - , ('millimetre', 'millimetres', 'mm', 0, 1, 0, 0, 0) - , ('kilogram', 'kilograms', 'kg', 1, 0, 1, 0, 0) - , ('gram', 'grams', 'g', 0, 0, 1, 0, 0) - , ('litre', 'litres', 'L', 0, 0, 0, 0, 1) - , ('millilitre', 'millilitres', 'mL', 0, 0, 0, 0, 1) - , ('item', 'items', 'x', 0, 0, 0, 0, 0) - , ('hour', 'hours', 'h', 1, 0, 0, 1, 0) - , ('day', 'days', 'd', 0, 0, 0, 1, 0) -; - --- Unit of Measurement Conversion -INSERT INTO Shop_Unit_Measurement_Conversion ( - id_unit_derived - , id_unit_base - , display_order - , multiplier_unit_base - , increment_unit_base - , apply_multiplier_before_increment +INSERT INTO partsltd_prod.CORE_Msg_Error_Type ( + code + , name + , description ) VALUES ( - 2 -- id_unit_derived - , 1 -- id_unit_base - , 1 -- display_order - , 0.001 -- multiplier_unit_base - , 0 -- increment_unit_base - , apply_multiplier_before_increment - ) + 'BAD_DATA' + , 'Invalid data' + , 'Rubbish data' + ) , ( - 4 -- id_unit_derived - , 3 -- id_unit_base - , 1 -- display_order - , 0.001 -- multiplier_unit_base - , 0 -- increment_unit_base - , apply_multiplier_before_increment - ) + 'NO_PERMISSION' + , 'No permission' + , 'Not authorised' + ) + , ( + 'MYSQL_ERROR' + , 'MySQL error' + , 'MySQL execution error.' + ) + , ( + 'WARNING' + , 'Warning' + , 'Non-breaking error.' + ) +; + +-- Access Levels +INSERT INTO partsltd_prod.PH_Access_Level ( + display_order + , code + , name + , priority +) +VALUES + ( + 1 + , 'VIEW' + , 'View' + , 3 + ) , ( - 6 -- id_unit_derived - , 5 -- id_unit_base - , 1 -- display_order - , 0.001 -- multiplier_unit_base - , 0 -- increment_unit_base - , apply_multiplier_before_increment - ) + 2 + , 'EDIT' + , 'Edit' + , 2 + ) , ( - 9 -- id_unit_derived - , 8 -- id_unit_base - , 1 -- display_order - , 24 -- multiplier_unit_base - , 0 -- increment_unit_base - , apply_multiplier_before_increment - ) + 3 + , 'ADMIN' + , 'Admin' + , 1 + ) ; - --- Categories -INSERT INTO Shop_Product_Category ( - display_order, - code, - name, - description, - id_access_level_required, - created_by -) -VALUES - (1, 'ASS', 'Assistive Devices', 'Braille product line and other assistive devices', 1, 1), - (99, 'MISC', 'Miscellaneous', 'Not category allocated products', 1, 1), - (2, 'TECH', 'Technology', 'Technological devices', 1, 1) -; - -/* --- Recurrence Interval -INSERT INTO Shop_Interval_Recurrence ( - code, name, name_plural -) -VALUES - ('WEEK', 'Week', 'Weeks'), - ('MONTH', 'Month', 'Months'), - ('YEAR', 'Year', 'Years') -; -*/ - --- Products -INSERT INTO Shop_Product ( - display_order, - id_category, - name, - has_variations, - id_access_level_required, - created_by -) -VALUES - ( - 1, - 1, - 'Braille Keyboard Translator', - 1, - 3, - 1 - ), - ( - 2, - 2, - 'Test product 1', - 0, - 3, - 1 - ), - ( - 3, - 3, - 'Phone', - 0, - 1, - 1 - ), - ( - 4, - 3, - 'Laptop', - 0, - 1, - 1 - ), - ( - 5, - 3, - 'Smart Watch', - 0, - 1, - 1 - ) -; - --- Product Permutations -INSERT INTO Shop_Product_Permutation ( - -- display_order, - id_permutation_temp, - id_product, - description, - cost_local_VAT_excl, - cost_local_VAT_incl, - id_currency_cost, - profit_local_min, - -- id_currency_profit_min, - latency_manufacture, - id_unit_measurement_quantity, - count_unit_measurement_per_quantity_step, - quantity_min, - quantity_max, - quantity_stock, - is_subscription, - id_unit_measurement_interval_recurrence, - count_interval_recurrence, - -- id_access_level_required, - id_stripe_product - , does_expire_faster_once_unsealed - , id_unit_measurement_interval_expiration_unsealed - , count_interval_expiration_unsealed -) -VALUES - ( - -- 1, - -1, - 1, - 'Good Red', - 5, - 6, - 1, - 3, - -- 1, - 14, - 1, - 1, - 3, - 99, - 1, - 0, - NULL, - NULL, - -- 1, - NULL - , 0 - , NULL - , NULL - ), - ( - -- 2, - -2, - 1, - 'Good Blue', - 6, - 7.2, - 1, - 4, - -- 1, - 14, - 1, - 1, - 3, - 99, - 1, - 0, - NULL, - NULL, - -- 1, - NULL - , 0 - , NULL - , NULL - ), - ( - -- 3, - -3, - 2, - 'Test product describes good', - 10, - 12, - 1, - 5, - -- 1, - 14, - 1, - 1, - 2, - 99, - 1, - 0, - NULL, - NULL, - -- 1, - NULL - , 0 - , NULL - , NULL - ), - ( - -- 4, - -4, - 3, - 'Phone describes good', - 10, - 12, - 1, - 5, - -- 1, - 14, - 1, - 1, - 2, - 99, - 1, - 0, - NULL, - NULL, - -- 1, - NULL - , 0 - , NULL - , NULL - ), - ( - -- 5, - -5, - 4, - 'Laptop describes good', - 10, - 12, - 1, - 5, - -- 1, - 14, - 1, - 1, - 2, - 99, - 1, - 0, - NULL, - NULL, - -- 1, - NULL - , 0 - , NULL - , NULL - ), - ( - -- 6, - -6, - 5, - 'Smart watch describes good', - 10, - 12, - 1, - 5, - -- 1, - 14, - 1, - 1, - 2, - 99, - 1, - 0, - NULL, - NULL, - -- 1, - NULL - , 0 - , NULL - , NULL - ) -; - --- Variation Types -INSERT INTO Shop_Variation_Type ( - display_order, code, name, name_plural -) -VALUES - (1, 'COLOUR', 'Colour', 'Colours') - , (2, 'SIZE', 'Size', 'Sizes') -; - --- Variations -INSERT INTO Shop_Variation ( - display_order, id_type, code, name, id_unit_measurement, count_unit_measurement -) -VALUES - (1, 1, 'RED', 'Red', NULL, NULL) - , (2, 1, 'BLUE', 'Blue', NULL, NULL) - , (3, 1, 'GREEN', 'Green', NULL, NULL) - , (4, 1, 'White', 'White', NULL, NULL) - , (5, 1, 'BLACK', 'Black', NULL, NULL) - , (1, 2, '400ml', '400 millilitres', 6, 400) - , (2, 2, '400g', '400 grams', 4, 400) - , (3, 2, '410g', '410 grams', 4, 410) - , (4, 2, '8g', '8 grams', 4, 8) - , (5, 2, '13g', '13 grams', 4, 13) - , (6, 2, '27g', '27 grams', 4, 27) - , (7, 2, '104g', '104 grams', 4, 104) - , (8, 2, '200g', '200 grams', 4, 200) - , (9, 2, '92g', '92 grams', 4, 92) - , (10, 2, '100g', '100 grams', 4, 100) - , (11, 2, '500g', '500 grams', 4, 500) - , (12, 2, '250g', '250 grams', 4, 250) - , (13, 2, '750g', '750 grams', 4, 750) - , (14, 2, '145g', '145 grams', 4, 145) - , (15, 2, '340g', '340 grams', 4, 340) - , (16, 2, '132g', '132 grams', 4, 132) - , (17, 2, '170g', '170 grams', 4, 170) - , (18, 2, '700g', '700 grams', 4, 700) - , (19, 2, '150g', '150 grams', 4, 150) - , (20, 2, '1kg', '1 kilogram', 3, 1) - , (21, 2, '2kg', '2 kilograms', 3, 2) - , (22, 2, '800ml', '800 millilitres', 6, 800) - , (23, 2, '570g', '570 grams', 4, 570) - , (24, 2, '300g', '300 grams', 4, 300) - , (25, 2, '350g', '350 grams', 4, 350) - , (26, 2, '30g', '30 grams', 4, 30) - , (27, 2, '1L', '1 litre', 5, 1) - , (28, 2, '1.2L', '1.2 litres', 5, 1.2) - , (29, 2, '1.8L', '1.8 litres', 5, 1.8) - , (30, 2, 'bag of 20', 'bag of 20', 7, 20) - , (31, 2, '180ml', '180 millilitres', 6, 180) - , (32, 2, '70g', '70 grams', 4, 70) - , (33, 2, '60ml', '60 millilitres', 6, 60) - , (34, 2, '325g', '325 grams', 4, 325) - , (35, 2, 'pack of 50', 'pack of 50', 7, 50) - , (36, 2, 'box of 24 (each 5.9g)', 'box of 24 (each 5.9 grams)', 7, 24) - , (37, 2, '397g', '397 grams', 4, 397) - , (38, 2, '720g', '720 grams', 4, 720) - , (39, 2, '454g', '454 grams', 4, 454) - , (40, 2, 'pack of 4 (each 37g)', 'pack of 4 (each 37 grams)', 7, 4) - , (41, 2, '450g', '450 grams', 4, 450) - , (42, 2, '24.6.g', '24.6 grams', 4, 24.6) - , (43, 2, '230g', '230 grams', 4, 230) - , (44, 2, '37.3g', '37.3 grams', 4, 37.3) - , (45, 2, '38.3g', '38.3 grams', 4, 38.3) - , (46, 2, '123g', '123 grams', 4, 123) - , (47, 2, '266g', '266 grams', 4, 266) - , (48, 2, '157g', '157 grams', 4, 157) - , (49, 2, '285g', '285 grams', 4, 285) - , (50, 2, '700ml', '700 millilitres', 6, 700) - , (51, 2, '5L', '5 litres', 5, 5) - , (52, 2, '216g', '216 grams', 4, 216) - , (53, 2, '320g', '320 grams', 4, 320) - , (54, 2, '2L', '2 litres', 5, 2) - , (55, 2, '200ml', '200 millilitres', 6, 200) - , (56, 2, '250ml', '250 millilitres', 6, 250) - , (57, 2, '1 punnet', '1 punnet', 7, 1) - , (58, 2, '420g', '420 grams', 4, 420) - , (59, 2, '230g', '230 grams', 4, 230) - , (60, 2, '465g', '465 grams', 4, 465) - , (61, 2, '500ml', '500 millilitres', 6, 500) - , (62, 2, '250ml', '250 millilitres', 6, 250) - , (63, 2, '238ml', '238 millilitres', 6, 238) - , (64, 2, '140ml', '140 millilitres', 6, 140) - , (65, 2, '195g', '195 grams', 4, 195) - , (66, 2, '1pt', '1 pint', 5, 1) - , (67, 2, '570ml', '570 millilitres', 6, 570) - , (68, 2, '360g', '360 grams', 4, 360) - , (69, 2, '90g', '90 grams', 4, 90) - , (70, 2, '800ml', '800 millilitres', 6, 800) - , (71, 2, '197g', '197 grams', 4, 197) -; - -INSERT INTO partsltd_prod.Shop_Product_Change_Set ( - comment -) -VALUES ( 'Update Variation Display Orders' ) -; -UPDATE partsltd_prod.Shop_Variation V -INNER JOIN ( - SELECT - V.id_variation, - RANK() OVER (ORDER BY - CONCAT( - CASE WHEN V.count_unit_measurement = FLOOR(V.count_unit_measurement) THEN - LPAD(CAST(V.count_unit_measurement AS CHAR), 25, '0') - ELSE - CONCAT( - LPAD( - CAST(FLOOR(V.count_unit_measurement) AS CHAR) - , 25 - , '0' - ) - , SUBSTRING( - CAST(V.count_unit_measurement AS CHAR) - FROM LOCATE('.', CAST(V.count_unit_measurement AS CHAR)) - ) - ) - END - , ' ' - , IFNULL(IFNULL(UM.symbol, UM.name_singular), '(No Unit of Measurement)') - ) - ) as new_order - FROM partsltd_prod.Shop_Variation V - INNER JOIN partsltd_prod.Shop_Unit_Measurement UM - ON V.id_unit_measurement = UM.id_unit_measurement - AND UM.active = 1 - WHERE - V.id_type = 2 -) AS RANKED ON V.id_variation = RANKED.id_variation -JOIN ( - SELECT CS.id_change_set - FROM partsltd_prod.Shop_Product_Change_Set CS - ORDER BY CS.id_change_set DESC - LIMIT 1 -) AS CS -SET - V.display_order = RANKED.new_order - , V.id_change_set = CS.id_change_set -WHERE - V.id_type = 2 -; - --- Product Permutation Variation Links -INSERT INTO Shop_Product_Permutation_Variation_Link ( - display_order, id_permutation, id_variation -) -VALUES - (1, 1, 1), - (2, 2, 2) -; - --- Stock items -INSERT INTO Shop_Stock_Item ( - id_permutation - , date_purchased - , id_location_storage - , id_currency_cost - , cost_local_VAT_incl - , cost_local_VAT_excl - , date_expiration -) -VALUES - (1, NOW(), 1, 1, 5, 4.2, '2025-09-05 00:00:00'), - (2, NOW(), 1, 1, 6, 5, '2026-09-05 00:00:00'), - (3, NOW(), 1, 1, 10, 8.4, '2027-09-05 00:00:00'), - (4, NOW(), 1, 1, 10, 8.4, '2028-09-05 00:00:00'), - (5, NOW(), 1, 1, 10, 8.4, '2029-09-05 00:00:00'), - (6, NOW(), 1, 1, 10, 8.4, '2030-09-05 00:00:00') -; - --- Product Price -INSERT INTO Shop_Product_Price ( - id_permutation - , id_currency - , id_region_purchase - , price_local_VAT_incl - , price_local_VAT_excl -) -VALUES - (1, 1, 1, 24, 20), - (1, 2, 1, 48, 40), - (2, 1, 1, 96, 80), - (3, 1, 1, 144, 120), - (4, 1, 1, 600, 500), - (5, 1, 1, 1500, 1200), - (6, 1, 1, 180, 150) -; - --- Product Images -INSERT INTO Shop_Product_Image ( - display_order, - id_permutation, - id_type_image, - url -) -VALUES - (1, 1, 1, '/static/images/prod_PB0NUOSEs06ymG.jpg'), - -- (1, 1, 1, '/static/images/prod_PB0NUOSEs06ymG.jpg'), - (2, 2, 1, '/static/images/prod_PB0NUOSEs06ymG.jpg'), - -- (1, 2, 1, '/static/images/prod_PB0NUOSEs06ymG.jpg') - (3, 3, 1, '/static/images/prod_PB0NUOSEs06ymG.jpg'), - (4, 4, 1, '/static/images/prod_.jpg'), - (5, 5, 1, '/static/images/prod_1.jpg'), - (6, 6, 1, '/static/images/prod_2.jpg') -; - --- Delivery Options -INSERT INTO Shop_Delivery_Option ( - display_order, code, name, latency_delivery_min, latency_delivery_max -) -VALUES - (1, 'COLLECT', 'Collection', 0, 0), - (2, 'SIGNED_1', 'First Class Signed-For', 2, 4) -; - --- Product Delivery Option Links -INSERT INTO Shop_Product_Permutation_Delivery_Option_Link ( - display_order, id_product, id_permutation, id_delivery_option, id_region, id_currency, price_local, quantity_min, quantity_max -) -VALUES - (1, 1, 1, 1, 1, 1, 5, 0, 1), - (2, 1, 2, 1, 1, 1, 9, 0, 1), - (3, 2, 3, 1, 1, 1, 10, 0, 1), - (4, 3, 4, 1, 1, 1, 10, 0, 1), - (5, 4, 5, 1, 1, 1, 10, 0, 1), - (6, 5, 6, 1, 1, 1, 10, 0, 1) -; - --- Discounts -INSERT INTO Shop_Discount ( - id_product, - id_permutation, - code, - name, - multiplier, - quantity_min, - quantity_max, - date_start, - date_end, - display_order -) -VALUES - (1, 1, 'CRIMBO50', 'Christmas 50% off sale!', 0.5, 3, 9, NOW(), '2023-12-31 23:59:59', 1), - (1, 2, 'CRIMBO50', 'Christmas 50% off sale!', 0.5, 3, 9, NOW(), '2023-12-31 23:59:59', 1) -; - --- Discount Delivery Region Currency Links -INSERT INTO Shop_Discount_Region_Currency_Link ( - id_discount, - id_region, - id_currency -) -VALUES - (1, 1, 1), - (2, 1, 1), - (1, 1, 2), - (2, 1, 2) -; - - -- Permission Groups -INSERT INTO Shop_Permission_Group ( - display_order, code, name +INSERT INTO partsltd_prod.PH_Permission_Group ( + display_order + , code + , name ) VALUES - (0, 'ADMIN', 'Website Admin'), - (1, 'HOME', 'Home, Contact Us, and other public information'), - (2, 'PRODUCT', 'Store Products'), - (3, 'USER', 'Store User'), - (4, 'SALES_AND_PURCHASING', 'Sales and Purchasing'), - (5, 'MANUFACTURING', 'Manufacturing') + ( + 0 + , 'CONTACT_FORM' + , 'Contact Form' + ) + , ( + 1 + , 'USER' + , 'Admin User' + ) ; -/* -select * from Shop_Permission -select * from Shop_Role_Permission_Link -*/ + -- Permissions -INSERT INTO Shop_Permission ( - display_order, code, name, id_permission_group, id_access_level_required +INSERT INTO partsltd_prod.PH_Permission ( + display_order + , code + , name + , id_permission_group + , id_access_level_required ) VALUES - (1, 'HOME', 'Home Page', 2, 1), - (2, 'STORE_PRODUCT', 'Store Product Page', 3, 1), - (3, 'STORE_USER', 'Store User Account Page', 4, 2), - (10, 'STORE_USER_ADMIN', 'Store User Admin Page', 4, 3), - (4, 'STORE_ADMIN', 'Store Admin Page', 1, 3), - (5, 'STORE_SUPPLIER', 'Store Supplier Page', 4, 2), - (6, 'STORE_SUPPLIER_PURCHASE_ORDER', 'Store Supplier Purchase Order Page', 4, 2), - (7, 'STORE_MANUFACTURING_PURCHASE_ORDER', 'Store Manufacturing Purchase Order Page', 5, 2), - (8, 'STORE_CUSTOMER', 'Store Customer Page', 4, 2), - (9, 'STORE_CUSTOMER_SALES_ORDER', 'Store Customer Sales Order Page', 4, 2), - (99, 'CONTACT_US', 'Contact Us Page', 2, 1) -; - --- Roles -INSERT INTO Shop_Role ( - display_order, - code, - name -) -VALUES - (1, 'DIRECTOR', 'Director'), - (2, 'USER', 'User') -; - --- Role Permission link -INSERT INTO Shop_Role_Permission_Link ( - id_role, id_permission, id_access_level -) -VALUES - (1, 1, 3), - (1, 2, 3), - (1, 3, 3), - (1, 4, 3), - (1, 5, 3), - (1, 6, 3), - (1, 7, 3), - (1, 8, 3), - (1, 9, 3), - (1, 10, 3), - (1, 11, 3), - (2, 1, 1), - (2, 2, 1), - (2, 3, 1), - (2, 4, 1), - (2, 5, 1) + ( + 1 + , 'CONTACT_FORM_NEW' + , 'New Contact Form' + , 1 + , 3 + ) + , ( + 1 + , 'CONTACT_FORM_ADMIN' + , 'Admin Contact Form' + , 1 + , 3 + ) + , ( + 1 + , 'CONTACT_FORM_CREATE' + , 'Create Contact Form' + , 1 + , 1 + ) ; -- Users -INSERT INTO Shop_User ( - id_user_auth0 +INSERT INTO partsltd_prod.PH_User ( + id_user_auth0 , firstname , surname , email @@ -24982,22 +2447,14 @@ INSERT INTO Shop_User ( ) VALUES ( - 'auth0|6582b95c895d09a70ba10fef' -- id_user_auth0 + 'auth0|6582b95c895d09a70ba10fef' -- id_user_auth0 , 'Teddy' -- firstname , 'Middleton-Smith' -- surname , 'edward.middletonsmith@gmail.com' -- email , 1 -- is_super_user , 1 -- active - ), - ( - 'parts_guest' -- id_user_auth0 - , 'Guest' -- firstname - , '' -- surname - , '' -- email - , 0 -- is_super_user - , 1 -- active - ), - ( + ) + , ( 'auth0|672659014296b7f94a9bab45' -- id_user_auth0 , 'Tierney' -- firstname , 'Gullen' -- surname @@ -25005,481 +2462,161 @@ VALUES , 1 -- is_super_user , 1 -- active ) + , ( + NULL -- id_user_auth0 + , 'Contact Form Bot' -- firstname + , 'Bot' -- surname + , 'teddy@partsltd.co.uk' -- email + , 0 -- is_super_user + , 1 -- active + ) ; --- User Role link -INSERT INTO Shop_User_Role_Link ( - id_user, id_role -) -VALUES - (1, 1) -; - --- User Addresses -INSERT INTO Shop_User_Address ( - id_user, id_region, name_full, phone_number, postcode, address_line_1, address_line_2, city, county -) -SELECT U.id_user, 1, CONCAT(U.firstname, ' ', U.surname), '07375 571430', 'CV22 6DN', '53 Alfred Green Close', '', 'Rugby', 'Warwickshire' - FROM Shop_User U -; - --- User Basket -INSERT INTO Shop_User_Basket ( - id_user, - id_product, - id_permutation, - quantity -) -VALUES - (1, 1, 1, 69) -; - --- User Order Status -INSERT INTO Shop_User_Order_Status ( - display_order, code, name, name_plural -) -VALUES - (1, 'SUCCESS', 'Success', 'Successes'), - (2, 'FAIL', 'Failure', 'Failures') -; - -/* --- User Order -INSERT INTO Shop_User_Order ( - id_user, value_total, id_order_status, id_checkout_session, id_currency -) -VALUES - (1, 25, 1, 'noods', 1), - (1, 25, 1, 'noods', 1) -; - --- User Order Product Link -INSERT INTO Shop_User_Order_Product_Link ( - id_order, id_product, id_permutation, quantity -) -VALUES - (1, 1, 1, 69), - (1, 2, NULL, 69), - (1, 1, 2, 69) -; -*/ - --- Supplier -INSERT INTO Shop_Supplier ( - id_supplier_temp - , name_company - , name_contact - , department_contact - -- , id_address - , phone_number - , fax - , email - , website - , id_currency -) -VALUES - ( - -1 - , 'Precision And Research Technology Systems Limited' - , 'Teddy Middleton-Smith' - , 'Executive Management' - -- , 1 - , '07375571430' - , '' - , 'teddy@partsltd.co.uk' - , 'www.partsltd.co.uk' - , 1 - ) -; - --- Suppliers -INSERT INTO Shop_Supplier ( - id_supplier_temp - , name_company - , name_contact - , department_contact - -- , id_address - , phone_number - , fax - , email - , website - , id_currency -) -VALUES - ( - -2 - , 'Malt Kiln Farm Shop' - , NULL - , NULL - -- , 1 - , '01788 832640' - , NULL - , 'farmshop@maltkilnfarmshop.co.uk' - , 'https://www.maltkilnfarmshop.co.uk/' - , 1 - ) - , ( - -3 - , 'Asda' - , NULL - , NULL - -- , 1 - , '' - , NULL - , '' - , '' - , 1 - ) -; - --- Supplier Addresses -INSERT INTO Shop_Supplier_Address ( - id_supplier - , id_region - , postcode - , address_line_1 - , address_line_2 - , city - , county - , active -) -VALUES - ( - 1 - , 1 - , 'CV22 6DN' - , '53 Alfred Green Close' - , '' - , 'Rugby' - , 'Warwickshire' - , 1 - ), - ( - 2 - , 1 - , 'CV22 6DN' - , '53 Alfred Green Close' - , '' - , 'Rugby' - , 'Warwickshire' - , 1 - ) -; - -/* --- Supplier Purchase Order -INSERT INTO Shop_Supplier_Purchase_Order ( - id_supplier, value_total, id_order_status, id_checkout_session, id_currency -) -VALUES -; - --- Supplier Purchase Order Product Link -INSERT INTO Shop_Supplier_Purchase_Order_Product_Link ( - id_order, id_permutation, cost_total_local, id_currency_cost, quantity_ordered, id_unit_quantity, quantity_received, latency_delivery, display_order -) -VALUES -; -*/ - -/* --- Manufacturing Purchase Order -INSERT INTO Shop_Manufacturing_Purchase_Order ( - cost_total_local, id_currency_cost -) -VALUES -; - --- Manufacturing Purchase Order Product Link -INSERT INTO Shop_Manufacturing_Purchase_Order_Product_Link ( - id_order, id_permutation, cost_total_local, id_currency_cost, quantity_used, id_unit_quantity, quantity_produced, latency_manufacturing_days, display_order -) -VALUES -; -*/ - -/* --- Customer -INSERT INTO Shop_Customer ( - name_company, name_contact, department_contact, id_address, phone_number, email, id_currency -) -VALUES - -; -*/ - -/* --- Customer Sales Order -INSERT INTO Shop_Customer_Sales_Order ( - cost_total_local, id_currency_cost -) -VALUES -; - --- Customer Sales Order Product Link -INSERT INTO Shop_Customer_Sales_Order_Product_Link ( - id_order, id_permutation, cost_total_local, id_currency_cost, quantity_ordered, id_unit_quantity, quantity_delivered, latency_delivery_days, display_order -) -VALUES -; -*/ - - - - -/* - -- Clean up -END // -DELIMITER ; - - --- Call -CALL p_populate_database(); - --- Remove proc -DROP PROCEDURE IF EXISTS p_populate_database; -*/ - --- File: 9001_view.sql - - - --- Product Change Sets -SELECT * FROM Shop_Product_Change_Set; - --- User Change Sets -SELECT * FROM Shop_User_Change_Set; - --- User Change Sets -SELECT * FROM Shop_Sales_And_Purchasing_Change_Set; - --- Access Levels -SELECT * FROM Shop_Access_Level; -SELECT * FROM Shop_Access_Level_Audit; - --- Error Message type -SELECT * FROM Shop_Msg_Error_Type; - --- File Types -SELECT * FROM File_Type; -SELECT * FROM File_Type_Audit; - --- Generic / shared properties -SELECT * FROM Shop_General; -SELECT * FROM Shop_General_Audit; - --- Image Types -SELECT * FROM Shop_Image_Type; -SELECT * FROM Shop_Image_Type_Audit; - - --- Regions -SELECT * FROM Shop_Region; -SELECT * FROM Shop_Region_Audit; - --- Region branches -SELECT * FROM Shop_Region_Branch; -SELECT * FROM Shop_Region_Branch_Audit; - --- Plants -SELECT * FROM Shop_Plant; -SELECT * FROM Shop_Plant_Audit; - --- Storage Locations -SELECT * FROM Shop_Storage_Location; -SELECT * FROM Shop_Storage_Location_Audit; - --- Storage Location branches -SELECT * FROM Shop_Storage_Location_Branch; -SELECT * FROM Shop_Storage_Location_Branch_Audit; - --- Currencies -SELECT * FROM Shop_Currency; -SELECT * FROM Shop_Currency_Audit; - --- Taxes and Surcharges -SELECT * FROM Shop_Tax_Or_Surcharge; -SELECT * FROM Shop_Tax_Or_Surcharge_Audit; - --- Unit of Measurement -SELECT * FROM Shop_Unit_Measurement; -SELECT * FROM Shop_Unit_Measurement_Audit; - --- Unit of Measurement Conversion -SELECT * FROM Shop_Unit_Measurement_Conversion; -SELECT * FROM Shop_Unit_Measurement_Conversion_Audit; - -/* --- Recurrence Interval -SELECT * FROM Shop_Interval_Recurrence; -SELECT * FROM Shop_Interval_Recurrence_Audit; -*/ - - --- Categories -SELECT * FROM Shop_Product_Category; -SELECT * FROM Shop_Product_Category_Audit; - --- Products -SELECT * FROM Shop_Product; -SELECT * FROM Shop_Product_Audit; - --- Permutations -SELECT * FROM Shop_Product_Permutation; -SELECT * FROM Shop_Product_Permutation_Audit; - --- Variation Types -SELECT * FROM Shop_Variation_Type; -SELECT * FROM Shop_Variation_Type_Audit; - --- Variations -SELECT * FROM Shop_Variation; -SELECT * FROM Shop_Variation_Audit; - --- Permutation Variation Links -SELECT * FROM Shop_Product_Permutation_Variation_Link; -SELECT * FROM Shop_Product_Permutation_Variation_Link_Audit; - --- Stock Items -SELECT * FROM Shop_Stock_Item; -SELECT * FROM Shop_Stock_Item_Audit; - --- Product Currency Links -SELECT * FROM Shop_Product_Price; -SELECT * FROM Shop_Product_Price; - --- Images -SELECT * FROM Shop_Product_Image; -SELECT * FROM Shop_Product_Image_Audit; - --- Delivery Option Types -SELECT * FROM Shop_Delivery_Option; -SELECT * FROM Shop_Delivery_Option_Audit; - --- Delivery Options -SELECT * FROM Shop_Product_Permutation_Delivery_Option_Link; -SELECT * FROM Shop_Product_Permutation_Delivery_Option_Link_Audit; - --- Discounts -SELECT * FROM Shop_Discount; -SELECT * FROM Shop_Discount_Audit; - --- Discount Delivery Region Links -SELECT * FROM Shop_Discount_Region_Currency_Link; -SELECT * FROM Shop_Discount_Region_Currency_Link_Audit; - - --- Permission Groups -SELECT * FROM Shop_Permission_Group; -SELECT * FROM Shop_Permission_Group_Audit; - --- Permissions -SELECT * FROM Shop_Permission; -SELECT * FROM Shop_Permission_Audit; - -- Roles -SELECT * FROM Shop_Role; -SELECT * FROM Shop_Role_Audit; - --- Role Permission link -SELECT * FROM Shop_Role_Permission_Link; -SELECT * FROM Shop_Role_Permission_Link_Audit; - --- Users -SELECT * FROM Shop_User; -SELECT * FROM Shop_User_Audit; - --- User Role link -SELECT * FROM Shop_User_Role_Link; -SELECT * FROM Shop_User_Role_Link_Audit; - --- Addresses -SELECT * FROM Shop_Address; -SELECT * FROM Shop_Address_Audit; - --- Basket -SELECT * FROM Shop_User_Basket; -SELECT * FROM Shop_User_Basket_Audit; - - --- Order Statuses -SELECT * FROM Shop_User_Order_Status; -SELECT * FROM Shop_User_Order_Status_Audit; - -/* --- Orders -SELECT * FROM Shop_User_Order; -SELECT * FROM Shop_User_Order_Audit; - --- Order Products -SELECT * FROM Shop_User_Order_Product_Link; -SELECT * FROM Shop_User_Order_Product_Link_Audit; -*/ - --- Supplier -SELECT * FROM Shop_Supplier; -SELECT * FROM Shop_Supplier_Audit; - --- Supplier Purchase Order -SELECT * FROM Shop_Supplier_Purchase_Order; -SELECT * FROM Shop_Supplier_Purchase_Order_Audit; - --- Supplier Purchase Order Product Link -SELECT * FROM Shop_Supplier_Purchase_Order_Product_Link; -SELECT * FROM Shop_Supplier_Purchase_Order_Product_Link_Audit; - --- Manufacturing Purchase Order -SELECT * FROM Shop_Manufacturing_Purchase_Order; -SELECT * FROM Shop_Manufacturing_Purchase_Order_Audit; - --- Manufacturing Purchase Order Product Link -SELECT * FROM Shop_Manufacturing_Purchase_Order_Product_Link; -SELECT * FROM Shop_Manufacturing_Purchase_Order_Product_Link_Audit; - --- Customers -SELECT * FROM Shop_Customer; -SELECT * FROM Shop_Customer_Audit; - --- Customer Sales Order -SELECT * FROM Shop_Customer_Sales_Order; -SELECT * FROM Shop_Customer_Sales_Order_Audit; - --- Customer Sales Order Product Link -SELECT * FROM Shop_Customer_Sales_Order_Product_Link; -SELECT * FROM Shop_Customer_Sales_Order_Product_Link_Audit; - - - --- File: 9010_anal.sql - - -/* - -SELECT TABLE_NAME -FROM INFORMATION_SCHEMA.TABLES -WHERE TABLE_NAME LIKE '%SHOP%' - OR TABLE_NAME LIKE '%FILE_TYPE%'; - - -SELECT FOUND_ROWS(); - - - -SELECT - CONSTRAINT_NAME, - CONSTRAINT_TYPE, - TABLE_NAME, - COLUMN_NAME, - REFERENCED_TABLE_NAME, - REFERENCED_COLUMN_NAME -FROM - INFORMATION_SCHEMA.TABLES -WHERE - TABLE_SCHEMA = 'PARTS' - -- AND TABLE_NAME = 'your_table_name' +INSERT INTO partsltd_prod.PH_Role ( + display_order + , code + , name + , id_user_created_by +) +VALUES + ( + 1 + , 'DIRECTOR' + , 'Director' + , 1 + ) + , ( + 2 + , 'USER' + , 'User' + , 1 + ) ; -*/ +-- Role Permission link +INSERT INTO partsltd_prod.PH_Role_Permission_Link ( + id_role + , id_permission + , id_access_level + , id_user_created_by +) +VALUES + ( + 1 + , 1 + , 3 + , 1 + ) + , ( + 1 + , 2 + , 3 + , 1 + ) + , ( + 1 + , 3 + , 3 + , 1 + ) + , ( + 2 + , 1 + , 1 + , 1 + ) + , ( + 2 + , 2 + , 1 + , 1 + ) + , ( + 2 + , 3 + , 1 + , 1 + ) +; + +-- User Role link +INSERT INTO partsltd_prod.PH_User_Role_Link ( + id_user + , id_role + , id_user_created_by +) +VALUES + ( + 1 + , 1 + , 1 + ) + , ( + 2 + , 2 + , 1 + ) + , ( + 3 + , 2 + , 1 + ) +; +INSERT INTO partsltd_prod.PH_Contact_Form ( + email + , name_contact + , name_company + , message + , id_user_created_by +) +VALUES + ( + 'edward.middleton-smith@gmail.com' + , 'Teddy Middleton-Smith' + , 'PARTS Ltd' + , 'Hello, I would like to enquire about your services.' + , 1 + ) +; +-- Error Message type +SELECT * FROM partsltd_prod.CORE_Msg_Error_Type; + +-- User Change Sets +SELECT * FROM partsltd_prod.PH_User_Change_Set; + +-- Access Levels +SELECT * FROM partsltd_prod.PH_Access_Level; + +-- Permission Groups +SELECT * FROM partsltd_prod.PH_Permission_Group; + +-- Permissions +SELECT * FROM partsltd_prod.PH_Permission; + +-- Users +SELECT * FROM partsltd_prod.PH_User; +SELECT * FROM partsltd_prod.PH_User_Audit; + +-- Roles +SELECT * FROM partsltd_prod.PH_Role; +SELECT * FROM partsltd_prod.PH_Role_Audit; + +-- Role Permission link +SELECT * FROM partsltd_prod.PH_Role_Permission_Link; +SELECT * FROM partsltd_prod.PH_Role_Permission_Link_Audit; + +-- User Role link +SELECT * FROM partsltd_prod.PH_User_Role_Link; +SELECT * FROM partsltd_prod.PH_User_Role_Link_Audit; + +-- Contact Form Change Sets +SELECT * FROM partsltd_prod.PH_Contact_Form_Change_Set; + +-- Contact Forms +SELECT * FROM partsltd_prod.PH_Contact_Form; +SELECT * FROM partsltd_prod.PH_Contact_Form_Audit; +SELECT * FROM partsltd_prod.PH_Contact_Form_Temp; \ No newline at end of file diff --git a/static/MySQL/0001_destroy.sql b/static/MySQL/0001_destroy.sql index 1bd79699..b7f7ba62 100644 --- a/static/MySQL/0001_destroy.sql +++ b/static/MySQL/0001_destroy.sql @@ -1,337 +1,71 @@ -/* Clear Store DataBase */ +USE partsltd_prod; +-- Permanent Temp Tables +DROP TABLE IF EXISTS partsltd_prod.tmp_ph_Calc_User; +DROP TABLE IF EXISTS partsltd_prod.tmp_core_Msg_Error; +DROP TABLE IF EXISTS partsltd_prod.tmp_ph_User; +DROP TABLE IF EXISTS partsltd_prod.tmp_ph_User_Role_Link; --- Drop dependencies -DROP TABLE IF EXISTS tmp_Shop_Calc_User; -DROP TABLE IF EXISTS tmp_Product_Calc_User; -DROP TABLE IF EXISTS tmp_Product_p_Shop_User_Eval; -DROP TABLE IF EXISTS tmp_Msg_Error; -DROP TABLE IF EXISTS tmp_Currency; -DROP TABLE IF EXISTS tmp_Delivery_Option; -DROP TABLE IF EXISTS tmp_Delivery_Region; -DROP TABLE IF EXISTS tmp_Region; -DROP TABLE IF EXISTS tmp_Price; -DROP TABLE IF EXISTS tmp_Shop_User; -DROP TABLE IF EXISTS tmp_Shop_Order; -DROP TABLE IF EXISTS tmp_Shop_Product; -DROP TABLE IF EXISTS tmp_Product; -DROP TABLE IF EXISTS tmp_Product_Permutation; -DROP TABLE IF EXISTS tmp_Permutation_Variation_Link; -DROP TABLE IF EXISTS tmp_Permutation; -DROP TABLE IF EXISTS tmp_Shop_Product_p_shop_calc_user; -DROP TABLE IF EXISTS tmp_Shop_Product_p_Shop_Calc_User; -DROP TABLE IF EXISTS tmp_Shop_Image; -DROP TABLE IF EXISTS tmp_Image; -DROP TABLE IF EXISTS tmp_Product_Image; -DROP TABLE IF EXISTS tmp_Shop_Variation; -DROP TABLE IF EXISTS tmp_Variation; -DROP TABLE IF EXISTS tmp_Variation_Type; -DROP TABLE IF EXISTS tmp_Shop_Discount; -DROP TABLE IF EXISTS tmp_Discount; -DROP TABLE IF EXISTS tmp_Shop_Category; -DROP TABLE IF EXISTS tmp_Category; -DROP TABLE IF EXISTS tmp_Shop_Product_Category; -DROP TABLE IF EXISTS tmp_Product_Category; -DROP TABLE IF EXISTS tmp_Shop_Product_Currency_Region_Link; -DROP TABLE IF EXISTS tmp_Shop_Product_Currency_Link; -DROP TABLE IF EXISTS tmp_User_Role_Link; -DROP TABLE IF EXISTS tmp_Shop_Basket; -DROP TABLE IF EXISTS tmp_Shop_Supplier_Purchase_Order_Product_Link; -DROP TABLE IF EXISTS tmp_Supplier_Purchase_Order_Product_Link; -DROP TABLE IF EXISTS tmp_Shop_Supplier_Purchase_Order; -DROP TABLE IF EXISTS tmp_Supplier_Purchase_Order; -DROP TABLE IF EXISTS tmp_Shop_Supplier; -DROP TABLE IF EXISTS tmp_Supplier; -DROP TABLE IF EXISTS tmp_Supplier_Address; -DROP TABLE IF EXISTS tmp_Shop_Manufacturing_Purchase_Order_Product_Link; -DROP TABLE IF EXISTS tmp_Manufacturing_Purchase_Order_Product_Link; -DROP TABLE IF EXISTS tmp_Shop_Manufacturing_Purchase_Order; -DROP TABLE IF EXISTS tmp_Manufacturing_Purchase_Order; -DROP TABLE IF EXISTS tmp_Shop_Customer; -DROP TABLE IF EXISTS tmp_Shop_Customer_Sale_Order_Product_Link; -DROP TABLE IF EXISTS tmp_Shop_Customer_Sale_Order; -DROP TABLE IF EXISTS tmp_Get_Variation_From_Csv_Variations; +-- Permanent Tables +DROP TABLE IF EXISTS partsltd_prod.PH_Contact_Form_Temp; +DROP TABLE IF EXISTS partsltd_prod.PH_Contact_Form_Audit; +DROP TABLE IF EXISTS partsltd_prod.PH_Contact_Form; +DROP TABLE IF EXISTS partsltd_prod.PH_Contact_Form_Change_Set; --- Delete old tables -DROP TABLE IF EXISTS Split_Temp; -DROP TABLE IF EXISTS Split_Key_Value_Pair_Csv_Temp; -DROP TABLE IF EXISTS Split_Key_Value_Pair_Temp; +DROP TABLE IF EXISTS partsltd_prod.PH_Calc_User_Temp; -DROP TABLE IF EXISTS Shop_User_Eval_Temp; -DROP TABLE IF EXISTS Shop_Calc_User_Temp; +DROP TABLE IF EXISTS partsltd_prod.PH_User_Role_Link_Audit; +DROP TABLE IF EXISTS partsltd_prod.PH_User_Role_Link; -DROP TABLE IF EXISTS Shop_Customer_Sales_Order_Product_Link_Temp; -DROP TABLE IF EXISTS Shop_Customer_Sales_Order_Product_Link_Audit; -DROP TABLE IF EXISTS Shop_Customer_Sales_Order_Product_Link; +DROP TABLE IF EXISTS partsltd_prod.PH_Role_Permission_Link_Audit; +DROP TABLE IF EXISTS partsltd_prod.PH_Role_Permission_Link; -DROP TABLE IF EXISTS Shop_Manufacturing_Purchase_Order_Product_Link_Temp; -DROP TABLE IF EXISTS Shop_Manufacturing_Purchase_Order_Product_Link_Audit; -DROP TABLE IF EXISTS Shop_Manufacturing_Purchase_Order_Product_Link; +DROP TABLE IF EXISTS partsltd_prod.PH_Role_Audit; +DROP TABLE IF EXISTS partsltd_prod.PH_Role; -DROP TABLE IF EXISTS Shop_Supplier_Purchase_Order_Product_Link_Temp; -DROP TABLE IF EXISTS Shop_Supplier_Purchase_Order_Product_Link_Audit; -DROP TABLE IF EXISTS Shop_Supplier_Purchase_Order_Product_Link; +DROP TABLE IF EXISTS partsltd_prod.PH_User_Temp; +DROP TABLE IF EXISTS partsltd_prod.PH_User_Audit; +DROP TABLE IF EXISTS partsltd_prod.PH_User; -DROP TABLE IF EXISTS Shop_Stock_Item_Temp; -DROP TABLE IF EXISTS Shop_Stock_Item_Audit; -DROP TABLE IF EXISTS Shop_Stock_Item; +DROP TABLE IF EXISTS partsltd_prod.PH_Permission_Audit; +DROP TABLE IF EXISTS partsltd_prod.PH_Permission; -DROP TABLE IF EXISTS Shop_Customer_Sales_Order_Audit; -DROP TABLE IF EXISTS Shop_Customer_Sales_Order; +DROP TABLE IF EXISTS partsltd_prod.PH_Permission_Group_Audit; +DROP TABLE IF EXISTS partsltd_prod.PH_Permission_Group; -DROP TABLE IF EXISTS Shop_Customer_Temp; -DROP TABLE IF EXISTS Shop_Customer_Audit; -DROP TABLE IF EXISTS Shop_Customer; +DROP TABLE IF EXISTS partsltd_prod.PH_Access_Level_Audit; +DROP TABLE IF EXISTS partsltd_prod.PH_Access_Level; -DROP TABLE IF EXISTS Shop_Manufacturing_Purchase_Order_Temp; -DROP TABLE IF EXISTS Shop_Manufacturing_Purchase_Order_Audit; -DROP TABLE IF EXISTS Shop_Manufacturing_Purchase_Order; +DROP TABLE IF EXISTS partsltd_prod.PH_User_Change_Set; -DROP TABLE IF EXISTS Shop_Supplier_Purchase_Order_Temp; -DROP TABLE IF EXISTS Shop_Supplier_Purchase_Order_Audit; -DROP TABLE IF EXISTS Shop_Supplier_Purchase_Order; +DROP TABLE IF EXISTS partsltd_prod.CORE_Split_Key_Value_Pair_Csv_Temp; +DROP TABLE IF EXISTS partsltd_prod.CORE_Split_Temp; -DROP TABLE IF EXISTS Shop_Supplier_Address_Temp; -DROP TABLE IF EXISTS Shop_Supplier_Address_Audit; -DROP TABLE IF EXISTS Shop_Supplier_Address; +DROP TABLE IF EXISTS partsltd_prod.CORE_Msg_Error_Type; -DROP TABLE IF EXISTS Shop_Supplier_Temp; -DROP TABLE IF EXISTS Shop_Supplier_Audit; -DROP TABLE IF EXISTS Shop_Supplier; +-- Stored Procedures +DROP PROCEDURE IF EXISTS partsltd_prod.p_ph_test_get_many_contact_form; +DROP PROCEDURE IF EXISTS partsltd_prod.p_ph_get_many_contact_form; +DROP PROCEDURE IF EXISTS partsltd_prod.p_ph_test_save_contact_form; +DROP PROCEDURE IF EXISTS partsltd_prod.p_ph_save_contact_form; -DROP TABLE IF EXISTS Shop_User_Order_Product_Link_Audit; -DROP TABLE IF EXISTS Shop_User_Order_Product_Link; +DROP PROCEDURE IF EXISTS partsltd_prod.p_ph_clear_calc_user; +DROP PROCEDURE IF EXISTS partsltd_prod.p_ph_calc_user; -DROP TABLE IF EXISTS Shop_User_Order_Audit; -DROP TABLE IF EXISTS Shop_User_Order; +DROP PROCEDURE IF EXISTS partsltd_prod.p_core_clear_split_key_value_pair_csv; +DROP PROCEDURE IF EXISTS partsltd_prod.p_core_split_key_value_pair_csv; +DROP PROCEDURE IF EXISTS partsltd_prod.p_core_clear_split; +DROP PROCEDURE IF EXISTS partsltd_prod.p_core_split; +DROP PROCEDURE IF EXISTS partsltd_prod.p_clear_split_key_value_pair_csv; +DROP PROCEDURE IF EXISTS partsltd_prod.p_split_key_value_pair_csv; +DROP PROCEDURE IF EXISTS partsltd_prod.p_clear_split; +DROP PROCEDURE IF EXISTS partsltd_prod.p_split; -DROP TABLE IF EXISTS Shop_User_Order_Status_Audit; -DROP TABLE IF EXISTS Shop_User_Order_Status; - -DROP TABLE IF EXISTS Shop_User_Basket_Audit; -DROP TABLE IF EXISTS Shop_User_Basket; - -DROP TABLE IF EXISTS Shop_User_Address_Audit; -DROP TABLE IF EXISTS Shop_User_Address; - -DROP TABLE IF EXISTS Shop_User_Role_Link_Audit; -DROP TABLE IF EXISTS Shop_User_Role_Link; - -DROP TABLE IF EXISTS Shop_User_Temp; -DROP TABLE IF EXISTS Shop_User_Audit; -DROP TABLE IF EXISTS Shop_User; - -DROP TABLE IF EXISTS Shop_Role_Permission_Link_Audit; -DROP TABLE IF EXISTS Shop_Role_Permission_Link; - -DROP TABLE IF EXISTS Shop_Role_Audit; -DROP TABLE IF EXISTS Shop_Role; - -DROP TABLE IF EXISTS Shop_Permission_Audit; -DROP TABLE IF EXISTS Shop_Permission; - -DROP TABLE IF EXISTS Shop_Permission_Group_Audit; -DROP TABLE IF EXISTS Shop_Permission_Group; - - -DROP TABLE IF EXISTS Shop_Discount_Region_Currency_Link_Audit; -DROP TABLE IF EXISTS Shop_Discount_Region_Currency_Link; - -DROP TABLE IF EXISTS Shop_Discount_Audit; -DROP TABLE IF EXISTS Shop_Discount; - -DROP TABLE IF EXISTS Shop_Product_Permutation_Delivery_Option_Link_Audit; -DROP TABLE IF EXISTS Shop_Product_Permutation_Delivery_Option_Link; -DROP TABLE IF EXISTS Shop_Product_Delivery_Option_Link_Audit; -DROP TABLE IF EXISTS Shop_Product_Delivery_Option_Link; - -DROP TABLE IF EXISTS Shop_Delivery_Option_Audit; -DROP TABLE IF EXISTS Shop_Delivery_Option; - -DROP TABLE IF EXISTS Shop_Product_Image_Audit; -DROP TABLE IF EXISTS Shop_Product_Image; -DROP TABLE IF EXISTS Shop_Image_Audit; -DROP TABLE IF EXISTS Shop_Image; - -DROP TABLE IF EXISTS Shop_Product_Price_Temp; -DROP TABLE IF EXISTS Shop_Product_Price_Audit; -DROP TABLE IF EXISTS Shop_Product_Price; - -DROP TABLE IF EXISTS Shop_Product_Currency_Region_Link_Audit; -DROP TABLE IF EXISTS Shop_Product_Currency_Region_Link; -DROP TABLE IF EXISTS Shop_Product_Currency_Link_Audit; -DROP TABLE IF EXISTS Shop_Product_Currency_Link; - -DROP TABLE IF EXISTS Shop_Product_Variation_Link_Audit; -DROP TABLE IF EXISTS Shop_Product_Variation_Link; -DROP TABLE IF EXISTS Shop_Product_Permutation_Variation_Link_Temp; -DROP TABLE IF EXISTS Shop_Product_Permutation_Variation_Link_Audit; -DROP TABLE IF EXISTS Shop_Product_Permutation_Variation_Link; - -DROP TABLE IF EXISTS Shop_Variation_Temp; -DROP TABLE IF EXISTS Shop_Variation_Audit; -DROP TABLE IF EXISTS Shop_Variation; -DROP TABLE IF EXISTS Shop_Product_Variation_Type_Link_Audit; -DROP TABLE IF EXISTS Shop_Product_Variation_Type_Link; -DROP TABLE IF EXISTS Shop_Product_Variation_Temp; -DROP TABLE IF EXISTS Shop_Product_Variation; - -DROP TABLE IF EXISTS Shop_Variation_Type_Temp; -DROP TABLE IF EXISTS Shop_Variation_Type_Audit; -DROP TABLE IF EXISTS Shop_Variation_Type; -DROP TABLE IF EXISTS Shop_Product_Variation_Type_Temp; -DROP TABLE IF EXISTS Shop_Product_Variation_Type; - -DROP TABLE IF EXISTS Shop_Product_Permutation_Temp; -DROP TABLE IF EXISTS Shop_Product_Permutation_Audit; -DROP TABLE IF EXISTS Shop_Product_Permutation; - -DROP TABLE IF EXISTS Shop_Interval_Recurrence_Audit; -DROP TABLE IF EXISTS Shop_Interval_Recurrence; - -DROP TABLE IF EXISTS Shop_Product_Audit; -DROP TABLE IF EXISTS Shop_Product; -DROP TABLE IF EXISTS Shop_Product_Temp; - -DROP TABLE IF EXISTS Shop_Product_Category_Temp; -DROP TABLE IF EXISTS Shop_Product_Category_Audit; -DROP TABLE IF EXISTS Shop_Product_Category; -DROP TABLE IF EXISTS Shop_Category_Audit; -DROP TABLE IF EXISTS Shop_Category; - -DROP TABLE IF EXISTS Shop_Tax_Or_Surcharge_Temp; -DROP TABLE IF EXISTS Shop_Tax_Or_Surcharge_Audit; -DROP TABLE IF EXISTS Shop_Tax_Or_Surcharge; - -DROP TABLE IF EXISTS Shop_Currency_Temp; -DROP TABLE IF EXISTS Shop_Currency_Audit; -DROP TABLE IF EXISTS Shop_Currency; - -DROP TABLE IF EXISTS Shop_Storage_Location_Branch_Temp; -DROP TABLE IF EXISTS Shop_Storage_Location_Branch_Audit; -DROP TABLE IF EXISTS Shop_Storage_Location_Branch; - -DROP TABLE IF EXISTS Shop_Storage_Location_Temp; -DROP TABLE IF EXISTS Shop_Storage_Location_Audit; -DROP TABLE IF EXISTS Shop_Storage_Location; - -DROP TABLE IF EXISTS Shop_Plant_Temp; -DROP TABLE IF EXISTS Shop_Plant_Audit; -DROP TABLE IF EXISTS Shop_Plant; - -DROP TABLE IF EXISTS Shop_Address_Audit; -DROP TABLE IF EXISTS Shop_Address; - -DROP TABLE IF EXISTS Shop_Delivery_Region_Branch_Audit; -DROP TABLE IF EXISTS Shop_Delivery_Region_Branch; -DROP TABLE IF EXISTS Shop_Region_Branch_Temp; -DROP TABLE IF EXISTS Shop_Region_Branch_Audit; -DROP TABLE IF EXISTS Shop_Region_Branch; - -DROP TABLE IF EXISTS Shop_Delivery_Region_Audit; -DROP TABLE IF EXISTS Shop_Delivery_Region; -DROP TABLE IF EXISTS Shop_Region_Temp; -DROP TABLE IF EXISTS Shop_Region_Audit; -DROP TABLE IF EXISTS Shop_Region; - - -DROP TABLE IF EXISTS Shop_Unit_Measurement_Conversion_Audit; -DROP TABLE IF EXISTS Shop_Unit_Measurement_Conversion; - -DROP TABLE IF EXISTS Shop_Unit_Measurement_Audit; -DROP TABLE IF EXISTS Shop_Unit_Measurement; - -DROP TABLE IF EXISTS Shop_Image_Type_Audit; -DROP TABLE IF EXISTS Shop_Image_Type; - -DROP TABLE IF EXISTS Shop_General_Audit; -DROP TABLE IF EXISTS Shop_General; - -DROP TABLE IF EXISTS File_Type_Audit; -DROP TABLE IF EXISTS File_Type; - -DROP TABLE IF EXISTS Msg_Error_Type; -DROP TABLE IF EXISTS Shop_Msg_Error_Type; - -DROP TABLE IF EXISTS Shop_Access_Level_Audit; -DROP TABLE IF EXISTS Shop_Access_Level; - -DROP TABLE IF EXISTS Shop_Sales_And_Purchasing_Change_Set; -DROP TABLE IF EXISTS Shop_User_Change_Set; -DROP TABLE IF EXISTS Shop_Product_Change_Set; - - --- Procedures -DROP PROCEDURE IF EXISTS p_split; -DROP PROCEDURE IF EXISTS p_clear_split_temp; -DROP PROCEDURE IF EXISTS p_split_key_value_pair_csv; -DROP PROCEDURE IF EXISTS p_clear_split_key_value_csv_temp; -DROP PROCEDURE IF EXISTS p_clear_split_key_value_pair_csv_temp; - -DROP PROCEDURE IF EXISTS p_debug_timing_reporting; -DROP PROCEDURE IF EXISTS p_validate_guid; -DROP PROCEDURE IF EXISTS p_validate_guid_test; - -DROP FUNCTION IF EXISTS fn_shop_get_product_permutation_name; - -DROP PROCEDURE IF EXISTS p_shop_calc_user; -DROP PROCEDURE IF EXISTS p_shop_calc_user; -DROP PROCEDURE IF EXISTS p_shop_clear_user_eval_temp; -DROP PROCEDURE IF EXISTS p_shop_clear_calc_user; - -DROP PROCEDURE IF EXISTS p_shop_get_many_access_level; -DROP PROCEDURE IF EXISTS p_shop_get_many_unit_measurement; - -DROP PROCEDURE IF EXISTS p_shop_get_many_region; -DROP PROCEDURE IF EXISTS p_shop_get_many_plant; -DROP PROCEDURE IF EXISTS p_shop_get_many_storage_location; -DROP PROCEDURE IF EXISTS p_shop_get_many_currency; - -DROP PROCEDURE IF EXISTS p_shop_save_category; -DROP PROCEDURE IF EXISTS p_shop_save_category_test; -DROP PROCEDURE IF EXISTS p_shop_save_product_category; -DROP PROCEDURE IF EXISTS p_shop_save_product_category_test; -DROP PROCEDURE IF EXISTS p_shop_save_product; -DROP PROCEDURE IF EXISTS p_shop_save_product_test; -DROP PROCEDURE IF EXISTS p_shop_calc_product_permutation; -DROP PROCEDURE IF EXISTS p_shop_clear_calc_product_permutation; -DROP PROCEDURE IF EXISTS p_shop_get_many_product; -DROP PROCEDURE IF EXISTS p_shop_get_many_stripe_product_new; -DROP PROCEDURE IF EXISTS p_shop_save_permutation; -DROP PROCEDURE IF EXISTS p_shop_save_product_permutation; -DROP PROCEDURE IF EXISTS p_shop_save_product_permutation_test; -DROP PROCEDURE IF EXISTS p_shop_save_product_variation; -DROP PROCEDURE IF EXISTS p_shop_save_product_variation_test; -DROP PROCEDURE IF EXISTS p_shop_get_many_product_variation; -DROP FUNCTION IF EXISTS fn_shop_get_id_product_permutation_from_variation_csv_list; -DROP FUNCTION IF EXISTS fn_shop_get_product_variations_from_id_csv_list; -DROP FUNCTION IF EXISTS fn_shop_get_product_permutation_variations_csv; -DROP PROCEDURE IF EXISTS p_shop_save_stock_item; -DROP PROCEDURE IF EXISTS p_shop_save_stock_item_test; -DROP PROCEDURE IF EXISTS p_shop_get_many_stock_item; -DROP PROCEDURE IF EXISTS p_shop_get_many_product_price_and_discount_and_delivery_option; -DROP PROCEDURE IF EXISTS p_shop_get_many_product_price_and_discount_and_delivery_option; -DROP PROCEDURE IF EXISTS p_shop_get_many_stripe_price_new; -DROP PROCEDURE IF EXISTS p_shop_save_user; -DROP PROCEDURE IF EXISTS p_shop_edit_user; -DROP PROCEDURE IF EXISTS p_shop_get_many_user; -DROP PROCEDURE IF EXISTS p_get_many_user; -DROP PROCEDURE IF EXISTS p_shop_get_many_user_basket; -DROP PROCEDURE IF EXISTS p_shop_edit_user_basket; -DROP PROCEDURE IF EXISTS p_shop_save_supplier; -DROP PROCEDURE IF EXISTS p_shop_save_supplier_test; -DROP PROCEDURE IF EXISTS p_shop_get_many_supplier; -DROP PROCEDURE IF EXISTS p_shop_save_supplier_purchase_order; -DROP PROCEDURE IF EXISTS p_shop_save_supplier_purchase_order_test; -DROP PROCEDURE IF EXISTS p_shop_get_many_supplier_purchase_order; -DROP PROCEDURE IF EXISTS p_shop_save_manufacturing_purchase_order; -DROP PROCEDURE IF EXISTS p_shop_save_manufacturing_purchase_order_test; -DROP PROCEDURE IF EXISTS p_shop_get_many_manufacturing_purchase_order; -DROP PROCEDURE IF EXISTS p_shop_save_customer; -DROP PROCEDURE IF EXISTS p_shop_get_many_customer; -DROP PROCEDURE IF EXISTS p_shop_save_customer_sales_order; -DROP PROCEDURE IF EXISTS p_shop_get_many_customer_sales_order; +DROP PROCEDURE IF EXISTS partsltd_prod.p_core_debug_timing_reporting; +DROP PROCEDURE IF EXISTS partsltd_prod.p_debug_timing_reporting; +DROP PROCEDURE IF EXISTS partsltd_prod.p_core_validate_guid; +DROP PROCEDURE IF EXISTS partsltd_prod.p_core_validate_guid_test; diff --git a/static/MySQL/1000_tbl_CORE_Msg_Error_Type.sql b/static/MySQL/1000_tbl_CORE_Msg_Error_Type.sql new file mode 100644 index 00000000..35bd5ebd --- /dev/null +++ b/static/MySQL/1000_tbl_CORE_Msg_Error_Type.sql @@ -0,0 +1,16 @@ + +USE partsltd_prod; + +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'CORE_Msg_Error_Type' +; + +CREATE TABLE IF NOT EXISTS partsltd_prod.CORE_Msg_Error_Type ( + id_type INT NOT NULL AUTO_INCREMENT PRIMARY KEY + , code VARCHAR(50) NOT NULL + , name VARCHAR(500) NOT NULL + , description VARCHAR(1000) +); diff --git a/static/MySQL/1000_tbl_Shop_Product_Change_Set.sql b/static/MySQL/1000_tbl_Shop_Product_Change_Set.sql deleted file mode 100644 index a00a728e..00000000 --- a/static/MySQL/1000_tbl_Shop_Product_Change_Set.sql +++ /dev/null @@ -1,13 +0,0 @@ - --- Product Change Sets - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Change_Set'; - -CREATE TABLE Shop_Product_Change_Set ( - id_change_set INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - comment VARCHAR(500), - updated_last_on DATETIME, - updated_last_by VARCHAR(100) -); \ No newline at end of file diff --git a/static/MySQL/1000_tbl_Split_Temp.sql b/static/MySQL/1000_tbl_Split_Temp.sql deleted file mode 100644 index 27eae56b..00000000 --- a/static/MySQL/1000_tbl_Split_Temp.sql +++ /dev/null @@ -1,12 +0,0 @@ - --- Split Staging --- USE partsltd_prod; --- DROP TABLE IF EXISTS Split_Temp; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Split_Temp'; - -CREATE TABLE Split_Temp ( - guid BINARY(36) NOT NULL - , display_order INT NOT NULL - , substring VARCHAR(4000) NOT NULL -); diff --git a/static/MySQL/1001_tbl_Shop_User_Change_Set.sql b/static/MySQL/1001_tbl_Shop_User_Change_Set.sql deleted file mode 100644 index b9916cb6..00000000 --- a/static/MySQL/1001_tbl_Shop_User_Change_Set.sql +++ /dev/null @@ -1,13 +0,0 @@ - --- User Change Sets - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Change_Set'; - -CREATE TABLE IF NOT EXISTS Shop_User_Change_Set ( - id_change_set INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - comment VARCHAR(500), - updated_last_on DATETIME, - updated_last_by VARCHAR(100) -); \ No newline at end of file diff --git a/static/MySQL/1001_tbl_Split_Key_Value_Pair_Csv_Temp.sql b/static/MySQL/1001_tbl_Split_Key_Value_Pair_Csv_Temp.sql deleted file mode 100644 index 608a0d68..00000000 --- a/static/MySQL/1001_tbl_Split_Key_Value_Pair_Csv_Temp.sql +++ /dev/null @@ -1,13 +0,0 @@ - --- Split Key Value Pair CSV Staging --- USE partsltd_prod; --- DROP TABLE IF EXISTS Split_Temp; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Split_Key_Value_Pair_Csv_Temp'; - -CREATE TABLE Split_Key_Value_Pair_Csv_Temp ( - guid BINARY(36) NOT NULL - , id INT NOT NULL - , key_column VARCHAR(4000) NULL - , value_column VARCHAR(4000) NULL -); diff --git a/static/MySQL/1002_tbl_Shop_Sales_And_Purchasing_Change_Set.sql b/static/MySQL/1002_tbl_Shop_Sales_And_Purchasing_Change_Set.sql deleted file mode 100644 index 04a664ee..00000000 --- a/static/MySQL/1002_tbl_Shop_Sales_And_Purchasing_Change_Set.sql +++ /dev/null @@ -1,13 +0,0 @@ - --- Sales And Purchasing Change Sets - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Sales_And_Purchasing_Change_Set'; - -CREATE TABLE Shop_Sales_And_Purchasing_Change_Set ( - id_change_set INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - comment VARCHAR(500), - updated_last_on DATETIME, - updated_last_by VARCHAR(100) -); \ No newline at end of file diff --git a/static/MySQL/1003_tbl_Shop_Access_Level.sql b/static/MySQL/1003_tbl_Shop_Access_Level.sql deleted file mode 100644 index 133f791a..00000000 --- a/static/MySQL/1003_tbl_Shop_Access_Level.sql +++ /dev/null @@ -1,23 +0,0 @@ - --- Access Levels - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Access_Level'; - -CREATE TABLE IF NOT EXISTS Shop_Access_Level ( - id_access_level INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - code VARCHAR(50), - name VARCHAR(255), - priority INT NOT NULL, - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Access_Level_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); - - diff --git a/static/MySQL/1004_tbl_Shop_Access_Level_Audit.sql b/static/MySQL/1004_tbl_Shop_Access_Level_Audit.sql deleted file mode 100644 index ca1b8cf1..00000000 --- a/static/MySQL/1004_tbl_Shop_Access_Level_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Access Level Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Access_Level_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Access_Level_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_access_level INT NOT NULL, - CONSTRAINT FK_Shop_Access_Level_Audit_id_access_level - FOREIGN KEY (id_access_level) - REFERENCES Shop_Access_Level(id_access_level) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Access_Level_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/MySQL/1005_tbl_Msg_Error_Type.sql b/static/MySQL/1005_tbl_Msg_Error_Type.sql deleted file mode 100644 index ca61049e..00000000 --- a/static/MySQL/1005_tbl_Msg_Error_Type.sql +++ /dev/null @@ -1,13 +0,0 @@ - --- Error Message Type - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Msg_Error_Type'; - -CREATE TABLE IF NOT EXISTS Shop_Msg_Error_Type ( - id_type INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - code VARCHAR(50) NOT NULL, - name VARCHAR(500) NOT NULL, - description VARCHAR(1000) -); diff --git a/static/MySQL/1010_tbl_File_Type.sql b/static/MySQL/1010_tbl_File_Type.sql deleted file mode 100644 index 64338624..00000000 --- a/static/MySQL/1010_tbl_File_Type.sql +++ /dev/null @@ -1,17 +0,0 @@ - --- File Types - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'File_Type'; - -CREATE TABLE IF NOT EXISTS File_Type ( - id_type INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - code VARCHAR(50), - name VARCHAR(100), - extension VARCHAR(50), - created_on DATETIME, - created_by INT, - updated_last_on DATETIME, - updated_last_by VARCHAR(100) -); diff --git a/static/MySQL/1011_tbl_File_Type_Audit.sql b/static/MySQL/1011_tbl_File_Type_Audit.sql deleted file mode 100644 index 86aebf6a..00000000 --- a/static/MySQL/1011_tbl_File_Type_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- File Type Audit - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'File_Type_Audit'; - -CREATE TABLE IF NOT EXISTS File_Type_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_type INT NOT NULL, - CONSTRAINT FK_File_Type_Audit_id_type - FOREIGN KEY (id_type) - REFERENCES File_Type(id_type) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - created_on DATETIME, - created_by INT, - updated_last_on DATETIME, - updated_last_by VARCHAR(100) -); \ No newline at end of file diff --git a/static/MySQL/1012_tbl_Shop_General.sql b/static/MySQL/1012_tbl_Shop_General.sql deleted file mode 100644 index 3d28ddbf..00000000 --- a/static/MySQL/1012_tbl_Shop_General.sql +++ /dev/null @@ -1,17 +0,0 @@ - --- Generic / shared properties - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_General'; - -CREATE TABLE IF NOT EXISTS Shop_General ( - id_general INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - quantity_max FLOAT, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT CHK_Shop_General_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/MySQL/1013_tbl_Shop_General_Audit.sql b/static/MySQL/1013_tbl_Shop_General_Audit.sql deleted file mode 100644 index 3f44caf1..00000000 --- a/static/MySQL/1013_tbl_Shop_General_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Shop General Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_General_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_General_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_general INT NOT NULL, - CONSTRAINT FK_Shop_General_Audit_id_general - FOREIGN KEY (id_general) - REFERENCES Shop_General(id_general) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_General_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/MySQL/1014_tbl_Shop_Image_Type.sql b/static/MySQL/1014_tbl_Shop_Image_Type.sql deleted file mode 100644 index fcc6b114..00000000 --- a/static/MySQL/1014_tbl_Shop_Image_Type.sql +++ /dev/null @@ -1,27 +0,0 @@ - --- Image Types - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Image_Type'; - -CREATE TABLE IF NOT EXISTS Shop_Image_Type ( - id_type INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - /* - id_type_file INT NOT NULL, - CONSTRAINT FK_Shop_Image_Type_id_type_file - FOREIGN KEY (id_type_file) - REFERENCES File_Type(id_type), - */ - code VARCHAR(50), - name VARCHAR(255), - name_plural VARCHAR(256), - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Image_Type_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/MySQL/1015_tbl_Shop_Image_Type_Audit.sql b/static/MySQL/1015_tbl_Shop_Image_Type_Audit.sql deleted file mode 100644 index f417ff84..00000000 --- a/static/MySQL/1015_tbl_Shop_Image_Type_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Image Type Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Image_Type_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Image_Type_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_type INT NOT NULL, - CONSTRAINT FK_Shop_Image_Type_Audit_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Image_Type(id_type) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Image_Type_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/MySQL/1090_tbl_CORE_Split_Temp.sql b/static/MySQL/1090_tbl_CORE_Split_Temp.sql new file mode 100644 index 00000000..7b7a2572 --- /dev/null +++ b/static/MySQL/1090_tbl_CORE_Split_Temp.sql @@ -0,0 +1,15 @@ + +USE partsltd_prod; + +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'CORE_Split_Temp' +; + +CREATE TABLE IF NOT EXISTS partsltd_prod.CORE_Split_Temp ( + guid BINARY(36) NOT NULL + , display_order INT NOT NULL + , substring VARCHAR(4000) NOT NULL +); diff --git a/static/MySQL/1091_tbl_CORE_Split_Key_Value_Pair_Csv_Temp.sql b/static/MySQL/1091_tbl_CORE_Split_Key_Value_Pair_Csv_Temp.sql new file mode 100644 index 00000000..5ffce08b --- /dev/null +++ b/static/MySQL/1091_tbl_CORE_Split_Key_Value_Pair_Csv_Temp.sql @@ -0,0 +1,16 @@ + +USE partsltd_prod; + +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'CORE_Split_Key_Value_Pair_Csv_Temp' +; + +CREATE TABLE IF NOT EXISTS partsltd_prod.CORE_Split_Key_Value_Pair_Csv_Temp ( + guid BINARY(36) NOT NULL + , id INT NOT NULL + , key_column VARCHAR(4000) NULL + , value_column VARCHAR(4000) NULL +); diff --git a/static/MySQL/1100_tbl_PH_User_Change_Set.sql b/static/MySQL/1100_tbl_PH_User_Change_Set.sql new file mode 100644 index 00000000..3600b1b4 --- /dev/null +++ b/static/MySQL/1100_tbl_PH_User_Change_Set.sql @@ -0,0 +1,16 @@ + +USE partsltd_prod; + +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'PH_User_Change_Set' +; + +CREATE TABLE IF NOT EXISTS partsltd_prod.PH_User_Change_Set ( + id_change_set INT NOT NULL AUTO_INCREMENT PRIMARY KEY + , comment VARCHAR(500) + , updated_last_on DATETIME + , id_user_updated_last_by INT +); \ No newline at end of file diff --git a/static/MySQL/1100_tbl_Shop_Region.sql b/static/MySQL/1100_tbl_Shop_Region.sql deleted file mode 100644 index 91645659..00000000 --- a/static/MySQL/1100_tbl_Shop_Region.sql +++ /dev/null @@ -1,18 +0,0 @@ - --- Regions - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Region'; - -CREATE TABLE IF NOT EXISTS Shop_Region ( - id_region INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - code VARCHAR(50) NOT NULL, - name VARCHAR(200) NOT NULL, - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Region_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/MySQL/1101_tbl_Shop_Region_Audit.sql b/static/MySQL/1101_tbl_Shop_Region_Audit.sql deleted file mode 100644 index 7df551ae..00000000 --- a/static/MySQL/1101_tbl_Shop_Region_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Region Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Region_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Region_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_region INT NOT NULL, - CONSTRAINT FK_Shop_Region_Audit_id_region - FOREIGN KEY (id_region) - REFERENCES Shop_Region(id_region) - ON UPDATE RESTRICT, - name_field VARCHAR(64) NOT NULL, - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Region_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/MySQL/1102_tbl_Shop_Region_Temp.sql b/static/MySQL/1102_tbl_Shop_Region_Temp.sql deleted file mode 100644 index bf5ef33d..00000000 --- a/static/MySQL/1102_tbl_Shop_Region_Temp.sql +++ /dev/null @@ -1,20 +0,0 @@ - --- Region Temp - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Region_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Region_Temp ( - id_region INT NOT NULL PRIMARY KEY, - code VARCHAR(50) NOT NULL, - name VARCHAR(200) NOT NULL, - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Region_Temp_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/MySQL/1103_tbl_Shop_Region_Branch.sql b/static/MySQL/1103_tbl_Shop_Region_Branch.sql deleted file mode 100644 index dce52238..00000000 --- a/static/MySQL/1103_tbl_Shop_Region_Branch.sql +++ /dev/null @@ -1,29 +0,0 @@ - --- Region Branchs - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Region_Branch'; - -CREATE TABLE IF NOT EXISTS Shop_Region_Branch ( - id_branch INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_region_parent INT NOT NULL, - CONSTRAINT FK_Shop_Region_Branch_id_region_parent - FOREIGN KEY (id_region_parent) - REFERENCES Shop_Region(id_region) - ON UPDATE RESTRICT, - id_region_child INT NOT NULL, - CONSTRAINT FK_Shop_Region_Branch_id_region_child - FOREIGN KEY (id_region_child) - REFERENCES Shop_Region(id_region) - ON UPDATE RESTRICT, - -- depth INT NOT NULL, - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Region_Branch_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/MySQL/1104_tbl_PH_Access_Level.sql b/static/MySQL/1104_tbl_PH_Access_Level.sql new file mode 100644 index 00000000..f556861a --- /dev/null +++ b/static/MySQL/1104_tbl_PH_Access_Level.sql @@ -0,0 +1,20 @@ + +USE partsltd_prod; + +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'PH_Access_Level' +; + +CREATE TABLE IF NOT EXISTS partsltd_prod.PH_Access_Level ( + id_access_level INT NOT NULL AUTO_INCREMENT PRIMARY KEY + , code VARCHAR(50) + , name VARCHAR(255) + , priority INT NOT NULL + , display_order INT NOT NULL + , active BIT NOT NULL DEFAULT 1 +); + + diff --git a/static/MySQL/1104_tbl_Shop_Region_Branch_Audit.sql b/static/MySQL/1104_tbl_Shop_Region_Branch_Audit.sql deleted file mode 100644 index f6efb58d..00000000 --- a/static/MySQL/1104_tbl_Shop_Region_Branch_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Region Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Region_Branch_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Region_Branch_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_branch INT NOT NULL, - CONSTRAINT FK_Shop_Region_Branch_Audit_id_branch - FOREIGN KEY (id_branch) - REFERENCES Shop_Region_Branch(id_branch) - ON UPDATE RESTRICT, - name_field VARCHAR(64) NOT NULL, - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Region_Branch_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/MySQL/1105_tbl_Shop_Region_Branch_Temp.sql b/static/MySQL/1105_tbl_Shop_Region_Branch_Temp.sql deleted file mode 100644 index 5de0ac35..00000000 --- a/static/MySQL/1105_tbl_Shop_Region_Branch_Temp.sql +++ /dev/null @@ -1,15 +0,0 @@ - --- Region Branch Temp - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Region_Branch_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Region_Branch_Temp ( - id_branch INT NOT NULL PRIMARY KEY, - id_region_parent INT NOT NULL, - id_region_child INT NOT NULL, - -- depth INT NOT NULL, - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL -); \ No newline at end of file diff --git a/static/MySQL/1106_tbl_Shop_Address.sql b/static/MySQL/1106_tbl_Shop_Address.sql deleted file mode 100644 index be052bdc..00000000 --- a/static/MySQL/1106_tbl_Shop_Address.sql +++ /dev/null @@ -1,31 +0,0 @@ - --- Addresses - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Address'; - -CREATE TABLE Shop_Address ( - id_address INT NOT NULL AUTO_INCREMENT PRIMARY KEY - , id_region INT NOT NULL - , CONSTRAINT FK_Shop_Address_id_region - FOREIGN KEY (id_region) - REFERENCES partsltd_prod.Shop_Region(id_region) - /* - , id_supplier INT NULL - , CONSTRAINT FK_Shop_Address_id_supplier - FOREIGN KEY (id_supplier) - REFERENCES partsltd_prod.Shop_Supplier(id_supplier) - */ - , postcode VARCHAR(20) NOT NULL - , address_line_1 VARCHAR(256) NOT NULL - , address_line_2 VARCHAR(256) NOT NULL - , city VARCHAR(256) NOT NULL - , county VARCHAR(256) NOT NULL - , active BIT NOT NULL DEFAULT 1 - , created_on DATETIME - , created_by INT - , id_change_set INT - , CONSTRAINT FK_Shop_Address_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES partsltd_prod.Shop_User_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/MySQL/1106_tbl_Shop_Plant.sql b/static/MySQL/1106_tbl_Shop_Plant.sql deleted file mode 100644 index 5b981a83..00000000 --- a/static/MySQL/1106_tbl_Shop_Plant.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Plant - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Plant'; - -CREATE TABLE IF NOT EXISTS Shop_Plant ( - id_plant INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - code VARCHAR(50) NOT NULL, - name VARCHAR(500) NOT NULL, - id_address INT NOT NULL, - CONSTRAINT FK_Shop_Plant_id_address - FOREIGN KEY (id_address) - REFERENCES Shop_Address(id_address), - id_user_manager INT NOT NULL, - active BIT NOT NULL DEFAULT 1, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Plant_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/MySQL/1107_tbl_Shop_Address_Audit.sql b/static/MySQL/1107_tbl_Shop_Address_Audit.sql deleted file mode 100644 index 28479c4e..00000000 --- a/static/MySQL/1107_tbl_Shop_Address_Audit.sql +++ /dev/null @@ -1,21 +0,0 @@ - --- Address Audits - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Address_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Address_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_address INT NOT NULL, - CONSTRAINT FK_Shop_Address_Audit_id_address - FOREIGN KEY (id_address) - REFERENCES Shop_Address(id_address) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Address_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - ON UPDATE RESTRICT -); \ No newline at end of file diff --git a/static/MySQL/1107_tbl_Shop_Plant_Audit.sql b/static/MySQL/1107_tbl_Shop_Plant_Audit.sql deleted file mode 100644 index d848199d..00000000 --- a/static/MySQL/1107_tbl_Shop_Plant_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Plant Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Plant_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Plant_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_plant INT NOT NULL, - CONSTRAINT FK_Shop_Plant_Audit_id_plant - FOREIGN KEY (id_plant) - REFERENCES Shop_Plant(id_plant) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Plant_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/MySQL/1108_tbl_PH_Permission_Group.sql b/static/MySQL/1108_tbl_PH_Permission_Group.sql new file mode 100644 index 00000000..21665ca8 --- /dev/null +++ b/static/MySQL/1108_tbl_PH_Permission_Group.sql @@ -0,0 +1,17 @@ + +USE partsltd_prod; + +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'PH_Permission_Group' +; + +CREATE TABLE IF NOT EXISTS partsltd_prod.PH_Permission_Group ( + id_group INT NOT NULL AUTO_INCREMENT PRIMARY KEY + , code VARCHAR(50) + , name VARCHAR(255) + , display_order INT NOT NULL + , active BIT NOT NULL DEFAULT 1 +); \ No newline at end of file diff --git a/static/MySQL/1108_tbl_Shop_Plant_Temp.sql b/static/MySQL/1108_tbl_Shop_Plant_Temp.sql deleted file mode 100644 index 80c31df0..00000000 --- a/static/MySQL/1108_tbl_Shop_Plant_Temp.sql +++ /dev/null @@ -1,16 +0,0 @@ - --- Plant Temp - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Plant_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Plant_Temp ( - id_plant INT NOT NULL PRIMARY KEY - , code VARCHAR(50) NOT NULL - , name VARCHAR(500) NOT NULL - , id_address INT NOT NULL - , id_user_manager INT NOT NULL - , active BIT NOT NULL DEFAULT 1 - , guid BINARY(36) NOT NULL -); diff --git a/static/MySQL/1109_tbl_Shop_Storage_Location.sql b/static/MySQL/1109_tbl_Shop_Storage_Location.sql deleted file mode 100644 index b10726b7..00000000 --- a/static/MySQL/1109_tbl_Shop_Storage_Location.sql +++ /dev/null @@ -1,23 +0,0 @@ - --- Storage Location - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Storage_Location'; - -CREATE TABLE IF NOT EXISTS Shop_Storage_Location ( - id_location INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_plant INT NOT NULL, - CONSTRAINT FK_Shop_Storage_Location_id_plant - FOREIGN KEY (id_plant) - REFERENCES Shop_Plant(id_plant), - code VARCHAR(50) NOT NULL, - name VARCHAR(500) NOT NULL, - active BIT NOT NULL DEFAULT 1, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Storage_Location_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/MySQL/1110_tbl_Shop_Storage_Location_Audit.sql b/static/MySQL/1110_tbl_Shop_Storage_Location_Audit.sql deleted file mode 100644 index b9706fe2..00000000 --- a/static/MySQL/1110_tbl_Shop_Storage_Location_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Storage Location Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Storage_Location_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Storage_Location_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_location INT NOT NULL, - CONSTRAINT FK_Shop_Storage_Location_Audit_id_location - FOREIGN KEY (id_location) - REFERENCES Shop_Storage_Location(id_location) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Storage_Location_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/MySQL/1111_tbl_Shop_Storage_Location_Temp.sql b/static/MySQL/1111_tbl_Shop_Storage_Location_Temp.sql deleted file mode 100644 index 5f8af6c9..00000000 --- a/static/MySQL/1111_tbl_Shop_Storage_Location_Temp.sql +++ /dev/null @@ -1,13 +0,0 @@ - --- Storage Location Temp - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Storage_Location_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Storage_Location ( - id_location INT NOT NULL PRIMARY KEY, - code VARCHAR(50) NOT NULL, - name VARCHAR(500) NOT NULL, - active BIT NOT NULL DEFAULT 1 -); diff --git a/static/MySQL/1112_tbl_PH_Permission.sql b/static/MySQL/1112_tbl_PH_Permission.sql new file mode 100644 index 00000000..a3647098 --- /dev/null +++ b/static/MySQL/1112_tbl_PH_Permission.sql @@ -0,0 +1,25 @@ + +USE partsltd_prod; + +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'PH_Permission' +; + +CREATE TABLE IF NOT EXISTS partsltd_prod.PH_Permission ( + id_permission INT NOT NULL AUTO_INCREMENT PRIMARY KEY + , code VARCHAR(50) + , name VARCHAR(255) + , id_permission_group INT NOT NULL + , CONSTRAINT FK_PH_Permission_id_permission_group + FOREIGN KEY (id_permission_group) + REFERENCES partsltd_prod.PH_Permission_Group(id_group) + , id_access_level_required INT NOT NULL + , CONSTRAINT FK_PH_Permission_id_access_level_required + FOREIGN KEY (id_access_level_required) + REFERENCES partsltd_prod.PH_Access_Level(id_access_level) + , display_order INT NOT NULL + , active BIT NOT NULL DEFAULT 1 +); \ No newline at end of file diff --git a/static/MySQL/1112_tbl_Shop_Storage_Location_Branch.sql b/static/MySQL/1112_tbl_Shop_Storage_Location_Branch.sql deleted file mode 100644 index 6bf4ffc7..00000000 --- a/static/MySQL/1112_tbl_Shop_Storage_Location_Branch.sql +++ /dev/null @@ -1,29 +0,0 @@ - --- Storage Location Branch - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Storage_Location_Branch'; - -CREATE TABLE IF NOT EXISTS Shop_Storage_Location_Branch ( - id_branch INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_location_parent INT NOT NULL, - CONSTRAINT FK_Shop_Storage_Location_Branch_id_location_parent - FOREIGN KEY (id_location_parent) - REFERENCES Shop_Storage_Location(id_location) - ON UPDATE RESTRICT, - id_location_child INT NOT NULL, - CONSTRAINT FK_Shop_Storage_Location_Branch_id_location_child - FOREIGN KEY (id_location_child) - REFERENCES Shop_Storage_Location(id_location) - ON UPDATE RESTRICT, - -- depth INT NOT NULL, - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Storage_Location_Branch_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/MySQL/1113_tbl_Shop_Storage_Location_Branch_Audit.sql b/static/MySQL/1113_tbl_Shop_Storage_Location_Branch_Audit.sql deleted file mode 100644 index 262e732e..00000000 --- a/static/MySQL/1113_tbl_Shop_Storage_Location_Branch_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Storage Location Branch Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Storage_Location_Branch_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Storage_Location_Branch_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_branch INT NOT NULL, - CONSTRAINT FK_Shop_Storage_Location_Branch_Audit_id_branch - FOREIGN KEY (id_branch) - REFERENCES Shop_Storage_Location_Branch(id_branch) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Storage_Location_Branch_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/MySQL/1114_tbl_Shop_Storage_Location_Branch_Temp.sql b/static/MySQL/1114_tbl_Shop_Storage_Location_Branch_Temp.sql deleted file mode 100644 index 2919c29e..00000000 --- a/static/MySQL/1114_tbl_Shop_Storage_Location_Branch_Temp.sql +++ /dev/null @@ -1,15 +0,0 @@ - --- Storage Location Branch Temp - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Storage_Location_Branch_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Storage_Location_Branch_Temp ( - id_branch INT NOT NULL PRIMARY KEY, - id_location_parent INT NOT NULL, - id_location_child INT NOT NULL, - -- depth INT NOT NULL, - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL -); \ No newline at end of file diff --git a/static/MySQL/1115_tbl_Shop_Currency.sql b/static/MySQL/1115_tbl_Shop_Currency.sql deleted file mode 100644 index be3934a8..00000000 --- a/static/MySQL/1115_tbl_Shop_Currency.sql +++ /dev/null @@ -1,23 +0,0 @@ - --- Currencies - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Currency'; - -CREATE TABLE IF NOT EXISTS Shop_Currency ( - id_currency INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - code VARCHAR(50) NOT NULL, - name VARCHAR(255) NOT NULL, - symbol VARCHAR(50) NOT NULL, - factor_from_GBP FLOAT NOT NULL, - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Currency_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) - ON UPDATE RESTRICT -); \ No newline at end of file diff --git a/static/MySQL/1116_tbl_PH_User.sql b/static/MySQL/1116_tbl_PH_User.sql new file mode 100644 index 00000000..8b0ee445 --- /dev/null +++ b/static/MySQL/1116_tbl_PH_User.sql @@ -0,0 +1,29 @@ + +USE partsltd_prod; + +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'PH_User' +; + +CREATE TABLE IF NOT EXISTS partsltd_prod.PH_User ( + id_user INT NOT NULL AUTO_INCREMENT PRIMARY KEY + , id_user_auth0 VARCHAR(200) + , firstname VARCHAR(255) + , surname VARCHAR(255) + , email VARCHAR(254) + , is_email_verified BIT NOT NULL DEFAULT 0 + , is_super_user BIT NOT NULL DEFAULT 0 + , active BIT NOT NULL DEFAULT 1 + , created_on DATETIME + , id_user_created_by INT + , CONSTRAINT FK_PH_User_id_user_created_by + FOREIGN KEY (id_user_created_by) + REFERENCES partsltd_prod.PH_User(id_user) + , id_change_set INT + , CONSTRAINT FK_PH_User_id_change_set + FOREIGN KEY (id_change_set) + REFERENCES partsltd_prod.PH_User_Change_Set(id_change_set) +); diff --git a/static/MySQL/1116_tbl_Shop_Currency_Audit.sql b/static/MySQL/1116_tbl_Shop_Currency_Audit.sql deleted file mode 100644 index bc910345..00000000 --- a/static/MySQL/1116_tbl_Shop_Currency_Audit.sql +++ /dev/null @@ -1,23 +0,0 @@ - --- Currency Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Currency_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Currency_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_currency INT NOT NULL, - CONSTRAINT FK_Shop_Currency_Audit_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Currency_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - ON UPDATE RESTRICT -); \ No newline at end of file diff --git a/static/MySQL/1117_tbl_Shop_Currency_Temp.sql b/static/MySQL/1117_tbl_Shop_Currency_Temp.sql deleted file mode 100644 index b9a9df3a..00000000 --- a/static/MySQL/1117_tbl_Shop_Currency_Temp.sql +++ /dev/null @@ -1,16 +0,0 @@ - --- Currency Temp - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Currency_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Currency_Temp ( - id_currency INT NOT NULL PRIMARY KEY, - code VARCHAR(50) NOT NULL, - name VARCHAR(255) NOT NULL, - symbol VARCHAR(1) NOT NULL, - factor_from_GBP FLOAT NOT NULL, - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL -); \ No newline at end of file diff --git a/static/MySQL/1118_tbl_PH_User_Audit.sql b/static/MySQL/1118_tbl_PH_User_Audit.sql new file mode 100644 index 00000000..fc71dfe4 --- /dev/null +++ b/static/MySQL/1118_tbl_PH_User_Audit.sql @@ -0,0 +1,24 @@ + +USE partsltd_prod; + +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'PH_User_Audit' +; + +CREATE TABLE IF NOT EXISTS partsltd_prod.PH_User_Audit ( + id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY + , id_user INT NOT NULL + , CONSTRAINT FK_PH_User_Audit_id_user + FOREIGN KEY (id_user) + REFERENCES partsltd_prod.PH_User(id_user) + , name_field VARCHAR(50) NOT NULL + , value_prev VARCHAR(500) + , value_new VARCHAR(500) + , id_change_set INT NOT NULL + , CONSTRAINT FK_PH_User_Audit_id_change_set + FOREIGN KEY (id_change_set) + REFERENCES partsltd_prod.PH_User_Change_Set(id_change_set) +); \ No newline at end of file diff --git a/static/MySQL/1118_tbl_Shop_Tax_Or_Surcharge.sql b/static/MySQL/1118_tbl_Shop_Tax_Or_Surcharge.sql deleted file mode 100644 index 92a5d4e5..00000000 --- a/static/MySQL/1118_tbl_Shop_Tax_Or_Surcharge.sql +++ /dev/null @@ -1,38 +0,0 @@ - --- Taxes and Surcharges - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Tax_Or_Surcharge'; - -CREATE TABLE Shop_Tax_Or_Surcharge ( - id_tax INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - code VARCHAR(50) NOT NULL, - name VARCHAR(200) NOT NULL, - id_region_buyer INT NOT NULL, - CONSTRAINT FK_Shop_Tax_Or_Surcharge_id_region_buyer - FOREIGN KEY (id_region_buyer) - REFERENCES Shop_Region(id_region), - id_region_seller INT NOT NULL, - CONSTRAINT FK_Shop_Tax_Or_Surcharge_id_region_seller - FOREIGN KEY (id_region_seller) - REFERENCES Shop_Region(id_region), - id_currency INT, - CONSTRAINT FK_Shop_Tax_Or_Surcharge_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency) - ON UPDATE RESTRICT, - fixed_fee FLOAT NOT NULL DEFAULT 0, - multiplier FLOAT NOT NULL DEFAULT 1 CHECK (multiplier > 0), - apply_fixed_fee_before_multiplier BIT DEFAULT 1, - quantity_min FLOAT NOT NULL DEFAULT 0, - quantity_max FLOAT NOT NULL, - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Tax_Or_Surcharge_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/MySQL/1119_tbl_PH_User_Temp.sql b/static/MySQL/1119_tbl_PH_User_Temp.sql new file mode 100644 index 00000000..cf09c942 --- /dev/null +++ b/static/MySQL/1119_tbl_PH_User_Temp.sql @@ -0,0 +1,22 @@ + +USE partsltd_prod; + +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'PH_User_Temp' +; + +CREATE TABLE IF NOT EXISTS partsltd_prod.PH_User_Temp ( + id_temp INT NOT NULL AUTO_INCREMENT PRIMARY KEY + , id_user INT NOT NULL + , id_user_auth0 VARCHAR(200) + , firstname VARCHAR(255) + , surname VARCHAR(255) + , email VARCHAR(254) + , is_email_verified BIT + , is_super_user BIT + , active BIT + , guid BINARY(36) NOT NULL +); diff --git a/static/MySQL/1119_tbl_Shop_Tax_Or_Surcharge_Audit.sql b/static/MySQL/1119_tbl_Shop_Tax_Or_Surcharge_Audit.sql deleted file mode 100644 index 51d3356b..00000000 --- a/static/MySQL/1119_tbl_Shop_Tax_Or_Surcharge_Audit.sql +++ /dev/null @@ -1,23 +0,0 @@ - --- Tax Or Surcharge Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Tax_Or_Surcharge_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Tax_Or_Surcharge_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_tax INT NOT NULL, - CONSTRAINT FK_Shop_Tax_Or_Surcharge_Audit_id_discount - FOREIGN KEY (id_tax) - REFERENCES Shop_Tax_Or_Surcharge(id_tax) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Tax_Or_Surcharge_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) - ON UPDATE RESTRICT -); \ No newline at end of file diff --git a/static/MySQL/1120_tbl_PH_Role.sql b/static/MySQL/1120_tbl_PH_Role.sql new file mode 100644 index 00000000..a2bd2bf0 --- /dev/null +++ b/static/MySQL/1120_tbl_PH_Role.sql @@ -0,0 +1,26 @@ + +USE partsltd_prod; + +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'PH_Role' +; + +CREATE TABLE IF NOT EXISTS partsltd_prod.PH_Role ( + id_role INT NOT NULL AUTO_INCREMENT PRIMARY KEY + , code VARCHAR(50) + , name VARCHAR(255) + , display_order INT NOT NULL + , active BIT NOT NULL DEFAULT 1 + , created_on DATETIME + , id_user_created_by INT + , CONSTRAINT FK_PH_Role_id_user_created_by + FOREIGN KEY (id_user_created_by) + REFERENCES partsltd_prod.PH_User(id_user) + , id_change_set INT + , CONSTRAINT FK_PH_Role_id_change_set + FOREIGN KEY (id_change_set) + REFERENCES partsltd_prod.PH_User_Change_Set(id_change_set) +); \ No newline at end of file diff --git a/static/MySQL/1120_tbl_Shop_Tax_Or_Surcharge_Temp.sql b/static/MySQL/1120_tbl_Shop_Tax_Or_Surcharge_Temp.sql deleted file mode 100644 index fe340585..00000000 --- a/static/MySQL/1120_tbl_Shop_Tax_Or_Surcharge_Temp.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Taxes and Surcharges Temp - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Tax_Or_Surcharge_Temp'; - -CREATE TABLE Shop_Tax_Or_Surcharge_Temp ( - id_tax INT NOT NULL PRIMARY KEY, - code VARCHAR(50) NOT NULL, - name VARCHAR(200) NOT NULL, - id_region_buyer INT NOT NULL, - id_region_seller INT NOT NULL, - id_currency INT, - fixed_fee FLOAT NOT NULL DEFAULT 0, - multiplier FLOAT NOT NULL DEFAULT 1 CHECK (multiplier > 0), - apply_fixed_fee_before_multiplier BIT DEFAULT 1, - quantity_min FLOAT NOT NULL DEFAULT 0, - quantity_max FLOAT NOT NULL, - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL -); diff --git a/static/MySQL/1121_tbl_PH_Role_Audit.sql b/static/MySQL/1121_tbl_PH_Role_Audit.sql new file mode 100644 index 00000000..cba62a56 --- /dev/null +++ b/static/MySQL/1121_tbl_PH_Role_Audit.sql @@ -0,0 +1,24 @@ + +USE partsltd_prod; + +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'PH_Role_Audit' +; + +CREATE TABLE IF NOT EXISTS partsltd_prod.PH_Role_Audit ( + id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY + , id_role INT NOT NULL + , CONSTRAINT FK_PH_Role_Audit_id_role + FOREIGN KEY (id_role) + REFERENCES partsltd_prod.PH_Role(id_role) + , name_field VARCHAR(50) NOT NULL + , value_prev VARCHAR(500) + , value_new VARCHAR(500) + , id_change_set INT NOT NULL + , CONSTRAINT FK_PH_Role_Audit_id_change_set + FOREIGN KEY (id_change_set) + REFERENCES partsltd_prod.PH_User_Change_Set(id_change_set) +); \ No newline at end of file diff --git a/static/MySQL/1121_tbl_Shop_Unit_Measurement.sql b/static/MySQL/1121_tbl_Shop_Unit_Measurement.sql deleted file mode 100644 index b22de910..00000000 --- a/static/MySQL/1121_tbl_Shop_Unit_Measurement.sql +++ /dev/null @@ -1,26 +0,0 @@ - --- Unit of Measurement - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Unit_Measurement'; - -CREATE TABLE IF NOT EXISTS Shop_Unit_Measurement ( - id_unit_measurement INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - name_singular VARCHAR(255) NOT NULL, - name_plural VARCHAR(256) NOT NULL, - symbol VARCHAR(50) NOT NULL, - symbol_is_suffix_not_prefix BIT NOT NULL DEFAULT 1, - is_base_unit BIT NOT NULL DEFAULT 0, - is_unit_of_distance BIT NOT NULL DEFAULT 0, - is_unit_of_mass BIT NOT NULL DEFAULT 0, - is_unit_of_time BIT NOT NULL DEFAULT 0, - is_unit_of_volume BIT NOT NULL DEFAULT 0, - active BIT NOT NULL DEFAULT 1, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Unit_Measurement_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/MySQL/1122_tbl_Shop_Unit_Measurement_Audit.sql b/static/MySQL/1122_tbl_Shop_Unit_Measurement_Audit.sql deleted file mode 100644 index 81a0e012..00000000 --- a/static/MySQL/1122_tbl_Shop_Unit_Measurement_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Unit of Measurement Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Unit_Measurement_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Unit_Measurement_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_unit_measurement INT NOT NULL, - CONSTRAINT FK_Shop_Unit_Measurement_Audit_id_unit_measurement - FOREIGN KEY (id_unit_measurement) - REFERENCES Shop_Unit_Measurement(id_unit_measurement) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Unit_Measurement_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/MySQL/1124_tbl_PH_Role_Permission_Link.sql b/static/MySQL/1124_tbl_PH_Role_Permission_Link.sql new file mode 100644 index 00000000..131ea038 --- /dev/null +++ b/static/MySQL/1124_tbl_PH_Role_Permission_Link.sql @@ -0,0 +1,35 @@ + +USE partsltd_prod; + +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'PH_Role_Permission_Link' +; + +CREATE TABLE IF NOT EXISTS partsltd_prod.PH_Role_Permission_Link ( + id_link INT NOT NULL AUTO_INCREMENT PRIMARY KEY + , id_role INT NOT NULL + , CONSTRAINT FK_PH_Role_Permission_Link_id_role + FOREIGN KEY (id_role) + REFERENCES partsltd_prod.PH_Role(id_role) + , id_permission INT NOT NULL + , CONSTRAINT FK_PH_Role_Permission_Link_id_permission + FOREIGN KEY (id_permission) + REFERENCES partsltd_prod.PH_Permission(id_permission) + , id_access_level INT NOT NULL + , CONSTRAINT FK_PH_Role_Permission_Link_id_access_level + FOREIGN KEY (id_access_level) + REFERENCES partsltd_prod.PH_Access_Level(id_access_level) + , active BIT NOT NULL DEFAULT 1 + , created_on DATETIME + , id_user_created_by INT + , CONSTRAINT FK_PH_Role_Permission_Link_id_user_created_by + FOREIGN KEY (id_user_created_by) + REFERENCES partsltd_prod.PH_User(id_user) + , id_change_set INT + , CONSTRAINT FK_PH_Role_Permission_Link_id_change_set + FOREIGN KEY (id_change_set) + REFERENCES partsltd_prod.PH_User_Change_Set(id_change_set) +); \ No newline at end of file diff --git a/static/MySQL/1124_tbl_Shop_Unit_Measurement_Conversion.sql b/static/MySQL/1124_tbl_Shop_Unit_Measurement_Conversion.sql deleted file mode 100644 index cbb2da10..00000000 --- a/static/MySQL/1124_tbl_Shop_Unit_Measurement_Conversion.sql +++ /dev/null @@ -1,23 +0,0 @@ - --- Unit of Measurement Conversion - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Unit_Measurement_Conversion'; - -CREATE TABLE IF NOT EXISTS Shop_Unit_Measurement_Conversion ( - id_conversion INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - id_unit_derived INT NOT NULL, - id_unit_base INT NOT NULL, - multiplier_unit_base FLOAT NOT NULL, - increment_unit_base FLOAT NOT NULL, - apply_multiplier_before_increment BIT NOT NULL DEFAULT 1, - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Unit_Measurement_Conversion_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/MySQL/1125_tbl_PH_Role_Permission_Link_Audit.sql b/static/MySQL/1125_tbl_PH_Role_Permission_Link_Audit.sql new file mode 100644 index 00000000..fbc4626b --- /dev/null +++ b/static/MySQL/1125_tbl_PH_Role_Permission_Link_Audit.sql @@ -0,0 +1,23 @@ + +USE partsltd_prod; + +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'PH_Role_Permission_Link_Audit'; + +CREATE TABLE IF NOT EXISTS partsltd_prod.PH_Role_Permission_Link_Audit ( + id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY + , id_link INT NOT NULL + , CONSTRAINT FK_PH_Role_Permission_Link_Audit_id_link + FOREIGN KEY (id_link) + REFERENCES partsltd_prod.PH_Role_Permission_Link(id_link) + , name_field VARCHAR(50) NOT NULL + , value_prev VARCHAR(500) + , value_new VARCHAR(500) + , id_change_set INT NOT NULL + , CONSTRAINT FK_PH_Role_Permission_Link_Audit_id_change_set + FOREIGN KEY (id_change_set) + REFERENCES partsltd_prod.PH_User_Change_Set(id_change_set) +); \ No newline at end of file diff --git a/static/MySQL/1125_tbl_Shop_Unit_Measurement_Conversion_Audit.sql b/static/MySQL/1125_tbl_Shop_Unit_Measurement_Conversion_Audit.sql deleted file mode 100644 index 3507be32..00000000 --- a/static/MySQL/1125_tbl_Shop_Unit_Measurement_Conversion_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Unit of Measurement Conversion Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Unit_Measurement_Conversion_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Unit_Measurement_Conversion_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_conversion INT NOT NULL, - CONSTRAINT FK_Shop_Unit_Measurement_Conversion_Audit_id_conversion - FOREIGN KEY (id_conversion) - REFERENCES Shop_Unit_Measurement_Conversion(id_conversion) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Unit_Measurement_Conversion_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/MySQL/1128_tbl_PH_User_Role_Link.sql b/static/MySQL/1128_tbl_PH_User_Role_Link.sql new file mode 100644 index 00000000..9693ee15 --- /dev/null +++ b/static/MySQL/1128_tbl_PH_User_Role_Link.sql @@ -0,0 +1,31 @@ + +USE partsltd_prod; + +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'PH_User_Role_Link' +; + +CREATE TABLE IF NOT EXISTS partsltd_prod.PH_User_Role_Link ( + id_link INT NOT NULL AUTO_INCREMENT PRIMARY KEY + , id_user INT NOT NULL + , CONSTRAINT FK_PH_User_Role_Link_id_user + FOREIGN KEY (id_user) + REFERENCES partsltd_prod.PH_User(id_user) + , id_role INT NOT NULL + , CONSTRAINT FK_PH_User_Role_Link_id_role + FOREIGN KEY (id_role) + REFERENCES partsltd_prod.PH_Role(id_role) + , active BIT NOT NULL DEFAULT 1 + , created_on DATETIME + , id_user_created_by INT + , CONSTRAINT FK_PH_User_Role_Link_id_user_created_by + FOREIGN KEY (id_user_created_by) + REFERENCES partsltd_prod.PH_User(id_user) + , id_change_set INT + , CONSTRAINT FK_PH_User_Role_Link_id_change_set + FOREIGN KEY (id_change_set) + REFERENCES partsltd_prod.PH_User_Change_Set(id_change_set) +); \ No newline at end of file diff --git a/static/MySQL/1129_tbl_PH_User_Role_Link_Audit.sql b/static/MySQL/1129_tbl_PH_User_Role_Link_Audit.sql new file mode 100644 index 00000000..f01eba09 --- /dev/null +++ b/static/MySQL/1129_tbl_PH_User_Role_Link_Audit.sql @@ -0,0 +1,24 @@ + +USE partsltd_prod; + +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'PH_User_Role_Link_Audit' +; + +CREATE TABLE IF NOT EXISTS partsltd_prod.PH_User_Role_Link_Audit ( + id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY + , id_link INT NOT NULL + , CONSTRAINT FK_PH_User_Role_Link_Audit_id_link + FOREIGN KEY (id_link) + REFERENCES partsltd_prod.PH_User_Role_Link(id_link) + , name_field VARCHAR(50) NOT NULL + , value_prev VARCHAR(500) + , value_new VARCHAR(500) + , id_change_set INT NOT NULL + , CONSTRAINT FK_PH_User_Role_Link_Audit_id_change_set + FOREIGN KEY (id_change_set) + REFERENCES partsltd_prod.PH_User_Change_Set(id_change_set) +); diff --git a/static/MySQL/1130_tbl_PH_Calc_User_Temp.sql b/static/MySQL/1130_tbl_PH_Calc_User_Temp.sql new file mode 100644 index 00000000..7ecaf0df --- /dev/null +++ b/static/MySQL/1130_tbl_PH_Calc_User_Temp.sql @@ -0,0 +1,22 @@ + +USE partsltd_prod; + +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'PH_Calc_User_Temp' +; + +CREATE TABLE IF NOT EXISTS partsltd_prod.PH_Calc_User_Temp ( + guid BINARY(36) NOT NULL + , id_user INT + , id_permission_required INT NOT NULL + , CONSTRAINT FK_PH_Calc_User_Temp_id_permission_required + FOREIGN KEY (id_permission_required) + REFERENCES partsltd_prod.PH_Permission (id_permission) + , priority_access_level_required INT NOT NULL + , is_super_user BIT + , priority_access_level_user INT + , has_access BIT +); \ No newline at end of file diff --git a/static/MySQL/1200_tbl_PH_Contact_Form_Change_Set.sql b/static/MySQL/1200_tbl_PH_Contact_Form_Change_Set.sql new file mode 100644 index 00000000..331b674e --- /dev/null +++ b/static/MySQL/1200_tbl_PH_Contact_Form_Change_Set.sql @@ -0,0 +1,19 @@ + +USE partsltd_prod; + +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'PH_Contact_Form_Change_Set' +; + +CREATE TABLE IF NOT EXISTS partsltd_prod.PH_Contact_Form_Change_Set ( + id_change_set INT NOT NULL AUTO_INCREMENT PRIMARY KEY + , comment VARCHAR(500) + , updated_last_on DATETIME + , id_user_updated_last_by INT + , CONSTRAINT FK_PH_Role_id_user_updated_last_by + FOREIGN KEY (id_user_updated_last_by) + REFERENCES partsltd_prod.PH_User(id_user) +); \ No newline at end of file diff --git a/static/MySQL/1200_tbl_Shop_Product_Category.sql b/static/MySQL/1200_tbl_Shop_Product_Category.sql deleted file mode 100644 index 79553f41..00000000 --- a/static/MySQL/1200_tbl_Shop_Product_Category.sql +++ /dev/null @@ -1,24 +0,0 @@ - --- Categories - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Category'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Category ( - id_category INT NOT NULL AUTO_INCREMENT PRIMARY KEY - , code VARCHAR(50) - , name VARCHAR(255) - , description VARCHAR(4000) - , active BIT NOT NULL DEFAULT 1 - , display_order INT NOT NULL - , id_access_level_required INT NOT NULL - , CONSTRAINT FK_Shop_Product_Category_id_access_level_required - FOREIGN KEY (id_access_level_required) - REFERENCES Shop_Access_Level(id_access_level) - , created_on DATETIME - , created_by INT NOT NULL - , id_change_set INT - , CONSTRAINT FK_Shop_Product_Category_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/MySQL/1201_tbl_PH_Contact_Form.sql b/static/MySQL/1201_tbl_PH_Contact_Form.sql new file mode 100644 index 00000000..5fa40444 --- /dev/null +++ b/static/MySQL/1201_tbl_PH_Contact_Form.sql @@ -0,0 +1,28 @@ + +USE partsltd_prod; + +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'PH_Contact_Form' +; + +CREATE TABLE IF NOT EXISTS partsltd_prod.PH_Contact_Form ( + id_contact_form INT NOT NULL AUTO_INCREMENT PRIMARY KEY + , email VARCHAR(255) NOT NULL + , name_contact VARCHAR(255) NOT NULL + , name_company VARCHAR(255) NOT NULL + , message TEXT NOT NULL + , receive_marketing_communications BIT NOT NULL DEFAULT 0 + , active BIT NOT NULL DEFAULT 1 + , created_on DATETIME + , id_user_created_by INT + , CONSTRAINT FK_PH_Contact_Form_id_user_created_by + FOREIGN KEY (id_user_created_by) + REFERENCES partsltd_prod.PH_User(id_user) + , id_change_set INT + , CONSTRAINT FK_PH_Contact_Form_id_change_set + FOREIGN KEY (id_change_set) + REFERENCES partsltd_prod.PH_Contact_Form_Change_Set(id_change_set) +); diff --git a/static/MySQL/1201_tbl_Shop_Product_Category_Audit.sql b/static/MySQL/1201_tbl_Shop_Product_Category_Audit.sql deleted file mode 100644 index 97beb2e6..00000000 --- a/static/MySQL/1201_tbl_Shop_Product_Category_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Category Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Category_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Category_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_category INT NOT NULL, - CONSTRAINT FK_Shop_Product_Category_Audit_id_category - FOREIGN KEY (id_category) - REFERENCES Shop_Product_Category(id_category) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Product_Category_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/MySQL/1202_tbl_PH_Contact_Form_Audit.sql b/static/MySQL/1202_tbl_PH_Contact_Form_Audit.sql new file mode 100644 index 00000000..7a4ea091 --- /dev/null +++ b/static/MySQL/1202_tbl_PH_Contact_Form_Audit.sql @@ -0,0 +1,24 @@ + +USE partsltd_prod; + +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'PH_Contact_Form_Audit' +; + +CREATE TABLE IF NOT EXISTS partsltd_prod.PH_Contact_Form_Audit ( + id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY + , id_contact_form INT NOT NULL + , CONSTRAINT FK_PH_Contact_Form_Audit_id_contact_form + FOREIGN KEY (id_contact_form) + REFERENCES partsltd_prod.PH_Contact_Form(id_contact_form) + , name_field VARCHAR(50) NOT NULL + , value_prev TEXT + , value_new TEXT + , id_change_set INT NOT NULL + , CONSTRAINT FK_PH_Contact_Form_Audit_id_change_set + FOREIGN KEY (id_change_set) + REFERENCES partsltd_prod.PH_Contact_Form_Change_Set(id_change_set) +); diff --git a/static/MySQL/1202_tbl_Shop_Product_Category_Temp.sql b/static/MySQL/1202_tbl_Shop_Product_Category_Temp.sql deleted file mode 100644 index e9448f0e..00000000 --- a/static/MySQL/1202_tbl_Shop_Product_Category_Temp.sql +++ /dev/null @@ -1,21 +0,0 @@ - --- Categories Temp - --- DROP TABLE Shop_Product_Category_Temp; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Category_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Category_Temp ( - id_temp INT NOT NULL PRIMARY KEY AUTO_INCREMENT - , id_category INT NOT NULL - , code VARCHAR(50) NOT NULL - , name VARCHAR(255) NOT NULL - , description VARCHAR(4000) NULL - , id_access_level_required INT NOT NULL DEFAULT 1 - , display_order INT NOT NULL - , active BIT NULL - , can_view BIT NULL - , can_edit BIT NULL - , can_admin BIT NULL - , guid BINARY(36) NOT NULL -); diff --git a/static/MySQL/1203_tbl_PH_Contact_Form_Temp.sql b/static/MySQL/1203_tbl_PH_Contact_Form_Temp.sql new file mode 100644 index 00000000..2258272b --- /dev/null +++ b/static/MySQL/1203_tbl_PH_Contact_Form_Temp.sql @@ -0,0 +1,21 @@ + +USE partsltd_prod; + +SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning +FROM INFORMATION_SCHEMA.TABLES +WHERE + TABLE_SCHEMA = 'partsltd_prod' + AND TABLE_NAME = 'PH_Contact_Form_Temp' +; + +CREATE TABLE IF NOT EXISTS partsltd_prod.PH_Contact_Form_Temp ( + id_temp INT NOT NULL PRIMARY KEY AUTO_INCREMENT + , id_contact_form INT + , email VARCHAR(255) + , name_contact VARCHAR(255) + , name_company VARCHAR(255) + , message TEXT + , receive_marketing_communications BIT + , active BIT + , guid BINARY(36) +); diff --git a/static/MySQL/1203_tbl_Shop_Product.sql b/static/MySQL/1203_tbl_Shop_Product.sql deleted file mode 100644 index 8c1c6201..00000000 --- a/static/MySQL/1203_tbl_Shop_Product.sql +++ /dev/null @@ -1,48 +0,0 @@ - --- Products - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product'; - -CREATE TABLE IF NOT EXISTS Shop_Product ( - id_product INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - name VARCHAR(255) NOT NULL, - -- description VARCHAR(4000), - id_category INT NOT NULL, - has_variations BIT NOT NULL, - /* - price_GBP_full FLOAT, - price_GBP_min FLOAT, - -- ratio_discount_overall FLOAT NOT NULL DEFAULT 0, - CONSTRAINT FK_Shop_Product_id_category - FOREIGN KEY (id_category) - REFERENCES Shop_Product_Category(id_category) - ON UPDATE RESTRICT, - latency_manuf INT, - quantity_min FLOAT, - quantity_max FLOAT, - quantity_step FLOAT, - quantity_stock FLOAT, - is_subscription BIT, - id_unit_measurement_interval_recurrence INT, - CONSTRAINT FK_Shop_Product_id_unit_measurement_interval_recurrence - FOREIGN KEY (id_unit_measurement_interval_recurrence) - REFERENCES Shop_Interval_Recurrence(id_interval), - count_interval_recurrence INT, - */ - id_access_level_required INT NOT NULL, - CONSTRAINT FK_Shop_Product_id_access_level_required - FOREIGN KEY (id_access_level_required) - REFERENCES Shop_Access_Level(id_access_level), - -- id_stripe_product VARCHAR(100), - -- id_stripe_price VARCHAR(100) NOT NULL, - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME NOT NULL, - created_by INT NOT NULL, - id_change_set INT, - CONSTRAINT FK_Shop_Product_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/MySQL/1204_tbl_Shop_Product_Audit.sql b/static/MySQL/1204_tbl_Shop_Product_Audit.sql deleted file mode 100644 index 761d1df3..00000000 --- a/static/MySQL/1204_tbl_Shop_Product_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Products - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_product INT NOT NULL, - CONSTRAINT FK_Shop_Product_Audit_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Product_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/MySQL/1205_tbl_Shop_Product_Temp.sql b/static/MySQL/1205_tbl_Shop_Product_Temp.sql deleted file mode 100644 index 9468a4e4..00000000 --- a/static/MySQL/1205_tbl_Shop_Product_Temp.sql +++ /dev/null @@ -1,21 +0,0 @@ - --- Products Temp - --- DROP TABLE IF EXISTS Shop_Product_Temp; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Temp ( - id_temp INT NOT NULL PRIMARY KEY AUTO_INCREMENT - , id_product INT NOT NULL - , name VARCHAR(255) NOT NULL - , id_category INT NOT NULL - , has_variations BIT NOT NULL - , id_access_level_required INT NOT NULL - , display_order INT NOT NULL - , active BIT NOT NULL DEFAULT 1 - , can_view BIT NULL DEFAULT NULL - , can_edit BIT NULL DEFAULT NULL - , can_admin BIT NULL DEFAULT NULL - , guid BINARY(36) NOT NULL -); diff --git a/static/MySQL/1206_tbl_Shop_Product_Permutation.sql b/static/MySQL/1206_tbl_Shop_Product_Permutation.sql deleted file mode 100644 index 52abdf8a..00000000 --- a/static/MySQL/1206_tbl_Shop_Product_Permutation.sql +++ /dev/null @@ -1,61 +0,0 @@ - --- Product Permutation - --- DROP TABLE partsltd_prod.Shop_Product_Permutation; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Permutation'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Permutation ( - id_permutation INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_permutation_temp INT NOT NULL, - id_product INT NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product) - ON UPDATE RESTRICT, - -- name VARCHAR(255) NOT NULL, - description VARCHAR(4000) NOT NULL, - cost_local_VAT_excl FLOAT NULL, - cost_local_VAT_incl FLOAT NULL, - id_currency_cost INT NOT NULL, - profit_local_min FLOAT NULL, - -- id_currency_profit_min INT NOT NULL, - latency_manufacture INT NOT NULL, - id_unit_measurement_quantity INT NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_id_unit_quantity - FOREIGN KEY (id_unit_measurement_quantity) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - count_unit_measurement_per_quantity_step FLOAT NOT NULL, - quantity_min FLOAT NULL, - quantity_max FLOAT NULL, - quantity_stock FLOAT NOT NULL, - is_subscription BIT NOT NULL, - id_unit_measurement_interval_recurrence INT, - CONSTRAINT FK_Shop_Product_Permutation_id_unit_interval_recurrence - FOREIGN KEY (id_unit_measurement_interval_recurrence) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - /* - CONSTRAINT CHECK_FK_Shop_Product_Permutation_id_unit_measurement_interval_recurrence - CHECK (id_unit_measurement_interval_recurrence IN (SELECT id_unit_measurement FROM Shop_Unit_Measurement WHERE is_unit_of_time = 1)), - */ - count_interval_recurrence INT, - id_stripe_product VARCHAR(100) NULL, - does_expire_faster_once_unsealed BIT NOT NULL DEFAULT 0, - id_unit_measurement_interval_expiration_unsealed INT, - CONSTRAINT FK_Shop_Product_Permutation_id_unit_interval_expiration_unsealed - FOREIGN KEY (id_unit_measurement_interval_expiration_unsealed) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - /* - CONSTRAINT CHECK_FK_Shop_Product_Permutation_id_interval_expiration_unsealed - CHECK (id_interval_expiration_unsealed IN (SELECT id_unit_measurement FROM Shop_Unit_Measurement WHERE is_unit_of_time = 1)), - */ - count_interval_expiration_unsealed INT, - active BIT NOT NULL DEFAULT 1, - -- display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Product_Permutation_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/MySQL/1207_tbl_Shop_Product_Permutation_Audit.sql b/static/MySQL/1207_tbl_Shop_Product_Permutation_Audit.sql deleted file mode 100644 index deaa8fe3..00000000 --- a/static/MySQL/1207_tbl_Shop_Product_Permutation_Audit.sql +++ /dev/null @@ -1,23 +0,0 @@ - --- Product Permutation Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Permutation_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Permutation_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_permutation INT NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_Audit_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) - ON UPDATE RESTRICT -); diff --git a/static/MySQL/1208_tbl_Shop_Product_Permutation_Temp.sql b/static/MySQL/1208_tbl_Shop_Product_Permutation_Temp.sql deleted file mode 100644 index 3e836815..00000000 --- a/static/MySQL/1208_tbl_Shop_Product_Permutation_Temp.sql +++ /dev/null @@ -1,37 +0,0 @@ - --- Product Permutation Temp - --- DROP TABLE IF EXISTS Shop_Product_Permutation_Temp; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Permutation_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Permutation_Temp ( - id_temp INT NOT NULL PRIMARY KEY AUTO_INCREMENT - , id_permutation INT NOT NULL - , id_product INT NOT NULL - , csv_id_pairs_variation VARCHAR(4000) NULL - , description VARCHAR(4000) NOT NULL - , cost_local_VAT_excl FLOAT NULL - , cost_local_VAT_incl FLOAT NULL - , id_currency_cost INT NOT NULL - , profit_local_min FLOAT NULL - , latency_manufacture INT NOT NULL - , id_unit_measurement_quantity INT NOT NULL - , count_unit_measurement_per_quantity_step FLOAT NOT NULL - , quantity_min FLOAT NULL - , quantity_max FLOAT NULL - , quantity_stock FLOAT NULL - , is_subscription BIT NOT NULL - , id_unit_measurement_interval_recurrence INT - , count_interval_recurrence INT - , id_stripe_product VARCHAR(100) NULL - , does_expire_faster_once_unsealed BIT NOT NULL DEFAULT 0 - , id_unit_measurement_interval_expiration_unsealed INT - , count_interval_expiration_unsealed INT - , active BIT NOT NULL DEFAULT 1 - -- display_order INT NOT NULL - , guid BINARY(36) - , can_view BIT NULL DEFAULT NULL - , can_edit BIT NULL DEFAULT NULL - , can_admin BIT NULL DEFAULT NULL -); diff --git a/static/MySQL/1209_tbl_Shop_Variation_Type.sql b/static/MySQL/1209_tbl_Shop_Variation_Type.sql deleted file mode 100644 index e88b30c2..00000000 --- a/static/MySQL/1209_tbl_Shop_Variation_Type.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Variation Types - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Variation_Type'; - -CREATE TABLE IF NOT EXISTS Shop_Variation_Type ( - id_type INT NOT NULL AUTO_INCREMENT PRIMARY KEY - , id_type_temp INT NULL - , code VARCHAR(50) - , name VARCHAR(255) - , name_plural VARCHAR(256) - , active BIT NOT NULL DEFAULT 1 - , display_order INT NOT NULL - , created_on DATETIME - , created_by INT - , id_change_set INT - , CONSTRAINT FK_Shop_Variation_Type_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/MySQL/1210_tbl_Shop_Variation_Type_Audit.sql b/static/MySQL/1210_tbl_Shop_Variation_Type_Audit.sql deleted file mode 100644 index 74c99ce3..00000000 --- a/static/MySQL/1210_tbl_Shop_Variation_Type_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Variation Type Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Variation_Type_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Variation_Type_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_type INT NOT NULL, - CONSTRAINT FK_Shop_Variation_Type_Audit_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Variation_Type(id_type) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Variation_Type_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/MySQL/1211_tbl_Shop_Variation_Type_Temp.sql b/static/MySQL/1211_tbl_Shop_Variation_Type_Temp.sql deleted file mode 100644 index 419ef11a..00000000 --- a/static/MySQL/1211_tbl_Shop_Variation_Type_Temp.sql +++ /dev/null @@ -1,20 +0,0 @@ - --- Variation Types Temp - --- DROP TABLE partsltd_prod.Shop_Variation_Type_Temp; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Variation_Type_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Variation_Type_Temp ( - id_temp INT NOT NULL PRIMARY KEY AUTO_INCREMENT - , id_type INT NOT NULL - -- , id_type_temp INT NOT NULL - , code VARCHAR(50) - , name VARCHAR(255) - , name_plural VARCHAR(256) - , active BIT NULL - , display_order INT NOT NULL - , created_on DATETIME - , created_by INT - , guid BINARY(36) NOT NULL -); \ No newline at end of file diff --git a/static/MySQL/1212_tbl_Shop_Variation.sql b/static/MySQL/1212_tbl_Shop_Variation.sql deleted file mode 100644 index 1b43dba9..00000000 --- a/static/MySQL/1212_tbl_Shop_Variation.sql +++ /dev/null @@ -1,30 +0,0 @@ - --- Variations - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Variation'; - -CREATE TABLE Shop_Variation ( - id_variation INT NOT NULL AUTO_INCREMENT PRIMARY KEY - , id_type INT NOT NULL - , CONSTRAINT FK_Shop_Variation_id_type - FOREIGN KEY (id_type) - REFERENCES partsltd_prod.Shop_Variation_Type(id_type) - ON UPDATE RESTRICT - , id_unit_measurement INT NULL - , CONSTRAINT FK_Shop_Unit_Measurement_id_unit_measurement - FOREIGN KEY (id_unit_measurement) - REFERENCES partsltd_prod.Shop_Unit_Measurement(id_unit_measurement) - , count_unit_measurement INT NULL - , code VARCHAR(50) - , name VARCHAR(255) - , active BIT NOT NULL DEFAULT 1 - , display_order INT NOT NULL - , created_on DATETIME - , created_by INT - , id_change_set INT - , CONSTRAINT FK_Shop_Variation_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES partsltd_prod.Shop_Product_Change_Set(id_change_set) -); diff --git a/static/MySQL/1213_tbl_Shop_Variation_Audit.sql b/static/MySQL/1213_tbl_Shop_Variation_Audit.sql deleted file mode 100644 index 2555eea2..00000000 --- a/static/MySQL/1213_tbl_Shop_Variation_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Variation Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Variation_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Variation_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_variation INT NOT NULL, - CONSTRAINT FK_Shop_Variation_Audit_id_variation - FOREIGN KEY (id_variation) - REFERENCES Shop_Variation(id_variation) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Variation_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/MySQL/1214_tbl_Shop_Variation_Temp.sql b/static/MySQL/1214_tbl_Shop_Variation_Temp.sql deleted file mode 100644 index 8412a815..00000000 --- a/static/MySQL/1214_tbl_Shop_Variation_Temp.sql +++ /dev/null @@ -1,21 +0,0 @@ - --- Variations Temp - --- DROP TABLE partsltd_prod.Shop_Variation_Temp; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Variation_Temp'; - -CREATE TABLE Shop_Variation_Temp ( - id_temp INT NOT NULL PRIMARY KEY AUTO_INCREMENT - , id_variation INT NOT NULL - , id_type INT NOT NULL - , id_unit_measurement INT NULL - , count_unit_measurement INT NULL - , code VARCHAR(50) - , name VARCHAR(255) - , active BIT - , display_order INT NOT NULL - , created_on DATETIME - , created_by INT - , guid BINARY(36) -); diff --git a/static/MySQL/1215_tbl_Shop_Product_Permutation_Variation_Link.sql b/static/MySQL/1215_tbl_Shop_Product_Permutation_Variation_Link.sql deleted file mode 100644 index 6687ea39..00000000 --- a/static/MySQL/1215_tbl_Shop_Product_Permutation_Variation_Link.sql +++ /dev/null @@ -1,28 +0,0 @@ - --- Product Permutation Variation Link - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Permutation_Variation_Link'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Permutation_Variation_Link ( - id_link INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_permutation INT NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_Variation_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation) - ON UPDATE RESTRICT, - id_variation INT NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_Variation_Link_id_variation - FOREIGN KEY (id_variation) - REFERENCES Shop_Variation(id_variation) - ON UPDATE RESTRICT, - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Product_Permutation_Variation_Link_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/MySQL/1216_tbl_Shop_Product_Permutation_Variation_Link_Audit.sql b/static/MySQL/1216_tbl_Shop_Product_Permutation_Variation_Link_Audit.sql deleted file mode 100644 index 38f4c915..00000000 --- a/static/MySQL/1216_tbl_Shop_Product_Permutation_Variation_Link_Audit.sql +++ /dev/null @@ -1,23 +0,0 @@ - --- Product Permutation Variation Link Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Permutation_Variation_Link_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Permutation_Variation_Link_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_link INT NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_Variation_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Product_Permutation_Variation_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_Variation_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) - ON UPDATE RESTRICT -); \ No newline at end of file diff --git a/static/MySQL/1217_tbl_Shop_Product_Permutation_Variation_Link_Temp.sql b/static/MySQL/1217_tbl_Shop_Product_Permutation_Variation_Link_Temp.sql deleted file mode 100644 index 3c1b4551..00000000 --- a/static/MySQL/1217_tbl_Shop_Product_Permutation_Variation_Link_Temp.sql +++ /dev/null @@ -1,16 +0,0 @@ - --- Product Permutation Variation Link - --- DROP TABLE IF EXISTS Shop_Product_Permutation_Variation_Link_Temp; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Permutation_Variation_Link_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Permutation_Variation_Link_Temp ( - id_temp INT NOT NULL AUTO_INCREMENT PRIMARY KEY - , id_link INT NOT NULL - , id_permutation INT NOT NULL - , id_variation INT NOT NULL - , active BIT NOT NULL - , display_order INT NOT NULL - , GUID BINARY(36) NOT NULL -); diff --git a/static/MySQL/1221_tbl_Shop_Product_Price.sql b/static/MySQL/1221_tbl_Shop_Product_Price.sql deleted file mode 100644 index ff504c33..00000000 --- a/static/MySQL/1221_tbl_Shop_Product_Price.sql +++ /dev/null @@ -1,32 +0,0 @@ - --- Product Price - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Price'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Price ( - id_price INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_permutation INT NULL, - CONSTRAINT FK_Shop_Product_Price_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - id_currency INT NOT NULL, - CONSTRAINT FK_Shop_Product_Price_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency), - id_region_purchase INT NOT NULL, - CONSTRAINT FK_Shop_Product_Price_id_region_purchase - FOREIGN KEY (id_region_purchase) - REFERENCES Shop_Region(id_region), - price_local_VAT_incl FLOAT NULL, - price_local_VAT_excl FLOAT NULL, - id_stripe_price VARCHAR(200), - active BIT NOT NULL DEFAULT 1, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Product_Price_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/MySQL/1222_tbl_Shop_Product_Price_Audit.sql b/static/MySQL/1222_tbl_Shop_Product_Price_Audit.sql deleted file mode 100644 index 5ddec22c..00000000 --- a/static/MySQL/1222_tbl_Shop_Product_Price_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Product Price Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Price_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Price_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_price INT NOT NULL, - CONSTRAINT FK_Shop_Product_Price_Audit_id_price - FOREIGN KEY (id_price) - REFERENCES Shop_Product_Price(id_price) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Product_Price_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/MySQL/1223_tbl_Shop_Product_Price_Temp.sql b/static/MySQL/1223_tbl_Shop_Product_Price_Temp.sql deleted file mode 100644 index 785fce8d..00000000 --- a/static/MySQL/1223_tbl_Shop_Product_Price_Temp.sql +++ /dev/null @@ -1,17 +0,0 @@ - --- Product Price Temp - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Price_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Price_Temp ( - id_price INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_permutation INT NULL, - id_currency INT NOT NULL, - id_region_purchase INT NOT NULL, - price_local_VAT_incl FLOAT NULL, - price_local_VAT_excl FLOAT NULL, - id_stripe_price VARCHAR(200), - active BIT NOT NULL DEFAULT 1 -); \ No newline at end of file diff --git a/static/MySQL/1224_tbl_Shop_Product_Image.sql b/static/MySQL/1224_tbl_Shop_Product_Image.sql deleted file mode 100644 index 41e447ad..00000000 --- a/static/MySQL/1224_tbl_Shop_Product_Image.sql +++ /dev/null @@ -1,27 +0,0 @@ - --- Product Permutation Images - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Image'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Image ( - id_image INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_type_image INT NOT NULL, - CONSTRAINT FK_Shop_Product_Image_id_type_image - FOREIGN KEY (id_type_image) - REFERENCES Shop_Image_Type(id_type), - id_permutation INT NULL, - CONSTRAINT FK_Shop_Product_Image_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - url VARCHAR(255), - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Product_Image_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/MySQL/1225_tbl_Shop_Product_Image_Audit.sql b/static/MySQL/1225_tbl_Shop_Product_Image_Audit.sql deleted file mode 100644 index 7b58799e..00000000 --- a/static/MySQL/1225_tbl_Shop_Product_Image_Audit.sql +++ /dev/null @@ -1,21 +0,0 @@ - --- Product Image Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Image_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Image_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_image INT NOT NULL, - CONSTRAINT FK_Shop_Product_Image_Audit_id_image - FOREIGN KEY (id_image) - REFERENCES Shop_Product_Image(id_image), - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Product_Image_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/MySQL/1227_tbl_Shop_Delivery_Option.sql b/static/MySQL/1227_tbl_Shop_Delivery_Option.sql deleted file mode 100644 index 98f77105..00000000 --- a/static/MySQL/1227_tbl_Shop_Delivery_Option.sql +++ /dev/null @@ -1,27 +0,0 @@ - --- Delivery Options - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Delivery_Option'; - -CREATE TABLE IF NOT EXISTS Shop_Delivery_Option ( - id_option INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - code VARCHAR(50) NOT NULL, - name VARCHAR(100) NOT NULL, - description VARCHAR(4000), - latency_delivery_min INT NOT NULL, - latency_delivery_max INT NOT NULL, - /* - quantity_min INT NOT NULL, - quantity_max INT NOT NULL, - */ - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Delivery_Option_Type_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/MySQL/1228_tbl_Shop_Delivery_Option_Audit.sql b/static/MySQL/1228_tbl_Shop_Delivery_Option_Audit.sql deleted file mode 100644 index 013ede49..00000000 --- a/static/MySQL/1228_tbl_Shop_Delivery_Option_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Delivery Option Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Delivery_Option_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Delivery_Option_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_option INT NOT NULL, - CONSTRAINT FK_Shop_Delivery_Option_Audit_id_option - FOREIGN KEY (id_option) - REFERENCES Shop_Delivery_Option(id_option) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Delivery_Option_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/MySQL/1230_tbl_Shop_Product_Permutation_Delivery_Option_Link.sql b/static/MySQL/1230_tbl_Shop_Product_Permutation_Delivery_Option_Link.sql deleted file mode 100644 index d2cc7be3..00000000 --- a/static/MySQL/1230_tbl_Shop_Product_Permutation_Delivery_Option_Link.sql +++ /dev/null @@ -1,46 +0,0 @@ - --- Delivery Option - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Permutation_Delivery_Option_Link'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Permutation_Delivery_Option_Link ( - id_link INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_product INT NOT NULL, - CONSTRAINT FK_Shop_Permutation_Delivery_Option_Link_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product) - ON UPDATE RESTRICT, - id_permutation INT, - CONSTRAINT FK_Shop_Permutation_Delivery_Option_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation) - ON UPDATE RESTRICT, - id_delivery_option INT NOT NULL, - CONSTRAINT FK_Shop_Permutation_Delivery_Option_Link_id_delivery_option - FOREIGN KEY (id_delivery_option) - REFERENCES Shop_Delivery_Option(id_option) - ON UPDATE RESTRICT, - id_region INT NOT NULL, - CONSTRAINT FK_Shop_Permutation_Delivery_Option_Link_id_region - FOREIGN KEY (id_region) - REFERENCES Shop_Region(id_region) - ON UPDATE RESTRICT, - id_currency INT NOT NULL, - CONSTRAINT FK_Shop_Permutation_Delivery_Option_Link_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency) - ON UPDATE RESTRICT, - price_local FLOAT NOT NULL, - quantity_min FLOAT NULL, - quantity_max FLOAT NULL, - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Permutation_Delivery_Option_Link_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/MySQL/1231_tbl_Shop_Product_Permutation_Delivery_Option_Link_Audit.sql b/static/MySQL/1231_tbl_Shop_Product_Permutation_Delivery_Option_Link_Audit.sql deleted file mode 100644 index d81a4068..00000000 --- a/static/MySQL/1231_tbl_Shop_Product_Permutation_Delivery_Option_Link_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Delivery Option Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Permutation_Delivery_Option_Link_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Permutation_Delivery_Option_Link_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_link INT NOT NULL, - CONSTRAINT FK_Shop_Permutation_Delivery_Option_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Product_Permutation_Delivery_Option_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(64) NOT NULL, - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Permutation_Delivery_Option_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/MySQL/1233_tbl_Shop_Discount.sql b/static/MySQL/1233_tbl_Shop_Discount.sql deleted file mode 100644 index 551f2581..00000000 --- a/static/MySQL/1233_tbl_Shop_Discount.sql +++ /dev/null @@ -1,48 +0,0 @@ - --- Discounts - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Discount'; - -CREATE TABLE Shop_Discount ( - id_discount INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - code VARCHAR(50) NOT NULL, - name VARCHAR(200) NOT NULL, - id_product INT NOT NULL, - CONSTRAINT FK_Shop_Discount_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - id_permutation INT, - CONSTRAINT FK_Shop_Discount_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation) - ON UPDATE RESTRICT, - /* - id_delivery_region INT, - CONSTRAINT FK_Shop_Discount_id_delivery_region - FOREIGN KEY (id_delivery_region) - REFERENCES Shop_Delivery_Region(id_region) - ON UPDATE RESTRICT, - id_currency INT, - CONSTRAINT FK_Shop_Discount_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency) - ON UPDATE RESTRICT, - */ - multiplier FLOAT NOT NULL DEFAULT 1 CHECK (multiplier > 0), - subtractor FLOAT NOT NULL DEFAULT 0, - apply_multiplier_first BIT DEFAULT 1, - quantity_min FLOAT NOT NULL DEFAULT 0, - quantity_max FLOAT NOT NULL, - date_start DATETIME NOT NULL, - date_end DATETIME NOT NULL, - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Discount_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/MySQL/1234_tbl_Shop_Discount_Audit.sql b/static/MySQL/1234_tbl_Shop_Discount_Audit.sql deleted file mode 100644 index 96ab2d56..00000000 --- a/static/MySQL/1234_tbl_Shop_Discount_Audit.sql +++ /dev/null @@ -1,23 +0,0 @@ - --- Discount Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Discount_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Discount_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_discount INT NOT NULL, - CONSTRAINT FK_Shop_Discount_Audit_id_discount - FOREIGN KEY (id_discount) - REFERENCES Shop_Discount(id_discount) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Discount_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) - ON UPDATE RESTRICT -); \ No newline at end of file diff --git a/static/MySQL/1236_tbl_Shop_Discount_Region_Currency_Link.sql b/static/MySQL/1236_tbl_Shop_Discount_Region_Currency_Link.sql deleted file mode 100644 index 6cb8d148..00000000 --- a/static/MySQL/1236_tbl_Shop_Discount_Region_Currency_Link.sql +++ /dev/null @@ -1,32 +0,0 @@ - --- Discount Region Currency Link - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Discount_Region_Currency_Link'; - -CREATE TABLE IF NOT EXISTS Shop_Discount_Region_Currency_Link ( - id_link INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_discount INT NOT NULL, - CONSTRAINT FK_Shop_Discount_Region_Currency_Link_id_discount - FOREIGN KEY (id_discount) - REFERENCES Shop_Discount(id_discount) - ON UPDATE RESTRICT, - id_region INT NOT NULL, - CONSTRAINT FK_Shop_Discount_Region_Currency_Link_id_region - FOREIGN KEY (id_region) - REFERENCES Shop_Region(id_region) - ON UPDATE RESTRICT, - id_currency INT NOT NULL, - CONSTRAINT FK_Shop_Discount_Region_Currency_Link_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency) - ON UPDATE RESTRICT, - active BIT NOT NULL DEFAULT 1, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Discount_Region_Currency_Link_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/MySQL/1237_tbl_Shop_Discount_Region_Currency_Link_Audit.sql b/static/MySQL/1237_tbl_Shop_Discount_Region_Currency_Link_Audit.sql deleted file mode 100644 index cf346b49..00000000 --- a/static/MySQL/1237_tbl_Shop_Discount_Region_Currency_Link_Audit.sql +++ /dev/null @@ -1,23 +0,0 @@ - --- Discount Region Currency Link Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Discount_Region_Currency_Link_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Discount_Region_Currency_Link_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_link INT NOT NULL, - CONSTRAINT FK_Shop_Discount_Region_Currency_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Discount_Region_Currency_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Discount_Region_Currency_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) - ON UPDATE RESTRICT -); \ No newline at end of file diff --git a/static/MySQL/1300_tbl_Shop_Permission_Group.sql b/static/MySQL/1300_tbl_Shop_Permission_Group.sql deleted file mode 100644 index cf6e1f1b..00000000 --- a/static/MySQL/1300_tbl_Shop_Permission_Group.sql +++ /dev/null @@ -1,21 +0,0 @@ - --- Permission Groups - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Permission_Group'; - -CREATE TABLE IF NOT EXISTS Shop_Permission_Group ( - id_group INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - code VARCHAR(50), - name VARCHAR(255), - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Permission_Group_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - ON UPDATE RESTRICT -); \ No newline at end of file diff --git a/static/MySQL/1301_tbl_Shop_Permission_Group_Audit.sql b/static/MySQL/1301_tbl_Shop_Permission_Group_Audit.sql deleted file mode 100644 index 7f3cab75..00000000 --- a/static/MySQL/1301_tbl_Shop_Permission_Group_Audit.sql +++ /dev/null @@ -1,23 +0,0 @@ - --- Permission Group Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Permission_Group_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Permission_Group_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_group INT NOT NULL, - CONSTRAINT FK_Shop_Permission_Group_Audit_id_group - FOREIGN KEY (id_group) - REFERENCES Shop_Permission_Group(id_group) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Permission_Group_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - ON UPDATE RESTRICT -); \ No newline at end of file diff --git a/static/MySQL/1303_tbl_Shop_Permission.sql b/static/MySQL/1303_tbl_Shop_Permission.sql deleted file mode 100644 index 93b55389..00000000 --- a/static/MySQL/1303_tbl_Shop_Permission.sql +++ /dev/null @@ -1,29 +0,0 @@ - --- Permissions - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Permission'; - -CREATE TABLE IF NOT EXISTS Shop_Permission ( - id_permission INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - code VARCHAR(50), - name VARCHAR(255), - id_permission_group INT NOT NULL, - CONSTRAINT FK_Shop_Permission_id_permission_group - FOREIGN KEY (id_permission_group) - REFERENCES Shop_Permission_Group(id_group) - ON UPDATE RESTRICT, - id_access_level_required INT NOT NULL, - CONSTRAINT FK_Shop_Permission_id_access_level_required - FOREIGN KEY (id_access_level_required) - REFERENCES Shop_Access_Level(id_access_level), - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Permission_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/MySQL/1304_tbl_Shop_Permission_Audit.sql b/static/MySQL/1304_tbl_Shop_Permission_Audit.sql deleted file mode 100644 index 9c889b03..00000000 --- a/static/MySQL/1304_tbl_Shop_Permission_Audit.sql +++ /dev/null @@ -1,23 +0,0 @@ - --- Permission Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Permission_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Permission_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_permission INT NOT NULL, - CONSTRAINT FK_Shop_Permission_Audit_id_permission - FOREIGN KEY (id_permission) - REFERENCES Shop_Permission(id_permission) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Permission_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - ON UPDATE RESTRICT -); \ No newline at end of file diff --git a/static/MySQL/1306_tbl_Shop_Role.sql b/static/MySQL/1306_tbl_Shop_Role.sql deleted file mode 100644 index 389547c8..00000000 --- a/static/MySQL/1306_tbl_Shop_Role.sql +++ /dev/null @@ -1,20 +0,0 @@ - --- Roles - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Role'; - -CREATE TABLE IF NOT EXISTS Shop_Role ( - id_role INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - code VARCHAR(50), - name VARCHAR(255), - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Role_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/MySQL/1307_tbl_Shop_Role_Audit.sql b/static/MySQL/1307_tbl_Shop_Role_Audit.sql deleted file mode 100644 index da46da4a..00000000 --- a/static/MySQL/1307_tbl_Shop_Role_Audit.sql +++ /dev/null @@ -1,23 +0,0 @@ - --- Role Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Role_Audit'; - -CREATE TABLE Shop_Role_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_role INT NOT NULL, - CONSTRAINT FK_Shop_Role_Audit_id_role - FOREIGN KEY (id_role) - REFERENCES Shop_Role(id_role) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Role_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - ON UPDATE RESTRICT -); \ No newline at end of file diff --git a/static/MySQL/1309_tbl_Shop_Role_Permission_Link.sql b/static/MySQL/1309_tbl_Shop_Role_Permission_Link.sql deleted file mode 100644 index 242aaef5..00000000 --- a/static/MySQL/1309_tbl_Shop_Role_Permission_Link.sql +++ /dev/null @@ -1,31 +0,0 @@ - --- Role Permission link - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Role_Permission_Link'; - -CREATE TABLE IF NOT EXISTS Shop_Role_Permission_Link ( - id_link INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_role INT, - CONSTRAINT FK_Shop_Role_Permission_Link_id_role - FOREIGN KEY (id_role) - REFERENCES Shop_Role(id_role) - ON UPDATE RESTRICT, - id_permission INT, - CONSTRAINT FK_Shop_Role_Permission_Link_id_permission - FOREIGN KEY (id_permission) - REFERENCES Shop_Permission(id_permission) - ON UPDATE RESTRICT, - id_access_level INT, - CONSTRAINT FK_Shop_Role_Permission_Link_id_access_level - FOREIGN KEY (id_access_level) - REFERENCES Shop_Access_Level(id_access_level), - active BIT NOT NULL DEFAULT 1, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Role_Permission_Link_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/MySQL/1310_tbl_Shop_Role_Permission_Link_Audit.sql b/static/MySQL/1310_tbl_Shop_Role_Permission_Link_Audit.sql deleted file mode 100644 index f1b2e6e0..00000000 --- a/static/MySQL/1310_tbl_Shop_Role_Permission_Link_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Role Permission link Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Role_Permission_Link_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Role_Permission_Link_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_link INT NOT NULL, - CONSTRAINT FK_Shop_Role_Permission_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Role_Permission_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Role_Permission_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/MySQL/1312_tbl_Shop_User.sql b/static/MySQL/1312_tbl_Shop_User.sql deleted file mode 100644 index b567d95f..00000000 --- a/static/MySQL/1312_tbl_Shop_User.sql +++ /dev/null @@ -1,26 +0,0 @@ - --- Users - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User'; - -CREATE TABLE IF NOT EXISTS Shop_User ( - id_user INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_user_auth0 VARCHAR(200) NOT NULL, - firstname VARCHAR(255) NULL, - surname VARCHAR(255) NULL, - email VARCHAR(254) NULL, - is_email_verified BIT NOT NULL DEFAULT 0, - is_super_user BIT NOT NULL DEFAULT 0, - id_currency_default INT NULL, - id_region_default INT NULL, - is_included_VAT_default BIT NOT NULL DEFAULT 1, - active BIT NOT NULL DEFAULT 1, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_User_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); diff --git a/static/MySQL/1313_tbl_Shop_User_Audit.sql b/static/MySQL/1313_tbl_Shop_User_Audit.sql deleted file mode 100644 index da7125b0..00000000 --- a/static/MySQL/1313_tbl_Shop_User_Audit.sql +++ /dev/null @@ -1,23 +0,0 @@ - --- User Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_User_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_user INT NOT NULL, - CONSTRAINT FK_Shop_User_Audit_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_User_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - ON UPDATE RESTRICT -); \ No newline at end of file diff --git a/static/MySQL/1314_tbl_Shop_User_Temp.sql b/static/MySQL/1314_tbl_Shop_User_Temp.sql deleted file mode 100644 index 0c692fae..00000000 --- a/static/MySQL/1314_tbl_Shop_User_Temp.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Users Temp - --- DROP TABLE IF EXISTS Shop_User_Temp; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_User_Temp ( - id_temp INT NOT NULL AUTO_INCREMENT PRIMARY KEY - , id_user INT NOT NULL - , id_user_auth0 VARCHAR(200) NOT NULL - , firstname VARCHAR(255) - , surname VARCHAR(255) - , email VARCHAR(254) - , is_email_verified BIT - , is_super_user BIT - , id_currency_default INT - , id_region_default INT - , is_included_VAT_default BIT - , active BIT - , guid BINARY(36) NOT NULL -); diff --git a/static/MySQL/1315_tbl_Shop_User_Role_Link.sql b/static/MySQL/1315_tbl_Shop_User_Role_Link.sql deleted file mode 100644 index 07d80f26..00000000 --- a/static/MySQL/1315_tbl_Shop_User_Role_Link.sql +++ /dev/null @@ -1,26 +0,0 @@ - --- User Role link - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Role_Link'; - -CREATE TABLE IF NOT EXISTS Shop_User_Role_Link ( - id_link INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_user INT NOT NULL, - CONSTRAINT FK_Shop_User_Role_Link_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user) - ON UPDATE RESTRICT, - id_role INT NOT NULL, - CONSTRAINT FK_Shop_User_Role_Link_id_role - FOREIGN KEY (id_role) - REFERENCES Shop_Role(id_role), - active BIT NOT NULL DEFAULT 1, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_User_Role_Link_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/MySQL/1316_tbl_Shop_User_Role_Link_Audit.sql b/static/MySQL/1316_tbl_Shop_User_Role_Link_Audit.sql deleted file mode 100644 index 461827aa..00000000 --- a/static/MySQL/1316_tbl_Shop_User_Role_Link_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- User Role Link Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Role_Link_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_User_Role_Link_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_link INT NOT NULL, - CONSTRAINT FK_Shop_User_Role_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_User_Role_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_User_Role_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); diff --git a/static/MySQL/1318_tbl_Shop_User_Address.sql b/static/MySQL/1318_tbl_Shop_User_Address.sql deleted file mode 100644 index 2b28b309..00000000 --- a/static/MySQL/1318_tbl_Shop_User_Address.sql +++ /dev/null @@ -1,29 +0,0 @@ - --- User Addresses - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Address'; - -CREATE TABLE Shop_User_Address ( - id_user_address INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_user INT NOT NULL, - CONSTRAINT FK_Shop_Address_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user) - ON UPDATE RESTRICT, - -- region VARCHAR(100) NOT NULL, - id_region INT NOT NULL, - name_full VARCHAR(255) NOT NULL, - phone_number VARCHAR(20) NOT NULL, - postcode VARCHAR(20) NOT NULL, - address_line_1 VARCHAR(256) NOT NULL, - address_line_2 VARCHAR(256) NOT NULL, - city VARCHAR(256) NOT NULL, - county VARCHAR(256) NOT NULL, - active BIT NOT NULL DEFAULT 1, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_User_Address_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/MySQL/1319_tbl_Shop_User_Address_Audit.sql b/static/MySQL/1319_tbl_Shop_User_Address_Audit.sql deleted file mode 100644 index 822593b8..00000000 --- a/static/MySQL/1319_tbl_Shop_User_Address_Audit.sql +++ /dev/null @@ -1,21 +0,0 @@ - --- Address Audits - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Address_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_User_Address_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_user_address INT NOT NULL, - CONSTRAINT FK_Shop_User_Address_Audit_id_address - FOREIGN KEY (id_user_address) - REFERENCES Shop_User_Address(id_user_address) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_User_Address_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - ON UPDATE RESTRICT -); \ No newline at end of file diff --git a/static/MySQL/1321_tbl_Shop_User_Basket.sql b/static/MySQL/1321_tbl_Shop_User_Basket.sql deleted file mode 100644 index 233be405..00000000 --- a/static/MySQL/1321_tbl_Shop_User_Basket.sql +++ /dev/null @@ -1,39 +0,0 @@ - --- User Basket (Product Link) - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Basket'; - -CREATE TABLE IF NOT EXISTS Shop_User_Basket ( - id_item INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_user INT NOT NULL, - CONSTRAINT FK_Shop_User_Basket_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user) - ON UPDATE RESTRICT, - id_product INT NOT NULL, - CONSTRAINT FK_Shop_User_Basket_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product) - ON UPDATE RESTRICT, - id_permutation INT, - CONSTRAINT FK_Shop_User_Basket_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation) - ON UPDATE RESTRICT, - quantity INT NOT NULL, - active BIT NOT NULL DEFAULT 1, - created_on DATETIME, - created_by INT, - id_change_set_user INT, - CONSTRAINT FK_Shop_User_Basket_id_change_set_user - FOREIGN KEY (id_change_set_user) - REFERENCES Shop_User_Change_Set(id_change_set) - /* - id_change_set_product INT, - CONSTRAINT FK_Shop_User_Basket_id_change_set_product - FOREIGN KEY (id_change_set_product) - REFERENCES Shop_Product_Change_Set(id_change_set) - */ -); diff --git a/static/MySQL/1322_tbl_Shop_User_Basket_Audit.sql b/static/MySQL/1322_tbl_Shop_User_Basket_Audit.sql deleted file mode 100644 index d9877ae9..00000000 --- a/static/MySQL/1322_tbl_Shop_User_Basket_Audit.sql +++ /dev/null @@ -1,27 +0,0 @@ - --- Product Basket Audits - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Basket_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_User_Basket_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_item INT NOT NULL, - CONSTRAINT FK_Shop_User_Basket_Audit_id_link - FOREIGN KEY (id_item) - REFERENCES Shop_User_Basket(id_item) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set_user INT, - CONSTRAINT FK_Shop_User_Basket_Audit_id_change_set_user - FOREIGN KEY (id_change_set_user) - REFERENCES Shop_User_Change_Set(id_change_set) - /* - id_change_set_product INT, - CONSTRAINT FK_Shop_User_Basket_Audit_id_change_set_product - FOREIGN KEY (id_change_set_product) - REFERENCES Shop_Product_Change_Set(id_change_set) - */ -); diff --git a/static/MySQL/1397_tbl_Shop_Order_Status.sql b/static/MySQL/1397_tbl_Shop_Order_Status.sql deleted file mode 100644 index 3d8488a1..00000000 --- a/static/MySQL/1397_tbl_Shop_Order_Status.sql +++ /dev/null @@ -1,21 +0,0 @@ - --- User Order Types - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Order_Status'; - -CREATE TABLE IF NOT EXISTS Shop_User_Order_Status ( - id_status INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - code VARCHAR(50), - name VARCHAR(255), - name_plural VARCHAR(256), - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_User_Order_Status_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); diff --git a/static/MySQL/1398_tbl_Shop_Order_Status_Audit.sql b/static/MySQL/1398_tbl_Shop_Order_Status_Audit.sql deleted file mode 100644 index 82acb321..00000000 --- a/static/MySQL/1398_tbl_Shop_Order_Status_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Order Type Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Order_Status_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_User_Order_Status_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_status INT NOT NULL, - CONSTRAINT FK_Shop_User_Order_Status_Audit_id_status - FOREIGN KEY (id_status) - REFERENCES Shop_User_Order_Status(id_status) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_User_Order_Status_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/MySQL/1400_tbl_Shop_Supplier.sql b/static/MySQL/1400_tbl_Shop_Supplier.sql deleted file mode 100644 index c2d2d9e8..00000000 --- a/static/MySQL/1400_tbl_Shop_Supplier.sql +++ /dev/null @@ -1,33 +0,0 @@ - --- Supplier - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Supplier'; - -CREATE TABLE IF NOT EXISTS Shop_Supplier ( - id_supplier INT NOT NULL AUTO_INCREMENT PRIMARY KEY - , name_company VARCHAR(255) NOT NULL - , name_contact VARCHAR(255) NULL - , department_contact VARCHAR(255) NULL - /* - id_address INT NOT NULL, - CONSTRAINT FK_Shop_Supplier_id_address - FOREIGN KEY (id_address) - REFERENCES Shop_Address(id_address), - */ - , phone_number VARCHAR(50) NULL - , fax VARCHAR(50) NULL - , email VARCHAR(255) NOT NULL - , website VARCHAR(255) NULL - , id_currency INT NOT NULL - , CONSTRAINT FK_Shop_Supplier_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency) - , active BIT NOT NULL DEFAULT 1 - , created_on DATETIME - , created_by INT - , id_change_set INT - , CONSTRAINT FK_Shop_Supplier_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - , id_supplier_temp INT NOT NULL -); diff --git a/static/MySQL/1401_tbl_Shop_Supplier_Audit.sql b/static/MySQL/1401_tbl_Shop_Supplier_Audit.sql deleted file mode 100644 index b04989ff..00000000 --- a/static/MySQL/1401_tbl_Shop_Supplier_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Supplier Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Supplier_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Supplier_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_supplier INT NOT NULL, - CONSTRAINT FK_Shop_Supplier_Audit_id_supplier - FOREIGN KEY (id_supplier) - REFERENCES Shop_Supplier(id_supplier) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Supplier_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); diff --git a/static/MySQL/1402_tbl_Shop_Supplier_Temp.sql b/static/MySQL/1402_tbl_Shop_Supplier_Temp.sql deleted file mode 100644 index 47c2ae0f..00000000 --- a/static/MySQL/1402_tbl_Shop_Supplier_Temp.sql +++ /dev/null @@ -1,20 +0,0 @@ - --- Supplier Staging - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Supplier_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Supplier_Temp ( - id_temp INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_supplier INT NOT NULL, - name_company VARCHAR(255) NOT NULL, - name_contact VARCHAR(255) NULL, - department_contact VARCHAR(255) NULL, - -- id_address INT NOT NULL, - phone_number VARCHAR(50) NULL, - fax VARCHAR(50) NULL, - email VARCHAR(255) NOT NULL, - website VARCHAR(255) NULL, - id_currency INT NOT NULL, - active BIT NULL, - GUID BINARY(36) NOT NULL -); diff --git a/static/MySQL/1403_tbl_Shop_Supplier_Address.sql b/static/MySQL/1403_tbl_Shop_Supplier_Address.sql deleted file mode 100644 index 9ae02145..00000000 --- a/static/MySQL/1403_tbl_Shop_Supplier_Address.sql +++ /dev/null @@ -1,29 +0,0 @@ - --- Supplier Addresses - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Supplier_Address'; - -CREATE TABLE Shop_Supplier_Address ( - id_address INT NOT NULL AUTO_INCREMENT PRIMARY KEY - , id_supplier INT NOT NULL - , CONSTRAINT FK_Shop_Supplier_Address_id_supplier - FOREIGN KEY (id_supplier) - REFERENCES partsltd_prod.Shop_Supplier(id_supplier) - ON UPDATE RESTRICT - , id_region INT NOT NULL - , CONSTRAINT FK_Shop_Supplier_Address_id_region - FOREIGN KEY (id_region) - REFERENCES partsltd_prod.Shop_Region(id_region) - , postcode VARCHAR(20) NOT NULL - , address_line_1 VARCHAR(256) NOT NULL - , address_line_2 VARCHAR(256) NOT NULL - , city VARCHAR(256) NOT NULL - , county VARCHAR(256) NOT NULL - , active BIT NOT NULL DEFAULT 1 - , created_on DATETIME - , created_by INT - , id_change_set INT - , CONSTRAINT FK_Shop_Supplier_Address_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES partsltd_prod.Shop_User_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/MySQL/1404_tbl_Shop_Supplier_Address_Audit.sql b/static/MySQL/1404_tbl_Shop_Supplier_Address_Audit.sql deleted file mode 100644 index 22a1e15a..00000000 --- a/static/MySQL/1404_tbl_Shop_Supplier_Address_Audit.sql +++ /dev/null @@ -1,21 +0,0 @@ - --- Supplier Address Audits - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Supplier_Address_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Supplier_Address_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_address INT NOT NULL, - CONSTRAINT FK_Shop_Supplier_Address_Audit_id_address - FOREIGN KEY (id_address) - REFERENCES Shop_Supplier_Address(id_address) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Supplier_Address_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - ON UPDATE RESTRICT -); \ No newline at end of file diff --git a/static/MySQL/1405_tbl_Shop_Supplier_Address_Temp.sql b/static/MySQL/1405_tbl_Shop_Supplier_Address_Temp.sql deleted file mode 100644 index 0f45f75d..00000000 --- a/static/MySQL/1405_tbl_Shop_Supplier_Address_Temp.sql +++ /dev/null @@ -1,17 +0,0 @@ - --- Supplier Addresses Staging - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Supplier_Address_Temp'; - -CREATE TABLE Shop_Supplier_Address_Temp ( - id_address INT NOT NULL AUTO_INCREMENT PRIMARY KEY - , id_supplier INT NOT NULL - , id_region INT NOT NULL - , postcode VARCHAR(20) NOT NULL - , address_line_1 VARCHAR(256) NOT NULL - , address_line_2 VARCHAR(256) NOT NULL - , city VARCHAR(256) NOT NULL - , county VARCHAR(256) NOT NULL - , active BIT NOT NULL DEFAULT 1 - , GUID BINARY(36) NOT NULL -); \ No newline at end of file diff --git a/static/MySQL/1409_tbl_Shop_Supplier_Purchase_Order.sql b/static/MySQL/1409_tbl_Shop_Supplier_Purchase_Order.sql deleted file mode 100644 index d53ad4a0..00000000 --- a/static/MySQL/1409_tbl_Shop_Supplier_Purchase_Order.sql +++ /dev/null @@ -1,43 +0,0 @@ - --- Supplier Purchase Order - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Supplier_Purchase_Order'; - -CREATE TABLE IF NOT EXISTS Shop_Supplier_Purchase_Order ( - id_order INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_order_temp INT NULL, - id_supplier_ordered INT NOT NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_id_supplier_ordered - FOREIGN KEY (id_supplier_ordered) - REFERENCES Shop_Supplier(id_supplier), - /* - id_supplier_fulfilled INT NOT NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_id_supplier_fulfilled - FOREIGN KEY (id_supplier_fulfilled) - REFERENCES Shop_Supplier(id_supplier), - */ - id_currency_cost INT NOT NULL, - cost_total_local_VAT_excl FLOAT NOT NULL, - cost_total_local_VAT_incl FLOAT NOT NULL, - /* - latency_delivery INT NOT NULL, - quantity_ordered FLOAT NOT NULL, - id_unit_quantity INT NOT NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit), - -- quantity_received INT NULL, - display_order INT NOT NULL, - */ - active BIT NOT NULL DEFAULT 1, - created_on DATETIME, - created_by INT, - updated_last_on DATETIME NULL, - created_last_by VARCHAR(100) NULL, - id_change_set INT NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); diff --git a/static/MySQL/1410_tbl_Shop_Supplier_Purchase_Order_Audit.sql b/static/MySQL/1410_tbl_Shop_Supplier_Purchase_Order_Audit.sql deleted file mode 100644 index 7dab3780..00000000 --- a/static/MySQL/1410_tbl_Shop_Supplier_Purchase_Order_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Supplier Purchase Order Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Supplier_Purchase_Order_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Supplier_Purchase_Order_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_order INT NOT NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_Audit_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Supplier_Purchase_Order(id_order) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); diff --git a/static/MySQL/1411_tbl_Shop_Supplier_Purchase_Order_Temp.sql b/static/MySQL/1411_tbl_Shop_Supplier_Purchase_Order_Temp.sql deleted file mode 100644 index 604933bb..00000000 --- a/static/MySQL/1411_tbl_Shop_Supplier_Purchase_Order_Temp.sql +++ /dev/null @@ -1,15 +0,0 @@ - --- Supplier Purchase Order Staging - -DROP TABLE IF EXISTS Shop_Supplier_Purchase_Order_Temp; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Supplier_Purchase_Order_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Supplier_Purchase_Order_Temp ( - id_temp INT NOT NULL AUTO_INCREMENT PRIMARY KEY - , id_order INT NOT NULL - , id_supplier_ordered INT NOT NULL - , id_currency_cost INT NOT NULL - , active BIT NULL - , GUID BINARY(36) NOT NULL -); diff --git a/static/MySQL/1412_tbl_Shop_Manufacturing_Purchase_Order.sql b/static/MySQL/1412_tbl_Shop_Manufacturing_Purchase_Order.sql deleted file mode 100644 index 8f7912b5..00000000 --- a/static/MySQL/1412_tbl_Shop_Manufacturing_Purchase_Order.sql +++ /dev/null @@ -1,40 +0,0 @@ - --- Manufacturing Purchase Order - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Manufacturing_Purchase_Order'; - -CREATE TABLE IF NOT EXISTS Shop_Manufacturing_Purchase_Order ( - id_order INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_order_temp INT NULL, - /* - cost_total_local FLOAT NOT NULL, - id_currency_cost INT NOT NULL, - */ - id_currency INT NOT NULL, - CONSTRAINT FK_Manufacturing_Purchase_Order_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency), - cost_total_local_VAT_excl FLOAT NULL, - cost_total_local_VAT_incl FLOAT NULL, - price_total_local_VAT_excl FLOAT NULL, - price_total_local_VAT_incl FLOAT NULL, - /* - latency_delivery INT NOT NULL, - quantity_ordered FLOAT NOT NULL, - id_unit_quantity INT NOT NULL, - CONSTRAINT FK_Shop_Manufacturing_Purchase_Order_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit), - quantity_received INT NULL, - display_order INT NOT NULL, - */ - active BIT NOT NULL DEFAULT 1, - created_on DATETIME, - created_by INT, - updated_last_on DATETIME NULL, - created_last_by VARCHAR(100) NULL, - id_change_set INT NULL, - CONSTRAINT FK_Shop_Manufacturing_Purchase_Order_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); diff --git a/static/MySQL/1413_tbl_Shop_Manufacturing_Purchase_Order_Audit.sql b/static/MySQL/1413_tbl_Shop_Manufacturing_Purchase_Order_Audit.sql deleted file mode 100644 index c5692f41..00000000 --- a/static/MySQL/1413_tbl_Shop_Manufacturing_Purchase_Order_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Manufacturing Purchase Order Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Manufacturing_Purchase_Order_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Manufacturing_Purchase_Order_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_order INT NOT NULL, - CONSTRAINT FK_Shop_Manufacturing_Purchase_Order_Audit_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Manufacturing_Purchase_Order(id_order) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Manufacturing_Purchase_Order_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); diff --git a/static/MySQL/1414_tbl_Shop_Manufacturing_Purchase_Order_Temp.sql b/static/MySQL/1414_tbl_Shop_Manufacturing_Purchase_Order_Temp.sql deleted file mode 100644 index db97fcd8..00000000 --- a/static/MySQL/1414_tbl_Shop_Manufacturing_Purchase_Order_Temp.sql +++ /dev/null @@ -1,31 +0,0 @@ - --- Manufacturing Purchase Order Temp - --- DROP TABLE Shop_Manufacturing_Purchase_Order_Temp - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Manufacturing_Purchase_Order_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Manufacturing_Purchase_Order_Temp ( - id_temp INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_order INT NOT NULL, - /* - cost_total_local FLOAT NOT NULL, - */ - id_currency INT NOT NULL, - cost_total_local_VAT_excl FLOAT NULL, - cost_total_local_VAT_incl FLOAT NULL, - price_total_local_VAT_excl FLOAT NULL, - price_total_local_VAT_incl FLOAT NULL, - /* - latency_delivery INT NOT NULL, - quantity_ordered FLOAT NOT NULL, - id_unit_quantity INT NOT NULL, - CONSTRAINT FK_Shop_Manufacturing_Purchase_Order_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit), - quantity_received INT NULL, - display_order INT NOT NULL, - */ - active BIT NOT NULL DEFAULT 1, - GUID BINARY(36) NOT NULL -); diff --git a/static/MySQL/1415_tbl_Shop_Customer.sql b/static/MySQL/1415_tbl_Shop_Customer.sql deleted file mode 100644 index d64e901c..00000000 --- a/static/MySQL/1415_tbl_Shop_Customer.sql +++ /dev/null @@ -1,29 +0,0 @@ --- Customer - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Customer'; - -CREATE TABLE IF NOT EXISTS Shop_Customer ( - id_customer INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - name_company VARCHAR(255) NOT NULL, - name_contact VARCHAR(255) NULL, - department_contact VARCHAR(255) NULL, - id_address INT NOT NULL, - CONSTRAINT FK_Shop_Customer_id_address - FOREIGN KEY (id_address) - REFERENCES Shop_Address(id_address), - phone_number VARCHAR(50) NULL, - email VARCHAR(255) NOT NULL, - id_currency INT NOT NULL, - CONSTRAINT FK_Shop_Customer_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency), - active BIT NOT NULL DEFAULT 1, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Customer_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); diff --git a/static/MySQL/1416_tbl_Shop_Customer_Audit.sql b/static/MySQL/1416_tbl_Shop_Customer_Audit.sql deleted file mode 100644 index 018437b0..00000000 --- a/static/MySQL/1416_tbl_Shop_Customer_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Customer Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Customer_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Customer_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_customer INT NOT NULL, - CONSTRAINT FK_Shop_Customer_Audit_id_customer - FOREIGN KEY (id_customer) - REFERENCES Shop_Customer(id_customer) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Customer_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); diff --git a/static/MySQL/1418_tbl_Shop_Customer_Sales_Order.sql b/static/MySQL/1418_tbl_Shop_Customer_Sales_Order.sql deleted file mode 100644 index e71a4b21..00000000 --- a/static/MySQL/1418_tbl_Shop_Customer_Sales_Order.sql +++ /dev/null @@ -1,35 +0,0 @@ - --- Customer Sales Purchase Order - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Customer_Sales_Order'; - -CREATE TABLE IF NOT EXISTS Shop_Customer_Sales_Order ( - id_order INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_customer INT NOT NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_id_customer - FOREIGN KEY (id_customer) - REFERENCES Shop_Customer(id_customer), - price_total_local FLOAT NOT NULL, - id_currency_price INT NOT NULL, - /* - latency_delivery INT NOT NULL, - quantity_ordered FLOAT NOT NULL, - id_unit_quantity INT NOT NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit), - quantity_received INT NULL, - display_order INT NOT NULL, - */ - active BIT NOT NULL DEFAULT 1, - created_on DATETIME, - created_by INT, - updated_last_on DATETIME NULL, - created_last_by VARCHAR(100) NULL, - id_change_set INT NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); diff --git a/static/MySQL/1419_tbl_Shop_Customer_Sales_Order_Audit.sql b/static/MySQL/1419_tbl_Shop_Customer_Sales_Order_Audit.sql deleted file mode 100644 index 8af149c2..00000000 --- a/static/MySQL/1419_tbl_Shop_Customer_Sales_Order_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Customer Sales Order Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Customer_Sales_Order_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Customer_Sales_Order_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_order INT NOT NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_Audit_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Customer_Sales_Order(id_order) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); diff --git a/static/MySQL/1421_tbl_Shop_Stock_Item.sql b/static/MySQL/1421_tbl_Shop_Stock_Item.sql deleted file mode 100644 index 57693684..00000000 --- a/static/MySQL/1421_tbl_Shop_Stock_Item.sql +++ /dev/null @@ -1,51 +0,0 @@ - --- Stock Stock Item - --- DROP TABLE IF EXISTS Shop_Stock_Item_Audit; --- DROP TABLE IF EXISTS Shop_Stock_Item; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Stock_Item'; - -CREATE TABLE IF NOT EXISTS Shop_Stock_Item ( - id_stock INT NOT NULL AUTO_INCREMENT PRIMARY KEY - , id_permutation INT NOT NULL - , CONSTRAINT FK_Shop_Stock_Item_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES partsltd_prod.Shop_Product_Permutation(id_permutation) - , id_supplier_purchase_order INT NULL - , CONSTRAINT FK_Shop_Stock_Item_id_supplier_purchase_order - FOREIGN KEY (id_supplier_purchase_order) - REFERENCES partsltd_prod.Shop_Supplier_Purchase_Order(id_order) - , id_manufacturing_purchase_order INT NULL - , CONSTRAINT FK_Shop_Stock_Item_id_manufacturing_purchase_order - FOREIGN KEY (id_manufacturing_purchase_order) - REFERENCES partsltd_prod.Shop_Manufacturing_Purchase_Order(id_order) - , id_customer_sales_order INT NULL - , CONSTRAINT FK_Shop_Stock_Item_id_customer_sales_order - FOREIGN KEY (id_customer_sales_order) - REFERENCES partsltd_prod.Shop_Customer_Sales_Order(id_order) - , date_purchased DATETIME NOT NULL - , date_received DATETIME - , id_location_storage INT NOT NULL - , CONSTRAINT FK_Shop_Stock_Item_id_location_storage - FOREIGN KEY (id_location_storage) - REFERENCES partsltd_prod.Shop_Storage_Location(id_location) - , id_currency_cost INT NOT NULL - , CONSTRAINT FK_Shop_Stock_Item_id_currency - FOREIGN KEY (id_currency_cost) - REFERENCES partsltd_prod.Shop_Currency(id_currency) - , cost_local_VAT_incl FLOAT - , cost_local_VAT_excl FLOAT - , is_sealed BIT NOT NULL DEFAULT 1 - , date_unsealed DATETIME - , date_expiration DATETIME NOT NULL - , is_consumed BIT NOT NULL DEFAULT 0 - , date_consumed DATETIME - , active BIT NOT NULL DEFAULT 1 - , created_on DATETIME - , created_by INT - , id_change_set INT - , CONSTRAINT FK_Shop_Stock_Item_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES partsltd_prod.Shop_Product_Change_Set(id_change_set) -); diff --git a/static/MySQL/1422_tbl_Shop_Stock_Item_Audit.sql b/static/MySQL/1422_tbl_Shop_Stock_Item_Audit.sql deleted file mode 100644 index 6c0fa456..00000000 --- a/static/MySQL/1422_tbl_Shop_Stock_Item_Audit.sql +++ /dev/null @@ -1,23 +0,0 @@ - --- Stock Item Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Stock_Item_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Stock_Item_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_stock INT NOT NULL, - CONSTRAINT FK_Shop_Stock_Item_Audit_id_stock - FOREIGN KEY (id_stock) - REFERENCES Shop_Stock_Item(id_stock) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Stock_Item_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) - ON UPDATE RESTRICT -); diff --git a/static/MySQL/1423_tbl_Shop_Stock_Item_Temp.sql b/static/MySQL/1423_tbl_Shop_Stock_Item_Temp.sql deleted file mode 100644 index 182c0523..00000000 --- a/static/MySQL/1423_tbl_Shop_Stock_Item_Temp.sql +++ /dev/null @@ -1,27 +0,0 @@ - --- Stock Stock Item Temp - -DROP TABLE IF EXISTS Shop_Stock_Item_Temp; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Stock_Item_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Stock_Item_Temp ( - id_stock INT NULL - -- , id_category INT NULL - , id_product INT NOT NULL - , id_permutation INT NULL - , id_pairs_variations VARCHAR(4000) NULL - , date_purchased DATETIME NOT NULL - , date_received DATETIME NULL - , id_location_storage INT NOT NULL - , id_currency_cost INT NOT NULL - , cost_local_VAT_incl FLOAT NOT NULL - , cost_local_VAT_excl FLOAT NOT NULL - , is_sealed BIT NOT NULL - , date_unsealed DATETIME NULL - , date_expiration DATETIME NULL - , is_consumed BIT NOT NULL - , date_consumed DATETIME NULL - , active BIT NOT NULL - , guid BINARY(36) NOT NULL -); diff --git a/static/MySQL/1424_tbl_Shop_Supplier_Purchase_Order_Product_Link.sql b/static/MySQL/1424_tbl_Shop_Supplier_Purchase_Order_Product_Link.sql deleted file mode 100644 index 71f96542..00000000 --- a/static/MySQL/1424_tbl_Shop_Supplier_Purchase_Order_Product_Link.sql +++ /dev/null @@ -1,40 +0,0 @@ - --- Supplier Purchase Order Product Link - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Supplier_Purchase_Order_Product_Link'; - -CREATE TABLE IF NOT EXISTS Shop_Supplier_Purchase_Order_Product_Link ( - id_link INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_order INT NOT NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_Product_Link_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Supplier_Purchase_Order(id_order), - id_permutation INT NOT NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_Product_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - -- id_currency_cost INT NOT NULL, - id_unit_quantity INT NOT NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_Product_Link_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - quantity_ordered FLOAT NOT NULL, - quantity_received FLOAT NULL, - latency_delivery_days INT NOT NULL, - display_order INT NOT NULL, - active BIT NOT NULL, - cost_total_local_VAT_excl FLOAT NOT NULL, - cost_total_local_VAT_incl FLOAT NOT NULL, - cost_unit_local_VAT_excl FLOAT NOT NULL, - cost_unit_local_VAT_incl FLOAT NOT NULL, - created_on DATETIME, - created_by INT, - updated_last_on DATETIME NULL, - created_last_by VARCHAR(100) NULL, - id_change_set INT NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_Product_Link_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); diff --git a/static/MySQL/1425_tbl_Shop_Supplier_Purchase_Order_Product_Link_Audit.sql b/static/MySQL/1425_tbl_Shop_Supplier_Purchase_Order_Product_Link_Audit.sql deleted file mode 100644 index 6e1b2c23..00000000 --- a/static/MySQL/1425_tbl_Shop_Supplier_Purchase_Order_Product_Link_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Supplier Purchase Order Product Link Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Supplier_Purchase_Order_Product_Link_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Supplier_Purchase_Order_Product_Link_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_link INT NOT NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_Product_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Supplier_Purchase_Order_Product_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_Product_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); diff --git a/static/MySQL/1426_tbl_Shop_Supplier_Purchase_Order_Product_Link_Temp.sql b/static/MySQL/1426_tbl_Shop_Supplier_Purchase_Order_Product_Link_Temp.sql deleted file mode 100644 index 7e7478a4..00000000 --- a/static/MySQL/1426_tbl_Shop_Supplier_Purchase_Order_Product_Link_Temp.sql +++ /dev/null @@ -1,26 +0,0 @@ - --- Supplier Purchase Order Product Link Temp - - - --- drop table Shop_Supplier_Purchase_Order_Product_Link_Temp; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Supplier_Purchase_Order_Product_Link_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Supplier_Purchase_Order_Product_Link_Temp ( - id_temp INT NOT NULL AUTO_INCREMENT PRIMARY KEY - , id_link INT NOT NULL - , id_order INT NOT NULL - , id_product INT NULL - , id_permutation INT NULL - , csv_list_variations VARCHAR(4000) NULL - , id_unit_quantity INT NOT NULL - , quantity_ordered FLOAT NOT NULL - , quantity_received FLOAT NULL - , latency_delivery_days INT NOT NULL - , display_order INT NOT NULL - , active BIT NOT NULL - , cost_total_local_VAT_excl FLOAT NOT NULL - , cost_total_local_VAT_incl FLOAT NOT NULL - , GUID BINARY(36) NOT NULL -); diff --git a/static/MySQL/1427_tbl_Shop_Manufacturing_Purchase_Order_Product_Link.sql b/static/MySQL/1427_tbl_Shop_Manufacturing_Purchase_Order_Product_Link.sql deleted file mode 100644 index 496319e1..00000000 --- a/static/MySQL/1427_tbl_Shop_Manufacturing_Purchase_Order_Product_Link.sql +++ /dev/null @@ -1,44 +0,0 @@ - --- Manufacturing Purchase Order Product Link - --- DROP TABLE partsltd_prod.Shop_Manufacturing_Purchase_Order_Product_Link_Audit --- DROP TABLE partsltd_prod.Shop_Manufacturing_Purchase_Order_Product_Link - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Manufacturing_Purchase_Order_Product_Link'; - -CREATE TABLE IF NOT EXISTS Shop_Manufacturing_Purchase_Order_Product_Link ( - id_link INT NOT NULL AUTO_INCREMENT PRIMARY KEY - , id_order INT NOT NULL - , CONSTRAINT FK_Manufacturing_Purchase_Order_Product_Link_id_order - FOREIGN KEY (id_order) - REFERENCES partsltd_prod.Shop_Manufacturing_Purchase_Order(id_order) - , id_permutation INT NOT NULL - , CONSTRAINT FK_Manufacturing_Purchase_Order_Product_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES partsltd_prod.Shop_Product_Permutation(id_permutation) - , cost_unit_local_VAT_excl FLOAT NULL - , cost_unit_local_VAT_incl FLOAT NULL - , price_unit_local_VAT_excl FLOAT NULL - , price_unit_local_VAT_incl FLOAT NULL - , id_unit_quantity INT NOT NULL - , CONSTRAINT FK_Manufacturing_Purchase_Order_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES partsltd_prod.Shop_Unit_Measurement(id_unit_measurement) - , quantity_used FLOAT NULL - , quantity_produced FLOAT NULL - , id_unit_latency_manufacture INT NULL - , CONSTRAINT FK_MPO_id_unit_latency_manufacture - FOREIGN KEY (id_unit_latency_manufacture) - REFERENCES partsltd_prod.Shop_Unit_Measurement(id_unit_measurement) - , latency_manufacture INT NULL - , display_order INT NOT NULL - , active BIT NOT NULL - , created_on DATETIME - , created_by INT - , updated_last_on DATETIME NULL - , created_last_by VARCHAR(100) NULL - , id_change_set INT NULL - , CONSTRAINT FK_Manufacturing_Purchase_Order_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES partsltd_prod.Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); diff --git a/static/MySQL/1428_tbl_Shop_Manufacturing_Purchase_Order_Product_Link_Audit.sql b/static/MySQL/1428_tbl_Shop_Manufacturing_Purchase_Order_Product_Link_Audit.sql deleted file mode 100644 index 1bca18b5..00000000 --- a/static/MySQL/1428_tbl_Shop_Manufacturing_Purchase_Order_Product_Link_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Manufacturing Purchase Order Product Link Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Manufacturing_Purchase_Order_Product_Link_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Manufacturing_Purchase_Order_Product_Link_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_link INT NOT NULL, - CONSTRAINT FK_Manufacturing_Purchase_Order_Product_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Manufacturing_Purchase_Order_Product_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Manufacturing_Purchase_Order_Product_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); diff --git a/static/MySQL/1429_tbl_Shop_Manufacturing_Purchase_Order_Product_Link_Temp.sql b/static/MySQL/1429_tbl_Shop_Manufacturing_Purchase_Order_Product_Link_Temp.sql deleted file mode 100644 index 31b6510b..00000000 --- a/static/MySQL/1429_tbl_Shop_Manufacturing_Purchase_Order_Product_Link_Temp.sql +++ /dev/null @@ -1,28 +0,0 @@ - --- Manufacturing Purchase Order Product Link Temp - --- DROP TABLE Shop_Manufacturing_Purchase_Order_Product_Link_Temp; --- SELECT * FROM Shop_Manufacturing_Purchase_Order_Product_Link_Temp; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Manufacturing_Purchase_Order_Product_Link_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Manufacturing_Purchase_Order_Product_Link_Temp ( - id_temp INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_link INT NOT NULL, - id_order INT NOT NULL, - id_product INT NULL, - id_permutation INT NULL, - csv_list_variations VARCHAR(4000) NULL, - id_unit_quantity INT NOT NULL, - quantity_used FLOAT NULL, - quantity_produced FLOAT NULL, - id_unit_latency_manufacture INT NULL, - latency_manufacture INT NULL, - display_order INT NOT NULL, - active BIT NOT NULL, - cost_unit_local_VAT_excl FLOAT NULL, - cost_unit_local_VAT_incl FLOAT NULL, - price_unit_local_VAT_excl FLOAT NULL, - price_unit_local_VAT_incl FLOAT NULL, - GUID BINARY(36) NOT NULL -); diff --git a/static/MySQL/1430_tbl_Shop_Customer_Sales_Order_Product_Link.sql b/static/MySQL/1430_tbl_Shop_Customer_Sales_Order_Product_Link.sql deleted file mode 100644 index 84fd5599..00000000 --- a/static/MySQL/1430_tbl_Shop_Customer_Sales_Order_Product_Link.sql +++ /dev/null @@ -1,38 +0,0 @@ - --- Customer Sales Order Product Link - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Customer_Sales_Order_Product_Link'; - -CREATE TABLE IF NOT EXISTS Shop_Customer_Sales_Order_Product_Link ( - id_link INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_order INT NOT NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_Product_Link_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Customer_Sales_Order(id_order), - id_permutation INT NOT NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_Product_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - price_total_local FLOAT NOT NULL, - id_currency_price INT NOT NULL, - quantity_ordered FLOAT NOT NULL, - id_unit_quantity INT NOT NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_Product_Link_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - quantity_delivered FLOAT NOT NULL, - latency_delivery_days INT NOT NULL, - display_order INT NOT NULL, - - active BIT NOT NULL, - created_on DATETIME, - created_by INT, - updated_last_on DATETIME NULL, - created_last_by VARCHAR(100) NULL, - id_change_set INT NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_Product_Link_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); diff --git a/static/MySQL/1431_tbl_Shop_Customer_Sales_Order_Product_Link_Audit.sql b/static/MySQL/1431_tbl_Shop_Customer_Sales_Order_Product_Link_Audit.sql deleted file mode 100644 index fece3a29..00000000 --- a/static/MySQL/1431_tbl_Shop_Customer_Sales_Order_Product_Link_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Customer Sales Order Product Link Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Customer_Sales_Order_Product_Link_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Customer_Sales_Order_Product_Link_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_link INT NOT NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_Product_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Customer_Sales_Order_Product_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_Product_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); diff --git a/static/MySQL/1432_tbl_Shop_Customer_Sales_Order_Product_Link_Temp.sql b/static/MySQL/1432_tbl_Shop_Customer_Sales_Order_Product_Link_Temp.sql deleted file mode 100644 index 310e1090..00000000 --- a/static/MySQL/1432_tbl_Shop_Customer_Sales_Order_Product_Link_Temp.sql +++ /dev/null @@ -1,34 +0,0 @@ - --- Customer Sales Order Product Link Temp - - - --- DROP TABLE Shop_Customer_Sales_Order_Product_Link_Temp; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Customer_Sales_Order_Product_Link_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Customer_Sales_Order_Product_Link_Temp ( - id_link INT NOT NULL PRIMARY KEY, - GUID BINARY(36) NOT NULL, - id_order INT NOT NULL, - /* - CONSTRAINT FK_Customer_Sales_Order_Product_Link_Temp_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Customer_Sales_Order(id_order), - */ - id_permutation INT NOT NULL, - CONSTRAINT FK_Customer_Sales_Order_Product_Link_Temp_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - price_total_local FLOAT NOT NULL, - id_currency_price INT NOT NULL, - quantity_ordered FLOAT NOT NULL, - id_unit_quantity INT NOT NULL, - CONSTRAINT FK_Customer_Sales_Order_Product_Link_Temp_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - quantity_delivered FLOAT NULL, - latency_delivery_days INT NOT NULL, - display_order INT NOT NULL, - active BIT NOT NULL -); diff --git a/static/MySQL/1500_tbl_Shop_Calc_User_Temp.sql b/static/MySQL/1500_tbl_Shop_Calc_User_Temp.sql deleted file mode 100644 index f6ee85d2..00000000 --- a/static/MySQL/1500_tbl_Shop_Calc_User_Temp.sql +++ /dev/null @@ -1,26 +0,0 @@ - --- Calc User Staging --- USE partsltd_prod; --- DROP TABLE IF EXISTS Shop_Calc_User_Temp; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Calc_User_Temp'; - -CREATE TABLE Shop_Calc_User_Temp ( - -- id_row INT PRIMARY KEY AUTO_INCREMENT NOT NULL, - guid BINARY(36) NOT NULL, - id_user INT NULL, - id_permission_required INT NOT NULL, - CONSTRAINT FK_Shop_Calc_User_Temp_id_permission_required - FOREIGN KEY (id_permission_required) - REFERENCES partsltd_prod.Shop_Permission (id_permission), - priority_access_level_required INT NOT NULL, - id_product INT NULL, - CONSTRAINT FK_Shop_Calc_User_Temp_id_product - FOREIGN KEY (id_product) - REFERENCES partsltd_prod.Shop_Product (id_product), - is_super_user BIT NULL, - priority_access_level_user INT NULL, - can_view BIT, - can_edit BIT, - can_admin BIT -); \ No newline at end of file diff --git a/static/MySQL/3000_tri_Shop_Access_Level.sql b/static/MySQL/3000_tri_Shop_Access_Level.sql deleted file mode 100644 index c3b231ac..00000000 --- a/static/MySQL/3000_tri_Shop_Access_Level.sql +++ /dev/null @@ -1,59 +0,0 @@ - --- Shop Access Level - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Access_Level; -DROP TRIGGER IF EXISTS before_update_Shop_Access_Level; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Access_Level -BEFORE INSERT ON Shop_Access_Level -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Access_Level -BEFORE UPDATE ON Shop_Access_Level -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Access_Level_Audit ( - id_access_level, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_access_level, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT (OLD.code <=> NEW.code) - UNION - -- Changed name - SELECT NEW.id_access_level, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT (OLD.name <=> NEW.name) - UNION - -- Changed priority - SELECT NEW.id_access_level, 'priority', CONVERT(OLD.priority, CHAR), CONVERT(NEW.priority, CHAR), NEW.id_change_set - WHERE NOT (OLD.priority <=> NEW.priority) - UNION - -- Changed active - SELECT NEW.id_access_level, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_access_level, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; -END // -DELIMITER ; diff --git a/static/MySQL/3000_tri_Shop_Product_Change_Set.sql b/static/MySQL/3000_tri_Shop_Product_Change_Set.sql deleted file mode 100644 index bf110ef5..00000000 --- a/static/MySQL/3000_tri_Shop_Product_Change_Set.sql +++ /dev/null @@ -1,20 +0,0 @@ - --- Product Change Set - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Product_Change_Set; - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Product_Change_Set -BEFORE INSERT ON Shop_Product_Change_Set -FOR EACH ROW -BEGIN - IF NEW.updated_last_on <=> NULL THEN - SET NEW.updated_last_on = NOW(); - END IF; - IF NEW.updated_last_by <=> NULL THEN - SET NEW.updated_last_by = CURRENT_USER(); - END IF; -END // -DELIMITER ; diff --git a/static/MySQL/3001_tri_Shop_User_Change_Set.sql b/static/MySQL/3001_tri_Shop_User_Change_Set.sql deleted file mode 100644 index 8d9af572..00000000 --- a/static/MySQL/3001_tri_Shop_User_Change_Set.sql +++ /dev/null @@ -1,21 +0,0 @@ - --- Shop User Change Set - - - -DROP TRIGGER IF EXISTS before_insert_Shop_User_Change_Set; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_User_Change_Set -BEFORE INSERT ON Shop_User_Change_Set -FOR EACH ROW -BEGIN - IF NEW.updated_last_on <=> NULL THEN - SET NEW.updated_last_on = NOW(); - END IF; - IF NEW.updated_last_by <=> NULL THEN - SET NEW.updated_last_by = CURRENT_USER(); - END IF; -END // -DELIMITER ; \ No newline at end of file diff --git a/static/MySQL/3002_tri_Shop_Sales_And_Purchasing_Change_Set.sql b/static/MySQL/3002_tri_Shop_Sales_And_Purchasing_Change_Set.sql deleted file mode 100644 index 94dd7637..00000000 --- a/static/MySQL/3002_tri_Shop_Sales_And_Purchasing_Change_Set.sql +++ /dev/null @@ -1,20 +0,0 @@ - --- Product Change Set - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Sales_And_Purchasing_Change_Set; - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Sales_And_Purchasing_Change_Set -BEFORE INSERT ON Shop_Sales_And_Purchasing_Change_Set -FOR EACH ROW -BEGIN - IF NEW.updated_last_on <=> NULL THEN - SET NEW.updated_last_on = NOW(); - END IF; - IF NEW.updated_last_by <=> NULL THEN - SET NEW.updated_last_by = CURRENT_USER(); - END IF; -END // -DELIMITER ; diff --git a/static/MySQL/3010_tri_File_Type.sql b/static/MySQL/3010_tri_File_Type.sql deleted file mode 100644 index 613e1cd4..00000000 --- a/static/MySQL/3010_tri_File_Type.sql +++ /dev/null @@ -1,43 +0,0 @@ - --- File Type - - - -DROP TRIGGER IF EXISTS before_insert_File_Type; -DROP TRIGGER IF EXISTS before_update_File_Type; - -DELIMITER // -CREATE TRIGGER before_insert_File_Type -BEFORE INSERT ON File_Type -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - -DELIMITER // -CREATE TRIGGER before_update_File_Type -BEFORE UPDATE ON File_Type -FOR EACH ROW -BEGIN - INSERT INTO File_Type_Audit ( - id_type, - name_field, - value_prev, - value_new - ) - -- Changed code - SELECT NEW.id_type, 'code', OLD.code, NEW.code - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_type, 'name', OLD.name, NEW.name - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed extension - SELECT NEW.id_type, 'extension', CONVERT(OLD.extension, CHAR), CONVERT(NEW.extension, CHAR) - WHERE NOT OLD.extension <=> NEW.extension - ; -END // -DELIMITER ; diff --git a/static/MySQL/3011_tri_File_Type_Audit.sql b/static/MySQL/3011_tri_File_Type_Audit.sql deleted file mode 100644 index 529df018..00000000 --- a/static/MySQL/3011_tri_File_Type_Audit.sql +++ /dev/null @@ -1,28 +0,0 @@ - --- File Type Audits - - - -DROP TRIGGER IF EXISTS before_insert_File_Type_Audit; -DROP TRIGGER IF EXISTS before_update_File_Type_Audit; - - -DELIMITER // -CREATE TRIGGER before_insert_File_Type_Audit -BEFORE INSERT ON File_Type_Audit -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - -DELIMITER // -CREATE TRIGGER before_update_File_Type_Audit -BEFORE UPDATE ON File_Type_Audit -FOR EACH ROW -BEGIN - SET NEW.updated_last_on = NOW(); - SET NEW.updated_last_by = CURRENT_USER(); -END // -DELIMITER ; \ No newline at end of file diff --git a/static/MySQL/3012_tri_Shop_General.sql b/static/MySQL/3012_tri_Shop_General.sql deleted file mode 100644 index 1b1a7e76..00000000 --- a/static/MySQL/3012_tri_Shop_General.sql +++ /dev/null @@ -1,41 +0,0 @@ - --- Shop General - - - -DROP TRIGGER IF EXISTS before_insert_Shop_General; -DROP TRIGGER IF EXISTS before_update_Shop_General; - -DELIMITER // -CREATE TRIGGER before_insert_Shop_General -BEFORE INSERT ON Shop_General -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - -DELIMITER // -CREATE TRIGGER before_update_Shop_General -BEFORE UPDATE ON Shop_General -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_General_Audit ( - id_general, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed quantity max - SELECT NEW.id_general, 'quantity_max', CONVERT(OLD.quantity_max, CHAR), CONVERT(NEW.quantity_max, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - ; -END // -DELIMITER ; \ No newline at end of file diff --git a/static/MySQL/3014_tri_Shop_Image_Type.sql b/static/MySQL/3014_tri_Shop_Image_Type.sql deleted file mode 100644 index 62968b00..00000000 --- a/static/MySQL/3014_tri_Shop_Image_Type.sql +++ /dev/null @@ -1,65 +0,0 @@ - --- Shop Image Type - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Image_Type; -DROP TRIGGER IF EXISTS before_update_Shop_Image_Type; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Image_Type -BEFORE INSERT ON Shop_Image_Type -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Image_Type -BEFORE UPDATE ON Shop_Image_Type -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Image_Type_Audit ( - id_type, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_type_file - SELECT NEW.id_type, 'id_type_file', OLD.id_type_file, NEW.id_type_file, NEW.id_change_set - WHERE NOT OLD.id_type_file <=> NEW.id_type_file - UNION - */ - -- Changed code - SELECT NEW.id_type, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_type, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed name_plural - SELECT NEW.id_type, 'name_plural', OLD.name_plural, NEW.name_plural, NEW.id_change_set - WHERE NOT OLD.name_plural <=> NEW.name_plural - UNION - -- Changed active - SELECT NEW.id_type, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_type, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; -END // -DELIMITER ; \ No newline at end of file diff --git a/static/MySQL/3100_tri_PH_User_Change_Set.sql b/static/MySQL/3100_tri_PH_User_Change_Set.sql new file mode 100644 index 00000000..2c41550c --- /dev/null +++ b/static/MySQL/3100_tri_PH_User_Change_Set.sql @@ -0,0 +1,27 @@ +USE partsltd_prod; + +DROP TRIGGER IF EXISTS partsltd_prod.before_insert_PH_User_Change_Set; + +DELIMITER // +CREATE TRIGGER partsltd_prod.before_insert_PH_User_Change_Set +BEFORE INSERT ON partsltd_prod.PH_User_Change_Set +FOR EACH ROW +BEGIN + IF NEW.updated_last_on <=> NULL THEN + SET NEW.updated_last_on = NOW(); + END IF; +END // +DELIMITER ; + + +DELIMITER // +CREATE TRIGGER partsltd_prod.before_update_PH_User_Change_Set +BEFORE UPDATE ON partsltd_prod.PH_User_Change_Set +FOR EACH ROW +BEGIN + IF NOT EXISTS(SELECT * FROM partsltd_prod.PH_User WHERE id_user = NEW.id_user_updated_last_by) THEN + SIGNAL SQLSTATE '45000' + SET MESSAGE_TEXT = 'New Updated-Last-By User ID must be provided.'; + END IF; +END // +DELIMITER ; diff --git a/static/MySQL/3100_tri_Shop_Region.sql b/static/MySQL/3100_tri_Shop_Region.sql deleted file mode 100644 index 8e677a42..00000000 --- a/static/MySQL/3100_tri_Shop_Region.sql +++ /dev/null @@ -1,55 +0,0 @@ - --- Shop Delivery Region - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Region; -DROP TRIGGER IF EXISTS before_update_Shop_Region; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Region -BEFORE INSERT ON Shop_Region -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Region -BEFORE UPDATE ON Shop_Region -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Region_Audit ( - id_region, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_region, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_region, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed active - SELECT NEW.id_region, 'active', CONVERT(OLD.active, CHAR), CONVERT(NEW.active, CHAR), NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - UNION - -- Changed display_order - SELECT NEW.id_region, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; -END // -DELIMITER ; diff --git a/static/MySQL/3103_tri_Shop_Region_Branch.sql b/static/MySQL/3103_tri_Shop_Region_Branch.sql deleted file mode 100644 index fc0c3081..00000000 --- a/static/MySQL/3103_tri_Shop_Region_Branch.sql +++ /dev/null @@ -1,53 +0,0 @@ - --- Shop Region Branch - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Region_Branch; -DROP TRIGGER IF EXISTS before_update_Shop_Region_Branch; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Region_Branch -BEFORE INSERT ON Shop_Region_Branch -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Region_Branch -BEFORE UPDATE ON Shop_Region_Branch -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Region_Branch_Audit ( - id_branch, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed depth - SELECT NEW.id_branch, 'depth', CONVERT(OLD.depth, CHAR), CONVERT(NEW.depth, CHAR), NEW.id_change_set - WHERE NOT OLD.depth <=> NEW.depth - UNION - */ - -- Changed active - SELECT NEW.id_branch, 'active', CONVERT(OLD.active, CHAR), CONVERT(NEW.active, CHAR), NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - UNION - -- Changed display_order - SELECT NEW.id_branch, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; -END // -DELIMITER ; diff --git a/static/MySQL/3106_tri_Shop_Address.sql b/static/MySQL/3106_tri_Shop_Address.sql deleted file mode 100644 index cde656e8..00000000 --- a/static/MySQL/3106_tri_Shop_Address.sql +++ /dev/null @@ -1,67 +0,0 @@ - --- Shop Address - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Address; -DROP TRIGGER IF EXISTS before_update_Shop_Address; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Address -BEFORE INSERT ON Shop_Address -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Address -BEFORE UPDATE ON Shop_Address -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Address_Audit ( - id_address, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed region - SELECT NEW.id_address, 'id_region', OLD.id_region, NEW.id_region, NEW.id_change_set - WHERE NOT OLD.id_region <=> NEW.id_region - UNION - -- Changed postcode - SELECT NEW.id_address, 'postcode', OLD.postcode, NEW.postcode, NEW.id_change_set - WHERE NOT OLD.postcode <=> NEW.postcode - UNION - -- Changed address_line_1 - SELECT NEW.id_address, 'address_line_1', OLD.address_line_1, NEW.address_line_1, NEW.id_change_set - WHERE NOT OLD.address_line_1 <=> NEW.address_line_1 - UNION - -- Changed address_line_2 - SELECT NEW.id_address, 'address_line_2', OLD.address_line_2, NEW.address_line_2, NEW.id_change_set - WHERE NOT OLD.address_line_2 <=> NEW.address_line_2 - UNION - -- Changed city - SELECT NEW.id_address, 'city', OLD.city, NEW.city, NEW.id_change_set - WHERE NOT OLD.city <=> NEW.city - UNION - -- Changed county - SELECT NEW.id_address, 'county', OLD.county, NEW.county, NEW.id_change_set - WHERE NOT OLD.county <=> NEW.county - UNION - -- Changed active - SELECT NEW.id_address, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; -END // -DELIMITER ; \ No newline at end of file diff --git a/static/MySQL/3109_tri_Shop_Storage_Location.sql b/static/MySQL/3109_tri_Shop_Storage_Location.sql deleted file mode 100644 index 8231de32..00000000 --- a/static/MySQL/3109_tri_Shop_Storage_Location.sql +++ /dev/null @@ -1,55 +0,0 @@ - --- Shop Storage Location - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Storage_Location; -DROP TRIGGER IF EXISTS before_update_Shop_Storage_Location; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Storage_Location -BEFORE INSERT ON Shop_Storage_Location -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Storage_Location -BEFORE UPDATE ON Shop_Storage_Location -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Storage_Location_Audit ( - id_location, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_plant - SELECT NEW.id_location, 'id_plant', OLD.id_plant, NEW.id_plant, NEW.id_change_set - WHERE NOT OLD.id_plant <=> NEW.id_plant - UNION - -- Changed code - SELECT NEW.id_location, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_location, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed active - SELECT NEW.id_location, 'active', CONVERT(OLD.active, CHAR), CONVERT(NEW.active, CHAR), NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - ; -END // -DELIMITER ; diff --git a/static/MySQL/3115_tri_Shop_Currency.sql b/static/MySQL/3115_tri_Shop_Currency.sql deleted file mode 100644 index 93abf6c3..00000000 --- a/static/MySQL/3115_tri_Shop_Currency.sql +++ /dev/null @@ -1,63 +0,0 @@ - --- Shop Currency - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Currency; -DROP TRIGGER IF EXISTS before_update_Shop_Currency; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Currency -BEFORE INSERT ON Shop_Currency -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Currency -BEFORE UPDATE ON Shop_Currency -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Currency_Audit ( - id_currency, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_currency, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_currency, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed symbol - SELECT NEW.id_currency, 'symbol', OLD.symbol, NEW.symbol, NEW.id_change_set - WHERE NOT OLD.symbol <=> NEW.symbol - UNION - -- Changed ratio_2_GBP - SELECT NEW.id_currency, 'factor_from_GBP', OLD.factor_from_GBP, NEW.factor_from_GBP, NEW.id_change_set - WHERE NOT OLD.factor_from_GBP <=> NEW.factor_from_GBP - UNION - -- Changed active - SELECT NEW.id_currency, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_currency, 'display_order', CONVERT(display_order, CHAR), CONVERT(display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; -END // -DELIMITER ; \ No newline at end of file diff --git a/static/MySQL/3312_tri_Shop_User.sql b/static/MySQL/3116_tri_PH_User.sql similarity index 59% rename from static/MySQL/3312_tri_Shop_User.sql rename to static/MySQL/3116_tri_PH_User.sql index 0567d692..0aaf7720 100644 --- a/static/MySQL/3312_tri_Shop_User.sql +++ b/static/MySQL/3116_tri_PH_User.sql @@ -1,26 +1,23 @@ --- Shop User +USE partsltd_prod; - - -DROP TRIGGER IF EXISTS before_insert_Shop_User; -DROP TRIGGER IF EXISTS before_update_Shop_User; +DROP TRIGGER IF EXISTS partsltd_prod.before_insert_PH_User; +DROP TRIGGER IF EXISTS partsltd_prod.before_update_PH_User; DELIMITER // -CREATE TRIGGER before_insert_Shop_User -BEFORE INSERT ON Shop_User +CREATE TRIGGER partsltd_prod.before_insert_PH_User +BEFORE INSERT ON partsltd_prod.PH_User FOR EACH ROW BEGIN SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); END // DELIMITER ; DELIMITER // -CREATE TRIGGER before_update_Shop_User -BEFORE UPDATE ON Shop_User +CREATE TRIGGER partsltd_prod.before_update_PH_User +BEFORE UPDATE ON partsltd_prod.PH_User FOR EACH ROW BEGIN IF OLD.id_change_set <=> NEW.id_change_set THEN @@ -28,7 +25,7 @@ BEGIN SET MESSAGE_TEXT = 'New change Set ID must be provided.'; END IF; - INSERT INTO Shop_User_Audit ( + INSERT INTO partsltd_prod.PH_User_Audit ( id_user, name_field, value_prev, @@ -62,18 +59,6 @@ BEGIN -- Changed active SELECT NEW.id_user, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed id_currency_default - SELECT NEW.id_user, 'id_currency_default', CONVERT(OLD.id_currency_default, CHAR), CONVERT(NEW.id_currency_default, CHAR), NEW.id_change_set - WHERE NOT (OLD.id_currency_default <=> NEW.id_currency_default) - UNION - -- Changed id_region_default - SELECT NEW.id_user, 'id_region_default', CONVERT(OLD.id_region_default, CHAR), CONVERT(NEW.id_region_default, CHAR), NEW.id_change_set - WHERE NOT (OLD.id_region_default <=> NEW.id_region_default) - UNION - -- Changed is_included_VAT_default - SELECT NEW.id_user, 'is_included_VAT_default', CONVERT(CONVERT(OLD.is_included_VAT_default, SIGNED), CHAR), CONVERT(CONVERT(NEW.is_included_VAT_default, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.is_included_VAT_default <=> NEW.is_included_VAT_default) ; END // DELIMITER ; \ No newline at end of file diff --git a/static/MySQL/3118_tri_Shop_Tax_Or_Surcharge.sql b/static/MySQL/3118_tri_Shop_Tax_Or_Surcharge.sql deleted file mode 100644 index f166fe75..00000000 --- a/static/MySQL/3118_tri_Shop_Tax_Or_Surcharge.sql +++ /dev/null @@ -1,75 +0,0 @@ - --- Shop Tax_Or_Surcharge - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Tax_Or_Surcharge; -DROP TRIGGER IF EXISTS before_update_Shop_Tax_Or_Surcharge; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Tax_Or_Surcharge -BEFORE INSERT ON Shop_Tax_Or_Surcharge -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - -DELIMITER // -CREATE TRIGGER before_update_Shop_Tax_Or_Surcharge -BEFORE UPDATE ON Shop_Tax_Or_Surcharge -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Tax_Or_Surcharge_Audit ( - id_tax, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_tax, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_tax, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed fixed_fee - SELECT NEW.id_tax, 'fixed_fee', OLD.fixed_fee, NEW.fixed_fee, NEW.id_change_set - WHERE NOT OLD.fixed_fee <=> NEW.fixed_fee - UNION - -- Changed multiplier - SELECT NEW.id_tax, 'multiplier', OLD.multiplier, NEW.multiplier, NEW.id_change_set - WHERE NOT OLD.multiplier <=> NEW.multiplier - UNION - -- Changed apply_fixed_fee_before_multiplier - SELECT NEW.id_tax, 'apply_fixed_fee_before_multiplier', CONVERT(CONVERT(OLD.apply_fixed_fee_before_multiplier, SIGNED), CHAR), CONVERT(CONVERT(NEW.apply_fixed_fee_before_multiplier, SIGNED), CHAR), NEW.id_change_set - WHERE NOT OLD.apply_fixed_fee_before_multiplier <=> NEW.apply_fixed_fee_before_multiplier - UNION - -- Changed quantity_min - SELECT NEW.id_tax, 'quantity_min', OLD.quantity_min, NEW.quantity_min, NEW.id_change_set - WHERE NOT OLD.quantity_min <=> NEW.quantity_min - UNION - -- Changed quantity_max - SELECT NEW.id_tax, 'quantity_max', OLD.quantity_max, NEW.quantity_max, NEW.id_change_set - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - UNION - -- Changed display_order - SELECT NEW.id_tax, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - UNION - -- Changed active - SELECT NEW.id_tax, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - ; -END // -DELIMITER ; - diff --git a/static/MySQL/3306_tri_Shop_Role.sql b/static/MySQL/3120_tri_PH_Role.sql similarity index 73% rename from static/MySQL/3306_tri_Shop_Role.sql rename to static/MySQL/3120_tri_PH_Role.sql index b7c24832..fa1bdc65 100644 --- a/static/MySQL/3306_tri_Shop_Role.sql +++ b/static/MySQL/3120_tri_PH_Role.sql @@ -1,26 +1,23 @@ --- Shop Role +USE partsltd_prod; - - -DROP TRIGGER IF EXISTS before_insert_Shop_Role; -DROP TRIGGER IF EXISTS before_update_Shop_Role; +DROP TRIGGER IF EXISTS partsltd_prod.before_insert_PH_Role; +DROP TRIGGER IF EXISTS partsltd_prod.before_update_PH_Role; DELIMITER // -CREATE TRIGGER before_insert_Shop_Role -BEFORE INSERT ON Shop_Role +CREATE TRIGGER partsltd_prod.before_insert_PH_Role +BEFORE INSERT ON partsltd_prod.PH_Role FOR EACH ROW BEGIN SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); END // DELIMITER ; DELIMITER // -CREATE TRIGGER before_update_Shop_Role -BEFORE UPDATE ON Shop_Role +CREATE TRIGGER partsltd_prod.before_update_PH_Role +BEFORE UPDATE ON partsltd_prod.PH_Role FOR EACH ROW BEGIN IF OLD.id_change_set <=> NEW.id_change_set THEN @@ -28,7 +25,7 @@ BEGIN SET MESSAGE_TEXT = 'New change Set ID must be provided.'; END IF; - INSERT INTO Shop_Role_Audit ( + INSERT INTO partsltd_prod.PH_Role_Audit ( id_role, name_field, value_prev, diff --git a/static/MySQL/3309_tri_Shop_Role_Permission_Link.sql b/static/MySQL/3124_tri_PH_Role_Permission_Link.sql similarity index 69% rename from static/MySQL/3309_tri_Shop_Role_Permission_Link.sql rename to static/MySQL/3124_tri_PH_Role_Permission_Link.sql index cfb647dd..a763a70c 100644 --- a/static/MySQL/3309_tri_Shop_Role_Permission_Link.sql +++ b/static/MySQL/3124_tri_PH_Role_Permission_Link.sql @@ -1,26 +1,23 @@ --- Shop Role Permission Link +USE partsltd_prod; - - -DROP TRIGGER IF EXISTS before_insert_Shop_Role_Permission_Link; -DROP TRIGGER IF EXISTS before_update_Shop_Role_Permission_Link; +DROP TRIGGER IF EXISTS partsltd_prod.before_insert_PH_Role_Permission_Link; +DROP TRIGGER IF EXISTS partsltd_prod.before_update_PH_Role_Permission_Link; DELIMITER // -CREATE TRIGGER before_insert_Shop_Role_Permission_Link -BEFORE INSERT ON Shop_Role_Permission_Link +CREATE TRIGGER partsltd_prod.before_insert_PH_Role_Permission_Link +BEFORE INSERT ON partsltd_prod.PH_Role_Permission_Link FOR EACH ROW BEGIN SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); END // DELIMITER ; DELIMITER // -CREATE TRIGGER before_update_Shop_Role_Permission_Link -BEFORE UPDATE ON Shop_Role_Permission_Link +CREATE TRIGGER partsltd_prod.before_update_PH_Role_Permission_Link +BEFORE UPDATE ON partsltd_prod.PH_Role_Permission_Link FOR EACH ROW BEGIN IF OLD.id_change_set <=> NEW.id_change_set THEN @@ -28,14 +25,13 @@ BEGIN SET MESSAGE_TEXT = 'New change Set ID must be provided.'; END IF; - INSERT INTO Shop_Role_Permission_Link_Audit ( + INSERT INTO partsltd_prod.PH_Role_Permission_Link_Audit ( id_link, name_field, value_prev, value_new, id_change_set ) - /* -- Changed id_role SELECT NEW.id_link, 'id_role', CONVERT(OLD.id_role, CHAR), CONVERT(NEW.id_role, CHAR), NEW.id_change_set WHERE NOT OLD.id_role <=> NEW.id_role @@ -44,7 +40,6 @@ BEGIN SELECT NEW.id_link, 'id_permission', CONVERT(OLD.id_permission, CHAR), CONVERT(NEW.id_permission, CHAR), NEW.id_change_set WHERE NOT OLD.id_permission <=> NEW.id_permission UNION - */ -- Changed id_access_level SELECT NEW.id_link, 'id_access_level', CONVERT(OLD.id_access_level, CHAR), CONVERT(NEW.id_access_level, CHAR), NEW.id_change_set WHERE NOT OLD.id_access_level <=> NEW.id_access_level diff --git a/static/MySQL/3128_tri_PH_User_Role_Link.sql b/static/MySQL/3128_tri_PH_User_Role_Link.sql new file mode 100644 index 00000000..448cb06b --- /dev/null +++ b/static/MySQL/3128_tri_PH_User_Role_Link.sql @@ -0,0 +1,48 @@ + +USE partsltd_prod; + +DROP TRIGGER IF EXISTS partsltd_prod.before_insert_PH_User_Role_Link; +DROP TRIGGER IF EXISTS partsltd_prod.before_update_PH_User_Role_Link; + + +DELIMITER // +CREATE TRIGGER partsltd_prod.before_insert_PH_User_Role_Link +BEFORE INSERT ON partsltd_prod.PH_User_Role_Link +FOR EACH ROW +BEGIN + SET NEW.created_on := IFNULL(NEW.created_on, NOW()); +END // +DELIMITER ; + + +DELIMITER // +CREATE TRIGGER partsltd_prod.before_update_PH_User_Role_Link +BEFORE UPDATE ON partsltd_prod.PH_User_Role_Link +FOR EACH ROW +BEGIN + IF OLD.id_change_set <=> NEW.id_change_set THEN + SIGNAL SQLSTATE '45000' + SET MESSAGE_TEXT = 'New change Set ID must be provided.'; + END IF; + + INSERT INTO partsltd_prod.PH_User_Role_Link_Audit ( + id_link, + name_field, + value_prev, + value_new, + id_change_set + ) + -- Changed id_user + SELECT NEW.id_link, 'id_user', CONVERT(OLD.id_user, CHAR), CONVERT(NEW.id_user, CHAR), NEW.id_change_set + WHERE NOT OLD.id_user <=> NEW.id_user + UNION + -- Changed id_role + SELECT NEW.id_link, 'id_role', CONVERT(OLD.id_role, CHAR), CONVERT(NEW.id_role, CHAR), NEW.id_change_set + WHERE NOT OLD.id_role <=> NEW.id_role + UNION + -- Changed active + SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set + WHERE NOT (OLD.active <=> NEW.active) + ; +END // +DELIMITER ; \ No newline at end of file diff --git a/static/MySQL/3200_tri_PH_Contact_Form_Change_Set.sql b/static/MySQL/3200_tri_PH_Contact_Form_Change_Set.sql new file mode 100644 index 00000000..baccad18 --- /dev/null +++ b/static/MySQL/3200_tri_PH_Contact_Form_Change_Set.sql @@ -0,0 +1,14 @@ +USE partsltd_prod; + +DROP TRIGGER IF EXISTS partsltd_prod.before_insert_PH_Contact_Form_Change_Set; + +DELIMITER // +CREATE TRIGGER partsltd_prod.before_insert_PH_Contact_Form_Change_Set +BEFORE INSERT ON partsltd_prod.PH_Contact_Form_Change_Set +FOR EACH ROW +BEGIN + IF NEW.updated_last_on <=> NULL THEN + SET NEW.updated_last_on = NOW(); + END IF; +END // +DELIMITER ; diff --git a/static/MySQL/3200_tri_Shop_Category.sql b/static/MySQL/3200_tri_Shop_Category.sql deleted file mode 100644 index f3100247..00000000 --- a/static/MySQL/3200_tri_Shop_Category.sql +++ /dev/null @@ -1,61 +0,0 @@ - --- Shop Category - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Product_Category; -DROP TRIGGER IF EXISTS before_update_Shop_Product_Category; - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Product_Category -BEFORE INSERT ON Shop_Product_Category -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - -DELIMITER // -CREATE TRIGGER before_update_Shop_Product_Category -BEFORE UPDATE ON Shop_Product_Category -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Product_Category_Audit ( - id_category, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_category, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_category, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed description - SELECT NEW.id_category, 'description', OLD.description, NEW.description, NEW.id_change_set - WHERE NOT OLD.description <=> NEW.description - UNION - -- Changed active - SELECT NEW.id_category, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_category, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - UNION - -- Changed id_access_level_required - SELECT NEW.id_category, 'id_access_level_required', CONVERT(OLD.id_access_level_required, CHAR), CONVERT(NEW.id_access_level_required, CHAR), NEW.id_change_set - WHERE NOT OLD.id_access_level_required <=> NEW.id_access_level_required - ; -END // -DELIMITER ; diff --git a/static/MySQL/3201_tri_PH_Contact_Form.sql b/static/MySQL/3201_tri_PH_Contact_Form.sql new file mode 100644 index 00000000..49636df3 --- /dev/null +++ b/static/MySQL/3201_tri_PH_Contact_Form.sql @@ -0,0 +1,58 @@ + +USE partsltd_prod; + +DROP TRIGGER IF EXISTS partsltd_prod.before_insert_PH_Contact_Form; +DROP TRIGGER IF EXISTS partsltd_prod.before_update_PH_Contact_Form; + +DELIMITER // +CREATE TRIGGER partsltd_prod.before_insert_PH_Contact_Form +BEFORE INSERT ON partsltd_prod.PH_Contact_Form +FOR EACH ROW +BEGIN + SET NEW.created_on := IFNULL(NEW.created_on, NOW()); +END // +DELIMITER ; + +DELIMITER // +CREATE TRIGGER partsltd_prod.before_update_PH_Contact_Form +BEFORE UPDATE ON partsltd_prod.PH_Contact_Form +FOR EACH ROW +BEGIN + IF OLD.id_change_set <=> NEW.id_change_set THEN + SIGNAL SQLSTATE '45000' + SET MESSAGE_TEXT = 'New change Set ID must be provided.'; + END IF; + + INSERT INTO partsltd_prod.PH_Contact_Form_Audit ( + id_contact_form, + name_field, + value_prev, + value_new, + id_change_set + ) + -- Changed email + SELECT NEW.id_contact_form, 'email', OLD.email, NEW.email, NEW.id_change_set + WHERE NOT OLD.email <=> NEW.email + UNION + -- Changed name_contact + SELECT NEW.id_contact_form, 'name_contact', OLD.name_contact, NEW.name_contact, NEW.id_change_set + WHERE NOT OLD.name_contact <=> NEW.name_contact + UNION + -- Changed name_company + SELECT NEW.id_contact_form, 'name_company', OLD.name_company, NEW.name_company, NEW.id_change_set + WHERE NOT OLD.name_company <=> NEW.name_company + UNION + -- Changed message + SELECT NEW.id_contact_form, 'message', OLD.message, NEW.message, NEW.id_change_set + WHERE NOT OLD.message <=> NEW.message + UNION + -- Changed receive_marketing_communications + SELECT NEW.id_contact_form, 'receive_marketing_communications', CONVERT(CONVERT(OLD.receive_marketing_communications, SIGNED), CHAR), CONVERT(CONVERT(NEW.receive_marketing_communications, SIGNED), CHAR), NEW.id_change_set + WHERE NOT (OLD.receive_marketing_communications <=> NEW.receive_marketing_communications) + UNION + -- Changed active + SELECT NEW.id_contact_form, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set + WHERE NOT (OLD.active <=> NEW.active) + ; +END // +DELIMITER ; diff --git a/static/MySQL/3203_tri_Shop_Product.sql b/static/MySQL/3203_tri_Shop_Product.sql deleted file mode 100644 index b55c041a..00000000 --- a/static/MySQL/3203_tri_Shop_Product.sql +++ /dev/null @@ -1,170 +0,0 @@ - --- Shop Product - - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Product; -DROP TRIGGER IF EXISTS before_update_Shop_Product; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Product -BEFORE INSERT ON Shop_Product -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Product -BEFORE UPDATE ON Shop_Product -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - /* - IF NOT NEW.has_variations THEN - IF ISNULL(NEW.price_GBP_full) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have price or variations (with prices).'; - END IF; - IF ISNULL(NEW.price_GBP_min) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have minimum price or variations (with prices).'; - END IF; - IF ISNULL(NEW.latency_manuf) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have manufacturing latency or variations (with manufacturing latencies).'; - END IF; - IF ISNULL(NEW.quantity_min) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have minimum quantity or variations (with minimum quantities).'; - END IF; - IF ISNULL(NEW.quantity_max) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have maximum quantity or variations (with maximum quantities).'; - END IF; - IF ISNULL(NEW.quantity_step) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have increment of quantity or variations (with increments of quantities).'; - END IF; - IF ISNULL(NEW.quantity_stock) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have stock quantity or variations (with stock quantities).'; - END IF; - IF ISNULL(NEW.is_subscription) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have subscription status or variations (with subscription statuses).'; - END IF; - IF ISNULL(NEW.id_unit_measurement_interval_recurrence) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have recurrence interval or variations (with recurrence intervals).'; - END IF; - IF ISNULL(NEW.count_interval_recurrence) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have recurrence interval count or variations (with recurrence interval counts).'; - END IF; - END IF; - */ - - INSERT INTO Shop_Product_Audit ( - id_product, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed name - SELECT NEW.id_product, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - /* - UNION - -- Changed description - SELECT NEW.id_product, 'description', OLD.description, NEW.description, NEW.id_change_set - WHERE NOT OLD.description <=> NEW.description - UNION - -- Changed price_GBP_full - SELECT NEW.id_product, 'price_GBP_full', CONVERT(OLD.price_GBP_full, CHAR), CONVERT(NEW.price_GBP_full, CHAR), NEW.id_change_set - WHERE NOT OLD.price_GBP_full <=> NEW.price_GBP_full - UNION - -- Changed price_GBP_min - SELECT NEW.id_product, 'price_GBP_min', CONVERT(OLD.price_GBP_min, CHAR), CONVERT(NEW.price_GBP_min, CHAR), NEW.id_change_set - WHERE NOT OLD.price_GBP_min <=> NEW.price_GBP_min - UNION - /* - -- Changed discount - SELECT NEW.id_product, 'discount', CONVERT(OLD.discount, CHAR), CONVERT(NEW.discount, CHAR), NEW.id_change_set - WHERE NOT OLD.discount <=> NEW.discount - */ - UNION - -- Changed id_category - SELECT NEW.id_product, 'id_category', CONVERT(OLD.id_category, CHAR), CONVERT(NEW.id_category, CHAR), NEW.id_change_set - WHERE NOT OLD.id_category <=> NEW.id_category - UNION - -- Changed has_variations - SELECT NEW.id_product, 'has_variations', CONVERT(CONVERT(NEW.has_variations, SIGNED), CHAR), CONVERT(CONVERT(NEW.has_variations, SIGNED), CHAR), NEW.id_change_set - WHERE NOT OLD.has_variations <=> NEW.has_variations - /* - UNION - -- Changed latency_manuf - SELECT NEW.id_product, 'latency_manuf', CONVERT(OLD.latency_manuf, CHAR), CONVERT(NEW.latency_manuf, CHAR), NEW.id_change_set - WHERE NOT OLD.latency_manuf <=> NEW.latency_manuf - UNION - -- Changed quantity_min - SELECT NEW.id_product, 'quantity_min', CONVERT(OLD.quantity_min, CHAR), CONVERT(NEW.quantity_min, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_min <=> NEW.quantity_min - UNION - -- Changed quantity_max - SELECT NEW.id_product, 'quantity_max', CONVERT(OLD.quantity_max, CHAR), CONVERT(NEW.quantity_max, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - UNION - -- Changed quantity_step - SELECT NEW.id_product, 'quantity_step', CONVERT(OLD.quantity_step, CHAR), CONVERT(NEW.quantity_step, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_step <=> NEW.quantity_step - UNION - -- Changed quantity_stock - SELECT NEW.id_product, 'quantity_stock', CONVERT(OLD.quantity_stock, CHAR), CONVERT(NEW.quantity_stock, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_stock <=> NEW.quantity_stock - UNION - -- Changed is_subscription - SELECT NEW.id_product, 'is_subscription', CONVERT(CONVERT(OLD.is_subscription, SIGNED), CHAR), CONVERT(CONVERT(NEW.is_subscription, SIGNED), CHAR), NEW.id_change_set - WHERE NOT OLD.is_subscription <=> NEW.is_subscription - UNION - -- Changed id_unit_measurement_interval_recurrence - SELECT NEW.id_product, 'id_unit_measurement_interval_recurrence', CONVERT(OLD.id_unit_measurement_interval_recurrence, CHAR), CONVERT(NEW.id_unit_measurement_interval_recurrence, CHAR), NEW.id_change_set - WHERE NOT OLD.id_unit_measurement_interval_recurrence <=> NEW.id_unit_measurement_interval_recurrence - UNION - -- Changed count_interval_recurrence - SELECT NEW.id_product, 'count_interval_recurrence', CONVERT(OLD.count_interval_recurrence, CHAR), CONVERT(NEW.count_interval_recurrence, CHAR), NEW.id_change_set - WHERE NOT OLD.count_interval_recurrence <=> NEW.count_interval_recurrence - UNION - -- Changed id_stripe_product - SELECT NEW.id_product, 'id_stripe_product', OLD.id_stripe_product, NEW.id_stripe_product, NEW.id_change_set - WHERE NOT OLD.id_stripe_product <=> NEW.id_stripe_product - /* - UNION - -- Changed id_stripe_price - SELECT NEW.id_product, 'id_stripe_price', OLD.id_stripe_price, NEW.id_stripe_price, NEW.id_change_set - WHERE NOT OLD.id_stripe_price <=> NEW.id_stripe_price - */ - UNION - -- Changed id_access_level_required - SELECT NEW.id_product, 'id_access_level_required', CONVERT(OLD.id_access_level_required, CHAR), CONVERT(NEW.id_access_level_required, CHAR), NEW.id_change_set - WHERE NOT OLD.id_access_level_required <=> NEW.id_access_level_required - UNION - -- Changed active - SELECT NEW.id_product, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_product, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; -END // -DELIMITER ; diff --git a/static/MySQL/3206_tri_Shop_Product_Permutation.sql b/static/MySQL/3206_tri_Shop_Product_Permutation.sql deleted file mode 100644 index c19ad38a..00000000 --- a/static/MySQL/3206_tri_Shop_Product_Permutation.sql +++ /dev/null @@ -1,167 +0,0 @@ - --- Shop Product Permutation - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Product_Permutation; -DROP TRIGGER IF EXISTS before_update_Shop_Product_Permutation; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Product_Permutation -BEFORE INSERT ON Shop_Product_Permutation -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Product_Permutation -BEFORE UPDATE ON Shop_Product_Permutation -FOR EACH ROW -BEGIN - DECLARE v_msg VARCHAR(4000); - - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - IF (NOT ( - NEW.id_unit_measurement_interval_recurrence IS NULL - OR NEW.id_unit_measurement_interval_recurrence IN (SELECT id_unit_measurement FROM Shop_Unit_Measurement WHERE is_unit_of_time = 1) - )) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Recurrence interval ID must be a unit of time.'; - END IF; - - IF (NOT ( - NEW.id_unit_measurement_interval_expiration_unsealed IS NULL - OR NEW.id_unit_measurement_interval_expiration_unsealed IN (SELECT id_unit_measurement FROM Shop_Unit_Measurement WHERE is_unit_of_time = 1) - )) THEN - SET v_msg := CONCAT('Unsealed expiration interval ID must be a unit of time. Invalid value: ', CAST(NEW.id_unit_measurement_interval_expiration_unsealed AS CHAR)); - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = v_msg - ; - END IF; - - INSERT INTO Shop_Product_Permutation_Audit ( - id_permutation, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_product - SELECT NEW.id_permutation, 'id_product', OLD.id_product, NEW.id_product, NEW.id_change_set - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed id_variation - SELECT NEW.id_permutation, 'id_variation', OLD.id_variation, NEW.id_variation, NEW.id_change_set - WHERE NOT OLD.id_variation <=> NEW.id_variation - UNION - -- Changed name - SELECT NEW.id_permutation, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT (OLD.name <=> NEW.name) - UNION - */ - -- Changed description - SELECT NEW.id_permutation, 'description', OLD.description, NEW.description, NEW.id_change_set - WHERE NOT (OLD.description <=> NEW.description) - UNION - -- Changed cost_local_VAT_excl - SELECT NEW.id_permutation, 'cost_local_VAT_excl', CONVERT(OLD.cost_local_VAT_excl, CHAR), CONVERT(NEW.cost_local_VAT_excl, CHAR), NEW.id_change_set - WHERE NOT (OLD.cost_local_VAT_excl <=> NEW.cost_local_VAT_excl) - UNION - -- Changed cost_local_VAT_incl - SELECT NEW.id_permutation, 'cost_local_VAT_incl', CONVERT(OLD.cost_local_VAT_incl, CHAR), CONVERT(NEW.cost_local_VAT_incl, CHAR), NEW.id_change_set - WHERE NOT (OLD.cost_local_VAT_incl <=> NEW.cost_local_VAT_incl) - UNION - -- Changed id_currency_cost - SELECT NEW.id_permutation, 'id_currency_cost', CONVERT(OLD.id_currency_cost, CHAR), CONVERT(NEW.id_currency_cost, CHAR), NEW.id_change_set - WHERE NOT (OLD.id_currency_cost <=> NEW.id_currency_cost) - UNION - /* - -- Changed profit_local_min - SELECT NEW.id_permutation, 'profit_local_min', CONVERT(OLD.profit_local_min, CHAR), CONVERT(NEW.profit_local_min, CHAR), NEW.id_change_set - WHERE NOT (OLD.profit_local_min <=> NEW.profit_local_min) - UNION - -- Changed id_currency_profit_min - SELECT NEW.id_permutation, 'id_currency_profit_min', CONVERT(OLD.id_currency_profit_min, CHAR), CONVERT(NEW.id_currency_profit_min, CHAR), NEW.id_change_set - WHERE NOT (OLD.id_currency_profit_min <=> NEW.id_currency_profit_min) - UNION - */ - /* - -- Changed price_GBP_min - SELECT NEW.id_permutation, 'price_GBP_min', CONVERT(OLD.price_GBP_min, CHAR), CONVERT(NEW.price_GBP_min, CHAR), NEW.id_change_set - WHERE NOT (OLD.price_GBP_min <=> NEW.price_GBP_min) - UNION - */ - -- Changed latency_manufacture - SELECT NEW.id_permutation, 'latency_manufacture', CONVERT(OLD.latency_manufacture, CHAR), CONVERT(NEW.latency_manufacture, CHAR), NEW.id_change_set - WHERE NOT OLD.latency_manufacture <=> NEW.latency_manufacture - UNION - -- Changed id_unit_measurement_quantity - SELECT NEW.id_permutation, 'id_unit_measurement_quantity', CONVERT(OLD.id_unit_measurement_quantity, CHAR), CONVERT(NEW.id_unit_measurement_quantity, CHAR), NEW.id_change_set - WHERE NOT OLD.id_unit_measurement_quantity <=> NEW.id_unit_measurement_quantity - UNION - -- Changed count_unit_measurement_per_quantity_step - SELECT NEW.id_permutation, 'count_unit_measurement_per_quantity_step', CONVERT(OLD.count_unit_measurement_per_quantity_step, CHAR), CONVERT(NEW.count_unit_measurement_per_quantity_step, CHAR), NEW.id_change_set - WHERE NOT OLD.count_unit_measurement_per_quantity_step <=> NEW.count_unit_measurement_per_quantity_step - UNION - -- Changed quantity_min - SELECT NEW.id_permutation, 'quantity_min', CONVERT(OLD.quantity_min, CHAR), CONVERT(NEW.quantity_min, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_min <=> NEW.quantity_min - UNION - -- Changed quantity_max - SELECT NEW.id_permutation, 'quantity_max', CONVERT(OLD.quantity_max, CHAR), CONVERT(NEW.quantity_max, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - UNION - -- Changed quantity_stock - SELECT NEW.id_permutation, 'quantity_stock', CONVERT(OLD.quantity_stock, CHAR), CONVERT(NEW.quantity_stock, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_stock <=> NEW.quantity_stock - UNION - -- Changed is_subscription - SELECT NEW.id_permutation, 'is_subscription', CONVERT(CONVERT(OLD.is_subscription, SIGNED), CHAR), CONVERT(CONVERT(NEW.is_subscription, SIGNED), CHAR), NEW.id_change_set - WHERE NOT OLD.is_subscription <=> NEW.is_subscription - UNION - -- Changed id_unit_measurement_interval_recurrence - SELECT NEW.id_permutation, 'id_unit_measurement_interval_recurrence', CONVERT(OLD.id_unit_measurement_interval_recurrence, CHAR), CONVERT(NEW.id_unit_measurement_interval_recurrence, CHAR), NEW.id_change_set - WHERE NOT OLD.id_unit_measurement_interval_recurrence <=> NEW.id_unit_measurement_interval_recurrence - UNION - -- Changed count_interval_recurrence - SELECT NEW.id_permutation, 'count_interval_recurrence', CONVERT(OLD.count_interval_recurrence, CHAR), CONVERT(NEW.count_interval_recurrence, CHAR), NEW.id_change_set - WHERE NOT OLD.count_interval_recurrence <=> NEW.count_interval_recurrence - UNION - -- Changed id_stripe_product - SELECT NEW.id_permutation, 'id_stripe_product', OLD.id_stripe_product, NEW.id_stripe_product, NEW.id_change_set - WHERE NOT (OLD.id_stripe_product <=> NEW.id_stripe_product) - UNION - -- Changed does_expire_faster_once_unsealed - SELECT NEW.id_permutation, 'does_expire_faster_once_unsealed', CONVERT(OLD.does_expire_faster_once_unsealed, CHAR), CONVERT(NEW.does_expire_faster_once_unsealed, CHAR), NEW.id_change_set - WHERE NOT OLD.does_expire_faster_once_unsealed <=> NEW.does_expire_faster_once_unsealed - UNION - -- Changed id_unit_measurement_interval_expiration_unsealed - SELECT NEW.id_permutation, 'id_unit_measurement_interval_expiration_unsealed', CONVERT(OLD.id_unit_measurement_interval_expiration_unsealed, CHAR), CONVERT(NEW.id_unit_measurement_interval_expiration_unsealed, CHAR), NEW.id_change_set - WHERE NOT OLD.id_unit_measurement_interval_expiration_unsealed <=> NEW.id_unit_measurement_interval_expiration_unsealed - UNION - -- Changed count_interval_expiration_unsealed - SELECT NEW.id_permutation, 'count_interval_expiration_unsealed', CONVERT(OLD.count_interval_expiration_unsealed, CHAR), CONVERT(NEW.count_interval_expiration_unsealed, CHAR), NEW.id_change_set - WHERE NOT OLD.count_interval_expiration_unsealed <=> NEW.count_interval_expiration_unsealed - UNION - -- Changed active - SELECT NEW.id_permutation, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - /* - UNION - -- Changed display_order - SELECT NEW.id_permutation, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - */ - ; -END // -DELIMITER ; diff --git a/static/MySQL/3209_tri_Shop_Variation_Type.sql b/static/MySQL/3209_tri_Shop_Variation_Type.sql deleted file mode 100644 index b7f75613..00000000 --- a/static/MySQL/3209_tri_Shop_Variation_Type.sql +++ /dev/null @@ -1,60 +0,0 @@ - --- Shop Variation Type - - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Variation_Type; -DROP TRIGGER IF EXISTS before_update_Shop_Variation_Type; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Variation_Type -BEFORE INSERT ON Shop_Variation_Type -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Variation_Type -BEFORE UPDATE ON Shop_Variation_Type -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Variation_Type_Audit ( - id_type, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_type, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_type, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed name_plural - SELECT NEW.id_type, 'name_plural', OLD.name_plural, NEW.name_plural, NEW.id_change_set - WHERE NOT OLD.name_plural <=> NEW.name_plural - UNION - -- Changed active - SELECT NEW.id_type, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_type, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; -END // -DELIMITER ; diff --git a/static/MySQL/3212_tri_Shop_Variation.sql b/static/MySQL/3212_tri_Shop_Variation.sql deleted file mode 100644 index 20b90194..00000000 --- a/static/MySQL/3212_tri_Shop_Variation.sql +++ /dev/null @@ -1,63 +0,0 @@ - --- Shop Variation - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Variation; -DROP TRIGGER IF EXISTS before_update_Shop_Variation; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Variation -BEFORE INSERT ON Shop_Variation -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Variation -BEFORE UPDATE ON Shop_Variation -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Variation_Audit ( - id_variation, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_unit_measurement - SELECT NEW.id_variation, 'id_unit_measurement', OLD.id_unit_measurement, NEW.id_unit_measurement, NEW.id_change_set - WHERE NOT OLD.id_unit_measurement <=> NEW.id_unit_measurement - UNION - -- Changed count_unit_measurement - SELECT NEW.id_variation, 'count_unit_measurement', OLD.count_unit_measurement, NEW.count_unit_measurement, NEW.id_change_set - WHERE NOT OLD.count_unit_measurement <=> NEW.count_unit_measurement - UNION - -- Changed code - SELECT NEW.id_variation, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_variation, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed active - SELECT NEW.id_variation, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_variation, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; -END // -DELIMITER ; diff --git a/static/MySQL/3215_tri_Shop_Product_Permutation_Variation_Link.sql b/static/MySQL/3215_tri_Shop_Product_Permutation_Variation_Link.sql deleted file mode 100644 index 8ca2dcfe..00000000 --- a/static/MySQL/3215_tri_Shop_Product_Permutation_Variation_Link.sql +++ /dev/null @@ -1,57 +0,0 @@ - --- Shop Product Permutation Variation Link - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Product_Permutation_Variation_Link; -DROP TRIGGER IF EXISTS before_update_Shop_Product_Permutation_Variation_Link; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Product_Permutation_Variation_Link -BEFORE INSERT ON Shop_Product_Permutation_Variation_Link -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Product_Permutation_Variation_Link -BEFORE UPDATE ON Shop_Product_Permutation_Variation_Link -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Product_Permutation_Variation_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_product - SELECT NEW.id_link, 'id_product', OLD.id_product, NEW.id_product, NEW.id_change_set - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed id_variation - SELECT NEW.id_link, 'id_variation', OLD.id_variation, NEW.id_variation, NEW.id_change_set - WHERE NOT OLD.id_variation <=> NEW.id_variation - UNION - */ - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_link, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; -END // -DELIMITER ; \ No newline at end of file diff --git a/static/MySQL/3218_tri_Shop_Stock_Item.sql b/static/MySQL/3218_tri_Shop_Stock_Item.sql deleted file mode 100644 index fe993efe..00000000 --- a/static/MySQL/3218_tri_Shop_Stock_Item.sql +++ /dev/null @@ -1,91 +0,0 @@ - --- Shop Product Permutation - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Stock_Item; -DROP TRIGGER IF EXISTS before_update_Shop_Stock_Item; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Stock_Item -BEFORE INSERT ON Shop_Stock_Item -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Stock_Item -BEFORE UPDATE ON Shop_Stock_Item -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Stock_Item_Audit ( - id_stock, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_permutation - SELECT NEW.id_stock, 'id_permutation', OLD.id_permutation, NEW.id_permutation, NEW.id_change_set - WHERE NOT (OLD.id_permutation <=> NEW.id_permutation) - UNION - -- Changed date_purchased - SELECT NEW.id_stock, 'date_purchased', OLD.date_purchased, NEW.date_purchased, NEW.id_change_set - WHERE NOT (OLD.date_purchased <=> NEW.date_purchased) - UNION - -- Changed date_received - SELECT NEW.id_stock, 'date_received', OLD.date_received, NEW.date_received, NEW.id_change_set - WHERE NOT (OLD.date_received <=> NEW.date_received) - UNION - -- Changed id_location_storage - SELECT NEW.id_stock, 'id_location_storage', OLD.id_location_storage, NEW.id_location_storage, NEW.id_change_set - WHERE NOT (OLD.id_location_storage <=> NEW.id_location_storage) - UNION - -- Changed id_currency_cost - SELECT NEW.id_stock, 'id_currency_cost', OLD.id_currency_cost, NEW.id_currency_cost, NEW.id_change_set - WHERE NOT (OLD.id_currency_cost <=> NEW.id_currency_cost) - UNION - -- Changed cost_local_VAT_incl - SELECT NEW.id_stock, 'cost_local_VAT_incl', OLD.cost_local_VAT_incl, NEW.cost_local_VAT_incl, NEW.id_change_set - WHERE NOT (OLD.cost_local_VAT_incl <=> NEW.cost_local_VAT_incl) - UNION - -- Changed cost_local_VAT_excl - SELECT NEW.id_stock, 'cost_local_VAT_excl', OLD.cost_local_VAT_excl, NEW.cost_local_VAT_excl, NEW.id_change_set - WHERE NOT (OLD.cost_local_VAT_excl <=> NEW.cost_local_VAT_excl) - UNION - -- Changed is_sealed - SELECT NEW.id_stock, 'is_sealed', OLD.is_sealed, NEW.is_sealed, NEW.id_change_set - WHERE NOT (OLD.is_sealed <=> NEW.is_sealed) - UNION - -- Changed date_unsealed - SELECT NEW.id_stock, 'date_unsealed', OLD.date_unsealed, NEW.date_unsealed, NEW.id_change_set - WHERE NOT (OLD.date_unsealed <=> NEW.date_unsealed) - UNION - -- Changed date_expiration - SELECT NEW.id_stock, 'date_expiration', OLD.date_expiration, NEW.date_expiration, NEW.id_change_set - WHERE NOT (OLD.date_expiration <=> NEW.date_expiration) - UNION - -- Changed is_consumed - SELECT NEW.id_stock, 'is_consumed', OLD.is_consumed, NEW.is_consumed, NEW.id_change_set - WHERE NOT (OLD.is_consumed <=> NEW.is_consumed) - UNION - -- Changed date_consumed - SELECT NEW.id_stock, 'date_consumed', OLD.date_consumed, NEW.date_consumed, NEW.id_change_set - WHERE NOT (OLD.date_consumed <=> NEW.date_consumed) - UNION - -- Changed active - SELECT NEW.id_stock, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; -END // -DELIMITER ; diff --git a/static/MySQL/3221_tri_Shop_Product_Price.sql b/static/MySQL/3221_tri_Shop_Product_Price.sql deleted file mode 100644 index 2abe60dc..00000000 --- a/static/MySQL/3221_tri_Shop_Product_Price.sql +++ /dev/null @@ -1,87 +0,0 @@ - --- Shop Product Currency Link - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Product_Price; -DROP TRIGGER IF EXISTS before_update_Shop_Product_Price; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Product_Price -BEFORE INSERT ON Shop_Product_Price -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - /* - SET NEW.price_local = ( - SELECT PP.price_GBP_full * C.factor_from_GBP - FROM Shop_Product_Permutation PP - INNER JOIN Shop_Product P ON PP.id_product = P.id_product - INNER JOIN Shop_Currency C ON NEW.id_currency = C.id_currency - WHERE NEW.id_product = P.id_product - LIMIT 1 - ); - */ -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Product_Price -BEFORE UPDATE ON Shop_Product_Price -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - /* - SET NEW.price_local = ( - SELECT P.price_GBP_full * C.factor_from_GBP - FROM Shop_Product P - INNER JOIN Shop_Currency C ON NEW.id_currency = C.id_currency - WHERE NEW.id_product = P.id_product - LIMIT 1 - ); - */ - - INSERT INTO Shop_Product_Price_Audit ( - id_price, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_permutation - SELECT NEW.id_price, 'id_permutation', CONVERT(OLD.id_permutation, CHAR), CONVERT(NEW.id_permutation, CHAR), NEW.id_change_set - WHERE NOT OLD.id_permutation <=> NEW.id_permutation - UNION - -- Changed id_currency - SELECT NEW.id_price, 'id_currency', CONVERT(OLD.id_currency, CHAR), CONVERT(NEW.id_currency, CHAR), NEW.id_change_set - WHERE NOT OLD.id_currency <=> NEW.id_currency - UNION - -- Changed id_region_purchase - SELECT NEW.id_price, 'id_region_purchase', CONVERT(OLD.id_region_purchase, CHAR), CONVERT(NEW.id_region_purchase, CHAR), NEW.id_change_set - WHERE NOT OLD.id_region_purchase <=> NEW.id_region_purchase - UNION - -- Changed price_local_VAT_incl - SELECT NEW.id_price, 'price_local_VAT_incl', OLD.price_local_VAT_incl, NEW.price_local_VAT_incl, NEW.id_change_set - WHERE NOT OLD.price_local_VAT_incl <=> NEW.price_local_VAT_incl - UNION - -- Changed price_local_VAT_excl - SELECT NEW.id_price, 'price_local_VAT_excl', OLD.price_local_VAT_excl, NEW.price_local_VAT_excl, NEW.id_change_set - WHERE NOT OLD.price_local_VAT_excl <=> NEW.price_local_VAT_excl - UNION - -- Changed id_stripe_price - SELECT NEW.id_price, 'id_stripe_price', OLD.id_stripe_price, NEW.id_stripe_price, NEW.id_change_set - WHERE NOT OLD.id_stripe_price <=> NEW.id_stripe_price - UNION - -- Changed active - SELECT NEW.id_price, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; -END // -DELIMITER ; diff --git a/static/MySQL/3224_tri_Shop_Product_Image.sql b/static/MySQL/3224_tri_Shop_Product_Image.sql deleted file mode 100644 index 6b53a70f..00000000 --- a/static/MySQL/3224_tri_Shop_Product_Image.sql +++ /dev/null @@ -1,73 +0,0 @@ - --- Shop Image - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Product_Image; -DROP TRIGGER IF EXISTS before_update_Shop_Product_Image; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Product_Image -BEFORE INSERT ON Shop_Product_Image -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Product_Image -BEFORE UPDATE ON Shop_Product_Image -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change set ID must be provided.'; - END IF; - IF ISNULL(NEW.id_permutation) THEN -- ISNULL(NEW.id_product) AND - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Image must NOT have ID for product AND product permutation.'; - END IF; - - INSERT INTO Shop_Product_Image_Audit ( - id_image, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_type_image - SELECT NEW.id_image, 'id_type_image', CONVERT(OLD.id_type_image, CHAR), CONVERT(NEW.id_type_image, CHAR), NEW.id_change_set - WHERE NOT OLD.id_type_image <=> NEW.id_type_image - UNION - /* - -- Changed id_type_file - SELECT NEW.id_image, 'id_type_file', CONVERT(OLD.id_type_file, CHAR), CONVERT(NEW.id_type_file, CHAR), NEW.id_change_set - WHERE NOT OLD.id_type_file <=> NEW.id_type_file - UNION - -- Changed id_product - SELECT NEW.id_image, 'id_product', CONVERT(OLD.id_product, CHAR), CONVERT(NEW.id_product, CHAR), NEW.id_change_set - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - */ - -- Changed id_permutation - SELECT NEW.id_image, 'id_permutation', CONVERT(OLD.id_permutation, CHAR), CONVERT(NEW.id_permutation, CHAR), NEW.id_change_set - WHERE NOT OLD.id_permutation <=> NEW.id_permutation - UNION - -- Changed url - SELECT NEW.id_image, 'url', OLD.url, NEW.url, NEW.id_change_set - WHERE NOT OLD.url <=> NEW.url - UNION - -- Changed active - SELECT NEW.id_image, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_image, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; -END // -DELIMITER ; \ No newline at end of file diff --git a/static/MySQL/3227_tri_Shop_Delivery_Option.sql b/static/MySQL/3227_tri_Shop_Delivery_Option.sql deleted file mode 100644 index 736c0cb4..00000000 --- a/static/MySQL/3227_tri_Shop_Delivery_Option.sql +++ /dev/null @@ -1,73 +0,0 @@ - --- Shop Delivery Option Type - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Delivery_Option; -DROP TRIGGER IF EXISTS before_update_Shop_Delivery_Option; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Delivery_Option -BEFORE INSERT ON Shop_Delivery_Option -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Delivery_Option -BEFORE UPDATE ON Shop_Delivery_Option -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Delivery_Option_Audit ( - id_option, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_option, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_option, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed latency_delivery_min - SELECT NEW.id_option, 'latency_delivery_min', CONVERT(OLD.latency_delivery_min, CHAR), CONVERT(NEW.latency_delivery_min, CHAR), NEW.id_change_set - WHERE NOT OLD.latency_delivery_min <=> NEW.latency_delivery_min - UNION - -- Changed latency_delivery_max - SELECT NEW.id_option, 'latency_delivery_max', CONVERT(OLD.latency_delivery_max, CHAR), CONVERT(NEW.latency_delivery_max, CHAR), NEW.id_change_set - WHERE NOT OLD.latency_delivery_max <=> NEW.latency_delivery_max - /* - UNION - -- Changed quantity_min - SELECT NEW.id_option, 'quantity_min', CONVERT(OLD.quantity_min, CHAR), CONVERT(NEW.quantity_min, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_min <=> NEW.quantity_min - UNION - -- Changed quantity_max - SELECT NEW.id_option, 'quantity_max', CONVERT(OLD.quantity_max, CHAR), CONVERT(NEW.quantity_max, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - */ - UNION - -- Changed active - SELECT NEW.id_option, 'active', CONVERT(OLD.active, CHAR), CONVERT(NEW.active, CHAR), NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - UNION - -- Changed display_order - SELECT NEW.id_option, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; -END // -DELIMITER ; \ No newline at end of file diff --git a/static/MySQL/3230_tri_Shop_Product_Permutation_Delivery_Option_Link.sql b/static/MySQL/3230_tri_Shop_Product_Permutation_Delivery_Option_Link.sql deleted file mode 100644 index 8f650ca2..00000000 --- a/static/MySQL/3230_tri_Shop_Product_Permutation_Delivery_Option_Link.sql +++ /dev/null @@ -1,79 +0,0 @@ - --- Shop Product Delivery Option Link - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Product_Permutation_Delivery_Option_Link; -DROP TRIGGER IF EXISTS before_update_Shop_Product_Permutation_Delivery_Option_Link; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Product_Permutation_Delivery_Option_Link -BEFORE INSERT ON Shop_Product_Permutation_Delivery_Option_Link -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Product_Permutation_Delivery_Option_Link -BEFORE UPDATE ON Shop_Product_Permutation_Delivery_Option_Link -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Product_Permutation_Delivery_Option_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_product - SELECT NEW.id_link, 'id_product', CONVERT(OLD.id_product, CHAR), CONVERT(NEW.id_product, CHAR), NEW.id_change_set - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed id_permutation - SELECT NEW.id_link, 'id_permutation', CONVERT(OLD.id_permutation, CHAR), CONVERT(NEW.id_permutation, CHAR), NEW.id_change_set - WHERE NOT OLD.id_permutation <=> NEW.id_permutation - UNION - -- Changed id_option - SELECT NEW.id_link, 'id_option', CONVERT(OLD.id_option, CHAR), CONVERT(NEW.id_option, CHAR), NEW.id_change_set - WHERE NOT OLD.id_option <=> NEW.id_option - UNION - -- Changed id_region - SELECT NEW.id_link, 'id_region', CONVERT(OLD.id_region, CHAR), CONVERT(NEW.id_region, CHAR), NEW.id_change_set - WHERE NOT OLD.id_region <=> NEW.id_region - UNION - */ - -- Changed price_local - SELECT NEW.id_link, 'price_local', CONVERT(OLD.price_local, CHAR), CONVERT(NEW.price_local, CHAR), NEW.id_change_set - WHERE NOT OLD.price_local <=> NEW.price_local - /* - UNION - -- Changed quantity_min - SELECT NEW.id_link, 'quantity_min', CONVERT(OLD.quantity_min, CHAR), CONVERT(NEW.quantity_min, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_min <=> NEW.quantity_min - UNION - -- Changed quantity_max - SELECT NEW.id_link, 'quantity_max', CONVERT(OLD.quantity_max, CHAR), CONVERT(NEW.quantity_max, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - */ - UNION - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_link, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; -END // -DELIMITER ; \ No newline at end of file diff --git a/static/MySQL/3233_tri_Shop_Discount.sql b/static/MySQL/3233_tri_Shop_Discount.sql deleted file mode 100644 index ae5da9aa..00000000 --- a/static/MySQL/3233_tri_Shop_Discount.sql +++ /dev/null @@ -1,83 +0,0 @@ - --- Shop Discount - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Discount; -DROP TRIGGER IF EXISTS before_update_Shop_Discount; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Discount -BEFORE INSERT ON Shop_Discount -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - -DELIMITER // -CREATE TRIGGER before_update_Shop_Discount -BEFORE UPDATE ON Shop_Discount -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Discount_Audit ( - id_discount, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_discount, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_discount, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed multiplier - SELECT NEW.id_discount, 'multiplier', OLD.multiplier, NEW.multiplier, NEW.id_change_set - WHERE NOT OLD.multiplier <=> NEW.multiplier - UNION - -- Changed subtractor - SELECT NEW.id_discount, 'subtractor', OLD.subtractor, NEW.subtractor, NEW.id_change_set - WHERE NOT OLD.subtractor <=> NEW.subtractor - UNION - -- Changed apply_multiplier_first - SELECT NEW.id_discount, 'apply_multiplier_first', CONVERT(CONVERT(OLD.apply_multiplier_first, SIGNED), CHAR), CONVERT(CONVERT(NEW.apply_multiplier_first, SIGNED), CHAR), NEW.id_change_set - WHERE NOT OLD.apply_multiplier_first <=> NEW.apply_multiplier_first - UNION - -- Changed quantity_min - SELECT NEW.id_discount, 'quantity_min', OLD.quantity_min, NEW.quantity_min, NEW.id_change_set - WHERE NOT OLD.quantity_min <=> NEW.quantity_min - UNION - -- Changed quantity_max - SELECT NEW.id_discount, 'quantity_max', OLD.quantity_max, NEW.quantity_max, NEW.id_change_set - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - UNION - -- Changed date_start - SELECT NEW.id_discount, 'date_start', OLD.date_start, NEW.date_start, NEW.id_change_set - WHERE NOT OLD.date_start <=> NEW.date_start - UNION - -- Changed date_end - SELECT NEW.id_discount, 'date_end', OLD.date_end, NEW.date_end, NEW.id_change_set - WHERE NOT OLD.date_end <=> NEW.date_end - UNION - -- Changed display_order - SELECT NEW.id_discount, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - UNION - -- Changed active - SELECT NEW.id_discount, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - ; -END // -DELIMITER ; - diff --git a/static/MySQL/3236_tri_Shop_Discount_Region_Currency_Link.sql b/static/MySQL/3236_tri_Shop_Discount_Region_Currency_Link.sql deleted file mode 100644 index 6a4d8b14..00000000 --- a/static/MySQL/3236_tri_Shop_Discount_Region_Currency_Link.sql +++ /dev/null @@ -1,53 +0,0 @@ - --- Shop Discount Region Currency Link - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Discount_Region_Currency_Link; -DROP TRIGGER IF EXISTS before_update_Shop_Discount_Region_Currency_Link; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Discount_Region_Currency_Link -BEFORE INSERT ON Shop_Discount_Region_Currency_Link -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Discount_Region_Currency_Link -BEFORE UPDATE ON Shop_Discount_Region_Currency_Link -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Discount_Region_Currency_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_discount - SELECT NEW.id_link, 'id_discount', CONVERT(OLD.id_discount, CHAR), CONVERT(NEW.id_discount, CHAR), NEW.id_change_set - WHERE NOT OLD.id_discount <=> NEW.id_discount - UNION - -- Changed id_region - SELECT NEW.id_link, 'id_region', CONVERT(OLD.id_region, CHAR), CONVERT(NEW.id_region, CHAR), NEW.id_change_set - WHERE NOT OLD.id_region <=> NEW.id_region - UNION - */ - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; -END // -DELIMITER ; \ No newline at end of file diff --git a/static/MySQL/3300_tri_Shop_Permission_Group.sql b/static/MySQL/3300_tri_Shop_Permission_Group.sql deleted file mode 100644 index 6084157a..00000000 --- a/static/MySQL/3300_tri_Shop_Permission_Group.sql +++ /dev/null @@ -1,55 +0,0 @@ - --- Shop Permission Group - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Permission_Group; -DROP TRIGGER IF EXISTS before_update_Shop_Permission_Group; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Permission_Group -BEFORE INSERT ON Shop_Permission_Group -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Permission_Group -BEFORE UPDATE ON Shop_Permission_Group -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Permission_Group_Audit ( - id_group, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_group, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_group, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed active - SELECT NEW.id_group, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_group, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; -END // -DELIMITER ; \ No newline at end of file diff --git a/static/MySQL/3303_tri_Shop_Permission.sql b/static/MySQL/3303_tri_Shop_Permission.sql deleted file mode 100644 index 8fdcd006..00000000 --- a/static/MySQL/3303_tri_Shop_Permission.sql +++ /dev/null @@ -1,63 +0,0 @@ - --- Shop Permission - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Permission; -DROP TRIGGER IF EXISTS before_update_Shop_Permission; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Permission -BEFORE INSERT ON Shop_Permission -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Permission -BEFORE UPDATE ON Shop_Permission -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Permission_Audit ( - id_permission, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_permission, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_permission, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed id_permission_group - SELECT NEW.id_permission, 'id_permission_group', CONVERT(OLD.id_permission_group, CHAR), CONVERT(NEW.id_permission_group, CHAR), NEW.id_change_set - WHERE NOT OLD.id_permission_group <=> NEW.id_permission_group - UNION - -- Changed Id_access_level_required - SELECT NEW.id_permission, 'Id_access_level_required', CONVERT(OLD.Id_access_level_required, CHAR), CONVERT(NEW.Id_access_level_required, CHAR), NEW.id_change_set - WHERE NOT OLD.Id_access_level_required <=> NEW.Id_access_level_required - UNION - -- Changed active - SELECT NEW.id_permission, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_permission, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; -END // -DELIMITER ; \ No newline at end of file diff --git a/static/MySQL/3315_tri_Shop_User_Role_Link.sql b/static/MySQL/3315_tri_Shop_User_Role_Link.sql deleted file mode 100644 index 1d5f9f69..00000000 --- a/static/MySQL/3315_tri_Shop_User_Role_Link.sql +++ /dev/null @@ -1,43 +0,0 @@ - --- Shop User Role Link - - - -DROP TRIGGER IF EXISTS before_insert_Shop_User_Role_Link; -DROP TRIGGER IF EXISTS before_update_Shop_User_Role_Link; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_User_Role_Link -BEFORE INSERT ON Shop_User_Role_Link -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_User_Role_Link -BEFORE UPDATE ON Shop_User_Role_Link -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_User_Role_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; -END // -DELIMITER ; \ No newline at end of file diff --git a/static/MySQL/3318_tri_Shop_User_Address.sql b/static/MySQL/3318_tri_Shop_User_Address.sql deleted file mode 100644 index 75464a8a..00000000 --- a/static/MySQL/3318_tri_Shop_User_Address.sql +++ /dev/null @@ -1,75 +0,0 @@ - --- Shop Address - - - -DROP TRIGGER IF EXISTS before_insert_Shop_User_Address; -DROP TRIGGER IF EXISTS before_update_Shop_User_Address; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_User_Address -BEFORE INSERT ON Shop_User_Address -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_User_Address -BEFORE UPDATE ON Shop_User_Address -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_User_Address_Audit ( - id_user_address, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed region - SELECT NEW.id_user_address, 'id_region', OLD.id_region, NEW.id_region, NEW.id_change_set - WHERE NOT OLD.id_region <=> NEW.id_region - UNION - -- Changed name_full - SELECT NEW.id_user_address, 'name_full', OLD.name_full, NEW.name_full, NEW.id_change_set - WHERE NOT OLD.name_full <=> NEW.name_full - UNION - -- Changed phone_number - SELECT NEW.id_user_address, 'phone_number', OLD.phone_number, NEW.phone_number, NEW.id_change_set - WHERE NOT OLD.phone_number <=> NEW.phone_number - UNION - -- Changed postcode - SELECT NEW.id_user_address, 'postcode', OLD.postcode, NEW.postcode, NEW.id_change_set - WHERE NOT OLD.postcode <=> NEW.postcode - UNION - -- Changed address_line_1 - SELECT NEW.id_user_address, 'address_line_1', OLD.address_line_1, NEW.address_line_1, NEW.id_change_set - WHERE NOT OLD.address_line_1 <=> NEW.address_line_1 - UNION - -- Changed address_line_2 - SELECT NEW.id_user_address, 'address_line_2', OLD.address_line_2, NEW.address_line_2, NEW.id_change_set - WHERE NOT OLD.address_line_2 <=> NEW.address_line_2 - UNION - -- Changed city - SELECT NEW.id_user_address, 'city', OLD.city, NEW.city, NEW.id_change_set - WHERE NOT OLD.city <=> NEW.city - UNION - -- Changed county - SELECT NEW.id_user_address, 'county', OLD.county, NEW.county, NEW.id_change_set - WHERE NOT OLD.county <=> NEW.county - UNION - -- Changed active - SELECT NEW.id_user_address, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; -END // -DELIMITER ; \ No newline at end of file diff --git a/static/MySQL/3321_tri_Shop_User_Basket.sql b/static/MySQL/3321_tri_Shop_User_Basket.sql deleted file mode 100644 index 5957474d..00000000 --- a/static/MySQL/3321_tri_Shop_User_Basket.sql +++ /dev/null @@ -1,55 +0,0 @@ - --- Shop Product Variation Link - - - -DROP TRIGGER IF EXISTS before_insert_Shop_User_Basket; -DROP TRIGGER IF EXISTS before_update_Shop_User_Basket; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_User_Basket -BEFORE INSERT ON Shop_User_Basket -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_User_Basket -BEFORE UPDATE ON Shop_User_Basket -FOR EACH ROW -BEGIN - IF NEW.id_change_set_user <=> OLD.id_change_set_user THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_User_Basket_Audit ( - id_item, - name_field, - value_prev, - value_new, - id_change_set_user - ) - -- Changed id_user - SELECT NEW.id_item, 'id_user', OLD.id_user, NEW.id_user, NEW.id_change_set_user - WHERE NOT OLD.id_user <=> NEW.id_user - UNION - -- Changed id_product - SELECT NEW.id_item, 'id_product', OLD.id_product, NEW.id_product, NEW.id_change_set_user - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed quantity - SELECT NEW.id_item, 'quantity', CONVERT(OLD.quantity, CHAR), CONVERT(NEW.quantity, CHAR), NEW.id_change_set_user - WHERE NOT (OLD.quantity <=> NEW.quantity) - UNION - -- Changed active - SELECT NEW.id_item, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set_user - WHERE NOT (OLD.active <=> NEW.active) - ; -END // -DELIMITER ; \ No newline at end of file diff --git a/static/MySQL/3324_tri_Shop_User_Order_Status.sql b/static/MySQL/3324_tri_Shop_User_Order_Status.sql deleted file mode 100644 index 706c1fab..00000000 --- a/static/MySQL/3324_tri_Shop_User_Order_Status.sql +++ /dev/null @@ -1,59 +0,0 @@ - --- Shop User Order Type - - - -DROP TRIGGER IF EXISTS before_insert_Shop_User_Order_Status; -DROP TRIGGER IF EXISTS before_update_Shop_User_Order_Status; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_User_Order_Status -BEFORE INSERT ON Shop_User_Order_Status -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_User_Order_Status -BEFORE UPDATE ON Shop_User_Order_Status -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_User_Order_Status_Audit ( - id_Status, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_Status, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_Status, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed name_plural - SELECT NEW.id_Status, 'name_plural', OLD.name_plural, NEW.name_plural, NEW.id_change_set - WHERE NOT OLD.name_plural <=> NEW.name_plural - UNION - -- Changed active - SELECT NEW.id_Status, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_Status, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; -END // -DELIMITER ; \ No newline at end of file diff --git a/static/MySQL/3400_tri_Shop_Supplier.sql b/static/MySQL/3400_tri_Shop_Supplier.sql deleted file mode 100644 index daa019e8..00000000 --- a/static/MySQL/3400_tri_Shop_Supplier.sql +++ /dev/null @@ -1,81 +0,0 @@ - --- Shop Supplier - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Supplier; -DROP TRIGGER IF EXISTS before_update_Shop_Supplier; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Supplier -BEFORE INSERT ON Shop_Supplier -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Supplier -BEFORE UPDATE ON Shop_Supplier -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Supplier_Audit ( - id_supplier, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed name_company - SELECT NEW.id_supplier, 'name_company', OLD.name_company, NEW.name_company, NEW.id_change_set - WHERE NOT OLD.name_company <=> NEW.name_company - UNION - -- Changed name_contact - SELECT NEW.id_supplier, 'name_contact', OLD.name_contact, NEW.name_contact, NEW.id_change_set - WHERE NOT OLD.name_contact <=> NEW.name_contact - UNION - -- Changed department_contact - SELECT NEW.id_supplier, 'department_contact', OLD.department_contact, NEW.department_contact, NEW.id_change_set - WHERE NOT OLD.department_contact <=> NEW.department_contact - UNION - /* - -- Changed id_address - SELECT NEW.id_supplier, 'id_address', OLD.id_address, NEW.id_address, NEW.id_change_set - WHERE NOT OLD.id_address <=> NEW.id_address - UNION - */ - -- Changed phone_number - SELECT NEW.id_supplier, 'phone_number', OLD.phone_number, NEW.phone_number, NEW.id_change_set - WHERE NOT OLD.phone_number <=> NEW.phone_number - UNION - -- Changed fax - SELECT NEW.id_supplier, 'fax', OLD.fax, NEW.fax, NEW.id_change_set - WHERE NOT OLD.fax <=> NEW.fax - UNION - -- Changed email - SELECT NEW.id_supplier, 'email', OLD.email, NEW.email, NEW.id_change_set - WHERE NOT OLD.email <=> NEW.email - UNION - -- Changed website - SELECT NEW.id_supplier, 'website', OLD.website, NEW.website, NEW.id_change_set - WHERE NOT OLD.website <=> NEW.website - UNION - -- Changed id_currency - SELECT NEW.id_supplier, 'id_currency', OLD.id_currency, NEW.id_currency, NEW.id_change_set - WHERE NOT OLD.id_currency <=> NEW.id_currency - UNION - -- Changed id_supplier_temp - SELECT NEW.id_supplier, 'id_supplier_temp', OLD.id_supplier_temp, NEW.id_supplier_temp, NEW.id_change_set - WHERE NOT OLD.id_supplier_temp <=> NEW.id_supplier_temp - ; -END // -DELIMITER ; diff --git a/static/MySQL/3403_tri_Shop_Supplier_Address.sql b/static/MySQL/3403_tri_Shop_Supplier_Address.sql deleted file mode 100644 index f22a1e75..00000000 --- a/static/MySQL/3403_tri_Shop_Supplier_Address.sql +++ /dev/null @@ -1,65 +0,0 @@ - --- Shop Supplier Address - -DROP TRIGGER IF EXISTS before_insert_Shop_Supplier_Address; -DROP TRIGGER IF EXISTS before_update_Shop_Supplier_Address; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Supplier_Address -BEFORE INSERT ON Shop_Supplier_Address -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Supplier_Address -BEFORE UPDATE ON Shop_Supplier_Address -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Supplier_Address_Audit ( - id_address, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed region - SELECT NEW.id_address, 'id_region', OLD.id_region, NEW.id_region, NEW.id_change_set - WHERE NOT OLD.id_region <=> NEW.id_region - UNION - -- Changed postcode - SELECT NEW.id_address, 'postcode', OLD.postcode, NEW.postcode, NEW.id_change_set - WHERE NOT OLD.postcode <=> NEW.postcode - UNION - -- Changed address_line_1 - SELECT NEW.id_address, 'address_line_1', OLD.address_line_1, NEW.address_line_1, NEW.id_change_set - WHERE NOT OLD.address_line_1 <=> NEW.address_line_1 - UNION - -- Changed address_line_2 - SELECT NEW.id_address, 'address_line_2', OLD.address_line_2, NEW.address_line_2, NEW.id_change_set - WHERE NOT OLD.address_line_2 <=> NEW.address_line_2 - UNION - -- Changed city - SELECT NEW.id_address, 'city', OLD.city, NEW.city, NEW.id_change_set - WHERE NOT OLD.city <=> NEW.city - UNION - -- Changed county - SELECT NEW.id_address, 'county', OLD.county, NEW.county, NEW.id_change_set - WHERE NOT OLD.county <=> NEW.county - UNION - -- Changed active - SELECT NEW.id_address, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; -END // -DELIMITER ; \ No newline at end of file diff --git a/static/MySQL/3403_tri_Shop_Unit_Measurement.sql b/static/MySQL/3403_tri_Shop_Unit_Measurement.sql deleted file mode 100644 index 34279869..00000000 --- a/static/MySQL/3403_tri_Shop_Unit_Measurement.sql +++ /dev/null @@ -1,76 +0,0 @@ - --- Shop Unit of Measurement - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Unit_Measurement; -DROP TRIGGER IF EXISTS before_update_Shop_Unit_Measurement; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Unit_Measurement -BEFORE INSERT ON Shop_Unit_Measurement -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Unit_Measurement -BEFORE UPDATE ON Shop_Unit_Measurement -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Unit_Measurement_Audit ( - id_unit_measurement, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed name_singular - SELECT NEW.id_unit_measurement, 'name_singular', OLD.name_singular, NEW.name_singular, NEW.id_change_set - WHERE NOT OLD.name_singular <=> NEW.name_singular - UNION - -- Changed name_plural - SELECT NEW.id_unit_measurement, 'name_plural', OLD.name_plural, NEW.name_plural, NEW.id_change_set - WHERE NOT OLD.name_plural <=> NEW.name_plural - UNION - -- Changed symbol - SELECT NEW.id_unit_measurement, 'symbol', OLD.symbol, NEW.symbol, NEW.id_change_set - WHERE NOT OLD.symbol <=> NEW.symbol - UNION - -- Changed is_base_unit - SELECT NEW.id_unit_measurement, 'is_base_unit', OLD.is_base_unit, NEW.is_base_unit, NEW.id_change_set - WHERE NOT OLD.is_base_unit <=> NEW.is_base_unit - UNION - -- Changed is_unit_of_distance - SELECT NEW.id_unit_measurement, 'is_unit_of_distance', OLD.is_unit_of_distance, NEW.is_unit_of_distance, NEW.id_change_set - WHERE NOT OLD.is_unit_of_distance <=> NEW.is_unit_of_distance - UNION - -- Changed is_unit_of_mass - SELECT NEW.id_unit_measurement, 'is_unit_of_mass', OLD.is_unit_of_mass, NEW.is_unit_of_mass, NEW.id_change_set - WHERE NOT OLD.is_unit_of_mass <=> NEW.is_unit_of_mass - UNION - -- Changed is_unit_of_time - SELECT NEW.id_unit_measurement, 'is_unit_of_time', OLD.is_unit_of_time, NEW.is_unit_of_time, NEW.id_change_set - WHERE NOT OLD.is_unit_of_time <=> NEW.is_unit_of_time - UNION - -- Changed is_unit_of_volume - SELECT NEW.id_unit_measurement, 'is_unit_of_volume', OLD.is_unit_of_volume, NEW.is_unit_of_volume, NEW.id_change_set - WHERE NOT OLD.is_unit_of_volume <=> NEW.is_unit_of_volume - UNION - -- Changed active - SELECT NEW.id_unit_measurement, 'active', OLD.active, NEW.active, NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - ; -END // -DELIMITER ; - diff --git a/static/MySQL/3406_tri_Shop_Unit_Of_Measurement_Conversion.sql b/static/MySQL/3406_tri_Shop_Unit_Of_Measurement_Conversion.sql deleted file mode 100644 index fa4263c0..00000000 --- a/static/MySQL/3406_tri_Shop_Unit_Of_Measurement_Conversion.sql +++ /dev/null @@ -1,64 +0,0 @@ - --- Shop Unit of Measurement Conversion - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Unit_Measurement_Conversion; -DROP TRIGGER IF EXISTS before_update_Shop_Unit_Measurement_Conversion; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Unit_Measurement_Conversion -BEFORE INSERT ON Shop_Unit_Measurement_Conversion -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Unit_Measurement_Conversion -BEFORE UPDATE ON Shop_Unit_Measurement_Conversion -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Unit_Measurement_Conversion_Audit ( - id_conversion, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_unit_derived - SELECT NEW.id_conversion, 'id_unit_derived', OLD.id_unit_derived, NEW.id_unit_derived, NEW.id_change_set - WHERE NOT OLD.id_unit_derived <=> NEW.id_unit_derived - UNION - -- Changed id_unit_base - SELECT NEW.id_conversion, 'id_unit_base', OLD.id_unit_base, NEW.id_unit_base, NEW.id_change_set - WHERE NOT OLD.id_unit_base <=> NEW.id_unit_base - UNION - -- Changed multiplier_unit_base - SELECT NEW.id_conversion, 'multiplier_unit_base', OLD.multiplier_unit_base, NEW.multiplier_unit_base, NEW.id_change_set - WHERE NOT OLD.multiplier_unit_base <=> NEW.multiplier_unit_base - UNION - -- Changed increment_unit_base - SELECT NEW.id_conversion, 'active', OLD.increment_unit_base, NEW.increment_unit_base, NEW.id_change_set - WHERE NOT OLD.increment_unit_base <=> NEW.increment_unit_base - UNION - -- Changed apply_multiplier_before_increment - SELECT NEW.id_conversion, 'apply_multiplier_before_increment', OLD.apply_multiplier_before_increment, NEW.apply_multiplier_before_increment, NEW.id_change_set - WHERE NOT OLD.apply_multiplier_before_increment <=> NEW.apply_multiplier_before_increment - UNION - -- Changed active - SELECT NEW.id_conversion, 'active', OLD.active, NEW.active, NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - ; -END // -DELIMITER ; - diff --git a/static/MySQL/3409_tri_Shop_Supplier_Purchase_Order.sql b/static/MySQL/3409_tri_Shop_Supplier_Purchase_Order.sql deleted file mode 100644 index b4b9df3c..00000000 --- a/static/MySQL/3409_tri_Shop_Supplier_Purchase_Order.sql +++ /dev/null @@ -1,78 +0,0 @@ - --- Shop Supplier Purchase Order - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Supplier_Purchase_Order; -DROP TRIGGER IF EXISTS before_update_Shop_Supplier_Purchase_Order; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Supplier_Purchase_Order -BEFORE INSERT ON Shop_Supplier_Purchase_Order -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Supplier_Purchase_Order -BEFORE UPDATE ON Shop_Supplier_Purchase_Order -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Supplier_Purchase_Order_Audit ( - id_order, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_order_temp - SELECT NEW.id_order, 'id_order_temp', OLD.id_order_temp, NEW.id_order_temp, NEW.id_change_set - WHERE NOT OLD.id_order_temp <=> NEW.id_order_temp - UNION - -- Changed id_supplier_ordered - SELECT NEW.id_order, 'id_supplier_ordered', OLD.id_supplier_ordered, NEW.id_supplier_ordered, NEW.id_change_set - WHERE NOT OLD.id_supplier_ordered <=> NEW.id_supplier_ordered - UNION - -- Changed id_currency_cost - SELECT NEW.id_order, 'id_currency_cost', OLD.id_currency_cost, NEW.id_currency_cost, NEW.id_change_set - WHERE NOT OLD.id_currency_cost <=> NEW.id_currency_cost - UNION - -- Changed cost_total_local_VAT_excl - SELECT NEW.id_order, 'cost_total_local_VAT_excl', OLD.cost_total_local_VAT_excl, NEW.cost_total_local_VAT_excl, NEW.id_change_set - WHERE NOT OLD.cost_total_local_VAT_excl <=> NEW.cost_total_local_VAT_excl - UNION - -- Changed cost_total_local_VAT_incl - SELECT NEW.id_order, 'cost_total_local_VAT_incl', OLD.cost_total_local_VAT_incl, NEW.cost_total_local_VAT_incl, NEW.id_change_set - WHERE NOT OLD.cost_total_local_VAT_incl <=> NEW.cost_total_local_VAT_incl - /* - UNION - -- Changed latency_delivery - SELECT NEW.id_order, 'latency_delivery', OLD.latency_delivery, NEW.latency_delivery, NEW.id_change_set - WHERE NOT OLD.latency_delivery <=> NEW.latency_delivery - UNION - -- Changed quantity_ordered - SELECT NEW.id_order, 'quantity_ordered', OLD.quantity_ordered, NEW.quantity_ordered, NEW.id_change_set - WHERE NOT OLD.quantity_ordered <=> NEW.quantity_ordered - UNION - -- Changed id_unit_quantity - SELECT NEW.id_order, 'id_unit_quantity', OLD.id_unit_quantity, NEW.id_unit_quantity, NEW.id_change_set - WHERE NOT OLD.id_unit_quantity <=> NEW.id_unit_quantity - UNION - -- Changed quantity_received - SELECT NEW.id_order, 'quantity_received', OLD.quantity_received, NEW.quantity_received, NEW.id_change_set - WHERE NOT OLD.quantity_received <=> NEW.quantity_received - */ - ; -END // -DELIMITER ; - diff --git a/static/MySQL/3412_tri_Shop_Supplier_Purchase_Order_Product_Link.sql b/static/MySQL/3412_tri_Shop_Supplier_Purchase_Order_Product_Link.sql deleted file mode 100644 index b1a08c70..00000000 --- a/static/MySQL/3412_tri_Shop_Supplier_Purchase_Order_Product_Link.sql +++ /dev/null @@ -1,93 +0,0 @@ - --- Shop Supplier Purchase Order Product Link - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Supplier_Purchase_Order_Product_Link; -DROP TRIGGER IF EXISTS before_update_Shop_Supplier_Purchase_Order_Product_Link; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Supplier_Purchase_Order_Product_Link -BEFORE INSERT ON Shop_Supplier_Purchase_Order_Product_Link -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Supplier_Purchase_Order_Product_Link -BEFORE UPDATE ON Shop_Supplier_Purchase_Order_Product_Link -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Supplier_Purchase_Order_Product_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_order - SELECT NEW.id_link, 'id_order', OLD.id_order, NEW.id_order, NEW.id_change_set - WHERE NOT OLD.id_order <=> NEW.id_order - UNION - -- Changed id_permutation - SELECT NEW.id_link, 'id_permutation', OLD.id_permutation, NEW.id_permutation, NEW.id_change_set - WHERE NOT OLD.id_permutation <=> NEW.id_permutation - UNION - /* - -- Changed id_currency_cost - SELECT NEW.id_link, 'id_currency_cost', OLD.id_currency_cost, NEW.id_currency_cost, NEW.id_change_set - WHERE NOT OLD.id_currency_cost <=> NEW.id_currency_cost - UNION - */ - -- Changed quantity_ordered - SELECT NEW.id_link, 'quantity_ordered', OLD.quantity_ordered, NEW.quantity_ordered, NEW.id_change_set - WHERE NOT OLD.quantity_ordered <=> NEW.quantity_ordered - UNION - -- Changed id_unit_quantity - SELECT NEW.id_link, 'id_unit_quantity', OLD.id_unit_quantity, NEW.id_unit_quantity, NEW.id_change_set - WHERE NOT OLD.id_unit_quantity <=> NEW.id_unit_quantity - UNION - -- Changed quantity_received - SELECT NEW.id_link, 'quantity_received', OLD.quantity_received, NEW.quantity_received, NEW.id_change_set - WHERE NOT OLD.quantity_received <=> NEW.quantity_received - UNION - -- Changed latency_delivery_days - SELECT NEW.id_link, 'latency_delivery_days', OLD.latency_delivery_days, NEW.latency_delivery_days, NEW.id_change_set - WHERE NOT OLD.latency_delivery_days <=> NEW.latency_delivery_days - UNION - -- Changed display_order - SELECT NEW.id_link, 'display_order', OLD.display_order, NEW.display_order, NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - UNION - -- Changed active - SELECT NEW.id_link, 'active', OLD.active, NEW.active, NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - UNION - -- Changed cost_total_local_VAT_excl - SELECT NEW.id_link, 'cost_total_local_VAT_excl', OLD.cost_total_local_VAT_excl, NEW.cost_total_local_VAT_excl, NEW.id_change_set - WHERE NOT OLD.cost_total_local_VAT_excl <=> NEW.cost_total_local_VAT_excl - UNION - -- Changed cost_total_local_VAT_incl - SELECT NEW.id_link, 'cost_total_local_VAT_incl', OLD.cost_total_local_VAT_incl, NEW.cost_total_local_VAT_incl, NEW.id_change_set - WHERE NOT OLD.cost_total_local_VAT_incl <=> NEW.cost_total_local_VAT_incl - UNION - -- Changed cost_unit_local_VAT_excl - SELECT NEW.id_link, 'cost_unit_local_VAT_excl', OLD.cost_unit_local_VAT_excl, NEW.cost_unit_local_VAT_excl, NEW.id_change_set - WHERE NOT OLD.cost_unit_local_VAT_excl <=> NEW.cost_unit_local_VAT_excl - UNION - -- Changed cost_unit_local_VAT_incl - SELECT NEW.id_link, 'cost_unit_local_VAT_incl', OLD.cost_unit_local_VAT_incl, NEW.cost_unit_local_VAT_incl, NEW.id_change_set - WHERE NOT OLD.cost_unit_local_VAT_incl <=> NEW.cost_unit_local_VAT_incl - ; -END // -DELIMITER ; diff --git a/static/MySQL/3415_tri_Shop_Manufacturing_Purchase_Order.sql b/static/MySQL/3415_tri_Shop_Manufacturing_Purchase_Order.sql deleted file mode 100644 index 7fd5e9f4..00000000 --- a/static/MySQL/3415_tri_Shop_Manufacturing_Purchase_Order.sql +++ /dev/null @@ -1,71 +0,0 @@ - --- Shop Manufacturing Purchase Order - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Manufacturing_Purchase_Order; -DROP TRIGGER IF EXISTS before_update_Shop_Manufacturing_Purchase_Order; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Manufacturing_Purchase_Order -BEFORE INSERT ON Shop_Manufacturing_Purchase_Order -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - -- SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - IF NOT EXISTS (SELECT * FROM partsltd_prod.Shop_User U WHERE U.id_user = NEW.created_by LIMIT 1) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Valid created by User ID must be provided.'; - END IF; -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Manufacturing_Purchase_Order -BEFORE UPDATE ON Shop_Manufacturing_Purchase_Order -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Manufacturing_Purchase_Order_Audit ( - id_order, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_order_temp - SELECT NEW.id_order, 'id_order_temp', OLD.id_order_temp, NEW.id_order_temp, NEW.id_change_set - WHERE NOT OLD.id_order_temp <=> NEW.id_order_temp - UNION - -- Changed id_currency - SELECT NEW.id_order, 'id_currency', OLD.id_currency, NEW.id_currency, NEW.id_change_set - WHERE NOT OLD.id_currency <=> NEW.id_currency - UNION - -- Changed cost_total_local_VAT_excl - SELECT NEW.id_order, 'cost_total_local_VAT_excl', OLD.cost_total_local_VAT_excl, NEW.cost_total_local_VAT_excl, NEW.id_change_set - WHERE NOT OLD.cost_total_local_VAT_excl <=> NEW.cost_total_local_VAT_excl - UNION - -- Changed cost_total_local_VAT_incl - SELECT NEW.id_order, 'cost_total_local_VAT_incl', OLD.cost_total_local_VAT_incl, NEW.cost_total_local_VAT_incl, NEW.id_change_set - WHERE NOT OLD.cost_total_local_VAT_incl <=> NEW.cost_total_local_VAT_incl - UNION - -- Changed price_total_local_VAT_excl - SELECT NEW.id_order, 'price_total_local_VAT_excl', OLD.price_total_local_VAT_excl, NEW.price_total_local_VAT_excl, NEW.id_change_set - WHERE NOT OLD.price_total_local_VAT_excl <=> NEW.price_total_local_VAT_excl - UNION - -- Changed price_total_local_VAT_incl - SELECT NEW.id_order, 'price_total_local_VAT_incl', OLD.price_total_local_VAT_incl, NEW.price_total_local_VAT_incl, NEW.id_change_set - WHERE NOT OLD.price_total_local_VAT_incl <=> NEW.price_total_local_VAT_incl - UNION - -- Changed active - SELECT NEW.id_order, 'active', OLD.active, NEW.active, NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - ; -END // -DELIMITER ; diff --git a/static/MySQL/3418_tri_Shop_Manufacturing_Purchase_Order_Product_Link.sql b/static/MySQL/3418_tri_Shop_Manufacturing_Purchase_Order_Product_Link.sql deleted file mode 100644 index 9d90aafd..00000000 --- a/static/MySQL/3418_tri_Shop_Manufacturing_Purchase_Order_Product_Link.sql +++ /dev/null @@ -1,92 +0,0 @@ - --- Shop Manufacturing Purchase Order Product Link - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Manufacturing_Purchase_Order_Product_Link; -DROP TRIGGER IF EXISTS before_update_Shop_Manufacturing_Purchase_Order_Product_Link; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Manufacturing_Purchase_Order_Product_Link -BEFORE INSERT ON Shop_Manufacturing_Purchase_Order_Product_Link -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Manufacturing_Purchase_Order_Product_Link -BEFORE UPDATE ON Shop_Manufacturing_Purchase_Order_Product_Link -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Manufacturing_Purchase_Order_Product_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_order - SELECT NEW.id_link, 'id_order', OLD.id_order, NEW.id_order, NEW.id_change_set - WHERE NOT OLD.id_order <=> NEW.id_order - UNION - -- Changed id_permutation - SELECT NEW.id_link, 'id_permutation', OLD.id_permutation, NEW.id_permutation, NEW.id_change_set - WHERE NOT OLD.id_permutation <=> NEW.id_permutation - UNION - -- Changed id_unit_quantity - SELECT NEW.id_link, 'id_unit_quantity', OLD.id_unit_quantity, NEW.id_unit_quantity, NEW.id_change_set - WHERE NOT OLD.id_unit_quantity <=> NEW.id_unit_quantity - UNION - -- Changed quantity_used - SELECT NEW.id_link, 'quantity_used', OLD.quantity_used, NEW.quantity_used, NEW.id_change_set - WHERE NOT OLD.quantity_used <=> NEW.quantity_used - UNION - -- Changed quantity_produced - SELECT NEW.id_link, 'quantity_produced', OLD.quantity_produced, NEW.quantity_produced, NEW.id_change_set - WHERE NOT OLD.quantity_produced <=> NEW.quantity_produced - UNION - -- Changed cost_unit_local_VAT_excl - SELECT NEW.id_order, 'cost_unit_local_VAT_excl', OLD.cost_unit_local_VAT_excl, NEW.cost_unit_local_VAT_excl, NEW.id_change_set - WHERE NOT OLD.cost_unit_local_VAT_excl <=> NEW.cost_unit_local_VAT_excl - UNION - -- Changed cost_unit_local_VAT_incl - SELECT NEW.id_order, 'cost_unit_local_VAT_incl', OLD.cost_unit_local_VAT_incl, NEW.cost_unit_local_VAT_incl, NEW.id_change_set - WHERE NOT OLD.cost_unit_local_VAT_incl <=> NEW.cost_unit_local_VAT_incl - UNION - -- Changed price_unit_local_VAT_excl - SELECT NEW.id_order, 'price_unit_local_VAT_excl', OLD.price_unit_local_VAT_excl, NEW.price_unit_local_VAT_excl, NEW.id_change_set - WHERE NOT OLD.price_unit_local_VAT_excl <=> NEW.price_unit_local_VAT_excl - UNION - -- Changed price_unit_local_VAT_incl - SELECT NEW.id_order, 'price_unit_local_VAT_incl', OLD.price_unit_local_VAT_incl, NEW.price_unit_local_VAT_incl, NEW.id_change_set - WHERE NOT OLD.price_unit_local_VAT_incl <=> NEW.price_unit_local_VAT_incl - UNION - -- Changed id_unit_latency_manufacture - SELECT NEW.id_link, 'id_unit_latency_manufacture', OLD.id_unit_latency_manufacture, NEW.id_unit_latency_manufacture, NEW.id_change_set - WHERE NOT OLD.id_unit_latency_manufacture <=> NEW.id_unit_latency_manufacture - UNION - -- Changed latency_manufacture - SELECT NEW.id_link, 'latency_manufacture', OLD.latency_manufacture, NEW.latency_manufacture, NEW.id_change_set - WHERE NOT OLD.latency_manufacture <=> NEW.latency_manufacture - UNION - -- Changed display_order - SELECT NEW.id_link, 'display_order', OLD.display_order, NEW.display_order, NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - UNION - -- Changed active - SELECT NEW.id_link, 'active', OLD.active, NEW.active, NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - ; -END // -DELIMITER ; - diff --git a/static/MySQL/3421_tri_Shop_Customer.sql b/static/MySQL/3421_tri_Shop_Customer.sql deleted file mode 100644 index 425b0062..00000000 --- a/static/MySQL/3421_tri_Shop_Customer.sql +++ /dev/null @@ -1,72 +0,0 @@ - --- Shop Customer - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Customer; -DROP TRIGGER IF EXISTS before_update_Shop_Customer; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Customer -BEFORE INSERT ON Shop_Customer -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Customer -BEFORE UPDATE ON Shop_Customer -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Customer_Audit ( - id_customer, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed name_company - SELECT NEW.id_customer, 'name_company', OLD.name_company, NEW.name_company, NEW.id_change_set - WHERE NOT OLD.name_company <=> NEW.name_company - UNION - -- Changed name_contact - SELECT NEW.id_customer, 'name_contact', OLD.name_contact, NEW.name_contact, NEW.id_change_set - WHERE NOT OLD.name_contact <=> NEW.name_contact - UNION - -- Changed department_contact - SELECT NEW.id_customer, 'department_contact', OLD.department_contact, NEW.department_contact, NEW.id_change_set - WHERE NOT OLD.department_contact <=> NEW.department_contact - UNION - -- Changed id_address - SELECT NEW.id_customer, 'id_address', OLD.id_address, NEW.id_address, NEW.id_change_set - WHERE NOT OLD.id_address <=> NEW.id_address - UNION - -- Changed phone_number - SELECT NEW.id_customer, 'phone_number', OLD.phone_number, NEW.phone_number, NEW.id_change_set - WHERE NOT OLD.phone_number <=> NEW.phone_number - UNION - -- Changed email - SELECT NEW.id_customer, 'email', OLD.email, NEW.email, NEW.id_change_set - WHERE NOT OLD.email <=> NEW.email - UNION - -- Changed id_currency - SELECT NEW.id_customer, 'id_currency', OLD.id_currency, NEW.id_currency, NEW.id_change_set - WHERE NOT OLD.id_currency <=> NEW.id_currency - UNION - -- Changed active - SELECT NEW.id_customer, 'active', OLD.active, NEW.active, NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - ; -END // -DELIMITER ; - diff --git a/static/MySQL/3424_tri_Shop_Customer_Sales_Order.sql b/static/MySQL/3424_tri_Shop_Customer_Sales_Order.sql deleted file mode 100644 index f0f00dba..00000000 --- a/static/MySQL/3424_tri_Shop_Customer_Sales_Order.sql +++ /dev/null @@ -1,55 +0,0 @@ - --- Shop Customer Sales Order - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Customer_Sales_Order; -DROP TRIGGER IF EXISTS before_update_Shop_Customer_Sales_Order; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Customer_Sales_Order -BEFORE INSERT ON Shop_Customer_Sales_Order -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Customer_Sales_Order -BEFORE UPDATE ON Shop_Customer_Sales_Order -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Customer_Sales_Order_Audit ( - id_order, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_customer - SELECT NEW.id_order, 'id_customer', OLD.id_customer, NEW.id_customer, NEW.id_change_set - WHERE NOT OLD.id_customer <=> NEW.id_customer - UNION - -- Changed price_total_local - SELECT NEW.id_order, 'price_total_local', OLD.price_total_local, NEW.price_total_local, NEW.id_change_set - WHERE NOT OLD.price_total_local <=> NEW.price_total_local - UNION - -- Changed id_currency_price - SELECT NEW.id_order, 'id_currency_price', OLD.id_currency_price, NEW.id_currency_price, NEW.id_change_set - WHERE NOT OLD.id_currency_price <=> NEW.id_currency_price - UNION - -- Changed active - SELECT NEW.id_order, 'active', OLD.active, NEW.active, NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - ; -END // -DELIMITER ; diff --git a/static/MySQL/3427_tri_Shop_Customer_Sales_Order_Product_Link.sql b/static/MySQL/3427_tri_Shop_Customer_Sales_Order_Product_Link.sql deleted file mode 100644 index 5545eefb..00000000 --- a/static/MySQL/3427_tri_Shop_Customer_Sales_Order_Product_Link.sql +++ /dev/null @@ -1,79 +0,0 @@ - --- Shop Customer Sales Order Product Link - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Customer_Sales_Order_Product_Link; -DROP TRIGGER IF EXISTS before_update_Shop_Customer_Sales_Order_Product_Link; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Customer_Sales_Order_Product_Link -BEFORE INSERT ON Shop_Customer_Sales_Order_Product_Link -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Customer_Sales_Order_Product_Link -BEFORE UPDATE ON Shop_Customer_Sales_Order_Product_Link -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Customer_Sales_Order_Product_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_order - SELECT NEW.id_link, 'id_order', OLD.id_order, NEW.id_order, NEW.id_change_set - WHERE NOT OLD.id_order <=> NEW.id_order - UNION - -- Changed id_permutation - SELECT NEW.id_link, 'id_permutation', OLD.id_permutation, NEW.id_permutation, NEW.id_change_set - WHERE NOT OLD.id_permutation <=> NEW.id_permutation - UNION - -- Changed price_total_local - SELECT NEW.id_link, 'price_total_local', OLD.price_total_local, NEW.price_total_local, NEW.id_change_set - WHERE NOT OLD.price_total_local <=> NEW.price_total_local - UNION - -- Changed id_currency_price - SELECT NEW.id_link, 'id_currency_price', OLD.id_currency_price, NEW.id_currency_price, NEW.id_change_set - WHERE NOT OLD.id_currency_price <=> NEW.id_currency_price - UNION - -- Changed quantity_ordered - SELECT NEW.id_link, 'quantity_ordered', OLD.quantity_ordered, NEW.quantity_ordered, NEW.id_change_set - WHERE NOT OLD.quantity_ordered <=> NEW.quantity_ordered - UNION - -- Changed id_unit_quantity - SELECT NEW.id_link, 'id_unit_quantity', OLD.id_unit_quantity, NEW.id_unit_quantity, NEW.id_change_set - WHERE NOT OLD.id_unit_quantity <=> NEW.id_unit_quantity - UNION - -- Changed quantity_delivered - SELECT NEW.id_link, 'quantity_delivered', OLD.quantity_delivered, NEW.quantity_delivered, NEW.id_change_set - WHERE NOT OLD.quantity_delivered <=> NEW.quantity_delivered - UNION - -- Changed latency_delivery_days - SELECT NEW.id_link, 'latency_delivery_days', OLD.latency_delivery_days, NEW.latency_delivery_days, NEW.id_change_set - WHERE NOT OLD.latency_delivery_days <=> NEW.latency_delivery_days - UNION - -- Changed display_order - SELECT NEW.id_link, 'display_order', OLD.display_order, NEW.display_order, NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - UNION - -- Changed active - SELECT NEW.id_link, 'active', OLD.active, NEW.active, NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - ; -END // -DELIMITER ; diff --git a/static/MySQL/6000_p_core_validate_guid.sql b/static/MySQL/6000_p_core_validate_guid.sql new file mode 100644 index 00000000..82cc8345 --- /dev/null +++ b/static/MySQL/6000_p_core_validate_guid.sql @@ -0,0 +1,29 @@ + +USE partsltd_prod; + +DROP PROCEDURE IF EXISTS partsltd_prod.p_core_validate_guid; +DROP PROCEDURE IF EXISTS partsltd_prod.p_core_validate_guid_test; + +DELIMITER // +CREATE PROCEDURE partsltd_prod.p_core_validate_guid ( + IN a_guid BINARY(36) +) +BEGIN + IF ISNULL(a_guid) THEN + SIGNAL SQLSTATE '45000' + SET MESSAGE_TEXT = 'GUID is required.' + ; + END IF; +END // +DELIMITER ; + + +DELIMITER // +CREATE PROCEDURE partsltd_prod.p_core_validate_guid_test () +BEGIN + CALL partsltd_prod.p_core_validate_guid ( 'nips' ); + CALL partsltd_prod.p_core_validate_guid ( NULL ); +END // +DELIMITER ; + +-- CALL partsltd_prod.p_core_validate_guid_test(); \ No newline at end of file diff --git a/static/MySQL/6001_p_clear_split_temp.sql b/static/MySQL/6001_p_clear_split_temp.sql deleted file mode 100644 index 0894de9f..00000000 --- a/static/MySQL/6001_p_clear_split_temp.sql +++ /dev/null @@ -1,29 +0,0 @@ - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_clear_split_temp; - - -DELIMITER // -CREATE PROCEDURE p_clear_split_temp ( - IN a_guid BINARY(36) -) -BEGIN - CALL p_validate_guid( a_guid ); - - START TRANSACTION; - - -- DROP TABLE IF EXISTS - DELETE FROM Split_Temp - WHERE GUID = a_guid - ; - - COMMIT; -END // -DELIMITER ; - -/* - -CALL p_clear_split_temp ( 'nips' ); - - -*/ diff --git a/static/MySQL/6000_p_debug_timing_reporting.sql b/static/MySQL/6001_p_core_debug_timing_reporting.sql similarity index 77% rename from static/MySQL/6000_p_debug_timing_reporting.sql rename to static/MySQL/6001_p_core_debug_timing_reporting.sql index e96935ef..c796e60b 100644 --- a/static/MySQL/6000_p_debug_timing_reporting.sql +++ b/static/MySQL/6001_p_core_debug_timing_reporting.sql @@ -1,15 +1,15 @@ --- USE partsltd_prod; --- Clear previous proc -DROP PROCEDURE IF EXISTS p_debug_timing_reporting; +USE partsltd_prod; + +DROP PROCEDURE IF EXISTS partsltd_prod.p_core_debug_timing_reporting; DELIMITER // -CREATE PROCEDURE p_debug_timing_reporting ( +CREATE PROCEDURE partsltd_prod.p_core_debug_timing_reporting ( IN a_time_start TIMESTAMP(6) ) BEGIN /* - PROCEDURE p_debug_timing_reporting + PROCEDURE partsltd_prod.p_core_debug_timing_reporting Shared method timing reporting */ DECLARE v_time_end TIMESTAMP(6); @@ -37,7 +37,7 @@ END // DELIMITER ; /* -CALL partsltd_prod.p_debug_timing_reporting ( +CALL partsltd_prod.p_core_debug_timing_reporting ( CURRENT_TIMESTAMP(6) ); */ \ No newline at end of file diff --git a/static/MySQL/6001_p_validate_guid.sql b/static/MySQL/6001_p_validate_guid.sql deleted file mode 100644 index 7a6cb0fc..00000000 --- a/static/MySQL/6001_p_validate_guid.sql +++ /dev/null @@ -1,59 +0,0 @@ - - -DROP PROCEDURE IF EXISTS p_validate_guid; -DROP PROCEDURE IF EXISTS p_validate_guid_test; - -DELIMITER // -CREATE PROCEDURE p_validate_guid ( - IN a_guid BINARY(36) - -- , IN a_debug BIT -) -BEGIN - /* - DECLARE v_code_type_error_bad_data VARCHAR(200); - DECLARE v_id_type_error_bad_data INT; - - IF ISNULL(a_guid) THEN - SET v_code_type_error_bad_data := (SELECT code FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA'); - SET v_id_type_error_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_type_error_bad_data); - - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , 'GUID is required.' - ; - END IF; - */ - IF ISNULL(a_guid) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'GUID is required.' - ; - END IF; -END // -DELIMITER ; - - -DELIMITER // -CREATE PROCEDURE p_validate_guid_test () -BEGIN - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - id_type INT - , code VARCHAR(200) - , msg TEXT - ); - - CALL p_validate_guid ( 'nips' ); - CALL p_validate_guid ( NULL ); - - SELECT * FROM tmp_Msg_Error; - - DROP TABLE tmp_Msg_Error; -END // -DELIMITER ; - --- CALL p_validate_guid_test(); \ No newline at end of file diff --git a/static/MySQL/6004_p_clear_split_key_value_pair_csv_temp.sql b/static/MySQL/6004_p_clear_split_key_value_pair_csv_temp.sql deleted file mode 100644 index 0ad0fbb2..00000000 --- a/static/MySQL/6004_p_clear_split_key_value_pair_csv_temp.sql +++ /dev/null @@ -1,29 +0,0 @@ - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_clear_split_key_value_pair_csv_temp; - - -DELIMITER // -CREATE PROCEDURE p_clear_split_key_value_pair_csv_temp ( - IN a_guid BINARY(36) -) -BEGIN - CALL p_validate_guid( a_guid ); - - START TRANSACTION; - - -- DROP TABLE IF EXISTS - DELETE FROM Split_Key_Value_Pair_Csv_Temp - WHERE GUID = a_guid - ; - - COMMIT; -END // -DELIMITER ; - -/* - -CALL p_clear_split_key_value_pair_csv_temp ( 'nipsnipsnipsnipsnipsnipsnipsnipsnips' ); - - -*/ diff --git a/static/MySQL/6000_p_split.sql b/static/MySQL/6010_p_core_split.sql similarity index 78% rename from static/MySQL/6000_p_split.sql rename to static/MySQL/6010_p_core_split.sql index 3b951846..1dc65aa1 100644 --- a/static/MySQL/6000_p_split.sql +++ b/static/MySQL/6010_p_core_split.sql @@ -1,10 +1,11 @@ +USE partsltd_prod; -DROP PROCEDURE IF EXISTS p_split; +DROP PROCEDURE IF EXISTS partsltd_prod.p_core_split; DELIMITER // -CREATE PROCEDURE p_split ( - IN a_guid BINARY(36) +CREATE PROCEDURE partsltd_prod.p_core_split ( + IN a_guid BINARY(36) , IN a_string LONGTEXT , IN a_separator VARCHAR(1000) -- IN a_allow_empty BIT @@ -26,14 +27,14 @@ BEGIN IF a_debug = 1 THEN SELECT - a_guid + a_guid , a_string , a_separator , a_debug ; END IF; - CALL p_validate_guid ( a_guid ); + CALL partsltd_prod.p_core_validate_guid ( a_guid ); DROP TABLE IF EXISTS tmp_Split_Split; @@ -64,13 +65,13 @@ BEGIN IF EXISTS (SELECT * FROM tmp_Split_Split LIMIT 1) THEN START TRANSACTION; - INSERT INTO Split_Temp ( - guid - , display_order + INSERT INTO partsltd_prod.CORE_Split_Temp ( + guid + , display_order , substring ) SELECT - a_guid + a_guid , display_order , substring FROM tmp_Split_Split @@ -81,15 +82,15 @@ BEGIN DROP TABLE IF EXISTS tmp_Split_Split; IF a_debug = 1 THEN - CALL p_debug_timing_reporting ( v_time_start ); + CALL partsltd_prod.p_core_debug_timing_reporting ( v_time_start ); END IF; END // DELIMITER ; /* -CALL p_split ( - 'nips' +CALL partsltd_prod.p_core_split ( + 'nips' , 'noods, cheese ' -- a_string , ',' -- a_separator -- '0', -- a_allow_empty @@ -97,8 +98,8 @@ CALL p_split ( ); SELECT * -FROM Split_Temp +FROM partsltd_prod.CORE_Split_Temp WHERE GUID = 'nips'; -CALL p_clear_split_temp( 'nips' ); +CALL partsltd_prod.p_core_clear_split_temp( 'nips' ); */ diff --git a/static/MySQL/6011_p_core_clear_split.sql b/static/MySQL/6011_p_core_clear_split.sql new file mode 100644 index 00000000..c380d1c1 --- /dev/null +++ b/static/MySQL/6011_p_core_clear_split.sql @@ -0,0 +1,30 @@ + +USE partsltd_prod; + +DROP PROCEDURE IF EXISTS partsltd_prod.p_core_clear_split; + + +DELIMITER // +CREATE PROCEDURE partsltd_prod.p_core_clear_split ( + IN a_guid BINARY(36) +) +BEGIN + CALL partsltd_prod.p_core_validate_guid( a_guid ); + + START TRANSACTION; + + -- DROP TABLE IF EXISTS + DELETE FROM partsltd_prod.CORE_Split_Temp + WHERE GUID = a_guid + ; + + COMMIT; +END // +DELIMITER ; + +/* + +CALL partsltd_prod.p_core_clear_split ( 'nips' ); + + +*/ diff --git a/static/MySQL/6003_p_split_key_value_pair_csv.sql b/static/MySQL/6012_p_core_split_key_value_pair_csv.sql similarity index 63% rename from static/MySQL/6003_p_split_key_value_pair_csv.sql rename to static/MySQL/6012_p_core_split_key_value_pair_csv.sql index 90140b14..395110d4 100644 --- a/static/MySQL/6003_p_split_key_value_pair_csv.sql +++ b/static/MySQL/6012_p_core_split_key_value_pair_csv.sql @@ -1,9 +1,10 @@ +USE partsltd_prod; -DROP PROCEDURE IF EXISTS p_split_key_value_pair_csv; +DROP PROCEDURE IF EXISTS partsltd_prod.p_core_split_key_value_pair_csv; DELIMITER // -CREATE PROCEDURE p_split_key_value_pair_csv ( +CREATE PROCEDURE partsltd_prod.p_core_split_key_value_pair_csv ( IN a_guid BINARY(36) , IN a_string LONGTEXT , IN a_debug BIT @@ -27,29 +28,29 @@ BEGIN ; END IF; - CALL p_validate_guid ( a_guid ); + CALL partsltd_prod.p_core_validate_guid ( a_guid ); - DROP TEMPORARY TABLE IF EXISTS tmp_Split_Input; - DROP TEMPORARY TABLE IF EXISTS tmp_Split_Split; + DROP TABLE IF EXISTS tmp_Input_Split_Key_Value_Pair_Csv; + DROP TABLE IF EXISTS tmp_Split_Split_Key_Value_Pair_Csv; - CREATE TEMPORARY TABLE tmp_Split_Input ( + CREATE TEMPORARY TABLE tmp_Input_Split_Key_Value_Pair_Csv ( input_string TEXT ); - CREATE TEMPORARY TABLE tmp_Split_Split ( + CREATE TEMPORARY TABLE tmp_Split_Split_Key_Value_Pair_Csv ( id INT AUTO_INCREMENT PRIMARY KEY , key_column VARCHAR(4000) , value_column VARCHAR(4000) ); - INSERT INTO tmp_Split_Input ( + INSERT INTO tmp_Input_Split_Key_Value_Pair_Csv ( input_string ) VALUES ( a_string ); - INSERT INTO tmp_Split_Split (key_column, value_column) + INSERT INTO tmp_Split_Split_Key_Value_Pair_Csv (key_column, value_column) SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(t.pair, ':', 1), ',', -1) AS key_column, SUBSTRING_INDEX(t.pair, ':', -1) AS value_column @@ -65,9 +66,9 @@ BEGIN WHERE n <= 1 + (LENGTH(input_string) - LENGTH(REPLACE(input_string, ',', ''))) ) t; - IF EXISTS (SELECT * FROM tmp_Split_Split LIMIT 1) THEN + IF EXISTS (SELECT * FROM tmp_Split_Split_Key_Value_Pair_Csv LIMIT 1) THEN START TRANSACTION; - INSERT INTO Split_Key_Value_Pair_Csv_Temp ( + INSERT INTO partsltd_prod.CORE_Split_Key_Value_Pair_Csv_Temp ( guid , id , key_column @@ -78,31 +79,31 @@ BEGIN , id , key_column , value_column - FROM tmp_Split_Split + FROM tmp_Split_Split_Key_Value_Pair_Csv ; COMMIT; END IF; - DROP TEMPORARY TABLE IF EXISTS tmp_Split_Input; - DROP TEMPORARY TABLE IF EXISTS tmp_Split_Split; + DROP TEMPORARY TABLE IF EXISTS tmp_Input_Split_Key_Value_Pair_Csv; + DROP TEMPORARY TABLE IF EXISTS tmp_Split_Split_Key_Value_Pair_Csv; IF a_debug = 1 THEN - CALL p_debug_timing_reporting ( v_time_start ); + CALL partsltd_prod.p_core_debug_timing_reporting ( v_time_start ); END IF; END // DELIMITER ; /* -CALL p_split_key_value_pair_csv ( +CALL partsltd_prod.p_core_split_key_value_pair_csv ( 'nipsnipsnipsnipsnipsnipsnipsnipsnips' , '1:100,2:200,3:300,4:400' -- a_string , 1 ); SELECT * -FROM Split_key_value_pair_csv_Temp +FROM partsltd_prod.CORE_Split_key_value_pair_csv_Temp WHERE GUID = 'nipsnipsnipsnipsnipsnipsnipsnipsnips'; -CALL p_clear_split_key_value_pair_csv_temp( 'nipsnipsnipsnipsnipsnipsnipsnipsnips' ); +CALL partsltd_prod.p_core_clear_split_key_value_pair_csv_temp( 'nipsnipsnipsnipsnipsnipsnipsnipsnips' ); */ diff --git a/static/MySQL/6013_p_core_clear_split_key_value_pair_csv.sql b/static/MySQL/6013_p_core_clear_split_key_value_pair_csv.sql new file mode 100644 index 00000000..dc38709d --- /dev/null +++ b/static/MySQL/6013_p_core_clear_split_key_value_pair_csv.sql @@ -0,0 +1,30 @@ + +USE partsltd_prod; + +DROP PROCEDURE IF EXISTS partsltd_prod.p_core_clear_split_key_value_pair_csv; + + +DELIMITER // +CREATE PROCEDURE partsltd_prod.p_core_clear_split_key_value_pair_csv ( + IN a_guid BINARY(36) +) +BEGIN + CALL partsltd_prod.p_core_validate_guid( a_guid ); + + START TRANSACTION; + + -- DROP TABLE IF EXISTS + DELETE FROM partsltd_prod.CORE_Split_Key_Value_Pair_Csv_Temp + WHERE GUID = a_guid + ; + + COMMIT; +END // +DELIMITER ; + +/* + +CALL partsltd_prod.p_core_clear_split_key_value_pair_csv ( 'nips' ); + + +*/ diff --git a/static/MySQL/6206_fn_shop_get_product_permutation_name.sql b/static/MySQL/6206_fn_shop_get_product_permutation_name.sql deleted file mode 100644 index f02187a2..00000000 --- a/static/MySQL/6206_fn_shop_get_product_permutation_name.sql +++ /dev/null @@ -1,44 +0,0 @@ - -DROP FUNCTION IF EXISTS fn_shop_get_product_permutation_name; - -DELIMITER // - -CREATE FUNCTION fn_shop_get_product_permutation_name(id_product_permutation INT) -RETURNS VARCHAR(4000) -DETERMINISTIC -BEGIN - DECLARE name VARCHAR(4000); - - SET name := ( - SELECT - CONCAT( - IFNULL(PC.name, '(No Category)') - , ' - ' - , IFNULL(P.name, '(No Product)') - , CASE WHEN P.has_variations = 1 THEN - CONCAT(' - ', GROUP_CONCAT(CONCAT(VT.name, ': ', V.name) SEPARATOR ', ')) - ELSE '' END - ) - FROM Shop_Product_Permutation PP - LEFT JOIN Shop_Product P ON PP.id_product = P.id_product - LEFT JOIN Shop_Product_Category PC ON P.id_category = PC.id_category - LEFT JOIN Shop_Product_Permutation_Variation_Link PPVL ON PP.id_permutation = PPVL.id_permutation - LEFT JOIN Shop_Variation V ON PPVL.id_variation = V.id_variation - LEFT JOIN Shop_Variation_Type VT ON V.id_type = VT.id_type - WHERE PP.id_permutation = id_product_permutation - GROUP BY PC.id_category, PC.name, P.id_product, P.name, P.has_variations, VT.display_order, VT.name, V.display_order, V.name - LIMIT 1 - ); - - RETURN name; -END // - -DELIMITER ; - -/* -SELECT - fn_shop_get_product_permutation_name( - 3 -- id_product_permutation - ) -; -*/ \ No newline at end of file diff --git a/static/MySQL/6210_fn_shop_get_id_product_permutation_from_variation_csv_list.sql b/static/MySQL/6210_fn_shop_get_id_product_permutation_from_variation_csv_list.sql deleted file mode 100644 index 427f0014..00000000 --- a/static/MySQL/6210_fn_shop_get_id_product_permutation_from_variation_csv_list.sql +++ /dev/null @@ -1,221 +0,0 @@ - -DROP FUNCTION IF EXISTS fn_shop_get_id_product_permutation_from_variation_csv_list; - -DELIMITER // - -CREATE FUNCTION fn_shop_get_id_product_permutation_from_variation_csv_list ( - a_id_product INT - , a_variation_csv TEXT -) -RETURNS INT -DETERMINISTIC -READS SQL DATA -BEGIN - DECLARE v_id_permutation INT; - DECLARE done INT DEFAULT FALSE; - DECLARE v_id_variation_type INT; - DECLARE v_id_variation INT; - DECLARE v_id_permutation_tmp INT; - DECLARE cur CURSOR FOR - SELECT - CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(t.pair, ':', 1), ',', -1) AS UNSIGNED) AS id_variation_type, - CAST(SUBSTRING_INDEX(t.pair, ':', -1) AS UNSIGNED) AS id_variation - FROM ( - SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(a_variation_csv, ',', n), ',', -1) pair - FROM ( - SELECT a.N + b.N * 10 + 1 n - FROM (SELECT 0 AS N UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) a - CROSS JOIN (SELECT 0 AS N UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) b - ORDER BY n - ) numbers - WHERE n <= 1 + (LENGTH(a_variation_csv) - LENGTH(REPLACE(a_variation_csv, ',', ''))) - ) t; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; - - SET v_id_permutation = NULL; - - OPEN cur; - - read_loop: LOOP - FETCH cur INTO v_id_variation_type, v_id_variation; - IF done THEN - LEAVE read_loop; - END IF; - - IF v_id_permutation IS NULL THEN - -- First iteration: find initial v_id_permutations - SELECT PPVL.id_permutation INTO v_id_permutation - FROM partsltd_prod.Shop_Product_Permutation_Variation_Link PPVL - INNER JOIN partsltd_prod.Shop_Product_Permutation PP ON PPVL.id_permutation = PP.id_permutation - INNER JOIN partsltd_prod.Shop_Variation PV ON PPVL.id_variation = PV.id_variation - WHERE 1=1 - AND PP.id_product = a_id_product - AND PPVL.id_variation = v_id_variation - AND PV.id_type = v_id_variation_type - ; - ELSE - -- Subsequent iterations: narrow down the v_id_permutation - SELECT PPVL.id_permutation INTO v_id_permutation_tmp - FROM partsltd_prod.Shop_Product_Permutation_Variation_Link PPVL - INNER JOIN partsltd_prod.Shop_Product_Permutation PP ON PPVL.id_permutation = PP.id_permutation - INNER JOIN partsltd_prod.Shop_Variation PV ON PPVL.id_variation = PV.id_variation - WHERE 1=1 - AND PP.id_product = a_id_product - AND PPVL.v_id_permutation = v_id_permutation - AND PPVL.id_variation = v_id_variation - AND PV.id_type = v_id_variation_type - ; - - IF v_id_permutation_tmp IS NULL THEN - -- If no match found, exit the loop - SET v_id_permutation := NULL; - LEAVE read_loop; - ELSE - SET v_id_permutation := v_id_permutation_tmp; - END IF; - END IF; - END LOOP; - - CLOSE cur; - - RETURN v_id_permutation; -END // - -DELIMITER ; - -/* -SELECT fn_shop_get_id_product_permutation_from_variation_csv_list ( 1, '1:1' ) AS id_permutation; -SELECT fn_shop_get_id_product_permutation_from_variation_csv_list ( 3, '' ) AS id_permutation; -*/ - - -/* --- Update the table using the function -UPDATE product_permutation_input -SET v_id_permutation = find_v_id_permutation(variation_csv) -WHERE v_id_permutation IS NULL; -*/ - -/* -select * from partsltd_prod.Shop_Variation - -DROP PROCEDURE IF EXISTS p_shop_get_id_product_permutation_from_variation_csv_list; - -DELIMITER // -CREATE PROCEDURE p_shop_get_id_product_permutation_from_variation_csv_list ( - IN a_guid BINARY(36) - , IN a_debug BIT -) -BEGIN - DECLARE done INT DEFAULT FALSE; - DECLARE v_id INT; - DECLARE v_row_id INT; - DECLARE v_variation_csv TEXT; - DECLARE v_id_permutation INT; - DECLARE v_time_start TIMESTAMP(6); - - -- Cursor to iterate through unprocessed rows - DECLARE cur CURSOR FOR - SELECT id, session_guid, row_id, variation_csv - FROM product_permutation_input - WHERE v_id_permutation IS NULL; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET a_debug := IFNULL(a_debug, 0); - - IF a_debug = 1 THEN - SELECT - a_guid - , a_debug - ; - END IF; - - CALL p_validate_guid ( a_guid ); - - OPEN cur; - - read_loop: LOOP - FETCH cur INTO v_id, v_session_guid, v_row_id, v_variation_csv; - IF done THEN - LEAVE read_loop; - END IF; - - -- Find matching v_id_permutation - SET v_id_permutation = NULL; - - SELECT ppvl.v_id_permutation INTO v_id_permutation - FROM ( - SELECT - SUBSTRING_INDEX(SUBSTRING_INDEX(t.pair, ':', 1), ',', -1) AS id_variation_type, - SUBSTRING_INDEX(t.pair, ':', -1) AS id_variation - FROM ( - SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(v_variation_csv, ',', numbers.n), ',', -1) pair - FROM ( - SELECT 1 n UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 -- add more if needed - ) numbers - WHERE CHAR_LENGTH(v_variation_csv) - CHAR_LENGTH(REPLACE(v_variation_csv, ',', '')) >= numbers.n - 1 - ) t - ) parsed - INNER JOIN product_permutation_variation_link ppvl - ON parsed.id_variation_type = ppvl.id_variation_type - AND parsed.id_variation = ppvl.id_variation - GROUP BY ppvl.v_id_permutation - HAVING COUNT(*) = (LENGTH(v_variation_csv) - LENGTH(REPLACE(v_variation_csv, ',', '')) + 1) - LIMIT 1; - - -- Update the v_id_permutation in the input table - UPDATE product_permutation_input - SET v_id_permutation = v_id_permutation - WHERE id = v_id; - - END LOOP; - - CLOSE cur; - - - IF EXISTS ( SELECT * FROM Shop_Get_Id_Product_Permutation_From_Variation_Csv_List_Temp WHERE GUID = a_guid LIMIT 1 ) THEN - IF EXISTS (SELECT * FROM tmp_Split_Split LIMIT 1) THEN - START TRANSACTION; - INSERT INTO Split_Key_Value_Pair_Csv_Temp ( - guid - , id - , key_column - , value_column - ) - SELECT - a_guid - , id - , key_column - , value_column - FROM tmp_Split_Split - ; - COMMIT; - END IF; - END IF; - - DROP TEMPORARY TABLE IF EXISTS tmp_Split_Input; - DROP TEMPORARY TABLE IF EXISTS tmp_Split_Split; - - IF a_debug = 1 THEN - CALL p_debug_timing_reporting ( v_time_start ); - END IF; -END // -DELIMITER ; -*/ - -/* -CALL p_shop_get_id_product_permutation_from_variation_csv_list ( - 'nipsnipsnipsnipsnipsnipsnipsnipsnips' - , '1:100,2:200,3:300,4:400' -- a_string - , 1 -); - -SELECT * -FROM Split_key_value_pair_csv_Temp -WHERE GUID = 'nipsnipsnipsnipsnipsnipsnipsnipsnips'; - -CALL p_clear_split_key_value_pair_csv_temp( 'nipsnipsnipsnipsnipsnipsnipsnipsnips' ); -*/ diff --git a/static/MySQL/6211_fn_shop_get_product_variations_from_id_csv_list.sql b/static/MySQL/6211_fn_shop_get_product_variations_from_id_csv_list.sql deleted file mode 100644 index b3c7e1d5..00000000 --- a/static/MySQL/6211_fn_shop_get_product_variations_from_id_csv_list.sql +++ /dev/null @@ -1,102 +0,0 @@ - -DROP FUNCTION IF EXISTS fn_shop_get_product_variations_from_id_csv_list; - -DELIMITER // - -CREATE FUNCTION fn_shop_get_product_variations_from_id_csv_list ( - a_id_permutation INT - , a_variation_csv TEXT - , a_guid BINARY(36) -) -RETURNS INT -DETERMINISTIC -READS SQL DATA -BEGIN - DECLARE v_csv_pairs VARCHAR(4000); - DECLARE v_current_pair VARCHAR(50); - DECLARE v_id_variation_type INT; - DECLARE v_id_variation INT; - DECLARE v_rank_counter INT; - - CALL p_validate_guid( a_guid ); - - SET v_csv_pairs := a_variation_csv; - SET v_rank_counter := 1; - - DROP TEMPORARY TABLE IF EXISTS tmp_Get_Variation_From_Csv_Variations; - CREATE TEMPORARY TABLE tmp_Get_Variation_From_Csv_Variations ( - id_variation_type INT NULL - , id_variation INT NOT NULL - ); - - WHILE LENGTH(v_csv_pairs) > 0 DO - IF LOCATE(',', v_csv_pairs) > 0 THEN - SET v_current_pair := SUBSTRING_INDEX(v_csv_pairs, ',', 1); - SET v_csv_pairs := SUBSTRING(v_csv_pairs, LOCATE(',', v_csv_pairs) + 1); - ELSE - SET v_current_pair := v_csv_pairs; - SET v_csv_pairs := ''; - END IF; - - SET v_id_variation_type := SUBSTRING_INDEX(v_current_pair, ':', 1); - SET v_id_variation := SUBSTRING_INDEX(v_current_pair, ':', -1); - - IF NOT ISNULL(v_id_variation) THEN - INSERT INTO tmp_Get_Variation_From_Csv_Variations ( - id_variation_type - , id_variation - ) - SELECT - v_id_variation_type AS id_variation_type - , v_id_variation AS id_variation - ; - - SET v_rank_counter := v_rank_counter + 1; - END IF; - END WHILE; - - INSERT INTO partsltd_prod.Shop_Product_Permutation_Variation_Link_Temp ( - id_link - , id_permutation - , id_variation - , display_order - , active - , GUID - ) - SELECT - IFNULL(PPVL.id_link, -v_rank_counter) AS id_link - , a_id_permutation - , t_V.id_variation - , v_rank_counter AS display_order - , 1 AS active - , a_guid - FROM tmp_Get_Variation_From_Csv_Variations t_V - LEFT JOIN partsltd_prod.Shop_Product_Permutation_Variation_Link PPVL ON t_V.id_variation = PPVL.id_variation - ; - - DROP TEMPORARY TABLE tmp_Get_Variation_From_Csv_Variations; - - RETURN v_rank_counter; -END // - -DELIMITER ; - - -/* - -SELECT - partsltd_prod.fn_shop_get_product_variations_from_id_csv_list( - 1 -- a_id_permutation - , '1:1' -- a_variation_csv - , 'NIPPLENIPPLENIPPLENIPPLENIPPLENIPPLE' -- a_guid - ) -; -SELECT * -FROM partsltd_prod.Shop_Product_Permutation_Variation_Link_Temp -WHERE GUID = 'NIPPLENIPPLENIPPLENIPPLENIPPLENIPPLE' -; -DELETE -FROM partsltd_prod.Shop_Product_Permutation_Variation_Link_Temp -WHERE GUID = 'NIPPLENIPPLENIPPLENIPPLENIPPLENIPPLE' -; -*/ diff --git a/static/MySQL/6212_fn_shop_get_product_permutation_variations_csv.sql b/static/MySQL/6212_fn_shop_get_product_permutation_variations_csv.sql deleted file mode 100644 index d1d34f5b..00000000 --- a/static/MySQL/6212_fn_shop_get_product_permutation_variations_csv.sql +++ /dev/null @@ -1,49 +0,0 @@ - -DROP FUNCTION IF EXISTS fn_shop_get_product_permutation_variations_csv; - -DELIMITER // - -CREATE FUNCTION fn_shop_get_product_permutation_variations_csv(id_product_permutation INT) -RETURNS VARCHAR(4000) -DETERMINISTIC -BEGIN - DECLARE csv VARCHAR(4000); - - SET csv := ( - SELECT - CASE WHEN P.has_variations = 0 THEN - '' - ELSE - GROUP_CONCAT( - CONCAT( - PV.id_type - , ':' - , PV.id_variation - ) - SEPARATOR ',' - ) - END - FROM partsltd_prod.Shop_Product_Permutation PP - LEFT JOIN partsltd_prod.Shop_Product P ON PP.id_product = P.id_product - LEFT JOIN partsltd_prod.Shop_Product_Permutation_Variation_Link PPVL ON PP.id_permutation = PPVL.id_permutation - LEFT JOIN partsltd_prod.Shop_Variation PV ON PPVL.id_variation = PV.id_variation - LEFT JOIN partsltd_prod.Shop_Variation_Type PVT ON PV.id_type = PVT.id_type - WHERE PP.id_permutation = id_product_permutation - GROUP BY P.id_product, P.has_variations, PVT.display_order, PVT.name, PV.display_order, PV.name - LIMIT 1 - ); - - RETURN csv; -END // - -DELIMITER ; -SELECT - fn_shop_get_product_permutation_variations_csv( - 3 -- id_product_permutation - ) - , fn_shop_get_product_permutation_variations_csv( - 1 -- id_product_permutation - ) -; -/* -*/ \ No newline at end of file diff --git a/static/MySQL/6500_p_shop_calc_user.sql b/static/MySQL/6500_p_shop_calc_user.sql deleted file mode 100644 index 918497ff..00000000 --- a/static/MySQL/6500_p_shop_calc_user.sql +++ /dev/null @@ -1,625 +0,0 @@ - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_user_eval; -DROP PROCEDURE IF EXISTS p_shop_calc_user; - -DELIMITER // -CREATE PROCEDURE p_shop_calc_user ( - IN a_guid BINARY(36) - , IN a_ids_user TEXT - , IN a_get_inactive_user BIT - , IN a_ids_permission VARCHAR(4000) - , IN a_ids_access_level VARCHAR(4000) - , IN a_ids_product TEXT - , IN a_debug BIT -) -BEGIN - -- Variable declaration - DECLARE v_has_filter_permission BIT; - DECLARE v_has_filter_user BIT; - DECLARE v_has_filter_access_level BIT; - -- DECLARE v_has_filter_permutation BIT; - DECLARE v_has_filter_product BIT; - DECLARE v_id_permission_product INT; - DECLARE v_id_permission INT; - -- DECLARE v_ids_product VARCHAR(500); - DECLARE v_id_access_level_view INT; - -- DECLARE v_id_access_level_product_required INT; - DECLARE v_priority_access_level_view INT; - DECLARE v_priority_access_level_edit INT; - DECLARE v_priority_access_level_admin INT; - DECLARE v_id_access_level INT; - DECLARE v_priority_access_level INT; - DECLARE v_time_start TIMESTAMP(6); - DECLARE v_ids_row_delete VARCHAR(500); - DECLARE v_code_type_error_bad_data VARCHAR(200); - DECLARE v_id_type_error_bad_data INT; - DECLARE v_code_error_permission VARCHAR(200); - DECLARE v_id_permission_required INT; - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_code_type_error_bad_data := (SELECT code FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA'); - SET v_id_type_error_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_type_error_bad_data); - - SET v_code_error_permission := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 2); - - CALL partsltd_prod.p_validate_guid ( a_guid ); - SET a_ids_user := TRIM(IFNULL(a_ids_user, '')); - SET a_get_inactive_user := IFNULL(a_get_inactive_user, 0); - SET a_ids_permission := TRIM(IFNULL(a_ids_permission, '')); - SET a_ids_access_level := TRIM(IFNULL(a_ids_access_level, '')); - SET a_ids_product := TRIM(IFNULL(a_ids_product, '')); - SET a_debug := IFNULL(a_debug, 0); - - IF a_debug = 1 THEN - SELECT - a_guid - , a_ids_user - , a_get_inactive_user - , a_ids_permission - , a_ids_access_level - , a_ids_product - , a_debug - ; - END IF; - - -- Clear previous proc results - DROP TABLE IF EXISTS tmp_Calc_User; - DROP TABLE IF EXISTS tmp_User_Calc_User; - DROP TABLE IF EXISTS tmp_Product_Calc_User; - DROP TABLE IF EXISTS tmp_Split; - - -- Permanent Table - CREATE TEMPORARY TABLE tmp_Calc_User ( - id_row INT PRIMARY KEY AUTO_INCREMENT NOT NULL, - id_user INT NULL, - id_permission_required INT NOT NULL, - priority_access_level_required INT NOT NULL, - id_product INT NULL, - is_super_user BIT NULL, - priority_access_level_user INT NULL, - can_view BIT, - can_edit BIT, - can_admin BIT - ); - - CREATE TEMPORARY TABLE tmp_Product_Calc_User ( - -- id_row INT PRIMARY KEY AUTO_INCREMENT NOT NULL - id_product INT NULL - , id_access_level_required INT NOT NULL - , priority_access_level_required INT NOT NULL - -- guid BINARY(36) NOT NULL, - -- rank_product INT NOT NULL - ); - - CREATE TEMPORARY TABLE tmp_User_Calc_User ( - id_user INT NOT NULL - , is_super_user BIT NOT NULL - -- , id_access_level INT - , priority_access_level INT NOT NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - -- guid BINARY(36) NOT NULL, - id_type INT NULL, - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Split ( - substring VARCHAR(4000) NOT NULL - , as_int INT NULL - ); - DELETE FROM tmp_Split; - - SET v_has_filter_user = CASE WHEN a_ids_user = '' THEN 0 ELSE 1 END; - SET a_ids_permission = REPLACE(a_ids_permission, '|', ','); - SET v_has_filter_permission = CASE WHEN a_ids_permission = '' THEN 0 ELSE 1 END; - SET a_ids_access_level = REPLACE(a_ids_access_level, '|', ','); - SET v_has_filter_access_level = CASE WHEN a_ids_access_level = '' THEN 0 ELSE 1 END; - /* - SET a_ids_permutation = REPLACE(a_ids_permutation, '|', ','); - SET v_has_filter_permutation = CASE WHEN a_ids_permutation = '' THEN 0 ELSE 1 END; - */ - SET a_ids_product = REPLACE(a_ids_product, '|', ','); - SET v_has_filter_product = CASE WHEN a_ids_product = '' THEN 0 ELSE 1 END; - SET v_id_access_level_view = (SELECT id_access_level FROM partsltd_prod.Shop_Access_Level WHERE code = 'VIEW' LIMIT 1); - SET v_priority_access_level_view = (SELECT priority FROM partsltd_prod.Shop_Access_Level WHERE id_access_level = v_id_access_level_view); - SET v_priority_access_level_edit = (SELECT priority FROM partsltd_prod.Shop_Access_Level WHERE code = 'EDIT' LIMIT 1); - SET v_priority_access_level_admin = (SELECT priority FROM partsltd_prod.Shop_Access_Level WHERE code = 'ADMIN' LIMIT 1); - - IF a_debug = 1 THEN - SELECT - v_priority_access_level_view - , v_priority_access_level_edit - , v_priority_access_level_admin - ; - END IF; - - -- Access levels - IF v_has_filter_access_level THEN - CALL partsltd_prod.p_split(a_guid, a_ids_access_level, ',', a_debug); - - INSERT INTO tmp_Split ( - substring - , as_int - ) - SELECT - substring - , CONVERT(substring, DECIMAL(10,0)) -- AS as_int - FROM Split_Temp - WHERE 1=1 - AND GUID = a_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( a_guid ); - - -- Invalid IDs - IF EXISTS ( - SELECT t_S.substring - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Access_Level AL ON t_S.as_int = AL.id_access_level - WHERE - ISNULL(t_S.as_int) - OR ISNULL(AL.id_access_level) - OR AL.active = 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - -- guid, - id_type, - code, - msg - ) - SELECT - -- a_guid, - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Invalid or inactive access level IDs: ', GROUP_CONCAT(t_S.substring SEPARATOR ', ')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Access_Level AL ON t_S.as_int = AL.id_access_level - WHERE - ISNULL(t_S.as_int) - OR ISNULL(AL.id_access_level) - OR AL.active = 0 - ; - ELSE - IF v_has_filter_access_level THEN - SET v_id_access_level := ( - SELECT AL.id_access_level - FROM tmp_Split t_S - INNER JOIN partsltd_prod.Shop_Access_Level AL - ON t_S.as_int = AL.id_access_level - AND AL.active - ORDER BY AL.priority ASC - LIMIT 1 - ); - ELSE - SET v_id_access_level = v_id_access_level_view; - END IF; - SET v_priority_access_level := (SELECT priority FROM partsltd_prod.Shop_Access_Level WHERE id_access_level = v_id_access_level LIMIT 1); - END IF; - END IF; - DELETE FROM tmp_Split; - - -- Permission IDs - IF v_has_filter_permission THEN - CALL partsltd_prod.p_split(a_guid, a_ids_permission, ',', a_debug); - - INSERT INTO tmp_Split ( - substring - , as_int - ) - SELECT - substring - , CONVERT(substring, DECIMAL(10,0)) AS as_int - FROM Split_Temp - WHERE 1=1 - AND GUID = a_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( a_guid ); - - -- Invalid or inactive - IF EXISTS (SELECT PERM.id_permission FROM tmp_Split t_S LEFT JOIN partsltd_prod.Shop_Permission PERM ON t_S.as_int = PERM.id_permission WHERE ISNULL(t_S.as_int) OR ISNULL(PERM.id_permission) OR PERM.active = 0) THEN - INSERT INTO tmp_Msg_Error ( - -- guid, - id_type, - code, - msg - ) - SELECT - -- a_guid, - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Invalid or inactive permission IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Permission PERM ON t_S.as_int = PERM.id_permission - WHERE - ISNULL(t_S.as_int) - OR ISNULL(PERM.id_permission) - OR PERM.active = 0 - ; - ELSE - SET v_id_permission_required := ( - SELECT PERM.id_permission - FROM partsltd_prod.Shop_Permission PERM - INNER JOIN partsltd_prod.Shop_Access_Level AL ON PERM.id_access_level_required = AL.id_access_level - ORDER BY AL.priority ASC - LIMIT 1 - ); - END IF; - END IF; - DELETE FROM tmp_Split; - - -- Users - CALL partsltd_prod.p_split(a_guid, a_ids_user, ',', a_debug); - - INSERT INTO tmp_Split ( - substring - , as_int - ) - SELECT - substring - , CONVERT(substring, DECIMAL(10,0)) AS as_int - FROM Split_Temp - WHERE 1=1 - AND GUID = a_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( a_guid ); - - -- Invalid or inactive - IF EXISTS (SELECT U.id_user FROM tmp_Split t_S LEFT JOIN partsltd_prod.Shop_User U ON t_S.as_int = U.id_user WHERE ISNULL(t_S.as_int) OR ISNULL(U.id_user) OR (a_get_inactive_user = 0 AND U.active = 0)) THEN - INSERT INTO tmp_Msg_Error ( - -- guid, - id_type, - code, - msg - ) - SELECT - -- a_guid, - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Invalid or inactive user IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_User U ON t_S.as_int = U.id_user - WHERE - ISNULL(t_S.as_int) - OR ISNULL(U.id_user) - OR ( - a_get_inactive_user = 0 - AND U.active = 0 - ) - ; - ELSE - /* - SET a_ids_user = ( - SELECT U.id_user - FROM tmp_Split t_S - INNER JOIN partsltd_prod.Shop_User U ON t_S.as_int = U.id_user - ); - SET v_has_filter_user = ISNULL(a_ids_user); - */ - IF NOT EXISTS (SELECT * FROM tmp_Split) THEN - INSERT INTO tmp_Split (substring, as_int) - VALUES ( '', NULL ); - END IF; - - IF a_debug = 1 THEN - SELECT * - FROM tmp_Split; - END IF; - - INSERT INTO tmp_User_Calc_User ( - id_user - -- , id_access_level - , is_super_user - , priority_access_level - ) - SELECT - U.id_user - , U.is_super_user - -- , IFNULL(AL_U.id_access_level, v_id_access_level_view) AS id_access_level - , IFNULL(MIN(AL_U.priority), v_priority_access_level_view) AS priority_access_level - FROM tmp_Split t_S - INNER JOIN partsltd_prod.Shop_User U ON t_S.as_int = U.id_user - LEFT JOIN partsltd_prod.Shop_User_Role_Link URL - ON U.id_user = URL.id_user - AND URL.active - LEFT JOIN partsltd_prod.Shop_Role_Permission_Link RPL - ON URL.id_role = RPL.id_role - AND RPL.active - LEFT JOIN partsltd_prod.Shop_Access_Level AL_U - ON RPL.id_access_level = AL_U.id_access_level - AND AL_U.active - GROUP BY U.id_user - ; - - INSERT INTO tmp_Calc_User ( - id_user - , id_permission_required - , priority_access_level_required - , id_product - , is_super_user - , priority_access_level_user - ) - SELECT - t_UCU.id_user - , v_id_permission_required - , v_priority_access_level AS priority_access_level_required - , NULL - , t_UCU.priority_access_level AS priority_access_level_user - , t_UCU.is_super_user AS is_super_user - FROM tmp_User_Calc_User t_UCU - ; - - /* - INSERT INTO tmp_Calc_User ( - id_user - , id_permission_required - , priority_access_level_required - -- , id_product - , priority_access_level_user - , is_super_user - ) - SELECT - U.id_user - , v_id_permission_required - , v_priority_access_level AS priority_access_level_required - -- , t_P.id_product - , CASE WHEN MIN(IFNULL(AL_U.priority, 0)) = 0 THEN v_priority_access_level_view ELSE MIN(IFNULL(AL_U.priority, 0)) END AS priority_access_level_user - , IFNULL(U.is_super_user, 0) AS is_super_user - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_User U - ON t_S.as_int = U.id_user - AND U.active - LEFT JOIN partsltd_prod.Shop_User_Role_Link URL - ON U.id_user = URL.id_user - AND URL.active - LEFT JOIN partsltd_prod.Shop_Role_Permission_Link RPL - ON URL.id_role = RPL.id_role - AND RPL.active - LEFT JOIN partsltd_prod.Shop_Access_Level AL_U - ON RPL.id_access_level = AL_U.id_access_level - AND AL_U.active - * - CROSS JOIN tmp_Product_Calc_User t_P - LEFT JOIN partsltd_prod.Shop_Access_Level AL_P - ON t_P.id_access_level_required = AL_P.id_access_level - AND AL_P.active - * - GROUP BY t_S.as_int, U.id_user - ; - */ - - -- SET v_has_filter_user = EXISTS ( SELECT * FROM tmp_User_Calc_User LIMIT 1 ); - END IF; - DELETE FROM tmp_Split; - - -- Products - IF v_has_filter_product = 1 THEN - CALL partsltd_prod.p_split(a_guid, a_ids_product, ',', a_debug); - - INSERT INTO tmp_Split ( - substring - , as_int - ) - SELECT - substring - , CONVERT(substring, DECIMAL(10,0)) AS as_int - FROM Split_Temp - WHERE 1=1 - AND GUID = a_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( a_guid ); - - -- Invalid product IDs - IF EXISTS (SELECT * FROM tmp_Split t_S LEFT JOIN partsltd_prod.Shop_Product P ON t_S.as_int = P.id_product WHERE ISNULL(t_S.as_int) OR ISNULL(P.id_product)) THEN - INSERT INTO tmp_Msg_Error ( - -- guid, - id_type, - code, - msg - ) - SELECT - -- a_guid, - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Invalid Product IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Product P ON t_S.as_int = P.id_product - WHERE - ISNULL(t_S.as_int) - OR ISNULL(P.id_product) - OR P.active = 0 - ; - END IF; - IF (EXISTS (SELECT * FROM tmp_Split)) THEN - INSERT INTO tmp_Product_Calc_User ( - id_product, - -- id_permutation, - id_access_level_required, - priority_access_level_required - ) - SELECT - DISTINCT P.id_product, - -- PP.id_permutation, - CASE WHEN AL_P.priority < AL_C.priority THEN AL_P.id_access_level ELSE AL_C.id_access_level END AS id_access_level_required, - CASE WHEN AL_P.priority < AL_C.priority THEN AL_P.priority ELSE AL_C.priority END AS priority_access_level_required - FROM tmp_Split t_S - INNER JOIN partsltd_prod.Shop_Product P ON t_S.as_int = P.id_product -- Shop_Product_Permutation PP - INNER JOIN partsltd_prod.Shop_Access_Level AL_P - ON P.id_access_level_required = AL_P.id_access_level - AND AL_P.active - INNER JOIN partsltd_prod.Shop_Product_Category C ON P.id_category = C.id_category - INNER JOIN partsltd_prod.Shop_Access_Level AL_C - ON C.id_access_level_required = AL_C.id_access_level - AND AL_C.active - ; - - SET v_has_filter_product = EXISTS (SELECT * FROM tmp_Product_Calc_User); - /* - UPDATE tmp_Product_Calc_User t_P - INNER JOIN partsltd_prod.Shop_Product P ON t_P.id_product = P.id_product - INNER JOIN partsltd_prod.Shop_Product_Category PC ON P.id_category = PC.id_category - INNER JOIN partsltd_prod.Shop_Access_Level AL ON PC.id_access_level_required = AL.id_access_level - SET - t_P.id_access_level_required = CASE WHEN t_P.priority_access_level_required <= AL.priority THEN t_P.id_access_level_required ELSE AL.id_access_level END - , t_P.priority_access_level_required = LEAST(t_P.priority_access_level_required, AL.priority) - ; - */ - ELSE - INSERT INTO tmp_Product_Calc_User ( - id_product, - -- id_permutation, - id_access_level_required, - priority_access_level_required - ) - VALUES ( - NULL - , v_id_access_level_view - , v_priority_access_level_view - ); - END IF; - END IF; - DELETE FROM tmp_Split; - - INSERT INTO tmp_Calc_User ( - id_user - , id_permission_required - , priority_access_level_required - , id_product - , is_super_user - , priority_access_level_user - ) - SELECT - t_U.id_user - , v_id_permission_required - , CASE WHEN AL.priority < v_priority_access_level THEN AL.priority ELSE v_priority_access_level END AS priority_access_level_required - , t_P.id_product - , t_U.priority_access_level AS priority_access_level_user - , t_U.is_super_user AS is_super_user - FROM tmp_User_Calc_User t_U - CROSS JOIN tmp_Product_Calc_User t_P - LEFT JOIN partsltd_prod.Shop_Access_Level AL ON t_P.id_access_level_required = AL.id_access_level - ; - - -- Calculated fields - UPDATE tmp_Calc_User t_CU - SET - t_CU.can_view = t_CU.is_super_user = 1 OR (t_CU.priority_access_level_user <= v_priority_access_level_view AND t_CU.priority_access_level_user <= t_CU.priority_access_level_required) - , t_CU.can_edit = t_CU.is_super_user = 1 OR (t_CU.priority_access_level_user <= v_priority_access_level_edit AND t_CU.priority_access_level_user <= t_CU.priority_access_level_required) - , t_CU.can_admin = t_CU.is_super_user = 1 OR (t_CU.priority_access_level_user <= v_priority_access_level_admin AND t_CU.priority_access_level_user <= t_CU.priority_access_level_required) - ; - - -- Export data to staging table - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - START TRANSACTION; - INSERT INTO partsltd_prod.Shop_Calc_User_Temp ( - guid - , id_user - , id_permission_required - , priority_access_level_required - , id_product - , is_super_user - , priority_access_level_user - , can_view - , can_edit - , can_admin - ) - SELECT - a_guid - , id_user - , id_permission_required - , priority_access_level_required - , id_product - , is_super_user - , priority_access_level_user - , can_view - , can_edit - , can_admin - FROM tmp_Calc_User - ; - COMMIT; - END IF; - - IF a_debug = 1 THEN - SELECT * FROM tmp_Msg_Error; - SELECT * FROM tmp_Calc_User; - SELECT * FROM tmp_User_Calc_User; - SELECT * FROM tmp_Product_Calc_User; - SELECT * FROM partsltd_prod.Shop_Calc_User_Temp WHERE GUID = a_guid; - CALL partsltd_prod.p_shop_clear_calc_user ( a_guid, a_debug ); - END IF; - - -- Clean up - DROP TABLE IF EXISTS tmp_Calc_User; - DROP TABLE IF EXISTS tmp_User_Calc_User; - DROP TABLE IF EXISTS tmp_Product_Calc_User; - -- Don't destroy common tables in nested Stored Procedures! - -- DROP TABLE IF EXISTS tmp_Split; - DELETE FROM tmp_Split; - - IF a_debug = 1 THEN - CALL partsltd_prod.p_debug_timing_reporting( v_time_start ); - END IF; -END // -DELIMITER ; - -/* - -CALL partsltd_prod.p_shop_calc_user ( - 'chips ' - , 1 - , 0 - , '2' - , '1' - , '1,2,3,4,5' - , 0 -); -CALL partsltd_prod.p_shop_calc_user ( - 'chips ' - , 1 - , 0 - , '2' - , '1' - , NULL - , 0 -); -SELECT * FROM partsltd_prod.Shop_Calc_User_Temp WHERE GUID = 'chips '; -DELETE FROM partsltd_prod.Shop_Calc_User_Temp WHERE GUID = 'chips '; - - --- SELECT * FROM partsltd_prod.Shop_Calc_User_Temp; -SELECT * FROM partsltd_prod.Shop_Calc_User_Temp WHERE GUID = 'chips '; -CALL partsltd_prod.p_shop_clear_calc_user ( 'chips ', 0 ); --- SELECT * FROM partsltd_prod.Shop_Calc_User_Temp; -DROP TABLE IF EXISTS tmp_Msg_Error; - - CALL p_shop_calc_user( - 'chips ' - , 1 - , FALSE -- a_get_inactive_users - , 2 - , 1 - , '' -- a_ids_product - , 0 -- a_debug - ); -SELECT * FROM partsltd_prod.Shop_Calc_User_Temp WHERE GUID = 'chips '; -CALL partsltd_prod.p_shop_clear_calc_user ( 'chips ', 0 ); -DROP TABLE IF EXISTS tmp_Msg_Error; - -SELECT * FROM partsltd_prod.shop_user_role_link; -SELECT * FROM partsltd_prod.shop_role_permission_link; - -*/ \ No newline at end of file diff --git a/static/MySQL/6501_p_shop_clear_calc_user.sql b/static/MySQL/6501_p_shop_clear_calc_user.sql deleted file mode 100644 index f4c07005..00000000 --- a/static/MySQL/6501_p_shop_clear_calc_user.sql +++ /dev/null @@ -1,45 +0,0 @@ - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_clear_Shop_Calc_User_Temp; -DROP PROCEDURE IF EXISTS p_clear_Shop_Calc_User_Temp; -DROP PROCEDURE IF EXISTS p_shop_clear_calc_user; - - -DELIMITER // -CREATE PROCEDURE p_shop_clear_calc_user ( - IN a_guid BINARY(36) - , IN a_debug BIT -) -BEGIN - DECLARE v_time_start TIMESTAMP(6); - SET v_time_start := CURRENT_TIMESTAMP(6); - - CALL p_validate_guid ( a_guid ); - - START TRANSACTION; - - DELETE FROM Shop_Calc_User_Temp - WHERE GUID = a_guid - ; - - COMMIT; - - IF a_debug = 1 THEN - CALL partsltd_prod.p_debug_timing_reporting( v_time_start ); - END IF; -END // -DELIMITER ; - -/* - -CALL p_shop_clear_calc_user ( - 'noods, cheese ' -- a_guid - , 1 -- debug -); - -SELECT * -FROM Shop_Calc_User_Temp -WHERE GUID = 'noods, cheese ' -; - -*/ diff --git a/static/MySQL/7003_p_shop_get_many_access_level.sql b/static/MySQL/7003_p_shop_get_many_access_level.sql deleted file mode 100644 index 7c8fe7f1..00000000 --- a/static/MySQL/7003_p_shop_get_many_access_level.sql +++ /dev/null @@ -1,45 +0,0 @@ - - - -/* - -CALL p_shop_get_many_access_level ( - 0 -- a_get_inactive_access_level -) - -*/ - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_get_many_access_level; - - -DELIMITER // -CREATE PROCEDURE p_shop_get_many_access_level ( - IN a_get_inactive_access_level BIT -) -BEGIN - SET a_get_inactive_access_level = IFNULL(a_get_inactive_access_level, 0); - - SELECT - AL.id_access_level - , AL.code - , AL.name - , AL.priority - , AL.display_order - , AL.active - FROM Shop_Access_Level AL - WHERE - a_get_inactive_access_level = 1 - OR AL.active = 1 - ORDER BY AL.display_order - ; -END // -DELIMITER ; - - -/* -CALL p_shop_get_many_access_level ( - 0 -- a_get_inactive_access_level -); -*/ diff --git a/static/MySQL/7101_p_shop_get_many_region.sql b/static/MySQL/7101_p_shop_get_many_region.sql deleted file mode 100644 index 32f066fe..00000000 --- a/static/MySQL/7101_p_shop_get_many_region.sql +++ /dev/null @@ -1,45 +0,0 @@ - - - -/* - -CALL p_shop_get_many_region ( - 0 -- a_get_inactive_region -) - -*/ - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_get_many_region; - - -DELIMITER // -CREATE PROCEDURE p_shop_get_many_region ( - IN a_get_inactive_region BIT -) -BEGIN - IF a_get_inactive_region IS NULL THEN - SET a_get_inactive_region = 0; - END IF; - - SELECT - R.id_region, - R.code, - R.name, - R.active, - R.display_order - FROM Shop_Region R - WHERE a_get_inactive_region - OR R.active - ORDER BY R.display_order - ; -END // -DELIMITER ; - - -/* -CALL p_shop_get_many_region ( - 0 -- a_get_inactive_region -); -*/ diff --git a/static/MySQL/7106_p_shop_get_many_plant.sql b/static/MySQL/7106_p_shop_get_many_plant.sql deleted file mode 100644 index 5046e7dd..00000000 --- a/static/MySQL/7106_p_shop_get_many_plant.sql +++ /dev/null @@ -1,36 +0,0 @@ - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_get_many_plant; - - -DELIMITER // -CREATE PROCEDURE p_shop_get_many_plant ( - IN a_get_inactive_plant BIT -) -BEGIN - SET a_get_inactive_plant = IFNULL(a_get_inactive_plant, 0); - - SELECT - P.id_plant - , P.id_address - , A.id_region - , P.id_user_manager - , P.code - , P.name - , P.active - FROM Shop_Plant P - INNER JOIN Shop_Address A ON P.id_address = A.id_address - WHERE - a_get_inactive_plant = 1 - OR P.active = 1 - ; -END // -DELIMITER ; - - -/* -CALL p_shop_get_many_plant ( - 0 -- a_get_inactive_plant -); -*/ diff --git a/static/MySQL/7109_p_shop_get_many_storage_location.sql b/static/MySQL/7109_p_shop_get_many_storage_location.sql deleted file mode 100644 index 96a736a6..00000000 --- a/static/MySQL/7109_p_shop_get_many_storage_location.sql +++ /dev/null @@ -1,37 +0,0 @@ - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_get_many_storage_location; - - -DELIMITER // -CREATE PROCEDURE p_shop_get_many_storage_location ( - IN a_get_inactive_storage_location BIT -) -BEGIN - SET a_get_inactive_storage_location = IFNULL(a_get_inactive_storage_location, 0); - - SELECT - SL.id_location - , P.id_plant - , P.id_address - , A.id_region - , SL.code - , SL.name - , P.active - FROM Shop_Storage_Location SL - INNER JOIN Shop_Plant P ON SL.id_plant = P.id_plant - INNER JOIN Shop_Address A ON P.id_address = A.id_address - WHERE - a_get_inactive_storage_location = 1 - OR SL.active = 1 - ; -END // -DELIMITER ; - - -/* -CALL p_shop_get_many_storage_location ( - 0 -- a_get_inactive_storage_location -); -*/ diff --git a/static/MySQL/7116_p_shop_get_many_currency.sql b/static/MySQL/7116_p_shop_get_many_currency.sql deleted file mode 100644 index 6284a488..00000000 --- a/static/MySQL/7116_p_shop_get_many_currency.sql +++ /dev/null @@ -1,47 +0,0 @@ - - - -/* - -CALL p_shop_get_many_currency ( - 0 -- a_get_inactive_currency -) - -*/ - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_get_many_currency; - - -DELIMITER // -CREATE PROCEDURE p_shop_get_many_currency ( - IN a_get_inactive_currency BIT -) -BEGIN - IF a_get_inactive_currency IS NULL THEN - SET a_get_inactive_currency = 0; - END IF; - - SELECT - C.id_currency, - C.code, - C.name, - C.symbol, - C.factor_from_GBP, - C.display_order, - C.active - FROM Shop_Currency C - WHERE a_get_inactive_currency - OR C.active - ORDER BY C.display_order - ; -END // -DELIMITER ; - - -/* -CALL p_shop_get_many_currency ( - 0 -- a_get_inactive_currency -); -*/ diff --git a/static/MySQL/7122_p_shop_get_many_unit_measurement.sql b/static/MySQL/7122_p_shop_get_many_unit_measurement.sql deleted file mode 100644 index 87144429..00000000 --- a/static/MySQL/7122_p_shop_get_many_unit_measurement.sql +++ /dev/null @@ -1,41 +0,0 @@ - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_get_many_unit_measurement; - - -DELIMITER // -CREATE PROCEDURE p_shop_get_many_unit_measurement ( - IN a_get_inactive_unit_measurement BIT -) -BEGIN - SET a_get_inactive_unit_measurement := IFNULL(a_get_inactive_unit_measurement, 0); - - SELECT - UM.id_unit_measurement, - UM.name_singular, - UM.name_plural, - UM.symbol, - UM.symbol_is_suffix_not_prefix, - UM.is_base_unit, - UM.is_unit_of_distance, - UM.is_unit_of_mass, - UM.is_unit_of_time, - UM.is_unit_of_volume, - UM.active - FROM Shop_Unit_Measurement UM - WHERE - a_get_inactive_unit_measurement = 1 - OR UM.active = 1 - ; -END // -DELIMITER ; - - -/* -CALL p_shop_get_many_unit_measurement ( - 0 -- a_get_inactive_unit_measurement -); - -select * -from shop_unit_measurement -*/ diff --git a/static/MySQL/7130_p_ph_calc_user.sql b/static/MySQL/7130_p_ph_calc_user.sql new file mode 100644 index 00000000..3e162b24 --- /dev/null +++ b/static/MySQL/7130_p_ph_calc_user.sql @@ -0,0 +1,341 @@ + +USE partsltd_prod; + +DROP PROCEDURE IF EXISTS partsltd_prod.p_ph_user_eval; +DROP PROCEDURE IF EXISTS partsltd_prod.p_ph_calc_user; + +DELIMITER // +CREATE PROCEDURE partsltd_prod.p_ph_calc_user ( + IN a_guid BINARY(36) + , IN a_ids_user TEXT + , IN a_get_inactive_user BIT + , IN a_ids_permission VARCHAR(4000) + , IN a_debug BIT +) +BEGIN + DECLARE v_has_filter_permission BIT; + DECLARE v_has_filter_user BIT; + DECLARE v_id_permission INT; + DECLARE v_time_start TIMESTAMP(6); + DECLARE v_ids_row_delete VARCHAR(500); + DECLARE v_code_type_error_bad_data VARCHAR(200); + DECLARE v_id_type_error_bad_data INT; + DECLARE v_code_error_permission VARCHAR(200); + DECLARE v_id_permission_required INT; + DECLARE v_priority_access_level_required INT; + DECLARE v_priority_access_level_view INT; + + SET v_time_start := CURRENT_TIMESTAMP(6); + SET v_code_type_error_bad_data := (SELECT code FROM partsltd_prod.CORE_Msg_Error_Type WHERE code = 'BAD_DATA'); + SET v_id_type_error_bad_data := (SELECT id_type FROM partsltd_prod.CORE_Msg_Error_Type WHERE code = v_code_type_error_bad_data); + SET v_code_error_permission := (SELECT code FROM partsltd_prod.CORE_Msg_Error_Type WHERE id_type = 2); + SET v_priority_access_level_view := (SELECT priority FROM partsltd_prod.PH_Access_Level WHERE code = 'VIEW' LIMIT 1); + + CALL partsltd_prod.p_core_validate_guid ( a_guid ); + SET a_ids_user := TRIM(IFNULL(a_ids_user, '')); + SET a_get_inactive_user := IFNULL(a_get_inactive_user, 0); + SET a_ids_permission := TRIM(IFNULL(a_ids_permission, '')); + SET a_debug := IFNULL(a_debug, 0); + + IF a_debug = 1 THEN + SELECT + a_guid + , a_ids_user + , a_get_inactive_user + , a_ids_permission + , a_debug + ; + END IF; + + DROP TABLE IF EXISTS tmp_Calc_User; + DROP TABLE IF EXISTS tmp_User_Calc_User; + DROP TABLE IF EXISTS tmp_Split_Calc_User; + + CREATE TEMPORARY TABLE tmp_Calc_User ( + id_row INT PRIMARY KEY AUTO_INCREMENT NOT NULL + , id_user INT NULL + , id_permission_required INT NOT NULL + , priority_access_level_required INT NOT NULL + , is_super_user BIT NULL + , priority_access_level_user INT NULL + , has_access BIT + ); + + CREATE TEMPORARY TABLE tmp_User_Calc_User ( + id_user INT NOT NULL + , is_super_user BIT NOT NULL + -- , id_access_level INT + , priority_access_level INT NOT NULL + ); + + CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( + display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT + , id_type INT NULL + , code VARCHAR(50) NOT NULL + , msg VARCHAR(4000) NOT NULL + ); + + CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Split_Calc_User ( + substring VARCHAR(4000) NOT NULL + , as_int INT NULL + ); + DELETE FROM tmp_Split_Calc_User; + + SET v_has_filter_user = CASE WHEN a_ids_user = '' THEN 0 ELSE 1 END; + SET a_ids_permission = REPLACE(a_ids_permission, '|', ','); + SET v_has_filter_permission = CASE WHEN a_ids_permission = '' THEN 0 ELSE 1 END; + -- SET v_id_access_level_view = (SELECT id_access_level FROM partsltd_prod.PH_Access_Level WHERE code = 'VIEW' LIMIT 1); + + + -- Permission IDs + IF NOT v_has_filter_permission THEN + INSERT INTO tmp_Msg_Error ( + id_type + , code + , msg + ) + SELECT + v_id_type_error_bad_data + , v_code_type_error_bad_data + , 'Permission ID required.' + ; + ELSE + CALL partsltd_prod.p_core_split(a_guid, a_ids_permission, ',', a_debug); + + INSERT INTO tmp_Split_Calc_User ( + substring + , as_int + ) + SELECT + substring + , CONVERT(substring, DECIMAL(10,0)) AS as_int + FROM partsltd_prod.CORE_Split_Temp + WHERE + GUID = a_guid + AND NOT ISNULL(substring) + AND substring != '' + ; + + CALL partsltd_prod.p_core_clear_split( a_guid ); + + -- Invalid or inactive + IF EXISTS ( + SELECT PERM.id_permission + FROM tmp_Split_Calc_User t_S + LEFT JOIN partsltd_prod.PH_Permission PERM ON t_S.as_int = PERM.id_permission + WHERE + ISNULL(t_S.as_int) + OR ISNULL(PERM.id_permission) + OR PERM.active = 0 + ) THEN + INSERT INTO tmp_Msg_Error ( + id_type + , code + , msg + ) + SELECT + v_id_type_error_bad_data + , v_code_type_error_bad_data + , CONCAT('Invalid or inactive permission IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) + FROM tmp_Split_Calc_User t_S + LEFT JOIN partsltd_prod.PH_Permission PERM ON t_S.as_int = PERM.id_permission + WHERE + ISNULL(t_S.as_int) + OR ISNULL(PERM.id_permission) + OR PERM.active = 0 + ; + ELSE + SELECT + PERM.id_permission + , PERM.id_access_level_required + INTO + v_id_permission_required + , v_priority_access_level_required + FROM tmp_Split_Calc_User t_S + LEFT JOIN partsltd_prod.PH_Permission PERM ON t_S.as_int = PERM.id_permission + INNER JOIN partsltd_prod.PH_Access_Level AL ON PERM.id_access_level_required = AL.id_access_level + ORDER BY AL.priority ASC + LIMIT 1 + ; + + IF ISNULL(v_id_permission_required) THEN + INSERT INTO tmp_Msg_Error ( + id_type + , code + , msg + ) + SELECT + v_id_type_error_bad_data + , v_code_type_error_bad_data + , 'Valid Permission ID required.' + ; + END IF; + END IF; + END IF; + DELETE FROM tmp_Split_Calc_User; + + -- Users + CALL partsltd_prod.p_core_split(a_guid, a_ids_user, ',', a_debug); + + INSERT INTO tmp_Split_Calc_User ( + substring + , as_int + ) + SELECT + substring + , CONVERT(substring, DECIMAL(10,0)) AS as_int + FROM partsltd_prod.CORE_Split_Temp + WHERE + GUID = a_guid + AND NOT ISNULL(substring) + AND substring != '' + ; + + CALL partsltd_prod.p_core_clear_split( a_guid ); + + -- Invalid or inactive + IF EXISTS (SELECT U.id_user FROM tmp_Split_Calc_User t_S LEFT JOIN partsltd_prod.PH_User U ON t_S.as_int = U.id_user WHERE ISNULL(t_S.as_int) OR ISNULL(U.id_user) OR (a_get_inactive_user = 0 AND U.active = 0)) THEN + INSERT INTO tmp_Msg_Error ( + id_type + , code + , msg + ) + SELECT + v_id_type_error_bad_data + , v_code_type_error_bad_data + , CONCAT('Invalid or inactive user IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) + FROM tmp_Split_Calc_User t_S + LEFT JOIN partsltd_prod.PH_User U ON t_S.as_int = U.id_user + WHERE + ISNULL(t_S.as_int) + OR ISNULL(U.id_user) + OR ( + a_get_inactive_user = 0 + AND U.active = 0 + ) + ; + ELSE + IF NOT EXISTS (SELECT * FROM tmp_Split_Calc_User) THEN + INSERT INTO tmp_Split_Calc_User (substring, as_int) + VALUES ( '', NULL ); + END IF; + + IF a_debug = 1 THEN + SELECT * + FROM tmp_Split_Calc_User; + END IF; + + INSERT INTO tmp_User_Calc_User ( + id_user + , is_super_user + , priority_access_level + ) + SELECT + U.id_user + , IFNULL(U.is_super_user, 0) AS is_super_user + , IFNULL(MIN(AL_U.priority), v_priority_access_level_view) AS priority_access_level + FROM tmp_Split_Calc_User t_S + INNER JOIN partsltd_prod.PH_User U ON t_S.as_int = U.id_user + LEFT JOIN partsltd_prod.PH_User_Role_Link URL + ON U.id_user = URL.id_user + AND URL.active + LEFT JOIN partsltd_prod.PH_Role_Permission_Link RPL + ON URL.id_role = RPL.id_role + AND RPL.active + LEFT JOIN partsltd_prod.PH_Access_Level AL_U + ON RPL.id_access_level = AL_U.id_access_level + AND AL_U.active + GROUP BY U.id_user + ; + + INSERT INTO tmp_Calc_User ( + id_user + , id_permission_required + , priority_access_level_required + , priority_access_level_user + , is_super_user + ) + SELECT + t_UCU.id_user + , v_id_permission_required + , v_priority_access_level_required + , t_UCU.priority_access_level AS priority_access_level_user + , t_UCU.is_super_user AS is_super_user + FROM tmp_User_Calc_User t_UCU + ; + END IF; + DELETE FROM tmp_Split_Calc_User; + + + -- Calculated fields + UPDATE tmp_Calc_User t_CU + SET + t_CU.has_access = ( + (t_CU.is_super_user = 1) + OR (t_CU.priority_access_level_user <= t_CU.priority_access_level_required) + ) + ; + + -- Export data to staging table + IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN + START TRANSACTION; + INSERT INTO partsltd_prod.PH_Calc_User_Temp ( + guid + , id_user + , id_permission_required + , priority_access_level_required + , priority_access_level_user + , is_super_user + , has_access + ) + SELECT + a_guid + , t_CU.id_user + , t_CU.id_permission_required + , t_CU.priority_access_level_required + , t_CU.priority_access_level_user + , t_CU.is_super_user + , t_CU.has_access + FROM tmp_Calc_User t_CU + ; + COMMIT; + END IF; + + IF a_debug = 1 THEN + SELECT * FROM tmp_Msg_Error; + SELECT * FROM tmp_Calc_User; + SELECT * FROM tmp_User_Calc_User; + SELECT * FROM partsltd_prod.PH_Calc_User_Temp WHERE GUID = a_guid; + CALL partsltd_prod.p_ph_clear_calc_user ( a_guid, a_debug ); + END IF; + + -- Clean up + DROP TABLE IF EXISTS tmp_Calc_User; + DROP TABLE IF EXISTS tmp_User_Calc_User; + DELETE FROM tmp_Split_Calc_User; + + IF a_debug = 1 THEN + CALL partsltd_prod.p_debug_timing_reporting( v_time_start ); + END IF; +END // +DELIMITER ; + +/* + +CALL partsltd_prod.p_ph_calc_user ( + 'chips ' -- a_guid + , 1 -- a_ids_user + , 0 -- a_get_inactive_user + , '2' -- a_ids_permission + , '1' -- a_ids_access_level + , 0 -- a_debug +); +CALL partsltd_prod.p_ph_calc_user ( + 'chips ' -- a_guid + , 1 -- a_ids_user + , 0 -- a_get_inactive_user + , '2' -- a_ids_permission + , '1' -- a_ids_access_level + , 0 -- a_debug +); +*/ \ No newline at end of file diff --git a/static/MySQL/7131_p_ph_clear_calc_user.sql b/static/MySQL/7131_p_ph_clear_calc_user.sql new file mode 100644 index 00000000..945a0a07 --- /dev/null +++ b/static/MySQL/7131_p_ph_clear_calc_user.sql @@ -0,0 +1,43 @@ + +USE partsltd_prod; + +DROP PROCEDURE IF EXISTS partsltd_prod.p_ph_clear_calc_user; + +DELIMITER // +CREATE PROCEDURE partsltd_prod.p_ph_clear_calc_user ( + IN a_guid BINARY(36) + , IN a_debug BIT +) +BEGIN + DECLARE v_time_start TIMESTAMP(6); + SET v_time_start := CURRENT_TIMESTAMP(6); + + CALL partsltd_prod.p_core_validate_guid ( a_guid ); + + START TRANSACTION; + + DELETE FROM partsltd_prod.PH_Calc_User_Temp + WHERE GUID = a_guid + ; + + COMMIT; + + IF a_debug = 1 THEN + CALL partsltd_prod.p_debug_timing_reporting( v_time_start ); + END IF; +END // +DELIMITER ; + +/* + +CALL partsltd_prod.p_ph_clear_calc_user ( + 'chips ' -- a_guid + , 1 -- debug +); + +SELECT * +FROM partsltd_prod.PH_Calc_User_Temp +WHERE GUID = 'chips ' +; + +*/ diff --git a/static/MySQL/7200_p_shop_save_product_category.sql b/static/MySQL/7200_p_shop_save_product_category.sql deleted file mode 100644 index 0827f535..00000000 --- a/static/MySQL/7200_p_shop_save_product_category.sql +++ /dev/null @@ -1,351 +0,0 @@ - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_save_category; -DROP PROCEDURE IF EXISTS p_shop_save_category; -DROP PROCEDURE IF EXISTS p_shop_save_product_category; - - -DELIMITER // -CREATE PROCEDURE p_shop_save_product_category ( - IN a_comment VARCHAR(500), - IN a_guid BINARY(36), - IN a_id_user INT, - IN a_debug BIT -) -BEGIN - DECLARE v_code_type_error_bad_data VARCHAR(100); - DECLARE v_id_type_error_bad_data INT; - DECLARE v_id_permission_product INT; - DECLARE v_ids_product_permission LONGTEXT; - DECLARE v_id_change_set INT; - DECLARE v_id_access_level_edit INT; - DECLARE v_time_start TIMESTAMP(6); - - DECLARE exit handler for SQLEXCEPTION - BEGIN - GET DIAGNOSTICS CONDITION 1 - @sqlstate = RETURNED_SQLSTATE - , @errno = MYSQL_ERRNO - , @text = MESSAGE_TEXT - ; - - ROLLBACK; - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT - , id_type INT NULL - , code VARCHAR(50) NOT NULL - , msg VARCHAR(4000) NOT NULL - ); - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - MET.id_type - , @errno - , @text - FROM partsltd_prod.Shop_Msg_Error_Type MET - WHERE MET.code = 'MYSQL_ERROR' - ; - SELECT * - FROM tmp_Msg_Error; - DROP TABLE IF EXISTS tmp_Msg_Error; - END; - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_code_type_error_bad_data := 'BAD_DATA'; - SET v_id_type_error_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_type_error_bad_data LIMIT 1); - SET v_id_access_level_edit := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'EDIT' LIMIT 1); - - CALL p_validate_guid ( a_guid ); - - DROP TABLE IF EXISTS tmp_Category; - - CREATE TEMPORARY TABLE tmp_Category ( - id_category INT NOT NULL - , code VARCHAR(50) NOT NULL - , name VARCHAR(255) NOT NULL - , description VARCHAR(4000) NULL - , id_access_level_required INT NOT NULL - , active BIT NOT NULL - , display_order INT NOT NULL - , can_view BIT NULL - , can_edit BIT NULL - , can_admin BIT NULL - , name_error VARCHAR(255) NOT NULL - , is_new BIT NOT NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT - , id_type INT NULL - , code VARCHAR(50) NOT NULL - , msg VARCHAR(4000) NOT NULL - ); - - - -- Get data from Temp table - INSERT INTO tmp_Category ( - id_category - , code - , name - , description - , id_access_level_required - , active - , display_order - , name_error - , is_new - ) - SELECT - PC_T.id_category AS id_category - , IFNULL(PC_T.code, PC.code) AS code - , IFNULL(PC_T.name, PC.code) AS name - , IFNULL(PC_T.description, PC.description) AS description - , IFNULL(PC_T.id_access_level_required, PC.id_access_level_required) AS id_access_level_required - , IFNULL(IFNULL(PC_T.active, PC.active), 1) AS active - , IFNULL(PC_T.display_order, PC.display_order) AS display_order - , IFNULL(PC_T.name, IFNULL(PC.name, IFNULL(PC_T.code, IFNULL(PC.code, IFNULL(PC_T.id_category, '(No Product Category)'))))) AS name_error - , CASE WHEN IFNULL(PC_T.id_category, 0) < 1 THEN 1 ELSE 0 END AS is_new - FROM partsltd_prod.Shop_Product_Category_Temp PC_T - LEFT JOIN partsltd_prod.Shop_Product_Category PC ON PC_T.id_category = PC.id_category - WHERE PC_T.guid = a_guid - ; - - -- Validation - -- Missing mandatory fields - -- code - IF EXISTS (SELECT * FROM tmp_Category t_C WHERE ISNULL(t_C.code) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following Product Category(s) do not have a code: ', GROUP_CONCAT(t_C.name_error SEPARATOR ', ')) AS msg - FROM tmp_Category t_C - WHERE ISNULL(t_C.code) - ; - END IF; - -- name - IF EXISTS (SELECT * FROM tmp_Category t_C WHERE ISNULL(t_C.name) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following Product Category(s) do not have a name: ', GROUP_CONCAT(t_C.name_error SEPARATOR ', ')) AS msg - FROM tmp_Category t_C - WHERE ISNULL(t_C.name) - ; - END IF; - -- display_order - IF EXISTS (SELECT * FROM tmp_Category t_C WHERE ISNULL(t_C.display_order) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following Product Category(s) do not have a display order: ', GROUP_CONCAT(t_C.name_error SEPARATOR ', ')) AS msg - FROM tmp_Category t_C - WHERE ISNULL(t_C.display_order) - ; - END IF; - - -- Permissions - SET v_ids_product_permission := ( - SELECT GROUP_CONCAT(P.id_product SEPARATOR ',') - FROM partsltd_prod.Shop_Product P - INNER JOIN tmp_Category t_C - ON P.id_category = t_C.id_category - AND t_C.is_new = 0 - WHERE P.active = 1 - ); - SET v_id_permission_product = (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_PRODUCT' LIMIT 1); - - IF a_debug = 1 THEN - SELECT - a_guid - , a_id_user - , FALSE -- a_get_inactive_user - , v_id_permission_product - , v_id_access_level_edit - , v_ids_product_permission - , 0 -- a_debug - ; - END IF; - - CALL partsltd_prod.p_shop_calc_user( - a_guid - , a_id_user - , FALSE -- a_get_inactive_user - , v_id_permission_product - , v_id_access_level_edit - , v_ids_product_permission - , 0 -- a_debug - ); - - UPDATE tmp_Category t_C - INNER JOIN partsltd_prod.Shop_Product P ON t_C.id_category = P.id_product - INNER JOIN partsltd_prod.Shop_Calc_User_Temp UE_T - ON P.id_product = UE_T.id_product - AND UE_T.GUID = a_guid - SET - t_C.can_view = UE_T.can_view - , t_C.can_edit = UE_T.can_edit - , t_C.can_admin = UE_T.can_admin - ; - - IF EXISTS (SELECT * FROM tmp_Category WHERE IFNULL(can_edit, 0) = 0 AND is_new = 0 LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_no_permission - , v_code_type_error_no_permission - , CONCAT('You do not have permission to edit the following Product Catogory(s): ', IFNULL(GROUP_CONCAT(IFNULL(t_C.name_error, 'NULL') SEPARATOR ', '), 'NULL')) - FROM tmp_Category t_C - WHERE - IFNULL(can_edit, 0) = 0 - AND is_new = 0 - ; - END IF; - - IF EXISTS (SELECT * FROM partsltd_prod.Shop_Calc_User_Temp WHERE ISNULL(id_product) AND GUID = a_guid AND can_edit = 0 LIMIT 1) THEN - DELETE t_ME - FROM tmp_Msg_Error t_ME - WHERE t_ME.id_type <> v_id_type_error_no_permission - ; - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - VALUES ( - v_id_type_error_no_permission - , v_code_type_error_no_permission - , 'You do not have permission to edit Product Catogories.' - ) - ; - END IF; - - CALL partsltd_prod.p_shop_clear_calc_user( - a_guid - , 0 -- a_debug - ); - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - START TRANSACTION; - - INSERT INTO partsltd_prod.Shop_Product_Change_Set ( comment ) - VALUES ( a_comment ) - ; - - SET v_id_change_set := LAST_INSERT_ID(); - - UPDATE partsltd_prod.Shop_Product_Category PC - INNER JOIN tmp_Category t_C - ON PC.id_category = t_C.id_category - AND t_C.is_new = 0 - SET - PC.id_category = t_C.id_category - , PC.code = t_C.code - , PC.name = t_C.name - , PC.description = t_C.description - , PC.id_access_level_required = t_C.id_access_level_required - , PC.active = t_C.active - , PC.display_order = t_C.display_order - , PC.id_change_set = v_id_change_set - ; - - INSERT INTO partsltd_prod.Shop_Product_Category ( - code - , name - , description - , id_access_level_required - , active - , display_order - , created_by - , created_on - ) - SELECT - -- t_C.id_category AS id_category - t_C.code AS code - , t_C.name AS name - , t_C.description AS description - , t_C.id_access_level_required AS id_access_level_required - , t_C.active AS active - , t_C.display_order AS display_order - , a_id_user AS created_by - , v_time_start AS created_on - FROM tmp_Category t_C - WHERE - t_C.is_new = 1 - AND t_C.active = 1 - ; - - COMMIT; - END IF; - - START TRANSACTION; - - DELETE FROM partsltd_prod.Shop_Product_Category_Temp - WHERE GUID = a_guid; - - COMMIT; - - -- Errors - SELECT * - FROM tmp_Msg_Error t_ME - INNER JOIN partsltd_prod.Shop_Msg_Error_Type MET ON t_ME.id_type = MET.id_type - ; - - IF a_debug = 1 THEN - SELECT * from tmp_Category; - END IF; - - DROP TEMPORARY TABLE tmp_Category; - DROP TEMPORARY TABLE tmp_Msg_Error; - - IF a_debug = 1 THEN - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); - END IF; -END // -DELIMITER ; - -/* -select - * - -- COUNT(*) --- delete -from partsltd_prod.Shop_Product_Category_Temp -; - - -CALL partsltd_prod.p_shop_save_product_category ( - 'nipples' - , (SELECT GUID FROM partsltd_prod.Shop_Product_Category_Temp ORDER BY id_temp DESC LIMIT 1) - , 1 - , 1 -); - -select - * - -- COUNT(*) --- delete -from partsltd_prod.Shop_Product_Category_Temp -; - -*/ diff --git a/static/MySQL/7200_p_shop_save_product_category_test.sql b/static/MySQL/7200_p_shop_save_product_category_test.sql deleted file mode 100644 index dc02a329..00000000 --- a/static/MySQL/7200_p_shop_save_product_category_test.sql +++ /dev/null @@ -1,75 +0,0 @@ - --- Clear previous proc -DROP PROCEDURE IF EXISTS partsltd_prod.p_shop_save_product_category_test; - - -DELIMITER // -CREATE PROCEDURE p_shop_save_product_category_test () -BEGIN - - DECLARE v_guid BINARY(36); - DECLARE v_time_start TIMESTAMP(6); - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_guid := 'nips'; - - SELECT * - FROM partsltd_prod.Shop_Product_Category - ; - SELECT * - FROM partsltd_prod.Shop_Product_Category_Temp - ; - - START TRANSACTION; - - INSERT INTO partsltd_prod.Shop_Product_Category_Temp ( - id_category - , name - , code - , description - , id_access_level_required - , display_order - , guid - ) - VALUES ( - -5 -- id_category - , 'Nips' -- name - , 'Lips' -- code - , 'Chips' -- description - , 2 -- id_access_level_required - , 25 -- display_order - , v_guid - ); - - COMMIT; - - SELECT * - FROM partsltd_prod.Shop_Product_Category_Temp - WHERE GUID = v_guid - ; - - CALL partsltd_prod.p_shop_save_product_category ( - 'Test save product category' -- comment - , v_guid -- guid - , 1 -- id_user - , 1 -- debug - ); - - SELECT * - FROM partsltd_prod.Shop_Product_Category - ; - SELECT * - FROM partsltd_prod.Shop_Product_Category_Temp - ; - - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); -END // -DELIMITER ; - -/* -CALL partsltd_prod.p_shop_save_product_category_test (); - -DELETE FROM partsltd_prod.Shop_Product_Category_Temp; - -DROP TABLE IF EXISTS tmp_Msg_Error; -*/ diff --git a/static/MySQL/7201_p_ph_save_contact_form.sql b/static/MySQL/7201_p_ph_save_contact_form.sql new file mode 100644 index 00000000..b6976777 --- /dev/null +++ b/static/MySQL/7201_p_ph_save_contact_form.sql @@ -0,0 +1,390 @@ + +USE partsltd_prod; + +DROP PROCEDURE IF EXISTS partsltd_prod.p_ph_save_contact_form; + +DELIMITER // +CREATE PROCEDURE partsltd_prod.p_ph_save_contact_form ( + IN a_comment VARCHAR(500), + IN a_guid BINARY(36), + IN a_id_user INT, + IN a_debug BIT +) +BEGIN + DECLARE v_code_type_error_bad_data VARCHAR(100); + DECLARE v_id_type_error_bad_data INT; + DECLARE v_id_permission_contact_form_admin INT; + DECLARE v_id_permission_contact_form_new INT; + DECLARE v_id_change_set INT; + DECLARE v_time_start TIMESTAMP(6); + DECLARE v_can_admin BIT; + DECLARE v_can_create BIT; + + DECLARE exit handler for SQLEXCEPTION + BEGIN + GET DIAGNOSTICS CONDITION 1 + @sqlstate = RETURNED_SQLSTATE + , @errno = MYSQL_ERRNO + , @text = MESSAGE_TEXT + ; + + ROLLBACK; + + CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( + display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT + , id_type INT NULL + , code VARCHAR(50) NOT NULL + , msg VARCHAR(4000) NOT NULL + ); + + INSERT INTO tmp_Msg_Error ( + id_type + , code + , msg + ) + SELECT + MET.id_type + , @errno + , @text + FROM partsltd_prod.CORE_Msg_Error_Type MET + WHERE MET.code = 'MYSQL_ERROR' + ; + + SELECT * + FROM tmp_Msg_Error; + DROP TABLE IF EXISTS tmp_Msg_Error + ; + END; + + SET v_time_start := CURRENT_TIMESTAMP(6); + SET v_code_type_error_bad_data := 'BAD_DATA'; + SET v_id_type_error_bad_data := (SELECT id_type FROM partsltd_prod.CORE_Msg_Error_Type WHERE code = v_code_type_error_bad_data LIMIT 1); + SET v_id_permission_contact_form_admin := (SELECT id_permission FROM partsltd_prod.PH_Permission P WHERE P.code = 'CONTACT_FORM_ADMIN' LIMIT 1); + SET v_id_permission_contact_form_new := (SELECT id_permission FROM partsltd_prod.PH_Permission P WHERE P.code = 'CONTACT_FORM_NEW' LIMIT 1); + + CALL partsltd_prod.p_core_validate_guid ( a_guid ); + + DROP TABLE IF EXISTS tmp_Contact_Form; + + CREATE TEMPORARY TABLE tmp_Contact_Form ( + id_contact_form INT NOT NULL + , email VARCHAR(255) NOT NULL + , name_contact VARCHAR(255) NOT NULL + , name_company VARCHAR(255) NOT NULL + , message TEXT NOT NULL + , receive_marketing_communications BIT NOT NULL + , active BIT NOT NULL + , name_error VARCHAR(255) + , is_new BIT NOT NULL + ); + + CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( + display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT + , id_type INT NULL + , code VARCHAR(50) NOT NULL + , msg VARCHAR(4000) NOT NULL + ); + + + -- Get data from Temp table + INSERT INTO tmp_Contact_Form ( + id_contact_form + , email + , name_contact + , name_company + , message + , receive_marketing_communications + , active + , is_new + ) + SELECT + CF_T.id_contact_form AS id_contact_form + , IFNULL(CF_T.email, CF.email) AS code + , IFNULL(CF_T.name_contact, CF.name_contact) AS name_contact + , IFNULL(CF_T.name_company, CF.name_company) AS name_company + , IFNULL(CF_T.message, CF.message) AS message + , COALESCE(CF_T.receive_marketing_communications, CF.receive_marketing_communications, 0) AS receive_marketing_communications + , COALESCE(CF_T.active, CF.active, 1) AS active + , CASE WHEN IFNULL(CF_T.id_contact_form, 0) < 1 THEN 1 ELSE 0 END AS is_new + FROM partsltd_prod.PH_Contact_Form_Temp CF_T + LEFT JOIN partsltd_prod.PH_Contact_Form CF ON CF_T.id_contact_form = CF.id_contact_form + WHERE CF_T.guid = a_guid + ; + + UPDATE tmp_Contact_Form t_CF + SET name_error = COALESCE(t_CF.email, t_CF.name_company, t_CF.name_contact, t_CF.message, '(No Contact Form)') + ; + + -- Validation + -- Missing mandatory fields + -- email + IF EXISTS (SELECT * FROM tmp_Contact_Form t_CF WHERE ISNULL(t_CF.email) LIMIT 1) THEN + INSERT INTO tmp_Msg_Error ( + id_type + , code + , msg + ) + SELECT + v_id_type_error_bad_data + , v_code_type_error_bad_data + , CONCAT('The following Contact Form(s) do not have an Email: ', GROUP_CONCAT(t_CF.name_error SEPARATOR ', ')) AS msg + FROM tmp_Contact_Form t_CF + WHERE ISNULL(t_CF.email) + ; + END IF; + -- name_contact + IF EXISTS (SELECT * FROM tmp_Contact_Form t_CF WHERE ISNULL(t_CF.name_contact) LIMIT 1) THEN + INSERT INTO tmp_Msg_Error ( + id_type + , code + , msg + ) + SELECT + v_id_type_error_bad_data + , v_code_type_error_bad_data + , CONCAT('The following Contact Form(s) do not have a Contact Name: ', GROUP_CONCAT(t_CF.name_error SEPARATOR ', ')) AS msg + FROM tmp_Contact_Form t_CF + WHERE ISNULL(t_CF.name_contact) + ; + END IF; + -- name_company + IF EXISTS (SELECT * FROM tmp_Contact_Form t_CF WHERE ISNULL(t_CF.name_company) LIMIT 1) THEN + INSERT INTO tmp_Msg_Error ( + id_type + , code + , msg + ) + SELECT + v_id_type_error_bad_data + , v_code_type_error_bad_data + , CONCAT('The following Contact Form(s) do not have a Company Name: ', GROUP_CONCAT(t_CF.name_error SEPARATOR ', ')) AS msg + FROM tmp_Contact_Form t_CF + WHERE ISNULL(t_CF.name) + ; + END IF; + -- message + IF EXISTS (SELECT * FROM tmp_Contact_Form t_CF WHERE ISNULL(t_CF.message) LIMIT 1) THEN + INSERT INTO tmp_Msg_Error ( + id_type + , code + , msg + ) + SELECT + v_id_type_error_bad_data + , v_code_type_error_bad_data + , CONCAT('The following Contact Form(s) do not have a Message: ', GROUP_CONCAT(t_CF.name_error SEPARATOR ', ')) AS msg + FROM tmp_Contact_Form t_CF + WHERE ISNULL(t_CF.message) + ; + END IF; + + -- Permissions + IF a_debug = 1 THEN + SELECT + a_guid + , a_id_user + , FALSE -- a_get_inactive_user + , v_id_permission_contact_form_admin + , v_id_permission_contact_form_new + , 0 -- a_debug + ; + END IF; + + CALL partsltd_prod.p_ph_calc_user( + a_guid + , a_id_user + , FALSE -- a_get_inactive_user + , v_id_permission_contact_form_admin + , 0 -- a_debug + ); + + SELECT + IFNULL(CU_T.has_access, 0) + INTO + v_can_admin + FROM partsltd_prod.PH_Calc_User_Temp CU_T + WHERE CU_T.GUID = a_guid + LIMIT 1 + ; + + CALL partsltd_prod.p_ph_clear_calc_user( + a_guid + , 0 -- a_debug + ); + + CALL partsltd_prod.p_ph_calc_user( + a_guid + , a_id_user + , FALSE -- a_get_inactive_user + , v_id_permission_contact_form_new + , 0 -- a_debug + ); + + SELECT + IFNULL(CU_T.has_access, 0) + INTO + v_can_create + FROM partsltd_prod.PH_Calc_User_Temp CU_T + WHERE CU_T.GUID = a_guid + LIMIT 1 + ; + + CALL partsltd_prod.p_ph_clear_calc_user( + a_guid + , 0 -- a_debug + ); + + IF (v_can_create = 0 AND EXISTS(SELECT * FROM tmp_Contact_Form WHERE is_new = 1)) THEN + DELETE t_ME + FROM tmp_Msg_Error t_ME + WHERE t_ME.id_type <> v_id_type_error_no_permission + ; + INSERT INTO tmp_Msg_Error ( + id_type + , code + , msg + ) + VALUES ( + v_id_type_error_no_permission + , v_code_type_error_no_permission + , 'You do not have permission to create new Contact Forms.' + ) + ; + END IF; + + IF (v_can_admin = 0 AND EXISTS(SELECT * FROM tmp_Contact_Form WHERE is_new = 0)) THEN + DELETE t_ME + FROM tmp_Msg_Error t_ME + WHERE t_ME.id_type <> v_id_type_error_no_permission + ; + INSERT INTO tmp_Msg_Error ( + id_type + , code + , msg + ) + VALUES ( + v_id_type_error_no_permission + , v_code_type_error_no_permission + , 'You do not have permission to admin Contact Forms.' + ) + ; + END IF; + + IF EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN + IF a_debug = 1 THEN + SELECT * from tmp_Contact_Form; + END IF; + + DELETE FROM tmp_Contact_Form; + END IF; + + IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN + START TRANSACTION; + + INSERT INTO partsltd_prod.PH_Contact_Form_Change_Set ( + comment + , id_user_updated_last_by + , updated_last_on + ) + VALUES ( + a_comment + , a_id_user + , v_time_start + ) + ; + + SET v_id_change_set := LAST_INSERT_ID(); + + UPDATE partsltd_prod.PH_Contact_Form CF + INNER JOIN tmp_Contact_Form t_CF + ON CF.id_contact_form = t_CF.id_contact_form + AND t_CF.is_new = 0 + SET + CF.email = t_CF.email + , CF.name_contact = t_CF.name_contact + , CF.name_company = t_CF.name_company + , CF.message = t_CF.message + , CF.receive_marketing_communications = t_CF.receive_marketing_communications + , CF.active = t_CF.active + , CF.id_change_set = v_id_change_set + ; + + INSERT INTO partsltd_prod.PH_Contact_Form ( + email + , name_contact + , name_company + , message + , receive_marketing_communications + , active + , id_user_created_by + , created_on + ) + SELECT + t_CF.email AS email + , t_CF.name_contact AS name_contact + , t_CF.name_company AS name_company + , t_CF.message AS message + , t_CF.receive_marketing_communications AS receive_marketing_communications + , t_CF.active AS active + , a_id_user AS created_by + , v_time_start AS created_on + FROM tmp_Contact_Form t_CF + WHERE + t_CF.is_new = 1 + AND t_CF.active = 1 + ; + + COMMIT; + END IF; + + START TRANSACTION; + + DELETE FROM partsltd_prod.PH_Contact_Form_Temp + WHERE GUID = a_guid + ; + + COMMIT; + + -- Errors + SELECT * + FROM tmp_Msg_Error t_ME + INNER JOIN partsltd_prod.CORE_Msg_Error_Type MET ON t_ME.id_type = MET.id_type + ; + + IF a_debug = 1 THEN + SELECT * from tmp_Contact_Form; + END IF; + + DROP TEMPORARY TABLE tmp_Contact_Form; + DROP TEMPORARY TABLE tmp_Msg_Error; + + IF a_debug = 1 THEN + CALL partsltd_prod.p_core_debug_timing_reporting ( v_time_start ); + END IF; +END // +DELIMITER ; + +/* +select + * + -- COUNT(*) +-- delete +from partsltd_prod.PH_Contact_Form_Temp +; + + +CALL partsltd_prod.p_ph_save_product_CFategory ( + 'nipples' + , (SELECT GUID FROM partsltd_prod.PH_Contact_Form_Temp ORDER BY id_temp DESC LIMIT 1) + , 1 + , 1 +); + +select + * + -- COUNT(*) +-- delete +from partsltd_prod.PH_Contact_Form_Temp +; + +*/ diff --git a/static/MySQL/7202_p_ph_test_save_contact_form.sql b/static/MySQL/7202_p_ph_test_save_contact_form.sql new file mode 100644 index 00000000..103735f9 --- /dev/null +++ b/static/MySQL/7202_p_ph_test_save_contact_form.sql @@ -0,0 +1,108 @@ +USE partsltd_prod; + +DROP PROCEDURE IF EXISTS partsltd_prod.p_ph_test_save_contact_form; + + +DELIMITER // +CREATE PROCEDURE partsltd_prod.p_ph_test_save_contact_form () +BEGIN + + DECLARE v_guid BINARY(36); + DECLARE v_time_start TIMESTAMP(6); + + SET v_time_start := CURRENT_TIMESTAMP(6); + SET v_guid := 'nipple_ripple_chipple_spittle_pickle'; -- 123456789012345678901234567890123456 + + SELECT 'Start of Test'; + + SELECT * + FROM partsltd_prod.PH_Contact_Form + ; + SELECT * + FROM partsltd_prod.PH_Contact_Form_Temp + ; + + START TRANSACTION; + + INSERT INTO partsltd_prod.PH_Contact_Form_Temp ( + id_contact_form + , email + , name_contact + , name_company + , message + , guid + , active + ) + /* + VALUES ( + -1 -- id_contact_form + , 'edward.middletonsmith@gmail.com' -- email + , 'Teddy' -- name_contact + , 'PARTS Ltd' -- name_company + , 'Sa dude' -- message + , v_guid + ) + */ + VALUES ( + -1 -- id_contact_form + , 'edward.middletonsmith@gmail.com' -- email + , 'Teddy' -- name_contact + , 'PARTS Ltd' -- name_company + , 'hegrodorf is good' -- message + , v_guid + , 1 -- active + ) + ; + + COMMIT; + + SELECT * + FROM partsltd_prod.PH_Contact_Form_Temp + -- WHERE GUID = v_guid + ; + + CALL partsltd_prod.p_ph_save_contact_form ( + 'Test save Contact Form' -- comment + , v_guid -- guid + , 3 -- 1 -- id_user + , 1 -- debug + ); + + SELECT * + FROM partsltd_prod.PH_Contact_Form + ; + SELECT * + FROM partsltd_prod.PH_Contact_Form_Temp + ; + + CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); +END // +DELIMITER ; + + +/* +SELECT 'Before Test'; +SELECT * +FROM partsltd_prod.PH_Contact_Form +; +SELECT * +FROM partsltd_prod.PH_Contact_Form_Temp +; + + +CALL partsltd_prod.p_ph_test_save_contact_form (); + +SELECT 'After Test'; +SELECT * +FROM partsltd_prod.PH_Contact_Form +; +SELECT * +FROM partsltd_prod.PH_Contact_Form_Temp +; + +DELETE FROM partsltd_prod.PH_Contact_Form_Temp; + +DROP TABLE IF EXISTS tmp_Msg_Error; + + +*/ diff --git a/static/MySQL/7202_p_shop_clear_calc_product_permutation.sql b/static/MySQL/7202_p_shop_clear_calc_product_permutation.sql deleted file mode 100644 index 400c8c1f..00000000 --- a/static/MySQL/7202_p_shop_clear_calc_product_permutation.sql +++ /dev/null @@ -1,52 +0,0 @@ - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_clear_calc_product_permutation; - - -DELIMITER // -CREATE PROCEDURE p_shop_clear_calc_product_permutation ( - IN a_guid BINARY(36) -) -BEGIN - IF ISNULL(a_guid) THEN - - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'GUID is required.'; - - ELSE - - START TRANSACTION; - - DELETE FROM Shop_Product_Category_Temp - WHERE GUID = a_guid - ; - DELETE FROM Shop_Product_Temp - WHERE GUID = a_guid - ; - DELETE FROM Shop_Product_Permutation_Temp - WHERE GUID = a_guid - ; - - COMMIT; - END IF; - -END // -DELIMITER ; - -/* - -CALL p_shop_clear_calc_product_permutation ( - 'noods, cheese ' -- a_guid -); - -SELECT * FROM Shop_Product_Category_Temp -WHERE GUID = a_guid -; -SELECT * FROM Shop_Product_Temp -WHERE GUID = a_guid -; -SELECT * FROM Shop_Product_Permutation_Temp -WHERE GUID = a_guid -; - -*/ diff --git a/static/MySQL/7203_p_ph_get_many_contact_form.sql b/static/MySQL/7203_p_ph_get_many_contact_form.sql new file mode 100644 index 00000000..30d35d96 --- /dev/null +++ b/static/MySQL/7203_p_ph_get_many_contact_form.sql @@ -0,0 +1,251 @@ + +USE partsltd_prod; + +DROP PROCEDURE IF EXISTS partsltd_prod.p_ph_get_many_contact_form; + +DELIMITER // +CREATE PROCEDURE partsltd_prod.p_ph_get_many_contact_form ( + IN a_id_user INT + , IN a_get_all_contact_form BIT + , IN a_get_inactive_contact_form BIT + , IN a_ids_contact_form VARCHAR(500) + , IN a_debug BIT +) +BEGIN + DECLARE v_has_filter_contact_form BIT; + DECLARE v_guid BINARY(36); + DECLARE v_id_permission_contact_form_view INT; + DECLARE v_id_minimum INT; + DECLARE v_time_start TIMESTAMP(6); + DECLARE v_can_view BIT; + + SET v_time_start := CURRENT_TIMESTAMP(6); + SET v_guid := UUID(); + SET v_id_permission_contact_form_view := (SELECT id_permission FROM partsltd_prod.PH_Permission WHERE code = 'CONTACT_FORM_ADMIN' LIMIT 1); + + SET a_id_user := IFNULL(a_id_user, 0); + SET a_get_all_contact_form := IFNULL(a_get_all_contact_form, 0); + SET a_get_inactive_contact_form := IFNULL(a_get_inactive_contact_form, 0); + SET a_ids_contact_form := TRIM(IFNULL(a_ids_contact_form, '')); + SET a_debug := IFNULL(a_debug, 0); + + IF a_debug = 1 THEN + SELECT + a_id_user + , a_get_all_contact_form + , a_get_inactive_contact_form + , a_ids_contact_form + , a_debug + ; + END IF; + + DROP TEMPORARY TABLE IF EXISTS tmp_Split; + DROP TEMPORARY TABLE IF EXISTS tmp_Contact_Form; + + CREATE TEMPORARY TABLE tmp_Contact_Form ( + id_contact_form INT NOT NULL + ); + + CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( + display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT + , id_type INT NULL + , code VARCHAR(50) NOT NULL + , msg VARCHAR(4000) NOT NULL + ); + + CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Split ( + substring VARCHAR(4000) NOT NULL + , as_int INT NULL + ); + DELETE FROM tmp_Split; + + CALL partsltd_prod.p_core_validate_guid ( v_guid ); + + SET v_has_filter_contact_form = CASE WHEN a_ids_contact_form = '' THEN 0 ELSE 1 END; + + -- Contact Forms + IF v_has_filter_contact_form = 1 THEN + CALL partsltd_prod.p_split(v_guid, a_ids_contact_form, ',', a_debug); + + INSERT INTO tmp_Split ( + substring + , as_int + ) + SELECT + substring + , CONVERT(substring, DECIMAL(10,0)) AS as_int + FROM partsltd_prod.CORE_Split_Temp + WHERE + GUID = v_guid + AND NOT ISNULL(substring) + AND substring != '' + ; + + CALL partsltd_prod.p_clear_split_temp( v_guid ); + END IF; + + IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN + IF EXISTS ( + SELECT * + FROM tmp_Split t_S + LEFT JOIN partsltd_prod.PH_Contact_Form CF ON t_S.as_int = CF.id_contact_form + WHERE + ISNULL(t_S.as_int) + OR ISNULL(CF.id_contact_form) + OR ( + CF.active = 0 + AND a_get_inactive_contact_form = 0 + ) + ) THEN + INSERT INTO tmp_Msg_Error ( + id_type + , code + , msg + ) + SELECT + v_id_type_error_bad_data + , v_code_type_error_bad_data + , CONCAT('Invalid or inactive Contact Form IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) + FROM tmp_Split t_S + LEFT JOIN partsltd_prod.PH_Contact_Form CF ON t_S.as_int = CF.id_contact_form + WHERE + ISNULL(t_S.as_int) + OR ISNULL(CF.id_contact_form) + OR ( + CF.active = 0 + AND a_get_inactive_contact_form = 0 + ) + ; + ELSE + INSERT INTO tmp_Contact_Form ( + id_contact_form + ) + SELECT + CF.id_contact_form + FROM tmp_Split t_S + RIGHT JOIN partsltd_prod.PH_Contact_Form CF ON t_S.as_int = CF.id_contact_form + WHERE + ( + a_get_all_contact_form = 1 + OR ( + v_has_filter_contact_form = 1 + AND NOT ISNULL(t_S.as_int) + ) + ) + AND ( + a_get_inactive_contact_form = 1 + OR CF.active = 1 + ) + ; + END IF; + END IF; + + DELETE FROM tmp_Split; + + + -- Permissions + IF a_debug = 1 THEN + SELECT + v_guid + , a_id_user + , FALSE -- a_get_inactive_user + , v_id_permission_contact_form_view + , 0 -- a_debug + ; + END IF; + + CALL partsltd_prod.p_ph_calc_user( + v_guid + , a_id_user + , FALSE -- a_get_inactive_user + , v_id_permission_contact_form_view + , 0 -- a_debug + ); + + SELECT + IFNULL(CU_T.has_access, 0) + INTO + v_can_view + FROM partsltd_prod.PH_Calc_User_Temp CU_T + WHERE CU_T.GUID = v_guid + LIMIT 1 + ; + + IF (v_can_view = 0) THEN + DELETE t_ME + FROM tmp_Msg_Error t_ME + WHERE t_ME.id_type <> v_id_type_error_no_permission + ; + INSERT INTO tmp_Msg_Error ( + id_type + , code + , msg + ) + VALUES ( + v_id_type_error_no_permission + , v_code_type_error_no_permission + , 'You do not have permission to view Contact Forms.' + ) + ; + END IF; + + CALL partsltd_prod.p_ph_clear_calc_user( + v_guid + , 0 -- a_debug + ); + + IF v_can_view = 0 THEN + IF a_debug = 1 THEN + SELECT * FROM tmp_Contact_Form; + END IF; + + DELETE FROM tmp_Contact_Form; + END IF; + + -- Outputs + -- Contact Forms + SELECT + t_CF.id_contact_form + , CF.email + , CF.name_contact + , CF.name_company + , CF.message + , CF.active + , v_can_view + FROM tmp_Contact_Form t_CF + INNER JOIN partsltd_prod.PH_Contact_Form CF ON t_CF.id_contact_form = CF.id_contact_form + GROUP BY t_CF.id_contact_form + ORDER BY CF.created_on DESC + ; + + -- Errors + SELECT * + FROM tmp_Msg_Error t_ME + INNER JOIN partsltd_prod.CORE_Msg_Error_Type MET ON t_ME.id_type = MET.id_type + ; + + IF a_debug = 1 AND v_can_view = 1 THEN + SELECT * FROM tmp_Contact_Form; + END IF; + + DROP TEMPORARY TABLE IF EXISTS tmp_Split; + DROP TEMPORARY TABLE IF EXISTS tmp_Contact_Form; + + IF a_debug = 1 THEN + CALL partsltd_prod.p_core_debug_timing_reporting ( v_time_start ); + END IF; +END // +DELIMITER ; + + +/* + +CALL partsltd_prod.p_ph_get_many_contact_form ( + 1 -- 'auth0|6582b95c895d09a70ba10fef', -- a_id_user + , 1 -- a_get_all_contact_form + , 0 -- a_get_inactive_contact_form + , '' -- a_ids_contact_form + , 0 -- a_debug +); + +*/ diff --git a/static/MySQL/7203_p_shop_save_product.sql b/static/MySQL/7203_p_shop_save_product.sql deleted file mode 100644 index b1489e03..00000000 --- a/static/MySQL/7203_p_shop_save_product.sql +++ /dev/null @@ -1,348 +0,0 @@ - - - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_save_product; -DROP PROCEDURE IF EXISTS p_shop_save_product; - - -DELIMITER // -CREATE PROCEDURE p_shop_save_product ( - IN a_comment VARCHAR(500), - IN a_guid BINARY(36), - IN a_id_user INT, - IN a_debug BIT -) -BEGIN - DECLARE v_code_type_error_bad_data VARCHAR(100); - DECLARE v_id_access_level_edit INT; - DECLARE v_id_type_error_bad_data INT; - DECLARE v_id_permission_product INT; - DECLARE v_ids_product_permission LONGTEXT; - DECLARE v_id_change_set INT; - DECLARE v_time_start TIMESTAMP(6); - - DECLARE exit handler for SQLEXCEPTION - BEGIN - -- Get diagnostic information - GET DIAGNOSTICS CONDITION 1 - @sqlstate = RETURNED_SQLSTATE - , @errno = MYSQL_ERRNO - , @text = MESSAGE_TEXT - ; - - -- Rollback the transaction - ROLLBACK; - - -- Select the error information - -- SELECT 'Error' AS status, @errno AS error_code, @sqlstate AS sql_state, @text AS message; - INSERT INTO tmp_Msg_Error ( - -- guid - id_type - , code - , msg - ) - SELECT - -- a_guid - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'MYSQL_ERROR' LIMIT 1) - , @errno - , IFNULL(@text, 'NULL') - ; - - SELECT * - FROM tmp_Msg_Error t_ME - INNER JOIN partsltd_prod.Shop_Msg_Error_Type MET ON t_ME.id_type = MET.id_type - ; - - DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error; - DROP TEMPORARY TABLE IF EXISTS tmp_Product; - END; - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_code_type_error_bad_data := (SELECT code FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1); - SET v_id_type_error_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_type_error_bad_data LIMIT 1); - SET v_id_access_level_edit := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'EDIT' LIMIT 1); - - CALL p_validate_guid ( a_guid ); - SET a_debug := IFNULL(a_debug, 0); - - IF a_debug = 1 THEN - SELECT - v_code_type_error_bad_data - , v_id_type_error_bad_data - ; - END IF; - - DROP TEMPORARY TABLE IF EXISTS tmp_Product; - DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error; - - CREATE TEMPORARY TABLE tmp_Product ( - id_category INT NOT NULL - , id_product INT NOT NULL - , name VARCHAR(255) NOT NULL - , has_variations BIT NOT NULL - , id_access_level_required INT NOT NULL - , active BIT NOT NULL - , display_order INT NOT NULL - , can_view BIT NULL - , can_edit BIT NULL - , can_admin BIT NULL - , name_error VARCHAR(255) NOT NULL - , is_new BIT NOT NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT - -- , guid BINARY(36) NOT NULL - , id_type INT NOT NULL - /* - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type (id_type), - */ - , code VARCHAR(50) NOT NULL - , msg VARCHAR(4000) NOT NULL - ); - - - -- Get data from Temp table - INSERT INTO tmp_Product ( - id_category - , id_product - , name - , has_variations - , id_access_level_required - , active - , display_order - , name_error - , is_new - ) - SELECT - IFNULL(P_T.id_category, P.id_category) AS id_category - , IFNULL(P_T.id_product, 0) AS id_product - , IFNULL(P_T.name, P.name) AS name - , IFNULL(P_T.has_variations, P.has_variations) AS has_variations - , IFNULL(P_T.id_access_level_required, P.id_access_level_required) AS id_access_level_required - , IFNULL(P_T.active, P.active) AS active - , IFNULL(P_T.display_order, P.display_order) AS display_order - , IFNULL(P_T.name, IFNULL(P.name, IFNULL(P_T.id_product, '(No Product)'))) AS name_error - , CASE WHEN IFNULL(P_T.id_product, 0) < 1 THEN 1 ELSE 0 END AS is_new - FROM partsltd_prod.Shop_Product_Temp P_T - LEFT JOIN partsltd_prod.Shop_Product P ON P_T.id_product = P.id_product - ; - - -- Validation - -- Missing mandatory fields - -- id_category - IF EXISTS (SELECT * FROM tmp_Product t_P WHERE ISNULL(t_P.id_category) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , IFNULL(CONCAT('The following product(s) do not have a category: ', GROUP_CONCAT(IFNULL(t_P.name_error, 'NULL') SEPARATOR ', ')), 'NULL') - FROM tmp_Product t_P - WHERE ISNULL(t_P.id_category) - ; - END IF; - - -- name - IF EXISTS (SELECT * FROM tmp_Product t_P WHERE ISNULL(t_P.name) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , IFNULL(CONCAT('The following product(s) do not have a name: ', GROUP_CONCAT(IFNULL(t_P.name_error, 'NULL') SEPARATOR ', ')), 'NULL') - FROM tmp_Product t_P - WHERE ISNULL(t_P.name) - ; - END IF; - - -- has_variations - IF EXISTS (SELECT * FROM tmp_Product t_P WHERE ISNULL(t_P.has_variations) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , IFNULL(CONCAT('The following product(s) do not have a has-variations setting: ', GROUP_CONCAT(IFNULL(t_P.name_error, 'NULL') SEPARATOR ', ')), 'NULL') - FROM tmp_Product t_P - WHERE ISNULL(t_P.has_variations) - ; - END IF; - - -- id_access_level_required - IF EXISTS (SELECT * FROM tmp_Product t_P WHERE ISNULL(t_P.id_access_level_required) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , IFNULL(CONCAT('The following product(s) do not have a required access level ID: ', GROUP_CONCAT(IFNULL(t_P.name_error, 'NULL') SEPARATOR ', ')), 'NULL') - FROM tmp_Product t_P - WHERE ISNULL(t_P.id_access_level_required) - ; - END IF; - - -- display_order - IF EXISTS (SELECT * FROM tmp_Product t_P WHERE ISNULL(t_P.display_order) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , IFNULL(CONCAT('The following product(s) do not have a display order: ', GROUP_CONCAT(IFNULL(t_P.name_error, 'NULL') SEPARATOR ', ')), 'NULL') - FROM tmp_Product t_P - WHERE ISNULL(t_P.display_order) - ; - END IF; - - - -- Permissions - SET v_ids_product_permission := (SELECT GROUP_CONCAT(id_product SEPARATOR ',') FROM tmp_Product WHERE is_new = 0); - - SET v_id_permission_product = (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_PRODUCT' LIMIT 1); - - CALL partsltd_prod.p_shop_calc_user( - a_guid - , a_id_user - , FALSE -- get_inactive_users - , v_id_permission_product - , v_id_access_level_edit - , v_ids_product_permission - , 0 -- debug - ); - - UPDATE tmp_Product t_P - INNER JOIN partsltd_prod.Shop_Calc_User_Temp UE_T - ON t_P.id_product = UE_T.id_product - AND UE_T.GUID = a_guid - SET - t_P.can_view = UE_T.can_view - , t_P.can_edit = UE_T.can_edit - , t_P.can_admin = UE_T.can_admin - ; - - IF EXISTS (SELECT * FROM tmp_Product WHERE IFNULL(can_edit, 0) = 0 AND is_new = 0 LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_no_permission - , v_code_type_error_no_permission - , CONCAT('You do not have permission to edit the following Product(s): ', IFNULL(GROUP_CONCAT(IFNULL(t_P.name_error, 'NULL') SEPARATOR ', '), 'NULL')) - FROM tmp_Product t_P - WHERE - IFNULL(can_edit, 0) = 0 - AND is_new = 0 - ; - END IF; - - IF EXISTS (SELECT * FROM partsltd_prod.Shop_Calc_User_Temp WHERE ISNULL(id_product) AND GUID = a_guid AND can_edit = 0) THEN - DELETE t_ME - FROM tmp_Msg_Error t_ME - WHERE t_ME.id_type <> v_id_type_error_no_permission - ; - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - VALUES ( - v_id_type_error_no_permission - , v_code_type_error_no_permission - , 'You do not have permission to edit Products' - ) - ; - END IF; - - CALL partsltd_prod.p_shop_clear_calc_user( - a_guid - , 0 -- debug - ); - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - START TRANSACTION; - - INSERT INTO partsltd_prod.Shop_Product_Change_Set ( comment ) - VALUES ( a_comment ) - ; - - SET v_id_change_set := LAST_INSERT_ID(); - - UPDATE partsltd_prod.Shop_Product P - INNER JOIN tmp_Product t_P ON P.id_product = t_P.id_product - SET - P.id_category = t_P.id_category - , P.name = t_P.name - , P.has_variations = t_P.has_variations - , P.id_access_level_required = t_P.id_access_level_required - , P.display_order = t_P.display_order - , P.active = t_P.active - , P.id_change_set = v_id_change_set - ; - - INSERT INTO partsltd_prod.Shop_Product ( - id_category - , name - , has_variations - , id_access_level_required - , display_order - , created_by - , created_on - ) - SELECT - t_P.id_category AS id_category - , t_P.name AS name - , t_P.has_variations AS has_variations - , t_P.id_access_level_required AS id_access_level_required - , t_P.display_order AS display_order - , a_id_user AS created_by - , v_time_start AS created_on - FROM tmp_Product t_P - WHERE is_new = 1 - ; - - COMMIT; - END IF; - - START TRANSACTION; - - DELETE FROM partsltd_prod.Shop_Product_Temp - WHERE GUID = a_guid; - - COMMIT; - - SELECT * - FROM tmp_Msg_Error t_ME - INNER JOIN partsltd_prod.Shop_Msg_Error_Type MET ON t_ME.id_type = MET.id_type - ; - - DROP TEMPORARY TABLE IF EXISTS tmp_Product; - DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error; - - IF a_debug = 1 THEN - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); - END IF; -END // -DELIMITER ; - diff --git a/static/MySQL/7203_p_shop_save_product_test.sql b/static/MySQL/7203_p_shop_save_product_test.sql deleted file mode 100644 index e176ef9e..00000000 --- a/static/MySQL/7203_p_shop_save_product_test.sql +++ /dev/null @@ -1,93 +0,0 @@ - - --- Clear previous proc -DROP PROCEDURE IF EXISTS partsltd_prod.p_shop_save_product_test; - - -DELIMITER // -CREATE PROCEDURE p_shop_save_product_test () -BEGIN - - DECLARE v_guid BINARY(36); - DECLARE v_time_start TIMESTAMP(6); - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_guid := 'nips'; - - SELECT * - FROM partsltd_prod.Shop_Product - ; - SELECT * - FROM partsltd_prod.Shop_Product_Temp - ; - - START TRANSACTION; - - INSERT INTO partsltd_prod.Shop_Product_Temp ( - id_product - , id_category - , name - , has_variations - , id_access_level_required - , display_order - , active - , guid - ) - VALUES - /* Test 1 - Update - ( - 4 -- id_product - , 1 -- id_category - , 'Laptops' -- name - , 0 -- has_variations - , 2 -- id_access_level_required - , 2 -- display_order - , 1 -- active - , v_guid - ) - */ - /* Test 2 - Insert */ - ( - -14 -- id_product - , 5 -- id_category - , 'Clip' -- name - , 0 -- has_variations - , 1 -- id_access_level_required - , 1 -- display_order - , 1 -- active - , v_guid - ) - ; - - COMMIT; - - SELECT * - FROM partsltd_prod.Shop_Product_Temp - WHERE GUID = v_guid - ; - - CALL partsltd_prod.p_shop_save_product ( - 'Test save product' -- comment - , v_guid -- guid - , 1 -- id_user - , 1 -- debug - ); - - SELECT * - FROM partsltd_prod.Shop_Product - ; - SELECT * - FROM partsltd_prod.Shop_Product_Temp - ; - - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); -END // -DELIMITER ; - -/* -CALL partsltd_prod.p_shop_save_product_test (); - -DELETE FROM partsltd_prod.Shop_Product_Temp; - -DROP TABLE IF EXISTS tmp_Msg_Error; -*/ \ No newline at end of file diff --git a/static/MySQL/7204_p_ph_test_get_many_contact_form.sql b/static/MySQL/7204_p_ph_test_get_many_contact_form.sql new file mode 100644 index 00000000..e69de29b diff --git a/static/MySQL/7204_p_shop_calc_product_permutation.sql b/static/MySQL/7204_p_shop_calc_product_permutation.sql deleted file mode 100644 index eb0fefe7..00000000 --- a/static/MySQL/7204_p_shop_calc_product_permutation.sql +++ /dev/null @@ -1,715 +0,0 @@ --- USE partsltd_prod; - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_calc_product_permutation; - -DELIMITER // -CREATE PROCEDURE p_shop_calc_product_permutation ( - IN a_id_user INT - , IN a_get_all_product_category BIT - , IN a_get_inactive_product_category BIT - , IN a_ids_product_category TEXT - , IN a_get_all_product BIT - , IN a_get_inactive_product BIT - , IN a_ids_product TEXT - , IN a_get_all_product_permutation BIT - , IN a_get_inactive_permutation BIT - , IN a_ids_permutation TEXT - , IN a_get_products_quantity_stock_below_min BIT - , IN a_guid BINARY(36) - , IN a_debug BIT -) -BEGIN -/* - PROCEDURE p_shop_calc_product_permutation - Shared filtering for product permutations - - select * FROM partsltd_prod.Shop_msg_error_type; -*/ - DECLARE v_has_filter_product_category BIT; - DECLARE v_has_filter_product BIT; - DECLARE v_has_filter_permutation BIT; - DECLARE v_id_permission_product INT; - DECLARE v_ids_product_permission TEXT; - DECLARE v_id_access_level_view INT; - DECLARE v_id_minimum INT; - DECLARE v_ids_product_invalid TEXT; - DECLARE v_ids_category_invalid TEXT; - DECLARE v_time_start TIMESTAMP(6); - DECLARE v_id_type_error_bad_data INT; - DECLARE v_code_type_error_bad_data VARCHAR(50); - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_id_access_level_view := (SELECT id_access_level FROM partsltd_prod.Shop_Access_Level WHERE code = 'VIEW'); - - SELECT - MET.id_type - , MET.code - INTO - v_id_type_error_bad_data - , v_code_type_error_bad_data - FROM partsltd_prod.Shop_Msg_Error_Type MET - WHERE MET.code = 'BAD_DATA' - ; - - SET a_id_user := IFNULL(a_id_user, 0); - SET a_get_all_product_category := IFNULL(a_get_all_product_category, 0); - SET a_get_inactive_product_category := IFNULL(a_get_inactive_product_category, 0); - SET a_ids_product_category := TRIM(IFNULL(a_ids_product_category, '')); - SET a_get_all_product := IFNULL(a_get_all_product, 0); - SET a_get_inactive_product := IFNULL(a_get_inactive_product, 0); - SET a_ids_product := TRIM(IFNULL(a_ids_product, '')); - SET a_get_all_product_permutation := IFNULL(a_get_all_product_permutation, 0); - SET a_get_inactive_permutation := IFNULL(a_get_inactive_permutation, 0); - SET a_ids_permutation := TRIM(IFNULL(a_ids_permutation, '')); - SET a_get_products_quantity_stock_below_min := IFNULL(a_get_products_quantity_stock_below_min, 0); - -- SET a_guid := IFNULL(a_guid, UUID()); - SET a_debug := IFNULL(a_debug, 0); - - IF a_debug = 1 THEN - SELECT - a_id_user - , a_get_all_product_category, a_ids_product_category, a_get_inactive_product_category - , a_get_all_product, a_get_inactive_product, a_ids_product - , a_get_all_product_permutation, a_get_inactive_permutation, a_ids_permutation - , a_get_products_quantity_stock_below_min - , a_debug - ; - END IF; - - -- Temporary tables - -- DROP TEMPORARY TABLE IF EXISTS tmp_Split; - DROP TEMPORARY TABLE IF EXISTS tmp_Category_calc; - DROP TEMPORARY TABLE IF EXISTS tmp_Product_calc; - DROP TEMPORARY TABLE IF EXISTS tmp_Permutation_calc; - - - CREATE TEMPORARY TABLE tmp_Category_calc ( - id_category INT NOT NULL - -- , active BIT NOT NULL - -- display_order INT NOT NULL - ); - - CREATE TEMPORARY TABLE tmp_Product_calc ( - id_category INT NOT NULL - , id_product INT NOT NULL - -- active BIT NOT NULL - -- display_order INT NOT NULL - , can_view BIT - , can_edit BIT - , can_admin BIT - ); - - CREATE TEMPORARY TABLE tmp_Permutation_calc ( - id_permutation INT NULL - -- id_category INT NOT NULL - , id_product INT NOT NULL - -- , active BIT NOT NULL - -- , display_order INT NOT NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT - -- , guid BINARY(36) NOT NULL - , id_type INT NULL - , code VARCHAR(50) NOT NULL - , msg VARCHAR(4000) NOT NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Split ( - substring VARCHAR(4000) NOT NULL - , as_int INT NULL - ); - DELETE FROM tmp_Split; - - -- Parse filters - SET v_has_filter_product_category = CASE WHEN a_ids_product_category = '' THEN 0 ELSE 1 END; - SET v_has_filter_product = CASE WHEN a_ids_product = '' THEN 0 ELSE 1 END; - SET v_has_filter_permutation = CASE WHEN a_ids_permutation = '' THEN 0 ELSE 1 END; - - CALL p_validate_guid ( a_guid ); - - IF a_debug = 1 THEN - SELECT - v_has_filter_product_category - , v_has_filter_product - , v_has_filter_permutation - ; - END IF; - - -- Categories - IF TRUE THEN -- NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - CALL partsltd_prod.p_split(a_guid, a_ids_product_category, ',', a_debug); - - INSERT INTO tmp_Split ( - substring - , as_int - ) - SELECT - substring - , CONVERT(substring, DECIMAL(10,0)) AS as_int - FROM partsltd_prod.Split_Temp - WHERE 1=1 - AND GUID = a_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( a_guid ); - END IF; - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Product_Category PC ON t_S.as_int = PC.id_category - WHERE - ISNULL(t_S.as_int) - OR ISNULL(PC.id_category) - OR ( - PC.active = 0 - AND a_get_inactive_product_category = 0 - ) - ) THEN - INSERT INTO tmp_Msg_Error ( - -- guid, - id_type, - code, - msg - ) - SELECT - -- a_guid, - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Invalid or inactive category IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Product_Category PC ON t_S.as_int = PC.id_category - WHERE - ISNULL(t_S.as_int) - OR ISNULL(PC.id_category) - OR ( - PC.active = 0 - AND a_get_inactive_product_category = 0 - ) - ; - ELSE - INSERT INTO tmp_Category_calc ( - id_category - ) - SELECT - PC.id_category - FROM tmp_Split t_S - RIGHT JOIN partsltd_prod.Shop_Product_Category PC ON t_S.as_int = PC.id_category - WHERE ( - a_get_all_product_category = 1 - OR ( - v_has_filter_product_category = 1 - AND NOT ISNULL(t_S.as_int) - ) - ) - AND ( - a_get_inactive_product_category = 1 - OR PC.active = 1 - ) - ; - END IF; - END IF; - - DELETE FROM tmp_Split; - - -- Products - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - CALL partsltd_prod.p_split(a_guid, a_ids_product, ',', a_debug); - - INSERT INTO tmp_Split ( - substring - , as_int - ) - SELECT - substring - , CONVERT(substring, DECIMAL(10,0)) AS as_int - FROM partsltd_prod.Split_Temp - WHERE 1=1 - AND GUID = a_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( a_guid ); - END IF; - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Product P ON t_S.as_int = P.id_product - WHERE - ISNULL(t_S.as_int) - OR ISNULL(P.id_product) - OR ( - P.active = 0 - AND a_get_inactive_product = 0 - ) - ) THEN - INSERT INTO tmp_Msg_Error ( - -- guid, - id_type, - code, - msg - ) - SELECT - -- a_guid, - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Invalid or inactive product IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Product P ON t_S.as_int = P.id_product - WHERE - ISNULL(t_S.as_int) - OR ISNULL(P.id_product) - OR ( - P.active = 0 - AND a_get_inactive_product = 0 - ) - ; - ELSE - INSERT INTO tmp_Product_calc ( - id_category - , id_product - ) - SELECT - P.id_category - , P.id_product - FROM tmp_Split t_S - RIGHT JOIN partsltd_prod.Shop_Product P ON t_S.as_int = P.id_product - INNER JOIN tmp_Category_calc t_C ON P.id_category = t_C.id_category - WHERE ( - a_get_all_product = 1 - OR ( - v_has_filter_product = 1 - AND NOT ISNULL(t_S.as_int) - ) - ) - AND ( - a_get_inactive_product = 1 - OR P.active = 1 - ) - ; - END IF; - END IF; - - DELETE FROM tmp_Split; - - -- Permutations - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - CALL partsltd_prod.p_split(a_guid, a_ids_product, ',', a_debug); - - INSERT INTO tmp_Split ( - substring - , as_int - ) - SELECT - substring - , CONVERT(substring, DECIMAL(10,0)) AS as_int - FROM partsltd_prod.Split_Temp - WHERE 1=1 - AND GUID = a_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( a_guid ); - END IF; - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Product_Permutation PP ON t_S.as_int = PP.id_permutation - WHERE - ISNULL(t_S.as_int) - OR ISNULL(PP.id_permutation) - ) THEN - INSERT INTO tmp_Msg_Error ( - -- guid, - id_type, - code, - msg - ) - SELECT - -- a_guid, - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Invalid or inactive permutation IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Product_Permutation PP ON t_S.as_int = PP.id_permutation - WHERE - ISNULL(t_S.as_int) - OR ISNULL(PP.id_permutation) - OR ( - PP.active = 0 - AND a_get_inactive_product_permutation = 0 - ) - ; - ELSE - INSERT INTO tmp_Permutation_calc ( - id_permutation - -- id_category, - , id_product - ) - SELECT - PP.id_permutation - -- P.id_category, - , PP.id_product - FROM tmp_Split t_S - RIGHT JOIN partsltd_prod.Shop_Product_Permutation PP ON t_S.as_int = PP.id_permutation - INNER JOIN tmp_Product_calc t_P ON PP.id_product = t_P.id_product - WHERE 1=1 - AND ( - a_get_all_product_permutation = 1 - OR ( - v_has_filter_permutation = 1 - AND NOT ISNULL(t_S.as_int) - ) - ) - AND ( - a_get_products_quantity_stock_below_min = 0 - OR PP.quantity_stock < PP.quantity_min - ) - AND ( - a_get_inactive_permutation = 1 - OR PP.active = 1 - ) - ; - END IF; - END IF; - - DELETE FROM tmp_Split; - - -- Permissions - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF EXISTS (SELECT * FROM tmp_Product_calc LIMIT 1) THEN - SET v_id_permission_product := (SELECT id_permission FROM partsltd_prod.Shop_Permission WHERE code = 'STORE_PRODUCT' LIMIT 1); - SET v_ids_product_permission := (SELECT GROUP_CONCAT(id_product SEPARATOR ',') FROM tmp_Product_calc WHERE NOT ISNULL(id_product)); - - IF a_debug = 1 THEN - SELECT - a_guid AS a_guid - , a_id_user - , false AS a_get_inactive_user - , v_id_permission_product AS a_ids_permission - , v_id_access_level_view AS a_ids_access_level - , v_ids_product_permission AS a_ids_product - ; - END IF; - - CALL p_shop_calc_user( - a_guid - , a_id_user - , false -- a_get_inactive_user - , v_id_permission_product -- a_ids_permission - , v_id_access_level_view -- a_ids_access_level - , v_ids_product_permission -- a_ids_permutation - , false -- a_debug - ); - - - UPDATE tmp_Product_calc t_P - INNER JOIN partsltd_prod.Shop_Calc_User_Temp UE_T - ON t_P.id_product = UE_T.id_product - AND UE_T.GUID = a_guid - SET t_P.can_view = UE_T.can_view, - t_P.can_edit = UE_T.can_edit, - t_P.can_admin = UE_T.can_admin - ; - - IF a_debug = 1 THEN - SELECT * - FROM partsltd_prod.Shop_Calc_User_Temp - WHERE GUID = a_guid - ; - END IF; - - SET v_ids_product_invalid := ( - SELECT GROUP_CONCAT(t_P.id_product SEPARATOR ',') - FROM tmp_Product_calc t_P - WHERE ISNULL(t_P.can_view) - ); - SET v_ids_category_invalid := ( - SELECT GROUP_CONCAT(t_P.id_category SEPARATOR ',') - FROM (SELECT DISTINCT id_category, id_product, can_view FROM tmp_Product_calc) t_P - WHERE ISNULL(t_P.can_view) - ); - - DELETE t_C - FROM tmp_Category_calc t_C - WHERE FIND_IN_SET(t_C.id_category, v_ids_category_invalid) > 0 - ; - - DELETE t_P - FROM tmp_Product_calc t_P - WHERE FIND_IN_SET(t_P.id_product, v_ids_product_invalid) > 0 - ; - - DELETE t_PP - FROM tmp_Permutation_calc t_PP - WHERE FIND_IN_SET(t_PP.id_product, v_ids_product_invalid) > 0 - ; - - CALL p_shop_clear_calc_user( a_guid, a_debug ); - END IF; - END IF; - - IF a_debug = 1 THEN - SELECT * FROM tmp_Category_calc; - SELECT * FROM tmp_Product_calc; - SELECT * FROM tmp_Permutation_calc; - END IF; - - -- Transaction - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - /* - DELETE FROM tmp_Category_calc; - DELETE FROM tmp_Product_calc; - DELETE FROM tmp_Permutation_calc; - ELSE - SELECT * FROM Shop_Product_Category_Temp; - SELECT * FROM Shop_Product_Temp; - SELECT * FROM Shop_Product_Permutation_Temp; - */ - START TRANSACTION; - - -- Categories - INSERT INTO Shop_Product_Category_Temp ( - id_category - , code - , name - , description - , id_access_level_required - , display_order - , active - , can_view - , can_edit - , can_admin - , guid - ) - SELECT - t_C.id_category - , PC.code - , PC.name - , PC.description - , PC.id_access_level_required - , PC.display_order - , PC.active - , MIN(IFNULL(t_P.can_view, 0)) AS can_view - , MIN(IFNULL(t_P.can_edit, 0)) AS can_edit - , MIN(IFNULL(t_P.can_admin, 0)) AS can_admin - , a_guid - FROM tmp_Category_calc t_C - INNER JOIN partsltd_prod.Shop_Product_Category PC ON t_C.id_category = PC.id_category - LEFT JOIN tmp_Product_calc t_P ON t_C.id_category = t_P.id_product - GROUP BY PC.id_category - ; - - -- Products - INSERT INTO Shop_Product_Temp ( - id_product - , id_category - , name - , has_variations - , id_access_level_required - , display_order - , active - , can_view - , can_edit - , can_admin - , guid - ) - SELECT - t_P.id_product - , P.id_category - , P.name - , P.has_variations - , P.id_access_level_required - , P.display_order - , P.active - , t_P.can_view - , t_P.can_edit - , t_P.can_admin - , a_guid - FROM tmp_Product_calc t_P - INNER JOIN partsltd_prod.Shop_Product P ON t_P.id_product = P.id_product - INNER JOIN tmp_Category_calc t_C ON t_P.id_category = t_C.id_category - INNER JOIN partsltd_prod.Shop_Access_Level AL ON P.id_access_level_required = AL.id_access_level - GROUP BY P.id_product, t_P.can_view, t_P.can_edit, t_P.can_admin - ; - - -- Product Permutations - INSERT INTO Shop_Product_Permutation_Temp ( - id_permutation - , id_product - , description - , cost_local_VAT_excl - , cost_local_VAT_incl - , id_currency_cost - , profit_local_min - , latency_manufacture - , id_unit_measurement_quantity - , count_unit_measurement_per_quantity_step - , quantity_min - , quantity_max - , quantity_stock - , is_subscription - , id_unit_measurement_interval_recurrence - , count_interval_recurrence - , id_stripe_product - , does_expire_faster_once_unsealed - , id_unit_measurement_interval_expiration_unsealed - , count_interval_expiration_unsealed - , active - , can_view - , can_edit - , can_admin - , guid - ) - SELECT - t_PP.id_permutation - , PP.id_product - , PP.description - , PP.cost_local_VAT_excl - , PP.cost_local_VAT_incl - , PP.id_currency_cost - , PP.profit_local_min - , PP.latency_manufacture - , PP.id_unit_measurement_quantity - , PP.count_unit_measurement_per_quantity_step - , PP.quantity_min - , PP.quantity_max - , PP.quantity_stock - , PP.is_subscription - , PP.id_unit_measurement_interval_recurrence - , PP.count_interval_recurrence - , PP.id_stripe_product - , PP.does_expire_faster_once_unsealed - , PP.id_unit_measurement_interval_expiration_unsealed - , PP.count_interval_expiration_unsealed - , PP.active - , IFNULL(t_P.can_view, 0) AS can_view - , IFNULL(t_P.can_edit, 0) AS can_edit - , IFNULL(t_P.can_admin, 0) AS can_admin - , a_guid - FROM tmp_Permutation_calc t_PP - INNER JOIN partsltd_prod.Shop_Product_Permutation PP ON t_PP.id_permutation = PP.id_permutation - INNER JOIN tmp_Product_calc t_P ON t_PP.id_product = t_P.id_product - INNER JOIN partsltd_prod.Shop_Product P ON t_PP.id_product = P.id_product - INNER JOIN partsltd_prod.Shop_Product_Category PC ON P.id_category = PC.id_category - LEFT JOIN partsltd_prod.Shop_Product_Permutation_Variation_Link PPVL ON PP.id_permutation = PPVL.id_permutation - LEFT JOIN partsltd_prod.Shop_Unit_Measurement UM_Q ON PP.id_unit_measurement_quantity = UM_Q.id_unit_measurement - LEFT JOIN partsltd_prod.Shop_Unit_Measurement UM_R ON PP.id_unit_measurement_interval_recurrence = UM_R.id_unit_measurement - LEFT JOIN partsltd_prod.Shop_Unit_Measurement UM_X ON PP.id_unit_measurement_interval_expiration_unsealed = UM_X.id_unit_measurement - INNER JOIN partsltd_prod.Shop_Currency C ON PP.id_currency_cost = C.id_currency - GROUP BY PP.id_permutation, t_P.can_view, t_P.can_edit, t_P.can_admin - ; - - COMMIT; - END IF; - - /* - -- Errors - SELECT - t_ME.display_order, - t_ME.guid, - t_ME.id_type, - t_ME.msg, - MET.code, - MET.name, - MET.description - FROM tmp_Msg_Error t_ME - INNER JOIN partsltd_prod.Shop_Msg_Error_Type MET - ON t_ME.id_type = MET.id_type - WHERE guid = a_guid - ; - */ - - IF a_debug = 1 THEN - SELECT * - FROM tmp_Msg_Error - ; - - SELECT * - FROM partsltd_prod.Shop_Product_Category_Temp - WHERE GUID = a_guid - ; - SELECT * - FROM partsltd_prod.Shop_Product_Temp - WHERE GUID = a_guid - ; - SELECT * - FROM partsltd_prod.Shop_Product_Permutation_Temp - WHERE GUID = a_guid - ; - - CALL p_shop_clear_calc_product_permutation ( a_guid ); - END IF; - - -- Clean up - -- DROP TEMPORARY TABLE IF EXISTS tmp_Split; - DROP TEMPORARY TABLE IF EXISTS tmp_Permutation_calc; - DROP TEMPORARY TABLE IF EXISTS tmp_Product_calc; - DROP TEMPORARY TABLE IF EXISTS tmp_Category_calc; - - IF a_debug = 1 THEN - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); - END IF; -END // -DELIMITER ; - - -/* - -CALL partsltd_prod.p_shop_calc_product_permutation ( - 1 --'auth0|6582b95c895d09a70ba10fef', -- a_id_user - , 1 -- a_get_all_product_category - , 0 -- a_get_inactive_product_category - , '' -- a_ids_product_category - , 1 -- a_get_all_product - , 0 -- a_get_inactive_product - , '' -- a_ids_product - , 1 -- a_get_all_product_permutation - , 0 -- a_get_inactive_permutation - , '' -- a_ids_permutation - , 0 -- a_get_products_quantity_stock_below_minimum - , 'NIPS ' -- a_guid - , 0 -- a_debug -); - - - SELECT * - FROM partsltd_prod.Shop_Product_Category_Temp - WHERE GUID = 'NIPS ' - ; - SELECT * - FROM partsltd_prod.Shop_Product_Temp - WHERE GUID = 'NIPS ' - ; - SELECT * - FROM partsltd_prod.Shop_Product_Permutation_Temp - WHERE GUID = 'NIPS ' - ; - - CALL p_shop_clear_calc_product_permutation ( 'NIPS ' ); - - SELECT * - FROM partsltd_prod.Shop_Product_Category_Temp - WHERE GUID = 'NIPS ' - ; - SELECT * - FROM partsltd_prod.Shop_Product_Temp - WHERE GUID = 'NIPS ' - ; - SELECT * - FROM partsltd_prod.Shop_Product_Permutation_Temp - WHERE GUID = 'NIPS ' - ; - -*/ \ No newline at end of file diff --git a/static/MySQL/7204_p_shop_get_many_product.sql b/static/MySQL/7204_p_shop_get_many_product.sql deleted file mode 100644 index 7b1a6a4b..00000000 --- a/static/MySQL/7204_p_shop_get_many_product.sql +++ /dev/null @@ -1,522 +0,0 @@ --- -USE partsltd_prod; - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_get_many_product; - -DELIMITER // -CREATE PROCEDURE p_shop_get_many_product ( - IN a_id_user INT - , IN a_get_all_product_category BIT - , IN a_get_inactive_product_category BIT - , IN a_ids_product_category VARCHAR(500) - , IN a_get_all_product BIT - , IN a_get_inactive_product BIT - , IN a_ids_product VARCHAR(500) - , IN a_get_all_product_permutation BIT - , IN a_get_inactive_permutation BIT - , IN a_ids_permutation VARCHAR(4000) - , IN a_get_all_image BIT - , IN a_get_inactive_image BIT - , IN a_ids_image VARCHAR(4000) - , IN a_get_products_quantity_stock_below_min BIT - , IN a_debug BIT -) -BEGIN - - -- Argument redeclaration - -- Variable declaration - -- DECLARE v_has_filter_product_category BIT; - -- DECLARE v_has_filter_product BIT; - -- DECLARE v_has_filter_permutation BIT; - DECLARE v_has_filter_image BIT; - DECLARE v_guid BINARY(36); - -- DECLARE v_id_user VARCHAR(100); - -- DECLARE v_ids_permutation_unavailable VARCHAR(4000); - DECLARE v_id_permission_product INT; - DECLARE v_ids_product_permission VARCHAR(4000); - -- DECLARE v_ids_permutation_permission VARCHAR(4000); - DECLARE v_id_access_level_view INT; - -- DECLARE v_now DATETIME; - DECLARE v_id_minimum INT; - DECLARE v_ids_product_invalid VARCHAR(4000); - DECLARE v_time_start TIMESTAMP(6); - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_guid := UUID(); - SET v_id_access_level_view := (SELECT id_access_level FROM partsltd_prod.Shop_Access_Level WHERE code = 'VIEW'); - - - -- Argument validation + default values - SET a_id_user := IFNULL(a_id_user, 0); - SET a_get_all_product_category := IFNULL(a_get_all_product_category, 0); - SET a_get_inactive_product_category := IFNULL(a_get_inactive_product_category, 0); - SET a_ids_product_category := TRIM(IFNULL(a_ids_product_category, '')); - SET a_get_all_product := IFNULL(a_get_all_product, 0); - SET a_get_inactive_product := IFNULL(a_get_inactive_product, 0); - SET a_ids_product := TRIM(IFNULL(a_ids_product, '')); - SET a_get_all_product_permutation := IFNULL(a_get_all_product_permutation, 0); - SET a_get_inactive_permutation := IFNULL(a_get_inactive_permutation, 0); - SET a_ids_permutation := TRIM(IFNULL(a_ids_permutation, '')); - SET a_get_all_image := IFNULL(a_get_all_image, 0); - SET a_get_inactive_image := IFNULL(a_get_inactive_image, 0); - SET a_ids_image := TRIM(IFNULL(a_ids_image, '')); - SET a_get_products_quantity_stock_below_min := IFNULL(a_get_products_quantity_stock_below_min, 0); - SET a_debug := IFNULL(a_debug, 0); - - IF a_debug = 1 THEN - SELECT - a_id_user - , a_get_all_product_category, a_ids_product_category, a_get_inactive_product_category - , a_get_all_product, a_get_inactive_product, a_ids_product - , a_get_all_product_permutation, a_get_inactive_permutation, a_ids_permutation - , a_get_all_image, a_get_inactive_image, a_ids_image - , a_get_products_quantity_stock_below_min - , a_debug - ; - END IF; - - -- Temporary tables - DROP TEMPORARY TABLE IF EXISTS tmp_Split; - DROP TEMPORARY TABLE IF EXISTS tmp_Image; - DROP TEMPORARY TABLE IF EXISTS tmp_Category; - DROP TEMPORARY TABLE IF EXISTS tmp_Permutation; - DROP TEMPORARY TABLE IF EXISTS tmp_Product; - - CREATE TEMPORARY TABLE tmp_Category ( - id_category INT NOT NULL - /* - active BIT NOT NULL - */ - , display_order INT NOT NULL - ); - - CREATE TEMPORARY TABLE tmp_Product ( - id_category INT NOT NULL - , id_product INT NOT NULL - , display_order INT NOT NULL - /* - active BIT NOT NULL, - */ - , can_view BIT - , can_edit BIT - , can_admin BIT - ); - - CREATE TEMPORARY TABLE tmp_Permutation ( - id_permutation INT NULL - -- id_category INT NOT NULL, - , id_product INT NOT NULL - -- , active BIT NOT NULL - -- , display_order INT NOT NULL - ); - - CREATE TEMPORARY TABLE tmp_Image ( - id_image INT NOT NULL - -- id_product INT NOT NULL, - , id_permutation INT NULL - /* - active BIT NOT NULL - display_order INT NOT NULL - -- rank_in_product_permutation INT NOT NULL - */ - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - -- guid BINARY(36) NOT NULL, - id_type INT NULL, - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Split ( - substring VARCHAR(4000) NOT NULL - , as_int INT NULL - ); - DELETE FROM tmp_Split; - - - -- Parse filters - -- CALL p_validate_guid ( v_guid ); - -- SET v_has_filter_product_category = CASE WHEN a_ids_product_category = '' THEN 0 ELSE 1 END; - -- SET v_has_filter_product = CASE WHEN a_ids_product = '' THEN 0 ELSE 1 END; - -- SET v_has_filter_permutation = CASE WHEN a_ids_permutation = '' THEN 0 ELSE 1 END; - SET v_has_filter_image = CASE WHEN a_ids_image = '' THEN 0 ELSE 1 END; - - -- select v_has_filter_product, v_has_filter_permutation; - - CALL partsltd_prod.p_shop_calc_product_permutation ( - a_id_user - , a_get_all_product_category - , a_get_inactive_product_category - , a_ids_product_category - , a_get_all_product - , a_get_inactive_product - , a_ids_product - , a_get_all_product_permutation - , a_get_inactive_permutation - , a_ids_permutation - , a_get_products_quantity_stock_below_min - , v_guid -- a_guid - , 0 -- a_debug - ); - - INSERT INTO tmp_Category ( - id_category - /* - active, - */ - , display_order - ) - SELECT - PC.id_category - /* - PC.active, - */ - , PC.display_order - FROM (SELECT * FROM partsltd_prod.Shop_Product_Category_Temp WHERE GUID = v_guid) PC_T - INNER JOIN partsltd_prod.Shop_Product_Category PC ON PC_T.id_category = PC.id_category - ; - - INSERT INTO tmp_Product ( - id_product - , id_category - /* - active - */ - , display_order - ) - SELECT - P.id_product - , P.id_category - -- P.active, - , P.display_order - FROM (SELECT * FROM partsltd_prod.Shop_Product_Temp WHERE GUID = v_guid) P_T - INNER JOIN partsltd_prod.Shop_Product P ON P.id_product = P_T.id_product - ; - - INSERT INTO tmp_Permutation ( - id_permutation - -- id_category, - , id_product - -- , active - -- , display_order - ) - SELECT - PP.id_permutation - -- P.id_category, - , PP.id_product - -- , PP.active - -- , RANK() OVER (ORDER BY VT.display_order, V.display_order) - FROM (SELECT * FROM partsltd_prod.Shop_Product_Permutation_Temp WHERE GUID = v_guid) PP_T - INNER JOIN partsltd_prod.Shop_Product_Permutation PP ON PP_T.id_permutation = PP.id_permutation - ; - - -- Product Images - IF (v_has_filter_image = 1 AND NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1)) THEN - CALL partsltd_prod.p_split(v_guid, a_ids_image, ',', a_debug); - - INSERT INTO tmp_Split ( - substring - , as_int - ) - SELECT - substring - , CONVERT(substring, DECIMAL(10,0)) AS as_int - FROM partsltd_prod.Split_Temp - WHERE 1=1 - AND GUID = v_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( v_guid ); - END IF; - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Product_Image I ON t_S.as_int = I.id_image - WHERE - ISNULL(t_S.as_int) - OR ISNULL(I.id_image) - ) THEN - INSERT INTO tmp_Msg_Error ( - -- guid, - id_type, - code, - msg - ) - SELECT - -- v_guid, - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Invalid or inactive image IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Product_Image I ON t_S.as_int = I.id_image - WHERE - ISNULL(t_S.as_int) - OR ISNULL(I.id_image) - -- OR PC.active = 0 - ; - ELSE - INSERT INTO tmp_Image ( - id_image - , id_permutation - ) - SELECT - I.id_image - , I.id_permutation - FROM tmp_Split t_S - RIGHT JOIN partsltd_prod.Shop_Product_Image I ON t_S.as_int = I.id_image - INNER JOIN tmp_Permutation t_PP ON I.id_permutation = t_PP.id_permutation - WHERE - ( - a_get_all_image = 1 - OR NOT ISNULL(t_S.as_int) - ) - AND ( - a_get_inactive_image = 1 - OR I.active = 1 - ) - ; - END IF; - END IF; - - DELETE FROM tmp_Split; - - -- Outputs - -- Categories - SELECT - -- DISTINCT - t_C.id_category - , PC.code - , PC.name - , PC.description - , PC.id_access_level_required - , AL.name AS name_access_level_required - , PC.display_order - , PC.active - , MIN(t_P.can_view) AS can_view - , MIN(t_P.can_edit) AS can_edit - , MIN(t_P.can_admin) AS can_admin - FROM tmp_Category t_C - INNER JOIN partsltd_prod.Shop_Product_Category PC ON t_C.id_category = PC.id_category - LEFT JOIN tmp_Product t_P ON t_C.id_category = t_P.id_product - INNER JOIN partsltd_prod.Shop_Access_Level AL ON PC.id_access_level_required = AL.id_access_level - GROUP BY t_C.id_category -- , t_P.id_product - ORDER BY PC.display_order - ; - - -- Products - SELECT - t_P.id_product, - P.id_category, - P.name, - P.has_variations, - P.id_access_level_required, - AL.name AS name_access_level_required, - P.active, - P.display_order, - t_P.can_view, - t_P.can_edit, - t_P.can_admin - FROM tmp_Product t_P - INNER JOIN partsltd_prod.Shop_Product P ON t_P.id_product = P.id_product - INNER JOIN tmp_Category t_C ON t_P.id_category = t_C.id_category - INNER JOIN partsltd_prod.Shop_Access_Level AL ON P.id_access_level_required = AL.id_access_level - GROUP BY t_P.id_category, t_C.display_order, t_P.id_product, t_P.can_view, t_P.can_edit, t_P.can_admin - ORDER BY t_C.display_order, P.display_order - ; - - -- Product Permutations - SELECT - t_PP.id_permutation, - PP.id_product, - P.id_category, - PP.description, - PP.cost_local_VAT_excl, - PP.cost_local_VAT_incl, - PP.id_currency_cost, - C.code AS code_currency_cost, - C.symbol AS symbol_currency_cost, - PP.profit_local_min, - PP.latency_manufacture, - PP.id_unit_measurement_quantity, - UM_Q.symbol AS symbol_unit_measurement_quantity, - UM_Q.symbol_is_suffix_not_prefix AS symbol_is_suffix_not_prefix_unit_measurement_quantity, - UM_Q.name_singular AS name_singular_unit_measurement_quantity, - UM_Q.name_plural AS name_plural_unit_measurement_quantity, - PP.count_unit_measurement_per_quantity_step, - PP.quantity_min, - PP.quantity_max, - PP.quantity_stock, - PP.is_subscription, - PP.id_unit_measurement_interval_recurrence, - UM_R.symbol AS symbol_unit_measurement_interval_recurrence, - UM_R.symbol_is_suffix_not_prefix AS symbol_is_suffix_not_prefix_unit_measurement_interval_recurrence, - UM_R.name_singular AS name_singular_unit_measurement_interval_recurrence, - UM_R.name_plural AS name_plural_unit_measurement_interval_recurrence, - PP.count_interval_recurrence, - PP.id_stripe_product, - PP.does_expire_faster_once_unsealed, - PP.id_unit_measurement_interval_expiration_unsealed, - UM_X.symbol AS symbol_unit_measurement_interval_expiration_unsealed, - UM_X.symbol_is_suffix_not_prefix AS symbol_is_suffix_not_prefix_unit_interval_expiration_unsealed, - UM_X.name_singular AS name_singular_unit_measurement_interval_expiration_unsealed, - UM_X.name_plural AS name_plural_unit_measurement_interval_expiration_unsealed, - PP.count_interval_expiration_unsealed, - NOT ISNULL(PPVL.id_permutation) AS has_variations, - PP.active, - -- PP.display_order, - IFNULL(t_P.can_view, 0) AS can_view, - IFNULL(t_P.can_edit, 0) AS can_edit, - IFNULL(t_P.can_admin, 0) AS can_admin - FROM tmp_Permutation t_PP - INNER JOIN partsltd_prod.Shop_Product_Permutation PP ON t_PP.id_permutation = PP.id_permutation - INNER JOIN tmp_Product t_P ON t_PP.id_product = t_P.id_product - INNER JOIN partsltd_prod.Shop_Product P ON t_PP.id_product = P.id_product - INNER JOIN partsltd_prod.Shop_Product_Category PC ON P.id_category = PC.id_category - LEFT JOIN partsltd_prod.Shop_Product_Permutation_Variation_Link PPVL ON PP.id_permutation = PPVL.id_permutation - LEFT JOIN partsltd_prod.Shop_Unit_Measurement UM_Q ON PP.id_unit_measurement_quantity = UM_Q.id_unit_measurement - LEFT JOIN partsltd_prod.Shop_Unit_Measurement UM_R ON PP.id_unit_measurement_interval_recurrence = UM_R.id_unit_measurement - LEFT JOIN partsltd_prod.Shop_Unit_Measurement UM_X ON PP.id_unit_measurement_interval_expiration_unsealed = UM_X.id_unit_measurement - INNER JOIN partsltd_prod.Shop_Currency C ON PP.id_currency_cost = C.id_currency - GROUP BY PC.id_category, P.id_product, PP.id_permutation, t_P.can_view, t_P.can_edit, t_P.can_admin - ORDER BY PC.display_order, P.display_order -- , t_PP.display_order - ; - - -- Variations - SELECT - V.id_variation - , V.id_type - , V.code AS code_variation - , V.name AS name_variation - , V.display_order AS display_order_variation - , V.active AS active_variation - , VT.code AS code_variation_type - , VT.name AS name_variation_type - , VT.name_plural AS name_plural_variation_type - , VT.display_order AS display_order_variation_type - , VT.active AS active_variation_type - , t_P.id_product - , t_PP.id_permutation - , t_C.id_category - FROM partsltd_prod.Shop_Variation V - INNER JOIN partsltd_prod.Shop_Variation_Type VT ON V.id_type = VT.id_type - INNER JOIN partsltd_prod.Shop_Product_Permutation_Variation_Link PPVL ON V.id_variation = PPVL.id_variation - INNER JOIN tmp_Permutation t_PP ON PPVL.id_permutation = t_PP.id_permutation - INNER JOIN tmp_Product t_P ON t_PP.id_product = t_P.id_product - INNER JOIN tmp_Category t_C ON t_P.id_category = t_C.id_category - WHERE - V.active - AND PPVL.active - ; - - -- Images - SELECT - t_I.id_image, - t_PP.id_product, - t_I.id_permutation, - t_C.id_category, - I.url, - I.active, - I.display_order - FROM tmp_Image t_I - INNER JOIN partsltd_prod.Shop_Product_Image I ON t_I.id_image = I.id_image - INNER JOIN tmp_Permutation t_PP ON t_I.id_permutation = t_PP.id_permutation - INNER JOIN tmp_Product t_P ON t_PP.id_product = t_P.id_product - INNER JOIN tmp_Category t_C ON t_P.id_category = t_C.id_category - ORDER BY t_C.display_order, t_P.display_order, I.display_order - ; - - -- Errors - SELECT * - /* - t_ME.display_order, - t_ME.guid, - t_ME.id_type, - t_ME.msg, - MET.code, - MET.name, - MET.description - */ - FROM tmp_Msg_Error t_ME - INNER JOIN partsltd_prod.Shop_Msg_Error_Type MET ON t_ME.id_type = MET.id_type - -- WHERE guid = v_guid - ; - - IF a_debug = 1 THEN - SELECT * FROM tmp_Category; - SELECT * FROM tmp_Product; - SELECT * FROM tmp_Permutation; - SELECT * FROM tmp_Image; - END IF; - - DROP TEMPORARY TABLE IF EXISTS tmp_Split; - DROP TEMPORARY TABLE IF EXISTS tmp_Image; - DROP TEMPORARY TABLE IF EXISTS tmp_Category; - DROP TEMPORARY TABLE IF EXISTS tmp_Permutation; - DROP TEMPORARY TABLE IF EXISTS tmp_Product; - - CALL partsltd_prod.p_shop_clear_calc_product_permutation ( v_guid ); - - IF a_debug = 1 THEN - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); - END IF; -END // -DELIMITER ; - - -/* - -CALL partsltd_prod.p_shop_get_many_product ( - 1 --'auth0|6582b95c895d09a70ba10fef', -- a_id_user - , 1 -- a_get_all_product_category - , 0 -- a_get_inactive_product_category - , '' -- a_ids_product_category - , 1 -- a_get_all_product - , 0 -- a_get_inactive_product - , '' -- a_ids_product - , 1 -- a_get_all_product_permutation - , 0 -- a_get_inactive_permutation - , '' -- a_ids_permutation - , 1 -- a_get_all_image - , 0 -- a_get_inactive_image - , '' -- a_ids_image - , 0 -- a_get_products_quantity_stock_below_minimum - , 0 -- a_debug -); - -select * FROM partsltd_prod.Shop_Calc_User_Temp; - -select * FROM partsltd_prod.Shop_Product_Category; -select * FROM partsltd_prod.Shop_Product_Permutation; -select * FROM partsltd_prod.Shop_product_change_set; -insert into shop_product_change_set ( comment ) values ('set stock quantities below minimum for testing'); -update shop_product_permutation -set quantity_stock = 0, - id_change_set = (select id_change_set FROM partsltd_prod.Shop_product_change_set order by id_change_set desc limit 1) -where id_permutation < 5 - -DROP TABLE IF EXISTS tmp_Msg_Error; - -select * FROM partsltd_prod.Shop_image; -select * FROM partsltd_prod.Shop_product; -select * from TMP_MSG_ERROR; -DROP TABLE TMP_MSG_ERROR; - -insert into shop_product_change_set (comment) - values ('set product not subscription - test bool output to python'); - update shop_product - set is_subscription = 0, - id_change_set = (select id_change_set FROM partsltd_prod.Shop_product_change_set order by id_change_set desc limit 1) - where id_product = 1 - -select * FROM partsltd_prod.Shop_Calc_User_Temp; -select distinct guid --- DELETE -FROM partsltd_prod.Shop_Calc_User_Temp; -*/ diff --git a/static/MySQL/7205_p_shop_get_many_stripe_product_new.sql b/static/MySQL/7205_p_shop_get_many_stripe_product_new.sql deleted file mode 100644 index f03e0780..00000000 --- a/static/MySQL/7205_p_shop_get_many_stripe_product_new.sql +++ /dev/null @@ -1,307 +0,0 @@ - - - -/* - -CALL p_shop_get_many_stripe_product_new ( - '' -) - -*/ - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_get_many_stripe_product_new; - - -DELIMITER // -CREATE PROCEDURE p_shop_get_many_stripe_product_new ( - IN a_id_user INT -) -BEGIN - DECLARE v_has_filter_user BIT; - DECLARE v_code_error_data VARCHAR(200); - DECLARE v_code_error_permission VARCHAR(200); - DECLARE v_guid BINARY(36); - - SET v_code_error_data := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 1); - SET v_code_error_permission := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 2); - SET v_guid = UUID(); - - - IF a_id_user IS NULL THEN - SET a_id_user = ''; - ELSE - SET a_id_user = TRIM(a_id_user); - END IF; - - - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Shop_Product; - DROP TABLE IF EXISTS tmp_Shop_User; - - CREATE TABLE tmp_Shop_User( - id_user INT NOT NULL PRIMARY KEY, - CONSTRAINT FK_tmp_Shop_User_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user), - active BIT NOT NULL - ); - - CREATE TABLE tmp_Shop_Product ( - id_product INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - id_permutation INT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - active BIT NOT NULL, - display_order_product INT NOT NULL, - display_order_permutation INT NOT NULL, - name VARCHAR(200) NOT NULL, - description VARCHAR(4000) NOT NULL - ); - - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( -- IF NOT EXISTS - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - guid BINARY(36) NOT NULL, - code VARCHAR(50) NOT NULL, - -- CONSTRAINT chk_tmp_Msg_Error_code CHECK (code IN (SELECT code FROM Shop_Msg_Error_Type)), - /* - id_type INT NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type(id_type), - */ - msg VARCHAR(4000) NOT NULL - ); - - - - -- Parse filters - SET v_has_filter_user = CASE WHEN a_id_user = '' THEN 0 ELSE 1 END; - - - - -- User - IF v_has_filter_user THEN - INSERT INTO tmp_Shop_User ( - id_user, - active - ) - SELECT id_user, - active - FROM Shop_User - WHERE id_user LIKE CONCAT('%', a_id_user, '%') - AND active - LIMIT 1 - ; - - SET v_has_filter_user = EXISTS (SELECT id_user FROM tmp_Shop_User LIMIT 1); - SET a_id_user := (SELECT id_user FROM tmp_Shop_User LIMIT 1); - END IF; - - IF NOT v_has_filter_user THEN - INSERT INTO tmp_Msg_Error ( - guid, - code, - msg - ) - VALUES ( - v_guid, - v_code_error_data, - 'User ID not valid.' - ) - ; - END IF; - - -- Get products - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - INSERT INTO tmp_Shop_Product ( - id_product, - id_permutation, - active, - display_order_product, - display_order_permutation, - name, - description - ) - SELECT id_product, - id_permutation, - active, - display_order_product, - display_order_permutation, - name, - description - FROM ( - SELECT id_product, - NULL AS id_permutation, - active, - display_order AS display_order_product, - NULL AS display_order_permutation, - name, - description, - id_stripe_product - FROM Shop_Product P - UNION - SELECT t_PPPV.id_product, - id_permutation, - t_PPPV.active, - display_order_product, - display_order_permutation, - CONCAT(P.name, ': ', names_variation) AS name, - CONCAT(P.description, ' With variations: ', type_name_pairs_variation) AS description, - t_PPPV.id_stripe_product - FROM ( - SELECT P.id_product, - PP.id_permutation, - PP.active, - P.display_order AS display_order_product, - PP.display_order AS display_order_permutation, - GROUP_CONCAT(V.name SEPARATOR ' ') AS names_variation, - GROUP_CONCAT(CONCAT(VT.name, ': ', V.name) SEPARATOR ', ') AS type_name_pairs_variation, - PP.id_stripe_product - FROM Shop_Product_Permutation PP - INNER JOIN Shop_Product P - ON PP.id_product = P.id_product - AND P.active - INNER JOIN Shop_Product_Permutation_Variation_Link PPVL - ON PP.id_permutation = PPVL.id_permutation - AND PPVL.active - INNER JOIN Shop_Variation V - ON PPVL.id_variation = V.id_variation - AND V.active - INNER JOIN Shop_Variation_Type VT - ON V.id_type = VT.id_type - AND VT.active - GROUP BY id_product, id_permutation -- , VT.id_type, V.id_variation - ) t_PPPV - INNER JOIN Shop_Product P - ON t_PPPV.id_product = P.id_product - ) t_PPP - WHERE ISNULL(id_stripe_product) - AND active - ; - END IF; - - -- Permissions - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - CALL p_shop_calc_user ( - v_guid, -- a_guid - a_id_user, -- a_id_user - 0, -- a_get_inactive_users - CONVERT((SELECT id_permission FROM Shop_Permission WHERE 'STORE_ADMIN' = code), CHAR), -- a_ids_permission - (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'ADMIN' AND active), -- a_ids_access_level - (SELECT GROUP_CONCAT(id_product SEPARATOR ',') From tmp_Shop_Product), -- a_ids_product - (SELECT GROUP_CONCAT(id_permutation SEPARATOR ',') From tmp_Shop_Product) -- a_ids_permutation -- WHERE NOT ISNULL(id_permutation) - ); - - IF EXISTS (SELECT can_admin FROM Shop_Calc_User_Temp WHERE guid = v_guid AND NOT can_admin) THEN - INSERT INTO tmp_Msg_Error ( - guid, - code, - msg - ) - VALUES ( - v_guid, - v_code_error_permission, - 'User ID does not have permission to get all new stripe products.' - ) - ; - END IF; - - DELETE FROM Shop_Calc_User_Temp - WHERE guid = v_guid - ; - END IF; - - - - - -- Returns - /* - SELECT * - FROM tmp_Shop_User - ; - */ - - IF EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - DELETE FROM tmp_Shop_Product; - END IF; - - SELECT id_product, - id_permutation, - name, - description - FROM tmp_Shop_Product - ORDER BY display_order_product, display_order_permutation - ; - SELECT PP.id_permutation, - V.id_variation, - V.name AS name_variation, - VT.id_type AS id_type_variation, - VT.name as name_variation_type - FROM tmp_Shop_Product t_P - INNER JOIN Shop_Product_Permutation PP - ON t_P.id_permutation = PP.id_permutation - INNER JOIN Shop_Product_Permutation_Variation_Link PPVL - ON PP.id_permutation = PPVL.id_permutation - AND PPVL.active - INNER JOIN Shop_Variation V - ON PPVL.id_variation = V.id_variation - AND V.active - INNER JOIN Shop_Variation_Type VT - ON V.id_type = VT.id_type - AND VT.active - ; - - - -- Errors - SELECT * - FROM tmp_Msg_Error - WHERE guid = v_guid - ; - - - /* - -- Return arguments for test - SELECT - a_id_user - ; - */ - - -- Clean up - DROP TABLE IF EXISTS tmp_Shop_Product; - DROP TABLE IF EXISTS tmp_Shop_User; -END // -DELIMITER ; - - -/* -CALL p_shop_get_many_stripe_product_new ( - '' -); - -CALL p_shop_get_many_stripe_product_new ( - 'auth0|6582b95c895d09a70ba10fef' -); - - - -select * from shop_product; -select * from shop_product_permutation_variation_link; - -CALL p_shop_calc_user ( - 'ead789a1-c7ac-11ee-a256-b42e9986184a', -- a_guid - 'auth0|6582b95c895d09a70ba10fef', -- a_id_user - 0, -- a_get_inactive_users - '4', -- a_ids_permission - '3', -- a_ids_access_level - '1', -- a_ids_product - '1' -- a_ids_permutation -- WHERE NOT ISNULL(id_permutation) - ); - -*/ diff --git a/static/MySQL/7206_p_shop_save_product_permutation.sql b/static/MySQL/7206_p_shop_save_product_permutation.sql deleted file mode 100644 index eec29d5e..00000000 --- a/static/MySQL/7206_p_shop_save_product_permutation.sql +++ /dev/null @@ -1,744 +0,0 @@ - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_save_permutation; -DROP PROCEDURE IF EXISTS p_shop_save_product_permutation; - -DELIMITER // -CREATE PROCEDURE p_shop_save_product_permutation ( - IN a_comment VARCHAR(500), - IN a_guid BINARY(36), - IN a_id_user INT, - IN a_debug BIT -) -BEGIN - - DECLARE v_code_type_error_bad_data VARCHAR(100); - DECLARE v_id_type_error_bad_data INT; - DECLARE v_id_permission_product INT; - DECLARE v_ids_product_permission LONGTEXT; - DECLARE v_id_change_set INT; - DECLARE v_id_access_level_edit INT; - DECLARE v_time_start TIMESTAMP(6); - - DECLARE exit handler for SQLEXCEPTION - BEGIN - -- Get diagnostic information - GET DIAGNOSTICS CONDITION 1 - @sqlstate = RETURNED_SQLSTATE - , @errno = MYSQL_ERRNO - , @text = MESSAGE_TEXT - ; - - -- Rollback the transaction - ROLLBACK; - - -- Select the error information - -- SELECT 'Error' AS status, @errno AS error_code, @sqlstate AS sql_state, @text AS message; - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT - , id_type INT NULL - , code VARCHAR(50) NOT NULL - , msg VARCHAR(4000) NOT NULL - ); - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - MET.id_type - , @errno - , @text - FROM partsltd_prod.Shop_Msg_Error_Type MET - WHERE MET.code = 'MYSQL_ERROR' - LIMIT 1 - ; - SELECT * - FROM tmp_Msg_Error; - DROP TABLE IF EXISTS tmp_Msg_Error; - END; - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_code_type_error_bad_data := 'BAD_DATA'; - SET v_id_type_error_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_type_error_bad_data LIMIT 1); - SET v_id_access_level_edit := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'EDIT' LIMIT 1); - - CALL p_validate_guid ( a_guid ); - - DROP TEMPORARY TABLE IF EXISTS tmp_Permutation_Variation_Link; - DROP TEMPORARY TABLE IF EXISTS tmp_Permutation; - - CREATE TEMPORARY TABLE tmp_Permutation ( - id_permutation INT NOT NULL - , id_permutation_temp INT NOT NULL - , id_product INT NOT NULL - , csv_id_pairs_variation VARCHAR(4000) NULL - , description VARCHAR(4000) NOT NULL - , cost_local_VAT_excl FLOAT NULL - , cost_local_VAT_incl FLOAT NULL - , id_currency_cost INT NOT NULL - , profit_local_min FLOAT NULL - , latency_manufacture INT NOT NULL - , id_unit_measurement_quantity INT NOT NULL - , count_unit_measurement_per_quantity_step FLOAT NOT NULL - , quantity_min FLOAT NULL - , quantity_max FLOAT NULL - , quantity_stock FLOAT NOT NULL - , is_subscription BIT NOT NULL - , id_unit_measurement_interval_recurrence INT - , count_interval_recurrence INT - , id_stripe_product VARCHAR(100) NULL - , does_expire_faster_once_unsealed BIT NOT NULL - , id_unit_measurement_interval_expiration_unsealed INT - , count_interval_expiration_unsealed INT - , active BIT NOT NULL DEFAULT 1 - , can_view BIT NULL - , can_edit BIT NULL - , can_admin BIT NULL - , name_error VARCHAR(255) NOT NULL - , is_new BIT NOT NULL - ); - - CREATE TEMPORARY TABLE tmp_Permutation_Variation_Link ( - id_link INT NOT NULL - , id_permutation INT NOT NULL - , id_variation INT NOT NULL - , active BIT NOT NULL - , display_order INT NOT NULL - , is_new BIT NOT NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT - , id_type INT NULL - , code VARCHAR(50) NOT NULL - , msg VARCHAR(4000) NOT NULL - ); - - - -- Get data from Temp table - INSERT INTO tmp_Permutation ( - id_permutation - , id_permutation_temp - , id_product - , csv_id_pairs_variation - , description - , cost_local_VAT_excl - , cost_local_VAT_incl - , id_currency_cost - , profit_local_min - , latency_manufacture - , id_unit_measurement_quantity - , count_unit_measurement_per_quantity_step - , quantity_min - , quantity_max - , quantity_stock - , is_subscription - , id_unit_measurement_interval_recurrence - , count_interval_recurrence - , id_stripe_product - , does_expire_faster_once_unsealed - , id_unit_measurement_interval_expiration_unsealed - , count_interval_expiration_unsealed - , active - , name_error - , is_new - ) - SELECT - PP_T.id_permutation - , PP_T.id_permutation - , IFNULL(PP_T.id_product, PP.id_product) AS id_product - , PP_T.csv_id_pairs_variation - , IFNULL(PP_T.description, PP.description) AS description - , IFNULL(PP_T.cost_local_VAT_excl, PP.cost_local_VAT_excl) AS cost_local_VAT_excl - , IFNULL(PP_T.cost_local_VAT_incl, PP.cost_local_VAT_incl) AS cost_local_VAT_incl - , IFNULL(PP_T.id_currency_cost, PP.id_currency_cost) AS a_id_currency_cost - , IFNULL(PP_T.profit_local_min, PP.profit_local_min) AS profit_local_min - , IFNULL(PP_T.latency_manufacture, PP.latency_manufacture) AS latency_manufacture - , IFNULL(PP_T.id_unit_measurement_quantity, PP.id_unit_measurement_quantity) AS id_unit_measurement_quantity - , IFNULL(PP_T.count_unit_measurement_per_quantity_step, PP.count_unit_measurement_per_quantity_step) AS count_unit_measurement_per_quantity_step - , IFNULL(PP_T.quantity_min, PP.quantity_min) AS quantity_min - , IFNULL(PP_T.quantity_max, PP.quantity_max) AS quantity_max - , IFNULL(PP_T.quantity_stock, PP.quantity_stock) AS quantity_stock - , IFNULL(PP_T.is_subscription, PP.is_subscription) AS is_subscription - , IFNULL(PP_T.id_unit_measurement_interval_recurrence, PP.id_unit_measurement_interval_recurrence) AS id_unit_measurement_interval_recurrence - , IFNULL(PP_T.count_interval_recurrence, PP.count_interval_recurrence) AS count_interval_recurrence - , IFNULL(PP_T.id_stripe_product, PP.id_stripe_product) AS id_stripe_product - , IFNULL(PP_T.does_expire_faster_once_unsealed, PP.does_expire_faster_once_unsealed) AS does_expire_faster_once_unsealed - , IFNULL(PP_T.id_unit_measurement_interval_expiration_unsealed, PP.id_unit_measurement_interval_expiration_unsealed) AS id_unit_measurement_interval_expiration_unsealed - , IFNULL(PP_T.count_interval_expiration_unsealed, PP.count_interval_expiration_unsealed) AS count_interval_expiration_unsealed - , IFNULL(PP_T.active, PP.active) AS active - , IFNULL(fn_shop_get_product_permutation_name(PP_T.id_permutation), '(No Permutation)') AS name_error - , CASE WHEN IFNULL(PP_T.id_permutation, 0) < 1 THEN 1 ELSE 0 END AS is_new - FROM Shop_Product_Permutation_Temp PP_T - LEFT JOIN Shop_Product_Permutation PP ON PP_T.id_permutation = PP.id_permutation - WHERE PP_T.guid = a_guid - ; - - SELECT - partsltd_prod.fn_shop_get_product_variations_from_id_csv_list( - t_PP.id_permutation -- a_id_permutation - , t_PP.csv_id_pairs_variation -- a_variation_csv - , a_guid -- a_guid - ) - FROM tmp_Permutation t_PP - WHERE NOT ISNULL(t_PP.csv_id_pairs_variation) - ; - - INSERT INTO tmp_Permutation_Variation_Link ( - id_link - , id_permutation - , id_variation - , display_order - , active - , is_new - ) - SELECT - PPVL_T.id_link - , PPVL_T.id_permutation - , PPVL_T.id_variation - , PPVL_T.display_order - , NOT ISNULL(PPVL_T.id_link) AS active - , IFNULL(PPVL_T.id_link, 0) < 1 AS is_new - FROM partsltd_prod.Shop_Product_Permutation_Variation_Link_Temp PPVL_T - LEFT JOIN partsltd_prod.Shop_Product_Permutation_Variation_Link PPVL ON PPVL_T.id_link = PPVL.id_variation - LEFT JOIN tmp_Permutation t_PP ON PPVL_T.id_permutation = t_PP.id_permutation - WHERE PPVL_T.GUID = a_guid - ; - - IF a_debug = 1 THEN - SELECT * - FROM tmp_Permutation - ; - SELECT * - FROM tmp_Permutation_Variation_Link - ; - END IF; - - -- Validation - -- Missing mandatory fields - -- id_product - IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.id_product) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following product permutation(s) do not have a product: ', GROUP_CONCAT(t_P.name_error SEPARATOR ', ')) AS msg - FROM tmp_Permutation t_P - WHERE ISNULL(t_P.id_product) - ; - END IF; - -- cost_local_VAT_excl - IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE NOT ISNULL(t_P.cost_local_VAT_excl) AND t_P.cost_local_VAT_excl < 0 LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following product permutation(s) do not have a valid local cost excluding VAT: ', GROUP_CONCAT(t_P.name_error SEPARATOR ', ')) AS msg - FROM tmp_Permutation t_P - WHERE NOT ISNULL(t_P.cost_local_VAT_excl) AND t_P.cost_local_VAT_excl < 0 - ; - END IF; - -- cost_local_VAT_incl - IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE NOT ISNULL(t_P.cost_local_VAT_incl) AND t_P.cost_local_VAT_incl < 0 LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following product permutation(s) do not have a valid local cost including VAT: ', GROUP_CONCAT(t_P.name_error SEPARATOR ', ')) AS msg - FROM tmp_Permutation t_P - WHERE NOT ISNULL(t_P.cost_local_VAT_incl) AND t_P.cost_local_VAT_incl < 0 - ; - END IF; - -- profit_local_min - IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE NOT ISNULL(t_P.profit_local_min) AND t_P.profit_local_min < 0 LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following product permutation(s) do not have a local minimum profit: ', GROUP_CONCAT(t_P.name_error SEPARATOR ', ')) AS msg - FROM tmp_Permutation t_P - WHERE NOT ISNULL(t_P.profit_local_min) AND t_P.profit_local_min < 0 - ; - END IF; - - -- latency_manufacture - IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.latency_manufacture) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following product permutation(s) do not have a manufacturing latency: ', GROUP_CONCAT(t_P.name_error SEPARATOR ', ')) AS msg - FROM tmp_Permutation t_P - WHERE ISNULL(t_P.latency_manufacture) - ; - END IF; - -- id_unit_measurement_quantity - IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.id_unit_measurement_quantity) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following product permutation(s) do not have a unit measurement for stock quantities: ', GROUP_CONCAT(t_P.name_error SEPARATOR ', ')) AS msg - FROM tmp_Permutation t_P - WHERE ISNULL(t_P.id_unit_measurement_quantity) - ; - END IF; - -- count_unit_measurement_per_quantity_step - IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.count_unit_measurement_per_quantity_step) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following product permutation(s) do not have a count unit measurement per quantity step: ', GROUP_CONCAT(t_P.name_error SEPARATOR ', ')) AS msg - FROM tmp_Permutation t_P - WHERE ISNULL(t_P.count_unit_measurement_per_quantity_step) - ; - END IF; - -- quantity_min - IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.quantity_min) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following product permutation(s) do not have a minimum quantity: ', GROUP_CONCAT(t_P.name_error SEPARATOR ', ')) AS msg - FROM tmp_Permutation t_P - WHERE ISNULL(t_P.quantity_min) - ; - END IF; - -- quantity_max - IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.quantity_max) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following product permutation(s) do not have a maximum quantity: ', GROUP_CONCAT(t_P.name_error SEPARATOR ', ')) AS msg - FROM tmp_Permutation t_P - WHERE ISNULL(t_P.quantity_max) - ; - END IF; - -- is_subscription - IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.is_subscription) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following product permutation(s) do not have an is subscription?: ', GROUP_CONCAT(t_P.name_error SEPARATOR ', ')) AS msg - FROM tmp_Permutation t_P - WHERE ISNULL(t_P.is_subscription) - ; - END IF; - -- does_expire_faster_once_unsealed - IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.does_expire_faster_once_unsealed) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following product permutation(s) do not have a does expire faster once unsealed: ', GROUP_CONCAT(t_P.name_error SEPARATOR ', ')) AS msg - FROM tmp_Permutation t_P - WHERE ISNULL(t_P.does_expire_faster_once_unsealed) - ; - END IF; - - -- Permissions - SET v_ids_product_permission := ( - SELECT GROUP_CONCAT(P.id_product SEPARATOR ',') - FROM Shop_Product P - INNER JOIN tmp_Permutation t_P - ON P.id_product = t_P.id_product - -- AND t_P.is_new = 0 - ); - - SET v_id_permission_product = (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_PRODUCT' LIMIT 1); - - IF a_debug = 1 THEN - SELECT - a_guid - , a_id_user - , FALSE AS a_get_inactive_user - , v_id_permission_product - , v_id_access_level_edit - , v_ids_product_permission - , 0 AS a_debug - ; - END IF; - - CALL p_shop_calc_user( - a_guid - , a_id_user - , FALSE -- a_get_inactive_user - , v_id_permission_product - , v_id_access_level_edit - , v_ids_product_permission - , 0 -- a_debug - ); - - UPDATE tmp_Permutation t_P - INNER JOIN Shop_Product P ON t_P.id_product = P.id_product - INNER JOIN Shop_Calc_User_Temp UE_T - ON P.id_product = UE_T.id_product - AND UE_T.GUID = a_guid - SET - t_P.can_view = UE_T.can_view - , t_P.can_edit = UE_T.can_edit - , t_P.can_admin = UE_T.can_admin - ; - - IF a_debug = 1 THEN - SELECT * - FROM partsltd_prod.Shop_Calc_User_Temp - WHERE GUID = a_guid - ; - SELECT * - FROM tmp_Permutation t_PP - LEFT JOIN Shop_Product P ON t_PP.id_product = P.id_product - ; - END IF; - - IF EXISTS (SELECT * FROM tmp_Permutation t_P WHERE ISNULL(t_P.can_edit) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following product permutation(s) do not have product edit permission: ', GROUP_CONCAT(t_P.name_error SEPARATOR ', ')) AS msg - FROM tmp_Permutation t_P - WHERE - ISNULL(t_P.can_edit) - ; - END IF; - - IF EXISTS (SELECT * FROM partsltd_prod.Shop_Calc_User_Temp WHERE ISNULL(id_product) AND GUID = a_guid AND can_edit = 0) THEN - DELETE FROM tmp_Msg_Error - WHERE id_type <> v_id_type_error_no_permission - ; - - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - VALUES ( - v_id_type_error_bad_data - , v_code_type_error_bad_data - , 'You do not have permission to edit Product Permutations' - ) - ; - END IF; - - CALL p_shop_clear_calc_user( - a_guid - , 0 -- a_debug - ); - - IF a_debug = 1 THEN - SELECT * - FROM partsltd_prod.Shop_Product_Permutation_Variation_Link_Temp - WHERE GUID = a_guid - ; - END IF; - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - START TRANSACTION; - - INSERT INTO Shop_Product_Change_Set ( comment ) - VALUES ( a_comment ) - ; - - SET v_id_change_set := LAST_INSERT_ID(); - - INSERT INTO Shop_Product_Permutation ( - id_permutation_temp - , id_product - , description - , cost_local_VAT_excl - , cost_local_VAT_incl - , id_currency_cost - , profit_local_min - , latency_manufacture - , id_unit_measurement_quantity - , count_unit_measurement_per_quantity_step - , quantity_min - , quantity_max - , quantity_stock - , is_subscription - , id_unit_measurement_interval_recurrence - , count_interval_recurrence - , id_stripe_product - , does_expire_faster_once_unsealed - , id_unit_measurement_interval_expiration_unsealed - , count_interval_expiration_unsealed - , active - , created_by - , created_on - , id_change_set - ) - SELECT - t_P.id_permutation - , t_P.id_product AS id_product - , t_P.description AS description - , t_P.cost_local_VAT_excl AS cost_local_VAT_excl - , t_P.cost_local_VAT_incl AS cost_local_VAT_incl - , t_P.id_currency_cost AS id_currency_cost - , t_P.profit_local_min AS profit_local_min - , t_P.latency_manufacture AS latency_manufacture - , t_P.id_unit_measurement_quantity AS id_unit_measurement_quantity - , t_P.count_unit_measurement_per_quantity_step AS count_unit_measurement_per_quantity_step - , t_P.quantity_min AS quantity_min - , t_P.quantity_max AS quantity_max - , t_P.quantity_stock AS quantity_stock - , t_P.is_subscription AS is_subscription - , t_P.id_unit_measurement_interval_recurrence AS id_unit_measurement_interval_recurrence - , t_P.count_interval_recurrence AS count_interval_recurrence - , t_P.id_stripe_product AS id_stripe_product - , t_P.does_expire_faster_once_unsealed AS does_expire_faster_once_unsealed - , t_P.id_unit_measurement_interval_expiration_unsealed AS id_unit_measurement_interval_expiration_unsealed - , t_P.count_interval_expiration_unsealed AS count_interval_expiration_unsealed - , t_P.active AS active - , a_id_user AS created_by - , v_time_start AS created_on - , v_id_change_set AS id_change_set - FROM tmp_Permutation t_P - WHERE - is_new = 1 - AND active = 1 - ; - - UPDATE Shop_Product_Permutation PP - INNER JOIN tmp_Permutation t_P - ON PP.id_permutation = t_P.id_permutation - AND t_P.is_new = 0 - SET - PP.id_product = t_P.id_product - , PP.description = t_P.description - , PP.cost_local_VAT_excl = t_P.cost_local_VAT_excl - , PP.cost_local_VAT_incl = t_P.cost_local_VAT_incl - , PP.id_currency_cost = t_P.id_currency_cost - , PP.profit_local_min = t_P.profit_local_min - , PP.latency_manufacture = t_P.latency_manufacture - , PP.id_unit_measurement_quantity = t_P.id_unit_measurement_quantity - , PP.count_unit_measurement_per_quantity_step = t_P.count_unit_measurement_per_quantity_step - , PP.quantity_min = t_P.quantity_min - , PP.quantity_max = t_P.quantity_max - , PP.quantity_stock = t_P.quantity_stock - , PP.is_subscription = t_P.is_subscription - , PP.id_unit_measurement_interval_recurrence = t_P.id_unit_measurement_interval_recurrence - , PP.count_interval_recurrence = t_P.count_interval_recurrence - , PP.id_stripe_product = t_P.id_stripe_product - , PP.does_expire_faster_once_unsealed = t_P.does_expire_faster_once_unsealed - , PP.id_unit_measurement_interval_expiration_unsealed = t_P.id_unit_measurement_interval_expiration_unsealed - , PP.count_interval_expiration_unsealed = t_P.count_interval_expiration_unsealed - , PP.active = t_P.active - , PP.id_change_set = v_id_change_set - ; - - UPDATE tmp_Permutation t_PP - INNER JOIN partsltd_prod.Shop_Product_Permutation PP - ON t_PP.id_permutation_temp = PP.id_permutation_temp - AND PP.id_change_set = v_id_change_set - SET - t_PP.id_permutation = PP.id_permutation - ; - UPDATE tmp_Permutation_Variation_Link t_PPVL - INNER JOIN tmp_Permutation t_PP ON t_PPVL.id_permutation = t_PP.id_permutation_temp - SET - t_PPVL.id_permutation = t_PP.id_permutation - ; - - INSERT INTO partsltd_prod.Shop_Product_Permutation_Variation_Link ( - id_permutation - , id_variation - , display_order - , active - ) - SELECT - t_PPVL.id_permutation - , t_PPVL.id_variation - , t_PPVL.display_order - , t_PPVL.active - FROM tmp_Permutation_Variation_Link t_PPVL - WHERE - t_PPVL.is_new = 1 - AND t_PPVL.active = 1 - ; - - UPDATE partsltd_prod.Shop_Product_Permutation_Variation_Link PPVL - INNER JOIN tmp_Permutation_Variation_Link t_PPVL - ON PPVL.id_link = t_PPVL.id_link - AND t_PPVL.is_new = 1 - SET - PPVL.id_permutation = t_PPVL.id_permutation - , PPVL.id_variation = t_PPVL.id_variation - , PPVL.display_order = t_PPVL.display_order - , PPVL.active = t_PPVL.active - , PPVL.id_change_set = v_id_change_set - ; - - COMMIT; - END IF; - - START TRANSACTION; - - DELETE FROM Shop_Product_Permutation_Temp - WHERE GUID = a_guid - ; - - DELETE FROM partsltd_prod.Shop_Product_Permutation_Variation_Link_Temp - WHERE GUID = a_guid - ; - - COMMIT; - - -- Errors - SELECT * - FROM tmp_Msg_Error t_ME - INNER JOIN partsltd_prod.Shop_Msg_Error_Type MET ON t_ME.id_type = MET.id_type - ; - - IF a_debug = 1 THEN - SELECT * FROM tmp_Permutation; - SELECT * FROM tmp_Permutation_Variation_Link; - END IF; - - DROP TEMPORARY TABLE tmp_Permutation_Variation_Link; - DROP TEMPORARY TABLE tmp_Permutation; - DROP TEMPORARY TABLE tmp_Msg_Error; - - IF a_debug = 1 THEN - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); - END IF; -END // -DELIMITER ; - - -/* - -DELETE FROM Shop_Product_Permutation_Temp -WHERE id_permutation = 1 -; - -INSERT INTO Shop_Product_Permutation_Temp ( - id_permutation, - id_product, - description, - cost_local, - id_currency_cost, - profit_local_min, - latency_manufacture, - id_unit_measurement_quantity, - count_unit_measurement_per_quantity_step, - quantity_min, - quantity_max, - quantity_stock, - is_subscription, - id_unit_measurement_interval_recurrence, - count_interval_recurrence, - id_stripe_product, - does_expire_faster_once_unsealed, - id_unit_measurement_interval_expiration_unsealed, - count_interval_expiration_unsealed, - active, - guid -) -VALUES - ( - 1 -- id_permutation, - , 1 -- id_product, - , 'Good Reddy Teddy' -- description, - , 5.0 -- cost_local, - , 1 -- id_currency_cost, - , 3.0 -- profit_local_min, - , 14 -- latency_manufacture, - , 1 -- id_unit_measurement_quantity, - , 1.0 -- count_unit_measurement_quantity, - , 3.0 -- quantity_min, - , 99.0 -- quantity_max, - , 1.0 -- quantity_stock, - , False -- is_subscription, - , null -- id_unit_measurement_interval_recurrence, - , null -- count_interval_recurrence, - , null -- id_stripe_product, - , False -- does_expire_faster_once_unsealed, - , null -- id_unit_measurement_interval_expiration_unsealed, - , null -- count_interval_expiration_unsealed, - , True -- active, - , 'NIPS' -- guid - ) -; - -select 'Shop_Product_Permutation_Temp before call'; -SELECT * FROM Shop_Product_Permutation_Temp; - -SELECT 'Shop_Product_Permutation before call' AS result_name; -select * FROM Shop_Product_Permutation; - -CALL p_shop_save_product_permutation ( - 1, -- 'auth0|6582b95c895d09a70ba10fef', -- a_id_user - 'Initial data', -- a_comment - 'NIPS' -- a_guid -); - -SELECT 'Shop_Product_Permutation_Temp after call' AS result_name; -select * FROM Shop_Product_Permutation_Temp; - -SELECT 'Shop_Product_Permutation after call' AS result_name; -select * FROM Shop_Product_Permutation; - - -DELETE FROM Shop_Product_Permutation_Temp -WHERE id_permutation = 1; - - -select * from shop_unit_measurement; - -*/ - diff --git a/static/MySQL/7206_p_shop_save_product_permutation_test.sql b/static/MySQL/7206_p_shop_save_product_permutation_test.sql deleted file mode 100644 index 4d61f29e..00000000 --- a/static/MySQL/7206_p_shop_save_product_permutation_test.sql +++ /dev/null @@ -1,171 +0,0 @@ - - --- Clear previous proc -DROP PROCEDURE IF EXISTS partsltd_prod.p_shop_save_product_permutation_test; - - -DELIMITER // -CREATE PROCEDURE p_shop_save_product_permutation_test () -BEGIN - - DECLARE v_guid BINARY(36); - DECLARE v_time_start TIMESTAMP(6); - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_guid := 'nips'; - - SELECT * - FROM partsltd_prod.Shop_Product_Permutation - ; - SELECT * - FROM partsltd_prod.Shop_Product_Permutation_Variation_Link - ; - SELECT * - FROM partsltd_prod.Shop_Product_Permutation_Temp - ; - - START TRANSACTION; - - INSERT INTO partsltd_prod.Shop_Product_Permutation_Temp ( - id_permutation - , id_product - , csv_id_pairs_variation - , description - , cost_local_VAT_excl - , cost_local_VAT_incl - , id_currency_cost - , profit_local_min - , latency_manufacture - , id_unit_measurement_quantity - , count_unit_measurement_per_quantity_step - , quantity_min - , quantity_max - , quantity_stock - , is_subscription - , id_unit_measurement_interval_recurrence - , count_interval_recurrence - , id_stripe_product - , does_expire_faster_once_unsealed - , id_unit_measurement_interval_expiration_unsealed - , count_interval_expiration_unsealed - , active - , guid - ) - VALUES - /* Test 1 - Insert - ( - -1 -- id_permutation - , 5 -- id_product - , '' -- csv_id_pairs_variation - , 'Hair clip' -- description - , NULL -- cost_local_VAT_excl - , NULL -- cost_local_VAT_incl - , 1 -- id_currency_cost - , NULL -- profit_local_min - , 1 -- latency_manufacture - , 3 -- id_unit_measurement_quantity - , 1 -- count_unit_measurement_per_quantity_step - , 0 -- quantity_min - , 0 -- quantity_max - , 2 -- quantity_stock - , FALSE -- is_subscription - , NULL -- id_unit_measurement_interval_recurrence - , NULL -- count_interval_recurrence - , NULL -- id_stripe_product - , FALSE -- does_expire_faster_once_unsealed - , NULL -- id_unit_measurement_interval_expiration_unsealed - , NULL -- count_interval_expiration_unsealed - , 1 -- active - , v_guid - ) - */ - /* Test 2 - Update - ( - 4 -- id_product - , 1 -- id_category - , 'Laptops' -- name - , 0 -- has_variations - , 2 -- id_access_level_required - , 2 -- display_order - , 1 -- active - , v_guid - ) - */ - /* Test 3 - Insert with Variations */ - ( - -1 -- id_permutation - , 1 -- id_product - , '1:3' -- csv_id_pairs_variation - , 'Good Green' -- description - , NULL -- cost_local_VAT_excl - , NULL -- cost_local_VAT_incl - , 1 -- id_currency_cost - , NULL -- profit_local_min - , 1 -- latency_manufacture - , 3 -- id_unit_measurement_quantity - , 1 -- count_unit_measurement_per_quantity_step - , 0 -- quantity_min - , 0 -- quantity_max - , 2 -- quantity_stock - , FALSE -- is_subscription - , NULL -- id_unit_measurement_interval_recurrence - , NULL -- count_interval_recurrence - , NULL -- id_stripe_product - , TRUE -- does_expire_faster_once_unsealed - , 8 -- id_unit_measurement_interval_expiration_unsealed - , 2 -- count_interval_expiration_unsealed - , 1 -- active - , v_guid - ) - ; - - COMMIT; - - SELECT * - FROM partsltd_prod.Shop_Product_Permutation_Temp - WHERE GUID = v_guid - ; - - CALL partsltd_prod.p_shop_save_product_permutation ( - 'Test save product' -- comment - , v_guid -- guid - , 1 -- id_user - , 1 -- debug - ); - - SELECT * - FROM partsltd_prod.Shop_Product_Permutation - ; - SELECT * - FROM partsltd_prod.Shop_Product_Permutation_Variation_Link - ; - SELECT * - FROM partsltd_prod.Shop_Product_Permutation_Temp - ; - - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); -END // -DELIMITER ; - -CALL partsltd_prod.p_shop_save_product_permutation_test (); - -DELETE FROM partsltd_prod.Shop_Product_Permutation_Temp; - -DROP TABLE IF EXISTS tmp_Msg_Error; - - -/* -DELETE FROM partsltd_prod.Shop_Product_Permutation_Variation_Link -WHERE id_link >= 3 -; -DELETE FROM partsltd_prod.Shop_Product_Permutation -WHERE id_permutation >= 7 -; - - SELECT * - FROM partsltd_prod.Shop_Product_Permutation_Variation_Link_Temp - ; - SELECT * - FROM partsltd_prod.Shop_Variation - ; -*/ \ No newline at end of file diff --git a/static/MySQL/7210_p_shop_get_many_product_variation.sql b/static/MySQL/7210_p_shop_get_many_product_variation.sql deleted file mode 100644 index ff56896a..00000000 --- a/static/MySQL/7210_p_shop_get_many_product_variation.sql +++ /dev/null @@ -1,417 +0,0 @@ - -DROP PROCEDURE IF EXISTS p_shop_get_many_product_variation; - -DELIMITER // -CREATE PROCEDURE p_shop_get_many_product_variation ( - IN a_id_user INT - , IN a_get_all_variation_type BIT - , IN a_get_inactive_variation_type BIT - , IN a_ids_variation_type VARCHAR(4000) - , IN a_get_all_variation BIT - , IN a_get_inactive_variation BIT - , IN a_ids_variation TEXT - , IN a_debug BIT -) -BEGIN - -- Argument redeclaration - -- Variable declaration - DECLARE v_has_filter_variation BIT; - DECLARE v_has_filter_variation_type BIT; - DECLARE v_guid BINARY(36); - -- DECLARE v_id_user VARCHAR(100); - -- DECLARE v_ids_permutation_unavailable VARCHAR(4000); - DECLARE v_id_permission_variation INT; - -- DECLARE v_ids_product_permission VARCHAR(4000); - -- DECLARE v_ids_permutation_permission VARCHAR(4000); - DECLARE v_id_access_level_view INT; - DECLARE v_time_start TIMESTAMP(6); - DECLARE v_id_minimum INT; - DECLARE v_code_error_bad_data VARCHAR(50); - DECLARE v_id_type_error_bad_data INT; - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_guid := UUID(); - SET v_id_access_level_view := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW' LIMIT 1); - SET v_code_error_bad_data := (SELECT code FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1); - SET v_id_type_error_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_bad_data LIMIT 1); - - -- Argument validation + default values - SET a_id_user = IFNULL(a_id_user, 0); - SET a_get_all_variation = IFNULL(a_get_all_variation, 1); - SET a_get_inactive_variation = IFNULL(a_get_inactive_variation, 0); - SET a_ids_variation = TRIM(REPLACE(IFNULL(a_ids_variation, ''), '|', ',')); - SET a_get_all_variation_type = IFNULL(a_get_all_variation_type, 1); - SET a_get_inactive_variation_type = IFNULL(a_get_inactive_variation_type, 0); - SET a_ids_variation_type = TRIM(REPLACE(IFNULL(a_ids_variation_type, ''), '|', ',')); - - IF a_debug = 1 THEN - SELECT - a_id_user - , a_get_all_variation_type - , a_get_inactive_variation_type - , a_ids_variation_type - , a_get_all_variation - , a_get_inactive_variation - , a_ids_variation - , a_debug - ; - END IF; - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Variation; - DROP TABLE IF EXISTS tmp_Variation_Type; - - CREATE TEMPORARY TABLE tmp_Variation_Type ( - id_type INT NOT NULL - ); - - CREATE TEMPORARY TABLE tmp_Variation ( - id_variation INT NOT NULL - , id_type INT NOT NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - -- guid BINARY(36) NOT NULL, - id_type INT NULL, - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Split ( - substring VARCHAR(4000) NOT NULL - , as_int INT NULL - ); - DELETE FROM tmp_Split; - - - -- Parse filters - SET v_has_filter_variation = CASE WHEN a_ids_variation = '' THEN 0 ELSE 1 END; - SET v_has_filter_variation_type = CASE WHEN a_ids_variation_type = '' THEN 0 ELSE 1 END; - - -- select v_has_filter_product, v_has_filter_permutation; - - IF v_has_filter_variation_type THEN -- NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - CALL partsltd_prod.p_split(v_guid, a_ids_variation_type, ',', a_debug); - - DELETE FROM tmp_Split; - - INSERT INTO tmp_Split ( - substring - , as_int - ) - SELECT - substring - , CONVERT(substring, DECIMAL(10,0)) AS as_int - FROM partsltd_prod.Split_Temp - WHERE 1=1 - AND GUID = v_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( v_guid ); - END IF; - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Variation_Type VT ON t_S.as_int = VT.id_type - WHERE - ISNULL(t_S.as_int) - OR ISNULL(VT.id_type) - ) THEN - INSERT INTO tmp_Msg_Error ( - -- guid, - id_type, - code, - msg - ) - SELECT - -- v_guid, - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Invalid or inactive variation type IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Variation_Type VT ON t_S.as_int = VT.id_type - WHERE - ISNULL(t_S.as_int) - OR ISNULL(VT.id_type) - ; - ELSE - INSERT INTO tmp_Variation_Type ( - id_type - ) - SELECT - DISTINCT VT.id_type - FROM tmp_Split t_S - RIGHT JOIN partsltd_prod.Shop_Variation_Type VT ON t_S.as_int = VT.id_type - WHERE - ( - a_get_all_variation_type = 1 - OR ( - v_has_filter_variation_type = 1 - AND NOT ISNULL(t_S.as_int) - ) - ) - AND ( - a_get_inactive_variation_type = 1 - OR VT.active = 1 - ) - ; - END IF; - END IF; - - DELETE FROM tmp_Split; - - IF (v_has_filter_variation AND NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1)) THEN -- NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - CALL partsltd_prod.p_split(v_guid, a_ids_variation, ',', a_debug); - - DELETE FROM tmp_Split; - - INSERT INTO tmp_Split ( - substring - , as_int - ) - SELECT - substring - , CONVERT(substring, DECIMAL(10,0)) AS as_int - FROM partsltd_prod.Split_Temp - WHERE 1=1 - AND GUID = v_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( v_guid ); - END IF; - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Variation V ON t_S.as_int = V.id_variation - WHERE - ISNULL(t_S.as_int) - OR ISNULL(V.id_variation) - ) THEN - INSERT INTO tmp_Msg_Error ( - -- guid, - id_type, - code, - msg - ) - SELECT - -- v_guid, - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Invalid or inactive variation IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Variation V ON t_S.as_int = V.id_variation - WHERE - ISNULL(t_S.as_int) - OR ISNULL(VT.id_type) - ; - ELSE - INSERT INTO tmp_Variation ( - id_variation - , id_type - ) - SELECT - DISTINCT V.id_variation - , V.id_type - FROM tmp_Split t_S - RIGHT JOIN partsltd_prod.Shop_Variation V ON t_S.as_int = V.id_variation - WHERE - ( - a_get_all_variation = 1 - OR ( - v_has_filter_variation = 1 - AND NOT ISNULL(t_S.as_int) - ) - ) - AND ( - a_get_inactive_variation = 1 - OR V.active = 1 - ) - ; - END IF; - END IF; - - DELETE FROM tmp_Split; - - -- Permissions - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - -- SET v_id_user := (SELECT id_user FROM Shop_User WHERE name = CURRENT_USER()); - SET v_id_permission_variation := (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_PRODUCT' LIMIT 1); - - IF a_debug = 1 THEN - SELECT - v_guid - , a_id_user - , FALSE AS a_get_inactive_users - , v_id_permission_variation - , v_id_access_level_view - , '' AS a_ids_product - , 0 AS a_debug - ; - -- select * from Shop_Calc_User_Temp; - END IF; - - CALL p_shop_calc_user( - v_guid - , a_id_user - , FALSE -- a_get_inactive_users - , v_id_permission_variation - , v_id_access_level_view - , '' -- a_ids_product - , 0 -- a_debug - ); - - IF a_debug = 1 THEN - select * from Shop_Calc_User_Temp; - END IF; - - IF NOT EXISTS (SELECT can_view FROM Shop_Calc_User_Temp UE_T WHERE UE_T.GUID = v_guid) THEN - INSERT INTO tmp_Msg_Error ( - -- guid, - id_type, - code, - msg - ) - VALUES ( - -- v_guid, - v_id_type_error_bad_data, - v_code_error_bad_data, - CONCAT('You do not have view permissions for ', (SELECT name FROM Shop_Permission WHERE id_permission = v_id_permission_variation LIMIT 1)) - ) - ; - END IF; - - CALL p_shop_clear_calc_user( v_guid, 0 ); - END IF; - - IF EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - DELETE FROM tmp_Variation; - DELETE FROM tmp_Variation_Type; - END IF; - - -- Returns - -- Variation Types - SELECT - t_VT.id_type - , VT.code - , VT.name - , VT.name_plural - , VT.display_order - , VT.active - FROM tmp_Variation_Type t_VT - INNER JOIN Shop_Variation_Type VT ON t_VT.id_type = VT.id_type - ; - - -- Variations - SELECT - t_V.id_variation - , t_V.id_type - , V.code AS code_variation - , V.name AS name_variation - , V.display_order - , V.active AS active_variation - /* - , VT.code AS code_variation_type - , VT.name AS name_variation_type - , VT.name_plural AS name_plural_variation_type - , VT.active AS active_variation_type - , VT.display_order - */ - FROM tmp_Variation t_V - INNER JOIN Shop_Variation V ON t_V.id_variation = V.id_variation - INNER JOIN tmp_Variation_Type t_VT ON V.id_type = t_VT.id_type - INNER JOIN Shop_Variation_Type VT ON t_VT.id_type = VT.id_type - ORDER BY VT.display_order, V.display_order - ; - - -- Errors - SELECT - * - FROM tmp_Msg_Error t_ME - INNER JOIN Shop_Msg_Error_Type MET ON t_ME.id_type = MET.id_type - -- WHERE guid = v_guid - ; - - - -- Clean up - DROP TABLE IF EXISTS tmp_Variation; - DROP TABLE IF EXISTS tmp_Variation_Type; - - CALL partsltd_prod.p_shop_clear_calc_product_permutation ( v_guid ); - - IF a_debug = 1 THEN - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); - END IF; -END // -DELIMITER ; - -/* - -CALL p_shop_get_many_product_variation ( - 1 -- 'auth0|6582b95c895d09a70ba10fef', -- a_id_user - , 1 -- a_get_all_variation_type - , 1 -- a_get_inactive_variation_type - , '' -- a_ids_variation_type - , 1 -- a_get_all_variation - , 1 -- a_get_inactive_variation - , '' -- a_ids_variation - , 0 -- a_debug -); - - -select * from TMP_MSG_ERROR; -DROP TABLE TMP_MSG_ERROR; - -select * from shop_variation; -select * from shop_variation_type; -*/ -/* -select * from shop_supplier; -select * from shop_product; - -insert into shop_product_change_set (comment) - values ('set product not subscription - test bool output to python'); - update shop_product - set is_subscription = 0, - id_change_set = (select id_change_set from shop_product_change_set order by id_change_set desc limit 1) - where id_product = 1 - - INSERT INTO tmp_Variation_Type ( - id_type, - active, - rank_type - ) - SELECT - VT.id_type, - S.active, - RANK() OVER (ORDER BY id_type ASC) AS rank_type - FROM Shop_Variation_Type VT - LEFT JOIN Split_Temp S_T ON VT.id_type = S_T.substring - WHERE - ( - a_get_all_variation_type = 1 - OR NOT ISNULL(S_T.substring) - ) - AND ( - a_get_inactive_variation_type - OR VT.active = 1 - ) - ; - END IF; - - - IF a_get_first_variation_type_only THEN - DELETE t_VT - FROM tmp_Shop_Variation_Type t_VT - WHERE t_VT.rank_type > 1 - ; - END IF; -*/ \ No newline at end of file diff --git a/static/MySQL/7212_p_shop_save_product_variation.sql b/static/MySQL/7212_p_shop_save_product_variation.sql deleted file mode 100644 index d77c6dc4..00000000 --- a/static/MySQL/7212_p_shop_save_product_variation.sql +++ /dev/null @@ -1,551 +0,0 @@ - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_save_product_variation; - -DROP TABLE IF EXISTS tmp_Variation_Type; -DROP TABLE IF EXISTS tmp_Variation; -DROP TABLE IF EXISTS tmp_Msg_Error; - -DELIMITER // -CREATE PROCEDURE p_shop_save_product_variation ( - IN a_comment VARCHAR(500) - , IN a_guid BINARY(36) - , IN a_id_user INT - , IN a_debug BIT -) -BEGIN - DECLARE v_code_type_error_bad_data VARCHAR(50); - DECLARE v_code_type_error_no_permission VARCHAR(50); - DECLARE v_code_type_error_warning VARCHAR(50); - DECLARE v_id_access_level_edit INT; - DECLARE v_id_change_set INT; - DECLARE v_ids_permission_product_variation VARCHAR(100); - DECLARE v_id_type_error_bad_data INT; - DECLARE v_id_type_error_no_permission INT; - DECLARE v_id_type_error_warning INT; - DECLARE v_ids_product_permission TEXT; - DECLARE v_time_start TIMESTAMP(6); - - DECLARE exit handler for SQLEXCEPTION - BEGIN - GET DIAGNOSTICS CONDITION 1 - @sqlstate = RETURNED_SQLSTATE - , @errno = MYSQL_ERRNO - , @text = MESSAGE_TEXT - ; - - ROLLBACK; - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT - , id_type INT NULL - , code VARCHAR(50) NOT NULL - , msg VARCHAR(4000) NOT NULL - ); - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - MET.id_type - , @errno - , @text - FROM partsltd_prod.Shop_Msg_Error_Type MET - WHERE code = 'MYSQL_ERROR' - LIMIT 1 - ; - SELECT * - FROM tmp_Msg_Error; - DROP TABLE IF EXISTS tmp_Msg_Error; - END; - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_code_type_error_bad_data := (SELECT code FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1); - SET v_id_type_error_bad_data := (SELECT id_type FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = v_code_type_error_bad_data LIMIT 1); - SET v_code_type_error_no_permission := (SELECT code FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = 'NO_PERMISSION' LIMIT 1); - SET v_id_type_error_no_permission := (SELECT id_type FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = v_code_type_error_no_permission LIMIT 1); - SET v_code_type_error_warning := (SELECT code FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = 'WARNING' LIMIT 1); - SET v_id_type_error_warning := (SELECT id_type FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = v_code_type_error_warning LIMIT 1); - SET v_ids_permission_product_variation := (SELECT GROUP_CONCAT(id_permission SEPARATOR ',') FROM partsltd_prod.Shop_Permission WHERE code IN ('STORE_PRODUCT')); - SET v_id_access_level_edit := (SELECT id_access_level FROM partsltd_prod.Shop_Access_Level WHERE code = 'EDIT' LIMIT 1); - - CALL p_validate_guid ( a_guid ); - SET a_comment := TRIM(IFNULL(a_comment, '')); - - DROP TEMPORARY TABLE IF EXISTS tmp_Variation_Type; - DROP TEMPORARY TABLE IF EXISTS tmp_Variation; - DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error; - - -- Temporary tables - CREATE TEMPORARY TABLE tmp_Variation_Type ( - id_type INT NOT NULL PRIMARY KEY - , id_type_temp INT NOT NULL - , code VARCHAR(50) - , name VARCHAR(255) - , name_plural VARCHAR(256) - , active BIT NULL - , display_order INT NOT NULL - , created_on DATETIME - , created_by INT - , is_new BIT NOT NULL - , name_error VARCHAR(1000) NOT NULL - ); - -- CREATE TEMPORARY TABLE tmp_Variation_Type_Count - - CREATE TEMPORARY TABLE tmp_Variation ( - id_variation INT NOT NULL PRIMARY KEY - , id_type INT NOT NULL - , code VARCHAR(50) - , name VARCHAR(255) - , active BIT - , display_order INT NOT NULL - , created_on DATETIME - , created_by INT - , has_type BIT NULL - , is_new BIT NOT NULL - , name_error VARCHAR(1000) NOT NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT - , id_type INT NOT NULL - , code VARCHAR(50) NOT NULL - , msg VARCHAR(4000) NOT NULL - ); - - INSERT INTO tmp_Variation_Type ( - id_type - , id_type_temp - , code - , name - , name_plural - , active - , display_order - , created_on - , created_by - , is_new - , name_error - ) - SELECT - VT_T.id_type - , VT_T.id_type - , VT_T.code - , VT_T.name - , VT_T.name_plural - , VT_T.active - , VT_T.display_order - , IFNULL(VT_T.created_on, VT.created_on) AS created_on - , IFNULL(VT_T.created_by, VT.created_by) AS created_by - , IFNULL(VT_T.id_type, 0) < 1 AS is_new - , CASE WHEN IFNULL(VT_T.id_type, 0) < 1 THEN - CONCAT( - 'New Variation Type: ' - , VT_T.display_order - , ' - ' - , IFNULL(VT_T.code, '(No Code)') - , ' - ' - , IFNULL(VT_T.name, '(No Name)') - ) - ELSE - CONCAT( - VT_T.display_order - , ' - ' - , IFNULL(VT_T.code, '(No Code)') - , ' - ' - , IFNULL(VT_T.name, '(No Name)') - ) - END AS name_error - FROM partsltd_prod.Shop_Variation_Type_Temp VT_T - LEFT JOIN partsltd_prod.Shop_Variation_Type VT ON VT_T.id_type = VT.id_type - WHERE VT_T.GUID = a_guid - ; - - INSERT INTO tmp_Variation ( - id_variation - , id_type - , code - , name - , active - , display_order - , created_on - , created_by - , has_type - , is_new - , name_error - ) - SELECT - V_T.id_variation - , IFNULL(V_T.id_type, V.id_type) AS id_type - , V_T.code - , V_T.name - , V_T.active - , V_T.display_order - , IFNULL(V_T.created_on, V.created_on) AS created_on - , IFNULL(V_T.created_by, V.created_by) AS created_by - , NOT ISNULL(t_VT.id_type) AS has_type - , IFNULL(V_T.id_variation, 0) < 1 AS is_new - , CASE WHEN IFNULL(V_T.id_variation, 0) < 1 THEN - CONCAT( - 'New Variation: ' - , V_T.display_order - , ' - ' - , IFNULL(V_T.code, '(No Code)') - , ' - ' - , IFNULL(V_T.name, '(No Name)') - ) - ELSE - CONCAT( - V_T.display_order - , ' - ' - , IFNULL(V_T.code, '(No Code)') - , ' - ' - , IFNULL(V_T.name, '(No Name)') - ) - END AS name_error - FROM partsltd_prod.Shop_Variation_Temp V_T - LEFT JOIN partsltd_prod.Shop_Variation V ON V_T.id_variation = V.id_variation - -- LEFT JOIN partsltd_prod.Shop_Variation_Type VT ON V_T.id_type = VT.id_type - LEFT JOIN tmp_Variation_Type t_VT ON V_T.id_type = t_VT.id_type - WHERE V_T.GUID = a_guid - ; - - -- Insert missing order records - INSERT INTO tmp_Variation_Type ( - id_type - , id_type_temp - , code - , name - , name_plural - , active - , display_order - , created_on - , created_by - , is_new - , name_error - ) - SELECT - VT.id_type - , VT.id_type - , VT.code - , VT.name - , VT.name_plural - , VT.active - , VT.display_order - , VT.created_on - , VT.created_by - , 0 AS is_new - , CONCAT( - VT.display_order - , ' - ' - , IFNULL(VT.code, '(No Code)') - , ' - ' - , IFNULL(VT.name, '(No Name)') - ) AS name_error - FROM partsltd_prod.Shop_Variation_Type VT - INNER JOIN tmp_Variation t_V - ON VT.id_type = t_V.id_type - AND t_V.has_type = 0 - AND NOT ISNULL(t_V.id_type) - ; - - UPDATE tmp_Variation t_V - INNER JOIN tmp_Variation_Type t_VT ON t_V.id_type = t_V.id_type - SET t_V.has_type = 1 - WHERE t_V.has_type = 0 - ; - - -- Validation - -- Variation Type - -- id_type - IF EXISTS ( - SELECT * - FROM tmp_Variation_Type t_VT - INNER JOIN partsltd_prod.Shop_Variation_Type VT ON t_VT.id_type = VT.id_type - WHERE 1=1 - AND t_VT.id_type > 0 - AND ISNULL(VT.id_type) - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT( - 'A valid ID is required for the following Product Variation Type(s): ' - , GROUP_CONCAT(t_VT.name_error SEPARATOR ', ') - ) AS msg - FROM tmp_Variation_Type t_VT - INNER JOIN partsltd_prod.Shop_Variation_Type VT ON t_VT.id_type = VT.id_type - WHERE 1=1 - AND t_VT.id_type > 0 - AND ISNULL(VT.id_type) - ; - END IF; - -- Variation - -- id_variation - IF EXISTS ( - SELECT * - FROM tmp_Variation t_V - INNER JOIN partsltd_prod.Shop_Variation V ON t_V.id_variation = V.id_variation - WHERE 1=1 - AND t_V.id_variation > 0 - AND ISNULL(V.id_variation) - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT( - 'A valid ID is required for the following Product Variation(s): ' - , GROUP_CONCAT(t_V.name_error SEPARATOR ', ') - ) AS msg - FROM tmp_Variation t_V - INNER JOIN partsltd_prod.Shop_Variation V ON t_V.id_variation = V.id_variation - WHERE 1=1 - AND t_V.id_variation > 0 - AND ISNULL(V.id_variation) - ; - END IF; - -- id_type - IF EXISTS ( SELECT * FROM tmp_Variation t_V WHERE t_V.has_type = 0 LIMIT 1 ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT( - 'A valid ID is required for the following Product Variation(s): ' - , GROUP_CONCAT(t_V.name_error SEPARATOR ', ') - ) AS msg - FROM tmp_Variation t_V - WHERE t_V.has_type = 0 - ; - END IF; - - -- Duplicate Variation Type Ids - -- Duplicate Variation Ids - -- Duplicate Variation Type Codes - -- Duplicate Variation Codes - -- Variation unit measurement with no count unit measurement - - -- Permissions - IF a_debug = 1 THEN - SELECT - a_guid - , a_id_user - , FALSE -- get inactive users - , v_ids_permission_product_variation - , v_id_access_level_edit - , NULL -- ids_product - , 0 -- a_debug - ; - SELECT * - FROM partsltd_prod.Shop_Calc_User_Temp - WHERE GUID = a_guid - ; - END IF; - - CALL p_shop_calc_user( - a_guid - , a_id_user - , FALSE -- get inactive users - , v_ids_permission_product_variation - , v_id_access_level_edit - , NULL -- ids_product - , 0 -- a_debug - ); - - IF a_debug = 1 THEN - SELECT * from partsltd_prod.Shop_Calc_User_Temp WHERE GUID = a_guid; - END IF; - - IF EXISTS (SELECT * FROM partsltd_prod.Shop_Calc_User_Temp UE_T WHERE UE_T.GUID = a_guid AND IFNULL(UE_T.can_view, 0) = 0) THEN - DELETE FROM tmp_Msg_Error; - - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_no_permission - , v_code_type_error_no_permission - , CONCAT( - 'You do not have edit permissions for ' - , GROUP_CONCAT(name SEPARATOR ', ') - ) - FROM partsltd_prod.Shop_Permission PERM - INNER JOIN partsltd_prod.Shop_Calc_User_Temp UE_T - ON PERM.id_permission = UE_T.id_permission - AND UE_T.GUID = a_guid - AND IFNULL(UE_T.can_view, 0) = 0 - ; - END IF; - - CALL partsltd_prod.p_shop_clear_calc_user( - a_guid - , 0 -- a_debug - ); - - IF EXISTS ( SELECT * FROM tmp_Msg_Error WHERE id_type <> v_id_type_error_warning LIMIT 1 ) THEN - DELETE FROM tmp_Variation_Type; - DELETE FROM tmp_Variation; - END IF; - - -- Transaction - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - START TRANSACTION; - INSERT INTO Shop_Product_Change_Set ( - comment - , updated_last_by - , updated_last_on - ) - VALUES ( - a_comment - , a_id_user - , v_time_start - ); - - SET v_id_change_set := LAST_INSERT_ID(); - - INSERT INTO partsltd_prod.Shop_Variation_Type ( - id_type_temp - , code - , name - , name_plural - , active - , display_order - , created_on - , created_by - ) - SELECT - t_VT.id_type - , t_VT.code - , t_VT.name - , t_VT.name_plural - , t_VT.active - , t_VT.display_order - , t_VT.created_on - , t_VT.created_by - FROM tmp_Variation_Type t_VT - WHERE t_VT.is_new = 1 - ; - - UPDATE tmp_Variation_Type t_VT - INNER JOIN partsltd_prod.Shop_Variation_Type VT ON t_VT.id_type_temp = VT.id_type_temp - SET - t_VT.id_type = VT.id_type - WHERE t_VT.is_new = 1 - ; - - UPDATE tmp_Variation t_V - INNER JOIN tmp_Variation_Type t_VT - ON t_V.id_type = t_VT.id_type_temp - AND t_VT.is_new = 1 - SET - t_V.id_type = t_VT.id_type - ; - - INSERT INTO partsltd_prod.Shop_Variation ( - id_type - , code - , name - , active - , display_order - , created_on - , created_by - ) - SELECT - t_V.id_type - , t_V.code - , t_V.name - , t_V.active - , t_V.display_order - , t_V.created_on - , t_V.created_by - FROM tmp_Variation t_V - WHERE t_V.is_new = 1 - ; - - UPDATE partsltd_prod.Shop_Variation_Type VT - INNER JOIN tmp_Variation_Type t_VT - ON VT.id_type = t_VT.id_type - AND t_VT.is_new = 0 - INNER JOIN tmp_Variation t_V ON t_VT.id_type = t_V.id_type - SET - VT.code = t_VT.code - , VT.name = t_VT.name - , VT.name_plural = t_VT.name_plural - , VT.active = t_VT.active - , VT.display_order = t_VT.display_order - , VT.created_on = t_VT.created_on - , VT.created_by = t_VT.created_by - , VT.id_change_set = v_id_change_set - ; - - UPDATE partsltd_prod.Shop_Variation V - INNER JOIN tmp_Variation t_V - ON V.id_variation = t_V.id_variation - AND t_V.is_new = 0 - SET - V.code = t_V.code - , V.name = t_V.name - , V.active = t_V.active - , V.display_order = t_V.display_order - , V.created_on = t_V.created_on - , V.created_by = t_V.created_by - , V.id_change_set = v_id_change_set - ; - - COMMIT; - END IF; - - START TRANSACTION; - - DELETE VT_T - FROM partsltd_prod.Shop_Variation_Type_Temp VT_T - WHERE VT_T.GUID = a_guid - ; - DELETE V_T - FROM partsltd_prod.Shop_Variation_Temp V_T - WHERE V_T.GUID = a_guid - ; - - COMMIT; - - -- Errors - SELECT * - FROM tmp_Msg_Error t_ME - INNER JOIN partsltd_prod.Shop_Msg_Error_Type MET ON t_ME.id_type = MET.id_type - ; - - IF a_debug = 1 THEN - SELECT * from tmp_Variation_Type; - SELECT * from tmp_Variation; - END IF; - - DROP TEMPORARY TABLE tmp_Variation_Type; - DROP TEMPORARY TABLE tmp_Variation; - DROP TEMPORARY TABLE tmp_Msg_Error; - - IF a_debug = 1 THEN - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); - END IF; -END // -DELIMITER ; - - diff --git a/static/MySQL/7212_p_shop_save_product_variation_test.sql b/static/MySQL/7212_p_shop_save_product_variation_test.sql deleted file mode 100644 index baca42e2..00000000 --- a/static/MySQL/7212_p_shop_save_product_variation_test.sql +++ /dev/null @@ -1,186 +0,0 @@ - - --- Clear previous proc -DROP PROCEDURE IF EXISTS partsltd_prod.p_shop_save_product_variation_test; - - -DELIMITER // -CREATE PROCEDURE p_shop_save_product_variation_test () -BEGIN - - DECLARE v_guid BINARY(36); - DECLARE v_time_start TIMESTAMP(6); - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_guid := 'nips'; - - SELECT * - FROM partsltd_prod.Shop_Variation_Type - ; - SELECT * - FROM partsltd_prod.Shop_Variation_Type_Temp - ; - SELECT * - FROM partsltd_prod.Shop_Variation - ; - SELECT * - FROM partsltd_prod.Shop_Variation_Temp - ; - - START TRANSACTION; - - DELETE FROM partsltd_prod.Shop_Variation_Type_Temp; - DELETE FROM partsltd_prod.Shop_Variation_Temp; - - INSERT INTO partsltd_prod.Shop_Variation_Type_Temp ( - id_type - -- , id_type_temp - , code - , name - , name_plural - , display_order - , active - , GUID - ) - /* Test 1 - Insert - VALUES ( - -1 - -- , -1 - , 'SIZE' - , 'Size' - , 'Sizes' - , 2 - , 1 - , v_guid - ) - */ - /* Test 2: Alter */ - SELECT - id_type - -- , id_type AS id_type_temp - , code - , name - , name_plural - , display_order - , active - , v_guid AS GUID - FROM partsltd_prod.Shop_Variation_Type - WHERE id_type = 1 - ; - - INSERT INTO partsltd_prod.Shop_Variation_Temp ( - id_variation - , id_type - , code - , name - , display_order - , active - , GUID - ) - /* Test 1 - Insert - VALUES ( - -1 -- id_variation - , -1 -- id_type - , '300 mL' -- code - , '300 millilitres' -- name - , 1 -- display_order - , 1 -- active - , v_guid -- - ) - */ - /* Test 3 - Insert - VALUES ( - -1 -- id_variation - , 1 -- id_type - , 'SILVER' -- code - , 'Silver' -- name - , 10 -- display_order - , 1 -- active - , 'NIPS' -- v_guid -- - ); - */ - /* Test 2: Alter */ - SELECT - id_variation - , id_type - , code - , name - , display_order - , active - , v_guid AS GUID - FROM partsltd_prod.Shop_Variation - WHERE id_variation = 2 - UNION - SELECT - -1 -- id_variation - , 1 -- id_type - , 'GREEN' -- code - , 'Green' -- name - , 3 -- display_order - , 1 -- active - , v_guid -- - ; - - COMMIT; - - SELECT * - FROM partsltd_prod.Shop_Variation_Type_Temp - WHERE GUID = v_guid - ; - - SELECT * - FROM partsltd_prod.Shop_Variation_Temp - WHERE GUID = v_guid - ; - - CALL partsltd_prod.p_shop_save_product_variation ( - 'Test save Variations - add + edit' -- comment - , v_guid -- guid - , 1 -- id_user - , 1 -- debug - ); - - SELECT * - FROM partsltd_prod.Shop_Variation_Type_Temp - ; - SELECT * - FROM partsltd_prod.Shop_Variation_Temp - ; - SELECT * - FROM partsltd_prod.Shop_Variation_Type - ; - SELECT * - FROM partsltd_prod.Shop_Variation - ; - - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); -END // -DELIMITER ; - -/* -CALL partsltd_prod.p_shop_save_product_variation_test (); - -DELETE FROM partsltd_prod.Shop_Variation_Type_Temp; -DELETE FROM partsltd_prod.Shop_Variation_Temp; - -DROP TABLE IF EXISTS tmp_Msg_Error; - - -delete from shop_variation_audit -where id_variation = 3 -; -delete from shop_variation_audit -where id_variation = 3 -; -delete from shop_variation_type_audit -where id_type = -1 -; -delete --- select * - from shop_variation_type -where id_type = -1 -; - -Cannot add or update a child row: a foreign key constraint fails (`partsltd_prod`.`shop_variation_type`, CONSTRAINT `FK_Shop_Variation_Type_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`)) - -*/ \ No newline at end of file diff --git a/static/MySQL/7219_p_shop_get_many_stock_item.sql b/static/MySQL/7219_p_shop_get_many_stock_item.sql deleted file mode 100644 index 42551b5d..00000000 --- a/static/MySQL/7219_p_shop_get_many_stock_item.sql +++ /dev/null @@ -1,775 +0,0 @@ - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_get_many_stock_item; - - -DELIMITER // -CREATE PROCEDURE p_shop_get_many_stock_item ( - IN a_id_user INT, - IN a_get_all_product_permutation BIT, - IN a_get_inactive_product_permutation BIT, - IN a_ids_product_permutation TEXT, - IN a_get_all_stock_item BIT, - IN a_get_inactive_stock_item BIT, - IN a_ids_stock_item LONGTEXT, - IN a_get_all_region_storage BIT, - IN a_get_inactive_region_storage BIT, - IN a_ids_region_storage TEXT, - IN a_get_all_plant_storage BIT, - IN a_get_inactive_plant_storage BIT, - IN a_ids_plant_storage TEXT, - IN a_get_all_location_storage BIT, - IN a_get_inactive_location_storage BIT, - IN a_ids_location_storage TEXT, - IN a_date_received_to DATETIME, - IN a_get_sealed_stock_item_only BIT, - IN a_get_unsealed_stock_item_only BIT, - IN a_get_expired_stock_item_only BIT, - IN a_get_nonexpired_stock_item_only BIT, - IN a_get_consumed_stock_item_only BIT, - IN a_get_nonconsumed_stock_item_only BIT, - IN a_debug BIT -) -BEGIN - DECLARE v_has_filter_permutation BIT; - DECLARE v_has_filter_stock_item BIT; - DECLARE v_has_filter_region_storage BIT; - DECLARE v_has_filter_plant_storage BIT; - DECLARE v_has_filter_location_storage BIT; - DECLARE v_guid BINARY(36); - -- DECLARE v_ids_permutation_unavailable LONGTEXT; - DECLARE v_id_permission_product INT; - DECLARE v_ids_product_permission LONGTEXT; - -- DECLARE v_ids_permutation_permission VARCHAR(4000); - DECLARE v_id_access_level_view INT; - -- DECLARE v_now DATETIME; - -- DECLARE v_id_minimum INT; - DECLARE v_time_start TIMESTAMP(6); - - SET v_guid := UUID(); - SET v_id_access_level_view := (SELECT id_access_level FROM partsltd_prod.Shop_Access_Level WHERE code = 'VIEW'); - SET v_time_start := CURRENT_TIMESTAMP(6); - - - -- Argument validation + default values - SET a_id_user := TRIM(IFNULL(a_id_user, '')); - SET a_get_all_product_permutation := IFNULL(a_get_all_product_permutation, 0); - -- SET a_guid_permutations := IFNULL(a_guid_permutations, ''); - SET a_get_inactive_product_permutation := IFNULL(a_get_inactive_product_permutation, 0); - SET a_ids_product_permutation := IFNULL(a_ids_product_permutation, ''); - SET a_get_all_stock_item := IFNULL(a_get_all_stock_item, 0); - SET a_get_inactive_stock_item := IFNULL(a_get_inactive_stock_item, 0); - SET a_ids_stock_item := TRIM(IFNULL(a_ids_stock_item, '')); - SET a_get_all_region_storage := IFNULL(a_get_all_region_storage, 0); - SET a_get_inactive_region_storage := IFNULL(a_get_inactive_region_storage, 0); - SET a_ids_region_storage := TRIM(IFNULL(a_ids_region_storage, '')); - SET a_get_all_plant_storage := IFNULL(a_get_all_plant_storage, 0); - SET a_get_inactive_plant_storage := IFNULL(a_get_inactive_plant_storage, 0); - SET a_ids_plant_storage := TRIM(IFNULL(a_ids_plant_storage, '')); - SET a_get_all_location_storage := IFNULL(a_get_all_location_storage, 0); - SET a_get_inactive_location_storage := IFNULL(a_get_inactive_location_storage, 0); - SET a_ids_location_storage := TRIM(IFNULL(a_ids_location_storage, '')); - SET a_date_received_to := a_date_received_to; -- IFNULL(a_date_received_to, NOW()); - SET a_get_sealed_stock_item_only := IFNULL(a_get_sealed_stock_item_only, 0); - SET a_get_unsealed_stock_item_only := IFNULL(a_get_unsealed_stock_item_only, 0); - SET a_get_expired_stock_item_only := IFNULL(a_get_expired_stock_item_only, 0); - SET a_get_nonexpired_stock_item_only := IFNULL(a_get_nonexpired_stock_item_only, 0); - SET a_get_consumed_stock_item_only := IFNULL(a_get_consumed_stock_item_only, 0); - SET a_get_nonconsumed_stock_item_only := IFNULL(a_get_nonconsumed_stock_item_only, 0); - - -- Temporary tables - DROP TEMPORARY TABLE IF EXISTS tmp_Region_Storage; - DROP TEMPORARY TABLE IF EXISTS tmp_Plant_Storage; - DROP TEMPORARY TABLE IF EXISTS tmp_Location_Storage; - DROP TEMPORARY TABLE IF EXISTS tmp_Stock_Item; - DROP TEMPORARY TABLE IF EXISTS tmp_Permutation; - -- DROP TABLE IF EXISTS tmp_Msg_Error; - DROP TEMPORARY TABLE IF EXISTS tmp_Category; - DROP TEMPORARY TABLE IF EXISTS tmp_Permutation; - DROP TEMPORARY TABLE IF EXISTS tmp_Product; - - CREATE TEMPORARY TABLE tmp_Category ( - id_category INT NOT NULL - , display_order INT NOT NULL - ); - - CREATE TEMPORARY TABLE tmp_Product ( - id_category INT NOT NULL - , id_product INT NOT NULL - , display_order INT NOT NULL - ); - - CREATE TEMPORARY TABLE tmp_Permutation ( - id_permutation INT NULL - , id_product INT NOT NULL - , can_view BIT - , can_edit BIT - , can_admin BIT - ); - - CREATE TEMPORARY TABLE tmp_Stock_Item ( - id_stock INT NOT NULL PRIMARY KEY - , id_permutation INT NOT NULL - , id_product INT NOT NULL - , id_location_storage INT NOT NULL - , can_view BIT NULL - , can_edit BIT NULL - , can_admin BIT NULL - ); - - CREATE TEMPORARY TABLE tmp_Region_Storage ( - id_region INT NOT NULL PRIMARY KEY - /* - CONSTRAINT FK_tmp_Region_Storage_id_region - FOREIGN KEY (id_region) - REFERENCES Shop_Region(id_region) - */ - -- , rank_region INT NOT NULL - ); - - CREATE TEMPORARY TABLE tmp_Plant_Storage ( - id_plant INT NOT NULL PRIMARY KEY - /* - CONSTRAINT FK_tmp_Plant_Storage_id_plant - FOREIGN KEY (id_plant) - REFERENCES Shop_Plant(id_plant) - */ - -- , rank_plant INT NOT NULL - , id_region INT NOT NULL - ); - - CREATE TEMPORARY TABLE tmp_Location_Storage ( - id_location INT NOT NULL PRIMARY KEY - /* - CONSTRAINT FK_tmp_Location_Storage_id_location - FOREIGN KEY (id_location) - REFERENCES Shop_Location_Storage(id_location) - */ - -- , rank_location INT NOT NULL - , id_plant INT NOT NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - -- guid BINARY(36) NOT NULL, - id_type INT NULL, - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Split ( - substring VARCHAR(4000) NOT NULL - , as_int INT NULL - ); - DELETE FROM tmp_Split; - - - -- Parse filters - SET v_has_filter_permutation = CASE WHEN a_ids_product_permutation = '' THEN 0 ELSE 1 END; -- CASE WHEN a_guid_permutations = '' THEN 0 ELSE 1 END; - SET v_has_filter_stock_item = CASE WHEN a_ids_stock_item = '' THEN 0 ELSE 1 END; - SET v_has_filter_region_storage = CASE WHEN a_ids_region_storage = '' THEN 0 ELSE 1 END; - SET v_has_filter_plant_storage = CASE WHEN a_ids_plant_storage = '' THEN 0 ELSE 1 END; - SET v_has_filter_location_storage = CASE WHEN a_ids_location_storage = '' THEN 0 ELSE 1 END; - - -- select v_has_filter_product, v_has_filter_permutation; - - CALL partsltd_prod.p_shop_calc_product_permutation ( - a_id_user - , 1 -- a_get_all_product_category - , 0 -- a_get_inactive_product_category - , '' -- a_ids_product_category - , 1 -- a_get_all_product - , 0 -- a_get_inactive_product - , '' -- a_ids_product - , a_get_all_product_permutation - , a_get_inactive_product_permutation - , a_ids_product_permutation - , 0 - , v_guid -- a_guid - , 0 -- a_debug - ); - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - INSERT INTO tmp_Category ( - id_category - , display_order - ) - SELECT - PC.id_category - , PC.display_order - FROM (SELECT * FROM partsltd_prod.Shop_Product_Category_Temp WHERE GUID = v_guid) PC_T - INNER JOIN partsltd_prod.Shop_Product_Category PC ON PC_T.id_category = PC.id_category - ; - - INSERT INTO tmp_Product ( - id_product - , id_category - , display_order - ) - SELECT - P.id_product - , P.id_category - , P.display_order - FROM (SELECT * FROM partsltd_prod.Shop_Product_Temp WHERE GUID = v_guid) P_T - INNER JOIN partsltd_prod.Shop_Product P ON P.id_product = P_T.id_product - ; - - INSERT INTO tmp_Permutation ( - id_permutation - , id_product - , can_view - , can_edit - , can_admin - ) - SELECT - PP.id_permutation - , PP.id_product - , PP_T.can_view - , PP_T.can_edit - , PP_T.can_admin - FROM (SELECT * FROM partsltd_prod.Shop_Product_Permutation_Temp WHERE GUID = v_guid) PP_T - INNER JOIN partsltd_prod.Shop_Product_Permutation PP ON PP_T.id_permutation = PP.id_permutation - ; - - -- Stock Items - CALL partsltd_prod.p_split(v_guid, a_ids_stock_item, ',', a_debug); - - DELETE FROM tmp_Split; - - INSERT INTO tmp_Split ( - substring - , as_int - ) - SELECT - substring - , CONVERT(substring, DECIMAL(10,0)) AS as_int - FROM partsltd_prod.Split_Temp - WHERE 1=1 - AND GUID = v_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( v_guid ); - END IF; - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Stock_Item SI ON t_S.as_int = SI.id_stock - WHERE - ISNULL(t_S.as_int) - OR ISNULL(SI.id_stock) - ) THEN - INSERT INTO tmp_Msg_Error ( - -- guid, - id_type, - code, - msg - ) - SELECT - -- v_guid, - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Invalid or inactive stock item IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Stock_Item SI ON t_S.as_int = SI.id_stock - WHERE - ISNULL(t_S.as_int) - OR ISNULL(SI.id_stock) - ; - ELSE - INSERT INTO tmp_Stock_Item ( - id_stock - , id_permutation - , id_product - , id_location_storage - ) - SELECT - SI.id_stock - , SI.id_permutation - , t_PP.id_product - , SI.id_location_storage - FROM tmp_Split t_S - RIGHT JOIN partsltd_prod.Shop_Stock_Item SI ON t_S.as_int = SI.id_stock - INNER JOIN tmp_Permutation t_PP ON SI.id_permutation = t_PP.id_permutation - WHERE - ( - a_get_all_stock_item = 1 - OR ( - v_has_filter_stock_item = 1 - AND NOT ISNULL(t_S.as_int) - ) - ) - AND ( - a_get_inactive_stock_item = 1 - OR SI.active = 1 - ) - AND ( - ISNULL(a_date_received_to) - OR SI.date_received <= a_date_received_to - ) - AND ( - a_get_unsealed_stock_item_only = 0 - OR SI.is_sealed = 0 - ) - AND ( - a_get_sealed_stock_item_only = 0 - OR SI.is_sealed = 1 - ) - AND ( - a_get_nonexpired_stock_item_only = 0 - OR SI.date_expiration > v_time_start - ) - AND ( - a_get_expired_stock_item_only = 0 - OR SI.date_expiration <= v_time_start - ) - AND ( - a_get_consumed_stock_item_only = 0 - OR SI.is_consumed = 1 - ) - AND ( - a_get_nonconsumed_stock_item_only = 0 - OR SI.is_consumed = 0 - ) - ; - END IF; - END IF; - - DELETE FROM tmp_Split; - - -- Storage Regions - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - CALL partsltd_prod.p_split(v_guid, a_ids_region_storage, ',', a_debug); - - DELETE FROM tmp_Split; - - INSERT INTO tmp_Split ( - substring - , as_int - ) - SELECT - substring - , CONVERT(substring, DECIMAL(10,0)) AS as_int - FROM partsltd_prod.Split_Temp - WHERE 1=1 - AND GUID = v_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( v_guid ); - END IF; - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Region R ON t_S.as_int = R.id_region - WHERE - ISNULL(t_S.as_int) - OR ISNULL(R.id_region) - ) THEN - INSERT INTO tmp_Msg_Error ( - -- guid, - id_type, - code, - msg - ) - SELECT - -- v_guid, - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Invalid or inactive region IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Region R ON t_S.as_int = R.id_region - WHERE - ISNULL(t_S.as_int) - OR ISNULL(R.id_region) - ; - ELSE - INSERT INTO tmp_Region_Storage ( - id_region - ) - WITH RECURSIVE Recursive_CTE_Region_Storage AS ( - SELECT - R.id_region AS id_region_parent, - NULL AS id_region_child - FROM tmp_Split t_S - RIGHT JOIN partsltd_prod.Shop_Region R - ON t_S.as_int = R.id_region - AND ( - a_get_all_region_storage = 1 - OR NOT ISNULL(t_S.as_int) - ) - AND ( - a_get_inactive_region_storage = 1 - OR R.active = 1 - ) - INNER JOIN ( - SELECT - A.id_region - FROM tmp_Stock_Item t_SI - -- INNER JOIN tmp_Stock_Item t_SI ON SL.id_location = t_SI.id_location_storage - INNER JOIN partsltd_prod.Shop_Storage_Location SL ON t_SI.id_location_storage = SL.id_location - INNER JOIN partsltd_prod.Shop_Plant P ON SL.id_plant = P.id_plant - INNER JOIN partsltd_prod.Shop_Address A ON P.id_address = A.id_address - ) A_SI ON R.id_region = A_SI.id_region - UNION - SELECT - RB.id_region_parent, - RB.id_region_child - FROM partsltd_prod.Shop_Region_Branch RB - INNER JOIN Recursive_CTE_Region_Storage r_RS - ON RB.id_region_parent = r_RS.id_region_child - AND ( - a_get_inactive_region_storage = 1 - OR RB.active = 1 - ) - ) - SELECT - DISTINCT R.id_region - FROM partsltd_prod.Shop_Region R - INNER JOIN Recursive_CTE_Region_Storage r_RS - ON R.id_region = r_RS.id_region_parent - OR R.id_region = r_RS.id_region_child - ; - END IF; - END IF; - - DELETE FROM tmp_Split; - - -- Plants - INSERT INTO tmp_Plant_Storage ( - id_plant - , id_region - ) - SELECT - DISTINCT P.id_plant - , A.id_region - FROM tmp_Stock_Item t_SI - INNER JOIN partsltd_prod.Shop_Storage_Location SL ON t_SI.id_location_storage = SL.id_location - INNER JOIN partsltd_prod.Shop_Plant P ON SL.id_plant = P.id_plant - INNER JOIN partsltd_prod.Shop_Address A ON P.id_address = A.id_address - ; - - -- Storage Locations - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - CALL partsltd_prod.p_split(v_guid, a_ids_location_storage, ',', a_debug); - - DELETE FROM tmp_Split; - - INSERT INTO tmp_Split ( - substring - , as_int - ) - SELECT - substring - , CONVERT(substring, DECIMAL(10,0)) AS as_int - FROM partsltd_prod.Split_Temp - WHERE 1=1 - AND GUID = v_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( v_guid ); - END IF; - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Region R ON t_S.as_int = R.id_region - WHERE - ISNULL(t_S.as_int) - OR ISNULL(R.id_region) - ) THEN - INSERT INTO tmp_Msg_Error ( - -- guid, - id_type, - code, - msg - ) - SELECT - -- v_guid, - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Invalid or inactive region IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Region R ON t_S.as_int = R.id_region - WHERE - ISNULL(t_S.as_int) - OR ISNULL(R.id_region) - ; - ELSE - INSERT INTO tmp_Location_Storage ( - id_location - , id_plant - ) - WITH RECURSIVE Recursive_CTE_Location_Storage AS ( - SELECT - SL.id_location AS id_location_parent, - NULL AS id_location_child - FROM tmp_Split t_S - RIGHT JOIN partsltd_prod.Shop_Storage_Location SL - ON t_S.as_int = SL.id_location - AND ( - a_get_all_location_storage = 1 - OR NOT ISNULL(t_S.as_int) - ) - AND ( - a_get_inactive_location_storage = 1 - OR SL.active = 1 - ) - INNER JOIN tmp_Stock_Item t_SI ON SL.id_location = t_SI.id_location_storage - UNION - SELECT - SLB.id_location_parent, - SLB.id_location_child - FROM partsltd_prod.Shop_Storage_Location_Branch SLB - INNER JOIN Recursive_CTE_Location_Storage r_LS - ON SLB.id_location_parent = r_LS.id_location_child - AND ( - a_get_inactive_location_storage - OR SLB.active = 1 - ) - ) - SELECT - DISTINCT SL.id_location - , SL.id_plant - FROM partsltd_prod.Shop_Storage_Location SL - INNER JOIN Recursive_CTE_Location_Storage r_LS - ON SL.id_location = r_LS.id_location_parent - OR SL.id_location = r_LS.id_location_child - ; - END IF; - END IF; - - DELETE FROM tmp_Split; - - /* - -- Permissions - IF EXISTS (SELECT * FROM tmp_Stock_Item LIMIT 1) THEN - SET v_id_permission_product := (SELECT id_permission FROM partsltd_prod.Shop_Permission WHERE code = 'STORE_PRODUCT' LIMIT 1); - SET v_ids_product_permission := (SELECT GROUP_CONCAT(id_product SEPARATOR ',') FROM tmp_Permutation WHERE NOT ISNULL(id_product)); - -- SET v_ids_permutation_permission := (SELECT GROUP_CONCAT(id_permutation SEPARATOR ',') FROM tmp_Shop_Product WHERE NOT ISNULL(id_permutation)); - - -- SELECT v_guid, a_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_product_permission; - -- select * FROM partsltd_prod.Shop_Calc_User_Temp; - - CALL p_shop_calc_user( - v_guid - , a_id_user - , false -- a_get_inactive_users - , v_id_permission_product - , v_id_access_level_view - , v_ids_product_permission - , 0 -- a_debug - ); - - -- select * FROM partsltd_prod.Shop_Calc_User_Temp; - - UPDATE tmp_Stock_Item t_SI - INNER JOIN partsltd_prod.Shop_Calc_User_Temp UE_T - ON t_SI.id_product = UE_T.id_product - AND UE_T.GUID = v_guid - SET t_SI.can_view = UE_T.can_view, - t_SI.can_edit = UE_T.can_edit, - t_SI.can_admin = UE_T.can_admin - ; - - DELETE t_SI - FROM tmp_Stock_Item t_SI - / * - LEFT JOIN partsltd_prod.Shop_Calc_User_Temp UE_T - ON t_SI.id_product = UE_T.id_product - AND UE_T.GUID = v_guid - * / - WHERE - / * - FIND_IN_SET(t_SI.id_product, ( - SELECT GROUP_CONCAT(UET.id_product SEPARATOR ',') - FROM partsltd_prod.Shop_Calc_User_Temp UET) - ) = 0 -- id_product NOT LIKE CONCAT('%', (SELECT GROUP_CONCAT(id_product SEPARATOR '|') FROM partsltd_prod.Shop_Calc_User_Temp), '%'); - * / - / * - ISNULL(UE_T.id_product) - OR IFNULL(UE_T.can_view, 0) = 0 - * / - t_SI.id_product NOT IN ( - SELECT id_product - FROM partsltd_prod.Shop_Calc_User_Temp UE_T - WHERE - GUID = v_guid - AND IFNULL(can_view, 0) = 1 - ) - ; - - -- CALL p_shop_clear_calc_user(v_guid); - -- DROP TABLE IF EXISTS Shop_Calc_User_Temp; - DELETE FROM partsltd_prod.Shop_Calc_User_Temp - WHERE GUID = v_guid - ; - END IF; - */ - - /* - select * FROM partsltd_prod.Shop_stock_item; - select * from tmp_Stock_Item; - select * from tmp_Permutation; - select * from tmp_Location_Storage; - select * from Shop_Storage_Location; - select * from tmp_Plant_Storage; - select * from tmp_Region_Storage; - */ - - -- Returns - -- SET v_now := NOW(); - -- Stock Items - SELECT - t_SI.id_stock, - t_SI.id_permutation, - P.id_product, - P.id_category, - t_SI.id_location_storage, - t_PS.id_plant, - PLANT.id_address AS id_address_plant, - t_RS.id_region AS id_region_plant, - SL.code AS code_storage_location, - SL.name AS name_storage_location, - PLANT.code AS code_plant, - PLANT.name AS name_plant, - SI.id_currency_cost, - CURRENCY.symbol AS symbol_currency_cost, - CURRENCY.code AS code_currency_cost, - SI.cost_local_VAT_excl, - SI.cost_local_VAT_incl, - SI.date_purchased, - SI.date_received, - SI.is_sealed, - SI.date_unsealed, - SI.date_expiration, - SI.is_consumed, - SI.date_consumed, - SI.active, - /* - t_SI.active_permutation, - t_SI.active_product, - t_SI.active_category, - */ - t_PP.can_view, - t_PP.can_edit, - t_PP.can_admin - FROM tmp_Stock_Item t_SI - INNER JOIN partsltd_prod.Shop_Stock_Item SI ON t_SI.id_stock = SI.id_stock - INNER JOIN tmp_Permutation t_PP ON t_SI.id_permutation = t_PP.id_permutation - INNER JOIN partsltd_prod.Shop_Product P ON t_PP.id_product = P.id_product - INNER JOIN tmp_Location_Storage t_LS ON t_SI.id_location_storage = t_LS.id_location - INNER JOIN tmp_Plant_Storage t_PS ON t_LS.id_plant = t_PS.id_plant - INNER JOIN partsltd_prod.Shop_Plant PLANT ON t_PS.id_plant = PLANT.id_plant - INNER JOIN partsltd_prod.Shop_Address A ON PLANT.id_address = A.id_address - INNER JOIN tmp_Region_Storage t_RS ON A.id_region = t_RS.id_region - INNER JOIN partsltd_prod.Shop_Storage_Location SL ON t_LS.id_location = SL.id_location - INNER JOIN partsltd_prod.Shop_Currency CURRENCY ON SI.id_currency_cost = CURRENCY.id_currency - WHERE - IFNULL(t_PP.can_view, 0) = 1 - ; - - -- Errors - SELECT - t_ME.display_order, - -- t_ME.guid, - t_ME.id_type, - t_ME.msg, - MET.code, - MET.name, - MET.description - FROM tmp_Msg_Error t_ME - INNER JOIN partsltd_prod.Shop_Msg_Error_Type MET - ON t_ME.id_type = MET.id_type - -- WHERE guid = v_guid - ; - - /* - -- Return arguments for test - SELECT - a_ids_category, - a_get_inactive_category, - a_ids_product, - a_get_inactive_product, - a_get_first_product_only, - a_get_all_product, - a_ids_image, - a_get_inactive_image, - a_get_first_image_only, - a_get_all_image - ; - */ - - - -- Clean up - DROP TEMPORARY TABLE IF EXISTS tmp_Region_Storage; - DROP TEMPORARY TABLE IF EXISTS tmp_Plant_Storage; - DROP TEMPORARY TABLE IF EXISTS tmp_Location_Storage; - DROP TEMPORARY TABLE IF EXISTS tmp_Stock_Item; - DROP TEMPORARY TABLE IF EXISTS tmp_Permutation; - -- DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error; - - CALL partsltd_prod.p_shop_clear_calc_product_permutation ( v_guid ); - - IF a_debug = 1 THEN - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); - END IF; -END // -DELIMITER ; - - -/* -CALL p_shop_get_many_stock_item ( - 1, -- a_id_user - 1, -- a_get_all_product_permutation - -- 'nips', -- a_guid_permutations - 0, -- a_get_inactive_product_permutation - '', -- a_ids_product_permutation - 1, -- a_get_all_stock_item - 0, -- a_get_inactive_stock_item - '', -- a_ids_stock_item - 1, -- a_get_all_region_storage - 0, -- a_get_inactive_delivery_region - '', -- a_ids_region_storage - 1, -- a_get_all_plant_storage - 0, -- a_get_inactive_plant_storage - '', -- a_ids_plant_storage - 1, -- a_get_all_location_storage - 0, -- a_get_inactive_location_storage - '', -- a_ids_location_storage - NULL, -- a_date_received_to - 0, -- a_get_sealed_stock_item_only - 0, -- a_get_unsealed_stock_item_only - 0, -- a_get_expired_stock_item_only - 0, -- a_get_nonexpired_stock_item_only - 0, -- a_get_consumed_stock_item_only - 0 -- a_get_nonconsumed_stock_item_only - , 0 -- a_debug -); - - - -DROP TABLE IF EXISTS tmp_Msg_Error; - -select * FROM partsltd_prod.Shop_Storage_Location; -select * FROM partsltd_prod.Shop_product; -select * from TMP_MSG_ERROR; -DROP TABLE TMP_MSG_ERROR; - -insert into shop_product_change_set (comment) - values ('set product not subscription - test bool output to python'); - update shop_product - set is_subscription = 0, - id_change_set = (select id_change_set FROM partsltd_prod.Shop_product_change_set order by id_change_set desc limit 1) - where id_product = 1 -*/ diff --git a/static/MySQL/7220_p_shop_save_stock_item.sql b/static/MySQL/7220_p_shop_save_stock_item.sql deleted file mode 100644 index 8c490953..00000000 --- a/static/MySQL/7220_p_shop_save_stock_item.sql +++ /dev/null @@ -1,702 +0,0 @@ - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_save_stock_item; - -DELIMITER // -CREATE PROCEDURE p_shop_save_stock_item ( - IN a_comment VARCHAR(500) - , IN a_guid BINARY(36) - , IN a_id_user INT - , IN a_debug BIT -) -BEGIN - - DECLARE v_code_type_error_bad_data VARCHAR(100); - DECLARE v_id_access_level_edit INT; - DECLARE v_id_change_set INT; - DECLARE v_id_permission_product INT; - DECLARE v_id_type_error_bad_data INT; - DECLARE v_ids_product_permission LONGTEXT; - DECLARE v_time_start TIMESTAMP(6); - DECLARE v_time_expire DATETIME; - - DECLARE exit handler for SQLEXCEPTION - BEGIN - -- Get diagnostic information - GET DIAGNOSTICS CONDITION 1 - @sqlstate = RETURNED_SQLSTATE - , @errno = MYSQL_ERRNO - , @text = MESSAGE_TEXT - ; - - -- Rollback the transaction - ROLLBACK; - - -- Select the error information - -- SELECT 'Error' AS status, @errno AS error_code, @sqlstate AS sql_state, @text AS message; - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT - , id_type INT NULL - , code VARCHAR(50) NOT NULL - , msg VARCHAR(4000) NOT NULL - ); - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - NULL - , @errno - , @text - ; - SELECT * - FROM tmp_Msg_Error; - DROP TABLE IF EXISTS tmp_Msg_Error; - END; - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_time_expire := DATE_ADD(v_time_start, INTERVAL 1000 YEAR); - SET v_code_type_error_bad_data := 'BAD_DATA'; - SET v_id_type_error_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_type_error_bad_data LIMIT 1); - SET v_id_access_level_edit := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'EDIT' LIMIT 1); - - CALL partsltd_prod.p_validate_guid ( a_guid ); - - DROP TEMPORARY TABLE IF EXISTS tmp_Stock_Item; - DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error; - - CREATE TEMPORARY TABLE tmp_Stock_Item ( - id_stock INT NOT NULL - , id_category INT NULL - , id_product INT NOT NULL - , id_permutation INT NULL - , id_pairs_variations VARCHAR(4000) NULL - , has_variations BIT NULL - , date_purchased DATETIME NOT NULL - , date_received DATETIME NULL - , id_location_storage INT NOT NULL - , id_currency_cost INT NOT NULL - , cost_local_VAT_incl FLOAT NOT NULL - , cost_local_VAT_excl FLOAT NOT NULL - , is_sealed BIT NOT NULL - , date_unsealed DATETIME NULL - , date_expiration DATETIME NOT NULL - , is_consumed BIT NOT NULL - , date_consumed DATETIME NULL - , active BIT NOT NULL - , can_view BIT NULL - , can_edit BIT NULL - , can_admin BIT NULL - , name_error VARCHAR(1000) NULL - , is_new BIT NOT NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT - , id_type INT NULL - , code VARCHAR(50) NOT NULL - , msg VARCHAR(4000) NOT NULL - ); - - - -- Get data from Temp table - INSERT INTO tmp_Stock_Item ( - id_stock - -- , id_category - , id_product - , id_permutation - , id_pairs_variations - , has_variations - , date_purchased - , date_received - , id_location_storage - , id_currency_cost - , cost_local_VAT_incl - , cost_local_VAT_excl - , is_sealed - , date_unsealed - , date_expiration - , is_consumed - , date_consumed - , active - -- , name_error - , is_new - ) - SELECT - SI_T.id_stock - -- , IFNULL(SI_T.id_category, P.id_category) AS id_category - , IFNULL(IFNULL(SI_T.id_product, PP.id_product), 0) AS id_product - , IFNULL(IFNULL(SI_T.id_permutation, SI.id_permutation), 0) AS id_permutation - , TRIM(IFNULL(SI_T.id_pairs_variations, '')) - , CASE WHEN TRIM(IFNULL(SI_T.id_pairs_variations, '')) = '' THEN 0 ELSE 1 END AS has_variations - , IFNULL(IFNULL(SI_T.date_purchased, SI.date_purchased), v_time_start) AS date_purchased - , IFNULL(SI_T.date_received, SI.date_received) AS date_received - , IFNULL(IFNULL(SI_T.id_location_storage, SI.id_location_storage), 0) AS id_location_storage - , IFNULL(IFNULL(SI_T.id_currency_cost, SI.id_currency_cost), 0) AS id_currency_cost - , IFNULL(SI_T.cost_local_VAT_incl, SI.cost_local_VAT_incl) AS cost_local_VAT_incl - , IFNULL(SI_T.cost_local_VAT_excl, SI.cost_local_VAT_excl) AS cost_local_VAT_excl - , IFNULL(IFNULL(SI_T.is_sealed, SI.is_sealed), 1) AS is_sealed - , IFNULL(SI_T.date_unsealed, SI.date_unsealed) AS date_unsealed - , IFNULL(IFNULL(SI_T.date_expiration, SI.date_expiration), v_time_expire) AS date_expiration - , IFNULL(IFNULL(SI_T.is_consumed, SI.is_consumed), 0) AS is_consumed - , IFNULL(SI_T.date_consumed, SI.date_consumed) AS date_consumed - , IFNULL(IFNULL(SI_T.active, SI.active), 1) AS active - -- , fn_shop_get_product_permutation_name(SI_T.id_permutation) - , CASE WHEN IFNULL(SI_T.id_stock, 0) < 1 THEN 1 ELSE 0 END AS is_new - FROM partsltd_prod.Shop_Stock_Item_Temp SI_T - LEFT JOIN partsltd_prod.Shop_Stock_Item SI ON SI_T.id_stock = SI.id_stock - LEFT JOIN partsltd_prod.Shop_Product_Permutation PP ON SI_T.id_permutation = PP.id_permutation - -- LEFT JOIN Shop_Product P ON PP.id_product = P.id_product - WHERE SI_T.guid = a_guid - ; - - -- Missing Permutation IDs for setting new permutation for stock item - -- With variations - UPDATE tmp_Stock_Item t_SI - INNER JOIN partsltd_prod.Shop_Product P ON t_SI.id_product = P.id_product - SET t_SI.id_permutation = IFNULL(fn_shop_get_id_product_permutation_from_variation_csv_list ( t_SI.id_product, t_SI.id_pairs_variations ), 0) - WHERE 1=1 - AND t_SI.id_permutation = 0 - AND t_SI.has_variations = 1 - ; - -- Without variations - UPDATE tmp_Stock_Item t_SI - -- INNER JOIN Shop_Product P ON t_SI.id_product = P.id_product - INNER JOIN partsltd_prod.Shop_Product_Permutation PP ON t_SI.id_product = PP.id_product - SET t_SI.id_permutation = IFNULL(PP.id_permutation, 0) - WHERE 1=1 - AND t_SI.id_permutation = 0 - AND t_SI.has_variations = 0 - ; - - -- Add stock item error names - UPDATE tmp_Stock_Item t_SI - INNER JOIN partsltd_prod.Shop_Product P ON t_SI.id_product = P.id_product - INNER JOIN partsltd_prod.Shop_Product_Category PC ON P.id_category = PC.id_category - -- INNER JOIN Shop_Product_Permutation PP ON t_SI.id_product = PP.id_product - SET t_SI.name_error = CONCAT( - PC.name, - ' - ', - P.name, - ' - ', - CASE WHEN IFNULL(t_SI.id_permutation, 0) = 0 THEN '(No permutation)' ELSE fn_shop_get_product_permutation_name ( t_SI.id_permutation ) END - ) - ; - - IF a_debug = 1 THEN - sElect * from tmp_Stock_Item; - END IF; - - -- Validation - -- id_stock - IF EXISTS ( - SELECT * - FROM tmp_Stock_Item t_SI - LEFT JOIN partsltd_prod.Shop_Stock_Item SI ON t_SI.id_stock = SI.id_stock - WHERE 1=1 - AND t_SI.id_stock > 0 - AND ISNULL(SI.id_stock) - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT( - 'Invalid stock item(s): ' - , GROUP_CONCAT( - CONCAT( - IFNULL(t_SI.id_stock, '(No Stock Item)') - , ' - ' - , IFNULL(t_SI.name_error, '(No Product)') - ) SEPARATOR ', ' - ) - ) AS msg - FROM tmp_Stock_Item t_SI - LEFT JOIN partsltd_prod.Shop_Product_Permutation PP ON t_SI.id_permutation = PP.id_permutation - WHERE 1=1 - AND t_SI.id_stock > 0 - AND ISNULL(SI.id_stock) - ; - END IF; - -- id_product - IF EXISTS (SELECT * FROM tmp_Stock_Item t_SI WHERE t_SI.id_product = 0 LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following stock item(s) do not have a product: ', GROUP_CONCAT(IFNULL(t_SI.name_error, 'NULL') SEPARATOR ', ')) AS msg - FROM tmp_Stock_Item t_SI - WHERE t_SI.id_product = 0 - ; - END IF; - -- id_permutation - IF EXISTS ( - SELECT * - FROM tmp_Stock_Item t_SI - LEFT JOIN partsltd_prod.Shop_Product_Permutation PP ON t_SI.id_permutation = PP.id_permutation - WHERE 1=1 - AND ( - t_SI.id_permutation = 0 - OR PP.active = 0 - ) - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('A valid permutation could not be found for the variations selected for the following stock item(s): ', GROUP_CONCAT(IFNULL(t_SI.name_error, 'NULL') SEPARATOR ', ')) AS msg - FROM tmp_Stock_Item t_SI - LEFT JOIN partsltd_prod.Shop_Product_Permutation PP ON t_SI.id_permutation = PP.id_permutation - WHERE 1=1 - AND ( - t_SI.id_permutation = 0 - OR PP.active = 0 - ) - ; - END IF; - -- date_purchased - IF EXISTS (SELECT * FROM tmp_Stock_Item t_SI WHERE ISNULL(t_SI.date_purchased) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following stock item(s) do not have an purchase date: ', GROUP_CONCAT(IFNULL(t_SI.name_error, 'NULL') SEPARATOR ', ')) AS msg - FROM tmp_Stock_Item t_SI - WHERE ISNULL(t_SI.date_purchased) - ; - END IF; - -- id_location_storage - IF EXISTS ( - SELECT * - FROM tmp_Stock_Item t_SI - INNER JOIN partsltd_prod.Shop_Storage_Location SL - ON t_SI.id_location_storage = SL.id_location - AND SL.active = 1 - WHERE ISNULL(SL.id_location) - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following stock item(s) do not have a valid storage location: ', GROUP_CONCAT(IFNULL(t_SI.name_error, 'NULL') SEPARATOR ', ')) AS msg - FROM tmp_Stock_Item t_SI - INNER JOIN partsltd_prod.Shop_Storage_Location SL - ON t_SI.id_location_storage = SL.id_location - AND SL.active = 1 - WHERE ISNULL(SL.id_location) - ; - END IF; - -- id_currency_cost - IF EXISTS ( - SELECT * - FROM tmp_Stock_Item t_SI - INNER JOIN partsltd_prod.Shop_Currency C - ON t_SI.id_currency_cost = C.id_currency - AND C.active = 1 - WHERE ISNULL(C.id_currency) - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following stock item(s) do not have a valid cost currency: ', GROUP_CONCAT(IFNULL(t_SI.name_error, 'NULL') SEPARATOR ', ')) AS msg - FROM tmp_Stock_Item t_SI - INNER JOIN partsltd_prod.Shop_Currency C - ON t_SI.id_currency_cost = C.id_currency - AND C.active = 1 - WHERE ISNULL(C.id_currency) - ; - END IF; - -- cost_local_VAT_excl - IF EXISTS ( - SELECT * - FROM tmp_Stock_Item t_SI - WHERE 1=1 - AND ( - ISNULL(t_SI.cost_local_VAT_excl) - OR t_SI.cost_local_VAT_excl < 0 - ) - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following stock item(s) do not have a valid cost excluding VAT: ', GROUP_CONCAT(IFNULL(t_SI.name_error, 'NULL') SEPARATOR ', ')) AS msg - FROM tmp_Stock_Item t_SI - WHERE 1=1 - AND ( - ISNULL(t_SI.cost_local_VAT_excl) - OR t_SI.cost_local_VAT_excl < 0 - ) - ; - END IF; - -- cost_local_VAT_incl - IF EXISTS ( - SELECT * - FROM tmp_Stock_Item t_SI - WHERE 1=1 - AND ( - ISNULL(t_SI.cost_local_VAT_incl) - OR t_SI.cost_local_VAT_incl < 0 - ) - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following stock item(s) do not have a valid cost including VAT: ', GROUP_CONCAT(IFNULL(t_SI.name_error, 'NULL') SEPARATOR ', ')) AS msg - FROM tmp_Stock_Item t_SI - WHERE 1=1 - AND ( - ISNULL(t_SI.cost_local_VAT_incl) - OR t_SI.cost_local_VAT_incl < t_SI.cost_local_VAT_excl - ) - ; - END IF; - -- date_received - IF EXISTS (SELECT * FROM tmp_Stock_Item t_SI WHERE NOT ISNULL(t_SI.date_received) AND t_SI.date_received < t_SI.date_purchased LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following stock item(s) do not have a valid received date: ', GROUP_CONCAT(IFNULL(t_SI.name_error, 'NULL') SEPARATOR ', ')) AS msg - FROM tmp_Stock_Item t_SI - WHERE 1=1 - AND NOT ISNULL(t_SI.date_received) - AND t_SI.date_received < t_SI.date_purchased - ; - END IF; - -- date_unsealed - IF EXISTS (SELECT * FROM tmp_Stock_Item t_SI WHERE NOT ISNULL(t_SI.date_unsealed) AND t_SI.date_unsealed < t_SI.date_purchased LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following stock item(s) do not have a valid unsealed date: ', GROUP_CONCAT(IFNULL(t_SI.name_error, 'NULL') SEPARATOR ', ')) AS msg - FROM tmp_Stock_Item t_SI - WHERE 1=1 - AND NOT ISNULL(t_SI.date_received) - AND t_SI.date_received < t_SI.date_purchased - ; - END IF; - -- date_expiration - IF EXISTS (SELECT * FROM tmp_Stock_Item t_SI WHERE NOT ISNULL(t_SI.date_expiration) AND t_SI.date_expiration < t_SI.date_purchased LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following stock item(s) do not have a valid expiration date: ', GROUP_CONCAT(IFNULL(t_SI.name_error, 'NULL') SEPARATOR ', ')) AS msg - FROM tmp_Stock_Item t_SI - WHERE 1=1 - AND NOT ISNULL(t_SI.date_expiration) - AND t_SI.date_expiration < t_SI.date_purchased - ; - END IF; - -- date_consumed - IF EXISTS (SELECT * FROM tmp_Stock_Item t_SI WHERE NOT ISNULL(t_SI.date_consumed) AND t_SI.date_consumed < t_SI.date_purchased LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following stock item(s) do not have a valid consumed date: ', GROUP_CONCAT(IFNULL(t_SI.name_error, 'NULL') SEPARATOR ', ')) AS msg - FROM tmp_Stock_Item t_SI - WHERE 1=1 - AND NOT ISNULL(t_SI.date_consumed) - AND t_SI.date_consumed < t_SI.date_purchased - ; - END IF; - - -- Permissions - SET v_ids_product_permission := ( SELECT GROUP_CONCAT(t_SI.id_product SEPARATOR ',') FROM tmp_Stock_Item t_SI ); - - IF NOT ISNULL(v_ids_product_permission) THEN - SET v_id_permission_product = (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_PRODUCT' LIMIT 1); - - CALL p_shop_calc_user( - a_guid - , a_id_user - , FALSE -- a_get_inactive_users - , v_id_permission_product - , v_id_access_level_edit - , v_ids_product_permission - , 0 -- a_debug - ); - - UPDATE tmp_Stock_Item t_SI - INNER JOIN Shop_Product P ON t_SI.id_product = P.id_product - INNER JOIN Shop_Calc_User_Temp UE_T - ON P.id_product = UE_T.id_product - AND UE_T.GUID = a_guid - SET - t_SI.can_view = UE_T.can_view - , t_SI.can_edit = UE_T.can_edit - , t_SI.can_admin = UE_T.can_admin - ; - - CALL p_shop_clear_calc_user( - a_guid - , 0 -- a_debug - ); - - IF EXISTS (SELECT * FROM tmp_Stock_Item t_SI WHERE IFNULL(t_SI.can_edit, 0) = 0 LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - guid - , id_type - , code - , msg - ) - SELECT - a_guid AS GUID - , v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following stock item(s) do not have product edit permission: ', GROUP_CONCAT(IFNULL(t_SI.name_error, 'NULL') SEPARATOR ', ')) AS msg - FROM tmp_Stock_Item t_SI - WHERE IFNULL(t_SI.can_edit, 0) = 0 - ; - END IF; - END IF; - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - START TRANSACTION; - - IF NOT ISNULL(v_ids_product_permission) THEN - INSERT INTO Shop_Product_Change_Set ( - comment - , updated_last_by - ) - VALUES ( - a_comment, - a_id_user - ) - ; - - SET v_id_change_set := LAST_INSERT_ID(); - - -- select * from partsltd_prod.Shop_Stock_Item - UPDATE partsltd_prod.Shop_Stock_Item SI - INNER JOIN tmp_Stock_Item t_SI - ON SI.id_stock = t_SI.id_stock - SET - SI.id_permutation = t_SI.id_permutation - , SI.date_purchased = t_SI.date_purchased - , SI.date_received = t_SI.date_received - , SI.id_location_storage = t_SI.id_location_storage - , SI.id_currency_cost = t_SI.id_currency_cost - , SI.cost_local_VAT_excl = t_SI.cost_local_VAT_excl - , SI.cost_local_VAT_incl = t_SI.cost_local_VAT_incl - , SI.is_sealed = t_SI.is_sealed - , SI.date_unsealed = t_SI.date_unsealed - , SI.date_expiration = t_SI.date_expiration - , SI.is_consumed = t_SI.is_consumed - , SI.date_consumed = t_SI.date_consumed - , SI.active = t_SI.active - , SI.id_change_set = v_id_change_set - ; - END IF; - - INSERT INTO partsltd_prod.Shop_Stock_Item ( - id_permutation - , date_purchased - , date_received - , id_location_storage - , id_currency_cost - , cost_local_VAT_excl - , cost_local_VAT_incl - , is_sealed - , date_unsealed - , date_expiration - , is_consumed - , date_consumed - , active - , created_by - , created_on - ) - SELECT - t_SI.id_permutation - , t_SI.date_purchased - , t_SI.date_received - , t_SI.id_location_storage - , t_SI.id_currency_cost - , t_SI.cost_local_VAT_excl - , t_SI.cost_local_VAT_incl - , t_SI.is_sealed - , t_SI.date_unsealed - , t_SI.date_expiration - , t_SI.is_consumed - , t_SI.date_consumed - , t_SI.active - , a_id_user AS created_by - , v_time_start AS created_on - FROM tmp_Stock_Item t_SI - WHERE - is_new = 1 - AND active = 1 - ; - - COMMIT; - END IF; - - START TRANSACTION; - - DELETE FROM partsltd_prod.Shop_Stock_Item_Temp - WHERE GUID = a_guid; - - COMMIT; - - -- Errors - SELECT * - FROM tmp_Msg_Error t_ME - INNER JOIN partsltd_prod.Shop_Msg_Error_Type MET ON t_ME.id_type = MET.id_type - ; - - IF a_debug = 1 THEN - SELECT * from tmp_Stock_Item; - END IF; - - DROP TEMPORARY TABLE IF EXISTS tmp_Stock_Item; - DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error; - - IF a_debug = 1 THEN - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); - END IF; -END // -DELIMITER ; - - -/* - -DELETE FROM Shop_Product_Permutation_Temp -WHERE id_permutation = 1 -; - -INSERT INTO Shop_Product_Permutation_Temp ( - id_permutation, - id_product, - description, - cost_local, - id_currency_cost, - profit_local_min, - latency_manufacture, - id_unit_measurement_quantity, - count_unit_measurement_per_quantity_step, - quantity_min, - quantity_max, - quantity_stock, - is_subscription, - id_unit_measurement_interval_recurrence, - count_interval_recurrence, - id_stripe_product, - does_expire_faster_once_unsealed, - id_unit_measurement_interval_expiration_unsealed, - count_interval_expiration_unsealed, - active, - guid -) -VALUES - ( - 1 -- id_permutation, - , 1 -- id_product, - , 'Good Reddy Teddy' -- description, - , 5.0 -- cost_local, - , 1 -- id_currency_cost, - , 3.0 -- profit_local_min, - , 14 -- latency_manufacture, - , 1 -- id_unit_measurement_quantity, - , 1.0 -- count_unit_measurement_quantity, - , 3.0 -- quantity_min, - , 99.0 -- quantity_max, - , 1.0 -- quantity_stock, - , False -- is_subscription, - , null -- id_unit_measurement_interval_recurrence, - , null -- count_interval_recurrence, - , null -- id_stripe_product, - , False -- does_expire_faster_once_unsealed, - , null -- id_unit_measurement_interval_expiration_unsealed, - , null -- count_interval_expiration_unsealed, - , True -- active, - , 'NIPS' -- guid - ) -; - -select 'Shop_Product_Permutation_Temp before call'; -SELECT * FROM Shop_Product_Permutation_Temp; - -SELECT 'Shop_Product_Permutation before call' AS result_name; -select * FROM Shop_Product_Permutation; - -CALL p_shop_save_product_permutation ( - 1, -- 'auth0|6582b95c895d09a70ba10fef', -- a_id_user - 'Initial data', -- a_comment - 'NIPS' -- a_guid -); - -SELECT 'Shop_Product_Permutation_Temp after call' AS result_name; -select * FROM Shop_Product_Permutation_Temp; - -SELECT 'Shop_Product_Permutation after call' AS result_name; -select * FROM Shop_Product_Permutation; - - -DELETE FROM Shop_Product_Permutation_Temp -WHERE id_permutation = 1; - - -*/ - diff --git a/static/MySQL/7220_p_shop_save_stock_item_test.sql b/static/MySQL/7220_p_shop_save_stock_item_test.sql deleted file mode 100644 index 0f03f955..00000000 --- a/static/MySQL/7220_p_shop_save_stock_item_test.sql +++ /dev/null @@ -1,101 +0,0 @@ - - --- Clear previous proc -DROP PROCEDURE IF EXISTS partsltd_prod.p_shop_save_stock_item_test; - - -DELIMITER // -CREATE PROCEDURE p_shop_save_stock_item_test () -BEGIN - - DECLARE v_guid BINARY(36); - DECLARE v_time_start TIMESTAMP(6); - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_guid := 'nips'; - - SELECT * - FROM partsltd_prod.Shop_Stock_Item - ; - SELECT * - FROM partsltd_prod.Shop_Stock_Item_Temp - ; - - START TRANSACTION; - - INSERT INTO partsltd_prod.Shop_Stock_Item_Temp ( - id_stock - -- id_category - , id_product - , id_permutation - , id_pairs_variations - -- , has_variations - , date_purchased - , date_received - , id_location_storage - , id_currency_cost - , cost_local_VAT_excl - , cost_local_VAT_incl - , is_sealed - , date_unsealed - , date_expiration - , is_consumed - , date_consumed - , active - , guid - ) - VALUES ( - -1 -- id_stock - -- 1 -- id_category - , 4 -- id_product - , NULL -- id_permutation - , NULL -- id_pairs_variations - -- , FALSE -- 0 -- has_variations - , '2025-09-05 00:00' -- date_purchased - , NULL -- date_received - , 1 -- id_location_storage - , 1 -- id_currency_cost - , 10 -- cost_local_VAT_excl - , 12 -- cost_local_VAT_incl - , 1 -- is_sealed - , NULL -- date_unsealed - , NULL -- date_expiration - , FALSE -- 0 -- is_consumed - , NULL -- date_consumed - , 1 -- active - , v_guid - ); - - COMMIT; - - SELECT * - FROM partsltd_prod.Shop_Stock_Item_Temp - WHERE GUID = v_guid - ; - - CALL partsltd_prod.p_shop_save_Stock_Item ( - 'Test save Stock_Item' -- comment - , v_guid -- guid - , 1 -- id_user - , 0 -- debug - ); - - SELECT * - FROM partsltd_prod.Shop_Stock_Item - ; - SELECT * - FROM partsltd_prod.Shop_Stock_Item_Temp - ; - - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); -END // -DELIMITER ; - -CALL partsltd_prod.p_shop_save_stock_item_test (); - -DELETE FROM partsltd_prod.Shop_Stock_Item_Temp; - -/* -update shop_product p set p.has_variations = 0 where id_product = 4 -DROP TABLE IF EXISTS tmp_Msg_Error; -*/ \ No newline at end of file diff --git a/static/MySQL/7221_p_get_many_shop_product_price_and_discount_and_delivery_option.sql b/static/MySQL/7221_p_get_many_shop_product_price_and_discount_and_delivery_option.sql deleted file mode 100644 index fb342ab4..00000000 --- a/static/MySQL/7221_p_get_many_shop_product_price_and_discount_and_delivery_option.sql +++ /dev/null @@ -1,1006 +0,0 @@ --- USE partsltd_prod; - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_get_many_product_price_and_discount_and_delivery_option; - -DELIMITER // -CREATE PROCEDURE p_shop_get_many_product_price_and_discount_and_delivery_option ( - IN a_id_user INT - , IN a_get_all_product_permutation BIT - , IN a_get_inactive_product_permutation BIT - , IN a_ids_product_permutation TEXT - , IN a_get_all_product_price BIT - , IN a_get_inactive_product_price BIT - , IN a_ids_product_price TEXT - , IN a_product_price_min FLOAT - , IN a_product_price_max FLOAT - , IN a_get_all_currency BIT - , IN a_get_inactive_currency BIT - , IN a_ids_currency VARCHAR(4000) - , IN a_get_all_discount BIT - , IN a_get_inactive_discount BIT - , IN a_ids_discount TEXT - , IN a_get_all_delivery_option BIT - , IN a_get_inactive_delivery_option BIT - , IN a_ids_delivery_option TEXT - , IN a_get_all_delivery_region BIT - , IN a_get_inactive_delivery_region BIT - , IN a_ids_delivery_region TEXT - , IN a_debug BIT -) -BEGIN - -- Argument redeclaration - -- Variable declaration - DECLARE v_has_filter_product_permutation BIT; - DECLARE v_has_filter_product_price BIT; - DECLARE v_has_filter_currency BIT; - DECLARE v_has_filter_discount BIT; - DECLARE v_has_filter_delivery_option BIT; - DECLARE v_has_filter_delivery_region BIT; - DECLARE v_guid BINARY(36); - -- DECLARE v_id_user VARCHAR(100); - DECLARE v_ids_permutation_unavailable VARCHAR(4000); - DECLARE v_id_permission_product INT; - DECLARE v_ids_product_permission VARCHAR(4000); - -- DECLARE v_ids_permutation_permission VARCHAR(4000); - DECLARE v_id_access_level_view INT; - -- DECLARE v_now DATETIME; - DECLARE v_id_minimum INT; - DECLARE v_time_start TIMESTAMP(6); - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_guid := UUID(); - SET v_id_access_level_view := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW'); - - - -- Argument validation + default values - SET a_id_user := TRIM(IFNULL(a_id_user, '')); - SET a_get_all_product_permutation := TRIM(IFNULL(a_get_all_product_permutation, 1)); - SET a_get_inactive_product_permutation := TRIM(IFNULL(a_get_inactive_product_permutation, 0)); - SET a_ids_product_permutation := TRIM(IFNULL(a_ids_product_permutation, '')); - SET a_get_all_delivery_region := TRIM(IFNULL(a_get_all_delivery_region, 1)); - SET a_get_inactive_delivery_region := TRIM(IFNULL(a_get_inactive_delivery_region, 0)); - SET a_ids_delivery_region := TRIM(IFNULL(a_ids_delivery_region, '')); - SET a_get_all_currency := TRIM(IFNULL(a_get_all_currency, 1)); - SET a_get_inactive_currency := TRIM(IFNULL(a_get_inactive_currency, 0)); - SET a_ids_currency := TRIM(IFNULL(a_ids_currency, '')); - SET a_get_all_discount := TRIM(IFNULL(a_get_all_discount, 1)); - SET a_get_inactive_discount := TRIM(IFNULL(a_get_inactive_discount, 0)); - SET a_ids_discount := TRIM(IFNULL(a_ids_discount, '')); - SET a_debug := IFNULL(a_debug, 0); - - IF a_debug = 1 THEN - SELECT - a_id_user - , a_get_all_variation_type - , a_get_inactive_variation_type - , a_get_first_variation_type_only - , a_ids_variation_type - , a_get_all_variation - , a_get_inactive_variation - , a_get_first_variation_only - , a_ids_variation - , a_debug - ; - END IF; - - -- Temporary tables - DROP TEMPORARY TABLE IF EXISTS tmp_Discount; - DROP TEMPORARY TABLE IF EXISTS tmp_Currency; - DROP TEMPORARY TABLE IF EXISTS tmp_Delivery_Region; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Image; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Variation; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Product; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Product_2; - DROP TEMPORARY TABLE IF EXISTS tmp_Category; - DROP TEMPORARY TABLE IF EXISTS tmp_Permutation; - DROP TEMPORARY TABLE IF EXISTS tmp_Product; - - CREATE TEMPORARY TABLE tmp_Category ( - id_category INT NOT NULL - , display_order INT NOT NULL - ); - - CREATE TEMPORARY TABLE tmp_Product ( - id_category INT NOT NULL - , id_product INT NOT NULL - , display_order INT NOT NULL - ); - - CREATE TEMPORARY TABLE tmp_Permutation ( - id_permutation INT NULL - , id_product INT NOT NULL - , can_view BIT - , can_edit BIT - , can_admin BIT - ); - - CREATE TEMPORARY TABLE tmp_Price ( - id_price INT - , id_permutation INT - ); - - CREATE TEMPORARY TABLE tmp_Currency ( - id_currency INT NOT NULl - /* - active BIT NOT NULL - display_order INT NOT NULL - */ - ); - - CREATE TEMPORARY TABLE tmp_Discount ( - id_discount INT NOT NULL - /* - active BIT NOT NULL, - display_order INT NOT NULL - */ - ); - - CREATE TEMPORARY TABLE tmp_Delivery_Option ( - id_option INT NOT NULL - /* - active BIT NOT NULL, - display_order INT NOT NULL, - requires_delivery_option BIT NOT NULL DEFAULT 0 - */ - ); - - CREATE TEMPORARY TABLE tmp_Delivery_Region ( - id_region INT NOT NULL - /* - active BIT NOT NULL, - display_order INT NOT NULL, - requires_delivery_option BIT NOT NULL DEFAULT 0 - */ - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - -- guid BINARY(36) NOT NULL, - id_type INT NULL, - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Split ( - substring VARCHAR(4000) NOT NULL - , as_int INT NULL - ); - DELETE FROM tmp_Split; - - - -- Parse filters - SET v_has_filter_product_permutation = CASE WHEN a_ids_product_permutation = '' THEN 0 ELSE 1 END; - SET v_has_filter_product_price = CASE WHEN a_ids_product_price = '' THEN 0 ELSE 1 END; - SET v_has_filter_currency = CASE WHEN a_ids_currency = '' THEN 0 ELSE 1 END; - SET v_has_filter_discount = CASE WHEN a_ids_discount = '' THEN 0 ELSE 1 END; - SET v_has_filter_delivery_option = CASE WHEN a_ids_delivery_option = '' THEN 0 ELSE 1 END; - SET v_has_filter_delivery_region = CASE WHEN a_ids_delivery_region = '' THEN 0 ELSE 1 END; - - IF a_debug = 1 THEN - SELECT - v_has_filter_product_permutation - , v_has_filter_product_price - , v_has_filter_currency - , v_has_filter_discount - , v_has_filter_delivery_option - , v_has_filter_delivery_region - ; - END IF; - - CALL partsltd_prod.p_shop_calc_product_permutation ( - a_id_user - , 1 -- a_get_all_product_category - , 0 -- a_get_inactive_product_category - , '' -- a_ids_product_category - , 1 -- a_get_all_product - , 0 -- a_get_inactive_product - , '' -- a_ids_product - , a_get_all_product_permutation - , a_get_inactive_product_permutation - , a_ids_product_permutation - , 0 - , v_guid -- a_guid - , 0 -- a_debug - ); - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - INSERT INTO tmp_Category ( - id_category - , display_order - ) - SELECT - PC.id_category - , PC.display_order - FROM (SELECT * FROM partsltd_prod.Shop_Product_Category_Temp WHERE GUID = v_guid) PC_T - INNER JOIN partsltd_prod.Shop_Product_Category PC ON PC_T.id_category = PC.id_category - ; - - INSERT INTO tmp_Product ( - id_product - , id_category - , display_order - ) - SELECT - P.id_product - , P.id_category - , P.display_order - FROM (SELECT * FROM partsltd_prod.Shop_Product_Temp WHERE GUID = v_guid) P_T - INNER JOIN partsltd_prod.Shop_Product P ON P.id_product = P_T.id_product - ; - - INSERT INTO tmp_Permutation ( - id_permutation - , id_product - , can_view - , can_edit - , can_admin - ) - SELECT - PP.id_permutation - , PP.id_product - , PP_T.can_view - , PP_T.can_edit - , PP_T.can_admin - FROM (SELECT * FROM partsltd_prod.Shop_Product_Permutation_Temp WHERE GUID = v_guid) PP_T - INNER JOIN partsltd_prod.Shop_Product_Permutation PP ON PP_T.id_permutation = PP.id_permutation - ; - - -- Product Prices - CALL partsltd_prod.p_split(v_guid, a_ids_product_price, ',', a_debug); - - DELETE FROM tmp_Split; - - INSERT INTO tmp_Split ( - substring - , as_int - ) - SELECT - substring - , CONVERT(substring, DECIMAL(10,0)) AS as_int - FROM partsltd_prod.Split_Temp - WHERE 1=1 - AND GUID = v_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( v_guid ); - END IF; - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Product_Price PRICE ON t_S.as_int = PRICE.id_price - WHERE - ISNULL(t_S.as_int) - OR ISNULL(PRICE.id_price) - ) THEN - INSERT INTO tmp_Msg_Error ( - -- guid, - id_type, - code, - msg - ) - SELECT - -- v_guid, - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Invalid or inactive product price IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Product_Price PRICE ON t_S.as_int = PRICE.id_price - WHERE - ISNULL(t_S.as_int) - OR ISNULL(PRICE.id_price) - ; - ELSE - INSERT INTO tmp_Price ( - id_price - , id_permutation - ) - SELECT - PRICE.id_price - , PRICE.id_permutation - FROM tmp_Split t_S - RIGHT JOIN partsltd_prod.Shop_Product_Price PRICE ON t_S.as_int = PRICE.id_price - INNER JOIN tmp_Permutation t_PP ON SI.id_permutation = t_PP.id_permutation - WHERE - ( - a_get_all_stock_item = 1 - OR ( - v_has_filter_stock_item = 1 - AND NOT ISNULL(t_S.as_int) - ) - ) - AND ( - a_get_inactive_stock_item = 1 - OR SI.active = 1 - ) - ; - END IF; - END IF; - - DELETE FROM tmp_Split; - - - INSERT INTO tmp_Shop_Product ( - id_permutation, - active_permutation, - display_order_permutation - ) - SELECT - PP.id_permutation, - PP.active AS active_permutation, - PP.display_order AS display_order_permutation - FROM Shop_Product P - INNER JOIN Shop_Product_Permutation PP - ON P.id_product = PP.id_product - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - WHERE - -- permutations - ( - a_get_all_product_permutation - OR ( - v_has_filter_product_permutation - AND FIND_IN_SET(PP.id_permutation, a_ids_product_permutation) > 0 - ) - OR ( - a_get_products_quantity_stock_below_min = 1 - AND PP.quantity_stock < PP.quantity_min - ) - ) - AND ( - a_get_inactive_product_permutation - OR PP.active - ) - ; - - -- Delivery Regions - INSERT INTO tmp_Delivery_Region ( - id_region, - active, - display_order, - requires_delivery_option - ) - WITH RECURSIVE Recursive_CTE_Delivery_Region AS ( - SELECT - DR.id_region AS id_region_parent, - NULL AS id_region_child, - CASE WHEN FIND_IN_SET(DR.id_region, a_ids_delivery_region) > 0 THEN 1 ELSE 0 END AS requires_delivery_option - FROM Shop_Product_Currency_Region_Link PCRL - INNER JOIN Shop_Currency C ON PCRL.id_currency = C.id_currency - INNER JOIN tmp_Shop_Product t_P - ON PCRL.id_product <=> t_P.id_product - AND PCRL.id_permutation <=> t_P.id_permutation - INNER JOIN Shop_Region DR ON PCRL.id_region_purchase = DR.id_region - WHERE - ( - a_get_all_delivery_region - OR FIND_IN_SET(DR.id_region, a_ids_delivery_region) > 0 - ) - AND ( - a_get_inactive_delivery_region - OR DR.active = 1 - ) - UNION - SELECT - DRB.id_region_parent, - DRB.id_region_child, - 0 AS requires_delivery_option - FROM Shop_Region_Branch DRB - INNER JOIN Recursive_CTE_Delivery_Region r_DR - ON DRB.id_region_parent = r_DR.id_region_child - AND ( - a_get_inactive_delivery_region - OR DRB.active = 1 - ) - ) - SELECT - DR.id_region, - DR.active, - DR.display_order, - requires_delivery_option - FROM Shop_Region DR - INNER JOIN Recursive_CTE_Delivery_Region r_DR - ON DR.id_region = r_DR.id_region_parent - OR DR.id_region = r_DR.id_region_child - ; - /* - select * from tmp_delivery_region; - SELECT * - FROM tmp_Shop_Product t_P - WHERE - *( - a_get_all_category - OR a_get_all_product - OR a_get_all_product_permutation - )* - FIND_IN_SET(t_P.id_category, a_ids_category) > 0 - OR FIND_IN_SET(t_P.id_product, a_ids_product) > 0 - OR FIND_IN_SET(t_P.id_permutation, a_ids_product_permutation) > 0 - ; - */ - - IF v_has_filter_delivery_region THEN - SET v_ids_permutation_unavailable = ( - SELECT GROUP_CONCAT(t_P.id_permutation SEPARATOR ', ') - FROM ( - SELECT * - FROM tmp_Shop_Product t_P - WHERE - /*( - a_get_all_category - OR a_get_all_produc - OR a_get_all_product_permutation - )*/ - FIND_IN_SET(t_P.id_category, a_ids_category) > 0 - OR FIND_IN_SET(t_P.id_product, a_ids_product) > 0 - OR FIND_IN_SET(t_P.id_permutation, a_ids_product_permutation) > 0 - ) t_P - LEFT JOIN ( - SELECT * - FROM Shop_Product_Currency_Region_Link PCRL - WHERE - ( - a_get_all_delivery_region - OR FIND_IN_SET(PCRL.id_region_purchase, a_ids_delivery_region) > 0 - ) - ) PCRL - ON t_P.id_product <=> PCRL.id_product - AND t_P.id_permutation <=> PCRL.id_permutation - LEFT JOIN tmp_Delivery_Region t_DR - ON PCRL.id_region_purchase = t_DR.id_region - AND t_DR.requires_delivery_option = 1 - WHERE - ISNULL(t_DR.id_region) - ); - IF NOT ISNULL(v_ids_permutation_unavailable) THEN - INSERT INTO tmp_Msg_Error ( - guid, - id_type, - code, - msg - ) - VALUES ( - v_guid, - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'PRODUCT_AVAILABILITY' LIMIT 1), - 'PRODUCT_AVAILABILITY', - CONCAT('Error: The following permutation IDs are not available in this region: ', IFNULL(v_ids_permutation_unavailable, 'NULL')) - ); - END IF; - /* - DELETE FROM tmp_Shop_Product t_P - WHERE t_P.id_permutation NOT IN ( - SELECT - id_permutation - FROM Shop_Product_Currency_Region_Link PCL - INNER JOIN tmp_Delivery_Region t_DR - ON PCRL.id_region_purchase = t_DR.id_region - ); - */ - END IF; - - -- select * from tmp_Shop_Product; - - -- Currencies - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid) THEN - INSERT INTO tmp_Currency ( - id_currency, - active, - display_order - ) - SELECT - C.id_currency, - C.active, - C.display_order - FROM Shop_Product_Currency_Region_Link PCRL - INNER JOIN Shop_Currency C ON PCRL.id_currency = C.id_currency - INNER JOIN tmp_Shop_Product t_P - ON PCRL.id_product <=> t_P.id_product - AND PCRL.id_permutation <=> t_P.id_permutation - INNER JOIN tmp_Delivery_Region t_DR ON PCRL.id_region_purchase = t_DR.id_region - WHERE - ( - a_get_all_currency - OR FIND_IN_SET(C.id_currency, a_ids_currency) > 0 - ) - AND ( - a_get_inactive_currency - OR ( - C.active - AND PCRL.active - ) - ) - ; - - -- select * from tmp_Currency; - - IF v_has_filter_currency THEN - SET v_ids_permutation_unavailable = ( - SELECT GROUP_CONCAT(t_P.id_permutation SEPARATOR ', ') - FROM ( - SELECT * - FROM tmp_Shop_Product t_P - WHERE - /*( - a_get_all_category - OR a_get_all_product - OR a_get_all_product_permutation - )*/ - FIND_IN_SET(t_P.id_category, a_ids_category) > 0 - OR FIND_IN_SET(t_P.id_product, a_ids_product) > 0 - OR FIND_IN_SET(t_P.id_permutation, a_ids_product_permutation) > 0 - ) t_P - INNER JOIN ( - SELECT * - FROM Shop_Product_Currency_Region_Link PCRL - WHERE - ( - a_get_all_currency - OR FIND_IN_SET(PCRL.id_currency, a_ids_currency) > 0 - ) - ) PCRL - ON t_P.id_permutation = PCRL.id_permutation - LEFT JOIN tmp_Currency t_C - ON PCRL.id_currency = t_C.id_currency - WHERE ISNULL(t_C.id_currency) - ); - IF NOT ISNULL(v_ids_permutation_unavailable) THEN - INSERT INTO tmp_Msg_Error ( - guid, - id_type, - code, - msg - ) - VALUES ( - v_guid, - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'PRODUCT_AVAILABILITY' LIMIT 1), - 'PRODUCT_AVAILABILITY', - CONCAT('Error: The following permutation IDs are not available in this currency: ', IFNULL(v_ids_permutation_unavailable, 'NULL')) - ); - END IF; - /* - DELETE FROM tmp_Shop_Product t_P - WHERE t_P.id_permutation NOT IN ( - SELECT - id_permutation - FROM Shop_Product_Currency_Region_Link PCL - INNER JOIN tmp_Currency t_C - ON PCRL.id_currency = t_C.id_currency - ); - */ - END IF; - END IF; - - -- Discounts - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid) THEN - INSERT INTO tmp_Discount ( - id_discount, - active, - display_order - ) - SELECT - D.id_discount, - D.active, - D.display_order - FROM Shop_Discount D - INNER JOIN tmp_Shop_Product t_P - ON D.id_product = t_P.id_product - AND D.id_permutation <=> t_P.id_permutation - WHERE - ( - a_get_all_discount - OR FIND_IN_SET(D.id_discount, a_ids_discount) > 0 - ) - AND ( - a_get_inactive_discount - OR D.active - ) - ; - END IF; - -- select 'pre-permission results'; - -- select * from tmp_Shop_Product; - - -- Permissions - IF EXISTS (SELECT * FROM tmp_Shop_Product_Category LIMIT 1) THEN - -- SET v_id_user := (SELECT id_user FROM Shop_User WHERE name = CURRENT_USER()); - SET v_id_permission_product := (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_PRODUCT' LIMIT 1); - SET v_ids_product_permission := (SELECT GROUP_CONCAT(id_product SEPARATOR ',') FROM tmp_Shop_Product WHERE NOT ISNULL(id_product)); - -- SET v_ids_permutation_permission := (SELECT GROUP_CONCAT(id_permutation SEPARATOR ',') FROM tmp_Shop_Product WHERE NOT ISNULL(id_permutation)); - - -- SELECT v_guid, a_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_product_permission; - -- select * from Shop_Calc_User_Temp; - - CALL p_shop_calc_user(v_guid, a_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_product_permission); - - -- select * from Shop_Calc_User_Temp; - - UPDATE tmp_Shop_Product t_P - INNER JOIN Shop_Calc_User_Temp UE_T - ON t_P.id_product = UE_T.id_product - AND UE_T.GUID = v_guid - SET t_P.can_view = UE_T.can_view, - t_P.can_edit = UE_T.can_edit, - t_P.can_admin = UE_T.can_admin - ; - -- select * from Shop_Calc_User_Temp; - -- select * from tmp_Shop_Product; - - DELETE t_P - FROM tmp_Shop_Product t_P - WHERE - FIND_IN_SET(t_P.id_product, (SELECT GROUP_CONCAT(UET.id_product SEPARATOR ',') FROM Shop_Calc_User_Temp UET)) = 0 -- id_product NOT LIKE CONCAT('%', (SELECT GROUP_CONCAT(id_product SEPARATOR '|') FROM Shop_Calc_User_Temp), '%'); - OR ( - ISNULL(t_P.can_view) - AND ( - NOT v_has_filter_category - OR FIND_IN_SET(t_P.id_category, a_ids_category) = 0 - ) - AND ( - NOT v_has_filter_product - OR FIND_IN_SET(t_P.id_product, a_ids_product) = 0 - ) - AND ( - NOT v_has_filter_product_permutation - OR FIND_IN_SET(t_P.id_permutation, a_ids_product_permutation) = 0 - ) - ) - ; - - CALL p_shop_clear_calc_user(v_guid); - -- DROP TABLE IF EXISTS Shop_Calc_User_Temp; - /* - DELETE FROM Shop_Calc_User_Temp UE_T - WHERE UE_T.GUID = v_guid - ; - */ - END IF; - - - -- select * from tmp_Shop_Product; - - -- Returns - -- SET v_now := NOW(); - - -- Categories - SELECT - DISTINCT t_C.id_category, - C.name, - C.description, - C.display_order - FROM tmp_Shop_Product_Category t_C - INNER JOIN Shop_Product_Category C - ON t_C.id_category = C.id_category - INNER JOIN tmp_Shop_Product t_P - ON t_C.id_category = t_P.id_category - ORDER BY C.display_order - ; - - -- Products - SELECT - t_P.id_product, - t_P.id_permutation, - t_P.name, - t_P.description, - P.has_variations, - P.id_category, - PP.cost_local, - PP.id_currency_cost, - CURRENCY.code AS code_currency_cost, - CURRENCY.symbol AS symbol_currency_cost, - PP.profit_local_min, - t_P.latency_manufacture, - t_P.quantity_min, - t_P.quantity_max, - t_P.quantity_step, - t_P.quantity_stock, - t_P.id_stripe_product, - t_P.is_subscription, - UM.name_singular AS name_interval_recurrence, - UM.name_plural AS name_plural_interval_recurrence, - PP.count_interval_recurrence, - t_P.display_order_category, - t_P.display_order_product, - t_P.display_order_permutation, - IFNULL(t_P.can_view, 0) AS can_view, - IFNULL(t_P.can_edit, 0) AS can_edit, - IFNULL(t_P.can_admin, 0) AS can_admin - FROM tmp_Shop_Product t_P - INNER JOIN Shop_Product P ON t_P.id_product = P.id_product - INNER JOIN Shop_Product_Permutation PP ON t_P.id_permutation = PP.id_permutation - -- LEFT JOIN Shop_Interval_Recurrence RI ON t_P.id_unit_measurement_interval_recurrence = RI.id_interval - LEFT JOIN Shop_Unit_Measurement UM ON PP.id_unit_measurement_interval_recurrence = UM.id_unit_measurement - INNER JOIN Shop_Currency CURRENCY ON PP.id_currency_cost = CURRENCY.id_currency - ORDER BY t_P.rank_permutation - ; - - -- Variations - SELECT - V.id_variation - , V.code AS code_variation - , V.name AS name_variation - , V.active AS active_variation - , V.display_order - , V.id_type - , VT.code AS code_variation_type - , VT.name AS name_variation_type - , VT.name_plural AS name_plural_variation_type - , VT.active AS active_variation_type - , VT.display_order - , t_P.id_product - , t_P.id_permutation - , t_P.id_category - FROM Shop_Variation V - INNER JOIN Shop_Variation_Type VT ON V.id_type = VT.id_type - INNER JOIN Shop_Product_Permutation_Variation_Link PPVL ON V.id_variation = PPVL.id_variation - INNER JOIN tmp_Shop_Product t_P ON PPVL.id_permutation <=> t_P.id_permutation - WHERE V.active - AND PPVL.active - ; - - /* - -- Permutation variations output - SELECT t_P.id_permutation, - t_P.id_product, - t_P.id_category, - id_variation - FROM Shop_Product_Permutation_Variation_Link PPVL - INNER JOIN tmp_Shop_Product t_P - ON t_P.id_permutation = PPVL.id_permutation - ORDER BY t_P.display_order - ; - */ - -- select * from Shop_Product_Currency_Region_Link; - -- select * from shop_currency; - /* - select * from tmp_Currency; - select * from tmp_delivery_region; - select * from tmp_shop_product; - */ - - -- Product Price - SELECT - PCRL.id_link AS id_price, - t_P.id_permutation, - t_P.id_product, - t_P.id_category, - t_C.id_currency, - C.code AS code_currency, - C.name AS name_currency, - C.symbol AS symbol_currency, - t_DR.id_region, - PCRL.price_local_VAT_incl, - PCRL.price_local_VAT_excl, - ROW_NUMBER() OVER(ORDER BY t_P.rank_permutation, C.display_order) AS display_order - FROM Shop_Product_Currency_Region_Link PCRL - INNER JOIN tmp_Shop_Product t_P - ON PCRL.id_product <=> t_P.id_product - AND PCRL.id_permutation <=> t_P.id_permutation - -- INNER JOIN Shop_Product P ON PCRL.id_product = P.id_product - INNER JOIN tmp_Currency t_C ON PCRL.id_currency = t_C.id_currency - INNER JOIN Shop_Currency C ON t_C.id_currency = C.id_currency - INNER JOIN tmp_Delivery_Region t_DR ON PCRL.id_region_purchase = t_DR.id_region - WHERE ( - a_get_inactive_product - AND a_get_inactive_product_permutation - AND a_get_inactive_currency - AND a_get_inactive_delivery_region - OR PCRL.active - ) - ORDER BY t_P.rank_permutation - ; - - /* - -- Currency - SELECT - DISTINCT C.id_currency, - C.code, - C.name, - C.factor_from_GBP, - t_C.display_order - FROM Shop_Currency C - INNER JOIN tmp_Currency t_C ON C.id_currency = t_C.id_currency - GROUP BY C.id_currency, t_C.display_order - ORDER BY t_C.display_order - ; - */ - - -- Images - SELECT - t_I.id_image, - t_I.id_product, - t_I.id_permutation, - t_P.id_category, - I.url, - I.active, - I.display_order - FROM tmp_Shop_Image t_I - INNER JOIN Shop_Product_Image I - ON t_I.id_image = I.id_image - INNER JOIN tmp_Shop_Product t_P - ON t_I.id_product = t_P.id_product - AND t_I.id_permutation <=> t_P.id_permutation - ORDER BY t_P.rank_permutation, I.display_order - ; - - -- Delivery options - SELECT - _DO.id_option, - PDOL.id_product, - PDOL.id_permutation, - t_P.id_category, - _DO.code, - _DO.name, - _DO.latency_delivery_min, - _DO.latency_delivery_max, - _DO.quantity_min, - _DO.quantity_max, - GROUP_CONCAT(DR.code SEPARATOR ',') AS codes_region, - GROUP_CONCAT(DR.name SEPARATOR ',') AS names_region, - PDOL.price_local, - PDOL.display_order - FROM Shop_Delivery_Option _DO - INNER JOIN Shop_Product_Permutation_Delivery_Option_Link PDOL - ON _DO.id_option = PDOL.id_delivery_option - AND ( - a_get_inactive_delivery_region - OR PDOL.active - ) - INNER JOIN tmp_Shop_Product t_P - ON PDOL.id_product = t_P.id_product - AND PDOL.id_permutation <=> t_P.id_permutation - INNER JOIN tmp_Delivery_Region t_DR ON PDOL.id_region = t_DR.id_region - INNER JOIN Shop_Region DR ON t_DR.id_region = DR.id_region - WHERE ( - a_get_inactive_delivery_region - OR _DO.active - ) - GROUP BY t_P.id_category, t_P.id_product, PDOL.id_permutation, t_P.rank_permutation, DR.id_region, _DO.id_option, PDOL.id_link - ORDER BY t_P.rank_permutation, PDOL.display_order - ; - - -- Discounts - SELECT - D.id_discount, - P.id_category, - D.id_product, - D.id_permutation, - DR.id_region, - C.id_currency, - D.code AS code_discount, - D.name AS name_discount, - D.multiplier, - D.subtractor, - D.apply_multiplier_first, - D.quantity_min, - D.quantity_max, - D.date_start, - D.date_end, - GROUP_CONCAT(DR.code) AS codes_region, - GROUP_CONCAT(DR.name) AS names_region, - GROUP_CONCAT(C.code) AS codes_currency, - GROUP_CONCAT(C.name) AS names_currency, - ROW_NUMBER() OVER(ORDER BY D.display_order) AS display_order - FROM tmp_Discount t_D - INNER JOIN Shop_Discount D ON t_D.id_discount = D.id_discount - INNER JOIN Shop_Product P ON D.id_product = P.id_product - INNER JOIN tmp_Shop_Product t_P - ON D.id_product = t_P.id_product - -- AND D.id_permutation <=> t_P.id_permutation - INNER JOIN Shop_Discount_Region_Currency_Link DRCL - ON D.id_discount = DRCL.id_discount - INNER JOIN tmp_Delivery_Region t_DR ON DRCL.id_region = t_DR.id_region - INNER JOIN Shop_Region DR ON t_DR.id_region = DR.id_region - INNER JOIN tmp_Currency t_C ON DRCL.id_currency = t_C.id_currency - INNER JOIN Shop_Currency C ON t_C.id_currency = C.id_currency - GROUP BY D.id_discount, DR.id_region, C.id_currency - ORDER BY D.display_order, DR.display_order, C.display_order - ; - - /* - -- Delivery Regions - SELECT - t_DR.id_region, - t_P.id_category, - t_P.id_product, - t_P.id_permutation, - DR.code, - DR.name - FROM tmp_Delivery_Region t_DR - INNER JOIN Shop_Delivery_Region DR ON t_DR.id_region = DR.id_region - INNER JOIN Shop_Product_Region_Currency_Link PDRL - ON DR.id_region = PDRL.id_region - AND ( - a_get_inactive_delivery_region - OR PDRL.active - ) - INNER JOIN tmp_Shop_Product t_P - ON PDRL.id_product = t_P.id_product - AND PDRL.id_permutation <=> t_P.id_permutation - INNER JOIN tmp_Currency t_C ON PDRL.id_currency = t_C.id_currency - ORDER BY t_DR.display_order - ; - */ - - -- Errors - SELECT - * - FROM tmp_Msg_Error t_ME - INNER JOIN Shop_Msg_Error_Type MET ON t_ME.id_type = MET.id_type - -- WHERE guid = v_guid - ; - - - -- Clean up - DROP TEMPORARY TABLE IF EXISTS tmp_Discount; - DROP TEMPORARY TABLE IF EXISTS tmp_Currency; - DROP TEMPORARY TABLE IF EXISTS tmp_Delivery_Region; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Image; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Variation; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Product; - DROP TEMPORARY TABLE IF EXISTS tmp_Product; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Product_2; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Product_Category; - DROP TEMPORARY TABLE IF EXISTS tmp_Category; - DROP TEMPORARY TABLE IF EXISTS tmp_Permutation; - DROP TEMPORARY TABLE IF EXISTS tmp_Product; - - - CALL partsltd_prod.p_shop_clear_calc_product_permutation ( v_guid ); - - IF a_debug = 1 THEN - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); - END IF; -END // -DELIMITER ; - - -/* - -CALL partsltd_prod.p_shop_get_many_product_price_and_discount_and_delivery_option ( - IN a_id_user INT, - IN a_get_all_product_permutation BIT, - IN a_get_inactive_product_permutation BIT, - IN a_ids_product_permutation VARCHAR(4000), - IN a_get_all_delivery_region BIT, - IN a_get_inactive_delivery_region BIT, - IN a_ids_delivery_region VARCHAR(4000), - IN a_get_all_currency BIT, - IN a_get_inactive_currency BIT, - IN a_ids_currency VARCHAR(4000), - IN a_get_all_discount BIT, - IN a_get_inactive_discount BIT, - IN a_ids_discount VARCHAR(4000) -); - -select * FROM Shop_Calc_User_Temp; - -select * from Shop_Product_Permutation; -select * from shop_product_change_set; -insert into shop_product_change_set ( comment ) values ('set stock quantities below minimum for testing'); -update shop_product_permutation -set quantity_stock = 0, - id_change_set = (select id_change_set from shop_product_change_set order by id_change_set desc limit 1) -where id_permutation < 5 - -DROP TABLE IF EXISTS tmp_Msg_Error; - -select * from shop_image; -select * from shop_product; -select * from TMP_MSG_ERROR; -DROP TABLE TMP_MSG_ERROR; - -insert into shop_product_change_set (comment) - values ('set product not subscription - test bool output to python'); - update shop_product - set is_subscription = 0, - id_change_set = (select id_change_set from shop_product_change_set order by id_change_set desc limit 1) - where id_product = 1 - -select * FROM Shop_Calc_User_Temp; -select distinct guid --- DELETE -FROM Shop_Calc_User_Temp; -*/ diff --git a/static/MySQL/7223_p_shop_get_many_stripe_price_new.sql b/static/MySQL/7223_p_shop_get_many_stripe_price_new.sql deleted file mode 100644 index c73efdfd..00000000 --- a/static/MySQL/7223_p_shop_get_many_stripe_price_new.sql +++ /dev/null @@ -1,243 +0,0 @@ - - - -/* - -CALL p_shop_get_many_stripe_price_new ( - '' -) - -*/ - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_get_many_stripe_price_new; - - -DELIMITER // -CREATE PROCEDURE p_shop_get_many_stripe_price_new ( - IN a_id_user INT -) -BEGIN - DECLARE v_has_filter_user BIT; - DECLARE v_code_error_data VARCHAR(200); - DECLARE v_code_error_permission VARCHAR(200); - DECLARE v_guid BINARY(36); - - SET v_code_error_data := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 1); - SET v_code_error_permission := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 2); - SET v_guid = UUID(); - - - - IF a_id_user IS NULL THEN - SET a_id_user = ''; - ELSE - SET a_id_user = TRIM(a_id_user); - END IF; - - - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Shop_Product_Currency_Link; - DROP TABLE IF EXISTS tmp_Shop_User; - - CREATE TABLE tmp_Shop_User( - id_user INT NOT NULL PRIMARY KEY, - CONSTRAINT FK_tmp_Shop_User_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user), - active BIT NOT NULL - ); - - CREATE TABLE tmp_Shop_Product_Currency_Link ( - id_link INT NOT NULL PRIMARY KEY, - CONSTRAINT FK_tmp_Shop_Product_Currency_Link_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Product_Currency_Link(id_link), - id_product INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_Currency_Link_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - id_permutation INT NULL, - CONSTRAINT FK_tmp_Shop_Product_Currency_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - id_currency INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_Currency_Link_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency), - active BIT NOT NULL - ); - - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( -- IF NOT EXISTS - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - guid BINARY(36) NOT NULL, - code VARCHAR(50) NOT NULL, - -- CONSTRAINT chk_tmp_Msg_Error_code CHECK (code IN (SELECT code FROM Shop_Msg_Error_Type)), - /* - id_type INT NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type(id_type), - */ - msg VARCHAR(4000) NOT NULL - ); - - - - -- Parse filters - SET v_has_filter_user = CASE WHEN a_id_user = '' THEN 0 ELSE 1 END; - - - - -- User permissions - IF v_has_filter_user THEN - INSERT INTO tmp_Shop_User ( - id_user, - active - ) - SELECT id_user, - active - FROM Shop_User - WHERE id_user LIKE CONCAT('%', a_id_user, '%') - AND active - LIMIT 1 - ; - - SET v_has_filter_user = EXISTS (SELECT id_user FROM tmp_Shop_User LIMIT 1); - SET a_id_user := (SELECT id_user FROM tmp_Shop_User LIMIT 1); - END IF; - IF NOT v_has_filter_user THEN - INSERT INTO tmp_Msg_Error ( - guid, - code, - msg - ) - VALUES ( - v_guid, - v_code_error_data, - 'Valid user ID not provided.' - ) - ; - END IF; - - -- Get products - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - INSERT INTO tmp_Shop_Product_Currency_Link ( - id_link, - id_product, - id_permutation, - id_currency, - active - ) - SELECT id_link, - id_product, - id_permutation, - id_currency, - active - FROM Shop_Product_Currency_Link - WHERE ISNULL(id_stripe_price) - AND active - ; - END IF; - - -- Permissions - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - -- SELECT * FROM tmp_Msg_Error LIMIT 1; - CALL p_shop_calc_user ( - v_guid, -- a_guid - a_id_user, -- a_id_user - 0, -- a_get_inactive_users - CONVERT((SELECT id_permission FROM Shop_Permission WHERE 'STORE_ADMIN' = code), CHAR), -- a_ids_permission - (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'ADMIN' AND active), -- a_ids_access_level - (SELECT GROUP_CONCAT(DISTINCT id_product SEPARATOR ',') FROM tmp_Shop_Product_Currency_Link), -- (SELECT DISTINCT id_product FROM tmp_Shop_Product_Currency_Link) calc_PCL) -- a_ids_product - (SELECT GROUP_CONCAT(DISTINCT id_permutation SEPARATOR ',') FROM tmp_Shop_Product_Currency_Link) -- a_ids_permutation - ); - -- SELECT * FROM tmp_Msg_Error LIMIT 1; - - IF EXISTS (SELECT can_admin FROM Shop_Calc_User_Temp WHERE guid = v_guid AND NOT can_admin LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - guid, - code, - msg - ) - VALUES ( - v_guid, - v_code_error_permission, - 'User ID does not have permission to get all new stripe prices.' - ) - ; - END IF; - - DELETE FROM Shop_Calc_User_Temp - WHERE guid = v_guid - ; - END IF; - - - - -- Returns - IF EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - DELETE FROM tmp_Shop_Product_Currency_Link; - END IF; - /* - SELECT * - FROM tmp_Shop_User - ; - */ - - - SELECT t_PCL.id_product, - t_PCL.id_permutation, - P.price_GBP_full * C.factor_from_GBP AS unit_price, - C.code AS code_currency, - P.id_stripe_product, - P.is_subscription, - LOWER(RI.code) AS name_recurring_interval, - P.count_interval_recurrence - FROM tmp_Shop_Product_Currency_Link t_PCL - INNER JOIN Shop_Product P - ON t_PCL.id_product = P.id_product - AND P.active - INNER JOIN Shop_Interval_Recurrence RI - ON P.id_unit_measurement_interval_recurrence = RI.id_interval - AND RI.active - INNER JOIN Shop_Currency C - ON t_PCL.id_currency = C.id_currency - AND C.active - WHERE t_PCL.active - ; - - - -- Errors - SELECT * - FROM tmp_Msg_Error - WHERE guid = v_guid - ; - - - /* - -- Return arguments for test - SELECT - a_id_user - ; - */ - - -- Clean up - DROP TABLE IF EXISTS tmp_Shop_User; - DROP TABLE IF EXISTS tmp_Shop_Product_Currency_Link; -END // -DELIMITER ; - - -/* -CALL p_shop_get_many_stripe_price_new ( - '' -); - -CALL p_shop_get_many_stripe_price_new ( - 'auth0|6582b95c895d09a70ba10fef' -); - -*/ diff --git a/static/MySQL/7312_p_shop_save_user.sql b/static/MySQL/7312_p_shop_save_user.sql deleted file mode 100644 index 223a6472..00000000 --- a/static/MySQL/7312_p_shop_save_user.sql +++ /dev/null @@ -1,279 +0,0 @@ - - -DROP PROCEDURE IF EXISTS p_shop_save_user; - - -DELIMITER // -CREATE PROCEDURE p_shop_save_user ( - IN a_comment VARCHAR(500), - IN a_guid BINARY(36), - IN a_id_user INT, - IN a_debug BIT -) -BEGIN - DECLARE v_code_type_error_bad_data VARCHAR(100); - DECLARE v_id_type_error_bad_data INT; - DECLARE v_id_permission_product INT; - DECLARE v_id_permission_user_admin LONGTEXT; - DECLARE v_id_change_set INT; - DECLARE v_id_access_level_edit INT; - DECLARE v_can_admin_user BIT; - DECLARE v_time_start TIMESTAMP(6); - - DECLARE exit handler for SQLEXCEPTION - BEGIN - GET DIAGNOSTICS CONDITION 1 - @sqlstate = RETURNED_SQLSTATE - , @errno = MYSQL_ERRNO - , @text = MESSAGE_TEXT - ; - - ROLLBACK; - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT - , id_type INT NULL - , code VARCHAR(50) NOT NULL - , msg VARCHAR(4000) NOT NULL - ); - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - MET.id_type - , @errno - , @text - FROM partsltd_prod.Shop_Msg_Error_Type MET - WHERE MET.code = 'MYSQL_ERROR' - ; - SELECT * - FROM tmp_Msg_Error; - DROP TABLE IF EXISTS tmp_Msg_Error; - END; - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_code_type_error_bad_data := 'BAD_DATA'; - SET v_id_type_error_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_type_error_bad_data LIMIT 1); - SET v_id_access_level_edit := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'EDIT' LIMIT 1); - SET v_id_permission_user_admin := (SELECT GROUP_CONCAT(id_permission SEPARATOR ',') FROM Shop_Permission WHERE code = 'STORE_USER_ADMIN' LIMIT 1); - CALL p_validate_guid ( a_guid ); - - DROP TABLE IF EXISTS tmp_Msg_Error; - DROP TABLE IF EXISTS tmp_User; - - CREATE TABLE tmp_User ( - id_user INT NOT NULL - , id_user_auth0 VARCHAR(200) NOT NULL - , firstname VARCHAR(255) - , surname VARCHAR(255) - , email VARCHAR(254) - , is_email_verified BIT NOT NULL - , is_super_user BIT NOT NULL - , id_currency_default INT - , id_region_default INT - , is_included_VAT_default BIT - , active BIT NOT NULL - , name_error VARCHAR(1000) - ); - - CREATE TABLE tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - id_type INT NOT NULL, - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - - -- Get data from Temp table - INSERT INTO tmp_User ( - id_user - , id_user_auth0 - , firstname - , surname - , email - , is_email_verified - , is_super_user - , id_currency_default - , id_region_default - , is_included_VAT_default - , active - ) - SELECT - U_T.id_user - , U_T.id_user_auth0 - , IFNULL(U_T.firstname, U.firstname) AS firstname - , IFNULL(U_T.surname, U.surname) AS surname - , IFNULL(U_T.email, U.email) AS email - , IFNULL(U_T.is_email_verified, U.is_email_verified) AS is_email_verified - , IFNULL(U_T.is_super_user, U.is_super_user) AS is_super_user - , IFNULL(U_T.id_currency_default, U.id_currency_default) AS id_currency_default - , IFNULL(U_T.id_region_default, U.id_region_default) AS id_region_default - , IFNULL(U_T.is_included_VAT_default, U.is_included_VAT_default) AS is_included_VAT_default - , IFNULL(IFNULL(U_T.active, U.active), 1) AS active - , IFNULL(U_T.display_order, PC.display_order) AS display_order - FROM partsltd_prod.Shop_User_Temp U_T - LEFT JOIN Shop_User U ON U_T.id_user = U.id_user - WHERE U_T.guid = a_guid - ; - - UPDATE tmp_User t_U - SET - t_U.name_error = IFNULL(t_U.email, t_U.id_user_auth0) - ; - - -- Validation - -- Missing mandatory fields - -- email - IF EXISTS (SELECT * FROM tmp_User t_U WHERE ISNULL(t_U.email) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following User(s) do not have an email: ', GROUP_CONCAT(t_U.name_error SEPARATOR ', ')) AS msg - FROM tmp_User t_U - WHERE ISNULL(t_U.email) - ; - END IF; - -- is_super_user - IF EXISTS (SELECT * FROM tmp_User t_U WHERE ISNULL(t_U.is_super_user) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following User(s) do not have an is super user field: ', GROUP_CONCAT(t_U.name_error SEPARATOR ', ')) AS msg - FROM tmp_User t_U - WHERE ISNULL(t_U.is_super_user) - ; - END IF; - -- is_email_verified - IF EXISTS (SELECT * FROM tmp_User t_U WHERE ISNULL(t_U.is_email_verified) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following User(s) do not have an is email verified: ', GROUP_CONCAT(t_U.name_error SEPARATOR ', ')) AS msg - FROM tmp_User t_U - WHERE ISNULL(t_U.is_email_verified) - ; - END IF; - - - -- Permissions - IF a_debug = 1 THEN - SELECT - a_guid -- GUID - , a_id_user -- ID User - , FALSE -- get inactive Users - , v_id_permission_user_admin -- IDs Permission - , v_id_access_level_edit -- ID Access Level - , NULL -- IDs Product - ; - END IF; - - CALL p_shop_calc_user( - a_guid -- GUID - , a_id_user -- ID User - , FALSE -- get inactive Users - , v_id_permission_user_admin -- IDs Permission - , v_id_access_level_edit -- ID Access Level - , NULL -- IDs Product - ); - - SET v_can_admin_user := ( - SELECT IFNULL(UE_T.can_edit, 0) = 1 - FROM partsltd_prod.Shop_User_Eval_Temp UE_T - WHERE - UE_T.GUID = a_guid - AND UE_T.id_user = a_id_user - AND UE_T.id_permission = v_id_permission_user_admin - ); - - IF (v_can_admin_user = 0 AND EXISTS ( - SELECT * - FROM tmp_User t_U - WHERE - t_U.id_user <> a_id_user - )) THEN - DELETE FROM tmp_Msg_Error; - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - VALUES ( - v_id_type_error_no_permission - , v_code_type_error_no_permission - , 'You do not have permission to edit other Users.' - ) - ; - END IF; - - CALL p_shop_clear_calc_user(a_guid); - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - START TRANSACTION; - - INSERT INTO Shop_User_Change_Set ( comment ) - VALUES ( a_comment ) - ; - - SET v_id_change_set := LAST_INSERT_ID(); - - UPDATE Shop_User U - INNER JOIN tmp_User t_U ON U.id_user = t_U.id_user - SET - U.id_user_auth0 = t_U.id_user_auth0 - , U.firstname = t_U.firstname - , U.surname = t_U.surname - , U.email = t_U.email - , U.is_email_verified = t_U.is_email_verified - , U.is_super_user = t_U.is_super_user - , U.id_currency_default = t_U.id_currency_default - , U.id_region_default = t_U.id_region_default - , U.is_included_VAT_default = t_U.is_included_VAT_default - , U.active = t_U.active - , U.id_change_set = v_id_change_set - ; - - COMMIT; - END IF; - - START TRANSACTION; - - DELETE FROM Shop_User_Temp - WHERE GUID = a_guid; - - COMMIT; - - -- Errors - SELECT * - FROM tmp_Msg_Error t_ME - INNER JOIN partsltd_prod.Shop_Msg_Error_Type MET ON t_ME.id_type = MET.id_type - ; - - IF a_debug = 1 THEN - SELECT * from tmp_User; - END IF; - - DROP TABLE IF EXISTS tmp_Msg_Error; - DROP TABLE IF EXISTS tmp_User; - - IF a_debug = 1 THEN - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); - END IF; -END // -DELIMITER ; - diff --git a/static/MySQL/7313_p_get_many_user.sql b/static/MySQL/7313_p_get_many_user.sql deleted file mode 100644 index 6c20d153..00000000 --- a/static/MySQL/7313_p_get_many_user.sql +++ /dev/null @@ -1,538 +0,0 @@ - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_get_many_user; - - -DELIMITER // -CREATE PROCEDURE p_get_many_user ( - IN a_id_user INT - , IN a_id_user_auth0 VARCHAR(200) - , IN a_get_all_user BIT - , IN a_get_inactive_user BIT - , IN a_ids_user LONGTEXT - , IN a_ids_user_auth0 LONGTEXT - , IN a_debug BIT -) -BEGIN - DECLARE v_id_access_level_admin INT; - DECLARE v_id_access_level_view INT; - DECLARE v_id_permission_store_admin INT; - DECLARE v_id_permission_user INT; - DECLARE v_id_permission_user_admin INT; - DECLARE v_ids_permission_required VARCHAR(4000); - DECLARE v_id_minimum INT; - DECLARE v_code_error_bad_data VARCHAR(50); - DECLARE v_id_type_error_bad_data INT; - DECLARE v_has_filter_user BIT; - DECLARE v_has_filter_user_auth0 BIT; - DECLARE v_guid BINARY(36); - DECLARE v_rank_max INT; - DECLARE v_time_start TIMESTAMP(6); - DECLARE v_is_new BIT; - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_guid := UUID(); - SET v_id_access_level_admin := (SELECT id_access_level FROM partsltd_prod.Shop_Access_Level WHERE code = 'ADMIN' LIMIT 1); - SET v_id_access_level_view := (SELECT id_access_level FROM partsltd_prod.Shop_Access_Level WHERE code = 'VIEW' LIMIT 1); - SET v_id_permission_store_admin := (SELECT id_permission FROM partsltd_prod.Shop_Permission WHERE code = 'STORE_ADMIN' LIMIT 1); - SET v_id_permission_user := (SELECT id_permission FROM partsltd_prod.Shop_Permission WHERE code = 'STORE_USER' LIMIT 1); - SET v_id_permission_user_admin := (SELECT id_permission FROM partsltd_prod.Shop_Permission WHERE code = 'STORE_USER_ADMIN' LIMIT 1); - SET v_code_error_bad_data := (SELECT code FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1); - SET v_id_type_error_bad_data := (SELECT id_type FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = v_code_error_bad_data LIMIT 1); - SET v_ids_permission_required := CONCAT(v_id_permission_user, ',', v_id_permission_user_admin, ',', v_id_permission_store_admin); - SET v_is_new := FALSE; - - SET a_get_all_user := IFNULL(a_get_all_user, 1); - SET a_get_inactive_user := IFNULL(a_get_inactive_user, 0); - -- SET a_get_first_user_only := IFNULL(a_get_first_user_only, 0); - SET a_ids_user := TRIM(IFNULL(a_ids_user, '')); - SET a_ids_user_auth0 := TRIM(IFNULL(a_ids_user_auth0, '')); - SET a_debug := IFNULL(a_debug, 0); - - IF a_debug = 1 THEN - SELECT - a_id_user - , a_id_user_auth0 - , a_get_all_user - , a_get_inactive_user - -- , a_get_first_user_only - , a_ids_user - , a_ids_user_auth0 - , a_debug - ; - END IF; - - DROP TEMPORARY TABLE IF EXISTS tmp_User; - DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error; - - CREATE TEMPORARY TABLE tmp_User ( - id_user INT NULL - , rank_user INT NULL - , can_admin_store BIT NULL - , can_admin_user BIT NULL - ); - - CREATE TEMPORARY TABLE tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - -- guid BINARY(36) NOT NULL, - id_type INT NOT NULL, - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Split ( - substring VARCHAR(4000) NOT NULL - , as_int INT NULL - ); - - IF ISNULL(a_id_user) AND NOT ISNULL(a_id_user_auth0) THEN - SET a_id_user := (SELECT U.id_user FROM partsltd_prod.Shop_User U WHERE U.id_user_auth0 = a_id_user_auth0 LIMIT 1); -- LIKE CONCAT('%', a_id_user_auth0, '%') LIMIT 1); - END IF; - - IF ISNULL(a_id_user) THEN - IF NOT ISNULL(a_id_user_auth0) THEN - INSERT INTO partsltd_prod.Shop_User ( - id_user_auth0 - , is_super_user - , active - ) - VALUES ( - a_id_user_auth0 - , 0 -- is_super_user - , 1 -- active - ) - ; - SET a_id_user := (SELECT U.id_user FROM partsltd_prod.Shop_User U WHERE U.id_user_auth0 = a_id_user_auth0 LIMIT 1); - SET v_is_new := TRUE; - ELSE - INSERT INTO tmp_Msg_Error ( - id_type, - code, - msg - ) - VALUES ( - v_id_type_error_bad_data, - v_code_error_bad_data, - CONCAT('User ID required for authorisation.') - ) - ; - END IF; - END IF; - - SET v_has_filter_user := CASE WHEN a_ids_user = '' THEN 0 ELSE 1 END; - SET v_has_filter_user_auth0 := CASE WHEN a_ids_user_auth0 = '' THEN 0 ELSE 1 END; - - IF a_debug = 1 THEN - SELECT - v_has_filter_user - , v_has_filter_user_auth0 - ; - END IF; - - -- User IDs - IF (NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) AND v_has_filter_user = 1) THEN - CALL partsltd_prod.p_split(v_guid, a_ids_user, ',', FALSE); - - DELETE FROM tmp_Split; - - INSERT INTO tmp_Split ( - substring - , as_int - ) - SELECT - substring - , CONVERT(substring, DECIMAL(10,0)) AS as_int - FROM partsltd_prod.Split_Temp - WHERE 1=1 - AND GUID = v_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( v_guid ); - END IF; - - IF (NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) AND v_has_filter_user = 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_User U ON t_S.as_int = U.id_user - WHERE - ISNULL(t_S.as_int) - OR ISNULL(U.id_user) - ) THEN - INSERT INTO tmp_Msg_Error ( - -- guid, - id_type, - code, - msg - ) - SELECT - -- v_guid, - v_id_type_error_bad_data, - v_code_error_bad_data, - CONCAT('Invalid or inactive User IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_User U ON t_S.as_int = U.id_user - WHERE - ISNULL(t_S.as_int) - OR ISNULL(U.id_user) - ; - ELSE - INSERT INTO tmp_User ( - id_user - , rank_user - ) - SELECT - U.id_user - , RANK() OVER (ORDER BY U.id_user DESC) AS rank_user - FROM tmp_Split t_S - RIGHT JOIN partsltd_prod.Shop_User U ON t_S.as_int = U.id_user - WHERE - ( - a_get_all_user = 1 - OR ( - v_has_filter_user = 1 - AND NOT ISNULL(t_S.as_int) - ) - ) - AND ( - a_get_inactive_user = 1 - OR U.active = 1 - ) - ; - END IF; - END IF; - - -- Auth0 User IDs - IF (NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) AND v_has_filter_user_auth0 = 1) THEN - CALL partsltd_prod.p_split(v_guid, a_ids_user_auth0, ',', FALSE); - - DELETE FROM tmp_Split; - - INSERT INTO tmp_Split ( - substring - ) - SELECT - substring - FROM partsltd_prod.Split_Temp - WHERE 1=1 - AND GUID = v_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( v_guid ); - END IF; - - IF (NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) AND v_has_filter_user_auth0 = 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_User U ON t_S.substring = U.id_user_auth0 - WHERE - ISNULL(t_S.substring) - OR ISNULL(U.id_user_auth0) - ) THEN - INSERT INTO tmp_Msg_Error ( - -- guid, - id_type, - code, - msg - ) - SELECT - -- v_guid, - v_id_type_error_bad_data, - v_code_error_bad_data, - CONCAT('Invalid or inactive Auth0 User IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_User U ON t_S.substring = U.id_user_auth0 - WHERE - ISNULL(t_S.substring) - OR ISNULL(U.id_user_auth0) - ; - ELSE - SET v_rank_max := IFNULL((SELECT rank_user FROM tmp_User ORDER BY rank_user DESC LIMIT 1), 0); - - INSERT INTO tmp_User ( - id_user - , rank_user - ) - SELECT - U.id_user - , v_rank_max + (RANK() OVER (ORDER BY U.id_user DESC)) AS rank_user - FROM tmp_Split t_S - RIGHT JOIN partsltd_prod.Shop_User U ON t_S.substring = U.id_user_auth0 - WHERE - ( - a_get_all_user = 1 - OR ( - v_has_filter_user_auth0 = 1 - AND NOT ISNULL(t_S.substring) - ) - ) - AND ( - a_get_inactive_user = 1 - OR U.active = 1 - ) - ; - END IF; - END IF; - - IF a_debug = 1 THEN - SELECT * FROM tmp_User; - END IF; - - /* - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF a_get_first_user_only THEN - DELETE t_U - FROM tmp_User t_U - WHERE t_U.rank_user > 1 - ; - END IF; - END IF; - */ - - IF a_debug = 1 THEN - SELECT * FROM tmp_User; - END IF; - - -- Can admin store - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF a_debug = 1 THEN - SELECT - v_guid -- guid - , a_id_user -- ids_user - , FALSE -- get_inactive_user - , v_id_permission_store_admin -- ids_permission - , v_id_access_level_admin -- ids_access_level - , '' -- ids_product - , 0 -- a_debug - ; - SELECT * FROM partsltd_prod.Shop_Calc_User_Temp; - END IF; - - CALL partsltd_prod.p_shop_calc_user( - v_guid -- guid - , a_id_user -- ids_user - , FALSE -- get_inactive_user - , v_id_permission_store_admin -- ids_permission - , v_id_access_level_admin -- ids_access_level - , '' -- ids_product - , 0 -- a_debug - ); - - IF a_debug = 1 THEN - SELECT * FROM partsltd_prod.Shop_Calc_User_Temp WHERE GUID = v_guid; - END IF; - - UPDATE tmp_User t_U - INNER JOIN partsltd_prod.Shop_Calc_User_Temp CUT - ON CUT.GUID = v_guid - AND t_U.id_user = CUT.id_user - SET t_U.can_admin_store = CUT.can_admin - ; - - CALL partsltd_prod.p_shop_clear_calc_user( v_guid, FALSE ); - END IF; - - -- Can admin user - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF a_debug = 1 THEN - SELECT - v_guid -- guid - , a_id_user -- ids_user - , FALSE -- get_inactive_user - , v_id_permission_user_admin -- ids_permission - , v_id_access_level_admin -- ids_access_level - , '' -- ids_product - , 0 -- a_debug - ; - SELECT * FROM partsltd_prod.Shop_Calc_User_Temp; - END IF; - - CALL partsltd_prod.p_shop_calc_user( - v_guid -- guid - , a_id_user -- ids_user - , FALSE -- get_inactive_user - , v_id_permission_user_admin -- ids_permission - , v_id_access_level_admin -- ids_access_level - , '' -- ids_product - , 0 -- a_debug - ); - - IF a_debug = 1 THEN - SELECT * FROM partsltd_prod.Shop_Calc_User_Temp WHERE GUID = v_guid; - END IF; - - UPDATE tmp_User t_U - INNER JOIN partsltd_prod.Shop_Calc_User_Temp CUT - ON CUT.GUID = v_guid - AND t_U.id_user = CUT.id_user - SET t_U.can_admin_user = CUT.can_admin - ; - - CALL partsltd_prod.p_shop_clear_calc_user( v_guid, FALSE ); - END IF; - - -- Permissions - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF a_debug = 1 THEN - SELECT - v_guid -- guid - , a_id_user -- ids_user - , FALSE -- get_inactive_user - , v_ids_permission_required -- ids_permission - , v_id_access_level_view -- ids_access_level - , '' -- ids_product - , 0 -- a_debug - ; - SELECT * FROM partsltd_prod.Shop_Calc_User_Temp; - END IF; - - CALL partsltd_prod.p_shop_calc_user( - v_guid -- guid - , a_id_user -- ids_user - , FALSE -- get_inactive_user - , v_ids_permission_required -- ids_permission - , v_id_access_level_view -- ids_access_level - , '' -- ids_product - , 0 -- a_debug - ); - - IF a_debug = 1 THEN - SELECT * FROM partsltd_prod.Shop_Calc_User_Temp WHERE GUID = v_guid; - END IF; - - IF NOT EXISTS ( - SELECT can_view - FROM partsltd_prod.Shop_Calc_User_Temp CUT - WHERE 1=1 - AND CUT.GUID = v_guid - AND can_view = 1 - -- AND FIND_IN_SET(v_ids_permission_required, CUT.id_permission_required) > 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - code, - msg - ) - VALUES ( - v_id_type_error_bad_data, - v_code_error_bad_data, - -- CONCAT('You do not have view permissions for ', (SELECT name FROM partsltd_prod.Shop_Permission WHERE id_permission = v_id_permission_user LIMIT 1)) - -- CONCAT('You do not have view permissions for ', (SELECT GROUP_CONCAT(name SEPARATOR ', ') FROM partsltd_prod.Shop_Permission WHERE FIND_IN_SET(v_id_permission_user, id_permission) > 0)) - CONCAT('You do not have view permissions for ', (SELECT name FROM partsltd_prod.Shop_Permission P INNER JOIN partsltd_prod.Shop_Calc_User_Temp CUT ON P.id_permission = CUT.id_permission_required WHERE GUID = v_guid AND IFNULL(can_view, 0) = 0 LIMIT 1)) -- WHERE IFNULL(CUT.can_view, 0) = 0 - ) - ; - ELSE - -- INSERT INTO - SET a_debug := a_debug; - END IF; - - CALL partsltd_prod.p_shop_clear_calc_user( v_guid, FALSE ); - END IF; - - - -- Returns - /* NULL record required for flask sql_alchemy to detect result set */ - IF EXISTS (SELECT * FROM tmp_Msg_Error) THEN - DELETE FROM tmp_User; - INSERT INTO tmp_User ( id_user ) - VALUES ( NULL ); - END IF; - - - SELECT - U.id_user - , U.id_user_auth0 - , U.firstname - , U.surname - , U.email - , U.is_email_verified - , U.id_currency_default - , U.id_region_default - , U.is_included_VAT_default - , U.is_super_user - , t_U.can_admin_store - , t_U.can_admin_user - , v_is_new AS is_new - FROM tmp_User t_U - INNER JOIN partsltd_prod.Shop_User U ON t_U.id_user = U.id_user - ; - - -- Errors - SELECT - t_ME.display_order, - MET.code, - t_ME.msg, - MET.name, - MET.description - FROM tmp_Msg_Error t_ME - INNER JOIN partsltd_prod.Shop_Msg_Error_Type MET - ON t_ME.id_type = MET.id_type - ; - - - IF a_debug = 1 THEN - SELECT * FROM tmp_User; - END IF; - - -- Clean up - DROP TEMPORARY TABLE IF EXISTS tmp_User; - DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error; - - /* - DELETE FROM partsltd_prod.Shop_Calc_User_Temp - WHERE GUID = v_guid; - */ - - IF a_debug = 1 THEN - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); - END IF; -END // -DELIMITER ; - - - -/* -CALL p_get_many_user ( - NULL - , 'google-oauth2|109567376920138999933' - , False - , False - -- , False - , NULL - , 'google-oauth2|109567376920138999933' - , 0 -); - NULL -- a_id_user - , 'auth0|6582b95c895d09a70ba10fef' -- a_id_user_auth0 - , 0 -- a_get_all_user - , 0 -- a_get_inactive_user - -- , 0 -- a_get_first_user_only - , NULL -- a_ids_user - , 'auth0|6582b95c895d09a70ba10fef' -- a_ids_user_auth0 - , 0 -- a_debug -);*/ - -/* -select * FROM partsltd_prod.Shop_Calc_User_Temp; -delete FROM partsltd_prod.Shop_Calc_User_Temp; - -SELECT * -FROM partsltd_prod.Shop_USER; - -CALL p_get_many_user( - NULL -- :a_id_user, - , 'auth0|6582b95c895d09a70ba10fef' -- :a_id_user_auth0, - , 1 -- :a_get_all_user, - , 0 -- :a_get_inactive_user, - -- , 0 -- :a_get_first_user_only, - , NULL -- :a_ids_user, - , 'auth0|6582b95c895d09a70ba10fef' -- :a_ids_user_auth0 -); - -*/ diff --git a/static/MySQL/7321_p_shop_save_user_basket.sql b/static/MySQL/7321_p_shop_save_user_basket.sql deleted file mode 100644 index 7ce38f21..00000000 --- a/static/MySQL/7321_p_shop_save_user_basket.sql +++ /dev/null @@ -1,830 +0,0 @@ - - - -/* - -CALL p_shop_edit_user_basket ( - '', -- a_id_user - '', -- a_ids_permutation_basket - '', -- a_quantities_permutation_basket - 1, -- a_id_permutation_edit - NULL, -- a_quantity_permutation_edit - 1, -- a_sum_not_edit - 1, -- a_id_currency_edit - 1 -- a_id_region_purchase -) - -*/ - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_edit_user_basket; - - -DELIMITER // -CREATE PROCEDURE p_shop_edit_user_basket ( - IN a_id_user INT, - IN a_ids_permutation_basket VARCHAR(4000), - IN a_quantities_permutation_basket VARCHAR(4000), - IN a_id_permutation_edit INT, - IN a_quantity_permutation_edit INT, - IN a_sum_not_edit BIT, - IN a_id_currency INT, - IN a_id_region_purchase INT -) -BEGIN - -- Argument redeclaration - -- Variable declaration - DECLARE v_has_filter_user BIT; - DECLARE v_has_filter_permutation_basket BIT; - DECLARE v_has_filter_permutation_edit BIT; - DECLARE v_has_filter_region BIT; - DECLARE v_has_filter_currency BIT; - DECLARE v_n_id_permutation_basket INT; - DECLARE v_n_quantity_permutation_basket INT; - DECLARE v_row_number INT; - DECLARE v_guid BINARY(36); - -- DECLARE v_id_user VARCHAR(100); - DECLARE v_id_permission_product INT; - DECLARE v_ids_permutation_permission VARCHAR(4000); - DECLARE v_now DATETIME; - -- DECLARE v_quantity_new INT; - DECLARE v_change_set_used BIT; - DECLARE v_id_change_set INT; - - SET v_guid = UUID(); - - -- Argument validation + default values - IF a_id_user IS NULL THEN - SET a_id_user = ''; - ELSE - SET a_id_user = TRIM(a_id_user); - END IF; - IF a_ids_permutation_basket IS NULL THEN - SET a_ids_permutation_basket = ''; - ELSE - SET a_ids_permutation_basket = TRIM(a_ids_permutation_basket); - END IF; - IF a_quantities_permutation_basket IS NULL THEN - SET a_quantities_permutation_basket = ''; - ELSE - SET a_quantities_permutation_basket = TRIM(a_quantities_permutation_basket); - END IF; - IF a_sum_not_edit IS NULL THEN - SET a_sum_not_edit = 1; - END IF; - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Msg_Error; - DROP TABLE IF EXISTS tmp_Shop_Basket; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Quantity; - DROP TABLE IF EXISTS tmp_Shop_Product; - DROP TABLE IF EXISTS tmp_Shop_User; - - CREATE TABLE tmp_Shop_User ( - id_user INT NOT NULL, - CONSTRAINT FK_tmp_Shop_User_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user), - active BIT NOT NULL - ); - - CREATE TABLE tmp_Shop_Product ( - id_product INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - id_permutation INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - display_order INT NOT NULL, - active INT NOT NULL DEFAULT 1 - ); - - CREATE TEMPORARY TABLE tmp_Shop_Quantity( - quantity INT NOT NULL, - display_order INT NOT NULL, - active INT NOT NULL DEFAULT 1 - ); - - CREATE TABLE tmp_Shop_Basket ( - id_category INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Basket_id_category - FOREIGN KEY (id_category) - REFERENCES Shop_Product_Category(id_category), - id_product INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Basket_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - id_permutation INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Basket_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - id_region_purchase INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Basket_id_region_purchase - FOREIGN KEY (id_region_purchase) - REFERENCES Shop_Region(id_region), - id_currency INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Basket_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency), - quantity INT NOT NULL, - active BIT NOT NULL DEFAULT 1 - /* - display_order_category INT NOT NULL, - display_order_product INT NOT NULL - */ - ); - - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - guid BINARY(36) NOT NULL, - id_type INT NOT NULL, - -- code VARCHAR(50) NOT NULL, - -- CONSTRAINT chk_tmp_Msg_Error_code CHECK (code IN (SELECT code FROM Shop_Msg_Error_Type)), - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type(id_type), - msg VARCHAR(4000) NOT NULL - ); - - - -- Parse filters - SET v_has_filter_user = NOT (a_id_user = ''); - SET v_has_filter_permutation_basket = NOT (a_ids_permutation_basket = ''); - SET v_has_filter_permutation_edit = NOT ISNULL(a_id_permutation_edit); - SET v_has_filter_currency = NOT ISNULL(a_id_currency); - SET v_has_filter_region = NOT ISNULL(a_id_region_purchase); - -- SET v_quantity_new = CASE WHEN a_sum_not_edit THEN quantity + a_quantity_product_edit ELSE a_quantity_product_edit END; - /* - SELECT v_has_filter_user, v_has_filter_basket - ; - - */ - - -- Currency - IF NOT v_has_filter_currency THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - 'Currency ID not provided.' - ) - ; - END IF; - IF v_has_filter_currency AND NOT EXISTS ( SELECT * FROM Shop_Currency WHERE id_currency = a_id_currency) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('Currency ID not found: ', a_id_currency, '.') - ) - ; - END IF; - - -- Region - IF NOT v_has_filter_region THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - 'Region ID not provided.' - ) - ; - END IF; - IF v_has_filter_region AND NOT EXISTS ( SELECT * FROM Shop_Region WHERE id_region = a_id_region_purchase) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('Region ID not found: ', a_id_region_purchase, '.') - ) - ; - END IF; - - -- User - IF v_has_filter_user THEN - INSERT INTO tmp_Shop_User ( - id_user, - active - ) - SELECT id_user, - active - FROM Shop_User - WHERE id_user LIKE CONCAT('%', a_id_user, '%') - AND active - LIMIT 1 - ; - - IF NOT EXISTS (SELECT id_user FROM tmp_Shop_User LIMIT 1) THEN - SET v_has_filter_user = 0; - - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('User ID not found: ', a_id_user, '.') - ) - ; - END IF; - - SET a_id_user := (SELECT id_user FROM tmp_Shop_User LIMIT 1); - END IF; - - IF v_has_filter_user AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - SET v_change_set_used = 0; - INSERT INTO Shop_User_Change_Set ( - comment - ) - VALUES ( - 'edit basket' - ); - SET v_id_change_set := (SELECT id_change_set FROM Shop_User_Change_Set ORDER BY id_change_set DESC LIMIT 1); - END IF; - - -- Get basket - -- User - IF v_has_filter_user AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - INSERT INTO tmp_Shop_Basket ( - id_category, - id_product, - id_permutation, - id_region_purchase, - id_currency, - quantity, - active - /* - display_order_category, - display_order_product - */ - ) - SELECT - C.id_category, - UB.id_product, - UB.id_permutation, - UB.id_region_purchase, - UB.id_currency, - UB.quantity, - UB.active - /* - C.display_order, - P.display_order - */ - FROM Shop_User_Basket UB - /* - INNER JOIN tmp_Shop_User t_U - ON UB.id_user = t_U.id_user - */ - INNER JOIN Shop_Product_Permutation PP - ON UB.id_product = PP.id_product - AND PP.active - INNER JOIN Shop_Product P - ON PP.id_product = P.id_product - AND P.active - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - AND C.active - WHERE UB.id_user = a_id_user - ; - END IF; - - -- Currency - IF EXISTS (SELECT * FROM tmp_Shop_Basket WHERE active LIMIT 1) - AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - IF EXISTS (SELECT * FROM tmp_Shop_Basket WHERE active AND id_currency != a_id_currency) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT( - 'Currency ID does not match currency of other items in basket. Basket currency: ', - (SELECT code FROM Shop_Currency WHERE id_currency = ( - SELECT - id_currency - FROM tmp_Shop_Basket - WHERE active - AND id_currency != a_id_currency - LIMIT 1 - )), - ', new currency: ', - (SELECT code FROM Shop_Currency WHERE id_currency = a_id_currency), - '.' - ) - ) - ; - END IF; - END IF; - - -- Region - IF EXISTS (SELECT * FROM tmp_Shop_Basket WHERE active LIMIT 1) - AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Shop_Basket - WHERE - active - AND id_region_purchase != a_id_region_purchase - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('Purchase region ID does not match region of other items in basket. Basket currency: ', - (SELECT code FROM Shop_Region WHERE id_region = ( - SELECT - id_region_purchase - FROM tmp_Shop_Basket - WHERE active - AND id_region != a_id_region_purchase - LIMIT 1 - )), - ', new currency: ', - (SELECT code FROM Shop_Region WHERE id_region = a_id_region_purchase), - '.' - ) - ) - ; - END IF; - END IF; - - -- String product id, permutation id, quantity list - IF NOT EXISTS (SELECT * FROM tmp_Shop_Basket WHERE active LIMIT 1) AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN -- NOT v_has_filter_user AND - -- Get product ids - CALL p_split(v_guid, a_ids_permutation_basket, ','); - INSERT INTO tmp_Shop_Product ( - id_product, id_permutation, display_order - ) - SELECT PP.id_product, ST.substring, ST.display_order - FROM Split_Temp ST - INNER JOIN Shop_Product_Permutation PP - ON ST.substring = PP.id_permutation - -- AND PP.active - ; - /* - SELECT substring as id_product, display_order - FROM Split_Temp - ; - */ - DROP TABLE Split_Temp; - - -- Get product quantities - CALL p_split(v_guid, a_quantities_permutation_basket, ','); - INSERT INTO tmp_Shop_Quantity ( - quantity, display_order - ) - SELECT substring, display_order - FROM Split_Temp - ; - /* - SELECT substring AS quantity_product, display_order - FROM Split_Temp - ; - */ - DROP TABLE Split_Temp; - - -- Compare number of product ids to number of quantities - SET v_n_id_permutation_basket := (SELECT display_order FROM tmp_Shop_Product ORDER BY display_order DESC LIMIT 1); - SET v_n_quantity_permutation_basket := (SELECT display_order FROM tmp_Shop_Quantity ORDER BY display_order DESC LIMIT 1); - IF NOT v_n_id_permutation_basket = v_n_quantity_permutation_basket THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('Number of permutations (', v_n_id_permutation_basket, ') does not equal number of quantities (', v_n_quantity_permutation_basket, ') for basket.') - ) - ; - ELSE - INSERT INTO tmp_Shop_Basket ( - id_category, - id_product, - id_permutation, - id_region_purchase, - id_currency, - quantity - ) - SELECT - C.id_category, - P.id_product, - t_P.id_permutation, - a_id_region_purchase, - a_id_currency, - t_Q.quantity - FROM tmp_Shop_Product t_P - INNER JOIN tmp_Shop_Quantity t_Q - ON t_P.display_order = t_Q.display_order - INNER JOIN Shop_Product_Permutation PP - ON t_P.id_permutation = PP.id_permutation - AND PP.active - INNER JOIN Shop_Product P - ON PP.id_product = P.id_product - AND P.active - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - AND C.active - -- RIGHT JOIN tmp_Shop_Basket t_UB ON ISNULL(t_UB.id_product) - -- WHERE t_P.id_product NOT IN (SELECT id_product FROM tmp_Shop_Basket) - ; - - /* - IF EXISTS( - SELECT * - FROM Shop_Product P - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - INNER JOIN tmp_Shop_Basket t_B - ON P.id_product = t_B.id_product - WHERE C.active = 0 OR P.active = 0 LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('No valid product IDs in list: ', a_ids_permutation_basket, '.') - ) - ; - END IF; - */ - END IF; - END IF; - - /* - select v_has_filter_edit; - select * from tmp_Shop_Basket; - select * from tmp_Msg_Error; - */ - - - -- Edit basket product - IF v_has_filter_permutation_edit AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM Shop_Product_Permutation PP - INNER JOIN Shop_Product P - ON PP.id_product = P.id_product - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - WHERE - ( - C.active = 0 - OR P.active = 0 - OR PP.active = 0 - ) - AND PP.id_permutation = a_id_permutation_edit - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('Invalid product ID to edit: ', a_id_product_edit, '.') - ) - ; - END IF; - END IF; - IF v_has_filter_permutation_edit AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Shop_Basket - WHERE - id_permutation = a_id_permutation_edit - ) THEN - UPDATE tmp_Shop_Basket - SET quantity = CASE WHEN a_sum_not_edit = 1 THEN IFNULL(quantity, 0) + a_quantity_permutation_edit ELSE a_quantity_permutation_edit END, - active = CASE WHEN CASE WHEN a_sum_not_edit = 1 THEN IFNULL(quantity, 0) + a_quantity_permutation_edit ELSE a_quantity_permutation_edit END = 0 THEN 0 ELSE 1 END - WHERE id_permutation = a_id_permutation_edit - ; - - IF EXISTS ( - SELECT * - FROM tmp_Shop_Basket t_B - WHERE t_B.quantity < 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - 'Invalid basket quantity.' - ) - ; - END IF; - - IF v_has_filter_user AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - SET v_change_set_used = 1; - - UPDATE Shop_User_Basket UB - INNER JOIN tmp_Shop_Basket t_UB - ON UB.id_permutation = a_id_permutation_edit - SET UB.quantity = t_UB.quantity, - UB.active = t_UB.active, - UB.id_change_set_user = v_id_change_set - WHERE UB.id_permutation = a_id_permutation_edit - AND id_user = a_id_user - ; - END IF; - ELSE - IF a_quantity_permutation_edit < 0 THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - 'Invalid basket quantity.' - ) - ; - ELSE - INSERT INTO tmp_Shop_Basket ( - id_category, - id_product, - id_permutation, - id_region_purchase, - id_currency, - quantity, - active - ) - SELECT - P.id_category, - P.id_product, - PP.id_permutation, - a_id_region_purchase, - a_id_currency, - a_quantity_permutation_edit, - CASE WHEN a_quantity_permutation_edit > 0 THEN 1 ELSE 0 END - FROM Shop_Product_Permutation PP - INNER JOIN Shop_Product P - ON PP.id_product = P.id_product - WHERE id_permutation = a_id_permutation_edit - ; - IF v_has_filter_user THEN - IF EXISTS ( - SELECT * - FROM Shop_User_Basket UB - WHERE - UB.id_permutation = a_id_permutation_edit - ) THEN - SET v_change_set_used = 1; - - UPDATE Shop_User_Basket - INNER JOIN tmp_Shop_Basket t_UB ON UB.id_permutation = t_UB.id_permutation - SET UB.quantity = t_UB.quantity, - UB.active = t_UB.active, - UB.id_change_set_user = v_id_change_set - WHERE UB.id_permutation = a_id_permutation_edit - AND id_user = a_id_user - ; - ELSE - INSERT INTO Shop_User_Basket ( - id_user, - id_product, - id_permutation, - id_region_purchase, - id_currency, - quantity, - active - ) - SELECT a_id_user, - t_UB.id_product, - t_UB.id_permutation, - t_UB.id_region_purchase, - t_UB.id_currency, - t_UB.quantity, - t_UB.active - FROM tmp_Shop_Basket t_UB - WHERE id_permutation = a_id_permutation_edit - ; - END IF; - END IF; - END IF; - END IF; - END IF; - - - -- Checks - /* - SELECT * FROM tmp_Shop_Basket; - SELECT - GROUP_CONCAT(t_UB.id_product SEPARATOR ',') AS basket_product_ids - FROM tmp_Shop_Basket t_UB - -- WHERE ISNULL(t_UB.id_permutation) - ; - SELECT - GROUP_CONCAT(t_UB.id_permutation SEPARATOR ',') AS basket_permutation_ids - FROM tmp_Shop_Basket t_UB - WHERE NOT ISNULL(t_UB.id_permutation) - ; - */ - -- Returns - CALL p_shop_get_many_product ( - a_id_user, -- a_id_user - 1, -- a_get_all_categories - '', -- a_ids_category - 0, -- a_get_inactive_categories - 0, -- a_get_all_products - ( - SELECT - GROUP_CONCAT(t_B.id_product SEPARATOR ',') - FROM tmp_Shop_Basket t_B - WHERE active = 1 - ), -- a_ids_product - 0, -- a_get_inactive_products - 0, -- a_get_first_product_only - 0, -- a_get_all_product_permutations - ( - SELECT - GROUP_CONCAT(t_B.id_permutation SEPARATOR ',') - FROM tmp_Shop_Basket t_B - WHERE NOT ISNULL(t_B.id_permutation) - AND active = 1 - ), -- a_ids_permutation - 0, -- a_get_inactive_permutations - 0, -- a_get_all_images - '', -- a_ids_image - 0, -- a_get_inactive_images - 1, -- a_get_first_image_only - 0, -- a_get_all_delivery_region - a_id_region_purchase, -- a_ids_delivery_region - 0, -- a_get_inactive_delivery_region - 0, -- a_get_all_currency - a_id_currency, -- a_ids_currency - 0, -- a_get_inactive_currency - 1, -- a_get_all_discount - '', -- a_ids_discount - 0 -- a_get_inactive_discount - ); - - -- Basket - SELECT t_UB.id_category, - t_UB.id_product, - t_UB.id_permutation, - P.name, - PCL.price_local_VAT_incl, - PCL.price_local_VAT_excl, - PCL.id_currency, - t_UB.quantity - FROM tmp_Shop_Basket t_UB - INNER JOIN Shop_Product_Permutation PP - ON t_UB.id_permutation = PP.id_permutation - INNER JOIN Shop_Product P - ON PP.id_product = P.id_product - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - INNER JOIN Shop_Product_Currency_Link PCL - ON PP.id_permutation = PCL.id_permutation - AND PCL.id_region_purchase = a_id_region_purchase - AND PCL.id_currency = a_id_currency - WHERE t_UB.active = 1 - ORDER BY C.display_order, P.display_order - ; - - -- Errors - /* Completed by product get many */ - SELECT - t_ME.display_order, - t_ME.guid, - t_ME.id_type, - t_ME.msg, - MET.code, - MET.name, - MET.description - FROM tmp_Msg_Error t_ME - INNER JOIN Shop_Msg_Error_Type MET - ON t_ME.id_type = MET.id_type - WHERE GUID = v_guid - ; - - /* - -- Return arguments for test - SELECT - a_ids_category, - a_get_inactive_categories, - a_ids_product, - a_get_inactive_products, - a_get_first_product_only, - a_get_all_products, - a_ids_image, - a_get_inactive_images, - a_get_first_image_only, - a_get_all_images - ; - */ - - -- Clean up - IF NOT v_change_set_used THEN - DELETE FROM Shop_User_Change_Set - WHERE id_change_set = v_id_change_set - ; - END IF; - - -- DROP TABLE IF EXISTS tmp_Msg_Error; - DELETE FROM tmp_Msg_Error WHERE guid = v_guid; - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - DROP TABLE tmp_Msg_Error; - END IF; - DROP TABLE IF EXISTS tmp_Shop_Basket; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Quantity; - DROP TABLE IF EXISTS tmp_Shop_Product; - DROP TABLE IF EXISTS tmp_Shop_User; -END // -DELIMITER ; - - -/* - -CALL p_shop_edit_user_basket ( - '', -- a_id_user - '', -- a_ids_permutation_basket - '', -- a_quantities_permutation_basket - 2, -- a_id_permutation_edit - 1, -- a_quantity_permutation_edit - 1, -- a_sum_not_edit - 2, -- a_id_currency_edit - 1 -- a_id_region_purchase -); - -CALL p_shop_edit_user_basket ( - '', -- a_id_user - '1', -- a_ids_permutation_basket - '9', -- a_quantities_permutation_basket - 1, -- a_id_permutation_edit - 69, -- a_quantity_permutation_edit - 1, -- a_sum_not_edit - 1, -- a_id_currency_edit - 1 -- a_id_region_purchase -); -CALL p_shop_edit_user_basket ( - 'auth0|6582b95c895d09a70ba10feF', -- a_id_user - '2', -- a_ids_permutation_basket - '7', -- a_quantities_permutation_basket - 2, -- a_id_permutation_edit - NULL, -- a_quantity_permutation_edit - 1, -- a_sum_not_edit - 1, -- a_id_currency_edit - 1 -- a_id_region_purchase -); - - - {'a_id_user': 'auth0|6582b95c895d09a70ba10fef', - 'a_ids_permutation_basket': '1', - '7', -- a_quantities_permutation_basket - 'a_id_permutation_edit': 1, - 'a_quantity_permutation_edit': 1, - 'a_sum_not_edit': 1} - - select * from shop_user_basket; - insert into shop_user_change_set (comment) - values( 'deactivate duplicates'); - update SHOP_USER_BASKET - set active = 0, - id_change_set_user = (select id_change_set from shop_user_change_set order by id_change_set desc limit 1) - where id_user = 'auth0|6582b95c895d09a70ba10fef' - and id_product = 1 - ; - select * from shop_user_basket; -*/ diff --git a/static/MySQL/7400_p_shop_save_supplier.sql b/static/MySQL/7400_p_shop_save_supplier.sql deleted file mode 100644 index 8a3a4dd1..00000000 --- a/static/MySQL/7400_p_shop_save_supplier.sql +++ /dev/null @@ -1,597 +0,0 @@ - - - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_save_supplier; - - -DELIMITER // -CREATE PROCEDURE p_shop_save_supplier ( - IN a_comment VARCHAR(500) - , IN a_guid BINARY(36) - , IN a_id_user INT - , IN a_debug BIT -) -BEGIN - DECLARE v_code_type_error_bad_data VARCHAR(50); - DECLARE v_code_type_error_no_permission VARCHAR(50); - DECLARE v_id_access_level_edit INT; - DECLARE v_id_change_set INT; - DECLARE v_id_permission_supplier INT; - DECLARE v_id_type_error_bad_data INT; - DECLARE v_id_type_error_no_permission INT; - DECLARE v_time_start TIMESTAMP(6); - - DECLARE exit handler for SQLEXCEPTION - BEGIN - GET DIAGNOSTICS CONDITION 1 - @sqlstate = RETURNED_SQLSTATE - , @errno = MYSQL_ERRNO - , @text = MESSAGE_TEXT - ; - - ROLLBACK; - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT - , id_type INT NULL - , code VARCHAR(50) NOT NULL - , msg VARCHAR(4000) NOT NULL - ); - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - id_type - , @errno - , @text - FROM partsltd_prod.Shop_Msg_Error_Type MET - WHERE code = 'MYSQL_ERROR' - ; - SELECT * - FROM tmp_Msg_Error; - DROP TABLE IF EXISTS tmp_Msg_Error; - END; - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_code_type_error_bad_data := (SELECT code FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1); - SET v_id_type_error_bad_data := (SELECT id_type FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = v_code_type_error_bad_data LIMIT 1); - SET v_code_type_error_no_permission := (SELECT code FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = 'NO_PERMISSION' LIMIT 1); - SET v_id_type_error_no_permission := (SELECT id_type FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = v_code_type_error_no_permission LIMIT 1); - SET v_id_permission_supplier := (SELECT id_permission FROM partsltd_prod.Shop_Permission WHERE code = 'STORE_SUPPLIER' LIMIT 1); - SET v_id_access_level_EDIT := (SELECT id_access_level FROM partsltd_prod.Shop_Access_Level WHERE code = 'EDIT' LIMIT 1); - - CALL p_validate_guid ( a_guid ); - SET a_comment := TRIM(IFNULL(a_comment, '')); - - DROP TEMPORARY TABLE IF EXISTS tmp_Supplier; - DROP TEMPORARY TABLE IF EXISTS tmp_Supplier_Address; - DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error; - - CREATE TEMPORARY TABLE tmp_Supplier ( - id_supplier_temp INT NOT NULL - , id_supplier INT NULL - , id_currency INT NOT NULL - , name_company VARCHAR(255) NOT NULL - , name_contact VARCHAR(255) NULL - , department_contact VARCHAR(255) NULL - , phone_number VARCHAR(50) NULL - , fax VARCHAR(50) NULL - , email VARCHAR(255) NOT NULL - , website VARCHAR(255) NULL - , active BIT NOT NULL - , name_error VARCHAR(1000) NOT NULL - , is_new BIT NOT NULL - ); - - CREATE TEMPORARY TABLE tmp_Supplier_Address ( - id_address INT NOT NULL - , id_supplier INT NOT NULL - , id_region INT NOT NULL - , postcode VARCHAR(20) NOT NULL - , address_line_1 VARCHAR(256) NOT NULL - , address_line_2 VARCHAR(256) NOT NULL - , city VARCHAR(256) NOT NULL - , county VARCHAR(256) NOT NULL - , active BIT NOT NULL - , name_error VARCHAR(1000) NOT NULL - , is_new BIT NOT NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT - , id_type INT NOT NULL - , code VARCHAR(50) NOT NULL - , msg VARCHAR(4000) NOT NULL - ); - - - INSERT INTO tmp_Supplier ( - id_supplier_temp - , id_supplier - , id_currency - , name_company - , name_contact - , department_contact - , phone_number - , fax - , email - , website - , active - , name_error - , is_new - ) - SELECT - S_T.id_supplier - , S_T.id_supplier - , S_T.id_currency - , S_T.name_company - , S_T.name_contact - , S_T.department_contact - , S_T.phone_number - , S_T.fax - , S_T.email - , S_T.website - , S_T.active - , IFNULL(S_T.name_company, IFNULL(S_T.email, IFNULL(S_T.website, IFNULL(S_T.name_contact, '(No Supplier)')))) - , IFNULL(S_T.id_supplier, 0) < 1 - FROM partsltd_prod.Shop_Supplier_Temp S_T - WHERE GUID = a_guid - ; - - INSERT INTO tmp_Supplier_Address ( - id_address - , id_supplier - , id_region - , postcode - , address_line_1 - , address_line_2 - , city - , county - , active - , name_error - , is_new - ) - SELECT - SA_T.id_address - , SA_T.id_supplier - , SA_T.id_region - , SA_T.postcode - , SA_T.address_line_1 - , SA_T.address_line_2 - , SA_T.city - , SA_T.county - , SA_T.active - , IFNULL(SA_T.postcode, IFNULL(SA_T.city, IFNULL(SA_T.county, IFNULL(SA_T.address_line_1, IFNULL(SA_T.address_line_2, '(No Supplier)'))))) AS name_error - , IFNULL(SA_T.id_address, 0) < 1 AS is_new - FROM partsltd_prod.Shop_Supplier_Address_Temp SA_T - WHERE GUID = a_guid - ; - - -- Validation - -- Suppliers - /* - -- id_address - IF EXISTS ( - SELECT * - FROM tmp_Supplier t_S - LEFT JOIN partsltd_prod.Shop_Address A ON t_S.id_address = A.id_address - WHERE 1=1 - AND ( - t_S.id_address = 0 - OR A.active = 0 - ) - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT( - 'The following supplier(s) have an invalid or inactive Address: ' - , GROUP_CONCAT(t_S.name_error SEPARATOR ', ') - ) AS msg - FROM tmp_Supplier t_S - LEFT JOIN partsltd_prod.Shop_Address A ON t_S.id_address = A.id_address - WHERE 1=1 - AND ( - t_S.id_address = 0 - OR A.active = 0 - ) - ; - END IF; - */ - -- id_currency - IF EXISTS ( - SELECT * - FROM tmp_Supplier t_S - LEFT JOIN partsltd_prod.Shop_Currency C ON t_S.id_currency = C.id_currency - WHERE 1=1 - AND ( - t_S.id_currency = 0 - OR C.active = 0 - ) - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT( - 'The following supplier(s) have an invalid or inactive Currency: ' - , GROUP_CONCAT(t_S.name_error SEPARATOR ', ') - ) AS msg - FROM tmp_Supplier t_S - LEFT JOIN partsltd_prod.Shop_Currency C ON t_S.id_currency = C.id_currency - WHERE 1=1 - AND ( - t_S.id_currency = 0 - OR C.active = 0 - ) - ; - END IF; - -- name_company - IF EXISTS (SELECT * FROM tmp_Supplier t_S WHERE ISNULL(t_S.name_company) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following supplier(s) do not have a name: ', GROUP_CONCAT(IFNULL(t_S.name_error, 'NULL') SEPARATOR ', ')) AS msg - FROM tmp_Supplier t_S - WHERE ISNULL(t_S.name_company) - ; - END IF; - -- email - IF EXISTS (SELECT * FROM tmp_Supplier t_S WHERE ISNULL(t_S.email) LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following supplier(s) do not have an email: ', GROUP_CONCAT(IFNULL(t_S.name_error, 'NULL') SEPARATOR ', ')) AS msg - FROM tmp_Supplier t_S - WHERE ISNULL(t_S.email) - ; - END IF; - -- duplicate - IF EXISTS (SELECT COUNT(*) FROM tmp_Supplier t_S GROUP BY t_S.id_supplier HAVING COUNT(*) > 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following supplier(s) are duplicates: ', GROUP_CONCAT(IFNULL(t_S.name_error, 'NULL') SEPARATOR ', ')) AS msg - FROM tmp_Supplier t_S - GROUP BY t_S.id_supplier - HAVING COUNT(*) > 1 - ; - END IF; - - -- Addresses - -- id_supplier - IF EXISTS ( - SELECT * - FROM tmp_Supplier_Address t_SA - LEFT JOIN partsltd_prod.Shop_Supplier S ON t_SA.id_supplier = S.id_supplier - WHERE 1=1 - AND ( - t_SA.id_supplier = 0 - OR S.active = 0 - ) - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT( - 'The following supplier address(es) have an invalid or inactive Supplier: ' - , GROUP_CONCAT(t_S.name_error SEPARATOR ', ') - ) AS msg - FROM tmp_Supplier t_S - LEFT JOIN partsltd_prod.Shop_Supplier S ON t_SA.id_supplier = S.id_supplier - WHERE 1=1 - AND ( - t_SA.id_supplier = 0 - OR S.active = 0 - ) - ; - END IF; - -- id_region - IF EXISTS ( - SELECT * - FROM tmp_Supplier_Address t_SA - LEFT JOIN partsltd_prod.Shop_Region R ON t_SA.id_region = R.id_region - WHERE 1=1 - AND ( - t_SA.id_region = 0 - OR R.active = 0 - ) - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT( - 'The following supplier address(es) have an invalid or inactive Supplier: ' - , GROUP_CONCAT(t_S.name_error SEPARATOR ', ') - ) AS msg - FROM tmp_Supplier t_S - LEFT JOIN partsltd_prod.Shop_Region R ON t_SA.id_region = R.id_region - WHERE 1=1 - AND ( - t_SA.id_region = 0 - OR R.active = 0 - ) - ; - END IF; - -- duplicate - IF EXISTS (SELECT COUNT(*) FROM tmp_Supplier_Address t_SA GROUP BY t_SA.id_address HAVING COUNT(*) > 1) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT('The following supplier address(es) are duplicates: ', GROUP_CONCAT(IFNULL(t_S.name_error, 'NULL') SEPARATOR ', ')) AS msg - FROM tmp_Supplier_Address t_SA - GROUP BY t_SA.id_address - HAVING COUNT(*) > 1 - ; - END IF; - - -- Permissions - IF a_debug = 1 THEN - SELECT - a_guid - , a_id_user - , FALSE -- get inactive users - , v_id_permission_supplier - , v_id_access_level_edit - , '' -- ids_product - , 0 -- a_debug - ; - SELECT * from partsltd_prod.Shop_Calc_User_Temp; - END IF; - - CALL p_shop_calc_user( - a_guid - , a_id_user - , FALSE -- get inactive users - , v_id_permission_supplier - , v_id_access_level_edit - , '' -- ids_product - , 0 -- a_debug - ); - - IF a_debug = 1 THEN - SELECT * from partsltd_prod.Shop_Calc_User_Temp WHERE GUID = a_guid; - END IF; - - IF NOT EXISTS (SELECT can_view FROM partsltd_prod.Shop_Calc_User_Temp UE_T WHERE UE_T.GUID = a_guid) THEN - DELETE FROM tmp_Msg_Error; - - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - VALUES ( - v_id_type_error_no_permission - , v_code_type_error_no_permission - , CONCAT('You do not have view permissions for ', (SELECT name FROM partsltd_prod.Shop_Permission WHERE id_permission = v_id_permission_supplier LIMIT 1)) - ) - ; - END IF; - - CALL partsltd_prod.p_shop_clear_calc_user( - a_guid - , 0 -- a_debug - ); - - IF EXISTS ( SELECT * FROM tmp_Msg_Error LIMIT 1 ) THEN - DELETE FROM tmp_Supplier; - END IF; - - - -- Transaction - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - START TRANSACTION; - INSERT INTO partsltd_prod.Shop_User_Change_Set ( - comment - , updated_last_by - , updated_last_on - ) - VALUES ( - a_comment - , a_id_user - , v_time_start - ); - - SET v_id_change_set := LAST_INSERT_ID(); - - INSERT INTO partsltd_prod.Shop_Supplier ( - id_supplier_temp - , id_currency - , name_company - , name_contact - , department_contact - , phone_number - , fax - , email - , website - , active - , id_change_set - ) - SELECT - t_S.id_supplier - , t_S.id_currency - , t_S.name_company - , t_S.name_contact - , t_S.department_contact - , t_S.phone_number - , t_S.fax - , t_S.email - , t_S.website - , t_S.active - , v_id_change_set - FROM tmp_Supplier t_S - WHERE t_S.is_new = 1 - ; - - UPDATE tmp_Supplier t_S - INNER JOIN partsltd_prod.Shop_Supplier S ON t_S.id_supplier_temp = S.id_supplier_temp - SET - t_S.id_supplier = S.id_supplier - WHERE t_S.is_new = 1 - ; - - UPDATE tmp_Supplier_Address t_SA - INNER JOIN tmp_Supplier t_S ON t_SA.id_supplier = t_S.id_supplier_temp - SET - t_SA.id_supplier = t_S.id_supplier - WHERE t_S.is_new = 1 - ; - - UPDATE partsltd_prod.Shop_Supplier S - INNER JOIN tmp_Supplier t_S - ON S.id_supplier = t_S.id_supplier - AND t_S.is_new = 0 - SET - S.id_currency = t_S.id_currency - , S.name_company = t_S.name_company - , S.name_contact = t_S.name_contact - , S.department_contact = t_S.department_contact - , S.phone_number = t_S.phone_number - , S.fax = t_S.fax - , S.email = t_S.email - , S.website = t_S.website - , S.active = t_S.active - , S.id_change_set = v_id_change_set - /* - S.name_company = a_name_company, - S.name_contact = a_name_contact, - S.department_contact = a_department_contact, - S.id_address = a_id_address, - S.phone_number = a_phone_number, - S.fax = a_fax, - S.email = a_email, - S.website = a_website, - S.id_currency = a_id_currency, - S.active = a_active, - S.id_change_set = v_id_change_set - */ - ; - - INSERT INTO partsltd_prod.Shop_Supplier_Address ( - id_supplier - , id_region - , postcode - , address_line_1 - , address_line_2 - , city - , county - , active - , id_change_set - ) - SELECT - t_SA.id_supplier - , t_SA.id_region - , t_SA.postcode - , t_SA.address_line_1 - , t_SA.address_line_2 - , t_SA.city - , t_SA.county - , t_SA.active - , v_id_change_set - FROM tmp_Supplier_Address t_SA - WHERE t_SA.is_new = 1 - ; - - UPDATE partsltd_prod.Shop_Supplier_Address SA - INNER JOIN tmp_Supplier_Address t_SA - ON SA.id_address = t_SA.id_address - AND t_SA.is_new = 0 - SET - SA.id_supplier = t_SA.id_supplier - , SA.id_region = t_SA.id_region - , SA.postcode = t_SA.postcode - , SA.address_line_1 = t_SA.address_line_1 - , SA.address_line_2 = t_SA.address_line_2 - , SA.city = t_SA.city - , SA.county = t_SA.county - , SA.active = t_SA.active - , SA.id_change_set = v_id_change_set - ; - COMMIT; - END IF; - - START TRANSACTION; - DELETE FROM partsltd_prod.Shop_Supplier_Temp - WHERE GUID = a_guid; - DELETE FROM partsltd_prod.Shop_Supplier_Address_Temp - WHERE GUID = a_guid; - COMMIT; - - -- Errors - SELECT * - FROM tmp_Msg_Error t_ME - INNER JOIN partsltd_prod.Shop_Msg_Error_Type MET ON t_ME.id_type = MET.id_type - ; - - IF a_debug = 1 THEN - SELECT 'A_DEBUG'; - SELECT * from tmp_Supplier; - SELECT * from tmp_Supplier_Address; - END IF; - - DROP TEMPORARY TABLE IF EXISTS tmp_Supplier; - DROP TEMPORARY TABLE IF EXISTS tmp_Supplier_Address; - DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error; - - IF a_debug = 1 THEN - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); - END IF; -END // -DELIMITER ; - - --- SELECT * FROM Shop_Supplier; -/* -delete from shop_supplier_audit where id_supplier = 9; -delete from shop_supplier where id_supplier = 9; -delete from shop_supplier_address_audit where id_address = -4; -delete from shop_supplier_address where id_address = -4; -*/ \ No newline at end of file diff --git a/static/MySQL/7400_p_shop_save_supplier_temp.sql b/static/MySQL/7400_p_shop_save_supplier_temp.sql deleted file mode 100644 index cb6a6331..00000000 --- a/static/MySQL/7400_p_shop_save_supplier_temp.sql +++ /dev/null @@ -1,167 +0,0 @@ - - --- Clear previous proc -DROP PROCEDURE IF EXISTS partsltd_prod.p_shop_save_supplier_test; - - -DELIMITER // -CREATE PROCEDURE p_shop_save_supplier_test () -BEGIN - - DECLARE v_guid BINARY(36); - DECLARE v_time_start TIMESTAMP(6); - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_guid := 'nips'; - - SELECT * - FROM partsltd_prod.Shop_Supplier - ; - SELECT * - FROM partsltd_prod.Shop_Supplier_Temp - ; - SELECT * - FROM partsltd_prod.Shop_Supplier_Address - ; - SELECT * - FROM partsltd_prod.Shop_Supplier_Address_Temp - ; - - START TRANSACTION; - - INSERT INTO partsltd_prod.Shop_Supplier_Temp ( - id_supplier - , id_currency - , name_company - , name_contact - , department_contact - , phone_number - , fax - , email - , website - , active - , guid - ) - /* Test 1 - Insert - VALUES ( - -3 - , 1 - , 'Asda' - , '' - , NULL - , '' - , '123' - , 'test mail' - , 'test url' - , 1 -- active - , v_guid - ) - */ - /* Test 2 - Update */ - SELECT - id_supplier - , id_currency - , name_company - , 'Nat' AS name_contact - , 'Butchery' AS department_contact - , phone_number - , fax - , email - , website - , active - , v_guid - FROM partsltd_prod.Shop_Supplier S - WHERE S.id_supplier = 2 - ; - - /* - INSERT INTO partsltd_prod.Shop_Supplier_Address_Temp ( - id_address - , id_supplier - , id_region - , postcode - , address_line_1 - , address_line_2 - , city - , county - , active - , GUID - ) - / Test 1 - Insert - VALUES ( - -4 - , -3 - , 1 - , 'test postcode' - , 'test' - , 'test' - , 'test' - , 'cunty' - , 1 - , v_guid - ) - / - / Test 2 - Update / - SELECT - id_address - , id_supplier - , id_region - , postcode - , address_line_1 - , address_line_2 - , city - , county - , active - , v_guid - FROM partsltd_prod.Shop_Supplier_Address SA - WHERE SA.id_supplier = 2 - ; - */ - - COMMIT; - - SELECT * - FROM partsltd_prod.Shop_Supplier_Temp - WHERE GUID = v_guid - ; - - SELECT * - FROM partsltd_prod.Shop_Supplier_Address_Temp - WHERE GUID = v_guid - ; - - CALL partsltd_prod.p_shop_save_supplier ( - 'Test save Supplier' -- comment - , v_guid -- guid - , 1 -- id_user - , 1 -- debug - ); - - SELECT * - FROM partsltd_prod.Shop_Supplier_Temp - ; - SELECT * - FROM partsltd_prod.Shop_Supplier_Address_Temp - ; - SELECT * - FROM partsltd_prod.Shop_Supplier - ; - SELECT * - FROM partsltd_prod.Shop_Supplier_Address - ; - - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); -END // -DELIMITER ; - -/* -CALL partsltd_prod.p_shop_save_supplier_test (); - -DELETE FROM partsltd_prod.Shop_Supplier_Temp; -DELETE FROM partsltd_prod.Shop_Supplier_Address_Temp; - -DROP TABLE IF EXISTS tmp_Msg_Error; - -Cannot add or update a child row: a foreign key constraint fails (`partsltd_prod`.`shop_supplier`, CONSTRAINT `FK_Shop_Supplier_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_sales_and_purchasing_change_set` (`id_change_set`)) - -*/ \ No newline at end of file diff --git a/static/MySQL/7401_p_shop_get_many_supplier.sql b/static/MySQL/7401_p_shop_get_many_supplier.sql deleted file mode 100644 index 6103080e..00000000 --- a/static/MySQL/7401_p_shop_get_many_supplier.sql +++ /dev/null @@ -1,263 +0,0 @@ - - -DROP PROCEDURE IF EXISTS p_shop_get_many_supplier; - -DELIMITER // -CREATE PROCEDURE p_shop_get_many_supplier ( - IN a_id_user INT - , IN a_get_all_supplier BIT - , IN a_get_inactive_supplier BIT - , IN a_ids_supplier TEXT - , IN a_debug BIT -) -BEGIN - DECLARE v_code_type_error_bad_data VARCHAR(50); - DECLARE v_code_type_error_no_permission VARCHAR(50); - DECLARE v_guid BINARY(36); - DECLARE v_has_filter_supplier BIT; - DECLARE v_id_access_level_view INT; - DECLARE v_id_permission_supplier INT; - DECLARE v_id_type_error_bad_data INT; - DECLARE v_id_type_error_no_permission INT; - DECLARE v_time_start TIMESTAMP(6); - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_guid := UUID(); - SET v_id_access_level_view := (SELECT id_access_level FROM partsltd_prod.Shop_Access_Level WHERE code = 'VIEW' LIMIT 1); - SET v_code_type_error_bad_data := (SELECT code FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1); - SET v_id_type_error_bad_data := (SELECT id_type FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = v_code_type_error_bad_data LIMIT 1); - SET v_code_type_error_no_permission := (SELECT code FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = 'NO_PERMISSION'); - SET v_id_type_error_no_permission := (SELECT id_type FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = v_code_type_error_no_permission); - SET v_id_permission_supplier := (SELECT id_permission FROM partsltd_prod.Shop_Permission WHERE code = 'STORE_SUPPLIER' LIMIT 1); - - SET a_get_all_supplier := IFNULL(a_get_all_supplier, 0); - SET a_get_inactive_supplier := IFNULL(a_get_inactive_supplier, 0); - SET a_ids_supplier := TRIM(IFNULL(a_ids_supplier, '')); - - DROP TEMPORARY TABLE IF EXISTS tmp_Supplier; - DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error; - DROP TEMPORARY TABLE IF EXISTS tmp_Split; - - CREATE TEMPORARY TABLE tmp_Supplier ( - id_supplier INT NOT NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - id_type INT NOT NULL, - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Split ( - substring VARCHAR(4000) NOT NULL - , as_int INT NULL - ); - DELETE FROM tmp_Split; - - - -- Parse filters - SET v_has_filter_supplier = CASE WHEN a_ids_supplier = '' THEN 0 ELSE 1 END; - - IF a_debug = 1 THEN - SELECT - v_has_filter_supplier - ; - END IF; - - -- Suppliers - IF v_has_filter_supplier = 1 THEN - CALL partsltd_prod.p_split(v_guid, a_ids_supplier, ',', a_debug); - - INSERT INTO tmp_Split ( - substring - , as_int - ) - SELECT - substring - , CONVERT(substring, DECIMAL(10,0)) AS as_int - FROM partsltd_prod.Split_Temp - WHERE 1=1 - AND GUID = v_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( v_guid ); - END IF; - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Supplier S ON t_S.as_int = S.id_supplier - WHERE - ISNULL(t_S.as_int) - OR ISNULL(S.id_supplier) - OR ( - S.active = 0 - AND a_get_inactive_supplier = 0 - ) - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - code, - msg - ) - SELECT - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Invalid or inactive Supplier IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Supplier S ON t_S.as_int = S.id_supplier - WHERE - ISNULL(t_S.as_int) - OR ISNULL(S.id_supplier) - OR ( - S.active = 0 - AND a_get_inactive_supplier = 0 - ) - ; - ELSE - INSERT INTO tmp_Supplier ( - id_supplier - ) - SELECT - S.id_supplier - FROM tmp_Split t_S - RIGHT JOIN partsltd_prod.Shop_Supplier S ON t_S.as_int = S.id_supplier - WHERE ( - a_get_all_supplier = 1 - OR ( - v_has_filter_supplier = 1 - AND NOT ISNULL(t_S.as_int) - ) - ) - AND ( - a_get_inactive_supplier = 1 - OR S.active = 1 - ) - ; - END IF; - END IF; - - DELETE FROM tmp_Split; - - -- Permissions - IF a_debug = 1 THEN - SELECT - v_guid - , a_id_user - , FALSE -- get inactive users - , v_id_permission_supplier - , v_id_access_level_view - , '' -- ids_product - , 0 -- a_debug - ; - SELECT * from Shop_Calc_User_Temp; - END IF; - - CALL p_shop_calc_user( - v_guid - , a_id_user - , FALSE -- get inactive users - , v_id_permission_supplier - , v_id_access_level_view - , '' -- ids_product - , 0 -- a_debug - ); - - IF a_debug = 1 THEN - SELECT * from Shop_Calc_User_Temp; - END IF; - - IF NOT EXISTS (SELECT can_view FROM Shop_Calc_User_Temp UE_T WHERE UE_T.GUID = v_guid) THEN - DELETE FROM tmp_Msg_Error; - - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - VALUES ( - v_id_type_error_no_permission - , v_code_type_error_no_permission - , CONCAT('You do not have view permissions for ', (SELECT name FROM Shop_Permission WHERE id_permission = v_id_permission_supplier LIMIT 1)) - ) - ; - END IF; - - IF EXISTS ( SELECT * FROM tmp_Msg_Error LIMIT 1 ) THEN - DELETE FROM tmp_Supplier; - END IF; - - -- Returns - -- Suppliers - SELECT - t_S.id_supplier, - S.id_currency, - C.code AS code_currency, - C.symbol AS symbol_currency, - S.name_company, - S.name_contact, - S.department_contact, - S.phone_number, - S.fax, - S.email, - S.website, - S.active - FROM tmp_Supplier t_S - INNER JOIN partsltd_prod.Shop_Supplier S ON t_S.id_supplier = S.id_supplier - LEFT JOIN partsltd_prod.Shop_Currency C ON S.id_currency = C.id_currency - ; - - -- Supplier Addresses - SELECT - t_S.id_supplier - , SA.id_address - , SA.id_region - , R.name AS name_region - , SA.postcode - , SA.address_line_1 - , SA.address_line_2 - , SA.city - , SA.county - , SA.active - FROM tmp_Supplier t_S - INNER JOIN partsltd_prod.Shop_Supplier S ON t_S.id_supplier = S.id_supplier - INNER JOIN partsltd_prod.Shop_Supplier_Address SA ON S.id_supplier = SA.id_supplier - LEFT JOIN partsltd_prod.Shop_Region R ON SA.id_region = R.id_region - ; - - -- Errors - SELECT * - FROM tmp_Msg_Error t_ME - INNER JOIN partsltd_prod.Shop_Msg_Error_Type MET ON t_ME.id_type = MET.id_type - ; - - IF a_debug = 1 THEN - SELECT * from tmp_Supplier; - END IF; - - DROP TEMPORARY TABLE IF EXISTS tmp_Supplier; - DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error; - DROP TEMPORARY TABLE IF EXISTS tmp_Split; - - IF a_debug = 1 THEN - CALL p_debug_timing_reporting( v_time_start ); - END IF; -END // -DELIMITER ; - - -/* - -CALL p_shop_get_many_supplier ( - 1 -- 'auth0|6582b95c895d09a70ba10fef' -- a_id_user - , 1 -- a_get_all_supplier - , 0 -- a_get_inactive_supplier - , '' -- a_ids_supplier - , 0 -- a_debug -); - -*/ \ No newline at end of file diff --git a/static/MySQL/7403_p_shop_save_supplier_purchase_order.sql b/static/MySQL/7403_p_shop_save_supplier_purchase_order.sql deleted file mode 100644 index cec3c8dd..00000000 --- a/static/MySQL/7403_p_shop_save_supplier_purchase_order.sql +++ /dev/null @@ -1,900 +0,0 @@ - - - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_save_supplier_purchase_order; - -DROP TABLE IF EXISTS tmp_Supplier_Purchase_Order_Product_Link; -DROP TABLE IF EXISTS tmp_Msg_Error; - -DELIMITER // -CREATE PROCEDURE p_shop_save_supplier_purchase_order ( - IN a_comment VARCHAR(500) - , IN a_guid BINARY(36) - , IN a_id_user INT - , IN a_debug BIT -) -BEGIN - DECLARE v_code_type_error_bad_data VARCHAR(50); - DECLARE v_code_type_error_no_permission VARCHAR(50); - DECLARE v_code_type_error_warning VARCHAR(50); - DECLARE v_id_access_level_edit INT; - DECLARE v_id_change_set INT; - DECLARE v_id_permission_supplier_purchase_order VARCHAR(100); - DECLARE v_id_type_error_bad_data INT; - DECLARE v_id_type_error_no_permission INT; - DECLARE v_id_type_error_warning INT; - DECLARE v_ids_product_permission TEXT; - DECLARE v_time_start TIMESTAMP(6); - - DECLARE exit handler for SQLEXCEPTION - BEGIN - GET DIAGNOSTICS CONDITION 1 - @sqlstate = RETURNED_SQLSTATE - , @errno = MYSQL_ERRNO - , @text = MESSAGE_TEXT - ; - - ROLLBACK; - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT - , id_type INT NULL - , code VARCHAR(50) NOT NULL - , msg VARCHAR(4000) NOT NULL - ); - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - MET.id_type - , @errno - , @text - FROM partsltd_prod.Shop_Msg_Error_Type MET - WHERE code = 'MYSQL_ERROR' - ; - SELECT * - FROM tmp_Msg_Error; - DROP TABLE IF EXISTS tmp_Msg_Error; - END; - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_code_type_error_bad_data := (SELECT code FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1); - SET v_id_type_error_bad_data := (SELECT id_type FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = v_code_type_error_bad_data LIMIT 1); - SET v_code_type_error_no_permission := (SELECT code FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = 'NO_PERMISSION' LIMIT 1); - SET v_id_type_error_no_permission := (SELECT id_type FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = v_code_type_error_no_permission LIMIT 1); - SET v_code_type_error_warning := (SELECT code FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = 'WARNING' LIMIT 1); - SET v_id_type_error_warning := (SELECT id_type FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = v_code_type_error_warning LIMIT 1); - SET v_id_permission_supplier_purchase_order := (SELECT GROUP_CONCAT(id_permission SEPARATOR ',') FROM partsltd_prod.Shop_Permission WHERE code IN ('STORE_SUPPLIER', 'STORE_SUPPLIER_PURCHASE_ORDER', 'STORE_PRODUCT')); - SET v_id_access_level_edit := (SELECT id_access_level FROM partsltd_prod.Shop_Access_Level WHERE code = 'EDIT' LIMIT 1); - - CALL p_validate_guid ( a_guid ); - SET a_comment := TRIM(IFNULL(a_comment, '')); - - DROP TEMPORARY TABLE IF EXISTS tmp_Supplier_Purchase_Order; - DROP TEMPORARY TABLE IF EXISTS tmp_Supplier_Purchase_Order_Product_Link; - DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error; - - -- Temporary tables - CREATE TEMPORARY TABLE tmp_Supplier_Purchase_Order ( - id_order INT NOT NULL PRIMARY KEY - , id_order_temp INT NOT NULL - , id_supplier_ordered INT NOT NULL - , id_currency_cost INT NOT NULL - , cost_total_local_VAT_excl FLOAT NULL - , cost_total_local_VAT_incl FLOAT NULL - , active BIT NOT NULL - , is_new BIT NOT NULL - , name_error VARCHAR(1000) NOT NULL - ); - - CREATE TEMPORARY TABLE tmp_Supplier_Purchase_Order_Product_Link ( - id_link INT NOT NULL PRIMARY KEY - , id_order INT NOT NULL - , id_permutation INT NOT NULL - , id_product INT - -- , id_currency_cost INT NOT NULL - , quantity_ordered FLOAT NOT NULL - , id_unit_quantity INT NOT NULL - , quantity_received FLOAT NULL - , latency_delivery_days INT NOT NULL - , display_order INT NOT NULL - , active BIT NOT NULL - , cost_total_local_VAT_excl FLOAT NOT NULL - , cost_total_local_VAT_incl FLOAT NOT NULL - , cost_unit_local_VAT_excl FLOAT NOT NULL - , cost_unit_local_VAT_incl FLOAT NOT NULL - , has_order BIT NULL - , is_new BIT NOT NULL - , name_error VARCHAR(1000) NULL - , can_edit BIT - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT - , id_type INT NOT NULL - , code VARCHAR(50) NOT NULL - , msg VARCHAR(4000) NOT NULL - ); - - INSERT INTO tmp_Supplier_Purchase_Order ( - id_order - , id_order_temp - , id_supplier_ordered - , id_currency_cost - , active - , is_new - , name_error - ) - SELECT - SPO_T.id_order - , SPO_T.id_order - , IFNULL(IFNULL(SPO_T.id_supplier_ordered, SPO.id_supplier_ordered), 0) AS id_supplier_ordered - , IFNULL(IFNULL(SPO_T.id_currency_cost, SPO.id_currency_cost), 0) AS id_currency_cost - , IFNULL(IFNULL(SPO_T.active, SPO.active), 1) AS active - , ISNULL(SPO.id_order) AS is_new - , CONCAT( - IFNULL(S.name_company, '(No Supplier)') - , ' - ' - , IFNULL(SPO.created_on, '(No creation date)') - , ' - ' - , IFNULL(C.symbol, '(No Currency)') - , ' ' - , IFNULL(IFNULL(SPO.cost_total_local_vat_excl, SPO.cost_total_local_vat_incl), '(No cost)') - ) AS name_error - FROM partsltd_prod.Shop_Supplier_Purchase_Order_Temp SPO_T - LEFT JOIN partsltd_prod.Shop_Supplier_Purchase_Order SPO ON SPO_T.id_order = SPO.id_order - LEFT JOIN partsltd_prod.Shop_Supplier S ON SPO_T.id_supplier_ordered = S.id_supplier - LEFT JOIN partsltd_prod.Shop_Currency C ON SPO_T.id_currency_cost = C.id_currency - WHERE SPO_T.GUID = a_guid - ; - - INSERT INTO tmp_Supplier_Purchase_Order_Product_Link ( - id_link - , id_order - , id_permutation - -- , id_currency_cost - , id_unit_quantity - , quantity_ordered - , quantity_received - , latency_delivery_days - , display_order - , cost_total_local_VAT_excl - , cost_total_local_VAT_incl - , cost_unit_local_VAT_excl - , cost_unit_local_VAT_incl - , active - , has_order - , is_new - ) - SELECT - IFNULL(SPOPL_T.id_link, 0) AS id_link - , IFNULL(IFNULL(SPOPL_T.id_order, SPOPL.id_order), 0) AS id_order - , IFNULL( - IFNULL( - IFNULL( - SPOPL_T.id_permutation - , CASE WHEN NOT ISNULL(SPOPL_T.id_product) AND NOT ISNULL(SPOPL_T.csv_list_variations) THEN - partsltd_prod.fn_shop_get_id_product_permutation_from_variation_csv_list(SPOPL_T.id_product, SPOPL_T.csv_list_variations) - ELSE NULL END - ) - , SPOPL.id_permutation - ) - , 0 - ) AS id_permutation - -- , IFNULL(IFNULL(SPOPL_T.id_currency_cost, SPOPL.id_currency_cost), 0) AS id_currency_cost - , IFNULL(IFNULL(SPOPL_T.id_unit_quantity, SPOPL.id_unit_quantity), 0) AS id_unit_quantity - , IFNULL(IFNULL(SPOPL_T.quantity_ordered, SPOPL.quantity_ordered), 0) AS quantity_ordered - , IFNULL(SPOPL_T.quantity_received, SPOPL.quantity_received) AS quantity_received - , IFNULL(SPOPL_T.latency_delivery_days, SPOPL.latency_delivery_days) AS latency_delivery_days - , RANK() OVER (PARTITION BY IFNULL(IFNULL(SPOPL_T.id_order, SPOPL.id_order), 0) ORDER BY IFNULL(IFNULL(SPOPL_T.display_order, SPOPL.display_order), 0)) AS display_order - , IFNULL(IFNULL(SPOPL_T.cost_total_local_VAT_excl, SPOPL.cost_total_local_VAT_excl), 0) AS cost_total_local_VAT_excl - , IFNULL(IFNULL(SPOPL_T.cost_total_local_VAT_incl, SPOPL.cost_total_local_VAT_incl), 0) AS cost_total_local_VAT_incl - /* - , IFNULL(SPOPL_T.cost_total_local_VAT_excl / SPOPL_T.quantity_ordered, SPOPL.cost_unit_local_VAT_excl) AS cost_unit_local_VAT_excl - , IFNULL(SPOPL_T.cost_total_local_VAT_incl / SPOPL_T.quantity_ordered, SPOPL.cost_unit_local_VAT_incl) AS cost_unit_local_VAT_incl - */ - , IFNULL(IFNULL(SPOPL_T.active, SPOPL.active), 1) AS active - , NOT ISNULL(t_SPO.id_order) AS has_order - , IFNULL(SPOPL_T.id_link, 0) < 1 AS is_new - FROM partsltd_prod.Shop_Supplier_Purchase_Order_Product_Link_Temp SPOPL_T - LEFT JOIN partsltd_prod.Shop_Supplier_Purchase_Order_Product_Link SPOPL ON SPOPL_T.id_link = SPOPL.id_link - LEFT JOIN tmp_Supplier_Purchase_Order t_SPO ON SPOPL_T.id_order = t_SPO.id_order - WHERE SPOPL_T.GUID = a_guid - ; - - UPDATE tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - LEFT JOIN partsltd_prod.Shop_Supplier_Purchase_Order_Product_Link_Temp SPOPL_T - ON t_SPOPL.id_link = SPOPL_T.id_link - AND t_SPOPL.GUID = a_guid - LEFT JOIN partsltd_prod.Shop_Supplier_Purchase_Order_Product_Link SPOPL ON t_SPOPL.id_link = SPOPL.id_link - LEFT JOIN partsltd_prod.Shop_Product_Permutation PP ON t_SPOPL.id_permutation = PP.id_permutation - LEFT JOIN partsltd_prod.Shop_Product P ON SPOPL_T.id_product = P.id_product - LEFT JOIN partsltd_prod.Shop_Product_Category PC ON P.id_category = PC.id_category - SET - t_SPOPL.id_product = IFNULL(P.id_product, SPOPL_T.id_product) - , t_SPOPL.name_error = CONCAT( - CASE WHEN ISNULL(t_SPOPL.id_permutation) THEN - CASE WHEN ISNULL(P.id_product) THEN - '(No Product Permutation)' - ELSE - CONCAT( - PC.name - , ' - ' - , P.name - ) - END - ELSE - fn_shop_get_product_permutation_name(t_SPOPL.id_permutation) - END - , ' - x' - , IFNULL(t_SPOPL.quantity_ordered, '(No Quantity)') - ) - , t_SPOPL.cost_unit_local_VAT_excl = t_SPOPL.cost_total_local_VAT_excl / t_SPOPL.quantity_ordered - , t_SPOPL.cost_unit_local_VAT_incl = t_SPOPL.cost_total_local_VAT_incl / t_SPOPL.quantity_ordered - , t_SPOPL.delta_quantity_ordered = t_SPOPL.quantity_ordered - IFNULL(SPOPL.quantity_ordered, 0) - , t_SPOPL.delta_quantity_received = t_SPOPL.quantity_received - IFNULL(SPOPL.quantity_received, 0) - ; - - INSERT INTO tmp_Supplier_Purchase_Order ( - id_order - , id_order_temp - , id_supplier_ordered - , id_currency_cost - , active - , is_new - ) - SELECT - SPO.id_order - , SPO.id_order - , IFNULL(SPO.id_supplier_ordered, 0) AS id_supplier_ordered - , IFNULL(SPO.id_currency_cost, 0) AS id_currency_cost - , SPO.active AS active - , 0 AS is_new - FROM partsltd_prod.Shop_Supplier_Purchase_Order SPO - INNER JOIN tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - ON SPO.id_order = t_SPOPL.id_order - AND t_SPOPL.has_order = 0 - ; - - UPDATE tmp_Supplier_Purchase_Order t_SPO - INNER JOIN ( - SELECT - t_SPOPL.id_order - , SUM(t_SPOPL.cost_total_local_VAT_excl) AS cost_total_local_VAT_excl - , SUM(t_SPOPL.cost_total_local_VAT_incl) AS cost_total_local_VAT_incl - FROM tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - GROUP BY t_SPOPL.id_order - ) SUM_t_SPOPL ON t_SPO.id_order = SUM_t_SPOPL.id_order - SET - t_SPO.cost_total_local_VAT_excl = SUM_t_SPOPL.cost_total_local_VAT_excl - , t_SPO.cost_total_local_VAT_incl = SUM_t_SPOPL.cost_total_local_VAT_incl - ; - - -- Validation - -- Supplier Purchase Order - -- id_order - IF EXISTS ( - SELECT * - FROM tmp_Supplier_Purchase_Order t_SPO - LEFT JOIN partsltd_prod.Shop_Supplier_Purchase_Order SPO ON t_SPO.id_order = SPO.id_order - WHERE 1=1 - AND t_SPO.id_order > 0 - AND ISNULL(SPO.id_order) - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT( - 'A valid ID is required for the following Supplier Purchase Order(s): ' - , GROUP_CONCAT(CONCAT(IFNULL(t_SPO.id_stock, '(No Supplier Purchase Order)')) SEPARATOR ', ') - ) AS msg - FROM tmp_Supplier_Purchase_Order t_SPO - LEFT JOIN partsltd_prod.Shop_Supplier_Purchase_Order SPO ON t_SPO.id_order = SPO.id_order - WHERE 1=1 - AND t_SPO.id_stock > 0 - AND ISNULL(SPO.id_stock) - ; - END IF; - -- id_supplier_ordered - IF EXISTS ( - SELECT * - FROM tmp_Supplier_Purchase_Order t_SPO - LEFT JOIN partsltd_prod.Shop_Supplier S ON t_SPO.id_supplier_ordered = S.id_supplier - WHERE 1=1 - AND ( - ISNULL(S.id_supplier) - OR S.active = 0 - ) - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT( - 'A valid supplier is required for the following Supplier Purchase Order(s): ' - , GROUP_CONCAT(CONCAT(IFNULL(t_SPO.id_stock, '(No Supplier Purchase Order)'), ' - ', t_SPO.id_supplier_ordered) SEPARATOR ', ') - ) AS msg - FROM tmp_Supplier_Purchase_Order t_SPO - LEFT JOIN partsltd_prod.Shop_Supplier S ON t_SPO.id_supplier_ordered = S.id_supplier - WHERE 1=1 - AND ( - ISNULL(S.id_supplier) - OR S.active = 0 - ) - ; - END IF; - -- id_currency_cost - IF EXISTS ( - SELECT * - FROM tmp_Supplier_Purchase_Order t_SPO - LEFT JOIN partsltd_prod.Shop_Currency C ON t_SPO.id_currency_cost = C.id_currency - WHERE 1=1 - AND ( - ISNULL(C.id_currency) - OR C.active = 0 - ) - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT( - 'A valid currency is required for the following Supplier Purchase Order(s): ' - , GROUP_CONCAT(CONCAT(IFNULL(t_SPO.id_stock, '(No Supplier Purchase Order)'), ' - ', t_SPO.id_currency_cost) SEPARATOR ', ') - ) AS msg - FROM tmp_Supplier_Purchase_Order t_SPO - LEFT JOIN partsltd_prod.Shop_Currency C ON t_SPO.id_currency_cost = C.id_currency - WHERE 1=1 - AND ( - ISNULL(C.id_currency) - OR C.active = 0 - ) - ; - END IF; - -- id_unit_quantity - IF EXISTS ( - SELECT * - FROM tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - LEFT JOIN partsltd_prod.Shop_Unit_Measurement UM ON t_SPOPL.id_unit_quantity = UM.id_unit_measurement - WHERE 1=1 - AND ( - ISNULL(UM.id_unit_measurement) - OR UM.active = 0 - ) - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT( - 'A valid unit measurement of quantity is required for the following Supplier Purchase Order(s): ' - , GROUP_CONCAT(CONCAT(IFNULL(t_SPO.id_stock, '(No Supplier Purchase Order)'), ' - ', t_SPO.id_currency_cost) SEPARATOR ', ') - ) AS msg - FROM tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - LEFT JOIN partsltd_prod.Shop_Unit_Measurement UM ON t_SPOPL.id_unit_quantity = UM.id_unit_measurement - WHERE 1=1 - AND ( - ISNULL(UM.id_unit_measurement) - OR UM.active = 0 - ) - ; - END IF; - -- Invalid quantity ordered - IF EXISTS ( - SELECT * - FROM tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - WHERE - ISNULL(t_SPOPL.quantity_ordered) - OR t_SPOPL.quantity_ordered <= 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, code, msg - ) - SELECT - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT( - 'A valid quantity ordered is required for the following Supplier Purchase Order Item(s): ' - , GROUP_CONCAT(t_SPOPL.name_error SEPARATOR ', ') - ) - FROM tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - WHERE - ISNULL(t_SPOPL.quantity_ordered) - OR t_SPOPL.quantity_ordered <= 0 - ; - END IF; - -- Invalid quantity received - IF EXISTS ( - SELECT * - FROM tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - WHERE t_SPOPL.quantity_received < 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, code, msg - ) - SELECT - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT( - 'A valid quantity received is required for the following Supplier Purchase Order Item(s): ' - , GROUP_CONCAT(t_SPOPL.name_error, ' - ', t_SPOPL.quantity_received SEPARATOR ', ') - ) - FROM tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - WHERE t_SPOPL.quantity_received < 0 - ; - END IF; - -- Invalid delivery latency - IF EXISTS ( - SELECT * - FROM tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - WHERE t_SPOPL.latency_delivery_days < 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, code, msg - ) - SELECT - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT( - 'A valid delivery latency is required for the following Supplier Purchase Order Item(s): ' - , GROUP_CONCAT(t_SPOPL.name_error, ' - ', t_SPOPL.latency_delivery_days SEPARATOR ', ') - ) - FROM tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - WHERE t_SPOPL.latency_delivery_days < 0 - ; - END IF; - - -- Duplicates - IF EXISTS ( - SELECT - id_permutation - , name_error - , COUNT(*) - FROM tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - GROUP BY id_permutation, name_error - HAVING COUNT(*) > 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, code, msg - ) - SELECT - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Duplicate records: ', GROUP_CONCAT(t_SPOPLC.name_error SEPARATOR ', ')) - FROM ( - SELECT - id_permutation - , name_error - , COUNT(*) - FROM tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - GROUP BY id_permutation, name_error - HAVING COUNT(*) > 1 - ) t_SPOPLC - ; - END IF; - -- Empty Supplier Purchase Order - IF EXISTS ( SELECT * FROM tmp_Supplier_Purchase_Order t_SPO LEFT JOIN tmp_Supplier_Purchase_Order_Product_Link t_SPOPL ON t_SPO.id_order = t_SPOPL.id_order WHERE ISNULL(t_SPOPL.id_order) ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, code, msg - ) - SELECT - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT( - 'There are no items in the following Supplier Purchase Order(s): ' - , GROUP_CONCAT(t_SPO.name_error SEPARATOR ', ') - ) AS msg - FROM tmp_Supplier_Purchase_Order t_SPO - LEFT JOIN tmp_Supplier_Purchase_Order_Product_Link t_SPOPL ON t_SPO.id_order = t_SPOPL.id_order - WHERE ISNULL(t_SPOPL.id_order) - ; - END IF; - - -- Supplier Purchase Order Items without Order - IF EXISTS ( - SELECT * - FROM tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - LEFT JOIN tmp_Supplier_Purchase_Order t_SPO ON t_SPOPL.id_order = t_SPO.id_order - WHERE ISNULL(t_SPO.id_order) - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, code, msg - ) - SELECT - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT( - 'There is no order for the following Supplier Purchase Order Item(s): ' - , GROUP_CONCAT(t_SPOPL.name_error SEPARATOR ', ') - ) AS msg - FROM tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - LEFT JOIN tmp_Supplier_Purchase_Order t_SPO ON t_SPOPL.id_order = t_SPO.id_order - WHERE ISNULL(t_SPO.id_order) - ; - END IF; - - -- Permissions - SET v_ids_product_permission := ( - SELECT - GROUP_CONCAT(DISTINCT PP.id_product SEPARATOR ',') - FROM tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - INNER JOIN partsltd_prod.Shop_Product_Permutation PP ON t_SPOPL.id_permutation = PP.id_permutation - ); - IF a_debug = 1 THEN - SELECT - a_guid - , a_id_user - , FALSE -- get inactive users - , v_id_permission_supplier_purchase_order - , v_id_access_level_edit - , v_ids_product_permission -- ids_product - , 0 -- a_debug - ; - SELECT * from partsltd_prod.Shop_Calc_User_Temp; - END IF; - - CALL p_shop_calc_user( - a_guid - , a_id_user - , FALSE -- get inactive users - , v_id_permission_supplier_purchase_order - , v_id_access_level_edit - , v_ids_product_permission -- ids_product - , 0 -- a_debug - ); - - IF a_debug = 1 THEN - SELECT * from partsltd_prod.Shop_Calc_User_Temp WHERE GUID = a_guid; - END IF; - - UPDATE tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - INNER JOIN partsltd_prod.Shop_Calc_User_Temp CUT - ON t_SPOPL.id_product = t_SPOPL.id_product - AND CUT.GUID = a_guid - SET - t_SPOPL.can_edit = CUT.can_edit - ; - - IF EXISTS (SELECT * FROM tmp_Supplier_Purchase_Order_Product_Link WHERE can_edit = 0) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_no_permission - , v_code_type_error_no_permission - , CONCAT( - 'You do not permissions to edit the following Product(s): ' - , GROUP_CONCAT(P.name SEPARATOR ', ') - ) AS msg - FROM tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - INNER JOIN partsltd_prod.Shop_Product P ON t_SPOPL.id_product = P.id_product - WHERE - t_SPOPL.is_new = 0 - AND t_SPOPL.can_view = 0 - ; - END IF; - - IF EXISTS (SELECT * FROM tmp_Supplier_Purchase_Order_Product_Link WHERE is_new = 0 AND can_edit = 0 LIMIT 1) THEN - DELETE FROM tmp_Msg_Error; - - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_no_permission - , v_code_type_error_no_permission - , CONCAT( - 'You are missing the following permissions with access level ' - , AL.name - , ': ' - , GROUP_CONCAT(PERM.name SEPARATOR ', ') - ) AS msg - FROM partsltd_prod.Shop_Access_Level AL - CROSS JOIN partsltd_prod.Shop_Calc_User_Temp CU_T - ON CU_T.GUID = a_guid - AND ISNULL(CU_T.id_product) - AND IFNULL(CU_T.can_edit, 0) = 0 - ; - END IF; - - CALL partsltd_prod.p_shop_clear_calc_user( - a_guid - , 0 -- a_debug - ); - - IF EXISTS ( - SELECT * - FROM tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - INNER JOIN partsltd_prod.Shop_Supplier_Purchase_Order_Product_Link SPOPL ON t_SPOPL.id_link = SPOPL.id_link - INNER JOIN partsltd_prod.Shop_Stock_Item SI ON SPOPL.id_permutation = SI.id_permutation - WHERE - t_SPOPL.is_new = 0 - AND t_SPOPL.quantity_received <> SPOPL.quantity_received - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_warning - , v_code_type_error_warning - , CONCAT( - 'The quantity received has changed on the following orders. Please update the stock items appropriately.' - , GROUP_CONCAT( - CONCAT( - t_SPOPL.name_error - , ' - from ' - , SPOPL.quantity_received - , ' to ' - , t_SPOPL.quantity_received - ) SEPARATOR ', ' - ) - ) AS msg - ; - END IF; - - IF EXISTS ( SELECT * FROM tmp_Msg_Error LIMIT 1 ) THEN - DELETE FROM tmp_Supplier_Purchase_Order; - DELETE FROM tmp_Supplier_Purchase_Order_Product_Link; - END IF; - - -- Transaction - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - START TRANSACTION; - INSERT INTO Shop_Sales_And_Purchasing_Change_Set ( - comment - , updated_last_by - , updated_last_on - ) - VALUES ( - a_comment - , a_id_user - , v_time_start - ); - - SET v_id_change_set := LAST_INSERT_ID(); - - INSERT INTO partsltd_prod.Shop_Supplier_Purchase_Order ( - id_order_temp - , id_supplier_ordered - , id_currency_cost - , cost_total_local_VAT_excl - , cost_total_local_VAT_incl - , active - , created_by - , created_on - , id_change_set - ) - SELECT - t_SPO.id_order_temp - , t_SPO.id_supplier_ordered - , t_SPO.id_currency_cost - , t_SPO.cost_total_local_VAT_excl - , t_SPO.cost_total_local_VAT_incl - , t_SPO.active - , a_id_user - , v_time_start - , v_id_change_set - FROM tmp_Supplier_Purchase_Order t_SPO - INNER JOIN tmp_Supplier_Purchase_Order_Product_Link t_SPOPL ON t_SPO.id_order = t_SPOPL.id_order - WHERE t_SPOPL.is_new = 1 - GROUP BY t_SPO.id_order - ; - - UPDATE partsltd_prod.Shop_Supplier_Purchase_Order SPO - INNER JOIN tmp_Supplier_Purchase_Order t_SPO - ON SPO.id_order = t_SPO.id_order - AND t_SPO.is_new = 0 - INNER JOIN tmp_Supplier_Purchase_Order_Product_Link t_SPOPL ON t_SPO.id_order = t_SPOPL.id_order - SET - SPO.id_supplier_ordered = t_SPO.id_supplier_ordered - , SPO.id_currency_cost = t_SPO.id_currency_cost - , SPO.cost_total_local_VAT_excl = t_SPO.cost_total_local_VAT_excl - , SPO.cost_total_local_VAT_incl = t_SPO.cost_total_local_VAT_incl - , SPO.active = t_SPO.active - , SPO.id_change_set = v_id_change_set - ; - - - UPDATE tmp_Supplier_Purchase_Order t_SPO - INNER JOIN partsltd_prod.Shop_Supplier_Purchase_Order SPO - ON t_SPO.id_order_temp = SPO.id_order_temp - AND SPO.id_change_set = v_id_change_set - SET - t_SPO.id_order = SPO.id_order - WHERE t_SPO.is_new = 1 - ; - - UPDATE tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - INNER JOIN tmp_Supplier_Purchase_Order t_SPO ON t_SPOPL.id_order = t_SPO.id_order_temp - SET - t_SPOPL.id_order = t_SPO.id_order - WHERE t_SPO.is_new = 1 - ; - - - INSERT INTO Shop_Supplier_Purchase_Order_Product_Link ( - id_order - , id_permutation - , id_unit_quantity - , quantity_ordered - , quantity_received - , latency_delivery_days - , display_order - , active - , cost_total_local_VAT_excl - , cost_total_local_VAT_incl - , cost_unit_local_VAT_excl - , cost_unit_local_VAT_incl - , created_by - , created_on - , id_change_set - ) - SELECT - t_SPOPL.id_order - , t_SPOPL.id_permutation - , t_SPOPL.id_unit_quantity - , t_SPOPL.quantity_ordered - , t_SPOPL.quantity_received - , t_SPOPL.latency_delivery_days - , t_SPOPL.display_order - , t_SPOPL.active - , t_SPOPL.cost_total_local_VAT_excl - , t_SPOPL.cost_total_local_VAT_incl - , t_SPOPL.cost_unit_local_VAT_excl - , t_SPOPL.cost_unit_local_VAT_incl - , a_id_user - , v_time_start - , v_id_change_set - FROM tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - WHERE t_SPOPL.is_new = 1 - ; - - UPDATE partsltd_prod.Shop_Supplier_Purchase_Order_Product_Link SPOPL - INNER JOIN tmp_Supplier_Purchase_Order_Product_Link t_SPOPL - ON SPOPL.id_link = t_SPOPL.id_link - AND t_SPOPL.is_new = 0 - SET - SPOPL.id_order = t_SPOPL.id_order - , SPOPL.id_permutation = t_SPOPL.id_permutation - , SPOPL.id_unit_quantity = t_SPOPL.id_unit_quantity - , SPOPL.quantity_ordered = t_SPOPL.quantity_ordered - , SPOPL.quantity_received = t_SPOPL.quantity_received - , SPOPL.latency_delivery_days = t_SPOPL.latency_delivery_days - , SPOPL.display_order = t_SPOPL.display_order - , SPOPL.active = t_SPOPL.active - , SPOPL.cost_total_local_VAT_excl = t_SPOPL.cost_total_local_VAT_excl - , SPOPL.cost_total_local_VAT_incl = t_SPOPL.cost_total_local_VAT_incl - , SPOPL.cost_unit_local_VAT_excl = t_SPOPL.cost_unit_local_VAT_excl - , SPOPL.cost_unit_local_VAT_incl = t_SPOPL.cost_unit_local_VAT_incl - , SPOPL.id_change_set = v_id_change_set - ; - - COMMIT; - END IF; - - START TRANSACTION; - - DELETE SPO_T - FROM Shop_Supplier_Purchase_Order_Temp SPO_T - WHERE SPO_T.GUID = a_guid - ; - DELETE SPOPL_T - FROM Shop_Supplier_Purchase_Order_Product_Link_Temp SPOPL_T - WHERE SPOPL_T.GUID = a_guid - ; - - COMMIT; - - -- Errors - SELECT * - FROM tmp_Msg_Error t_ME - INNER JOIN partsltd_prod.Shop_Msg_Error_Type MET ON t_ME.id_type = MET.id_type - ; - - IF a_debug = 1 THEN - SELECT * from tmp_Supplier_Purchase_Order; - SELECT * from tmp_Supplier_Purchase_Order_Product_Link; - END IF; - - DROP TEMPORARY TABLE tmp_Supplier_Purchase_Order; - DROP TEMPORARY TABLE tmp_Supplier_Purchase_Order_Product_Link; - DROP TEMPORARY TABLE tmp_Msg_Error; - - IF a_debug = 1 THEN - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); - END IF; -END // -DELIMITER ; - - -/* - -DELETE FROM Shop_Supplier_Purchase_Order_Product_Link_Audit; -DELETE FROM Shop_Supplier_Purchase_Order_Product_Link; -DELETE FROM Shop_Supplier_Purchase_Order_Product_Link_Temp; -DELETE FROM Shop_Supplier_Purchase_Order_Audit; -DELETE FROM Shop_Supplier_Purchase_Order; - -INSERT INTO Shop_Supplier_Purchase_Order_Product_Link_Temp ( - guid, - id_link, - id_order, - id_permutation, - cost_total_local, - id_currency_cost, - quantity_ordered, - id_unit_quantity, - quantity_received, - latency_delivery_days, - display_order, - active -) -VALUES - ( - 'NIPS', -- guid - -1, -- id_link, - -1, -- id_order, - 1, -- id_permutation, - 100, -- cost_total_local, - 1, -- id_currency_cost, - 1, -- quantity_ordered, - 1, -- id_unit_quantity, - 1, -- quantity_received, - 14, -- latency_delivery_days , - 1, -- display_order - 1 -- active - ) -; - -SELECT * FROM Shop_Supplier_Purchase_Order_Product_Link_Temp; - -CALL p_shop_save_supplier_purchase_order ( - 'NIPS', -- a_guid - 'auth0|6582b95c895d09a70ba10fef', -- a_id_user - -1, -- a_id_order - 1, -- a_id_supplier_ordered - 1 -- a_id_currency_cost -); - -SELECT * FROM Shop_Supplier_Purchase_Order_Product_Link_Temp; - -DELETE FROM Shop_Supplier_Purchase_Order_Product_Link_Audit; -DELETE FROM Shop_Supplier_Purchase_Order_Product_Link; -DELETE FROM Shop_Supplier_Purchase_Order_Product_Link_Temp; -DELETE FROM Shop_Supplier_Purchase_Order_Audit; -DELETE FROM Shop_Supplier_Purchase_Order; - - -*/ - diff --git a/static/MySQL/7403_p_shop_save_supplier_purchase_order_test.sql b/static/MySQL/7403_p_shop_save_supplier_purchase_order_test.sql deleted file mode 100644 index f7d73755..00000000 --- a/static/MySQL/7403_p_shop_save_supplier_purchase_order_test.sql +++ /dev/null @@ -1,155 +0,0 @@ - - --- Clear previous proc -DROP PROCEDURE IF EXISTS partsltd_prod.p_shop_save_supplier_purchase_order_test; - - -DELIMITER // -CREATE PROCEDURE p_shop_save_supplier_purchase_order_test () -BEGIN - - DECLARE v_guid BINARY(36); - DECLARE v_time_start TIMESTAMP(6); - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_guid := 'nips'; - - SELECT * - FROM partsltd_prod.Shop_Supplier_Purchase_Order - ; - SELECT * - FROM partsltd_prod.Shop_Supplier_Purchase_Order_Temp - ; - SELECT * - FROM partsltd_prod.Shop_Supplier_Purchase_Order_Product_Link - ; - SELECT * - FROM partsltd_prod.Shop_Supplier_Purchase_Order_Product_Link_Temp - ; - - START TRANSACTION; - - DELETE FROM partsltd_prod.Shop_Supplier_Purchase_Order_Temp; - DELETE FROM partsltd_prod.Shop_Supplier_Purchase_Order_Product_Link_Temp; - - INSERT INTO partsltd_prod.Shop_Supplier_Purchase_Order_Temp ( - id_order - , id_supplier_ordered - , id_currency_cost - , active - , GUID - ) - /* Test 1 - Insert */ - VALUES ( - -1 - , 1 - , 1 - , 1 - , v_guid - ) - /* Test 2 - Update - SELECT - id_order - , id_supplier_ordered - , id_currency_cost - , active - , v_guid - FROM partsltd_prod.Shop_Supplier_Purchase_Order - WHERE id_order = 6 - */ - ; - INSERT INTO partsltd_prod.Shop_Supplier_Purchase_Order_Product_Link_Temp ( - id_link - , id_order - , id_permutation - , id_unit_quantity - , quantity_ordered - , quantity_received - , latency_delivery_days - , display_order - , active - , cost_total_local_VAT_excl - , cost_total_local_VAT_incl - , GUID - ) - /* Test 1 - Insert */ - VALUES ( - -1 - , -1 - , 3 - , 3 - , 3 - , 1 - , 7 - , 1 - , 1 - , 5 - , 6 - , v_guid - ) - /* Test 2 - Update - SELECT - id_link - , id_order - , id_permutation - , id_unit_quantity - , 5 AS quantity_ordered - , quantity_received - , latency_delivery_days - , display_order - , active - , cost_total_local_VAT_excl - , cost_total_local_VAT_incl - , v_guid - FROM partsltd_prod.Shop_Supplier_Purchase_Order_Product_Link - WHERE id_order = 6 - */ - ; - - COMMIT; - - SELECT * - FROM partsltd_prod.Shop_Supplier_Purchase_Order_Temp - WHERE GUID = v_guid - ; - - SELECT * - FROM partsltd_prod.Shop_Supplier_Purchase_Order_Product_Link_Temp - WHERE GUID = v_guid - ; - - CALL partsltd_prod.p_shop_save_supplier_purchase_order ( - 'Test save Supplier Purchase Order' -- comment - , v_guid -- guid - , 1 -- id_user - , 1 -- debug - ); - - SELECT * - FROM partsltd_prod.Shop_Supplier_Purchase_Order_Temp - ; - SELECT * - FROM partsltd_prod.Shop_Supplier_Purchase_Order_Product_Link_Temp - ; - SELECT * - FROM partsltd_prod.Shop_Supplier_Purchase_Order - ; - SELECT * - FROM partsltd_prod.Shop_Supplier_Purchase_Order_Product_Link - ; - - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); -END // -DELIMITER ; - -/* -CALL partsltd_prod.p_shop_save_supplier_purchase_order_test (); - -DELETE FROM partsltd_prod.Shop_Supplier_Purchase_Order_Temp; -DELETE FROM partsltd_prod.Shop_Supplier_Purchase_Order_Product_Link_Temp; - -DROP TABLE IF EXISTS tmp_Msg_Error; - -Cannot add or update a child row: a foreign key constraint fails (`partsltd_prod`.`shop_supplier_address`, CONSTRAINT `FK_Shop_Supplier_Address_id_supplier` FOREIGN KEY (`id_supplier`) REFERENCES `shop_supplier` (`id_supplier`) ON UPDATE RESTRICT) - -*/ \ No newline at end of file diff --git a/static/MySQL/7404_p_shop_get_many_supplier_purchase_order.sql b/static/MySQL/7404_p_shop_get_many_supplier_purchase_order.sql deleted file mode 100644 index cbe68ae6..00000000 --- a/static/MySQL/7404_p_shop_get_many_supplier_purchase_order.sql +++ /dev/null @@ -1,504 +0,0 @@ - - -DROP PROCEDURE IF EXISTS p_shop_get_many_supplier_purchase_order; - -DELIMITER // -CREATE PROCEDURE p_shop_get_many_supplier_purchase_order ( - IN a_id_user INT, - IN a_get_all_supplier BIT, - IN a_get_inactive_supplier BIT, - IN a_ids_supplier TEXT, - IN a_get_all_order BIT, - IN a_get_inactive_order BIT, - IN a_ids_order TEXT, - IN a_ids_permutation TEXT, - IN a_date_from DATETIME, - IN a_date_to DATETIME, - IN a_debug BIT -) -BEGIN - DECLARE v_code_type_error_bad_data VARCHAR(50); - DECLARE v_code_type_error_no_permission VARCHAR(50); - DECLARE v_guid BINARY(36); - DECLARE v_has_filter_supplier BIT; - DECLARE v_has_filter_order BIT; - DECLARE v_has_filter_permutation BIT; - DECLARE v_has_filter_date_from BIT; - DECLARE v_has_filter_date_to BIT; - DECLARE v_id_access_level_view INT; - DECLARE v_ids_permission_supplier_purchase_order VARCHAR(100); - DECLARE v_id_type_error_bad_data INT; - DECLARE v_id_type_error_no_permission INT; - DECLARE v_time_start TIMESTAMP(6); - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_guid := UUID(); - SET v_id_access_level_view := (SELECT id_access_level FROM partsltd_prod.Shop_Access_Level WHERE code = 'VIEW' LIMIT 1); - SET v_code_type_error_bad_data := (SELECT code FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1); - SET v_id_type_error_bad_data := (SELECT id_type FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = v_code_type_error_bad_data LIMIT 1); - SET v_code_type_error_no_permission := (SELECT code FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = 'NO_PERMISSION' LIMIT 1); - SET v_id_type_error_no_permission := (SELECT id_type FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = v_code_type_error_no_permission LIMIT 1); - SET v_ids_permission_supplier_purchase_order := (SELECT GROUP_CONCAT(id_permission SEPARATOR ',') FROM partsltd_prod.Shop_Permission WHERE code IN ('STORE_SUPPLIER', 'STORE_SUPPLIER_PURCHASE_ORDER', 'STORE_PRODUCT')); - - SET a_get_all_supplier := IFNULL(a_get_all_supplier, 1); - SET a_get_inactive_supplier := IFNULL(a_get_inactive_supplier, 0); - SET a_ids_supplier := TRIM(IFNULL(a_ids_supplier, '')); - SET a_get_all_order := IFNULL(a_get_all_order, 1); - SET a_get_inactive_order := IFNULL(a_get_inactive_order, 0); - SET a_ids_order := TRIM(IFNULL(a_ids_order, '')); - SET a_ids_permutation := TRIM(IFNULL(a_ids_permutation, '')); - SET a_date_from := IFNULL(a_date_from, NULL); - SET a_date_to := IFNULL(a_date_to, NULL); - SET a_debug := IFNULL(a_debug, 0); - - DROP TEMPORARY TABLE IF EXISTS tmp_Supplier_Purchase_Order_Product_Link; - DROP TEMPORARY TABLE IF EXISTS tmp_Supplier_Purchase_Order; - DROP TEMPORARY TABLE IF EXISTS tmp_Supplier; - DROP TEMPORARY TABLE IF EXISTS tmp_Permutation; - DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error; - DROP TEMPORARY TABLE IF EXISTS tmp_Split; - - CREATE TEMPORARY TABLE tmp_Supplier ( - id_supplier INT NOT NULL PRIMARY KEY - ); - - CREATE TEMPORARY TABLE tmp_Supplier_Purchase_Order ( - id_order INT NOT NULL PRIMARY KEY - ); - - CREATE TEMPORARY TABLE tmp_Permutation ( - id_permutation INT NOT NULL PRIMARY KEY - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - id_type INT NOT NULL, - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Split ( - substring VARCHAR(4000) NOT NULL - , as_int INT NULL - ); - DELETE FROM tmp_Split; - - SET v_has_filter_supplier = CASE WHEN a_ids_supplier = '' THEN 0 ELSE 1 END; - SET v_has_filter_order = CASE WHEN a_ids_order = '' THEN 0 ELSE 1 END; - SET v_has_filter_permutation = CASE WHEN a_ids_permutation = '' THEN 0 ELSE 1 END; - SET v_has_filter_date_from = CASE WHEN ISNULL(a_date_from) THEN 0 ELSE 1 END; - SET v_has_filter_date_to = CASE WHEN ISNULL(a_date_to) THEN 0 ELSE 1 END; - - IF a_debug = 1 THEN - SELECT - v_has_filter_supplier, - v_has_filter_order, - v_has_filter_permutation, - v_has_filter_date_from, - v_has_filter_date_to - ; - END IF; - - -- Permutations - IF v_has_filter_permutation = 1 THEN - CALL partsltd_prod.p_split(v_guid, a_ids_permutation, ',', a_debug); - - INSERT INTO tmp_Split ( - substring - , as_int - ) - SELECT - substring - , CONVERT(substring, DECIMAL(10,0)) AS as_int - FROM partsltd_prod.Split_Temp - WHERE 1=1 - AND GUID = v_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( v_guid ); - END IF; - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Product_Permutation PP ON t_S.as_int = PP.id_permutation - WHERE - ISNULL(t_S.as_int) - OR ISNULL(PP.id_permutation) - OR PP.active = 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - code, - msg - ) - SELECT - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Invalid or inactive permutation IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Product_Permutation PP ON t_S.as_int = PP.id_permutation - WHERE - ISNULL(t_S.as_int) - OR ISNULL(PP.id_permutation) - OR PP.active = 0 - ; - ELSE - INSERT INTO tmp_Permutation ( - id_permutation - ) - SELECT - PP.id_permutation - FROM tmp_Split t_S - RIGHT JOIN partsltd_prod.Shop_Product_Permutation PP ON t_S.as_int = PP.id_permutation - WHERE ( - v_has_filter_permutation = 0 - OR NOT ISNULL(t_S.as_int) - ) - ; - END IF; - END IF; - - DELETE FROM tmp_Split; - - -- Suppliers - IF v_has_filter_supplier = 1 THEN - CALL partsltd_prod.p_split(v_guid, a_ids_supplier, ',', a_debug); - - INSERT INTO tmp_Split ( - substring - , as_int - ) - SELECT - substring - , CONVERT(substring, DECIMAL(10,0)) AS as_int - FROM partsltd_prod.Split_Temp - WHERE 1=1 - AND GUID = v_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( v_guid ); - END IF; - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Supplier S ON t_S.as_int = S.id_supplier - WHERE - ISNULL(t_S.as_int) - OR ISNULL(S.id_supplier) - OR ( - S.active = 0 - AND a_get_inactive_supplier = 0 - ) - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - code, - msg - ) - SELECT - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Invalid or inactive Supplier IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Supplier S ON t_S.as_int = S.id_supplier - WHERE - ISNULL(t_S.as_int) - OR ISNULL(S.id_supplier) - OR ( - S.active = 0 - AND a_get_inactive_supplier = 0 - ) - ; - ELSE - INSERT INTO tmp_Supplier ( - id_supplier - ) - SELECT - S.id_supplier - FROM tmp_Split t_S - RIGHT JOIN partsltd_prod.Shop_Supplier S ON t_S.as_int = S.id_supplier - WHERE ( - a_get_all_supplier = 1 - OR ( - v_has_filter_supplier = 1 - AND NOT ISNULL(t_S.as_int) - ) - ) - AND ( - a_get_inactive_supplier = 1 - OR S.active = 1 - ) - ; - END IF; - END IF; - - DELETE FROM tmp_Split; - - -- Supplier Purchase Orders - IF v_has_filter_order = 1 THEN - CALL partsltd_prod.p_split(v_guid, a_ids_order, ',', a_debug); - - INSERT INTO tmp_Split ( - substring - , as_int - ) - SELECT - substring - , CONVERT(substring, DECIMAL(10,0)) AS as_int - FROM partsltd_prod.Split_Temp - WHERE 1=1 - AND GUID = v_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( v_guid ); - END IF; - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Supplier_Purchase_Order SPO ON t_S.as_int = SPO.id_order - WHERE - ISNULL(t_S.as_int) - OR ISNULL(SPO.id_order) - OR ( - SPO.active = 0 - AND a_get_inactive_order = 0 - ) - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - code, - msg - ) - SELECT - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Invalid or inactive Supplier Purchase Order IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Supplier_Purchase_Order SPO ON t_S.as_int = SPO.id_order - WHERE - ISNULL(t_S.as_int) - OR ISNULL(SPO.id_order) - OR ( - SPO.active = 0 - AND a_get_inactive_order = 0 - ) - ; - ELSE - INSERT INTO tmp_Supplier_Purchase_Order ( - id_order - ) - SELECT - SPO.id_order - FROM tmp_Split t_S - RIGHT JOIN partsltd_prod.Shop_Supplier_Purchase_Order SPO ON t_S.as_int = SPO.id_order - INNER JOIN tmp_Supplier t_SUPP ON SPO.id_supplier_ordered = t_SUPP.id_supplier - INNER JOIN partsltd_prod.Shop_Supplier_Purchase_Order_Product_Link SPOPL ON SPO.id_order = SPOPL.id_order - INNER JOIN tmp_Permutation t_PP ON SPOPL.id_permutation = t_PP.id_permutation - WHERE ( - a_get_all_order = 1 - OR ( - v_has_filter_order = 1 - AND NOT ISNULL(t_S.as_int) - ) - OR ( - v_has_filter_supplier = 1 - AND NOT ISNULL(t_SUPP.id_supplier) - ) - OR ( - v_has_filter_permutation = 1 - AND NOT ISNULL(t_PP.id_permutation) - ) - ) - AND ( - a_get_inactive_order = 1 - OR SPO.active = 1 - ) - AND ( - v_has_filter_date_from = 0 - OR SPO.created_on > a_date_from - ) - AND ( - v_has_filter_date_to = 0 - OR SPO.created_on < a_date_to - ) - - ; - END IF; - END IF; - - DELETE FROM tmp_Split; - - -- Permissions - IF a_debug = 1 THEN - SELECT - v_guid - , a_id_user - , FALSE -- get inactive users - , v_ids_permission_supplier_purchase_order - , v_id_access_level_view - , '' -- ids_product - , 0 -- a_debug - ; - SELECT * from partsltd_prod.Shop_Calc_User_Temp; - END IF; - - CALL p_shop_calc_user( - v_guid - , a_id_user - , FALSE -- get inactive users - , v_ids_permission_supplier_purchase_order - , v_id_access_level_view - , '' -- ids_product - , 0 -- a_debug - ); - - IF a_debug = 1 THEN - SELECT * from partsltd_prod.Shop_Calc_User_Temp; - END IF; - - IF NOT EXISTS (SELECT can_view FROM partsltd_prod.Shop_Calc_User_Temp UE_T WHERE UE_T.GUID = v_guid) THEN - DELETE FROM tmp_Msg_Error; - - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - VALUES ( - v_id_type_error_no_permission - , v_code_type_error_no_permission - , CONCAT('You do not have view permissions for ', (SELECT name FROM partsltd_prod.Shop_Permission WHERE id_permission = v_ids_permission_supplier_purchase_order LIMIT 1)) - ) - ; - END IF; - - IF EXISTS ( SELECT * FROM tmp_Msg_Error LIMIT 1 ) THEN - DELETE FROM tmp_Permutation; - DELETE FROM tmp_Supplier_Purchase_Order; - END IF; - - -- Returns - /* - -- Suppliers - SELECT - t_S.id_supplier, - S.name_company, - S.name_contact, - S.department_contact, - S.id_address, - S.phone_number, - S.fax, - S.email, - S.website, - S.id_currency, - t_S.active - FROM tmp_Supplier t_S - INNER JOIN partsltd_prod.Shop_Supplier S - ON t_S.id_supplier = S.id_supplier - ; - */ - - -- Supplier Purchase Order - SELECT - t_SPO.id_order - , SPO.id_supplier_ordered - , S.name_company - , SPO.id_currency_cost - , C.symbol - , C.code - , SPO.cost_total_local_VAT_excl - , SPO.cost_total_local_VAT_incl - , SPO.active - , SPO.created_on - , CONCAT( - SPO.cost_total_local_VAT_excl - , ' on ' - , SPO.created_on - ) AS name - FROM tmp_Supplier_Purchase_Order t_SPO - INNER JOIN partsltd_prod.Shop_Supplier_Purchase_Order SPO ON SPO.id_order = t_SPO.id_order - LEFT JOIN partsltd_prod.Shop_Supplier S ON SPO.id_supplier_ordered = S.id_supplier - LEFT JOIN partsltd_prod.Shop_Currency C ON SPO.id_currency_cost = C.id_currency - ; - - -- Supplier Purchase Order Product Link - SELECT - SPOPL.id_link - , SPOPL.id_order - , P.id_category - , P.id_product - , SPOPL.id_permutation - , fn_shop_get_product_permutation_name(SPOPL.id_permutation) AS name_permutation - , fn_shop_get_product_permutation_variations_csv(SPOPL.id_permutation) AS csv_id_pairs_variation - -- , SPOPL.id_currency_cost - , SPOPL.id_unit_quantity - , SPOPL.quantity_ordered - , SPOPL.quantity_received - , SPOPL.latency_delivery_days - , SPOPL.display_order - , SPOPL.cost_total_local_VAT_excl - , SPOPL.cost_total_local_VAT_incl - , SPOPL.cost_unit_local_VAT_excl - , SPOPL.cost_unit_local_VAT_incl - , SPOPL.active - FROM tmp_Supplier_Purchase_Order t_SPO - INNER JOIN partsltd_prod.Shop_Supplier_Purchase_Order_Product_Link SPOPL ON t_SPO.id_order = SPOPL.id_order - LEFT JOIN partsltd_prod.Shop_Product_Permutation PP ON SPOPL.id_permutation = PP.id_permutation - LEFT JOIN partsltd_prod.Shop_Product P ON PP.id_product = P.id_product - ; - - -- Errors - SELECT * - FROM tmp_Msg_Error t_ME - INNER JOIN partsltd_prod.Shop_Msg_Error_Type MET ON t_ME.id_type = MET.id_type - ; - - IF a_debug = 1 THEN - SELECT * from tmp_Supplier_Purchase_Order_Product_Link; - SELECT * from tmp_Supplier_Purchase_Order; - SELECT * from tmp_Supplier; - END IF; - - DROP TEMPORARY TABLE IF EXISTS tmp_Supplier_Purchase_Order_Product_Link; - DROP TEMPORARY TABLE IF EXISTS tmp_Supplier_Purchase_Order; - DROP TEMPORARY TABLE IF EXISTS tmp_Supplier; - DROP TEMPORARY TABLE IF EXISTS tmp_Permutation; - DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error; - DROP TEMPORARY TABLE IF EXISTS tmp_Split; - - IF a_debug = 1 THEN - CALL p_debug_timing_reporting( v_time_start ); - END IF; -END // -DELIMITER ; - - -/* - -CALL p_shop_get_many_supplier_purchase_order ( - 1, -- a_id_user - 1, -- a_get_all_supplier - 0, -- a_get_inactive_supplier - '', -- a_ids_supplier - 1, -- a_get_all_order - 0, -- a_get_inactive_order - '', -- a_ids_order - '', -- a_ids_permutation - NULL, -- a_date_from - NULL -- a_date_to - , 0 -- a_debug -); - -*/ diff --git a/static/MySQL/7415_p_shop_save_Manufacturing_purchase_order_test.sql b/static/MySQL/7415_p_shop_save_Manufacturing_purchase_order_test.sql deleted file mode 100644 index 9753d993..00000000 --- a/static/MySQL/7415_p_shop_save_Manufacturing_purchase_order_test.sql +++ /dev/null @@ -1,150 +0,0 @@ - - --- Clear previous proc -DROP PROCEDURE IF EXISTS partsltd_prod.p_shop_save_Manufacturing_purchase_order_test; - - -DELIMITER // -CREATE PROCEDURE p_shop_save_Manufacturing_purchase_order_test () -BEGIN - - DECLARE v_guid BINARY(36); - DECLARE v_time_start TIMESTAMP(6); - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_guid := 'nips'; - - SELECT * - FROM partsltd_prod.Shop_Manufacturing_Purchase_Order - ; - SELECT * - FROM partsltd_prod.Shop_Manufacturing_Purchase_Order_Temp - ; - SELECT * - FROM partsltd_prod.Shop_Manufacturing_Purchase_Order_Product_Link - ; - SELECT * - FROM partsltd_prod.Shop_Manufacturing_Purchase_Order_Product_Link_Temp - ; - - START TRANSACTION; - - DELETE FROM partsltd_prod.Shop_Manufacturing_Purchase_Order_Temp; - DELETE FROM partsltd_prod.Shop_Manufacturing_Purchase_Order_Product_Link_Temp; - - INSERT INTO partsltd_prod.Shop_Manufacturing_Purchase_Order_Temp ( - id_order - , id_currency - , active - , GUID - ) - /* Test 1 - Insert */ - VALUES ( - -1 - , 1 - , 1 - , v_guid - ) - /* Test 2: Alter - SELECT - id_order - , id_currency - , active - , v_guid - FROM partsltd_prod.Shop_Manufacturing_Purchase_Order - WHERE id_order = 6 - */ - ;-- SELECT * FROM partsltd_prod.Shop_Unit_Measurement; - - INSERT INTO partsltd_prod.Shop_Manufacturing_Purchase_Order_Product_Link_Temp ( - id_link - , id_order - , id_permutation - , id_unit_quantity - , quantity_used - , quantity_produced - , id_unit_latency_manufacture - , latency_manufacture - , display_order - , active - , GUID - ) - /* Test 1 - Insert */ - VALUES ( - -1 -- id_link - , -1 -- id_order - , 3 -- id_permutation - , 3 -- id_unit_quantity - , 3 -- quantity_used - , 0 -- quantity_produced - , 4 -- id_unit_latency_manufacture - , 4 -- latency_manufacture - , 1 -- display_order - , 1 -- active - , v_guid -- - ) - /* Test 2: Alter - SELECT - id_link - , id_order - , id_permutation - , id_unit_quantity - , quantity_used - , quantity_produced - , id_unit_latency_manufacture - , latency_manufacture - , display_order - , active - , v_guid - FROM partsltd_prod.Shop_Manufacturing_Purchase_Order_Product_Link - WHERE id_order = 6 - */ - ; - - COMMIT; - - SELECT * - FROM partsltd_prod.Shop_Manufacturing_Purchase_Order_Temp - WHERE GUID = v_guid - ; - - SELECT * - FROM partsltd_prod.Shop_Manufacturing_Purchase_Order_Product_Link_Temp - WHERE GUID = v_guid - ; - - CALL partsltd_prod.p_shop_save_Manufacturing_purchase_order ( - 'Test save Manufacturing Purchase Order' -- comment - , v_guid -- guid - , 1 -- id_user - , 1 -- debug - ); - - SELECT * - FROM partsltd_prod.Shop_Manufacturing_Purchase_Order_Temp - ; - SELECT * - FROM partsltd_prod.Shop_Manufacturing_Purchase_Order_Product_Link_Temp - ; - SELECT * - FROM partsltd_prod.Shop_Manufacturing_Purchase_Order - ; - SELECT * - FROM partsltd_prod.Shop_Manufacturing_Purchase_Order_Product_Link - ; - - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); -END // -DELIMITER ; - -/* -CALL partsltd_prod.p_shop_save_Manufacturing_purchase_order_test (); - -DELETE FROM partsltd_prod.Shop_Manufacturing_Purchase_Order_Temp; -DELETE FROM partsltd_prod.Shop_Manufacturing_Purchase_Order_Product_Link_Temp; - -DROP TABLE IF EXISTS tmp_Msg_Error; - -select * from partsltd_prod.Shop_User; -Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'partsltd_prod.t_MPOPL.name_error' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by -*/ \ No newline at end of file diff --git a/static/MySQL/7415_p_shop_save_manufacturing_purchase_order.sql b/static/MySQL/7415_p_shop_save_manufacturing_purchase_order.sql deleted file mode 100644 index 49de0f05..00000000 --- a/static/MySQL/7415_p_shop_save_manufacturing_purchase_order.sql +++ /dev/null @@ -1,1020 +0,0 @@ - - - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_save_manufacturing_purchase_order; - -DROP TABLE IF EXISTS tmp_Manufacturing_Purchase_Order_Product_Link; -DROP TABLE IF EXISTS tmp_Msg_Error; - -DELIMITER // -CREATE PROCEDURE p_shop_save_manufacturing_purchase_order ( - IN a_comment VARCHAR(500) - , IN a_guid BINARY(36) - , IN a_id_user INT - , IN a_debug BIT -) -BEGIN - DECLARE v_code_type_error_bad_data VARCHAR(50); - DECLARE v_code_type_error_no_permission VARCHAR(50); - DECLARE v_code_type_error_warning VARCHAR(50); - DECLARE v_id_access_level_edit INT; - DECLARE v_id_change_set INT; - DECLARE v_ids_permission_manufacturing_purchase_order VARCHAR(100); - DECLARE v_id_type_error_bad_data INT; - DECLARE v_id_type_error_no_permission INT; - DECLARE v_id_type_error_warning INT; - DECLARE v_ids_product_permission TEXT; - DECLARE v_time_start TIMESTAMP(6); - - DECLARE exit handler for SQLEXCEPTION - BEGIN - GET DIAGNOSTICS CONDITION 1 - @sqlstate = RETURNED_SQLSTATE - , @errno = MYSQL_ERRNO - , @text = MESSAGE_TEXT - ; - - ROLLBACK; - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT - , id_type INT NULL - , code VARCHAR(50) NOT NULL - , msg VARCHAR(4000) NOT NULL - ); - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - MET.id_type - , @errno - , @text - FROM partsltd_prod.Shop_Msg_Error_Type MET - WHERE code = 'MYSQL_ERROR' - ; - SELECT * - FROM tmp_Msg_Error; - DROP TABLE IF EXISTS tmp_Msg_Error; - END; - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_code_type_error_bad_data := (SELECT code FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1); - SET v_id_type_error_bad_data := (SELECT id_type FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = v_code_type_error_bad_data LIMIT 1); - SET v_code_type_error_no_permission := (SELECT code FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = 'NO_PERMISSION' LIMIT 1); - SET v_id_type_error_no_permission := (SELECT id_type FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = v_code_type_error_no_permission LIMIT 1); - SET v_code_type_error_warning := (SELECT code FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = 'WARNING' LIMIT 1); - SET v_id_type_error_warning := (SELECT id_type FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = v_code_type_error_warning LIMIT 1); - SET v_ids_permission_manufacturing_purchase_order := (SELECT GROUP_CONCAT(id_permission SEPARATOR ',') FROM partsltd_prod.Shop_Permission WHERE code IN ('STORE_MANUFACTURING_PURCHASE_ORDER', 'STORE_PRODUCT')); - SET v_id_access_level_edit := (SELECT id_access_level FROM partsltd_prod.Shop_Access_Level WHERE code = 'EDIT' LIMIT 1); - - CALL p_validate_guid ( a_guid ); - SET a_comment := TRIM(IFNULL(a_comment, '')); - - DROP TEMPORARY TABLE IF EXISTS tmp_Manufacturing_Purchase_Order; - DROP TEMPORARY TABLE IF EXISTS tmp_Manufacturing_Purchase_Order_Product_Link; - DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error; - - -- Temporary tables - CREATE TEMPORARY TABLE tmp_Manufacturing_Purchase_Order ( - id_order INT NOT NULL PRIMARY KEY - , id_order_temp INT NOT NULL - , id_currency INT NOT NULL - , active BIT NOT NULL - , is_new BIT NOT NULL - , name_error VARCHAR(1000) NOT NULL - , cost_total_local_VAT_excl FLOAT NULL - , cost_total_local_VAT_incl FLOAT NULL - , price_total_local_VAT_excl FLOAT NULL - , price_total_local_VAT_incl FLOAT NULL - ); - - CREATE TEMPORARY TABLE tmp_Manufacturing_Purchase_Order_Product_Link ( - id_link INT NOT NULL PRIMARY KEY - , id_order INT NOT NULL - , id_product INT NULL - , id_permutation INT NULL - , id_unit_quantity INT NOT NULL - , quantity_used FLOAT NOT NULL - , quantity_produced FLOAT NULL - , id_unit_latency_manufacture INT NULL - , latency_manufacture INT NULL - , display_order INT NOT NULL - , active BIT NOT NULL - , cost_unit_local_VAT_excl FLOAT NULL - , cost_unit_local_VAT_incl FLOAT NULL - , cost_total_local_VAT_excl FLOAT NULL - , cost_total_local_VAT_incl FLOAT NULL - , price_unit_local_VAT_excl FLOAT NULL - , price_unit_local_VAT_incl FLOAT NULL - , price_total_local_VAT_excl FLOAT NULL - , price_total_local_VAT_incl FLOAT NULL - , has_order BIT NULL - , is_new BIT NOT NULL - , name_error VARCHAR(1000) NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT - , id_type INT NOT NULL - , code VARCHAR(50) NOT NULL - , msg VARCHAR(4000) NOT NULL - ); - - INSERT INTO tmp_Manufacturing_Purchase_Order ( - id_order - , id_order_temp - , id_currency - , active - , is_new - , name_error - ) - SELECT - MPO_T.id_order - , MPO_T.id_order - , IFNULL(IFNULL(MPO_T.id_currency, MPO.id_currency), 0) AS id_currency - , IFNULL(IFNULL(MPO_T.active, MPO.active), 1) AS active - , IFNULL(MPO_T.id_order, 0) < 1 AS is_new - , CASE WHEN IFNULL(MPO_T.id_order, -1) < 0 THEN - CONCAT('New Manufacturing Purchase Order ', MPO_T.id_order) - ELSE - CONCAT( - IFNULL(IFNULL(MPO_T.id_order, MPO.id_order), '(No Manufacturing Purchase Order)') - , ' - ' - , IFNULL(IFNULL(MPO_T.id_currency, MPO.id_currency), '(No Currency)') - ) - END AS name_error - FROM partsltd_prod.Shop_Manufacturing_Purchase_Order_Temp MPO_T - LEFT JOIN partsltd_prod.Shop_Manufacturing_Purchase_Order MPO ON MPO_T.id_order = MPO.id_order - WHERE MPO_T.GUID = a_guid - ; - - INSERT INTO tmp_Manufacturing_Purchase_Order_Product_Link ( - id_link - , id_order - , id_product - , id_permutation - , id_unit_quantity - , quantity_used - , quantity_produced - , id_unit_latency_manufacture - , latency_manufacture - , display_order - , active - , cost_unit_local_VAT_excl - , cost_unit_local_VAT_incl - , price_unit_local_VAT_excl - , price_unit_local_VAT_incl - , has_order - , is_new - ) - SELECT - IFNULL(MPOPL_T.id_link, 0) AS id_link - , IFNULL(IFNULL(MPOPL_T.id_order, MPOPL.id_order), 0) AS id_order - , IFNULL(MPOPL_T.id_product, PP.id_product) AS id_product - , IFNULL( - IFNULL( - IFNULL( - MPOPL_T.id_permutation - , CASE WHEN NOT ISNULL(MPOPL_T.id_product) AND NOT ISNULL(MPOPL_T.csv_list_variations) THEN - partsltd_prod.fn_shop_get_id_product_permutation_from_variation_csv_list(MPOPL_T.id_product, MPOPL_T.csv_list_variations) - ELSE NULL END - ) - , MPOPL.id_permutation - ) - , 0 - ) AS id_permutation - , IFNULL(IFNULL(MPOPL_T.id_unit_quantity, MPOPL.id_unit_quantity), 0) AS id_unit_quantity - , MPOPL_T.quantity_used AS quantity_used - , MPOPL_T.quantity_produced AS quantity_produced - , MPOPL_T.id_unit_latency_manufacture AS id_unit_latency_manufacture - , MPOPL_T.latency_manufacture AS latency_manufacture - , IFNULL(MPOPL_T.display_order, RANK() OVER (PARTITION BY IFNULL(IFNULL(MPOPL_T.id_order, MPOPL.id_order), 0) ORDER BY IFNULL(IFNULL(MPOPL_T.display_order, MPOPL.display_order), 0))) AS display_order - , IFNULL(IFNULL(MPOPL_T.active, MPOPL.active), 1) AS active - -- , MPOPL_T.cost_total_local_VAT_excl / MPOPL_T.quantity_used AS cost_unit_local_VAT_excl - -- , MPOPL_T.cost_total_local_VAT_incl / MPOPL_T.quantity_used AS cost_unit_local_VAT_incl - , IFNULL(MPOPL_T.cost_unit_local_VAT_excl, MPOPL.cost_unit_local_VAT_excl) AS cost_unit_local_VAT_excl - , IFNULL(MPOPL_T.cost_unit_local_VAT_incl, MPOPL.cost_unit_local_VAT_incl) AS cost_unit_local_VAT_incl - , IFNULL(MPOPL_T.price_unit_local_VAT_excl, MPOPL.price_unit_local_VAT_excl) AS price_unit_local_VAT_excl - , IFNULL(MPOPL_T.price_unit_local_VAT_incl, MPOPL.price_unit_local_VAT_incl) AS price_unit_local_VAT_incl - , NOT ISNULL(t_MPO.id_order) AS has_order - , IFNULL(MPOPL_T.id_link, 0) < 1 AS is_new - FROM partsltd_prod.Shop_Manufacturing_Purchase_Order_Product_Link_Temp MPOPL_T - LEFT JOIN partsltd_prod.Shop_Manufacturing_Purchase_Order_Product_Link MPOPL ON MPOPL_T.id_link = MPOPL.id_link - LEFT JOIN tmp_Manufacturing_Purchase_Order t_MPO ON MPOPL_T.id_order = t_MPO.id_order - LEFT JOIN partsltd_prod.Shop_Product_Permutation PP ON MPOPL.id_permutation = PP.id_permutation - WHERE MPOPL_T.GUID = a_guid - ; - - UPDATE tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - -- INNER JOIN partsltd_prod.Shop_Manufacturing_Purchase_Order_Product_Link_Temp MPOPL_T ON t_MPOPL.id_order = MPOPL_T.id_order - LEFT JOIN partsltd_prod.Shop_Product_Permutation PP ON t_MPOPL.id_permutation = PP.id_permutation - LEFT JOIN partsltd_prod.Shop_Product P ON PP.id_product = P.id_product - LEFT JOIN partsltd_prod.Shop_Product_Category PC ON P.id_category = PC.id_category - SET - name_error = CONCAT( - CASE WHEN ISNULL(t_MPOPL.id_permutation) THEN - CASE WHEN ISNULL(PP.id_product) THEN - '(No Product Permutation)' - ELSE - CONCAT( - PC.name - , ' - ' - , P.name - ) - END - ELSE - fn_shop_get_product_permutation_name(PP.id_permutation) - END - , ' - x' - , IFNULL(t_MPOPL.quantity_used, '(No Quantity)') - , ' Used - x' - , IFNULL(t_MPOPL.quantity_produced, '(No Quantity)') - , ' Produced' - ) - , cost_total_local_VAT_excl = t_MPOPL.quantity_used * t_MPOPL.cost_unit_local_VAT_excl - , cost_total_local_VAT_incl = t_MPOPL.quantity_used * t_MPOPL.cost_unit_local_VAT_incl - , price_total_local_VAT_excl = t_MPOPL.quantity_produced * t_MPOPL.price_unit_local_VAT_excl - , price_total_local_VAT_incl = t_MPOPL.quantity_produced * t_MPOPL.price_unit_local_VAT_incl - ; - - -- Insert missing order records - INSERT INTO tmp_Manufacturing_Purchase_Order ( - id_order - , id_order_temp - , id_currency - , active - , is_new - , name_error - ) - SELECT - MPO.id_order - , MPO.id_order_temp - , MPO.id_currency - , MPO.active - , FALSE AS is_new - , CONCAT( - IFNULL(MPO.id_order, '(No Manufacturing Purchase Order)') - , ' - ' - , IFNULL(MPO.id_currency, '(No Currency)') - ) AS name_error - FROM partsltd_prod.Shop_Manufacturing_Purchase_Order MPO - INNER JOIN tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - ON MPO.id_order = t_MPOPL.id_order - AND t_MPOPL.has_order = 0 - ; - - UPDATE tmp_Manufacturing_Purchase_Order t_MPO - INNER JOIN ( - SELECT - t_MPOPL.id_order - , SUM(t_MPOPL.cost_total_local_VAT_excl) AS cost_total_local_VAT_excl - , SUM(t_MPOPL.cost_total_local_VAT_incl) AS cost_total_local_VAT_incl - , SUM(t_MPOPL.price_total_local_VAT_excl) AS price_total_local_VAT_excl - , SUM(t_MPOPL.price_total_local_VAT_incl) AS price_total_local_VAT_incl - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - GROUP BY t_MPOPL.id_order - ) SUM_t_MPOPL ON t_MPO.id_order = SUM_t_MPOPL.id_order - SET - t_MPO.cost_total_local_VAT_excl = SUM_t_MPOPL.cost_total_local_VAT_excl - , t_MPO.cost_total_local_VAT_incl = SUM_t_MPOPL.cost_total_local_VAT_incl - , t_MPO.price_total_local_VAT_excl = SUM_t_MPOPL.price_total_local_VAT_excl - , t_MPO.price_total_local_VAT_incl = SUM_t_MPOPL.price_total_local_VAT_incl - ; - - -- Validation - -- Manufacturing Purchase Order - -- id_order - IF EXISTS ( - SELECT * - FROM tmp_Manufacturing_Purchase_Order t_MPO - LEFT JOIN partsltd_prod.Shop_Manufacturing_Purchase_Order MPO ON t_MPO.id_order = MPO.id_order - WHERE 1=1 - AND t_MPO.id_order > 0 - AND ISNULL(MPO.id_order) - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT( - 'A valid ID is required for the following Manufacturing Purchase Order(s): ' - , GROUP_CONCAT(t_MPO.name_error SEPARATOR ', ') - ) AS msg - FROM tmp_Manufacturing_Purchase_Order t_MPO - LEFT JOIN partsltd_prod.Shop_Manufacturing_Purchase_Order MPO ON t_MPO.id_order = MPO.id_order - WHERE 1=1 - AND t_MPO.id_order > 0 - AND ISNULL(MPO.id_order) - ; - END IF; - -- id_currency - IF EXISTS ( - SELECT * - FROM tmp_Manufacturing_Purchase_Order t_MPO - LEFT JOIN partsltd_prod.Shop_Currency C ON t_MPO.id_currency = C.id_currency - WHERE 1=1 - AND ( - ISNULL(C.id_currency) - OR C.active = 0 - ) - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT( - 'A valid currency is required for the following Manufacturing Purchase Order(s): ' - , GROUP_CONCAT(CONCAT(t_MPO.name_error, ' - ', t_MPO.id_currency) SEPARATOR ', ') - ) AS msg - FROM tmp_Manufacturing_Purchase_Order t_MPO - LEFT JOIN partsltd_prod.Shop_Currency C ON t_MPO.id_currency = C.id_currency - WHERE 1=1 - AND ( - ISNULL(C.id_currency) - OR C.active = 0 - ) - ; - END IF; - -- id_unit_quantity - IF EXISTS ( - SELECT * - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - LEFT JOIN partsltd_prod.Shop_Unit_Measurement UM ON t_MPOPL.id_unit_quantity = UM.id_unit_measurement - WHERE 1=1 - AND ( - ISNULL(UM.id_unit_measurement) - OR UM.active = 0 - ) - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT( - 'A valid unit measurement of quantity is required for the following Manufacturing Purchase Order(s): ' - , GROUP_CONCAT(CONCAT(t_MPOPL.name_error, ' - ', t_MPO.id_unit_quantity) SEPARATOR ', ') - ) AS msg - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - LEFT JOIN partsltd_prod.Shop_Unit_Measurement UM ON t_MPOPL.id_unit_quantity = UM.id_unit_measurement - WHERE 1=1 - AND ( - ISNULL(UM.id_unit_measurement) - OR UM.active = 0 - ) - ; - END IF; - -- Invalid quantity used - IF EXISTS ( - SELECT * - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE - ISNULL(t_MPOPL.quantity_used) - OR t_MPOPL.quantity_used <= 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, code, msg - ) - SELECT - v_id_error_type_bad_data, - v_code_error_type_bad_data, - CONCAT( - 'A valid quantity used is required for the following Manufacturing Purchase Order Item(s): ' - , GROUP_CONCAT(CONCAT(t_MPOPL.name_error, ' - ', t_MPOPL.quantity_used) SEPARATOR ', ') - ) - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE - NOT ISNULL(t_MPOPL.quantity_used) - AND t_MPOPL.quantity_used <= 0 - ; - END IF; - -- Invalid quantity produced - IF EXISTS ( - SELECT * - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE - NOT ISNULL(t_MPOPL.quantity_produced) - AND t_MPOPL.quantity_produced < 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, code, msg - ) - SELECT - v_id_error_type_bad_data, - v_code_error_type_bad_data, - CONCAT( - 'A valid quantity produced is required for the following Manufacturing Purchase Order Item(s): ' - , GROUP_CONCAT(CONCAT(t_MPOPL.name_error, ' - ', t_MPOPL.quantity_produced) SEPARATOR ', ') - ) - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE - NOT ISNULL(t_MPOPL.quantity_produced) - AND t_MPOPL.quantity_produced < 0 - ; - END IF; - -- id_unit_latency_manufacture - IF EXISTS ( - SELECT * - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - LEFT JOIN partsltd_prod.Shop_Unit_Measurement UM ON t_MPOPL.id_unit_latency_manufacture = UM.id_unit_measurement - WHERE - ISNULL(t_MPOPL.id_unit_latency_manufacture) - OR ISNULL(UM.id_unit_measurement) - OR UM.active = 0 - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_bad_data - , v_code_type_error_bad_data - , CONCAT( - 'A valid unit measurement of manufacture latency is required for the following Manufacturing Purchase Order(s): ' - , GROUP_CONCAT(CONCAT(t_MPOPL.name_error, ' - ', t_MPOPL.id_unit_latency_manufacture) SEPARATOR ', ') - ) AS msg - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - LEFT JOIN partsltd_prod.Shop_Unit_Measurement UM ON t_MPOPL.id_unit_latency_manufacture = UM.id_unit_measurement - WHERE - ISNULL(t_MPOPL.id_unit_latency_manufacture) - OR ISNULL(UM.id_unit_measurement) - OR UM.active = 0 - ; - END IF; - -- Invalid manufacture latency - IF EXISTS ( - SELECT * - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE t_MPOPL.latency_manufacture < 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, code, msg - ) - SELECT - v_id_error_type_bad_data, - v_code_error_type_bad_data, - CONCAT( - 'A valid manufacture latency is required for the following Manufacturing Purchase Order Item(s): ' - , GROUP_CONCAT(CONCAT(t_MPOPL.name_error, ' - ', t_MPOPL.latency_manufacture) SEPARATOR ', ') - ) - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE t_MPOPL.latency_manufacture < 0 - ; - END IF; - - -- Invalid costs excl VAT - IF EXISTS ( - SELECT * - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE - NOT ISNULL(t_MPOPL.cost_unit_local_VAT_excl) - AND t_MPOPL.cost_unit_local_VAT_excl < 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, code, msg - ) - SELECT - v_id_error_type_bad_data, - v_code_error_type_bad_data, - CONCAT( - 'A valid cost excluding VAT is required for the following Manufacturing Purchase Order Item(s): ' - , GROUP_CONCAT(CONCAT(t_MPOPL.name_error, ' - ', t_MPOPL.cost_unit_local_VAT_excl) SEPARATOR ', ') - ) - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE - NOT ISNULL(t_MPOPL.cost_unit_local_VAT_excl) - AND t_MPOPL.cost_unit_local_VAT_excl < 0 - ; - END IF; - -- Invalid costs incl VAT - IF EXISTS ( - SELECT * - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE - NOT ISNULL(t_MPOPL.cost_unit_local_VAT_incl) - AND t_MPOPL.cost_unit_local_VAT_incl < 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, code, msg - ) - SELECT - v_id_error_type_bad_data, - v_code_error_type_bad_data, - CONCAT( - 'A valid cost including VAT is required for the following Manufacturing Purchase Order Item(s): ' - , GROUP_CONCAT(CONCAT(t_MPOPL.name_error, ' - ', t_MPOPL.cost_unit_local_VAT_incl) SEPARATOR ', ') - ) - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE - NOT ISNULL(t_MPOPL.cost_unit_local_VAT_incl) - AND t_MPOPL.cost_unit_local_VAT_incl < 0 - ; - END IF; - - -- Invalid prices excl VAT - IF EXISTS ( - SELECT * - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE - NOT ISNULL(t_MPOPL.price_unit_local_VAT_excl) - AND t_MPOPL.price_unit_local_VAT_excl < 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, code, msg - ) - SELECT - v_id_error_type_bad_data, - v_code_error_type_bad_data, - CONCAT( - 'A valid price excluding VAT is required for the following Manufacturing Purchase Order Item(s): ' - , GROUP_CONCAT(CONCAT(t_MPOPL.name_error, ' - ', t_MPOPL.price_unit_local_VAT_excl) SEPARATOR ', ') - ) - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE - NOT ISNULL(t_MPOPL.price_unit_local_VAT_excl) - AND t_MPOPL.price_unit_local_VAT_excl < 0 - ; - END IF; - -- Invalid prices incl VAT - IF EXISTS ( - SELECT * - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE - NOT ISNULL(t_MPOPL.price_unit_local_VAT_incl) - AND t_MPOPL.price_unit_local_VAT_incl < 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, code, msg - ) - SELECT - v_id_error_type_bad_data, - v_code_error_type_bad_data, - CONCAT( - 'A valid price including VAT is required for the following Manufacturing Purchase Order Item(s): ' - , GROUP_CONCAT(CONCAT(t_MPOPL.name_error, ' - ', t_MPOPL.price_unit_local_VAT_incl) SEPARATOR ', ') - ) - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE - NOT ISNULL(t_MPOPL.price_unit_local_VAT_incl) - AND t_MPOPL.price_unit_local_VAT_incl < 0 - ; - END IF; - - -- Duplicates - /* - IF EXISTS ( - SELECT - t_MPOPL.id_permutation - , t_MPOPL.name_error - , COUNT(*) - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - GROUP BY t_MPOPL.id_permutation, t_MPOPL.name_error - HAVING COUNT(*) > 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, code, msg - ) - SELECT - v_id_error_type_bad_data, - v_code_error_type_bad_data, - CONCAT('Duplicate records: ', GROUP_CONCAT(t_MPOPLC.name_error SEPARATOR ', ')) - FROM ( - SELECT - t_MPOPL.id_permutation - , t_MPOPL.name_error - , COUNT(*) - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - GROUP BY t_MPOPL.id_permutation, t_MPOPL.name_error - HAVING COUNT(*) > 1 - ) t_MPOPLC - ; - END IF; - */ - -- Empty Manufacturing Purchase Order - IF EXISTS ( SELECT * FROM tmp_Manufacturing_Purchase_Order t_MPO LEFT JOIN tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL ON t_MPO.id_order = t_MPOPL.id_order WHERE ISNULL(t_MPOPL.id_order) ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, code, msg - ) - SELECT - v_id_error_type_bad_data, - v_code_error_type_bad_data, - CONCAT( - 'There are no items in the following Manufacturing Purchase Order(s): ' - , GROUP_CONCAT(t_MPO.name_error SEPARATOR ', ') - ) AS msg - FROM tmp_Manufacturing_Purchase_Order t_MPO - LEFT JOIN tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL ON t_MPO.id_order = t_MPOPL.id_order - WHERE ISNULL(t_MPOPL.id_order) - ; - END IF; - - -- Manufacturing Purchase Order Items without Order - IF EXISTS ( - SELECT * - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - LEFT JOIN tmp_Manufacturing_Purchase_Order t_MPO ON t_MPOPL.id_order = t_MPO.id_order - WHERE ISNULL(t_MPO.id_order) - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, code, msg - ) - SELECT - v_id_error_type_bad_data, - v_code_error_type_bad_data, - CONCAT( - 'There is no order for the following Manufacturing Purchase Order Item(s): ' - , GROUP_CONCAT(t_MPOPL.name_error SEPARATOR ', ') - ) AS msg - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - LEFT JOIN tmp_Manufacturing_Purchase_Order t_MPO ON t_MPOPL.id_order = t_MPO.id_order - WHERE ISNULL(t_MPO.id_order) - ; - END IF; - - -- Permissions - SET v_ids_product_permission := ( - SELECT - GROUP_CONCAT(DISTINCT PP.id_product SEPARATOR ',') - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - INNER JOIN partsltd_prod.Shop_Product_Permutation PP ON t_MPOPL.id_permutation = PP.id_permutation - ); - IF a_debug = 1 THEN - SELECT - a_guid - , a_id_user - , FALSE -- get inactive users - , v_ids_permission_manufacturing_purchase_order - , v_id_access_level_edit - , v_ids_product_permission -- ids_product - , 0 -- a_debug - ; - SELECT * - FROM partsltd_prod.Shop_Calc_User_Temp - WHERE GUID = a_guid - ; - END IF; - - CALL p_shop_calc_user( - a_guid - , a_id_user - , FALSE -- get inactive users - , v_ids_permission_manufacturing_purchase_order - , v_id_access_level_edit - , v_ids_product_permission -- ids_product - , 0 -- a_debug - ); - - IF a_debug = 1 THEN - SELECT * from partsltd_prod.Shop_Calc_User_Temp WHERE GUID = a_guid; - END IF; - - IF EXISTS (SELECT * FROM partsltd_prod.Shop_Calc_User_Temp UE_T WHERE UE_T.GUID = a_guid AND IFNULL(UE_T.can_view, 0) = 0) THEN - DELETE FROM tmp_Msg_Error; - - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_no_permission - , v_code_type_error_no_permission - , CONCAT( - 'You do not have edit permissions for ' - , GROUP_CONCAT(name SEPARATOR ', ') - ) - FROM partsltd_prod.Shop_Permission PERM - INNER JOIN partsltd_prod.Shop_Calc_User_Temp UE_T - ON PERM.id_permission = UE_T.id_permission - AND UE_T.GUID = a_guid - AND IFNULL(UE_T.can_view, 0) = 0 - ; - END IF; - - CALL partsltd_prod.p_shop_clear_calc_user( - a_guid - , 0 -- a_debug - ); - - -- Changed quantity used - IF EXISTS ( - SELECT * - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - INNER JOIN partsltd_prod.Shop_Manufacturing_Purchase_Order_Product_Link MPOPL ON t_MPOPL.id_link = MPOPL.id_link - INNER JOIN partsltd_prod.Shop_Stock_Item SI ON MPOPL.id_permutation = SI.id_permutation - WHERE - t_MPOPL.is_new = 0 - AND t_MPOPL.quantity_used <> MPOPL.quantity_used - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_warning - , v_code_type_error_warning - , CONCAT( - 'The quantity used has changed on the following orders. Please update the stock items appropriately.' - , GROUP_CONCAT( - CONCAT( - t_MPOPL.name_error - , ' - from ' - , MPOPL.quantity_used - , ' to ' - , t_MPOPL.quantity_used - ) SEPARATOR ', ' - ) - ) AS msg - ; - END IF; - -- Changed quantity produced - IF EXISTS ( - SELECT * - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - INNER JOIN partsltd_prod.Shop_Manufacturing_Purchase_Order_Product_Link MPOPL ON t_MPOPL.id_link = MPOPL.id_link - INNER JOIN partsltd_prod.Shop_Stock_Item SI ON MPOPL.id_permutation = SI.id_permutation - WHERE - t_MPOPL.is_new = 0 - AND t_MPOPL.quantity_produced <> MPOPL.quantity_produced - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - SELECT - v_id_type_error_warning - , v_code_type_error_warning - , CONCAT( - 'The quantity produced has changed on the following orders. Please update the stock items appropriately.' - , GROUP_CONCAT( - CONCAT( - t_MPOPL.name_error - , ' - from ' - , MPOPL.quantity_produced - , ' to ' - , t_MPOPL.quantity_produced - ) SEPARATOR ', ' - ) - ) AS msg - ; - END IF; - - IF EXISTS ( SELECT * FROM tmp_Msg_Error WHERE id_type <> v_id_type_error_warning LIMIT 1 ) THEN - DELETE FROM tmp_Manufacturing_Purchase_Order_Product_Link; - DELETE FROM tmp_Manufacturing_Purchase_Order; - END IF; - - -- Transaction - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - START TRANSACTION; - INSERT INTO Shop_Sales_And_Purchasing_Change_Set ( - comment - , updated_last_by - , updated_last_on - ) - VALUES ( - a_comment - , a_id_user - , v_time_start - ); - - SET v_id_change_set := LAST_INSERT_ID(); - - INSERT INTO partsltd_prod.Shop_Manufacturing_Purchase_Order ( - id_order_temp - , id_currency - , cost_total_local_VAT_excl - , cost_total_local_VAT_incl - , price_total_local_VAT_excl - , price_total_local_VAT_incl - , active - , created_by - , created_on - , id_change_set - ) - SELECT - t_MPO.id_order_temp - , t_MPO.id_currency - , t_MPO.cost_total_local_VAT_excl - , t_MPO.cost_total_local_VAT_incl - , t_MPO.price_total_local_VAT_excl - , t_MPO.price_total_local_VAT_incl - , t_MPO.active - , a_id_user - , v_time_start - , v_id_change_set - FROM tmp_Manufacturing_Purchase_Order t_MPO - INNER JOIN tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL ON t_MPO.id_order = t_MPOPL.id_order - WHERE t_MPO.is_new = 1 - ; - - UPDATE tmp_Manufacturing_Purchase_Order t_MPO - INNER JOIN partsltd_prod.Shop_Manufacturing_Purchase_Order MPO - ON t_MPO.id_order_temp = MPO.id_order_temp - AND MPO.id_change_set = v_id_change_set - SET - t_MPO.id_order = MPO.id_order - WHERE t_MPO.is_new = 1 - ; - - UPDATE tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - INNER JOIN tmp_Manufacturing_Purchase_Order t_MPO ON t_MPOPL.id_order = t_MPO.id_order_temp - SET - t_MPOPL.id_order = t_MPO.id_order - WHERE t_MPO.is_new = 1 - ; - - INSERT INTO Shop_Manufacturing_Purchase_Order_Product_Link ( - id_order - , id_permutation - , id_unit_quantity - , quantity_used - , quantity_produced - , id_unit_latency_manufacture - , latency_manufacture - , display_order - , active - , cost_unit_local_VAT_excl - , cost_unit_local_VAT_incl - , price_unit_local_VAT_excl - , price_unit_local_VAT_incl - , created_by - , created_on - , id_change_set - ) - SELECT - t_MPOPL.id_order - , t_MPOPL.id_permutation - , t_MPOPL.id_unit_quantity - , t_MPOPL.quantity_used - , t_MPOPL.quantity_produced - , t_MPOPL.id_unit_latency_manufacture - , t_MPOPL.latency_manufacture - , t_MPOPL.display_order - , t_MPOPL.active - , t_MPOPL.cost_unit_local_VAT_excl - , t_MPOPL.cost_unit_local_VAT_incl - , t_MPOPL.price_unit_local_VAT_excl - , t_MPOPL.price_unit_local_VAT_incl - , a_id_user - , v_time_start - , v_id_change_set - FROM tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE t_MPOPL.is_new = 1 - ; - - UPDATE partsltd_prod.Shop_Manufacturing_Purchase_Order MPO - INNER JOIN tmp_Manufacturing_Purchase_Order t_MPO - ON MPO.id_order = t_MPO.id_order - AND t_MPO.is_new = 0 - INNER JOIN tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL ON t_MPO.id_order = t_MPOPL.id_order - SET - MPO.id_currency = t_MPO.id_currency - , MPO.cost_total_local_VAT_excl = t_MPO.cost_total_local_VAT_excl - , MPO.cost_total_local_VAT_incl = t_MPO.cost_total_local_VAT_incl - , MPO.price_total_local_VAT_excl = t_MPO.price_total_local_VAT_excl - , MPO.price_total_local_VAT_incl = t_MPO.price_total_local_VAT_incl - , MPO.active = t_MPO.active - , MPO.id_change_set = v_id_change_set - ; - - UPDATE partsltd_prod.Shop_Manufacturing_Purchase_Order_Product_Link MPOPL - INNER JOIN tmp_Manufacturing_Purchase_Order_Product_Link t_MPOPL - ON MPOPL.id_link = t_MPOPL.id_link - AND t_MPOPL.is_new = 0 - SET - MPOPL.id_order = t_MPOPL.id_order - , MPOPL.id_permutation = t_MPOPL.id_permutation - , MPOPL.id_unit_quantity = t_MPOPL.id_unit_quantity - , MPOPL.quantity_used = t_MPOPL.quantity_used - , MPOPL.quantity_produced = t_MPOPL.quantity_produced - , MPOPL.id_unit_latency_manufacture = t_MPOPL.id_unit_latency_manufacture - , MPOPL.latency_manufacture = t_MPOPL.latency_manufacture - , MPOPL.display_order = t_MPOPL.display_order - , MPOPL.active = t_MPOPL.active - , MPOPL.cost_unit_local_VAT_excl = t_MPOPL.cost_unit_local_VAT_excl - , MPOPL.cost_unit_local_VAT_incl = t_MPOPL.cost_unit_local_VAT_incl - , MPOPL.price_unit_local_VAT_excl = t_MPOPL.price_unit_local_VAT_excl - , MPOPL.price_unit_local_VAT_incl = t_MPOPL.price_unit_local_VAT_incl - , MPOPL.id_change_set = v_id_change_set - ; - - COMMIT; - END IF; - - START TRANSACTION; - - DELETE MPO_T - FROM partsltd_prod.Shop_Manufacturing_Purchase_Order_Temp MPO_T - WHERE MPO_T.GUID = a_guid - ; - DELETE MPOPL_T - FROM partsltd_prod.Shop_Manufacturing_Purchase_Order_Product_Link_Temp MPOPL_T - WHERE MPOPL_T.GUID = a_guid - ; - - COMMIT; - - -- Errors - SELECT * - FROM tmp_Msg_Error t_ME - INNER JOIN partsltd_prod.Shop_Msg_Error_Type MET ON t_ME.id_type = MET.id_type - ; - - IF a_debug = 1 THEN - SELECT * from tmp_Manufacturing_Purchase_Order; - SELECT * from tmp_Manufacturing_Purchase_Order_Product_Link; - END IF; - - DROP TEMPORARY TABLE tmp_Manufacturing_Purchase_Order; - DROP TEMPORARY TABLE tmp_Manufacturing_Purchase_Order_Product_Link; - DROP TEMPORARY TABLE tmp_Msg_Error; - - IF a_debug = 1 THEN - CALL partsltd_prod.p_debug_timing_reporting ( v_time_start ); - END IF; -END // -DELIMITER ; - - -/* - -DELETE FROM Shop_Manufacturing_Purchase_Order_Product_Link_Audit; -DELETE FROM Shop_Manufacturing_Purchase_Order_Product_Link; -DELETE FROM Shop_Manufacturing_Purchase_Order_Product_Link_Temp; -DELETE FROM Shop_Manufacturing_Purchase_Order_Audit; -DELETE FROM Shop_Manufacturing_Purchase_Order; - -INSERT INTO Shop_Manufacturing_Purchase_Order_Product_Link_Temp ( - guid, - id_link, - id_order, - id_permutation, - cost_total_local, - id_currency, - quantity_used, - id_unit_quantity, - quantity_produced, - latency_manufacture, - display_order, - active -) -VALUES - ( - 'NIPS', -- guid - -1, -- id_link, - -1, -- id_order, - 1, -- id_permutation, - 100, -- cost_total_local, - 1, -- id_currency, - 1, -- quantity_used, - 1, -- id_unit_quantity, - 1, -- quantity_produced, - 14, -- latency_manufacture , - 1, -- display_order - 1 -- active - ) -; - -SELECT * FROM Shop_Manufacturing_Purchase_Order_Product_Link_Temp; - -CALL p_shop_save_manufacturing_purchase_order ( - 'TEST SAVE' - , 'NIPS' -- a_guid - , 1 -- 'auth0|6582b95c895d09a70ba10fef', -- a_id_user - , 1 -- a_debug -); - -SELECT * FROM Shop_Manufacturing_Purchase_Order_Product_Link_Temp; - -DELETE FROM Shop_Manufacturing_Purchase_Order_Product_Link_Audit; -DELETE FROM Shop_Manufacturing_Purchase_Order_Product_Link; -DELETE FROM Shop_Manufacturing_Purchase_Order_Product_Link_Temp; -DELETE FROM Shop_Manufacturing_Purchase_Order_Audit; -DELETE FROM Shop_Manufacturing_Purchase_Order; - - -*/ - diff --git a/static/MySQL/7416_p_shop_get_many_manufacturing_purchase_order.sql b/static/MySQL/7416_p_shop_get_many_manufacturing_purchase_order.sql deleted file mode 100644 index 12c1b86a..00000000 --- a/static/MySQL/7416_p_shop_get_many_manufacturing_purchase_order.sql +++ /dev/null @@ -1,408 +0,0 @@ - - -DROP PROCEDURE IF EXISTS p_shop_get_many_manufacturing_purchase_order; - -DELIMITER // -CREATE PROCEDURE p_shop_get_many_manufacturing_purchase_order ( - IN a_id_user INT, - IN a_get_all_order BIT, - IN a_get_inactive_order BIT, - IN a_ids_order TEXT, - IN a_ids_permutation TEXT, - IN a_date_from DATETIME, - IN a_date_to DATETIME, - IN a_debug BIT -) -BEGIN - DECLARE v_code_type_error_bad_data VARCHAR(50); - DECLARE v_code_type_error_no_permission VARCHAR(50); - DECLARE v_guid BINARY(36); - DECLARE v_has_filter_order BIT; - DECLARE v_has_filter_permutation BIT; - DECLARE v_has_filter_date_from BIT; - DECLARE v_has_filter_date_to BIT; - DECLARE v_id_access_level_view INT; - DECLARE v_ids_permission_manufacturing_purchase_order VARCHAR(100); - DECLARE v_id_type_error_bad_data INT; - DECLARE v_id_type_error_no_permission INT; - DECLARE v_time_start TIMESTAMP(6); - - SET v_time_start := CURRENT_TIMESTAMP(6); - SET v_guid := UUID(); - SET v_id_access_level_view := (SELECT id_access_level FROM partsltd_prod.Shop_Access_Level WHERE code = 'VIEW' LIMIT 1); - SET v_code_type_error_bad_data := (SELECT code FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1); - SET v_id_type_error_bad_data := (SELECT id_type FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = v_code_type_error_bad_data LIMIT 1); - SET v_code_type_error_no_permission := (SELECT code FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = 'NO_PERMISSION'); - SET v_id_type_error_no_permission := (SELECT id_type FROM partsltd_prod.Shop_Msg_Error_Type WHERE code = v_code_type_error_no_permission); - SET v_ids_permission_manufacturing_purchase_order := (SELECT GROUP_CONCAT(id_permission SEPARATOR ',') FROM partsltd_prod.Shop_Permission WHERE code IN ('STORE_MANUFACTURING_PURCHASE_ORDER', 'STORE_PRODUCT')); - - SET a_get_all_order := IFNULL(a_get_all_order, 1); - SET a_get_inactive_order := IFNULL(a_get_inactive_order, 0); - SET a_ids_order := TRIM(IFNULL(a_ids_order, '')); - SET a_ids_permutation := TRIM(IFNULL(a_ids_permutation, '')); - SET a_date_from := IFNULL(a_date_from, NULL); - SET a_date_to := IFNULL(a_date_to, NULL); - SET a_debug := IFNULL(a_debug, 0); - - DROP TEMPORARY TABLE IF EXISTS tmp_Manufacturing_Purchase_Order_Product_Link; - DROP TEMPORARY TABLE IF EXISTS tmp_Manufacturing_Purchase_Order; - DROP TEMPORARY TABLE IF EXISTS tmp_Permutation; - DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error; - DROP TEMPORARY TABLE IF EXISTS tmp_Split; - - CREATE TEMPORARY TABLE tmp_Manufacturing_Purchase_Order ( - id_order INT NOT NULL PRIMARY KEY - ); - - CREATE TEMPORARY TABLE tmp_Permutation ( - id_permutation INT NOT NULL PRIMARY KEY - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - id_type INT NOT NULL, - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Split ( - substring VARCHAR(4000) NOT NULL - , as_int INT NULL - ); - DELETE FROM tmp_Split; - - SET v_has_filter_order = CASE WHEN a_ids_order = '' THEN 0 ELSE 1 END; - SET v_has_filter_permutation = CASE WHEN a_ids_permutation = '' THEN 0 ELSE 1 END; - SET v_has_filter_date_from = CASE WHEN ISNULL(a_date_from) THEN 0 ELSE 1 END; - SET v_has_filter_date_to = CASE WHEN ISNULL(a_date_to) THEN 0 ELSE 1 END; - - IF a_debug = 1 THEN - SELECT - v_has_filter_order - , v_has_filter_permutation - , v_has_filter_date_from - , v_has_filter_date_to - ; - END IF; - - -- Permutations - IF v_has_filter_permutation = 1 THEN - CALL partsltd_prod.p_split(v_guid, a_ids_permutation, ',', a_debug); - - INSERT INTO tmp_Split ( - substring - , as_int - ) - SELECT - substring - , CONVERT(substring, DECIMAL(10,0)) AS as_int - FROM partsltd_prod.Split_Temp - WHERE 1=1 - AND GUID = v_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( v_guid ); - END IF; - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Product_Permutation PP ON t_S.as_int = PP.id_permutation - WHERE - ISNULL(t_S.as_int) - OR ISNULL(PP.id_permutation) - OR PP.active = 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - code, - msg - ) - SELECT - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Invalid or inactive permutation IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Product_Permutation PP ON t_S.as_int = PP.id_permutation - WHERE - ISNULL(t_S.as_int) - OR ISNULL(PP.id_permutation) - OR PP.active = 0 - ; - ELSE - INSERT INTO tmp_Permutation ( - id_permutation - ) - SELECT - PP.id_permutation - FROM tmp_Split t_S - RIGHT JOIN partsltd_prod.Shop_Product_Permutation PP ON t_S.as_int = PP.id_permutation - WHERE ( - v_has_filter_permutation = 0 - OR NOT ISNULL(t_S.as_int) - ) - ; - END IF; - END IF; - - DELETE FROM tmp_Split; - - -- Manufacturing Purchase Orders - IF v_has_filter_order = 1 THEN - CALL partsltd_prod.p_split(v_guid, a_ids_order, ',', a_debug); - - INSERT INTO tmp_Split ( - substring - , as_int - ) - SELECT - substring - , CONVERT(substring, DECIMAL(10,0)) AS as_int - FROM partsltd_prod.Split_Temp - WHERE 1=1 - AND GUID = v_guid - AND NOT ISNULL(substring) - AND substring != '' - ; - - CALL partsltd_prod.p_clear_split_temp( v_guid ); - END IF; - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Manufacturing_Purchase_Order MPO ON t_S.as_int = MPO.id_order - WHERE - ISNULL(t_S.as_int) - OR ISNULL(MPO.id_order) - OR ( - MPO.active = 0 - AND a_get_inactive_order = 0 - ) - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - code, - msg - ) - SELECT - v_id_type_error_bad_data, - v_code_type_error_bad_data, - CONCAT('Invalid or inactive Manufacturing Purchase Order IDs: ', IFNULL(GROUP_CONCAT(t_S.substring SEPARATOR ', '), 'NULL')) - FROM tmp_Split t_S - LEFT JOIN partsltd_prod.Shop_Manufacturing_Purchase_Order MPO ON t_S.as_int = MPO.id_order - WHERE - ISNULL(t_S.as_int) - OR ISNULL(MPO.id_order) - OR ( - MPO.active = 0 - AND a_get_inactive_order = 0 - ) - ; - ELSE - INSERT INTO tmp_Manufacturing_Purchase_Order ( - id_order - ) - SELECT - MPO.id_order - FROM tmp_Split t_S - RIGHT JOIN partsltd_prod.Shop_Manufacturing_Purchase_Order MPO ON t_S.as_int = MPO.id_order - INNER JOIN partsltd_prod.Shop_Manufacturing_Purchase_Order_Product_Link MPOPL ON MPO.id_order = MPOPL.id_order - INNER JOIN tmp_Permutation t_PP ON MPOPL.id_permutation = t_PP.id_permutation - WHERE ( - a_get_all_order = 1 - OR ( - v_has_filter_order = 1 - AND NOT ISNULL(t_S.as_int) - ) - OR ( - v_has_filter_permutation = 1 - AND NOT ISNULL(t_PP.id_permutation) - ) - ) - AND ( - a_get_inactive_order = 1 - OR MPO.active = 1 - ) - AND ( - v_has_filter_date_from = 0 - OR MPO.created_on > a_date_from - ) - AND ( - v_has_filter_date_to = 0 - OR MPO.created_on < a_date_to - ) - - ; - END IF; - END IF; - - DELETE FROM tmp_Split; - - -- Permissions - IF a_debug = 1 THEN - SELECT - v_guid - , a_id_user - , FALSE -- get inactive users - , v_ids_permission_manufacturing_purchase_order - , v_id_access_level_view - , '' -- ids_product - , 0 -- a_debug - ; - SELECT * FROM partsltd_prod.Shop_Calc_User_Temp; - END IF; - - CALL p_shop_calc_user( - v_guid - , a_id_user - , FALSE -- get inactive users - , v_ids_permission_manufacturing_purchase_order - , v_id_access_level_view - , '' -- ids_product - , 0 -- a_debug - ); - - IF a_debug = 1 THEN - SELECT * FROM partsltd_prod.Shop_Calc_User_Temp; - END IF; - - IF NOT EXISTS (SELECT can_view FROM partsltd_prod.Shop_Calc_User_Temp UE_T WHERE UE_T.GUID = v_guid) THEN - DELETE FROM tmp_Msg_Error; - - INSERT INTO tmp_Msg_Error ( - id_type - , code - , msg - ) - VALUES ( - v_id_type_error_no_permission - , v_code_type_error_no_permission - , CONCAT('You do not have view permissions for ', IFNULL((SELECT IFNULL(name, '(No Permission Name)') FROM partsltd_prod.Shop_Permission WHERE FIND_IN_SET(id_permission, v_ids_permission_manufacturing_purchase_order) > 0 LIMIT 1), '(No Permissions Found)')) - ) - ; - END IF; - - IF EXISTS ( SELECT * FROM tmp_Msg_Error LIMIT 1 ) THEN - -- DELETE FROM tmp_Manufacturing_Purchase_Order_Product_Link; - DELETE FROM tmp_Manufacturing_Purchase_Order; - END IF; - - -- Returns - /* - -- Manufacturings - SELECT - t_S.id_manufacturing, - S.name_company, - S.name_contact, - S.department_contact, - S.id_address, - S.phone_number, - S.fax, - S.email, - S.website, - S.id_currency, - t_S.active - FROM tmp_Manufacturing t_S - INNER JOIN partsltd_prod.Shop_Manufacturing S - ON t_S.id_manufacturing = S.id_manufacturing - ; - */ - - -- Manufacturing Purchase Order - SELECT - t_MPO.id_order - , MPO.id_currency - , C.code - , C.symbol - , MPO.cost_total_local_VAT_excl - , MPO.cost_total_local_VAT_incl - , MPO.price_total_local_VAT_excl - , MPO.price_total_local_VAT_incl - , MPO.active - , MPO.created_on - , CONCAT( - MPO.cost_total_local_VAT_excl - , ' on ' - , MPO.created_on - ) AS name - FROM tmp_Manufacturing_Purchase_Order t_MPO - INNER JOIN partsltd_prod.Shop_Manufacturing_Purchase_Order MPO ON MPO.id_order = t_MPO.id_order - LEFT JOIN partsltd_prod.Shop_Currency C ON MPO.id_currency = C.id_currency - ; - - -- Manufacturing Purchase Order Product Link - SELECT - MPOPL.id_link - , MPOPL.id_order - , P.id_category - , P.id_product - , MPOPL.id_permutation - , fn_shop_get_product_permutation_name(MPOPL.id_permutation) AS name_permutation - , fn_shop_get_product_permutation_variations_csv(MPOPL.id_permutation) AS csv_id_pairs_variation - , MPOPL.id_unit_quantity - , MPOPL.quantity_used - , MPOPL.quantity_produced - , MPOPL.id_unit_latency_manufacture - , MPOPL.latency_manufacture - , MPOPL.display_order - , MPOPL.cost_unit_local_VAT_excl - , MPOPL.cost_unit_local_VAT_incl - , MPOPL.price_unit_local_VAT_excl - , MPOPL.price_unit_local_VAT_incl - , MPOPL.active - FROM tmp_Manufacturing_Purchase_Order t_MPO - INNER JOIN partsltd_prod.Shop_Manufacturing_Purchase_Order_Product_Link MPOPL ON t_MPO.id_order = MPOPL.id_order - LEFT JOIN partsltd_prod.Shop_Product_Permutation PP ON MPOPL.id_permutation = PP.id_permutation - LEFT JOIN partsltd_prod.Shop_Product P ON PP.id_product = P.id_product - ; - - -- Errors - SELECT * - FROM tmp_Msg_Error t_ME - INNER JOIN partsltd_prod.Shop_Msg_Error_Type MET ON t_ME.id_type = MET.id_type - ; - - IF a_debug = 1 THEN - SELECT * from tmp_Manufacturing_Purchase_Order; - SELECT * from tmp_Permutation; - END IF; - - DROP TEMPORARY TABLE IF EXISTS tmp_Manufacturing_Purchase_Order_Product_Link; - DROP TEMPORARY TABLE IF EXISTS tmp_Manufacturing_Purchase_Order; - DROP TEMPORARY TABLE IF EXISTS tmp_Permutation; - DROP TEMPORARY TABLE IF EXISTS tmp_Msg_Error; - DROP TEMPORARY TABLE IF EXISTS tmp_Split; - - IF a_debug = 1 THEN - CALL p_debug_timing_reporting( v_time_start ); - END IF; -END // -DELIMITER ; - - -/* - -CALL p_shop_get_many_manufacturing_purchase_order ( - 0 -- a_id_user - , 1 -- a_get_all_order - , 1 -- a_get_inactive_order - , '' -- a_ids_order - , '' -- a_ids_permutation - , NULL -- a_date_from - , NULL -- a_date_to - , 0 -- a_debug -); - - -select * -from partsltd_prod.shop_manufacturing_purchase_order -; -select * -from partsltd_prod.shop_manufacturing_purchase_order_product_link -; -*/ diff --git a/static/MySQL/7421_p_shop_save_customer.sql b/static/MySQL/7421_p_shop_save_customer.sql deleted file mode 100644 index 400ea59e..00000000 --- a/static/MySQL/7421_p_shop_save_customer.sql +++ /dev/null @@ -1,300 +0,0 @@ - - - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_save_customer; - - -DELIMITER // -CREATE PROCEDURE p_shop_save_customer ( - IN a_guid VARCHAR(500), - IN a_id_user INT, - IN a_comment VARCHAR(500), - IN a_id_customer INT, - IN a_name_company VARCHAR(256), - IN a_name_contact VARCHAR(256), - IN a_department_contact VARCHAR(256), - IN a_id_address INT, - IN a_phone_number VARCHAR(20), - IN a_email VARCHAR(515), - IN a_id_currency INT, - IN a_active BIT -) -BEGIN - DECLARE v_id_error_type_bad_data INT; - DECLARE v_id_error_type_no_permission INT; - DECLARE v_guid_permission BINARY(36); - DECLARE v_id_permission_customer INT; - DECLARE v_id_access_level_EDIT INT; - DECLARE v_has_permission BIT; - DECLARE v_id_change_set INT; - DECLARE v_is_new_customer BIT; - - SET v_id_error_type_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA'); - SET v_guid_permission = UUID(); - SET v_id_permission_customer = (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_CUSTOMER' LIMIT 1); - SET v_id_access_level_EDIT = (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'EDIT'); - - -- Argument default values - IF a_guid IS NULL THEN - SET a_guid = UUID(); - END IF; - - - -- Temporary tables - /* - CREATE TABLE tmp_Shop_Customer ( - id_customer INT NOT NULL, - name_company VARCHAR(255) NOT NULL, - name_contact VARCHAR(255) NULL, - department_contact VARCHAR(255) NULL, - id_address INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Customer_id_address - FOREIGN KEY (id_address) - REFERENCES Shop_Address(id_address), - phone_number VARCHAR(50) NULL, - fax VARCHAR(50) NULL, - email VARCHAR(255) NOT NULL, - website VARCHAR(255) NULL, - id_currency INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Customer_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency), - active BIT NOT NULL, - can_view BIT NOT NULL, - can_edit BIT NOT NULL, - can_admin BIT NOT NULL - ); - */ - - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - guid BINARY(36) NOT NULL, - id_type INT NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type (id_type), - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - - - -- Argument validation - IF a_id_customer IS NULL THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, msg - ) - VALUES - (a_guid, v_id_error_type_bad_data, 'Customer ID must not be null') - ; - END IF; - IF a_name_company IS NULL THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, msg - ) - VALUES - (a_guid, v_id_error_type_bad_data, 'Customer company name must not be null') - ; - END IF; - IF a_id_address IS NULL THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, msg - ) - VALUES - (a_guid, v_id_error_type_bad_data, 'Customer address ID must not be null') - ; - END IF; - IF a_email IS NULL THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, msg - ) - VALUES - (a_guid, v_id_error_type_bad_data, 'Customer email must not be null') - ; - END IF; - IF a_active IS NULL THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, msg - ) - VALUES - (a_guid, v_id_error_type_bad_data, 'Customer active status must not be null') - ; - END IF; - - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - SET v_is_new_customer := CASE WHEN a_id_customer <= 0 THEN 1 ELSE 0 END; - - IF (v_is_new_customer = 0 AND NOT EXISTS (SELECT * FROM Shop_Customer C WHERE C.id_customer = a_id_customer)) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, msg - ) - VALUES - (a_guid, v_id_error_type_bad_data, CONCAT('Invalid customer ID: ', a_id_customer)) - ; - END IF; - END IF; - - /* - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - INSERT INTO tmp_Shop_Customer ( - id_customer, name_company, name_contact, department_contact, id_address, phone_number, fax, email, website, id_currency, active - ) - VALUES - (a_id_customer, a_name_company, a_name_contact, a_department_contact, a_id_address, a_phone_number, a_fax, a_email, a_website, a_id_currency, a_active) - /* - FROM Shop_Customer S - WHERE (NOT v_has_filter_category OR C.id_category LIKE '%' || a_ids_category || '%') - AND (a_get_inactive_categories OR C.active) - * - ; - END IF; - */ - - -- Permissions - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - CALL p_shop_calc_user(v_guid_permission, a_id_user, 0, v_id_permission_customer, v_id_access_level_edit, ''); - - /* - UPDATE tmp_Shop_Customer t_S - INNER JOIN Shop_Calc_User_Temp TP - ON TP.GUID = v_guid_permission - SET tP.can_view = TP.can_view, - tP.can_edit = TP.can_edit, - tP.can_admin = TP.can_admin; - */ - SET v_has_permission := (SELECT can_edit FROM Shop_Calc_User_Temp WHERE GUID = v_guid_permission); - - IF v_has_permission = 0 THEN - SET v_id_error_type_no_permission := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'NO_PERMISSION'); - INSERT INTO tmp_Msg_Error ( - guid, id_type, msg - ) - SELECT - a_guid, - v_id_error_type_no_permission, - CONCAT('You do not have ', name, ' permissions.') - FROM Shop_Permission - WHERE id_permission = v_id_permission_customer - ; - END IF; - - -- CALL p_shop_clear_calc_user(v_guid_permission); - - DELETE FROM Shop_Calc_User_Temp - WHERE GUID = a_guid; - END IF; - - - -- Transaction - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - INSERT INTO Shop_Sales_And_Purchasing_Change_Set ( - comment, - updated_last_by, - updated_last_on - ) - VALUES ( - CONCAT( - 'Save ', - CASE WHEN v_is_new_customer = 1 THEN 'new ' ELSE '' END, - 'Customer - ', - a_comment - ), - a_id_user, - CURRENT_TIME() - ); - - SET v_id_change_set := (SELECT id_change_set FROM Shop_Sales_And_Purchasing_Change_Set ORDER BY id_change_set DESC LIMIT 1); - - START TRANSACTION; - IF (v_is_new_customer = 1) THEN - INSERT INTO Shop_Customer ( - -- id_customer, - name_company, name_contact, department_contact, id_address, phone_number, email, id_currency, active, id_change_set - ) - VALUES - ( - -- a_id_customer, - a_name_company, a_name_contact, a_department_contact, a_id_address, a_phone_number, a_email, a_id_currency, a_active, v_id_change_set - ) - /* - FROM Shop_Customer S - WHERE (NOT v_has_filter_category OR C.id_category LIKE '%' || a_ids_category || '%') - AND (a_get_inactive_categories OR C.active) - */ - ; - ELSE - UPDATE Shop_Customer C - -- INNER JOIN tmp_Shop_Customer t_S ON S.id_customer = t_S.id_customer - SET - /* - S.name_company = t_S.name_company, - S.name_contact = t_S.name_contact, - S.department_contact = t_S.department_contact, - S.id_address = t_S.id_address, - S.phone_number = t_S.phone_number, - S.fax = t_S.fax, - S.email = t_S.email, - S.website = t_S.website, - S.id_currency = t_S.id_currency, - S.active = t_S.active - */ - C.name_company = a_name_company, - C.name_contact = a_name_contact, - C.department_contact = a_department_contact, - C.id_address = a_id_address, - C.phone_number = a_phone_number, - C.email = a_email, - C.website = a_website, - C.id_currency = a_id_currency, - C.active = a_active, - C.id_change_set = v_id_change_set - ; - END IF; - - IF EXISTS (SELECT * FROM tmp_Msg_Error) THEN - ROLLBACK; - ELSE - COMMIT; - END IF; - END IF; - - -- Returns - -- SET v_now = NOW(); - - -- Errors - SELECT * - FROM tmp_Msg_Error - ; - - -- DROP TABLE tmp_Shop_Customer; - DROP TABLE tmp_Msg_Error; -END // -DELIMITER ; - - -/* - -CALL p_shop_save_customer ( - 'NIPS', -- a_guid - 'auth0|6582b95c895d09a70ba10fef', -- a_id_user - 'Initial Customer', -- a_comment - '-1', -- a_id_customer - 'good co', -- a_name_company - 'teddy', -- a_name_contact - 'manufacturing', -- a_department_contact - 1, -- a_id_address - 'BRING BRING', -- a_phone_number - 'e@mail.com', -- a_email - 1, -- a_id_currency_cost - 1 -- a_active -); - -SELECT * FROM Shop_Customer -; - -DELETE FROM Shop_Customer -; - -*/ diff --git a/static/MySQL/7422_p_shop_get_many_customer.sql b/static/MySQL/7422_p_shop_get_many_customer.sql deleted file mode 100644 index f26db581..00000000 --- a/static/MySQL/7422_p_shop_get_many_customer.sql +++ /dev/null @@ -1,271 +0,0 @@ - - - -/* - -CALL p_shop_get_many_customer ( - '', -- a_id_user - 1, -- a_get_all_customer - 0, -- a_get_inactive_customer - 0, -- a_get_first_customer_only - '', -- a_ids_customer -); - -*/ - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_get_many_customer; - - -DELIMITER // -CREATE PROCEDURE p_shop_get_many_customer ( - IN a_id_user INT, - IN a_get_all_customer BIT, - IN a_get_inactive_customer BIT, - IN a_get_first_customer_only BIT, - IN a_ids_customer VARCHAR(4000) -) -BEGIN - -- Argument redeclaration - -- Variable declaration - DECLARE v_id_error_type_bad_data INT; - DECLARE v_code_error_type_bad_data VARCHAR(50); - DECLARE v_has_filter_customer BIT; - DECLARE v_guid BINARY(36); - -- DECLARE v_id_user VARCHAR(100); - -- DECLARE v_ids_permutation_unavailable VARCHAR(4000); - DECLARE v_id_permission_customer INT; - -- DECLARE v_ids_product_permission VARCHAR(4000); - -- DECLARE v_ids_permutation_permission VARCHAR(4000); - DECLARE v_id_access_level_view INT; - DECLARE v_now DATETIME; - DECLARE v_id_minimum INT; - - SET v_code_error_type_bad_data = 'BAD_DATA'; - SET v_id_error_type_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_type_bad_data LIMIT 1); - SET v_guid := UUID(); - SET v_id_access_level_view := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW'); - - - -- Argument validation + default values - IF a_id_user IS NULL THEN - SET a_id_user = ''; - ELSE - SET a_id_user = TRIM(a_id_user); - END IF; - IF a_get_inactive_customer IS NULL THEN - SET a_get_inactive_customer = 0; - END IF; - IF a_get_first_customer_only IS NULL THEN - SET a_get_first_customer_only = 0; - END IF; - IF a_ids_customer IS NULL THEN - SET a_ids_customer = ''; - ELSE - SET a_ids_customer = TRIM(REPLACE(a_ids_customer, '|', ',')); - END IF; - - SET v_has_filter_customer = CASE WHEN a_ids_customer = '' THEN 0 ELSE 1 END; - - IF a_get_all_customer IS NULL THEN - SET a_get_all_customer = NOT v_has_filter_customer; - END IF; - - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Shop_Customer; - - CREATE TABLE tmp_Shop_Customer ( - id_customer INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Customer_id_customer - FOREIGN KEY (id_customer) - REFERENCES Shop_Customer(id_customer), - active BIT NOT NULL, - rank_customer INT NULL, - can_view BIT, - can_edit BIT, - can_admin BIT - ); - - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - guid BINARY(36) NOT NULL, - id_type INT NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type (id_type), - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - - - -- Parse filters - SET v_has_filter_customer = CASE WHEN a_ids_customer = '' THEN 0 ELSE 1 END; - - -- select v_has_filter_product, v_has_filter_permutation; - - IF v_has_filter_customer = 1 OR a_get_all_customer = 1 THEN - CALL p_split(v_guid, a_ids_customer, ','); - - IF EXISTS (SELECT * FROM Split_Temp S_T LEFT JOIN Shop_Customer C ON S_T.substring = C.id_customer WHERE ISNULL(C.id_customer)) THEN - INSERT INTO tmp_Msg_Error ( - guid, - id_type, - code, - msg - ) - VALUES ( - v_guid, - v_id_error_type_bad_data, - v_code_error_type_bad_data, - CONCAT('Invalid customer IDs: ', (SELECT GROUP_CONCAT(C.id_customer) FROM Split_Temp S_T LEFT JOIN Shop_Customer C ON S_T.substring = C.id_customer WHERE ISNULL(C.id_customer))) - ) - ; - ELSE - INSERT INTO tmp_Shop_Customer ( - id_customer, - active, - rank_customer - ) - SELECT - C.id_customer, - C.active, - RANK() OVER (ORDER BY C.id_customer ASC) AS rank_customer - FROM Shop_Customer C - LEFT JOIN Split_Temp S_T ON C.id_customer = S_T.substring - WHERE - ( - a_get_all_customer = 1 - OR NOT ISNULL(S_T.substring) - ) - AND ( - a_get_inactive_customer = 1 - OR C.active = 1 - ) - ; - END IF; - - DROP TABLE Split_Temp; - - IF a_get_first_customer_only = 1 THEN - DELETE t_C - FROM tmp_Shop_Customer t_C - WHERE t_C.rank_customer > ( - SELECT MIN(t_C.rank_customer) - FROM tmp_Shop_Customer t_C - ) - ; - END IF; - END IF; - - -- Permissions - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - -- SET v_id_user := (SELECT id_user FROM Shop_User WHERE name = CURRENT_USER()); - SET v_id_permission_customer := (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_CUSTOMER' LIMIT 1); - - -- SELECT v_guid, a_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_permutation_permission; - -- select * from Shop_Calc_User_Temp; - - CALL p_shop_calc_user(v_guid, a_id_user, FALSE, v_id_permission_customer, v_id_access_level_view, ''); - - -- select * from Shop_Calc_User_Temp; - - IF NOT EXISTS (SELECT can_view FROM Shop_Calc_User_Temp UE_T WHERE UE_T.GUID = v_guid) THEN - INSERT INTO tmp_Msg_Error ( - guid, - id_type, - code, - msg - ) - VALUES ( - v_guid, - v_id_error_type_bad_data, - v_code_error_type_bad_data, - CONCAT('You do not have view permissions for ', IFNULL((SELECT name FROM Shop_Permission WHERE id_permission = v_id_permission_customer LIMIT 1), 'Permission not found')) - ) - ; - END IF; - END IF; - - - -- select * from tmp_Shop_Product; - - -- Returns - -- SET v_now := NOW(); - - -- customers - SELECT - t_C.id_customer, - C.name_company, - C.name_contact, - C.department_contact, - C.id_address, - C.phone_number, - C.email, - C.id_currency, - C.active - FROM tmp_Shop_Customer t_C - INNER JOIN Shop_Customer C ON t_C.id_customer = C.id_customer - ; - - -- Errors - SELECT - /* - t_ME.display_order, - t_ME.guid, - t_ME.id_type, - t_ME.msg, - MET.code, - MET.name, - MET.description - */ - * - FROM tmp_Msg_Error t_ME - INNER JOIN Shop_Msg_Error_Type MET - ON t_ME.id_type = MET.id_type - WHERE guid = v_guid - ; - - /* - -- Return arguments for test - SELECT - a_ids_category, - a_get_inactive_category, - a_ids_product, - a_get_inactive_product, - a_get_first_product_only, - a_get_all_product, - a_ids_image, - a_get_inactive_image, - a_get_first_image_only, - a_get_all_image - ; - */ - - -- select 'other outputs'; - -- select * from tmp_Shop_Product; - - -- Clean up - DROP TABLE IF EXISTS tmp_Shop_Customer; - - DELETE FROM Shop_Calc_User_Temp - WHERE GUID = v_guid - ; -END // -DELIMITER ; - - -/* -CALL p_shop_get_many_customer ( - '', -- a_id_user - 1, -- a_get_all_customer - 0, -- a_get_inactive_customer - 0, -- a_get_first_customer_only - '' -- a_ids_customer -); - -SELECT * -FROM Shop_Customer; - -*/ diff --git a/static/MySQL/7424_p_shop_save_customer_sales_order.sql b/static/MySQL/7424_p_shop_save_customer_sales_order.sql deleted file mode 100644 index dbf03770..00000000 --- a/static/MySQL/7424_p_shop_save_customer_sales_order.sql +++ /dev/null @@ -1,557 +0,0 @@ - - - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_save_customer_sales_order; - -DROP TABLE IF EXISTS tmp_Shop_Customer_Sales_Order_Product_Link; -DROP TABLE IF EXISTS tmp_Msg_Error; - -DELIMITER // -CREATE PROCEDURE p_shop_save_customer_sales_order ( - IN a_guid VARCHAR(500), - IN a_id_user INT, - IN a_comment VARCHAR(500), - IN a_id_order INT, - IN a_id_customer INT, - IN a_id_currency_price INT, - IN a_active BIT -) -BEGIN - DECLARE v_id_error_type_bad_data INT; - DECLARE v_code_error_type_bad_data VARCHAR(50); - DECLARE v_id_error_type_no_permission INT; - DECLARE v_code_error_type_no_permission VARCHAR(50); - DECLARE v_guid_permission BINARY(36); - -- DECLARE v_id_user VARCHAR(100); - DECLARE v_id_permission_Customer_Sales_order INT; - DECLARE v_id_access_level_EDIT INT; - DECLARE v_ids_product VARCHAR(4000); - DECLARE v_ids_product_no_permission VARCHAR(4000); - -- DECLARE v_id_order_new INT; - DECLARE v_id_change_set INT; - DECLARE v_is_new_Customer_Sales_order BIT; - - SET SESSION sql_mode = sys.list_drop(@@session.sql_mode, 'ONLY_FULL_GROUP_BY'); - - SET v_code_error_type_bad_data = 'BAD_DATA'; - SET v_id_error_type_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_type_bad_data LIMIT 1); - SET v_code_error_type_no_permission = 'NO_PERMISSION'; - SET v_id_error_type_no_permission := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_type_no_permission LIMIT 1); - SET v_guid_permission = UUID(); - -- SET v_id_user = CURRENT_USER(); - SET v_id_permission_Customer_Sales_order := (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_CUSTOMER_SALES_ORDER' LIMIT 1); - SET v_id_access_level_EDIT := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'EDIT'); - - -- Argument default values - IF a_guid IS NULL THEN - SET a_guid = UUID(); - END IF; - IF a_active IS NULL THEN - SET a_active = 0; - END IF; - - -- Temporary tables - /* - CREATE TABLE tmp_Shop_Customer_Sales_Order ( - id_order INT NOT NULL PRIMARY KEY, - id_supplier_ordered INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Customer_Sales_Order_id_supplier_ordered - FOREIGN KEY (id_supplier_ordered) - REFERENCES Shop_Supplier(id_supplier), - price_total_local FLOAT NOT NULL, - id_currency_price INT NOT NULL - ); - */ - - CREATE TABLE tmp_Shop_Customer_Sales_Order_Product_Link ( - id_link INT NOT NULL PRIMARY KEY, - id_order INT NOT NULL, - /* - CONSTRAINT FK_tmp_Supplier_Purchase_Order_Product_Link_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Customer_Sales_Order(id_order), - */ - id_permutation INT NOT NULL, - CONSTRAINT FK_tmp_Supplier_Purchase_Order_Product_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - price_total_local FLOAT NOT NULL, - id_currency_price INT NOT NULL, - quantity_ordered FLOAT NOT NULL, - id_unit_quantity INT NOT NULL, - CONSTRAINT FK_tmp_Supplier_Purchase_Order_Product_Link_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - quantity_delivered FLOAT NULL, - latency_delivery_days INT NOT NULL, - display_order INT NOT NULL, - active BIT NOT NULL, - name_error VARCHAR(200) NOT NULL - ); - - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - guid BINARY(36) NOT NULL, - id_type INT NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type (id_type), - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - - - -- Argument validation - -- User ID - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF ISNULL(a_id_user) OR NOT EXISTS (SELECT * FROM Shop_User WHERE id_user = a_id_user) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES - (a_guid, v_id_error_type_bad_data, v_code_error_type_bad_data, CONCAT('Invalid User ID: ', IFNULL(a_id_user, 'NULL'))) - ; - END IF; - END IF; - - -- Order ID - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF ISNULL(a_id_order) OR ((a_id_order > 0) AND NOT EXISTS (SELECT * FROM Shop_Customer_Sales_Order WHERE id_order = a_id_order)) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES - (a_guid, v_id_error_type_bad_data, v_code_error_type_bad_data, CONCAT('Invalid Customer Sales Order ID: ', IFNULL(a_id_order, 'NULL'))) - ; - END IF; - END IF; - - -- Customer ID - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF ISNULL(a_id_customer) OR NOT EXISTS (SELECT * FROM Shop_Customer WHERE id_customer = a_id_customer) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES - (a_guid, v_id_error_type_bad_data, v_code_error_type_bad_data, CONCAT('Invalid Customer ID: ', IFNULL(a_id_customer, 'NULL'))) - ; - END IF; - END IF; - - -- Currency ID - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF ISNULL(a_id_currency_price) OR NOT EXISTS (SELECT * FROM Shop_Currency WHERE id_currency = a_id_currency_price) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES - (a_guid, v_id_error_type_bad_data, v_code_error_type_bad_data, CONCAT('Invalid currency ID: ', IFNULL(a_id_currency, 'NULL'))) - ; - END IF; - END IF; - - -- Comment - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF ISNULL(a_comment) OR TRIM(a_comment) = '' THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES - (a_guid, v_id_error_type_bad_data, v_code_error_type_bad_data, 'A comment must be provided.') - ; - END IF; - END IF; - - - -- Get data from Temp table - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - SET v_is_new_Customer_Sales_order := CASE WHEN a_id_order <= 0 THEN 1 ELSE 0 END; - - INSERT INTO tmp_Shop_Customer_Sales_Order_Product_Link ( - id_link, - id_order, - id_permutation, - price_total_local, - id_currency_price, - quantity_ordered, - id_unit_quantity, - quantity_delivered, - latency_delivery_days, - display_order, - active, - name_error - ) - /* - VALUES - (a_id_supplier, a_name_company, a_name_contact, a_department_contact, a_id_address, a_phone_number, a_fax, a_email, a_website, a_id_currency, a_active) - */ - SELECT - CSOPL_T.id_link, - CSOPL_T.id_order, - CSOPL_T.id_permutation, - (PP.cost_local + PP.profit_local_min) * quantity_ordered AS price_total_local, - CSOPL_T.id_currency_price, - CSOPL_T.quantity_ordered, - CSOPL_T.id_unit_quantity, - CSOPL_T.quantity_delivered, - CSOPL_T.latency_delivery_days, - CSOPL_T.display_order, - CSOPL_T.active, - CONCAT(PP.id_permutation, ' - ', IFNULL(P.name ,'')) AS name_error - FROM Shop_Customer_Sales_Order_Product_Link_Temp CSOPL_T - INNER JOIN Shop_Product_Permutation PP ON CSOPL_T.id_permutation = PP.id_permutation - INNER JOIN Shop_Product P ON PP.id_product = P.id_product - WHERE CSOPL_T.GUID = a_guid - ; - DELETE CSOPL_T - FROM Shop_Customer_Sales_Order_Product_Link_Temp CSOPL_T - WHERE CSOPL_T.GUID = a_guid - ; - - /* - UPDATE tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL - SET - price_total_local - */ - END IF; - - -- Invalid quantity ordered - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF EXISTS ( - SELECT * - FROM tmp_Shop_Customer_Sales_Order_Product_Link - WHERE - NOT ISNULL(quantity_ordered) - AND quantity_ordered < 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - SELECT - a_guid, - v_id_error_type_bad_data, - v_code_error_type_bad_data, - CONCAT('Invalid quantity ordered property for the following permutations: ', GROUP_CONCAT(t_CSOPL.name_error SEPARATOR ', ')) - FROM tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL - -- INNER JOIN Shop_Product_Permutation PP ON t_CSOPL.id_permutation = PP.id_permutation - WHERE t_CSOPL.quantity_ordered < 0 - ; - END IF; - END IF; - - -- Duplicates - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF EXISTS (SELECT id_permutation, name_error, COUNT(*) FROM tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL GROUP BY id_permutation HAVING COUNT(*) > 1) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - SELECT - a_guid, - v_id_error_type_bad_data, - v_code_error_type_bad_data, - CONCAT('Duplicate records: ', GROUP_CONCAT(t_CSOPLC.name_error SEPARATOR ', ')) - FROM (SELECT id_permutation, name_error, COUNT(*) FROM tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL GROUP BY id_permutation HAVING COUNT(*) > 1) t_CSOPLC - ; - END IF; - END IF; - - - - -- Permissions - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - SET v_ids_product := ( - SELECT GROUP_CONCAT(G.id_product SEPARATOR ',') - FROM ( - SELECT DISTINCT PP.id_product - FROM tmp_Shop_Customer_Sales_Order_Product_Link t_SPO - INNER JOIN Shop_Product_Permutation PP ON t_SPO.id_permutation = PP.id_permutation - ) G - ); - - CALL p_shop_calc_user(v_guid_permission, a_id_user, 0, v_id_permission_Customer_Sales_order, v_id_access_level_edit, v_ids_product); - - /* - UPDATE tmp_Shop_Supplier t_S - INNER JOIN Shop_Calc_User_Temp TP - ON TP.GUID = v_guid_permission - SET tP.can_view = TP.can_view, - tP.can_edit = TP.can_edit, - tP.can_admin = TP.can_admin; - */ - /* - SET v_has_permission := ( - SELECT can_edit - FROM Shop_Calc_User_Temp - WHERE - GUID = v_guid_permission - AND can_edit = 0 - ); - - IF v_has_permission = 0 THEN - SET v_id_error_type_no_permission := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'NO_PERMISSION'); - INSERT INTO tmp_Msg_Error ( - guid, id_type, msg - ) - SELECT - a_guid, - v_id_error_type_no_permission, - CONCAT('You do not have ', name, ' permissions.') - FROM Shop_Permission - WHERE id_permission = v_id_permission_Customer_Sales_order - ; - END IF; - */ - SET v_ids_product_no_permission := ( - SELECT GROUP_CONCAT(PT.id_product SEPARATOR ',') - FROM Shop_Calc_User_Temp PT - WHERE - PT.can_edit = 0 - AND NOT ISNULL(PT.id_product) - ); - IF NOT ISNULL(v_ids_product_no_permission) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES ( - a_guid, - v_id_error_type_no_permission, - v_code_error_type_no_permission, - CONCAT('You do not have permission to edit the following product IDs: ', v_ids_product_no_permission) - ) - ; - END IF; - - DELETE FROM Shop_Calc_User_Temp - WHERE GUID = a_guid; - END IF; - - -- Transaction - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - START TRANSACTION; - INSERT INTO Shop_Sales_And_Purchasing_Change_Set ( - comment, - updated_last_by, - updated_last_on - ) - VALUES ( - CONCAT( - 'Save ', - CASE WHEN v_is_new_Customer_Sales_order = 1 THEN 'new ' ELSE '' END, - 'Customer Sales Order - ', - a_comment - ), - a_id_user, - CURRENT_TIME() - ); - - SET v_id_change_set := (SELECT id_change_set FROM Shop_Sales_And_Purchasing_Change_Set ORDER BY id_change_set DESC LIMIT 1); - - IF (v_is_new_Customer_Sales_order = 1) THEN - INSERT INTO Shop_Customer_Sales_Order ( - id_customer, - price_total_local, - id_currency_price, - created_by, - id_change_set, - active - ) - SELECT - a_id_customer, - SUM(t_CSOPL.price_total_local), - a_id_currency_price, - a_id_user, - v_id_change_set, - a_active - FROM tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL - ; - -- SET v_id_order_new - SET a_id_order := (SELECT id_order FROM Shop_Customer_Sales_Order ORDER BY id_order DESC LIMIT 1); - INSERT INTO Shop_Customer_Sales_Order_Product_Link ( - id_order, - id_permutation, - price_total_local, - id_currency_price, - quantity_ordered, - id_unit_quantity, - quantity_delivered, - latency_delivery_days, - display_order, - active, - created_by, - id_change_set - ) - SELECT - a_id_order, -- v_id_order_new, - id_permutation, - price_total_local, - id_currency_price, - quantity_ordered, - id_unit_quantity, - quantity_delivered, - latency_delivery_days, - display_order, - active, - a_id_user, - v_id_change_set - FROM tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL - ; - ELSE - UPDATE Shop_Customer_Sales_Order CSO - INNER JOIN tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL ON CSO.id_order = t_CSOPL.id_order - SET - CSO.id_customer = a_id_customer, - CSO.price_total_local = SUM(t_CSOPL.price_total_local), - CSO.id_currency = a_id_currency_price, - CSO.id_change_set = v_id_change_set, - CSO.active = a_active - WHERE SPO.id_order = a_id_order - ; - IF EXISTS (SELECT * FROM tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL INNER JOIN Shop_Customer_Sales_Order_Product_Link CSOPL ON t_CSOPL.id_link = CSOPL.id_link) THEN - UPDATE Shop_Customer_Sales_Order_Product_Link CSOPL - INNER JOIN tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL - ON CSOPL.id_link = t_CSOPL.id_link - SET - CSOPL.id_order = t_CSOPL.id_order, - CSOPL.id_permutation = t_CSOPL.id_permutation, - CSOPL.price_total_local = t_CSOPL.price_total_local, - CSOPL.id_currency_price = t_CSOPL.id_currency_price, - CSOPL.quantity_ordered = t_CSOPL.quantity_ordered, - CSOPL.id_unit_quantity = t_CSOPL.id_unit_quantity, - CSOPL.quantity_delivered = t_CSOPL.quantity_delivered, - CSOPL.latency_delivery_days = t_CSOPL.latency_delivery_days, - CSOPL.display_order = t_CSOPL.display_order, - CSOPL.active = t_CSOPL.active, - CSOPL.id_change_set = v_id_change_set - ; - ELSE - INSERT INTO Shop_Customer_Sales_Order_Product_Link ( - id_order, - id_permutation, - price_total_local, - id_currency_price, - quantity_ordered, - id_unit_quantity, - quantity_delivered, - latency_delivery_days, - display_order, - active, - created_by, - id_change_set - ) - SELECT - id_order, - id_permutation, - price_total_local, - id_currency_price, - quantity_ordered, - id_unit_quantity, - quantity_delivered, - latency_delivery_days, - display_order, - active, - a_id_user, - v_id_change_set - FROM tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL - WHERE t_CSOPL.id_link < 0 - ; - END IF; - END IF; - - IF EXISTS (SELECT * FROM tmp_Msg_Error) THEN - ROLLBACK; - ELSE - COMMIT; - END IF; - END IF; - - -- Returns - -- SET v_now = NOW(); - - -- Supplier Purchase Orders - SELECT * - FROM Shop_Customer_Sales_Order - WHERE id_order = a_id_order - ; - - -- Supplier Purchase Order Product Links - SELECT * - FROM Shop_Customer_Sales_Order_Product_Link - WHERE id_order = a_id_order - ; - - -- Errors - SELECT * - FROM tmp_Msg_Error - ; - - -- DROP TABLE tmp_Shop_Customer_Sales_Order; - DROP TABLE tmp_Shop_Customer_Sales_Order_Product_Link; - DROP TABLE tmp_Msg_Error; -END // -DELIMITER ; - - -/* - -DELETE FROM Shop_Customer_Sales_Order_Product_Link_Audit; -DELETE FROM Shop_Customer_Sales_Order_Product_Link; -DELETE FROM Shop_Customer_Sales_Order_Product_Link_Temp; -DELETE FROM Shop_Customer_Sales_Order_Audit; -DELETE FROM Shop_Customer_Sales_Order; - -INSERT INTO Shop_Customer_Sales_Order_Product_Link_Temp ( - guid, - id_link, - id_order, - id_permutation, - price_total_local, - id_currency_price, - quantity_ordered, - id_unit_quantity, - quantity_delivered, - latency_delivery_days, - display_order, - active -) -VALUES - ( - 'NIPS', -- guid - -1, -- id_link, - -1, -- id_order, - 1, -- id_permutation, - 100, -- price_total_local, - 1, -- id_currency_price, - 1, -- quantity_ordered, - 1, -- id_unit_quantity, - 1, -- quantity_delivered, - 14, -- latency_delivery_days , - 1, -- display_order - 1 -- active - ) -; - -SELECT * FROM Shop_Customer_Sales_Order_Product_Link_Temp; - -CALL p_shop_save_customer_sales_order ( - 'NIPS', -- a_guid - 'auth0|6582b95c895d09a70ba10fef', -- a_id_user - 'Initial customer', -- a_comment - -1, -- a_id_order - 4, -- a_id_customer - 1, -- a_id_currency_price - 1 -- a_active -); - -SELECT * FROM Shop_Customer_Sales_Order_Product_Link_Temp; - -DELETE FROM Shop_Customer_Sales_Order_Product_Link_Audit; -DELETE FROM Shop_Customer_Sales_Order_Product_Link; -DELETE FROM Shop_Customer_Sales_Order_Product_Link_Temp; -DELETE FROM Shop_Customer_Sales_Order_Audit; -DELETE FROM Shop_Customer_Sales_Order; - - -*/ - diff --git a/static/MySQL/7425_p_shop_get_many_customer_sales_order.sql b/static/MySQL/7425_p_shop_get_many_customer_sales_order.sql deleted file mode 100644 index d5ce1ca9..00000000 --- a/static/MySQL/7425_p_shop_get_many_customer_sales_order.sql +++ /dev/null @@ -1,776 +0,0 @@ - - - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_get_many_customer_sales_order; - - -DELIMITER // -CREATE PROCEDURE p_shop_get_many_customer_sales_order ( - IN a_id_user INT, - IN a_get_all_customer BIT, - IN a_get_inactive_customer BIT, - IN a_get_first_customer_only BIT, - IN a_ids_customer VARCHAR(4000), - IN a_get_all_order BIT, - IN a_get_inactive_order BIT, - IN a_get_first_order_only BIT, - IN a_ids_order VARCHAR(4000), - IN a_get_inactive_category BIT, - IN a_ids_category VARCHAR(4000), - IN a_get_inactive_product BIT, - IN a_ids_product VARCHAR(4000), - IN a_get_inactive_permutation BIT, - IN a_ids_permutation VARCHAR(4000), - IN a_date_from DATETIME, - IN a_date_to DATETIME -) -BEGIN - -- Argument redeclaration - -- Variable declaration - DECLARE v_has_filter_customer BIT; - DECLARE v_has_filter_order BIT; - DECLARE v_has_filter_category BIT; - DECLARE v_has_filter_product BIT; - DECLARE v_has_filter_permutation BIT; - DECLARE v_has_filter_date_from BIT; - DECLARE v_has_filter_date_to BIT; - DECLARE v_guid BINARY(36); - -- DECLARE v_id_user VARCHAR(100); - -- DECLARE v_ids_permutation_unavailable VARCHAR(4000); - DECLARE v_ids_permission_customer_purchase_order VARCHAR(4000); - DECLARE v_ids_product_permission VARCHAR(4000); - -- DECLARE v_ids_permutation_permission VARCHAR(4000); - DECLARE v_id_access_level_view INT; - -- DECLARE v_now DATETIME; - -- DECLARE v_id_minimum INT; - DECLARE v_code_error_data VARCHAR(50); - DECLARE v_id_type_error_data INT; - - SET v_guid := UUID(); - SET v_id_access_level_view := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW' LIMIT 1); - -- SET v_ids_permission_customer_purchase_order := (SELECT id_permission FROM Shop_Permission WHERE code = 'Shop_Customer_Sales_ORDER' LIMIT 1); - SET v_code_error_data = 'BAD_DATA'; - SET v_id_type_error_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_data); - - -- Argument validation + default values - IF a_id_user IS NULL THEN - SET a_id_user = ''; - ELSE - SET a_id_user = TRIM(a_id_user); - END IF; - IF a_get_inactive_customer IS NULL THEN - SET a_get_inactive_customer = 0; - END IF; - IF a_get_first_customer_only IS NULL THEN - SET a_get_first_customer_only = 0; - END IF; - IF a_ids_customer IS NULL THEN - SET a_ids_customer = ''; - ELSE - SET a_ids_customer = TRIM(REPLACE(a_ids_customer, '|', ',')); - END IF; - - SET v_has_filter_customer = CASE WHEN a_ids_customer = '' THEN 0 ELSE 1 END; - - IF a_get_all_customer IS NULL THEN - SET a_get_all_customer = NOT v_has_filter_customer; - END IF; - IF a_get_inactive_order IS NULL THEN - SET a_get_inactive_order = 0; - END IF; - IF a_get_first_order_only IS NULL THEN - SET a_get_first_order_only = 0; - END IF; - IF a_ids_order IS NULL THEN - SET a_ids_order = ''; - ELSE - SET a_ids_order = TRIM(REPLACE(a_ids_order, '|', ',')); - END IF; - - SET v_has_filter_order = CASE WHEN a_ids_order = '' THEN 0 ELSE 1 END; - - IF a_get_all_order IS NULL THEN - SET a_get_all_order = NOT v_has_filter_customer; - END IF; - IF a_get_inactive_category IS NULL THEN - SET a_get_inactive_category = 0; - END IF; - IF a_ids_category IS NULL THEN - SET a_ids_category = ''; - ELSE - SET a_ids_category = TRIM(REPLACE(a_ids_category, '|', ',')); - END IF; - IF a_get_inactive_product IS NULL THEN - SET a_get_inactive_product = 0; - END IF; - IF a_ids_product IS NULL THEN - SET a_ids_product = ''; - ELSE - SET a_ids_product = TRIM(REPLACE(a_ids_product, '|', ',')); - END IF; - IF a_get_inactive_permutation IS NULL THEN - SET a_get_inactive_permutation = 0; - END IF; - IF a_ids_permutation IS NULL THEN - SET a_ids_permutation = ''; - ELSE - SET a_ids_permutation = TRIM(REPLACE(a_ids_permutation, '|', ',')); - END IF; - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Shop_Customer_Sales_Order_Product_Link; - DROP TABLE IF EXISTS tmp_Shop_Customer_Sales_Order; - DROP TABLE IF EXISTS tmp_Shop_Customer; - DROP TABLE IF EXISTS tmp_Shop_Product; - - CREATE TABLE tmp_Shop_Customer ( - id_customer INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Customer_id_customer - FOREIGN KEY (id_customer) - REFERENCES Shop_Customer(id_customer), - active BIT NOT NULL, - rank_customer INT NULL, - can_view BIT, - can_edit BIT, - can_admin BIT - ); - - CREATE TABLE tmp_Shop_Customer_Sales_Order ( - id_order INT NOT NULL PRIMARY KEY, - /* - id_customer INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Customer_Sales_Order_id_customer - FOREIGN KEY (id_customer) - REFERENCES Shop_Customer(id_customer), - price_total_local FLOAT NOT NULL, - id_currency_price INT NOT NULL, - */ - active BIT NOT NULL, - rank_order INT NOT NULL - ); - - /* - CREATE TABLE tmp_Shop_Customer_Sales_Order_Product_Link ( - id_link INT NOT NULL PRIMARY KEY, - id_order INT NOT NULL, - CONSTRAINT FK_tmp_customer_Purchase_Order_Product_Link_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Customer_Sales_Order(id_order), - id_permutation INT NOT NULL, - CONSTRAINT FK_tmp_customer_Purchase_Order_Product_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - price_total_local FLOAT NOT NULL, - id_currency_price INT NOT NULL, - quantity_ordered FLOAT NOT NULL, - id_unit_quantity INT NOT NULL, - CONSTRAINT FK_tmp_customer_Purchase_Order_Product_Link_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - quantity_received FLOAT NULL, - latency_delivery_days INT NOT NULL, - display_order INT NOT NULL - ); - */ - - CREATE TABLE tmp_Shop_Product ( - id_category INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_category - FOREIGN KEY (id_category) - REFERENCES Shop_Product_Category(id_category), - id_product INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - -- product_has_variations BIT NOT NULL, - id_permutation INT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - active_category BIT NOT NULL, - active_product BIT NOT NULL, - active_permutation BIT NULL, - display_order_category INT NOT NULL, - display_order_product INT NOT NULL, - display_order_permutation INT NULL, - rank_permutation INT NOT NULL, -- _in_category - -- name VARCHAR(255) NOT NULL, - -- description VARCHAR(4000) NOT NULL, - /* - price_GBP_full FLOAT NOT NULL, - price_GBP_min FLOAT NOT NULL, - */ - /* - latency_manufacture INT NOT NULL, - quantity_min FLOAT NOT NULL, - quantity_max FLOAT NOT NULL, - quantity_step FLOAT NOT NULL, - quantity_stock FLOAT NOT NULL, - is_subscription BIT NOT NULL, - id_unit_measurement_interval_recurrence INT, - CONSTRAINT FK_tmp_Shop_Product_id_unit_measurement_interval_recurrence - FOREIGN KEY (id_unit_measurement_interval_recurrence) - REFERENCES Shop_Interval_Recurrence(id_interval), - count_interval_recurrence INT, - id_stripe_product VARCHAR(100), - product_has_variations INT NOT NULL, - */ - can_view BIT, - can_edit BIT, - can_admin BIT - ); - - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - guid BINARY(36) NOT NULL, - id_type INT NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type (id_type), - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - - - -- Parse filters - SET v_has_filter_category = CASE WHEN a_ids_category = '' THEN 0 ELSE 1 END; - SET v_has_filter_product = CASE WHEN a_ids_product = '' THEN 0 ELSE 1 END; - SET v_has_filter_permutation = CASE WHEN a_ids_permutation = '' THEN 0 ELSE 1 END; - SET v_has_filter_date_from = CASE WHEN ISNULL(a_date_from) THEN 0 ELSE 1 END; - SET v_has_filter_date_to = CASE WHEN ISNULL(a_date_to) THEN 0 ELSE 1 END; - - -- select v_has_filter_product, v_has_filter_permutation; - - IF v_has_filter_customer = 1 OR a_get_all_customer = 1 THEN - CALL p_split(v_guid, a_ids_customer, ','); - - IF EXISTS (SELECT * FROM Split_Temp TS LEFT JOIN Shop_Customer S ON TS.substring = S.id_customer WHERE ISNULL(S.id_customer)) THEN - INSERT INTO tmp_Msg_Error ( - guid, - id_type, - code, - msg - ) - SELECT - v_guid, - v_id_type_error_data, - v_code_error_data, - CONCAT('Invalid customer IDs: ', IFNULL(GROUP_CONCAT(TS.substring SEPARATOR ', '), 'NULL')) - FROM Split_Temp TS - LEFT JOIN Shop_Customer C ON TS.substring = C.id_customer - WHERE ISNULL(C.id_customer) - ; - ELSE - INSERT INTO tmp_Shop_Customer ( - id_customer, - active, - rank_customer - ) - SELECT - C.id_customer, - C.active, - RANK() OVER (ORDER BY id_customer ASC) AS rank_customer - FROM Shop_Customer C - LEFT JOIN Split_Temp S_T ON C.id_customer = S_T.substring - WHERE - ( - a_get_all_customer = 1 - OR NOT ISNULL(S_T.substring) - ) - AND ( - a_get_inactive_customer - OR C.active = 1 - ) - ; - END IF; - - DROP TABLE Split_Temp; - - IF a_get_first_customer_only THEN - DELETE t_C - FROM tmp_Shop_Customer t_C - WHERE t_C.rank_customer > ( - SELECT MIN(t_C.rank_customer) - FROM tmp_Shop_Customer t_C - ) - ; - END IF; - END IF; - - IF v_has_filter_category = 1 THEN - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - CALL p_split(v_guid, a_ids_category, ','); - - IF EXISTS (SELECT * FROM Split_Temp TS LEFT JOIN Shop_Product_Category C ON TS.substring = C.id_category WHERE ISNULL(C.id_category)) THEN - INSERT INTO tmp_Msg_Error ( - guid, - id_type, - code, - msg - ) - SELECT - v_guid, - v_id_type_error_data, - v_code_error_data, - CONCAT('Invalid category IDs: ', IFNULL(GROUP_CONCAT(TS.substring SEPARATOR ', ') ,'NULL')) - FROM Split_Temp TS - LEFT JOIN Shop_Product_Category C ON TS.substring = C.id_category - WHERE ISNULL(C.id_category) - ; - END IF; - - DROP TABLE Temp_Split; - END IF; - END IF; - - IF v_has_filter_product = 1 THEN - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - CALL p_split(v_guid, a_ids_product, ','); - - IF EXISTS (SELECT * FROM Split_Temp TS LEFT JOIN Shop_Product ON TS.substring = P.id_product WHERE ISNULL(P.id_product)) THEN - INSERT INTO tmp_Msg_Error ( - guid, - id_type, - code, - msg - ) - SELECT - v_guid, - v_id_type_error_data, - v_code_error_data, - CONCAT('Invalid product IDs: ', IFNULL(GROUP_CONCAT(TS.substring SEPARATOR ', ') ,'NULL')) - FROM Split_Temp TS - LEFT JOIN Shop_Product ON TS.substring = P.id_product - WHERE ISNULL(P.id_product) - ; - END IF; - - DROP TABLE Temp_Split; - END IF; - END IF; - - IF v_has_filter_permutation = 1 THEN - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - CALL p_split(v_guid, a_ids_permutation, ','); - - IF EXISTS (SELECT * FROM Split_Temp TS LEFT JOIN Shop_Product_Permutation PP ON TS.substring = PP.id_permutation WHERE ISNULL(PP.id_permutation)) THEN - INSERT INTO tmp_Msg_Error ( - guid, - id_type, - code, - msg - ) - SELECT - v_guid, - v_id_type_error_data, - v_code_error_data, - CONCAT('Invalid permutation IDs: ', IFNULL(GROUP_CONCAT(TS.substring SEPARATOR ', ') ,'NULL')) - FROM Split_Temp TS - LEFT JOIN Shop_Product_Permutation PP ON TS.substring = PP.id_permutation - WHERE ISNULL(PP.id_permutation) - ; - END IF; - - DROP TABLE Temp_Split; - END IF; - END IF; - - IF v_has_filter_category = 1 OR v_has_filter_product = 1 OR v_has_filter_permutation = 1 THEN - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - INSERT INTO tmp_Shop_Product ( - id_category, - id_product, - id_permutation, - active_category, - active_product, - active_permutation, - display_order_category, - display_order_product, - display_order_permutation - -- rank_permutation, - /* - name, - description, - / * - price_GBP_VAT_incl, - price_GBP_VAT_excl, - price_GBP_min, - * - latency_manufacture, - quantity_min, - quantity_max, - quantity_step, - quantity_stock, - is_subscription, - id_unit_measurement_interval_recurrence, - count_interval_recurrence, - id_stripe_product, - product_has_variations - */ - ) - SELECT - P.id_category, - P.id_product, - -- P.has_variations AS product_has_variations, - PP.id_permutation, - C.active AS active_category, - P.active AS active_product, - PP.active AS active_permutation, - C.display_order AS display_order_category, - P.display_order AS display_order_product, - PP.display_order AS display_order_permutation - -- RANK() OVER (ORDER BY C.display_order, P.display_order, PP.display_order) AS rank_permutation, --PARTITION BY P.id_category -- _in_category - /* - P.name, - PP.description, - / * - PP.price_GBP_VAT_incl, - PP.price_GBP_VAT_excl, - PP.price_GBP_min, - * - PP.latency_manufacture, - PP.quantity_min, - PP.quantity_max, - PP.quantity_step, - PP.quantity_stock, - PP.is_subscription, - PP.id_unit_measurement_interval_recurrence, - PP.count_interval_recurrence, - PP.id_stripe_product, - P.has_variations - */ - FROM Shop_Product P - INNER JOIN Shop_Product_Permutation PP - ON P.id_product = PP.id_product - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - WHERE - -- permutations - ( - ( - NOT v_has_filter_permutation - OR FIND_IN_SET(PP.id_permutation, a_ids_permutation) > 0 - ) - AND ( - a_get_inactive_permutation - OR PP.active = 1 - ) - ) - -- categories - AND ( - ( - NOT v_has_filter_category - OR FIND_IN_SET(P.id_category, a_ids_category) > 0 - ) - AND ( - a_get_inactive_category - OR C.active = 1 - ) - ) - -- products - AND ( - ( - NOT v_has_filter_product - OR FIND_IN_SET(P.id_product, a_ids_product) > 0 - ) - AND ( - a_get_inactive_product - OR P.active = 1 - ) - ) - ; - END IF; - END IF; - - -- Get orders - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - CALL p_split(v_guid, a_ids_order, ','); - - IF v_has_filter_order AND EXISTS (SELECT * FROM Split_Temp TS LEFT JOIN Shop_Customer_Sales_Order CSO ON TS.substring = CSO.id_order WHERE ISNULL(CSO.id_order)) THEN - INSERT INTO tmp_Msg_Error ( - guid, - id_type, - code, - msg - ) - SELECT - v_guid, - v_id_type_error_data, - v_code_error_data, - CONCAT('Invalid order IDs: ', IFNULL(GROUP_CONCAT(TS.substring SEPARATOR ', '), 'NULL')) - FROM Split_Temp TS - LEFT JOIN Shop_Customer_Sales_Order CSO ON TS.substring = CSO.id_order - WHERE ISNULL(CSO.id_order) - ; - END IF; - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - INSERT INTO tmp_Shop_Customer_Sales_Order ( -- _Product_Link - id_order, - active, - rank_order - ) - SELECT - CSO.id_order, - CSO.active, - RANK() OVER (ORDER BY CSO.id_order ASC) AS rank_order - FROM Shop_Customer_Sales_Order CSO - LEFT JOIN Split_Temp S_T ON CSO.id_order = S_T.substring - INNER JOIN Shop_Customer_Sales_Order_Product_Link CSOPL ON CSO.id_order = CSOPL.id_order - INNER JOIN Shop_Customer S ON CSO.id_customer = S.id_customer - INNER JOIN Shop_Product_Permutation PP ON CSOPL.id_permutation = PP.id_permutation - INNER JOIN Shop_Product P ON PP.id_product = P.id_product - INNER JOIN Shop_Product_Category C ON P.id_category = C.id_category - LEFT JOIN tmp_Shop_Product t_P ON CSOPL.id_permutation = t_P.id_permutation - LEFT JOIN tmp_Shop_Customer t_S ON CSO.id_customer = t_S.id_customer - WHERE - -- customer - /* - ( - a_get_all_customer = 1 - OR NOT ISNULL(t_S.id_customer) -- CSO.id_customer IN (SELECT DISTINCT id_customer FROM tmp_Shop_Customer) - ) - */ - NOT ISNULL(t_S.id_customer) - -- order - AND ( - ( - a_get_all_order = 1 - OR ( - -- ID - -- FIND_IN_SET(CSO.id_order, a_ids_order) > 0 - NOT ISNULL(S_T.substring) - -- date - AND ( - ( - v_has_filter_date_from = 0 - OR CSO.created_on > a_date_from - ) - AND ( - v_has_filter_date_to = 0 - OR CSO.created_on < a_date_to - ) - ) - ) - ) - -- active - AND ( - a_get_inactive_order - OR CSO.active = 1 - ) - ) - -- permutations - AND ( - ( - v_has_filter_category = 0 - AND v_has_filter_product = 0 - AND v_has_filter_permutation = 0 - ) - OR NOT ISNULL(t_P.id_permutation) -- CSO.id_permutation IN (SELECT DISTINCT id_permutation FROM tmp_Shop_Product) - ) - ; - END IF; - - DROP TABLE Split_Temp; - - IF a_get_first_order_only THEN - DELETE t_CSO - FROM tmp_Shop_Customer_Sales_Order t_CSO - WHERE t_CSO.rank_order > ( - SELECT MIN(t_CSO.rank_order) - FROM tmp_Shop_Customer_Sales_Order t_CSO - ) - ; - END IF; - END IF; - - -- Permissions - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - -- SET v_id_user := (SELECT id_user FROM Shop_User WHERE name = CURRENT_USER()); - SET v_ids_permission_customer_purchase_order := (SELECT GROUP_CONCAT(id_permission SEPARATOR ',') FROM Shop_Permission WHERE code IN ('STORE_customer', 'STORE_customer_PURCHASE_ORDER')); - -- SET v_ids_permutation_permission := (SELECT GROUP_CONCAT(id_permutation SEPARATOR ',') FROM tmp_Shop_Product WHERE NOT ISNULL(id_permutation)); - SET v_ids_product_permission := (SELECT GROUP_CONCAT(P.id_product SEPARATOR ',') FROM (SELECT DISTINCT id_product FROM tmp_Shop_Product WHERE NOT ISNULL(id_product)) P); - - -- SELECT v_guid, a_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_permutation_permission; - -- select * from Shop_Calc_User_Temp; - - CALL p_shop_calc_user(v_guid, a_id_user, FALSE, v_ids_permission_customer_purchase_order, v_id_access_level_view, v_ids_product_permission); - - -- select * from Shop_Calc_User_Temp; - - IF NOT EXISTS (SELECT can_view FROM Shop_Calc_User_Temp UE_T WHERE UE_T.GUID = v_guid) THEN - INSERT INTO tmp_Msg_Error ( - guid, - id_type, - code, - msg - ) - SELECT - v_guid, - v_id_type_error_data, - v_code_error_data, - CONCAT('You do not have view permissions for ', GROUP_CONCAT(name SEPARATOR ', ')) - FROM Shop_Permission - WHERE id_permission = v_ids_permission_customer_purchase_order - ; - END IF; - - - UPDATE tmp_Shop_Product t_P - INNER JOIN Shop_Calc_User_Temp UE_T - ON t_P.id_product = UE_T.id_product -- t_P.id_permutation = UE_T.id_permutation - AND UE_T.GUID = v_guid - SET t_P.can_view = UE_T.can_view, - t_P.can_edit = UE_T.can_edit, - t_P.can_admin = UE_T.can_admin - ; - - -- CALL p_shop_clear_calc_user(v_guid); - -- DROP TABLE IF EXISTS Shop_Calc_User_Temp; - DELETE FROM Shop_Calc_User_Temp - WHERE GUID = v_guid - ; - END IF; - - - -- select * from tmp_Shop_Customer; - -- select * from tmp_Shop_Product; - - -- Returns - -- SET v_now := NOW(); - - -- customers - SELECT - t_S.id_customer, - S.name_company, - S.name_contact, - S.department_contact, - S.id_address, - S.phone_number, - S.email, - S.id_currency, - t_S.active - FROM tmp_Shop_Customer t_S - INNER JOIN Shop_Customer S - ON t_S.id_customer = S.id_customer - ; - - -- Customer Sales Order - SELECT -- * - t_CSO.id_order, - CSO.id_customer, - CSO.price_total_local, - CSO.id_currency_price, - t_CSO.active - FROM Shop_Customer_Sales_Order CSO - INNER JOIN tmp_Shop_Customer_Sales_Order t_CSO ON CSO.id_order = t_CSO.id_order - ; - - -- Customer Sales Order Product Link - SELECT - CSOPL.id_link, - CSOPL.id_order, - CSOPL.id_permutation, - P.name as name_product, - CSOPL.price_total_local, - CSOPL.id_currency_price, - CSOPL.quantity_ordered, - CSOPL.id_unit_quantity, - CSOPL.quantity_delivered, - CSOPL.latency_delivery_days, - CSOPL.display_order - FROM Shop_Customer_Sales_Order_Product_Link CSOPL - -- INNER JOIN tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL ON CSOPL.id_link = t_CSOPL.id_link - INNER JOIN tmp_Shop_Customer_Sales_Order t_CSO ON CSOPL.id_order = t_CSO.id_order - INNER JOIN Shop_Product_Permutation PP ON CSOPL.id_permutation = PP.id_permutation - INNER JOIN Shop_Product P ON PP.id_product = P.id_product - INNER JOIN Shop_Product_Category C ON P.id_category = C.id_category - ORDER BY CSOPL.id_order, C.display_order, P.display_order, PP.display_order - ; - - -- Errors - SELECT - /* - t_ME.display_order, - t_ME.guid, - t_ME.id_type, - t_ME.msg, - MET.code, - MET.name, - MET.description - */ - * - FROM tmp_Msg_Error t_ME - INNER JOIN Shop_Msg_Error_Type MET - ON t_ME.id_type = MET.id_type - WHERE guid = v_guid - ; - - /* - -- Return arguments for test - SELECT - a_ids_category, - a_get_inactive_category, - a_ids_product, - a_get_inactive_product, - a_get_first_product_only, - a_get_all_product, - a_ids_image, - a_get_inactive_image, - a_get_first_image_only, - a_get_all_image - ; - */ - - -- select 'other outputs'; - -- select * from tmp_Shop_Product; - - -- Clean up - DROP TABLE IF EXISTS tmp_Shop_Customer_Sales_Order_Product_Link; - DROP TABLE IF EXISTS tmp_Shop_Customer_Sales_Order; - DROP TABLE IF EXISTS tmp_Shop_Customer; - DROP TABLE IF EXISTS tmp_Shop_Product; - - DELETE FROM Shop_Calc_User_Temp - WHERE GUID = v_guid - ; -END // -DELIMITER ; - - -/* - -CALL p_shop_get_many_customer_sales_order ( - '', -- a_id_user - 1, -- a_get_all_customer - 0, -- a_get_inactive_customer - 0, -- a_get_first_customer_only - '', -- a_ids_customer - 1, -- a_get_all_order - 0, -- a_get_inactive_order - 0, -- a_get_first_order_only - '', -- a_ids_order - 0, -- a_get_inactive_category - '', -- a_ids_category - 0, -- a_get_inactive_product - '', -- a_ids_product - 0, -- a_get_inactive_permutation - '', -- a_ids_permutation - NULL, -- a_date_from - NULL -- a_date_to -); - -select * from shop_image; -select * from shop_product; -select * from TMP_MSG_ERROR; -DROP TABLE TMP_MSG_ERROR; - -insert into shop_product_change_set (comment) - values ('set product not subscription - test bool output to python'); - update shop_product - set is_subscription = 0, - id_change_set = (select id_change_set from shop_product_change_set order by id_change_set desc limit 1) - where id_product = 1 -*/ diff --git a/static/MySQL/9000_populate.sql b/static/MySQL/9000_populate.sql index bf38ef57..93656437 100644 --- a/static/MySQL/9000_populate.sql +++ b/static/MySQL/9000_populate.sql @@ -1,875 +1,118 @@ +USE partsltd_prod; -/* - -CALL p_populate_database () - -*/ - -/* --- Remove previous proc -DROP PROCEDURE IF EXISTS p_populate_database; - - -DELIMITER // -CREATE PROCEDURE p_populate_database () -BEGIN -*/ - - --- Access Levels -INSERT INTO Shop_Access_Level ( - display_order, code, name, priority -) -VALUES - (1, 'VIEW', 'View', 3), - (2, 'EDIT', 'Edit', 2), - (3, 'ADMIN', 'Admin', 1) -; - -- Error Message Types -INSERT INTO Shop_Msg_Error_Type ( - code, name, description -) -VALUES - ('BAD_DATA', 'Invalid data', 'Rubbish data') - , ('NO_PERMISSION', 'No permission', 'Not authorised') - , ('PRODUCT_AVAILABILITY', 'Product not available', 'Product not available') - , ('MYSQL_ERROR', 'MySQL error', 'MySQL execution error.') - , ('WARNING', 'Warning', 'Non-breaking error.') -; - --- File Types -INSERT INTO File_Type ( - code, name, extension -) -VALUES - ('JPEG', 'Joint Photographic Export Group', 'jpg'), - ('PNG', 'Portable Network Graphic', 'png'), - ('GIF', 'GIF', 'gif'), - ('MPEG-4', 'Multimedia Photographic Export Group 4', 'mp4') -; - --- Generic / shared properties -INSERT INTO Shop_General ( - quantity_max -) -VALUES ( - 10 -); - --- Image types -INSERT INTO Shop_Image_Type ( - display_order, code, name, name_plural -) -VALUES - (1, 'FULL', 'Full Quality Image', 'Full Quality Images'), - (2, 'LOW', 'Low Quality Image', 'Low Quality Images'), - (3, 'THUMBNAIL', 'Thumbnail Image', 'Thumbnail Images') -; - --- Regions -INSERT INTO Shop_Region ( - display_order, code, name -) -VALUES - (1, 'UK', 'United Kingdom') -; - -/* --- Region Branches -INSERT INTO Shop_Region_Branch ( - display_order, id_region_parent, id_region_child -) -VALUES - (1, 1, 2) -; -*/ - --- Addresses -INSERT INTO Shop_Address ( - id_region, postcode, address_line_1, address_line_2, city, county -) -VALUES ( - 1, 'CV22 6DN', '53 Alfred Green Close', '', 'Rugby', 'Warwickshire' -); - --- Plants -INSERT INTO Shop_Plant ( - code, name, id_address, id_user_manager -) -VALUES - ('MAIN', 'Main Plant', 1, 1) -; - --- Storage Locations -INSERT INTO Shop_Storage_Location ( - id_plant, code, name -) -VALUES - (1, 'K-F-1', 'Kitchen Fridge 1') - , (1, 'K-AHL-M-B', 'Kitchen - Above Hob Left Medial - Bottom') - , (1, 'K-AHL-M-M', 'Kitchen - Above Hob Left Medial - Middle') - , (1, 'K-AHL-M-T', 'Kitchen - Above Hob Left Medial - Top') - , (1, 'K-AHL-L-B', 'Kitchen - Above Hob Left Lateral - Bottom') - , (1, 'K-AHL-L-M', 'Kitchen - Above Hob Left Lateral - Middle') - , (1, 'K-AHL-L-T', 'Kitchen - Above Hob Left Lateral - Top') - , (1, 'K-AHR-M-B', 'Kitchen - Above Hob Left Medial - Bottom') - , (1, 'K-AHR-M-M', 'Kitchen - Above Hob Left Medial - Middle') - , (1, 'K-AHR-M-T', 'Kitchen - Above Hob Left Medial - Top') - , (1, 'K-AHL-M-B', 'Kitchen - Above Hob Left Medial - Bottom') - , (1, 'K-AHL-M-M', 'Kitchen - Above Hob Left Medial - Middle') - , (1, 'K-AHL-M-T', 'Kitchen - Above Hob Left Medial - Top') - , (1, 'K-AHL-L-B', 'Kitchen - Above Hob Left Lateral - Bottom') - , (1, 'K-AHL-L-M', 'Kitchen - Above Hob Left Lateral - Middle') - , (1, 'K-AHL-L-T', 'Kitchen - Above Hob Left Lateral - Top') - , (1, 'K-AHL-XL-B', 'Kitchen - Above Hob Left Extra Lateral - Bottom') - , (1, 'K-AHL-XL-M', 'Kitchen - Above Hob Left Extra Lateral - Middle') - , (1, 'K-AHL-XL-T', 'Kitchen - Above Hob Left Extra Lateral - Top') - , (1, 'K-BS-B', 'Kitchen - Below Sink - Bottom') - , (1, 'K-BS-T', 'Kitchen - Below Sink - Top') - , (1, 'K-LO-B', 'Kitchen - Left of Oven - Bottom') - , (1, 'K-LO-T', 'Kitchen - Left of Oven - Top') - , (1, 'K-RO-M-B', 'Kitchen - Right of Oven - Medial - Bottom') - , (1, 'K-RO-M-M', 'Kitchen - Right of Oven - Medial - Middle') - , (1, 'K-RO-M-T', 'Kitchen - Right of Oven - Medial - Top') - , (1, 'K-RO-L-B', 'Kitchen - Right of Oven - Lateral - Bottom') - , (1, 'K-RO-L-T', 'Kitchen - Right of Oven - Lateral - Top') - , (1, 'K-BBB-B', 'Kitchen - Below Breakfast Bar - Bottom') - , (1, 'K-BBB-T', 'Kitchen - Below Breakfast Bar - Top') - , (1, 'K-BSL-M-B', 'Kitchen - Bekow Sink Left - Medial - Bottom') - , (1, 'K-BSL-M-T', 'Kitchen - Bekow Sink Left - Medial - Top') - , (1, 'K-BSL-L-B', 'Kitchen - Bekow Sink Left - Lateral - Bottom') - , (1, 'K-BSL-L-T', 'Kitchen - Bekow Sink Left - Lateral - Top') - , (1, 'K-ASL-M-B', 'Kitchen - Above Sink Left - Medial - Bottom') - , (1, 'K-ASL-M-M', 'Kitchen - Above Sink Left - Medial - Middle') - , (1, 'K-ASL-M-T', 'Kitchen - Above Sink Left - Medial - Top') - , (1, 'K-ASL-L-B', 'Kitchen - Above Sink Left - Lateral - Bottom') - , (1, 'K-ASL-L-M', 'Kitchen - Above Sink Left - Lateral - Middle') - , (1, 'K-ASL-L-T', 'Kitchen - Above Sink Left - Lateral - Top') - , (1, 'K-ASL-XL-B', 'Kitchen - Above Sink Left - Extra Lateral - Bottom') - , (1, 'K-ASL-XL-M', 'Kitchen - Above Sink Left - Extra Lateral - Middle') - , (1, 'K-ASL-XL-T', 'Kitchen - Above Sink Left - Extra Lateral - Top') - , (1, 'K-T-B', 'Kitchen - Tower - Bottom') - , (1, 'K-T-LM', 'Kitchen - Tower - Lower Middle') - , (1, 'K-T-UM', 'Kitchen - Tower - Upper Middle') - , (1, 'K-T-T', 'Kitchen - Tower - Top') - , (1, 'K-FJ-MEAT', 'Kitchen - Fridge - Meat Drawer') - , (1, 'K-FJ-VEG', 'Kitchen - Fridge - Vegetables Drawer') - , (1, 'K-FJ-CHEESE', 'Kitchen - Fridge - Cheese Drawer') - , (1, 'K-FJ-S-B', 'Kitchen - Fridge - Shelf - Bottom') - , (1, 'K-FJ-S-LM', 'Kitchen - Fridge - Shelf - Lower Middle') - , (1, 'K-FJ-S-UM', 'Kitchen - Fridge - Shelf - Upper Middle') - , (1, 'K-FJ-S-T', 'Kitchen - Fridge - Shelf - Top') - , (1, 'K-FJ-DG-B', 'Kitchen - Door Shelf (Guarded) - Bottom') - , (1, 'K-FJ-DG-LM', 'Kitchen - Door Shelf (Guarded) - Lower Middle') - , (1, 'K-FJ-DG-UM', 'Kitchen - Door Shelf (Guarded) - Upper Middle') - , (1, 'K-FJ-DG-T', 'Kitchen - Door Shelf (Guarded) - Top') - , (1, 'K-FJ-DU', 'Kitchen - Door Shelf (Unguarded)') - , (1, 'K-FZ-DRAWER-B', 'Kitchen - Freezer - Drawer - Bottom') - , (1, 'K-FZ-DRAWER-T', 'Kitchen - Freezer - Drawer - Top') - , (1, 'K-FZ-DRAWER-I', 'Kitchen - Freezer - Drawer - Ice') - , (1, 'K-FZ-S-B', 'Kitchen - Freezer - Shelf - Bottom') - , (1, 'K-FZ-S-M', 'Kitchen - Freezer - Shelf - Middle') - , (1, 'K-FZ-S-T', 'Kitchen - Freezer - Shelf - Top') - , (1, 'K-FZ-DOOR-XL', 'Kitchen - Freezer - Door - Extra Low') - , (1, 'K-FZ-DOOR-L', 'Kitchen - Freezer - Door - Lower') - , (1, 'K-FZ-DOOR-LM', 'Kitchen - Freezer - Door - Lower Middle') - , (1, 'K-FZ-DOOR-UM', 'Kitchen - Freezer - Door - Upper Middle') - , (1, 'K-FZ-DOOR-U', 'Kitchen - Freezer - Door - Upper') - , (1, 'K-FZ-DOOR-XU', 'Kitchen - Freezer - Door - Extra Up') - , (1, 'K-AFF', 'Kitchen - Above Fridge-Freezer') - , (1, 'K-CT', 'Kitchen - Counter Top') -; - -/* --- Storage Location Branches -INSERT INTO Shop_Storage_Location_Branch ( - id_location_parent, id_location_child -) -VALUES - (1, 2) -; -*/ - --- Currency -INSERT INTO Shop_Currency ( - display_order, code, name, symbol, factor_from_GBP -) -VALUES - (1, 'GBP', 'Great British Pound', '£', 1), - (2, 'EUR', 'Euro', '€', 1.17) -; - --- Taxes and Surcharges -INSERT INTO Shop_Tax_Or_Surcharge ( - display_order, - id_tax, - code, - name, - id_region_buyer, - id_region_seller, - fixed_fee, - multiplier, - apply_fixed_fee_before_multiplier, - quantity_min, - quantity_max -) -VALUES - (1, 1, 'VAT', 'Value Added Tax', 1, 1, 0, 0.2, 1, 0, 1) -; - --- Unit of Measurement -INSERT INTO Shop_Unit_Measurement ( - name_singular, name_plural, symbol, is_base_unit, is_unit_of_distance, is_unit_of_mass, is_unit_of_time, is_unit_of_volume -) -VALUES - ('metre', 'metres', 'm', 1, 1, 0, 0, 0) - , ('millimetre', 'millimetres', 'mm', 0, 1, 0, 0, 0) - , ('kilogram', 'kilograms', 'kg', 1, 0, 1, 0, 0) - , ('gram', 'grams', 'g', 0, 0, 1, 0, 0) - , ('litre', 'litres', 'L', 0, 0, 0, 0, 1) - , ('millilitre', 'millilitres', 'mL', 0, 0, 0, 0, 1) - , ('item', 'items', 'x', 0, 0, 0, 0, 0) - , ('hour', 'hours', 'h', 1, 0, 0, 1, 0) - , ('day', 'days', 'd', 0, 0, 0, 1, 0) -; - --- Unit of Measurement Conversion -INSERT INTO Shop_Unit_Measurement_Conversion ( - id_unit_derived - , id_unit_base - , display_order - , multiplier_unit_base - , increment_unit_base - , apply_multiplier_before_increment +INSERT INTO partsltd_prod.CORE_Msg_Error_Type ( + code + , name + , description ) VALUES ( - 2 -- id_unit_derived - , 1 -- id_unit_base - , 1 -- display_order - , 0.001 -- multiplier_unit_base - , 0 -- increment_unit_base - , apply_multiplier_before_increment - ) + 'BAD_DATA' + , 'Invalid data' + , 'Rubbish data' + ) , ( - 4 -- id_unit_derived - , 3 -- id_unit_base - , 1 -- display_order - , 0.001 -- multiplier_unit_base - , 0 -- increment_unit_base - , apply_multiplier_before_increment - ) + 'NO_PERMISSION' + , 'No permission' + , 'Not authorised' + ) + , ( + 'MYSQL_ERROR' + , 'MySQL error' + , 'MySQL execution error.' + ) + , ( + 'WARNING' + , 'Warning' + , 'Non-breaking error.' + ) +; + +-- Access Levels +INSERT INTO partsltd_prod.PH_Access_Level ( + display_order + , code + , name + , priority +) +VALUES + ( + 1 + , 'VIEW' + , 'View' + , 3 + ) , ( - 6 -- id_unit_derived - , 5 -- id_unit_base - , 1 -- display_order - , 0.001 -- multiplier_unit_base - , 0 -- increment_unit_base - , apply_multiplier_before_increment - ) + 2 + , 'EDIT' + , 'Edit' + , 2 + ) , ( - 9 -- id_unit_derived - , 8 -- id_unit_base - , 1 -- display_order - , 24 -- multiplier_unit_base - , 0 -- increment_unit_base - , apply_multiplier_before_increment - ) + 3 + , 'ADMIN' + , 'Admin' + , 1 + ) ; - --- Categories -INSERT INTO Shop_Product_Category ( - display_order, - code, - name, - description, - id_access_level_required, - created_by -) -VALUES - (1, 'ASS', 'Assistive Devices', 'Braille product line and other assistive devices', 1, 1), - (99, 'MISC', 'Miscellaneous', 'Not category allocated products', 1, 1), - (2, 'TECH', 'Technology', 'Technological devices', 1, 1) -; - -/* --- Recurrence Interval -INSERT INTO Shop_Interval_Recurrence ( - code, name, name_plural -) -VALUES - ('WEEK', 'Week', 'Weeks'), - ('MONTH', 'Month', 'Months'), - ('YEAR', 'Year', 'Years') -; -*/ - --- Products -INSERT INTO Shop_Product ( - display_order, - id_category, - name, - has_variations, - id_access_level_required, - created_by -) -VALUES - ( - 1, - 1, - 'Braille Keyboard Translator', - 1, - 3, - 1 - ), - ( - 2, - 2, - 'Test product 1', - 0, - 3, - 1 - ), - ( - 3, - 3, - 'Phone', - 0, - 1, - 1 - ), - ( - 4, - 3, - 'Laptop', - 0, - 1, - 1 - ), - ( - 5, - 3, - 'Smart Watch', - 0, - 1, - 1 - ) -; - --- Product Permutations -INSERT INTO Shop_Product_Permutation ( - -- display_order, - id_permutation_temp, - id_product, - description, - cost_local_VAT_excl, - cost_local_VAT_incl, - id_currency_cost, - profit_local_min, - -- id_currency_profit_min, - latency_manufacture, - id_unit_measurement_quantity, - count_unit_measurement_per_quantity_step, - quantity_min, - quantity_max, - quantity_stock, - is_subscription, - id_unit_measurement_interval_recurrence, - count_interval_recurrence, - -- id_access_level_required, - id_stripe_product - , does_expire_faster_once_unsealed - , id_unit_measurement_interval_expiration_unsealed - , count_interval_expiration_unsealed -) -VALUES - ( - -- 1, - -1, - 1, - 'Good Red', - 5, - 6, - 1, - 3, - -- 1, - 14, - 1, - 1, - 3, - 99, - 1, - 0, - NULL, - NULL, - -- 1, - NULL - , 0 - , NULL - , NULL - ), - ( - -- 2, - -2, - 1, - 'Good Blue', - 6, - 7.2, - 1, - 4, - -- 1, - 14, - 1, - 1, - 3, - 99, - 1, - 0, - NULL, - NULL, - -- 1, - NULL - , 0 - , NULL - , NULL - ), - ( - -- 3, - -3, - 2, - 'Test product describes good', - 10, - 12, - 1, - 5, - -- 1, - 14, - 1, - 1, - 2, - 99, - 1, - 0, - NULL, - NULL, - -- 1, - NULL - , 0 - , NULL - , NULL - ), - ( - -- 4, - -4, - 3, - 'Phone describes good', - 10, - 12, - 1, - 5, - -- 1, - 14, - 1, - 1, - 2, - 99, - 1, - 0, - NULL, - NULL, - -- 1, - NULL - , 0 - , NULL - , NULL - ), - ( - -- 5, - -5, - 4, - 'Laptop describes good', - 10, - 12, - 1, - 5, - -- 1, - 14, - 1, - 1, - 2, - 99, - 1, - 0, - NULL, - NULL, - -- 1, - NULL - , 0 - , NULL - , NULL - ), - ( - -- 6, - -6, - 5, - 'Smart watch describes good', - 10, - 12, - 1, - 5, - -- 1, - 14, - 1, - 1, - 2, - 99, - 1, - 0, - NULL, - NULL, - -- 1, - NULL - , 0 - , NULL - , NULL - ) -; - --- Variation Types -INSERT INTO Shop_Variation_Type ( - display_order, code, name, name_plural -) -VALUES - (1, 'COLOUR', 'Colour', 'Colours') - , (2, 'SIZE', 'Size', 'Sizes') -; - --- Variations -INSERT INTO Shop_Variation ( - display_order, id_type, code, name, id_unit_measurement, count_unit_measurement -) -VALUES - (1, 1, 'RED', 'Red', NULL, NULL) - , (2, 1, 'BLUE', 'Blue', NULL, NULL) - , (3, 1, 'GREEN', 'Green', NULL, NULL) - , (4, 1, 'White', 'White', NULL, NULL) - , (5, 1, 'BLACK', 'Black', NULL, NULL) - , (1, 2, '400ml', '400 millilitres', 6, 400) - , (2, 2, '400g', '400 grams', 4, 400) - , (3, 2, '410g', '410 grams', 4, 410) - , (4, 2, '8g', '8 grams', 4, 8) - , (5, 2, '13g', '13 grams', 4, 13) - , (6, 2, '27g', '27 grams', 4, 27) - , (7, 2, '104g', '104 grams', 4, 104) - , (8, 2, '200g', '200 grams', 4, 200) - , (9, 2, '92g', '92 grams', 4, 92) - , (10, 2, '100g', '100 grams', 4, 100) - , (11, 2, '500g', '500 grams', 4, 500) - , (12, 2, '250g', '250 grams', 4, 250) - , (13, 2, '750g', '750 grams', 4, 750) - , (14, 2, '145g', '145 grams', 4, 145) - , (15, 2, '340g', '340 grams', 4, 340) - , (16, 2, '132g', '132 grams', 4, 132) - , (17, 2, '170g', '170 grams', 4, 170) - , (18, 2, '700g', '700 grams', 4, 700) - , (19, 2, '150g', '150 grams', 4, 150) - , (20, 2, '1kg', '1 kilogram', 3, 1) - , (21, 2, '2kg', '2 kilograms', 3, 2) - , (22, 2, '800ml', '800 millilitres', 6, 800) - , (23, 2, '570g', '570 grams', 4, 570) - , (24, 2, '300g', '300 grams', 4, 300) - , (25, 2, '350g', '350 grams', 4, 350) - , (26, 2, '30g', '30 grams', 4, 30) - , (27, 2, '1L', '1 litre', 5, 1) - , (28, 2, '1.2L', '1.2 litres', 5, 1.2) - , (29, 2, '1.8L', '1.8 litres', 5, 1.8) - , (30, 2, 'bag of 20', 'bag of 20', 7, 20) - , (31, 2, '180ml', '180 millilitres', 6, 180) - , (32, 2, '70g', '70 grams', 4, 70) - , (33, 2, '60ml', '60 millilitres', 6, 60) - , (34, 2, '325g', '325 grams', 4, 325) - , (35, 2, 'pack of 50', 'pack of 50', 7, 50) - , (36, 2, 'box of 24 (each 5.9g)', 'box of 24 (each 5.9 grams)', 7, 24) - , (37, 2, '397g', '397 grams', 4, 397) - , (38, 2, '720g', '720 grams', 4, 720) - , (39, 2, '454g', '454 grams', 4, 454) - , (40, 2, 'pack of 4 (each 37g)', 'pack of 4 (each 37 grams)', 7, 4) - , (41, 2, '450g', '450 grams', 4, 450) - , (42, 2, '24.6.g', '24.6 grams', 4, 24.6) - , (43, 2, '230g', '230 grams', 4, 230) - , (44, 2, '37.3g', '37.3 grams', 4, 37.3) - , (45, 2, '38.3g', '38.3 grams', 4, 38.3) - , (46, 2, '123g', '123 grams', 4, 123) - , (47, 2, '266g', '266 grams', 4, 266) - , (48, 2, '157g', '157 grams', 4, 157) - , (49, 2, '285g', '285 grams', 4, 285) - , (50, 2, '700ml', '700 millilitres', 6, 700) - , (51, 2, '5L', '5 litres', 5, 5) - , (52, 2, '216g', '216 grams', 4, 216) - , (53, 2, '320g', '320 grams', 4, 320) - , (54, 2, '2L', '2 litres', 5, 2) - , (55, 2, '200ml', '200 millilitres', 6, 200) - , (56, 2, '250ml', '250 millilitres', 6, 250) - , (57, 2, '1 punnet', '1 punnet', 7, 1) - , (58, 2, '420g', '420 grams', 4, 420) - , (59, 2, '230g', '230 grams', 4, 230) - , (60, 2, '465g', '465 grams', 4, 465) - , (61, 2, '500ml', '500 millilitres', 6, 500) - , (62, 2, '250ml', '250 millilitres', 6, 250) - , (63, 2, '238ml', '238 millilitres', 6, 238) - , (64, 2, '140ml', '140 millilitres', 6, 140) - , (65, 2, '195g', '195 grams', 4, 195) - , (66, 2, '1pt', '1 pint', 5, 1) - , (67, 2, '570ml', '570 millilitres', 6, 570) - , (68, 2, '360g', '360 grams', 4, 360) - , (69, 2, '90g', '90 grams', 4, 90) - , (70, 2, '800ml', '800 millilitres', 6, 800) - , (71, 2, '197g', '197 grams', 4, 197) -; - -INSERT INTO partsltd_prod.Shop_Product_Change_Set ( - comment -) -VALUES ( 'Update Variation Display Orders' ) -; -UPDATE partsltd_prod.Shop_Variation V -INNER JOIN ( - SELECT - V.id_variation, - RANK() OVER (ORDER BY - CONCAT( - CASE WHEN V.count_unit_measurement = FLOOR(V.count_unit_measurement) THEN - LPAD(CAST(V.count_unit_measurement AS CHAR), 25, '0') - ELSE - CONCAT( - LPAD( - CAST(FLOOR(V.count_unit_measurement) AS CHAR) - , 25 - , '0' - ) - , SUBSTRING( - CAST(V.count_unit_measurement AS CHAR) - FROM LOCATE('.', CAST(V.count_unit_measurement AS CHAR)) - ) - ) - END - , ' ' - , IFNULL(IFNULL(UM.symbol, UM.name_singular), '(No Unit of Measurement)') - ) - ) as new_order - FROM partsltd_prod.Shop_Variation V - INNER JOIN partsltd_prod.Shop_Unit_Measurement UM - ON V.id_unit_measurement = UM.id_unit_measurement - AND UM.active = 1 - WHERE - V.id_type = 2 -) AS RANKED ON V.id_variation = RANKED.id_variation -JOIN ( - SELECT CS.id_change_set - FROM partsltd_prod.Shop_Product_Change_Set CS - ORDER BY CS.id_change_set DESC - LIMIT 1 -) AS CS -SET - V.display_order = RANKED.new_order - , V.id_change_set = CS.id_change_set -WHERE - V.id_type = 2 -; - --- Product Permutation Variation Links -INSERT INTO Shop_Product_Permutation_Variation_Link ( - display_order, id_permutation, id_variation -) -VALUES - (1, 1, 1), - (2, 2, 2) -; - --- Stock items -INSERT INTO Shop_Stock_Item ( - id_permutation - , date_purchased - , id_location_storage - , id_currency_cost - , cost_local_VAT_incl - , cost_local_VAT_excl - , date_expiration -) -VALUES - (1, NOW(), 1, 1, 5, 4.2, '2025-09-05 00:00:00'), - (2, NOW(), 1, 1, 6, 5, '2026-09-05 00:00:00'), - (3, NOW(), 1, 1, 10, 8.4, '2027-09-05 00:00:00'), - (4, NOW(), 1, 1, 10, 8.4, '2028-09-05 00:00:00'), - (5, NOW(), 1, 1, 10, 8.4, '2029-09-05 00:00:00'), - (6, NOW(), 1, 1, 10, 8.4, '2030-09-05 00:00:00') -; - --- Product Price -INSERT INTO Shop_Product_Price ( - id_permutation - , id_currency - , id_region_purchase - , price_local_VAT_incl - , price_local_VAT_excl -) -VALUES - (1, 1, 1, 24, 20), - (1, 2, 1, 48, 40), - (2, 1, 1, 96, 80), - (3, 1, 1, 144, 120), - (4, 1, 1, 600, 500), - (5, 1, 1, 1500, 1200), - (6, 1, 1, 180, 150) -; - --- Product Images -INSERT INTO Shop_Product_Image ( - display_order, - id_permutation, - id_type_image, - url -) -VALUES - (1, 1, 1, '/static/images/prod_PB0NUOSEs06ymG.jpg'), - -- (1, 1, 1, '/static/images/prod_PB0NUOSEs06ymG.jpg'), - (2, 2, 1, '/static/images/prod_PB0NUOSEs06ymG.jpg'), - -- (1, 2, 1, '/static/images/prod_PB0NUOSEs06ymG.jpg') - (3, 3, 1, '/static/images/prod_PB0NUOSEs06ymG.jpg'), - (4, 4, 1, '/static/images/prod_.jpg'), - (5, 5, 1, '/static/images/prod_1.jpg'), - (6, 6, 1, '/static/images/prod_2.jpg') -; - --- Delivery Options -INSERT INTO Shop_Delivery_Option ( - display_order, code, name, latency_delivery_min, latency_delivery_max -) -VALUES - (1, 'COLLECT', 'Collection', 0, 0), - (2, 'SIGNED_1', 'First Class Signed-For', 2, 4) -; - --- Product Delivery Option Links -INSERT INTO Shop_Product_Permutation_Delivery_Option_Link ( - display_order, id_product, id_permutation, id_delivery_option, id_region, id_currency, price_local, quantity_min, quantity_max -) -VALUES - (1, 1, 1, 1, 1, 1, 5, 0, 1), - (2, 1, 2, 1, 1, 1, 9, 0, 1), - (3, 2, 3, 1, 1, 1, 10, 0, 1), - (4, 3, 4, 1, 1, 1, 10, 0, 1), - (5, 4, 5, 1, 1, 1, 10, 0, 1), - (6, 5, 6, 1, 1, 1, 10, 0, 1) -; - --- Discounts -INSERT INTO Shop_Discount ( - id_product, - id_permutation, - code, - name, - multiplier, - quantity_min, - quantity_max, - date_start, - date_end, - display_order -) -VALUES - (1, 1, 'CRIMBO50', 'Christmas 50% off sale!', 0.5, 3, 9, NOW(), '2023-12-31 23:59:59', 1), - (1, 2, 'CRIMBO50', 'Christmas 50% off sale!', 0.5, 3, 9, NOW(), '2023-12-31 23:59:59', 1) -; - --- Discount Delivery Region Currency Links -INSERT INTO Shop_Discount_Region_Currency_Link ( - id_discount, - id_region, - id_currency -) -VALUES - (1, 1, 1), - (2, 1, 1), - (1, 1, 2), - (2, 1, 2) -; - - -- Permission Groups -INSERT INTO Shop_Permission_Group ( - display_order, code, name +INSERT INTO partsltd_prod.PH_Permission_Group ( + display_order + , code + , name ) VALUES - (0, 'ADMIN', 'Website Admin'), - (1, 'HOME', 'Home, Contact Us, and other public information'), - (2, 'PRODUCT', 'Store Products'), - (3, 'USER', 'Store User'), - (4, 'SALES_AND_PURCHASING', 'Sales and Purchasing'), - (5, 'MANUFACTURING', 'Manufacturing') + ( + 0 + , 'CONTACT_FORM' + , 'Contact Form' + ) + , ( + 1 + , 'USER' + , 'Admin User' + ) ; -/* -select * from Shop_Permission -select * from Shop_Role_Permission_Link -*/ + -- Permissions -INSERT INTO Shop_Permission ( - display_order, code, name, id_permission_group, id_access_level_required +INSERT INTO partsltd_prod.PH_Permission ( + display_order + , code + , name + , id_permission_group + , id_access_level_required ) VALUES - (1, 'HOME', 'Home Page', 2, 1), - (2, 'STORE_PRODUCT', 'Store Product Page', 3, 1), - (3, 'STORE_USER', 'Store User Account Page', 4, 2), - (10, 'STORE_USER_ADMIN', 'Store User Admin Page', 4, 3), - (4, 'STORE_ADMIN', 'Store Admin Page', 1, 3), - (5, 'STORE_SUPPLIER', 'Store Supplier Page', 4, 2), - (6, 'STORE_SUPPLIER_PURCHASE_ORDER', 'Store Supplier Purchase Order Page', 4, 2), - (7, 'STORE_MANUFACTURING_PURCHASE_ORDER', 'Store Manufacturing Purchase Order Page', 5, 2), - (8, 'STORE_CUSTOMER', 'Store Customer Page', 4, 2), - (9, 'STORE_CUSTOMER_SALES_ORDER', 'Store Customer Sales Order Page', 4, 2), - (99, 'CONTACT_US', 'Contact Us Page', 2, 1) -; - --- Roles -INSERT INTO Shop_Role ( - display_order, - code, - name -) -VALUES - (1, 'DIRECTOR', 'Director'), - (2, 'USER', 'User') -; - --- Role Permission link -INSERT INTO Shop_Role_Permission_Link ( - id_role, id_permission, id_access_level -) -VALUES - (1, 1, 3), - (1, 2, 3), - (1, 3, 3), - (1, 4, 3), - (1, 5, 3), - (1, 6, 3), - (1, 7, 3), - (1, 8, 3), - (1, 9, 3), - (1, 10, 3), - (1, 11, 3), - (2, 1, 1), - (2, 2, 1), - (2, 3, 1), - (2, 4, 1), - (2, 5, 1) + ( + 1 + , 'CONTACT_FORM_NEW' + , 'New Contact Form' + , 1 + , 3 + ) + , ( + 1 + , 'CONTACT_FORM_ADMIN' + , 'Admin Contact Form' + , 1 + , 3 + ) + , ( + 1 + , 'CONTACT_FORM_CREATE' + , 'Create Contact Form' + , 1 + , 1 + ) ; -- Users -INSERT INTO Shop_User ( - id_user_auth0 +INSERT INTO partsltd_prod.PH_User ( + id_user_auth0 , firstname , surname , email @@ -878,22 +121,14 @@ INSERT INTO Shop_User ( ) VALUES ( - 'auth0|6582b95c895d09a70ba10fef' -- id_user_auth0 + 'auth0|6582b95c895d09a70ba10fef' -- id_user_auth0 , 'Teddy' -- firstname , 'Middleton-Smith' -- surname , 'edward.middletonsmith@gmail.com' -- email , 1 -- is_super_user , 1 -- active - ), - ( - 'parts_guest' -- id_user_auth0 - , 'Guest' -- firstname - , '' -- surname - , '' -- email - , 0 -- is_super_user - , 1 -- active - ), - ( + ) + , ( 'auth0|672659014296b7f94a9bab45' -- id_user_auth0 , 'Tierney' -- firstname , 'Gullen' -- surname @@ -901,237 +136,122 @@ VALUES , 1 -- is_super_user , 1 -- active ) + , ( + NULL -- id_user_auth0 + , 'Contact Form Bot' -- firstname + , 'Bot' -- surname + , 'teddy@partsltd.co.uk' -- email + , 0 -- is_super_user + , 1 -- active + ) +; + +-- Roles +INSERT INTO partsltd_prod.PH_Role ( + display_order + , code + , name + , id_user_created_by +) +VALUES + ( + 1 + , 'DIRECTOR' + , 'Director' + , 1 + ) + , ( + 2 + , 'USER' + , 'User' + , 1 + ) +; + +-- Role Permission link +INSERT INTO partsltd_prod.PH_Role_Permission_Link ( + id_role + , id_permission + , id_access_level + , id_user_created_by +) +VALUES + ( + 1 + , 1 + , 3 + , 1 + ) + , ( + 1 + , 2 + , 3 + , 1 + ) + , ( + 1 + , 3 + , 3 + , 1 + ) + , ( + 2 + , 1 + , 1 + , 1 + ) + , ( + 2 + , 2 + , 1 + , 1 + ) + , ( + 2 + , 3 + , 1 + , 1 + ) ; -- User Role link -INSERT INTO Shop_User_Role_Link ( - id_user, id_role +INSERT INTO partsltd_prod.PH_User_Role_Link ( + id_user + , id_role + , id_user_created_by ) VALUES - (1, 1) -; - --- User Addresses -INSERT INTO Shop_User_Address ( - id_user, id_region, name_full, phone_number, postcode, address_line_1, address_line_2, city, county -) -SELECT U.id_user, 1, CONCAT(U.firstname, ' ', U.surname), '07375 571430', 'CV22 6DN', '53 Alfred Green Close', '', 'Rugby', 'Warwickshire' - FROM Shop_User U -; - --- User Basket -INSERT INTO Shop_User_Basket ( - id_user, - id_product, - id_permutation, - quantity -) -VALUES - (1, 1, 1, 69) -; - --- User Order Status -INSERT INTO Shop_User_Order_Status ( - display_order, code, name, name_plural -) -VALUES - (1, 'SUCCESS', 'Success', 'Successes'), - (2, 'FAIL', 'Failure', 'Failures') -; - -/* --- User Order -INSERT INTO Shop_User_Order ( - id_user, value_total, id_order_status, id_checkout_session, id_currency -) -VALUES - (1, 25, 1, 'noods', 1), - (1, 25, 1, 'noods', 1) -; - --- User Order Product Link -INSERT INTO Shop_User_Order_Product_Link ( - id_order, id_product, id_permutation, quantity -) -VALUES - (1, 1, 1, 69), - (1, 2, NULL, 69), - (1, 1, 2, 69) -; -*/ - --- Supplier -INSERT INTO Shop_Supplier ( - id_supplier_temp - , name_company - , name_contact - , department_contact - -- , id_address - , phone_number - , fax - , email - , website - , id_currency -) -VALUES ( - -1 - , 'Precision And Research Technology Systems Limited' - , 'Teddy Middleton-Smith' - , 'Executive Management' - -- , 1 - , '07375571430' - , '' - , 'teddy@partsltd.co.uk' - , 'www.partsltd.co.uk' + 1 , 1 - ) -; - --- Suppliers -INSERT INTO Shop_Supplier ( - id_supplier_temp - , name_company - , name_contact - , department_contact - -- , id_address - , phone_number - , fax - , email - , website - , id_currency -) -VALUES - ( - -2 - , 'Malt Kiln Farm Shop' - , NULL - , NULL - -- , 1 - , '01788 832640' - , NULL - , 'farmshop@maltkilnfarmshop.co.uk' - , 'https://www.maltkilnfarmshop.co.uk/' , 1 - ) + ) , ( - -3 - , 'Asda' - , NULL - , NULL - -- , 1 - , '' - , NULL - , '' - , '' + 2 + , 2 , 1 - ) + ) + , ( + 3 + , 2 + , 1 + ) ; --- Supplier Addresses -INSERT INTO Shop_Supplier_Address ( - id_supplier - , id_region - , postcode - , address_line_1 - , address_line_2 - , city - , county - , active + +INSERT INTO partsltd_prod.PH_Contact_Form ( + email + , name_contact + , name_company + , message + , id_user_created_by ) VALUES - ( - 1 - , 1 - , 'CV22 6DN' - , '53 Alfred Green Close' - , '' - , 'Rugby' - , 'Warwickshire' - , 1 - ), - ( - 2 + ( + 'edward.middleton-smith@gmail.com' + , 'Teddy Middleton-Smith' + , 'PARTS Ltd' + , 'Hello, I would like to enquire about your services.' , 1 - , 'CV22 6DN' - , '53 Alfred Green Close' - , '' - , 'Rugby' - , 'Warwickshire' - , 1 - ) -; - -/* --- Supplier Purchase Order -INSERT INTO Shop_Supplier_Purchase_Order ( - id_supplier, value_total, id_order_status, id_checkout_session, id_currency -) -VALUES -; - --- Supplier Purchase Order Product Link -INSERT INTO Shop_Supplier_Purchase_Order_Product_Link ( - id_order, id_permutation, cost_total_local, id_currency_cost, quantity_ordered, id_unit_quantity, quantity_received, latency_delivery, display_order -) -VALUES -; -*/ - -/* --- Manufacturing Purchase Order -INSERT INTO Shop_Manufacturing_Purchase_Order ( - cost_total_local, id_currency_cost -) -VALUES -; - --- Manufacturing Purchase Order Product Link -INSERT INTO Shop_Manufacturing_Purchase_Order_Product_Link ( - id_order, id_permutation, cost_total_local, id_currency_cost, quantity_used, id_unit_quantity, quantity_produced, latency_manufacturing_days, display_order -) -VALUES -; -*/ - -/* --- Customer -INSERT INTO Shop_Customer ( - name_company, name_contact, department_contact, id_address, phone_number, email, id_currency -) -VALUES - -; -*/ - -/* --- Customer Sales Order -INSERT INTO Shop_Customer_Sales_Order ( - cost_total_local, id_currency_cost -) -VALUES -; - --- Customer Sales Order Product Link -INSERT INTO Shop_Customer_Sales_Order_Product_Link ( - id_order, id_permutation, cost_total_local, id_currency_cost, quantity_ordered, id_unit_quantity, quantity_delivered, latency_delivery_days, display_order -) -VALUES -; -*/ - - - - -/* - -- Clean up -END // -DELIMITER ; - - --- Call -CALL p_populate_database(); - --- Remove proc -DROP PROCEDURE IF EXISTS p_populate_database; -*/ \ No newline at end of file + ) +; \ No newline at end of file diff --git a/static/MySQL/9001_view.sql b/static/MySQL/9001_view.sql index a66613d1..1fbf3a86 100644 --- a/static/MySQL/9001_view.sql +++ b/static/MySQL/9001_view.sql @@ -1,207 +1,40 @@ - --- Product Change Sets -SELECT * FROM Shop_Product_Change_Set; - --- User Change Sets -SELECT * FROM Shop_User_Change_Set; - --- User Change Sets -SELECT * FROM Shop_Sales_And_Purchasing_Change_Set; - --- Access Levels -SELECT * FROM Shop_Access_Level; -SELECT * FROM Shop_Access_Level_Audit; - -- Error Message type -SELECT * FROM Shop_Msg_Error_Type; +SELECT * FROM partsltd_prod.CORE_Msg_Error_Type; --- File Types -SELECT * FROM File_Type; -SELECT * FROM File_Type_Audit; - --- Generic / shared properties -SELECT * FROM Shop_General; -SELECT * FROM Shop_General_Audit; - --- Image Types -SELECT * FROM Shop_Image_Type; -SELECT * FROM Shop_Image_Type_Audit; - - --- Regions -SELECT * FROM Shop_Region; -SELECT * FROM Shop_Region_Audit; - --- Region branches -SELECT * FROM Shop_Region_Branch; -SELECT * FROM Shop_Region_Branch_Audit; - --- Plants -SELECT * FROM Shop_Plant; -SELECT * FROM Shop_Plant_Audit; - --- Storage Locations -SELECT * FROM Shop_Storage_Location; -SELECT * FROM Shop_Storage_Location_Audit; - --- Storage Location branches -SELECT * FROM Shop_Storage_Location_Branch; -SELECT * FROM Shop_Storage_Location_Branch_Audit; - --- Currencies -SELECT * FROM Shop_Currency; -SELECT * FROM Shop_Currency_Audit; - --- Taxes and Surcharges -SELECT * FROM Shop_Tax_Or_Surcharge; -SELECT * FROM Shop_Tax_Or_Surcharge_Audit; - --- Unit of Measurement -SELECT * FROM Shop_Unit_Measurement; -SELECT * FROM Shop_Unit_Measurement_Audit; - --- Unit of Measurement Conversion -SELECT * FROM Shop_Unit_Measurement_Conversion; -SELECT * FROM Shop_Unit_Measurement_Conversion_Audit; - -/* --- Recurrence Interval -SELECT * FROM Shop_Interval_Recurrence; -SELECT * FROM Shop_Interval_Recurrence_Audit; -*/ - - --- Categories -SELECT * FROM Shop_Product_Category; -SELECT * FROM Shop_Product_Category_Audit; - --- Products -SELECT * FROM Shop_Product; -SELECT * FROM Shop_Product_Audit; - --- Permutations -SELECT * FROM Shop_Product_Permutation; -SELECT * FROM Shop_Product_Permutation_Audit; - --- Variation Types -SELECT * FROM Shop_Variation_Type; -SELECT * FROM Shop_Variation_Type_Audit; - --- Variations -SELECT * FROM Shop_Variation; -SELECT * FROM Shop_Variation_Audit; - --- Permutation Variation Links -SELECT * FROM Shop_Product_Permutation_Variation_Link; -SELECT * FROM Shop_Product_Permutation_Variation_Link_Audit; - --- Stock Items -SELECT * FROM Shop_Stock_Item; -SELECT * FROM Shop_Stock_Item_Audit; - --- Product Currency Links -SELECT * FROM Shop_Product_Price; -SELECT * FROM Shop_Product_Price; - --- Images -SELECT * FROM Shop_Product_Image; -SELECT * FROM Shop_Product_Image_Audit; - --- Delivery Option Types -SELECT * FROM Shop_Delivery_Option; -SELECT * FROM Shop_Delivery_Option_Audit; - --- Delivery Options -SELECT * FROM Shop_Product_Permutation_Delivery_Option_Link; -SELECT * FROM Shop_Product_Permutation_Delivery_Option_Link_Audit; - --- Discounts -SELECT * FROM Shop_Discount; -SELECT * FROM Shop_Discount_Audit; - --- Discount Delivery Region Links -SELECT * FROM Shop_Discount_Region_Currency_Link; -SELECT * FROM Shop_Discount_Region_Currency_Link_Audit; +-- User Change Sets +SELECT * FROM partsltd_prod.PH_User_Change_Set; +-- Access Levels +SELECT * FROM partsltd_prod.PH_Access_Level; -- Permission Groups -SELECT * FROM Shop_Permission_Group; -SELECT * FROM Shop_Permission_Group_Audit; +SELECT * FROM partsltd_prod.PH_Permission_Group; -- Permissions -SELECT * FROM Shop_Permission; -SELECT * FROM Shop_Permission_Audit; - --- Roles -SELECT * FROM Shop_Role; -SELECT * FROM Shop_Role_Audit; - --- Role Permission link -SELECT * FROM Shop_Role_Permission_Link; -SELECT * FROM Shop_Role_Permission_Link_Audit; +SELECT * FROM partsltd_prod.PH_Permission; -- Users -SELECT * FROM Shop_User; -SELECT * FROM Shop_User_Audit; +SELECT * FROM partsltd_prod.PH_User; +SELECT * FROM partsltd_prod.PH_User_Audit; + +-- Roles +SELECT * FROM partsltd_prod.PH_Role; +SELECT * FROM partsltd_prod.PH_Role_Audit; + +-- Role Permission link +SELECT * FROM partsltd_prod.PH_Role_Permission_Link; +SELECT * FROM partsltd_prod.PH_Role_Permission_Link_Audit; -- User Role link -SELECT * FROM Shop_User_Role_Link; -SELECT * FROM Shop_User_Role_Link_Audit; +SELECT * FROM partsltd_prod.PH_User_Role_Link; +SELECT * FROM partsltd_prod.PH_User_Role_Link_Audit; --- Addresses -SELECT * FROM Shop_Address; -SELECT * FROM Shop_Address_Audit; - --- Basket -SELECT * FROM Shop_User_Basket; -SELECT * FROM Shop_User_Basket_Audit; - - --- Order Statuses -SELECT * FROM Shop_User_Order_Status; -SELECT * FROM Shop_User_Order_Status_Audit; - -/* --- Orders -SELECT * FROM Shop_User_Order; -SELECT * FROM Shop_User_Order_Audit; - --- Order Products -SELECT * FROM Shop_User_Order_Product_Link; -SELECT * FROM Shop_User_Order_Product_Link_Audit; -*/ - --- Supplier -SELECT * FROM Shop_Supplier; -SELECT * FROM Shop_Supplier_Audit; - --- Supplier Purchase Order -SELECT * FROM Shop_Supplier_Purchase_Order; -SELECT * FROM Shop_Supplier_Purchase_Order_Audit; - --- Supplier Purchase Order Product Link -SELECT * FROM Shop_Supplier_Purchase_Order_Product_Link; -SELECT * FROM Shop_Supplier_Purchase_Order_Product_Link_Audit; - --- Manufacturing Purchase Order -SELECT * FROM Shop_Manufacturing_Purchase_Order; -SELECT * FROM Shop_Manufacturing_Purchase_Order_Audit; - --- Manufacturing Purchase Order Product Link -SELECT * FROM Shop_Manufacturing_Purchase_Order_Product_Link; -SELECT * FROM Shop_Manufacturing_Purchase_Order_Product_Link_Audit; - --- Customers -SELECT * FROM Shop_Customer; -SELECT * FROM Shop_Customer_Audit; - --- Customer Sales Order -SELECT * FROM Shop_Customer_Sales_Order; -SELECT * FROM Shop_Customer_Sales_Order_Audit; - --- Customer Sales Order Product Link -SELECT * FROM Shop_Customer_Sales_Order_Product_Link; -SELECT * FROM Shop_Customer_Sales_Order_Product_Link_Audit; +-- Contact Form Change Sets +SELECT * FROM partsltd_prod.PH_Contact_Form_Change_Set; +-- Contact Forms +SELECT * FROM partsltd_prod.PH_Contact_Form; +SELECT * FROM partsltd_prod.PH_Contact_Form_Audit; +SELECT * FROM partsltd_prod.PH_Contact_Form_Temp; \ No newline at end of file diff --git a/static/MySQL/9010_anal.sql b/static/MySQL/9010_anal.sql deleted file mode 100644 index 65229fa0..00000000 --- a/static/MySQL/9010_anal.sql +++ /dev/null @@ -1,30 +0,0 @@ - - -/* - -SELECT TABLE_NAME -FROM INFORMATION_SCHEMA.TABLES -WHERE TABLE_NAME LIKE '%SHOP%' - OR TABLE_NAME LIKE '%FILE_TYPE%'; - - -SELECT FOUND_ROWS(); - - - -SELECT - CONSTRAINT_NAME, - CONSTRAINT_TYPE, - TABLE_NAME, - COLUMN_NAME, - REFERENCED_TABLE_NAME, - REFERENCED_COLUMN_NAME -FROM - INFORMATION_SCHEMA.TABLES -WHERE - TABLE_SCHEMA = 'PARTS' - -- AND TABLE_NAME = 'your_table_name' -; - -*/ - diff --git a/static/MySQL/deprecated/000_init_tables_authentication.sql b/static/MySQL/deprecated/000_init_tables_authentication.sql deleted file mode 100644 index 632e0fe1..00000000 --- a/static/MySQL/deprecated/000_init_tables_authentication.sql +++ /dev/null @@ -1,824 +0,0 @@ -/* Store */ - - --- Drop dependencies --- DROP PROCEDURE IF EXISTS p_shop_user_eval; -DROP TABLE IF EXISTS User_Eval_Temp; - --- Delete old tables -DROP TABLE IF EXISTS Shop_Address_Audit; -DROP TABLE IF EXISTS Shop_Address; - -DROP TABLE IF EXISTS Shop_User_Role_Link_Audit; -DROP TABLE IF EXISTS Shop_User_Role_Link; - -DROP TABLE IF EXISTS Shop_User_Audit; -DROP TABLE IF EXISTS Shop_User; - -DROP TABLE IF EXISTS Shop_Role_Permission_Link_Audit; -DROP TABLE IF EXISTS Shop_Role_Permission_Link; - -DROP TABLE IF EXISTS Shop_Role_Audit; -DROP TABLE IF EXISTS Shop_Role; - -DROP TABLE IF EXISTS Shop_Permission_Audit; -DROP TABLE IF EXISTS Shop_Permission; - -DROP TABLE IF EXISTS Shop_Permission_Group_Audit; -DROP TABLE IF EXISTS Shop_Permission_Group; - -DROP TABLE IF EXISTS Shop_Access_Level_Audit; -DROP TABLE IF EXISTS Shop_Access_Level; - -DROP TABLE IF EXISTS Shop_User_Change_Set; - - - --- User Change Sets -CREATE TABLE Shop_User_Change_Set ( - id_change_set INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - comment VARCHAR(500), - updated_last_on DATETIME, - updated_last_by VARCHAR(100) -); - -DELIMITER // -CREATE TRIGGER before_insert_Shop_User_Change_Set -BEFORE INSERT ON Shop_User_Change_Set -FOR EACH ROW -BEGIN - IF NEW.updated_last_on <=> NULL THEN - SET NEW.updated_last_on = NOW(); - END IF; - IF NEW.updated_last_by <=> NULL THEN - SET NEW.updated_last_by = CURRENT_USER(); - END IF; -END // -DELIMITER ; - -SELECT * FROM Shop_User_Change_Set; - - - --- Access Levels -CREATE TABLE Shop_Access_Level ( - id_access_level INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - code VARCHAR(50), - name VARCHAR(255), - priority INT NOT NULL, - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Access_Level_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Access_Level -BEFORE INSERT ON Shop_Access_Level -FOR EACH ROW -BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END // -DELIMITER ; - -CREATE TABLE Shop_Access_Level_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_access_level INT NOT NULL, - CONSTRAINT FK_Shop_Access_Level_Audit_id_access_level - FOREIGN KEY (id_access_level) - REFERENCES Shop_Access_Level(id_access_level) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Access_Level_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); - -DELIMITER // -CREATE TRIGGER before_update_Shop_Access_Level -BEFORE UPDATE ON Shop_Access_Level -FOR EACH ROW -BEGIN - INSERT INTO Shop_Access_Level_Audit ( - id_access_level, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_access_level, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT (OLD.code <=> NEW.code) - UNION - -- Changed name - SELECT NEW.id_access_level, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT (OLD.name <=> NEW.name) - UNION - -- Changed priority - SELECT NEW.id_access_level, 'priority', CONVERT(OLD.priority, CHAR), CONVERT(NEW.priority, CHAR), NEW.id_change_set - WHERE NOT (OLD.priority <=> NEW.priority) - UNION - -- Changed active - SELECT NEW.id_access_level, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; -END // -DELIMITER ; - -INSERT INTO Shop_Access_Level ( - display_order, code, name, priority -) -VALUES - (1, 'VIEW', 'View', 3), - (2, 'EDIT', 'Edit', 2), - (3, 'ADMIN', 'Admin', 1) -; - -SELECT * FROM Shop_Access_Level; -SELECT * FROM Shop_Access_Level_Audit; - - - --- Permission Groups -CREATE TABLE Shop_Permission_Group ( - id_group INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - code VARCHAR(50), - name VARCHAR(255), - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Permission_Group_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - ON UPDATE RESTRICT -); - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Permission_Group -BEFORE INSERT ON Shop_Permission_Group -FOR EACH ROW -BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END // -DELIMITER ; - -CREATE TABLE Shop_Permission_Group_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_group INT NOT NULL, - CONSTRAINT FK_Shop_Permission_Group_Audit_id_group - FOREIGN KEY (id_group) - REFERENCES Shop_Permission_Group(id_group) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Permission_Group_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - ON UPDATE RESTRICT -); - -DELIMITER // -CREATE TRIGGER before_update_Shop_Permission_Group -BEFORE UPDATE ON Shop_Permission_Group -FOR EACH ROW -BEGIN - INSERT INTO Shop_Permission_Group_Audit ( - id_group, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_group, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_group, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed active - SELECT NEW.id_group, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; -END // -DELIMITER ; - -INSERT INTO Shop_Permission_Group ( - display_order, code, name -) -VALUES - (1, 'STORE', 'Store Home') -; - -SELECT * FROM Shop_Permission_Group; -SELECT * FROM Shop_Permission_Group_Audit; - - - --- Permissions -CREATE TABLE Shop_Permission ( - id_permission INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - code VARCHAR(50), - name VARCHAR(255), - id_permission_group INT NOT NULL, - CONSTRAINT FK_Shop_Permission_id_permission_group - FOREIGN KEY (id_permission_group) - REFERENCES Shop_Permission_Group(id_group) - ON UPDATE RESTRICT, - required_access_level INT NOT NULL, - CONSTRAINT FK_Shop_Permission_id_access_level - FOREIGN KEY (required_access_level) - REFERENCES Shop_Access_Level(id_access_level), - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Permission_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Permission -BEFORE INSERT ON Shop_Permission -FOR EACH ROW -BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END // -DELIMITER ; - -CREATE TABLE Shop_Permission_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_permission INT NOT NULL, - CONSTRAINT FK_Shop_Permission_Audit_id_permission - FOREIGN KEY (id_permission) - REFERENCES Shop_Permission(id_permission) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Permission_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - ON UPDATE RESTRICT -); - -DELIMITER // -CREATE TRIGGER before_update_Shop_Permission -BEFORE UPDATE ON Shop_Permission -FOR EACH ROW -BEGIN - INSERT INTO Shop_Permission_Audit ( - id_permission, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_permission, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_permission, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed id_permission_group - SELECT NEW.id_permission, 'id_permission_group', CONVERT(OLD.id_permission_group, CHAR), CONVERT(NEW.id_permission_group, CHAR), NEW.id_change_set - WHERE NOT OLD.id_permission_group <=> NEW.id_permission_group - UNION - -- Changed required_access_level - SELECT NEW.id_permission, 'required_access_level', CONVERT(OLD.required_access_level, CHAR), CONVERT(NEW.required_access_level, CHAR), NEW.id_change_set - WHERE NOT OLD.required_access_level <=> NEW.required_access_level - UNION - -- Changed active - SELECT NEW.id_permission, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; -END // -DELIMITER ; - -INSERT INTO Shop_Permission ( - display_order, code, name, id_permission_group, required_access_level -) -VALUES - (1, 'STORE_PRODUCT', 'Store Product Page', 1, 1), - (2, 'STORE_SERVICES', 'Store Services Page', 1, 1), - (3, 'CONTACT_US', 'Contact Us Page', 1, 1) -; - -SELECT * FROM Shop_Permission; -SELECT * FROM Shop_Permission_Audit; - - - --- Roles -CREATE TABLE Shop_Role ( - id_role INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - code VARCHAR(50), - name VARCHAR(255), - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Role_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Role -BEFORE INSERT ON Shop_Role -FOR EACH ROW -BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END // -DELIMITER ; - -CREATE TABLE Shop_Role_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_role INT NOT NULL, - CONSTRAINT FK_Shop_Role_Audit_id_role - FOREIGN KEY (id_role) - REFERENCES Shop_Role(id_role) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Role_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - ON UPDATE RESTRICT -); - -DELIMITER // -CREATE TRIGGER before_update_Shop_Role -BEFORE UPDATE ON Shop_Role -FOR EACH ROW -BEGIN - INSERT INTO Shop_Role_Audit ( - id_role, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_role, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_role, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed active - SELECT NEW.id_role, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; -END // -DELIMITER ; - -INSERT INTO Shop_Role ( - display_order, - code, - name -) -VALUES - (1, 'DIRECTOR', 'Director'), - (2, 'USER', 'User') -; - -SELECT * FROM Shop_Role; -SELECT * FROM Shop_Role_Audit; - - - --- Role Permission link -CREATE TABLE Shop_Role_Permission_Link ( - id_link INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_role INT, - CONSTRAINT FK_Shop_Role_Permission_Link_id_role - FOREIGN KEY (id_role) - REFERENCES Shop_Role(id_role) - ON UPDATE RESTRICT, - id_permission INT, - CONSTRAINT FK_Shop_Role_Permission_Link_id_permission - FOREIGN KEY (id_permission) - REFERENCES Shop_Permission(id_permission) - ON UPDATE RESTRICT, - id_access_level INT, - CONSTRAINT FK_Shop_Role_Permission_Link_id_access_level - FOREIGN KEY (id_access_level) - REFERENCES Shop_Access_Level(id_access_level) - ON UPDATE RESTRICT, - active BIT NOT NULL DEFAULT 1, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Role_Permission_Link_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Role_Permission_Link -BEFORE INSERT ON Shop_Role_Permission_Link -FOR EACH ROW -BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END // -DELIMITER ; - -CREATE TABLE Shop_Role_Permission_Link_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_link INT NOT NULL, - CONSTRAINT FK_Shop_Role_Permission_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Role_Permission_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Role_Permission_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - ON UPDATE RESTRICT -); - -DELIMITER // -CREATE TRIGGER before_update_Shop_Role_Permission_Link -BEFORE UPDATE ON Shop_Role_Permission_Link -FOR EACH ROW -BEGIN - INSERT INTO Shop_Role_Permission_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_role - SELECT NEW.id_link, 'id_role', CONVERT(OLD.id_role, CHAR), CONVERT(NEW.id_role, CHAR), NEW.id_change_set - WHERE NOT OLD.id_role <=> NEW.id_role - UNION - -- Changed id_permission - SELECT NEW.id_link, 'id_permission', CONVERT(OLD.id_permission, CHAR), CONVERT(NEW.id_permission, CHAR), NEW.id_change_set - WHERE NOT OLD.id_permission <=> NEW.id_permission - UNION - -- Changed id_access_level - SELECT NEW.id_link, 'id_access_level', CONVERT(OLD.id_access_level, CHAR), CONVERT(NEW.id_access_level, CHAR), NEW.id_change_set - WHERE NOT OLD.id_access_level <=> NEW.id_access_level - UNION - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; -END // -DELIMITER ; - -INSERT INTO Shop_Role_Permission_Link ( - id_role, id_permission, id_access_level -) -VALUES - (1, 1, 3), - (1, 2, 3), - (1, 3, 3), - (2, 1, 1), - (2, 2, 1), - (2, 3, 1) -; - -SELECT * FROM Shop_Role_Permission_Link; -SELECT * FROM Shop_Role_Permission_Link_Audit; - - - --- Users -CREATE TABLE Shop_User ( - id_user INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - name VARCHAR(255), - is_super_user BIT NOT NULL DEFAULT 0, - active BIT NOT NULL DEFAULT 1, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_User_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); - -DELIMITER // -CREATE TRIGGER before_insert_Shop_User -BEFORE INSERT ON Shop_User -FOR EACH ROW -BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END // -DELIMITER ; - -CREATE TABLE Shop_User_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_user INT NOT NULL, - CONSTRAINT FK_Shop_User_Audit_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_User_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - ON UPDATE RESTRICT -); - -DELIMITER // -CREATE TRIGGER before_update_Shop_User -BEFORE UPDATE ON Shop_User -FOR EACH ROW -BEGIN - INSERT INTO Shop_User_Audit ( - id_user, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed name - SELECT NEW.id_user, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT (OLD.name <=> NEW.name) - UNION - -- Changed is_super_user - SELECT NEW.id_user, 'is_super_user', CONVERT(CONVERT(OLD.is_super_user, SIGNED), CHAR), CONVERT(CONVERT(NEW.is_super_user, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.is_super_user <=> NEW.is_super_user) - UNION - -- Changed active - SELECT NEW.id_user, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; -END // -DELIMITER ; - -INSERT INTO Shop_User ( - name, - is_super_user -) -VALUES ( - 'Teddy', - 1 -); - -SELECT * FROM Shop_User; -SELECT * FROM Shop_User_Audit; - - - --- User Role link -CREATE TABLE Shop_User_Role_Link ( - id_link INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_user INT, - CONSTRAINT FK_Shop_User_Role_Link_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user) - ON UPDATE RESTRICT, - id_role INT, - CONSTRAINT FK_Shop_User_Role_Link_id_role - FOREIGN KEY (id_role) - REFERENCES Shop_Role(id_role) - ON UPDATE RESTRICT, - active BIT NOT NULL DEFAULT 1, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_User_Role_Link_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); - -DELIMITER // -CREATE TRIGGER before_insert_Shop_User_Role_Link -BEFORE INSERT ON Shop_User_Role_Link -FOR EACH ROW -BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END // -DELIMITER ; - -CREATE TABLE Shop_User_Role_Link_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_link INT NOT NULL, - CONSTRAINT FK_Shop_User_Role_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_User_Role_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_User_Role_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - ON UPDATE RESTRICT -); - -DELIMITER // -CREATE TRIGGER before_update_Shop_User_Role_Link -BEFORE UPDATE ON Shop_User_Role_Link -FOR EACH ROW -BEGIN - INSERT INTO Shop_User_Role_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; -END // -DELIMITER ; - -INSERT INTO Shop_User_Role_Link ( - id_user, id_role -) -VALUES - (1, 1) -; - -SELECT * FROM Shop_User_Role_Link; -SELECT * FROM Shop_User_Role_Link_Audit; - - - --- Addresses -CREATE TABLE Shop_Address ( - id_address INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_user INT NOT NULL, - CONSTRAINT FK_Shop_Address_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user) - ON UPDATE RESTRICT, - region VARCHAR(100) NOT NULL, - name_full VARCHAR(255) NOT NULL, - phone_number VARCHAR(20) NOT NULL, - postcode VARCHAR(20) NOT NULL, - address_line_1 VARCHAR(100) NOT NULL, - address_line_2 VARCHAR(100) NOT NULL, - city VARCHAR(50) NOT NULL, - county VARCHAR(100) NOT NULL, - active BIT NOT NULL DEFAULT 1, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Address_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Address -BEFORE INSERT ON Shop_Address -FOR EACH ROW -BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END // -DELIMITER ; - -CREATE TABLE Shop_Address_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_address INT NOT NULL, - CONSTRAINT FK_Shop_Address_Audit_id_address - FOREIGN KEY (id_address) - REFERENCES Shop_Address(id_address) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Address_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - ON UPDATE RESTRICT -); - -DELIMITER // -CREATE TRIGGER before_update_Shop_Address -BEFORE UPDATE ON Shop_Address -FOR EACH ROW -BEGIN - INSERT INTO Shop_Address_Audit ( - id_address, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed region - SELECT NEW.id_address, 'region', OLD.region, NEW.region, NEW.id_change_set - WHERE NOT OLD.region <=> NEW.region - UNION - -- Changed name_full - SELECT NEW.id_address, 'name_full', OLD.name_full, NEW.name_full, NEW.id_change_set - WHERE NOT OLD.name_full <=> NEW.name_full - UNION - -- Changed phone_number - SELECT NEW.id_address, 'phone_number', OLD.phone_number, NEW.phone_number, NEW.id_change_set - WHERE NOT OLD.phone_number <=> NEW.phone_number - UNION - -- Changed postcode - SELECT NEW.id_address, 'postcode', OLD.postcode, NEW.postcode, NEW.id_change_set - WHERE NOT OLD.postcode <=> NEW.postcode - UNION - -- Changed address_line_1 - SELECT NEW.id_address, 'address_line_1', OLD.address_line_1, NEW.address_line_1, NEW.id_change_set - WHERE NOT OLD.address_line_1 <=> NEW.address_line_1 - UNION - -- Changed address_line_2 - SELECT NEW.id_address, 'address_line_2', OLD.address_line_2, NEW.address_line_2, NEW.id_change_set - WHERE NOT OLD.address_line_2 <=> NEW.address_line_2 - UNION - -- Changed city - SELECT NEW.id_address, 'city', OLD.city, NEW.city, NEW.id_change_set - WHERE NOT OLD.city <=> NEW.city - UNION - -- Changed county - SELECT NEW.id_address, 'county', OLD.county, NEW.county, NEW.id_change_set - WHERE NOT OLD.county <=> NEW.county - UNION - -- Changed active - SELECT NEW.id_address, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; -END // -DELIMITER ; - -INSERT INTO Shop_Address ( - id_user, region, name_full, phone_number, postcode, address_line_1, address_line_2, city, county -) -SELECT U.id_user, 'United Kingdom', U.name, '07375 571430', 'NN6 6EB', 'The Laurels', 'Cold Ashby Road', 'Cold Ashby', 'Northamptonshire' - FROM Shop_User U; - -SELECT * FROM Shop_Address; -SELECT * FROM Shop_Address_Audit; - - diff --git a/static/MySQL/deprecated/000_init_tables_product.sql b/static/MySQL/deprecated/000_init_tables_product.sql deleted file mode 100644 index d10e97ff..00000000 --- a/static/MySQL/deprecated/000_init_tables_product.sql +++ /dev/null @@ -1,1520 +0,0 @@ -/* Store */ - - - --- Delete old tables -DROP TABLE IF EXISTS Shop_Product_Delivery_Region_Link_Audit; -DROP TABLE IF EXISTS Shop_Product_Delivery_Region_Link; - -DROP TABLE IF EXISTS Shop_Delivery_Region_Audit; -DROP TABLE IF EXISTS Shop_Delivery_Region; - -DROP TABLE IF EXISTS Shop_Delivery_Option_Audit; -DROP TABLE IF EXISTS Shop_Delivery_Option; - -DROP TABLE IF EXISTS Shop_Delivery_Option_Type_Audit; -DROP TABLE IF EXISTS Shop_Delivery_Option_Type; - -DROP TABLE IF EXISTS Shop_Product_Image_Link_Audit; -DROP TABLE IF EXISTS Shop_Product_Image_Link; - -DROP TABLE IF EXISTS Shop_Image_Audit; -DROP TABLE IF EXISTS Shop_Image; - -DROP TABLE IF EXISTS Shop_Image_Type_Audit; -DROP TABLE IF EXISTS Shop_Image_Type; - -DROP TABLE IF EXISTS Shop_Product_Variation_Link_Audit; -DROP TABLE IF EXISTS Shop_Product_Variation_Link; - -DROP TABLE IF EXISTS Shop_Variation_Audit; -DROP TABLE IF EXISTS Shop_Variation; - -DROP TABLE IF EXISTS Shop_Variation_Type_Audit; -DROP TABLE IF EXISTS Shop_Variation_Type; - -DROP TABLE IF EXISTS Shop_Product_Audit; -DROP TABLE IF EXISTS Shop_Product; - -DROP TABLE IF EXISTS Shop_Interval_Recurrence_Audit; -DROP TABLE IF EXISTS Shop_Interval_Recurrence; - -DROP TABLE IF EXISTS Shop_Product_Category_Audit; -DROP TABLE IF EXISTS Shop_Product_Category; - -DROP TABLE IF EXISTS Shop_General_Audit; -DROP TABLE IF EXISTS Shop_General; - -DROP TABLE IF EXISTS File_Type_Audit; -DROP TABLE IF EXISTS File_Type; - -DROP TABLE IF EXISTS Shop_Product_Change_Set; - - - --- Product Change Sets -CREATE TABLE Shop_Product_Change_Set ( - id_change_set INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - comment VARCHAR(500), - updated_last_on DATETIME, - updated_last_by VARCHAR(100) -); - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Product_Change_Set -BEFORE INSERT ON Shop_Product_Change_Set -FOR EACH ROW -BEGIN - IF NEW.updated_last_on <=> NULL THEN - SET NEW.updated_last_on = NOW(); - END IF; - IF NEW.updated_last_by <=> NULL THEN - SET NEW.updated_last_by = CURRENT_USER(); - END IF; -END // -DELIMITER ; - -SELECT * FROM Shop_Product_Change_Set; - - - --- File Types -CREATE TABLE File_Type ( - id_type INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - code VARCHAR(50), - name VARCHAR(100), - extension VARCHAR(50), - created_on DATETIME, - created_by INT, - updated_last_on DATETIME, - updated_last_by VARCHAR(100) -); - -DELIMITER // -CREATE TRIGGER before_insert_File_Type -BEFORE INSERT ON File_Type -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - -CREATE TABLE File_Type_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_type INT NOT NULL, - CONSTRAINT FK_File_Type_Audit_id_type - FOREIGN KEY (id_type) - REFERENCES File_Type(id_type) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - created_on DATETIME, - created_by INT, - updated_last_on DATETIME, - updated_last_by VARCHAR(100) -); - -DELIMITER // -CREATE TRIGGER before_insert_File_Type_Audit -BEFORE INSERT ON File_Type_Audit -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - -DELIMITER // -CREATE TRIGGER before_update_File_Type_Audit -BEFORE UPDATE ON File_Type_Audit -FOR EACH ROW -BEGIN - SET NEW.updated_last_on = NOW(); - SET NEW.updated_last_by = CURRENT_USER(); -END // -DELIMITER ; - -DELIMITER // -CREATE TRIGGER before_update_File_Type -BEFORE UPDATE ON File_Type -FOR EACH ROW -BEGIN - INSERT INTO File_Type_Audit ( - id_type, - name_field, - value_prev, - value_new - ) - -- Changed code - SELECT NEW.id_type, 'code', OLD.code, NEW.code - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_type, 'name', OLD.name, NEW.name - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed extension - SELECT NEW.id_type, 'extension', CONVERT(OLD.extension, CHAR), CONVERT(NEW.extension, CHAR) - WHERE NOT OLD.extension <=> NEW.extension - ; -END // -DELIMITER ; - -INSERT INTO File_Type ( - code, name, extension -) -VALUES - ('JPEG', 'Joint Photographic Export Group', 'jpg'), - ('PNG', 'Portable Network Graphic', 'png'), - ('GIF', 'GIF', 'gif'), - ('MPEG-4', 'Multimedia Photographic Export Group 4', 'mp4') -; - -SELECT * FROM File_Type; -SELECT * FROM File_Type_Audit; - - - --- Generic / shared properties -CREATE TABLE Shop_General ( - id_general INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - quantity_max FLOAT, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_General_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - -DELIMITER // -CREATE TRIGGER before_insert_Shop_General -BEFORE INSERT ON Shop_General -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - -CREATE TABLE Shop_General_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_general INT NOT NULL, - CONSTRAINT FK_Shop_General_Audit_id_general - FOREIGN KEY (id_general) - REFERENCES Shop_General(id_general) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_General_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - -DELIMITER // -CREATE TRIGGER before_update_Shop_General -BEFORE UPDATE ON Shop_General -FOR EACH ROW -BEGIN - INSERT INTO Shop_General_Audit ( - id_general, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed quantity max - SELECT NEW.id_general, 'quantity_max', CONVERT(OLD.quantity_max, CHAR), CONVERT(NEW.quantity_max, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - ; -END // -DELIMITER ; - -INSERT INTO Shop_General ( - quantity_max -) -VALUES ( - 10 -); - -SELECT * FROM Shop_General; -SELECT * FROM Shop_General_Audit; - - - --- Categories -CREATE TABLE Shop_Product_Category ( - id_category INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - code VARCHAR(50), - name VARCHAR(255), - description VARCHAR(4000), - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Product_Category_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Product_Category -BEFORE INSERT ON Shop_Product_Category -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - -CREATE TABLE Shop_Product_Category_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_category INT NOT NULL, - CONSTRAINT FK_Shop_Product_Category_Audit_id_category - FOREIGN KEY (id_category) - REFERENCES Shop_Product_Category(id_category) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Product_Category_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - -DELIMITER // -CREATE TRIGGER before_update_Shop_Product_Category -BEFORE UPDATE ON Shop_Product_Category -FOR EACH ROW -BEGIN - INSERT INTO Shop_Product_Category_Audit ( - id_category, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_category, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_category, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed description - SELECT NEW.id_category, 'description', OLD.description, NEW.description, NEW.id_change_set - WHERE NOT OLD.description <=> NEW.description - UNION - -- Changed active - SELECT NEW.id_category, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_category, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; -END // -DELIMITER ; - -INSERT INTO Shop_Product_Category ( - display_order, - code, - name, - description -) -VALUES ( - 1, - 'MISC', - 'Miscellaneous', - 'Not category allocated products' -); - -SELECT * FROM Shop_Product_Category; -SELECT * FROM Shop_Product_Category_Audit; - - - --- Recurrence Interval -CREATE TABLE Shop_Interval_Recurrence ( - id_interval INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - code VARCHAR(50), - name VARCHAR(255), - name_plural VARCHAR(256), - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Interval_Recurrence_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Interval_Recurrence -BEFORE INSERT ON Shop_Interval_Recurrence -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - -CREATE TABLE Shop_Interval_Recurrence_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_interval INT NOT NULL, - CONSTRAINT FK_Shop_Interval_Recurrence_Audit_id_interval - FOREIGN KEY (id_interval) - REFERENCES Shop_Interval_Recurrence(id_interval) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(256), - value_new VARCHAR(256), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Interval_Recurrence_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - -DELIMITER // -CREATE TRIGGER before_update_Shop_Interval_Recurrence -BEFORE UPDATE ON Shop_Interval_Recurrence -FOR EACH ROW -BEGIN - INSERT INTO Shop_Interval_Recurrence_Audit ( - id_interval, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_interval, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_interval, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed name_plural - SELECT NEW.id_interval, 'name_plural', OLD.name_plural, NEW.name_plural, NEW.id_change_set - WHERE NOT OLD.name_plural <=> NEW.name_plural - ; -END // -DELIMITER ; - -INSERT INTO Shop_Interval_Recurrence ( - code, name, name_plural -) -VALUES - ('WEEK', 'Week', 'Weeks'), - ('MONTH', 'Month', 'Months'), - ('YEAR', 'Year', 'Years') -; - -SELECT * FROM Shop_Interval_Recurrence; -SELECT * FROM Shop_Interval_Recurrence_Audit; - - - --- Products -CREATE TABLE Shop_Product ( - id_product INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - name VARCHAR(255), - description VARCHAR(4000), - price_GBP FLOAT, - id_category INT NOT NULL, - CONSTRAINT FK_Shop_Product_id_category - FOREIGN KEY (id_category) - REFERENCES Shop_Product_Category(id_category) - ON UPDATE RESTRICT, - latency_manuf INT NOT NULL DEFAULT 14, - quantity_min FLOAT NOT NULL DEFAULT 1, - quantity_max FLOAT NOT NULL DEFAULT 1, -- @_quantity_max, - quantity_step FLOAT NOT NULL DEFAULT 1, - quantity_stock FLOAT NOT NULL DEFAULT 0, - is_subscription BIT NOT NULL DEFAULT 0, - id_unit_measurement_interval_recurrence INT, - CONSTRAINT FK_Shop_Product_id_unit_measurement_interval_recurrence - FOREIGN KEY (id_unit_measurement_interval_recurrence) - REFERENCES Shop_Interval_Recurrence(id_interval), - count_interval_recurrence INT, - id_stripe_product VARCHAR(100), - id_stripe_price VARCHAR(100), - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Product_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Product -BEFORE INSERT ON Shop_Product -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - -CREATE TABLE Shop_Product_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_product INT NOT NULL, - CONSTRAINT FK_Shop_Product_Audit_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Product_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - -DELIMITER // -CREATE TRIGGER before_update_Shop_Product -BEFORE UPDATE ON Shop_Product -FOR EACH ROW -BEGIN - INSERT INTO Shop_Product_Audit ( - id_product, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed name - SELECT NEW.id_product, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed description - SELECT NEW.id_product, 'description', OLD.description, NEW.description, NEW.id_change_set - WHERE NOT OLD.description <=> NEW.description - UNION - -- Changed price_GBP - SELECT NEW.id_product, 'price_GBP', CONVERT(OLD.price_GBP, CHAR), CONVERT(NEW.price_GBP, CHAR), NEW.id_change_set - WHERE NOT OLD.price_GBP <=> NEW.price_GBP - UNION - -- Changed id_category - SELECT NEW.id_product, 'id_category', CONVERT(OLD.id_category, CHAR), CONVERT(NEW.id_category, CHAR), NEW.id_change_set - WHERE NOT OLD.id_category <=> NEW.id_category - UNION - -- Changed latency_manuf - SELECT NEW.id_product, 'latency_manuf', CONVERT(OLD.latency_manuf, CHAR), CONVERT(NEW.latency_manuf, CHAR), NEW.id_change_set - WHERE NOT OLD.latency_manuf <=> NEW.latency_manuf - UNION - -- Changed quantity_min - SELECT NEW.id_product, 'quantity_min', CONVERT(OLD.quantity_min, CHAR), CONVERT(NEW.quantity_min, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_min <=> NEW.quantity_min - UNION - -- Changed quantity_max - SELECT NEW.id_product, 'quantity_max', CONVERT(OLD.quantity_max, CHAR), CONVERT(NEW.quantity_max, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - UNION - -- Changed quantity_step - SELECT NEW.id_product, 'quantity_step', CONVERT(OLD.quantity_step, CHAR), CONVERT(NEW.quantity_step, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_step <=> NEW.quantity_step - UNION - -- Changed quantity_stock - SELECT NEW.id_product, 'quantity_stock', CONVERT(OLD.quantity_stock, CHAR), CONVERT(NEW.quantity_stock, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_stock <=> NEW.quantity_stock - UNION - -- Changed is_subscription - SELECT NEW.id_product, 'is_subscription', CONVERT(CONVERT(OLD.is_subscription, SIGNED), CHAR), CONVERT(CONVERT(NEW.is_subscription, SIGNED), CHAR), NEW.id_change_set - WHERE NOT OLD.is_subscription <=> NEW.is_subscription - UNION - -- Changed id_unit_measurement_interval_recurrence - SELECT NEW.id_product, 'id_unit_measurement_interval_recurrence', CONVERT(OLD.id_unit_measurement_interval_recurrence, CHAR), CONVERT(NEW.id_unit_measurement_interval_recurrence, CHAR), NEW.id_change_set - WHERE NOT OLD.id_unit_measurement_interval_recurrence <=> NEW.id_unit_measurement_interval_recurrence - UNION - -- Changed count_interval_recurrence - SELECT NEW.id_product, 'count_interval_recurrence', CONVERT(OLD.count_interval_recurrence, CHAR), CONVERT(NEW.count_interval_recurrence, CHAR), NEW.id_change_set - WHERE NOT OLD.count_interval_recurrence <=> NEW.count_interval_recurrence - UNION - -- Changed id_stripe_product - SELECT NEW.id_product, 'id_stripe_product', OLD.id_stripe_product, NEW.id_stripe_product, NEW.id_change_set - WHERE NOT OLD.id_stripe_product <=> NEW.id_stripe_product - UNION - -- Changed id_stripe_price - SELECT NEW.id_product, 'id_stripe_price', OLD.id_stripe_price, NEW.id_stripe_price, NEW.id_change_set - WHERE NOT OLD.id_stripe_price <=> NEW.id_stripe_price - UNION - -- Changed active - SELECT NEW.id_product, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_product, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; -END // -DELIMITER ; - -INSERT INTO Shop_Product ( - display_order, - name, - description, - price_GBP, - id_category, - latency_manuf, - quantity_stock, - id_stripe_product, - id_stripe_price -) -VALUES ( - 1, - 'Braille Keyboard Translator', - 'Translate text into 3D Braille keyboard.', - 25, - 1, - 14, - 99, - 'prod_PB0NUOSEs06ymG', - 'price_1OMeN9L7BuLKjoMpyMY6Aae4' -); - -SELECT * FROM Shop_Product; -SELECT * FROM Shop_Product_Audit; - - - --- Variation Types -CREATE TABLE Shop_Variation_Type ( - id_type INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - code VARCHAR(50), - name VARCHAR(255), - name_plural VARCHAR(256), - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Variation_Type_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Variation_Type -BEFORE INSERT ON Shop_Variation_Type -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - -CREATE TABLE Shop_Variation_Type_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_type INT NOT NULL, - CONSTRAINT FK_Shop_Variation_Type_Audit_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Variation_Type(id_type) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Variation_Type_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - -DELIMITER // -CREATE TRIGGER before_update_Shop_Variation_Type -BEFORE UPDATE ON Shop_Variation_Type -FOR EACH ROW -BEGIN - INSERT INTO Shop_Variation_Type_Audit ( - id_type, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_type, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_type, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed name_plural - SELECT NEW.id_type, 'name_plural', OLD.name_plural, NEW.name_plural, NEW.id_change_set - WHERE NOT OLD.name_plural <=> NEW.name_plural - UNION - -- Changed active - SELECT NEW.id_type, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_type, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; -END // -DELIMITER ; - -INSERT INTO Shop_Variation_Type ( - display_order, code, name, name_plural -) -VALUES - (1, 'COLOUR', 'Colour', 'Colours') -; - -SELECT * FROM Shop_Variation_Type; -SELECT * FROM Shop_Variation_Type_Audit; - - - --- Variations -CREATE TABLE Shop_Variation ( - id_variation INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_type INT NOT NULL, - CONSTRAINT FK_Shop_Variation_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Variation_Type(id_type) - ON UPDATE RESTRICT, - code VARCHAR(50), - name VARCHAR(255), - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Variation_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Variation -BEFORE INSERT ON Shop_Variation -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - -CREATE TABLE Shop_Variation_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_variation INT NOT NULL, - CONSTRAINT FK_Shop_Variation_Audit_id_variation - FOREIGN KEY (id_variation) - REFERENCES Shop_Variation(id_variation) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Variation_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - -DELIMITER // -CREATE TRIGGER before_update_Shop_Variation -BEFORE UPDATE ON Shop_Variation -FOR EACH ROW -BEGIN - INSERT INTO Shop_Variation_Audit ( - id_variation, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_variation, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_variation, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed active - SELECT NEW.id_variation, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_variation, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; -END // -DELIMITER ; - -INSERT INTO Shop_Variation ( - display_order, id_type, code, name -) -VALUES - (1, 1, 'RED', 'Red') -; - -SELECT * FROM Shop_Variation_Type; -SELECT * FROM Shop_Variation_Type_Audit; - - - --- Product Variation Link -CREATE TABLE Shop_Product_Variation_Link ( - id_link INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_product INT, - CONSTRAINT FK_Shop_Product_Variation_Link_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product) - ON UPDATE RESTRICT, - id_variation INT, - CONSTRAINT FK_Shop_Product_Variation_Link_id_variation - FOREIGN KEY (id_variation) - REFERENCES Shop_Variation(id_variation) - ON UPDATE RESTRICT, - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Product_Variation_Link_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Product_Variation_Link -BEFORE INSERT ON Shop_Product_Variation_Link -FOR EACH ROW -BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END // -DELIMITER ; - -CREATE TABLE Shop_Product_Variation_Link_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_link INT NOT NULL, - CONSTRAINT FK_Shop_Product_Variation_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Product_Variation_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Product_Variation_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) - ON UPDATE RESTRICT -); - -DELIMITER // -CREATE TRIGGER before_update_Shop_Product_Variation_Link -BEFORE UPDATE ON Shop_Product_Variation_Link -FOR EACH ROW -BEGIN - INSERT INTO Shop_Product_Variation_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_product - SELECT NEW.id_link, 'id_product', OLD.id_product, NEW.id_product, NEW.id_change_set - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed id_variation - SELECT NEW.id_link, 'id_variation', OLD.id_variation, NEW.id_variation, NEW.id_change_set - WHERE NOT OLD.id_variation <=> NEW.id_variation - UNION - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_link, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; -END // -DELIMITER ; - -INSERT INTO Shop_Product_Variation_Link ( - display_order, id_product, id_variation -) -VALUES - (1, 1, 1) -; - -SELECT * FROM Shop_Product_Variation_Link; -SELECT * FROM Shop_Product_Variation_Link_Audit; - - - --- Image Types -CREATE TABLE Shop_Image_Type ( - id_type INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - code VARCHAR(50), - name VARCHAR(255), - name_plural VARCHAR(256), - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Image_Type_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Image_Type -BEFORE INSERT ON Shop_Image_Type -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - -CREATE TABLE Shop_Image_Type_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_type INT NOT NULL, - CONSTRAINT FK_Shop_Image_Type_Audit_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Image_Type(id_type) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Image_Type_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - -DELIMITER // -CREATE TRIGGER before_update_Shop_Image_Type -BEFORE UPDATE ON Shop_Image_Type -FOR EACH ROW -BEGIN - INSERT INTO Shop_Image_Type_Audit ( - id_type, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_type, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_type, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed name_plural - SELECT NEW.id_type, 'name_plural', OLD.name_plural, NEW.name_plural, NEW.id_change_set - WHERE NOT OLD.name_plural <=> NEW.name_plural - UNION - -- Changed active - SELECT NEW.id_type, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_type, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; -END // -DELIMITER ; - -INSERT INTO Shop_Image_Type ( - display_order, code, name, name_plural -) -VALUES - (1, 'FULL', 'Full Quality Image', 'Full Quality Images'), - (1, 'LOW', 'Low Quality Image', 'Low Quality Images'), - (1, 'THUMBNAIL', 'Thumbnail Image', 'Thumbnail Images') -; - -SELECT * FROM Shop_Image_Type; -SELECT * FROM Shop_Image_Type_Audit; - - - --- Images -CREATE TABLE Shop_Image ( - id_image INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_type INT NOT NULL, - CONSTRAINT FK_Shop_Image_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Image_Type(id_type), - id_product INT NOT NULL, - CONSTRAINT FK_Shop_Image_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - url VARCHAR(255), - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Image_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Image -BEFORE INSERT ON Shop_Image -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - -CREATE TABLE Shop_Image_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_image INT NOT NULL, - CONSTRAINT FK_Shop_Image_Audit_id_image - FOREIGN KEY (id_image) - REFERENCES Shop_Image(id_image), - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Image_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - -DELIMITER // -CREATE TRIGGER before_update_Shop_Image -BEFORE UPDATE ON Shop_Image -FOR EACH ROW -BEGIN - INSERT INTO Shop_Image_Audit ( - id_image, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_type - SELECT NEW.id_image, 'id_type', CONVERT(OLD.id_type, CHAR), CONVERT(NEW.id_type, CHAR), NEW.id_change_set - WHERE NOT OLD.id_type <=> NEW.id_type - UNION - -- Changed id_product - SELECT NEW.id_image, 'id_product', CONVERT(OLD.id_product, CHAR), CONVERT(NEW.id_product, CHAR), NEW.id_change_set - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed url - SELECT NEW.id_image, 'url', OLD.url, NEW.url, NEW.id_change_set - WHERE NOT OLD.url <=> NEW.url - UNION - -- Changed active - SELECT NEW.id_image, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_image, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; -END // -DELIMITER ; - -INSERT INTO Shop_Image ( - display_order, id_product, id_type, url -) -VALUES - (1, 1, 1, 'www.porn.co.uk') -; - -SELECT * FROM Shop_Image; -SELECT * FROM Shop_Image_Audit; - - -/* --- Product Image Link -CREATE TABLE Shop_Product_Image_Link ( - id_link INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_product INT, - CONSTRAINT FK_Shop_Product_Image_Link_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product) - ON UPDATE RESTRICT, - id_image INT, - CONSTRAINT FK_Shop_Product_Image_Link_id_image - FOREIGN KEY (id_image) - REFERENCES Shop_Image(id_image) - ON UPDATE RESTRICT, - active BIT NOT NULL DEFAULT 1, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Product_Image_Link_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Product_Image_Link -BEFORE INSERT ON Shop_Product_Image_Link -FOR EACH ROW -BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END // -DELIMITER ; - -CREATE TABLE Shop_Product_Image_Link_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_link INT NOT NULL, - CONSTRAINT FK_Shop_Product_Image_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Product_Image_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Product_Image_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) - ON UPDATE RESTRICT -); - -DELIMITER // -CREATE TRIGGER before_update_Shop_Product_Image_Link -BEFORE UPDATE ON Shop_Product_Image_Link -FOR EACH ROW -BEGIN - INSERT INTO Shop_Product_Image_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - VALUES ( - ( -- Changed id_product - SELECT NEW.id_link, 'id_product', OLD.id_product, NEW.id_product, NEW.id_change_set - WHERE NOT OLD.id_product <=> NEW.id_product - ), - ( -- Changed id_variation - SELECT NEW.id_link, 'id_image', OLD.id_image, NEW.id_image, NEW.id_change_set - WHERE NOT OLD.id_image <=> NEW.id_image - ), - ( -- Changed active - SELECT NEW.id_link, 'active', OLD.active, NEW.active, NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - ) - ); -END // -DELIMITER ; - -INSERT INTO Shop_Product_Image_Link ( - id_product, id_image -) -VALUES - (1, 1) -; - -SELECT * FROM Shop_Product_Image_Link; -SELECT * FROM Shop_Product_Image_Link_Audit; -*/ - - --- Delivery Option Types -CREATE TABLE Shop_Delivery_Option_Type ( - id_type INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - code VARCHAR(50) NOT NULL, - name VARCHAR(100) NOT NULL, - latency_delivery_min INT NOT NULL, - latency_delivery_max INT NOT NULL, - quantity_min INT NOT NULL, - quantity_max INT NOT NULL, - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Delivery_Option_Type_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Delivery_Option_Type -BEFORE INSERT ON Shop_Delivery_Option_Type -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - -CREATE TABLE Shop_Delivery_Option_Type_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_type INT NOT NULL, - CONSTRAINT FK_Shop_Delivery_Option_Type_Audit_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Delivery_Option_Type(id_type) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Delivery_Option_Type_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - -DELIMITER // -CREATE TRIGGER before_update_Shop_Delivery_Option_Type -BEFORE UPDATE ON Shop_Delivery_Option_Type -FOR EACH ROW -BEGIN - INSERT INTO Shop_Delivery_Option_Type_Audit ( - id_type, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_type, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_type, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed latency_delivery_min - SELECT NEW.id_type, 'latency_delivery_min', CONVERT(OLD.latency_delivery_min, CHAR), CONVERT(NEW.latency_delivery_min, CHAR), NEW.id_change_set - WHERE NOT OLD.latency_delivery_min <=> NEW.latency_delivery_min - UNION - -- Changed latency_delivery_max - SELECT NEW.id_type, 'latency_delivery_max', CONVERT(OLD.latency_delivery_max, CHAR), CONVERT(NEW.latency_delivery_max, CHAR), NEW.id_change_set - WHERE NOT OLD.latency_delivery_max <=> NEW.latency_delivery_max - UNION - -- Changed quantity_min - SELECT NEW.id_type, 'quantity_min', CONVERT(OLD.quantity_min, CHAR), CONVERT(NEW.quantity_min, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_min <=> NEW.quantity_min - UNION - -- Changed quantity_max - SELECT NEW.id_type, 'quantity_max', CONVERT(OLD.quantity_max, CHAR), CONVERT(NEW.quantity_max, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - UNION - -- Changed active - SELECT NEW.id_type, 'active', CONVERT(OLD.active, CHAR), CONVERT(NEW.active, CHAR), NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - UNION - -- Changed display_order - SELECT NEW.id_type, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; -END // -DELIMITER ; - -INSERT INTO Shop_Delivery_Option_Type ( - display_order, code, name, latency_delivery_min, latency_delivery_max, quantity_min, quantity_max -) -VALUES - (1, 'COLLECT', 'Collection', 0, 0, 0, 1), - (2, 'SIGNED_1', 'First Class Signed-For', 2, 4, 0, 1) -; - -SELECT * FROM Shop_Delivery_Option_Type; -SELECT * FROM Shop_Delivery_Option_Type_Audit; - - - --- Delivery Option -CREATE TABLE Shop_Delivery_Option ( - id_option INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_product INT, - CONSTRAINT FK_Shop_Delivery_Option_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product) - ON UPDATE RESTRICT, - id_delivery_type INT, - CONSTRAINT FK_Shop_Delivery_Option_id_delivery_type - FOREIGN KEY (id_delivery_type) - REFERENCES Shop_Delivery_Option_Type(id_type) - ON UPDATE RESTRICT, - price_GBP FLOAT NOT NULL, - active BIT NOT NULL DEFAULT 1, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Delivery_Option_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Delivery_Option -BEFORE INSERT ON Shop_Delivery_Option -FOR EACH ROW -BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END // -DELIMITER ; - -CREATE TABLE Shop_Delivery_Option_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_option INT NOT NULL, - CONSTRAINT FK_Shop_Delivery_Option_Audit_id_option - FOREIGN KEY (id_option) - REFERENCES Shop_Delivery_Option(id_option) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Delivery_Option_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) - ON UPDATE RESTRICT -); - -DELIMITER // -CREATE TRIGGER before_update_Shop_Delivery_Option -BEFORE UPDATE ON Shop_Delivery_Option -FOR EACH ROW -BEGIN - INSERT INTO Shop_Delivery_Option_Audit ( - id_option, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_product - SELECT NEW.id_option, 'id_product', CONVERT(OLD.id_product, CHAR), CONVERT(NEW.id_product, CHAR), NEW.id_change_set - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed id_delivery_type - SELECT NEW.id_option, 'id_delivery_type', CONVERT(OLD.id_delivery_type, CHAR), CONVERT(NEW.id_delivery_type, CHAR), NEW.id_change_set - WHERE NOT OLD.id_delivery_type <=> NEW.id_delivery_type - UNION - -- Changed price_GBP - SELECT NEW.id_option, 'price_GBP', CONVERT(OLD.price_GBP, CHAR), CONVERT(NEW.price_GBP, CHAR), NEW.id_change_set - WHERE NOT OLD.price_GBP <=> NEW.price_GBP - UNION - -- Changed active - SELECT NEW.id_option, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; -END // -DELIMITER ; - -INSERT INTO Shop_Delivery_Option ( - id_product, id_delivery_type, price_GBP -) -VALUES - (1, 1, 5) -; - -SELECT * FROM Shop_Delivery_Option; -SELECT * FROM Shop_Delivery_Option_Audit; - - - --- Delivery Regions -CREATE TABLE Shop_Delivery_Region ( - id_region INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - code VARCHAR(50) NOT NULL, - name VARCHAR(200) NOT NULL, - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Delivery_Region_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Delivery_Region -BEFORE INSERT ON Shop_Delivery_Region -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - -CREATE TABLE Shop_Delivery_Region_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_region INT NOT NULL, - CONSTRAINT FK_Shop_Delivery_Region_Audit_id_region - FOREIGN KEY (id_region) - REFERENCES Shop_Delivery_Region(id_region) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Delivery_Region_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - -DELIMITER // -CREATE TRIGGER before_update_Shop_Delivery_Region -BEFORE UPDATE ON Shop_Delivery_Region -FOR EACH ROW -BEGIN - INSERT INTO Shop_Delivery_Region_Audit ( - id_region, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_region, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_region, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed active - SELECT NEW.id_region, 'active', CONVERT(OLD.active, CHAR), CONVERT(NEW.active, CHAR), NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - UNION - -- Changed display_order - SELECT NEW.id_region, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; -END // -DELIMITER ; - -INSERT INTO Shop_Delivery_Region ( - display_order, code, name -) -VALUES - (1, 'UK', 'United Kingdom') -; - -SELECT * FROM Shop_Delivery_Region; -SELECT * FROM Shop_Delivery_Region_Audit; - - - --- Product Delivery Option Link -CREATE TABLE Shop_Product_Delivery_Region_Link ( - id_link INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_product INT NOT NULL, - CONSTRAINT FK_Shop_Product_Delivery_Region_Link_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product) - ON UPDATE RESTRICT, - id_region INT NOT NULL, - CONSTRAINT FK_Shop_Product_Delivery_Region_Link_id_region - FOREIGN KEY (id_region) - REFERENCES Shop_Delivery_Region(id_region) - ON UPDATE RESTRICT, - active BIT NOT NULL DEFAULT 1, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Product_Delivery_Region_Link_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Product_Delivery_Region_Link -BEFORE INSERT ON Shop_Product_Delivery_Region_Link -FOR EACH ROW -BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END // -DELIMITER ; - -CREATE TABLE Shop_Product_Delivery_Region_Link_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_link INT NOT NULL, - CONSTRAINT FK_Shop_Product_Delivery_Region_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Product_Delivery_Region_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Product_Delivery_Region_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) - ON UPDATE RESTRICT -); - -DELIMITER // -CREATE TRIGGER before_update_Shop_Product_Delivery_Region_Link -BEFORE UPDATE ON Shop_Product_Delivery_Region_Link -FOR EACH ROW -BEGIN - INSERT INTO Shop_Product_Delivery_Region_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_product - SELECT NEW.id_link, 'id_product', CONVERT(OLD.id_product, CHAR), CONVERT(NEW.id_product, CHAR), NEW.id_change_set - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed id_region - SELECT NEW.id_link, 'id_region', CONVERT(OLD.id_region, CHAR), CONVERT(NEW.id_region, CHAR), NEW.id_change_set - WHERE NOT OLD.id_region <=> NEW.id_region - UNION - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; -END // -DELIMITER ; - -INSERT INTO Shop_Product_Delivery_Region_Link ( - id_product, id_region -) -VALUES - (1, 1) -; - -SELECT * FROM Shop_Product_Delivery_Region_Link; -SELECT * FROM Shop_Product_Delivery_Region_Link_Audit; diff --git a/static/MySQL/deprecated/108_tbl_Shop_Recurrence_Interval.sql b/static/MySQL/deprecated/108_tbl_Shop_Recurrence_Interval.sql deleted file mode 100644 index d76bcc6a..00000000 --- a/static/MySQL/deprecated/108_tbl_Shop_Recurrence_Interval.sql +++ /dev/null @@ -1,20 +0,0 @@ - --- Recurrence Interval - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Interval_Recurrence'; - -CREATE TABLE IF NOT EXISTS Shop_Interval_Recurrence ( - id_interval INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - code VARCHAR(50), - name VARCHAR(255), - name_plural VARCHAR(256), - active BIT NOT NULL DEFAULT 1, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Interval_Recurrence_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/MySQL/deprecated/109_tbl_Shop_Recurrence_Interval_Audit.sql b/static/MySQL/deprecated/109_tbl_Shop_Recurrence_Interval_Audit.sql deleted file mode 100644 index 54fdc973..00000000 --- a/static/MySQL/deprecated/109_tbl_Shop_Recurrence_Interval_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Recurrence Interval Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Interval_Recurrence_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Interval_Recurrence_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_interval INT NOT NULL, - CONSTRAINT FK_Shop_Interval_Recurrence_Audit_id_interval - FOREIGN KEY (id_interval) - REFERENCES Shop_Interval_Recurrence(id_interval) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(256), - value_new VARCHAR(256), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Interval_Recurrence_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/MySQL/deprecated/113.1_tbl_Shop_Product_Variation_Type_Link.sql b/static/MySQL/deprecated/113.1_tbl_Shop_Product_Variation_Type_Link.sql deleted file mode 100644 index e3f42c62..00000000 --- a/static/MySQL/deprecated/113.1_tbl_Shop_Product_Variation_Type_Link.sql +++ /dev/null @@ -1,28 +0,0 @@ - --- Product Variation Type Link - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Variation_Type_Link'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Variation_Type_Link ( - id_link INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_product INT NOT NULL, - CONSTRAINT FK_Shop_Product_Variation_Type_Link_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product) - ON UPDATE RESTRICT, - id_variation_type INT NOT NULL, - CONSTRAINT FK_Shop_Product_Variation_Type_Link_id_variation_type - FOREIGN KEY (id_variation_type) - REFERENCES Shop_Variation_Type(id_type) - ON UPDATE RESTRICT, - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Product_Variation_Type_Link_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/MySQL/deprecated/113.2_tbl_Shop_Product_Variation_Type_Link_Audit.sql b/static/MySQL/deprecated/113.2_tbl_Shop_Product_Variation_Type_Link_Audit.sql deleted file mode 100644 index d0f6b01c..00000000 --- a/static/MySQL/deprecated/113.2_tbl_Shop_Product_Variation_Type_Link_Audit.sql +++ /dev/null @@ -1,23 +0,0 @@ - --- Product Variation Type Link Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Variation_Type_Link_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Variation_Type_Link_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_link INT NOT NULL, - CONSTRAINT FK_Shop_Product_Variation_Type_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Product_Variation_Type_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Product_Variation_Type_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) - ON UPDATE RESTRICT -); diff --git a/static/MySQL/deprecated/116_tbl_Shop_Product_Variation_Link.sql b/static/MySQL/deprecated/116_tbl_Shop_Product_Variation_Link.sql deleted file mode 100644 index 3816bd9c..00000000 --- a/static/MySQL/deprecated/116_tbl_Shop_Product_Variation_Link.sql +++ /dev/null @@ -1,35 +0,0 @@ - --- Product Variation Link - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Variation_Link'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Variation_Link ( - id_link INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_product INT NOT NULL, - CONSTRAINT FK_Shop_Product_Variation_Link_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product) - ON UPDATE RESTRICT, - id_variation INT NOT NULL, - CONSTRAINT FK_Shop_Product_Variation_Link_id_variation - FOREIGN KEY (id_variation) - REFERENCES Shop_Variation(id_variation) - ON UPDATE RESTRICT, - /* - id_product_variation_type_link INT NOT NULL, - CONSTRAINT FK_Shop_Product_Variation_Link_id_product_variation_type_link - FOREIGN KEY (id_product_variation_type_link) - REFERENCES Shop_Product_Variation_Type_Link(id_link) - ON UPDATE RESTRICT, - */ - active BIT NOT NULL DEFAULT 1, - display_order INT NOT NULL, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Product_Variation_Link_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/MySQL/deprecated/117.0_tbl_Shop_Product_Variation_Link_Audit.sql b/static/MySQL/deprecated/117.0_tbl_Shop_Product_Variation_Link_Audit.sql deleted file mode 100644 index 55543919..00000000 --- a/static/MySQL/deprecated/117.0_tbl_Shop_Product_Variation_Link_Audit.sql +++ /dev/null @@ -1,23 +0,0 @@ - --- Product Variation Link Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Variation_Link_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Variation_Link_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_link INT NOT NULL, - CONSTRAINT FK_Shop_Product_Variation_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Product_Variation_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Product_Variation_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) - ON UPDATE RESTRICT -); diff --git a/static/MySQL/deprecated/128_tbl_Shop_Product_Delivery_Region_Link.sql b/static/MySQL/deprecated/128_tbl_Shop_Product_Delivery_Region_Link.sql deleted file mode 100644 index c4f7b6b8..00000000 --- a/static/MySQL/deprecated/128_tbl_Shop_Product_Delivery_Region_Link.sql +++ /dev/null @@ -1,32 +0,0 @@ - --- Product Delivery Option Link - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Delivery_Region_Link'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Delivery_Region_Link ( - id_link INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_product INT NOT NULL, - CONSTRAINT FK_Shop_Product_Delivery_Region_Link_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product) - ON UPDATE RESTRICT, - id_permutation INT, - CONSTRAINT FK_Shop_Product_Delivery_Region_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation) - ON UPDATE RESTRICT, - id_region INT NOT NULL, - CONSTRAINT FK_Shop_Product_Delivery_Region_Link_id_region - FOREIGN KEY (id_region) - REFERENCES Shop_Delivery_Region(id_region) - ON UPDATE RESTRICT, - active BIT NOT NULL DEFAULT 1, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_Product_Delivery_Region_Link_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/MySQL/deprecated/129_tbl_Shop_Product_Delivery_Region_Link_Audit.sql b/static/MySQL/deprecated/129_tbl_Shop_Product_Delivery_Region_Link_Audit.sql deleted file mode 100644 index 665671c3..00000000 --- a/static/MySQL/deprecated/129_tbl_Shop_Product_Delivery_Region_Link_Audit.sql +++ /dev/null @@ -1,23 +0,0 @@ - --- Product Delivery Region Link Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Delivery_Region_Link_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Delivery_Region_Link_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_link INT NOT NULL, - CONSTRAINT FK_Shop_Product_Delivery_Region_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Product_Delivery_Region_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_Product_Delivery_Region_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) - ON UPDATE RESTRICT -); \ No newline at end of file diff --git a/static/MySQL/deprecated/170_ish_tbl_ERP_Order.sql b/static/MySQL/deprecated/170_ish_tbl_ERP_Order.sql deleted file mode 100644 index 73960c87..00000000 --- a/static/MySQL/deprecated/170_ish_tbl_ERP_Order.sql +++ /dev/null @@ -1,19 +0,0 @@ - --- ERP Order - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'ERP_Order'; - -CREATE TABLE IF NOT EXISTS ERP_Order ( - id_order INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - code VARCHAR(50), - name VARCHAR(100), - extension VARCHAR(50), - created_on DATETIME, - created_by INT, - id_customer INT NOT NULL, - CONSTRAINT FK_ERP_Order_id_customer - FOREIGN KEY (id_customer) - REFERENCES ERP_Customer(id_customer) -); diff --git a/static/MySQL/deprecated/171_tbl_Shop_User_Order.sql b/static/MySQL/deprecated/171_tbl_Shop_User_Order.sql deleted file mode 100644 index bf3160b3..00000000 --- a/static/MySQL/deprecated/171_tbl_Shop_User_Order.sql +++ /dev/null @@ -1,39 +0,0 @@ - --- User Order - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Order'; - -CREATE TABLE IF NOT EXISTS Shop_User_Order ( - id_order INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_user INT NOT NULL, - CONSTRAINT FK_Shop_User_Order_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user) - ON UPDATE RESTRICT, - value_total FLOAT, - id_order_status INT NOT NULL, - CONSTRAINT FK_Shop_User_Order_id_order_status - FOREIGN KEY (id_order_status) - REFERENCES Shop_User_Order_Status(id_status), - id_checkout_session VARCHAR(200) NOT NULL, - id_currency INT NOT NULL, - CONSTRAINT FK_Shop_User_Order_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency) - ON UPDATE RESTRICT, - active BIT NOT NULL DEFAULT 1, - created_on DATETIME, - created_by INT, - id_change_set_user INT, - CONSTRAINT FK_Shop_User_Order_id_change_set_user - FOREIGN KEY (id_change_set_user) - REFERENCES Shop_User_Change_Set(id_change_set) - /* - id_change_set_product INT, - CONSTRAINT FK_Shop_User_Basket_id_change_set_product - FOREIGN KEY (id_change_set_product) - REFERENCES Shop_Product_Change_Set(id_change_set) - */ -); diff --git a/static/MySQL/deprecated/172_tbl_Shop_User_Order_Audit.sql b/static/MySQL/deprecated/172_tbl_Shop_User_Order_Audit.sql deleted file mode 100644 index 1b602f1a..00000000 --- a/static/MySQL/deprecated/172_tbl_Shop_User_Order_Audit.sql +++ /dev/null @@ -1,27 +0,0 @@ - --- User Order Audits - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Order_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_User_Order_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_order INT NOT NULL, - CONSTRAINT FK_Shop_User_Order_Audit_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_User_Order(id_order) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set_user INT, - CONSTRAINT FK_Shop_User_Order_Audit_id_change_set_user - FOREIGN KEY (id_change_set_user) - REFERENCES Shop_User_Change_Set(id_change_set) - /* - id_change_set_product INT, - CONSTRAINT FK_Shop_User_Basket_Audit_id_change_set_product - FOREIGN KEY (id_change_set_product) - REFERENCES Shop_Product_Change_Set(id_change_set) - */ -); diff --git a/static/MySQL/deprecated/173_tbl_Shop_User_Order_Product_Link.sql b/static/MySQL/deprecated/173_tbl_Shop_User_Order_Product_Link.sql deleted file mode 100644 index 9e467382..00000000 --- a/static/MySQL/deprecated/173_tbl_Shop_User_Order_Product_Link.sql +++ /dev/null @@ -1,33 +0,0 @@ - --- User Order Product link - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Order_Product_Link'; - -CREATE TABLE IF NOT EXISTS Shop_User_Order_Product_Link ( - id_link INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_order INT NOT NULL, - CONSTRAINT FK_Shop_User_Order_Product_Link_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_User_Order(id_order) - ON UPDATE RESTRICT, - id_product INT NOT NULL, - CONSTRAINT FK_Shop_User_Order_Product_Link_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product) - ON UPDATE RESTRICT, - id_permutation INT NULL, - CONSTRAINT FK_Shop_User_Order_Product_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation) - ON UPDATE RESTRICT, - quantity FLOAT NOT NULL, - active BIT NOT NULL DEFAULT 1, - created_on DATETIME, - created_by INT, - id_change_set INT, - CONSTRAINT FK_Shop_User_Order_Product_Link_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/MySQL/deprecated/174_tbl_Shop_User_Order_Product_Link_Audit.sql b/static/MySQL/deprecated/174_tbl_Shop_User_Order_Product_Link_Audit.sql deleted file mode 100644 index bd3c31f9..00000000 --- a/static/MySQL/deprecated/174_tbl_Shop_User_Order_Product_Link_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- User Order Product Link Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Order_Product_Link_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_User_Order_Product_Link_Audit ( - id_audit INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - id_link INT NOT NULL, - CONSTRAINT FK_Shop_User_Order_Product_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_User_Order_Product_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(500), - value_new VARCHAR(500), - id_change_set INT NOT NULL, - CONSTRAINT FK_Shop_User_Order_Product_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); diff --git a/static/MySQL/deprecated/308_tri_Shop_Recurrence_Interval.sql b/static/MySQL/deprecated/308_tri_Shop_Recurrence_Interval.sql deleted file mode 100644 index e0277d48..00000000 --- a/static/MySQL/deprecated/308_tri_Shop_Recurrence_Interval.sql +++ /dev/null @@ -1,56 +0,0 @@ - --- Shop Recurrence Interval - - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Interval_Recurrence; -DROP TRIGGER IF EXISTS before_update_Shop_Interval_Recurrence; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Interval_Recurrence -BEFORE INSERT ON Shop_Interval_Recurrence -FOR EACH ROW -BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Interval_Recurrence -BEFORE UPDATE ON Shop_Interval_Recurrence -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Interval_Recurrence_Audit ( - id_interval, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_interval, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_interval, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed name_plural - SELECT NEW.id_interval, 'name_plural', OLD.name_plural, NEW.name_plural, NEW.id_change_set - WHERE NOT OLD.name_plural <=> NEW.name_plural - UNION - -- Changed name - SELECT NEW.id_interval, 'active', OLD.active, NEW.active, NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - ; -END // -DELIMITER ; \ No newline at end of file diff --git a/static/MySQL/deprecated/313.1_tri_Shop_Product_Variation_Type_Link.sql b/static/MySQL/deprecated/313.1_tri_Shop_Product_Variation_Type_Link.sql deleted file mode 100644 index f2ed43e7..00000000 --- a/static/MySQL/deprecated/313.1_tri_Shop_Product_Variation_Type_Link.sql +++ /dev/null @@ -1,61 +0,0 @@ - --- Shop Product Variation Link - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Product_Variation_Type_Link; -DROP TRIGGER IF EXISTS before_update_Shop_Product_Variation_Type_Link; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Product_Variation_Type_Link -BEFORE INSERT ON Shop_Product_Variation_Type_Link -FOR EACH ROW -BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Product_Variation_Type_Link -BEFORE UPDATE ON Shop_Product_Variation_Type_Link -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Product_Variation_Type_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_product - SELECT NEW.id_link, 'id_product', OLD.id_product, NEW.id_product, NEW.id_change_set - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed id_variation - SELECT NEW.id_link, 'id_variation', OLD.id_variation, NEW.id_variation, NEW.id_change_set - WHERE NOT OLD.id_variation <=> NEW.id_variation - UNION - */ - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_link, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; -END // -DELIMITER ; \ No newline at end of file diff --git a/static/MySQL/deprecated/316_tri_Shop_Product_Variation_Link.sql b/static/MySQL/deprecated/316_tri_Shop_Product_Variation_Link.sql deleted file mode 100644 index ad37c160..00000000 --- a/static/MySQL/deprecated/316_tri_Shop_Product_Variation_Link.sql +++ /dev/null @@ -1,61 +0,0 @@ - --- Shop Product Variation Link - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Product_Variation_Link; -DROP TRIGGER IF EXISTS before_update_Shop_Product_Variation_Link; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Product_Variation_Link -BEFORE INSERT ON Shop_Product_Variation_Link -FOR EACH ROW -BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Product_Variation_Link -BEFORE UPDATE ON Shop_Product_Variation_Link -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Product_Variation_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_product - SELECT NEW.id_link, 'id_product', OLD.id_product, NEW.id_product, NEW.id_change_set - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed id_variation - SELECT NEW.id_link, 'id_variation', OLD.id_variation, NEW.id_variation, NEW.id_change_set - WHERE NOT OLD.id_variation <=> NEW.id_variation - UNION - */ - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_link, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; -END // -DELIMITER ; \ No newline at end of file diff --git a/static/MySQL/deprecated/322_tri_Shop_Price.sql b/static/MySQL/deprecated/322_tri_Shop_Price.sql deleted file mode 100644 index c5b57f50..00000000 --- a/static/MySQL/deprecated/322_tri_Shop_Price.sql +++ /dev/null @@ -1,93 +0,0 @@ - --- Shop Product Currency Region Link - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Product_Currency_Region_Link; -DROP TRIGGER IF EXISTS before_update_Shop_Product_Currency_Region_Link; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Product_Currency_Region_Link -BEFORE INSERT ON Shop_Product_Currency_Region_Link -FOR EACH ROW -BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; - /* - SET NEW.price_local = ( - SELECT PP.price_GBP_full * C.factor_from_GBP - FROM Shop_Product_Permutation PP - INNER JOIN Shop_Product P ON PP.id_product = P.id_product - INNER JOIN Shop_Currency C ON NEW.id_currency = C.id_currency - WHERE NEW.id_product = P.id_product - LIMIT 1 - ); - */ -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Product_Currency_Region_Link -BEFORE UPDATE ON Shop_Product_Currency_Region_Link -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - /* - SET NEW.price_local = ( - SELECT P.price_GBP_full * C.factor_from_GBP - FROM Shop_Product P - INNER JOIN Shop_Currency C ON NEW.id_currency = C.id_currency - WHERE NEW.id_product = P.id_product - LIMIT 1 - ); - */ - - INSERT INTO Shop_Product_Currency_Region_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_product - SELECT NEW.id_link, 'id_product', CONVERT(OLD.id_product, CHAR), CONVERT(NEW.id_product, CHAR), NEW.id_change_set - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed id_currency - SELECT NEW.id_link, 'id_currency', CONVERT(OLD.id_currency, CHAR), CONVERT(NEW.id_currency, CHAR), NEW.id_change_set - WHERE NOT OLD.id_currency <=> NEW.id_currency - UNION - -- Changed price_local - SELECT NEW.id_link, 'price_local', OLD.price_local, NEW.price_local, NEW.id_change_set - WHERE NOT OLD.price_local <=> NEW.price_local - UNION - */ - -- Changed price_local_VAT_incl - SELECT NEW.id_link, 'price_local_VAT_incl', OLD.price_local_VAT_incl, NEW.price_local_VAT_incl, NEW.id_change_set - WHERE NOT OLD.price_local_VAT_incl <=> NEW.price_local_VAT_incl - UNION - -- Changed price_local_VAT_excl - SELECT NEW.id_link, 'price_local_VAT_excl', OLD.price_local_VAT_excl, NEW.price_local_VAT_excl, NEW.id_change_set - WHERE NOT OLD.price_local_VAT_excl <=> NEW.price_local_VAT_excl - UNION - -- Changed id_stripe_price - SELECT NEW.id_link, 'id_stripe_price', OLD.id_stripe_price, NEW.id_stripe_price, NEW.id_change_set - WHERE NOT OLD.id_stripe_price <=> NEW.id_stripe_price - UNION - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; -END // -DELIMITER ; diff --git a/static/MySQL/deprecated/328_tri_Shop_Product_Delivery_Region_Link.sql b/static/MySQL/deprecated/328_tri_Shop_Product_Delivery_Region_Link.sql deleted file mode 100644 index edfe357b..00000000 --- a/static/MySQL/deprecated/328_tri_Shop_Product_Delivery_Region_Link.sql +++ /dev/null @@ -1,57 +0,0 @@ - --- Shop Product Delivery Region Link - - - -DROP TRIGGER IF EXISTS before_insert_Shop_Product_Delivery_Region_Link; -DROP TRIGGER IF EXISTS before_update_Shop_Product_Delivery_Region_Link; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_Product_Delivery_Region_Link -BEFORE INSERT ON Shop_Product_Delivery_Region_Link -FOR EACH ROW -BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_Product_Delivery_Region_Link -BEFORE UPDATE ON Shop_Product_Delivery_Region_Link -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Product_Delivery_Region_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_product - SELECT NEW.id_link, 'id_product', CONVERT(OLD.id_product, CHAR), CONVERT(NEW.id_product, CHAR), NEW.id_change_set - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed id_region - SELECT NEW.id_link, 'id_region', CONVERT(OLD.id_region, CHAR), CONVERT(NEW.id_region, CHAR), NEW.id_change_set - WHERE NOT OLD.id_region <=> NEW.id_region - UNION - */ - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; -END // -DELIMITER ; \ No newline at end of file diff --git a/static/MySQL/deprecated/371_tri_Shop_User_Order.sql b/static/MySQL/deprecated/371_tri_Shop_User_Order.sql deleted file mode 100644 index ff46d095..00000000 --- a/static/MySQL/deprecated/371_tri_Shop_User_Order.sql +++ /dev/null @@ -1,67 +0,0 @@ - --- Shop Product Variation Link - - - -DROP TRIGGER IF EXISTS before_insert_Shop_User_Order; -DROP TRIGGER IF EXISTS before_update_Shop_User_Order; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_User_Order -BEFORE INSERT ON Shop_User_Order -FOR EACH ROW -BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_User_Order -BEFORE UPDATE ON Shop_User_Order -FOR EACH ROW -BEGIN - IF OLD.id_change_set_user <=> NEW.id_change_set_user THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - IF NOT (NEW.id_checkout_session <=> OLD.id_checkout_session) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Checkout session ID must not change.'; - END IF; - - INSERT INTO Shop_User_Order_Audit ( - id_order, - name_field, - value_prev, - value_new, - id_change_set_user - ) - -- Changed id_user - SELECT NEW.id_order, 'id_user', OLD.id_user, NEW.id_user, NEW.id_change_set_user - WHERE NOT OLD.id_user <=> NEW.id_user - UNION - -- Changed value_total - SELECT NEW.id_order, 'value_total', CONVERT(OLD.value_total, CHAR), CONVERT(NEW.value_total, CHAR), NEW.id_change_set_user - WHERE NOT (OLD.value_total <=> NEW.value_total) - UNION - -- Changed id_order_status - SELECT NEW.id_order, 'id_order_status', CONVERT(OLD.id_order_status, CHAR), CONVERT(NEW.id_order_status, CHAR), NEW.id_change_set_user - WHERE NOT (OLD.id_order_status <=> NEW.id_order_status) - UNION - -- Changed id_checkout_session - SELECT NEW.id_order, 'id_checkout_session', OLD.id_checkout_session, NEW.id_checkout_session, NEW.id_change_set_user - WHERE NOT (OLD.id_checkout_session <=> NEW.id_checkout_session) - UNION - -- Changed active - SELECT NEW.id_order, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set_user - WHERE NOT (OLD.active <=> NEW.active) - ; -END // -DELIMITER ; \ No newline at end of file diff --git a/static/MySQL/deprecated/373_tri_Shop_User_Order_Product_Link.sql b/static/MySQL/deprecated/373_tri_Shop_User_Order_Product_Link.sql deleted file mode 100644 index 6c734f2b..00000000 --- a/static/MySQL/deprecated/373_tri_Shop_User_Order_Product_Link.sql +++ /dev/null @@ -1,55 +0,0 @@ - --- Shop User Order Product Link - - - -DROP TRIGGER IF EXISTS before_insert_Shop_User_Order_Product_Link; -DROP TRIGGER IF EXISTS before_update_Shop_User_Order_Product_Link; - - -DELIMITER // -CREATE TRIGGER before_insert_Shop_User_Order_Product_Link -BEFORE INSERT ON Shop_User_Order_Product_Link -FOR EACH ROW -BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END // -DELIMITER ; - - -DELIMITER // -CREATE TRIGGER before_update_Shop_User_Order_Product_Link -BEFORE UPDATE ON Shop_User_Order_Product_Link -FOR EACH ROW -BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_User_Order_Product_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_product - SELECT NEW.id_link, 'active', CONVERT(OLD.id_product, CHAR), CONVERT(NEW.id_product, CHAR), NEW.id_change_set - WHERE NOT (OLD.id_product <=> NEW.id_product) - UNION - -- Changed quantity - SELECT NEW.id_link, 'quantity', CONVERT(OLD.quantity, CHAR), CONVERT(NEW.quantity, CHAR), NEW.id_change_set - WHERE NOT (OLD.quantity <=> NEW.quantity) - UNION - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; -END // -DELIMITER ; \ No newline at end of file diff --git a/static/MySQL/deprecated/7000_p_shop_get_many_role_permission.sql b/static/MySQL/deprecated/7000_p_shop_get_many_role_permission.sql deleted file mode 100644 index 0352273e..00000000 --- a/static/MySQL/deprecated/7000_p_shop_get_many_role_permission.sql +++ /dev/null @@ -1,131 +0,0 @@ - - - -/* -THIS STRUCTURE DOES NOT WORK WITH MYSQL ?? - -CALL p_shop_get_many_role_permission ( - '', - 0, - '', - 0, - 0, - 1, - '', - 0, - 0, - 1 -) - -*/ - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_get_many_role_permission; -/* -DROP TABLE IF EXISTS tmp_Shop_Image; -DROP TABLE IF EXISTS tmp_Shop_Product; -DROP TABLE IF EXISTS tmp_Shop_Variation; -DROP TABLE IF EXISTS tmp_Shop_Product_Category; -*/ - -DELIMITER // -CREATE PROCEDURE p_shop_get_many_role_permission ( - a_ids_role NVARCHAR(500), - a_get_inactive_roles BIT -) -BEGIN - -- Variable declaration - DECLARE v_has_filter_role BIT; - DECLARE v_priority_view INT; - DECLARE v_priority_edit INT; - DECLARE v_priority_admin INT; - /* - DECLARE v_ids_product_permission VARCHAR(500); - DECLARE v_now DATETIME; - */ - - -- Parse arguments + get default values - IF a_ids_role IS NULL THEN - SET a_ids_role = ''; - ELSE - SET a_ids_role = TRIM(a_ids_role); - END IF; - IF a_get_inactive_roles IS NULL THEN - SET a_get_inactive_roles = 0; - END IF; - - - -- Temporary tables - CREATE TABLE tmp_Permission ( - id_role INT NOT NULL, - CONSTRAINT FK_tmp_User_Permission_id_role - FOREIGN KEY (id_role) - REFERENCES Shop_Role(id_role), - id_permission INT, - CONSTRAINT FK_tmp_User_Permission_id_permission - FOREIGN KEY (id_permission) - REFERENCES Shop_Permission(id_permission), - id_access_level INT, - CONSTRAINT FK_tmp_User_Permission_id_access_level - FOREIGN KEY (id_user) - REFERENCES Shop_Access_Level(id_user), - can_view BIT, - can_edit BIT, - can_admin BIT - ); - - - -- Parse filters - SET a_ids_role = REPLACE(a_ids_role, ',', '|'); - SET v_has_filter_role = CASE WHEN a_ids_role = '' THEN 0 ELSE 1 END; - - INSERT INTO tmp_User_Permission ( - id_role, - id_permission, - id_access_level, - can_view, - can_edit, - can_admin - ) - SELECT U.id_user, - U.is_super_user, - U.is_super_user, - U.is_super_user, - U.is_super_user - FROM Shop_Role R - INNER JOIN Shop_Role_Permission_Link RPL - ON R.id_role = RPL.id_role - AND RPL.active - INNER JOIN Shop_Permission PERM - ON RPL.id_permission = PERM.id_permission - AND PERM.active - INNER JOIN Shop_Permission_Group PG - ON PERM.id_permission_group = PG.id_group - AND PG.active - LEFT JOIN Shop_Access_Level AL - ON RPL.id_access_level = AL.id_access_level - AND AL.active - WHERE - R.id_role LIKE CONCAT('%', a_ids_role, '%') - AND ( - PERM.required_access_level = 0 - OR AL.priority >= PERM.required_access_level - ) - ; - - UPDATE tmp_User_Permission t_UP - INNER JOIN Shop_Access_Level AL - ON AL.code = 'ADMIN' - SET t_UP.id_access_level = AL.id_access_level - WHERE t_UP.is_super_user - ; - - - -- Clean up - DROP TABLE IF EXISTS tmp_Shop_Product_Category; - DROP TABLE IF EXISTS tmp_Shop_Product; - DROP TABLE IF EXISTS tmp_Shop_Image; -END // -DELIMITER ; - diff --git a/static/MySQL/deprecated/7000_p_shop_get_many_user_order.sql b/static/MySQL/deprecated/7000_p_shop_get_many_user_order.sql deleted file mode 100644 index 3bae9227..00000000 --- a/static/MySQL/deprecated/7000_p_shop_get_many_user_order.sql +++ /dev/null @@ -1,285 +0,0 @@ - - - -/* - -CALL p_shop_get_many_user_order ( - '', - '', - 1, - '' -) - -*/ - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_get_many_user_order; - - -DELIMITER // -CREATE PROCEDURE p_shop_get_many_user_order ( - IN a_id_user INT, - IN a_ids_order VARCHAR(4000), - IN a_n_order_max INT, - IN a_id_checkout_session VARCHAR(200) -) -BEGIN - -- Argument redeclaration - -- Variable declaration - DECLARE v_has_filter_user BIT; - DECLARE v_has_filter_order BIT; - DECLARE v_has_filter_session BIT; - DECLARE v_code_error_data VARCHAR(200); - DECLARE v_code_error_permission VARCHAR(200); - DECLARE v_guid BINARY(36); - - SET v_code_error_data := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 1); - SET v_code_error_permission := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 2); - SET v_guid = UUID(); - - -- Argument validation + default values - IF a_id_user IS NULL THEN - SET a_id_user = ''; - ELSE - SET a_id_user = TRIM(a_id_user); - END IF; - IF a_ids_order IS NULL THEN - SET a_ids_order = ''; - ELSE - SET a_ids_order = TRIM(a_ids_order); - END IF; - IF a_n_order_max IS NULL THEN - SET a_n_order_max = 1; - END IF; - IF a_id_checkout_session IS NULL THEN - SET a_id_checkout_session = ''; - ELSE - SET a_id_checkout_session = TRIM(a_id_checkout_session); - END IF; - - - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Shop_User; - DROP TABLE IF EXISTS tmp_Shop_Order; - - CREATE TABLE tmp_Shop_User( - id_user INT NOT NULL PRIMARY KEY, - CONSTRAINT FK_tmp_Shop_User_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user), - active BIT NOT NULL - ); - - CREATE TABLE tmp_Shop_Order ( - id_order INT NOT NULL PRIMARY KEY, - CONSTRAINT FK_tmp_Shop_Order_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_User_Order(id_order), - active BIT NOT NULL - ); - - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - guid BINARY(36) NOT NULL, - -- id_type INT NOT NULL, - -- CONSTRAINT FK_tmp_Msg_Error_id_type FOREIGN KEY (id_type) - -- REFERENCES Shop_Msg_Error_Type (id_type), - code VARCHAR(50), - msg VARCHAR(4000) NOT NULL - ); - - - -- Parse filters - SET v_has_filter_user = CASE WHEN a_id_user = '' THEN 0 ELSE 1 END; - SET a_ids_order = REPLACE(a_ids_order, '|', ','); - SET v_has_filter_order = CASE WHEN a_ids_order = '' THEN 0 ELSE 1 END; - SET v_has_filter_session = CASE WHEN a_id_checkout_session = '' THEN 0 ELSE 1 END; - - -- User - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF v_has_filter_user THEN - INSERT INTO tmp_Shop_User ( - id_user, - active - ) - SELECT id_user, - active - FROM Shop_User - WHERE id_user LIKE CONCAT('%', a_id_user, '%') - AND active - LIMIT 1 - ; - - SET v_has_filter_user = EXISTS (SELECT id_user FROM tmp_Shop_User LIMIT 1); - SET a_id_user := (SELECT id_user FROM tmp_Shop_User LIMIT 1); - END IF; - END IF; - IF NOT v_has_filter_user THEN - INSERT INTO tmp_Msg_Error ( - guid, - code, - msg - ) - VALUES ( - v_guid, - v_code_error_data, - 'User ID not valid.' - ) - ; - END IF; - - -- Permissions - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - CALL p_shop_user_eval ( - v_guid, -- a_guid - a_id_user, -- a_id_user - 0, -- a_get_inactive_users - CONVERT((SELECT id_permission FROM Shop_Permission WHERE 'STORE_USER' = code), CHAR), -- a_ids_permission - (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW' AND active), -- a_ids_access_level - '', -- a_ids_product - '' -- a_ids_permutation - ); - - IF NOT (SELECT can_edit FROM Shop_User_Eval_Temp WHERE guid = v_guid) THEN - INSERT INTO tmp_Msg_Error ( - guid, - code, - msg - ) - VALUES ( - v_guid, - v_code_error_permission, - 'User ID does not have permission to access orders.' - ) - ; - END IF; - - DELETE FROM Shop_User_Eval_Temp - WHERE guid = v_guid - ; - END IF; - - -- Invalid Orders - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - -- Invalid Order IDs - IF EXISTS (SELECT * FROM Shop_User_Order WHERE NOT (id_user = a_id_user) AND v_has_filter_order AND FIND_IN_SET(id_order, a_ids_order) > 0) THEN -- id_order LIKE CONCAT('%', a_ids_order, '%') LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - guid, - code, - msg - ) - VALUES ( - v_guid, - v_code_error_data, - CONCAT('You do not have access to the following order IDs: ', (SELECT GROUP_CONCAT(id_order SEPARATOR ', ') FROM Shop_User_Order WHERE NOT (id_user = a_id_user) AND FIND_IN_SET(id_order, a_ids_order) > 0)) -- id_order LIKE CONCAT('%', a_ids_order, '%'))) -- AND v_has_filter_order -- filtered by parent condition - ) - ; - END IF; - -- Invalid Checkout Session IDs - IF EXISTS (SELECT * FROM Shop_User_Order WHERE NOT (id_user = a_id_user) AND v_has_filter_session AND id_checkout_session = a_id_checkout_session) THEN - INSERT INTO tmp_Msg_Error ( - guid, - code, - msg - ) - VALUES ( - v_guid, - v_code_error_data, - CONCAT('You do not have access to the following checkout session IDs: ', (SELECT GROUP_CONCAT(id_order SEPARATOR ', ') FROM Shop_User_Order WHERE NOT (id_user = a_id_user) AND id_checkout_session = a_id_checkout_session)) -- AND v_has_filter_order -- filtered by parent condition - ) - ; - END IF; - END IF; - - -- Valid Orders - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - - INSERT INTO tmp_Shop_Order ( - id_order, - active - ) - SELECT UO.id_order, - UO.active - FROM Shop_User_Order UO - INNER JOIN tmp_Shop_User t_U - ON UO.id_user = t_U.id_user - AND t_U.active - WHERE ((NOT v_has_filter_order OR FIND_IN_SET(UO.id_order, a_ids_order) > 0) -- UO.id_order LIKE CONCAT('%', a_ids_order, '%')) - OR (NOT v_has_filter_session OR UO.id_checkout_session = a_id_checkout_session)) - AND UO.active - ; - END IF; - - - - -- Returns - /* - SELECT * - FROM tmp_Shop_User - ; - */ - - SELECT t_O.id_order, - UOPL.id_product, - UOPL.id_permutation, - UOPL.quantity - FROM tmp_Shop_Order t_O - INNER JOIN Shop_User_Order UO - ON t_O.id_order = UO.id_order - INNER JOIN Shop_User_Order_Product_Link UOPL - ON UO.id_order = UOPL.id_order - WHERE t_O.active - ; - - - -- Errors - SELECT * - FROM tmp_Msg_Error - WHERE guid = v_guid - ; - - - /* - -- Return arguments for test - SELECT - a_id_user, - a_ids_order, - a_n_order_max, - a_id_checkout_session - ; - */ - - -- Clean up - DROP TABLE IF EXISTS tmp_Shop_User; - DROP TABLE IF EXISTS tmp_Shop_Order; -END // -DELIMITER ; - - -/* - -CALL p_shop_get_many_user_order ( - 'auth0|6582b95c895d09a70ba10fef', - '1', - 0, - '' -); - -CALL p_shop_get_many_user_order ( - '', - '1', - 0, - '' -); - -insert into shop_product_change_set (comment) - values ('set product not subscription - test bool output to python'); - update shop_product - set is_subscription = 0, - id_change_set = (select id_change_set from shop_product_change_set order by id_change_set desc limit 1) - where id_product = 1 -select * from shop_User; -select * from shop_User_oRDER; -*/ diff --git a/static/MySQL/deprecated/706_p_shop_get_product.sql b/static/MySQL/deprecated/706_p_shop_get_product.sql deleted file mode 100644 index 968a6080..00000000 --- a/static/MySQL/deprecated/706_p_shop_get_product.sql +++ /dev/null @@ -1,657 +0,0 @@ - - - -/* - -CALL p_shop_get_product ( - '', -- a_id_user - 1, -- a_id_product - '', -- a_ids_image - 0, -- a_get_first_image_only - 1 -- a_get_all_images -) - -*/ - - --- Clear previous proc -DROP PROCEDURE IF EXISTS p_shop_get_product; - - -DELIMITER // -CREATE PROCEDURE p_shop_get_product ( - IN a_id_user INT, - IN a_id_product INT, - IN a_ids_permutation VARCHAR(4000), - IN a_ids_image VARCHAR(500), - IN a_get_first_image_only BIT, - IN a_get_all_images BIT -) -BEGIN - -- Argument redeclaration - -- Variable declaration - DECLARE v_has_filter_product BIT; - DECLARE v_id_product_search VARCHAR(10); - DECLARE v_has_filter_permutation BIT; - DECLARE v_has_product_permutations BIT; - DECLARE v_guid BINARY(36); - -- DECLARE v_id_user VARCHAR(100); - DECLARE v_id_permission_product INT; - DECLARE v_ids_product_permission VARCHAR(500); - DECLARE v_id_access_level_view INT; - DECLARE v_has_filter_image BIT; - DECLARE v_now DATETIME; - DECLARE v_id_minimum INT; - DECLARE v_code_error_data VARCHAR(50); - - - SET v_guid := UUID(); - SET v_code_error_data := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 1); - SET v_id_access_level_view := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW'); - - -- Argument validation + default values - IF a_id_user IS NULL THEN - SET a_id_user = ''; - ELSE - SET a_id_user = TRIM(a_id_user); - END IF; - IF a_ids_image IS NULL THEN - SET a_ids_image = ''; - ELSE - SET a_ids_image = TRIM(a_ids_image); - END IF; - - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Shop_Image; - DROP TABLE IF EXISTS tmp_Shop_Variation; - DROP TABLE IF EXISTS tmp_Shop_Product; - - CREATE TABLE tmp_Shop_Product ( - id_product INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - id_permutation INT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - id_category INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_category - FOREIGN KEY (id_category) - REFERENCES Shop_Product_Category(id_category), - display_order INT, - can_view BIT, - can_edit BIT, - can_admin BIT - ); - - /* - CREATE TEMPORARY TABLE tmp_Shop_Variation ( - id_variation INT NOT NULL, - id_product INT NOT NULL, - display_order INT NOT NULL - ); - */ - - CREATE TABLE tmp_Shop_Image ( - id_product INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Image_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - id_permutation INT NULL, - CONSTRAINT FK_tmp_Shop_Image_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - id_image INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Image_id_image - FOREIGN KEY (id_image) - REFERENCES Shop_Image(id_image), - display_order INT NOT NULL - ); - - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - guid BINARY(36) NOT NULL, - -- code VARCHAR(50) NOT NULL, - -- CONSTRAINT chk_tmp_Msg_Error_code CHECK (code IN (SELECT code FROM Shop_Msg_Error_Type)), - id_type INT NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type(id_type), - msg VARCHAR(4000) NOT NULL - ); - - - -- Parse filters - -- SET v_id_product_search = CONCAT('%', CAST(a_id_product AS CHAR), '%'); - -- select v_id_product_search; - SET v_has_filter_image = ''; - - -- Products - INSERT INTO tmp_Shop_Product ( - id_product, id_category, display_order - ) - SELECT P.id_product, P.id_category, P.display_order - FROM Shop_Product P - -- WHERE P.id_product LIKE v_id_product_search - WHERE P.id_product = a_id_product - AND NOT P.has_variations - AND P.active - ; - -- Product Permutations - INSERT INTO tmp_Shop_Product ( - id_product, id_category, id_permutation, display_order - ) - SELECT PP.id_product, P.id_category, PP.id_permutation, PP.display_order - FROM Shop_Product_Permutation PP - INNER JOIN Shop_Product P - ON PP.id_product = P.id_product - AND P.has_variations - AND P.active - -- WHERE PP.id_product LIKE v_id_product_search - WHERE PP.id_product = a_id_product - AND PP.active - ; - - SET a_id_product := (SELECT id_product FROM tmp_Shop_Product LIMIT 1); - -- SET v_has_filter_product = NOT ISNULL(a_id_product); - SET v_has_product_permutations = EXISTS (SELECT id_permutation FROM tmp_Shop_Product WHERE NOT ISNULL(id_permutation)); - - IF ISNULL(a_id_product) THEN -- NOT v_has_filter_product - INSERT INTO tmp_Msg_Error ( - guid, - code, - msg - ) - VALUES ( - v_guid, - v_code_error_data, - 'Valid product ID not provided.' - ) - ; - END IF; - - -- Permutations - IF v_has_filter_permutation THEN - DELETE FROM tmp_Shop_Product - WHERE FIND_IN_SET(id_permutation, a_ids_permutation) = 0 - ; - - IF NOT EXISTS (SELECT * FROM tmp_Shop_Product) THEN - INSERT INTO tmp_Msg_Error ( - guid, - code, - msg - ) - VALUES ( - v_guid, - v_code_error_data, - 'Permutation IDs not associated with product ID.' - ) - ; - END IF; - END IF; - - - /* - -- Variations - INSERT INTO tmp_Shop_Variation ( - id_variation, id_product - ) - SELECT P.id_variation, P.id_product - FROM Shop_Variation V - INNER JOIN tmp_Shop_Product t_P - ON V.id_product = t_P.id_product - WHERE V.active - ; - */ - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid) THEN - -- Product Images - INSERT INTO tmp_Shop_Image ( - id_product, id_image, display_order - ) - SELECT t_P.id_product, I.id_image, I.display_order - FROM Shop_Image I - INNER JOIN tmp_Shop_Product t_P - ON I.id_product = t_P.id_product - AND ISNULL(I.id_permutation) - INNER JOIN Shop_Product P - ON t_P.id_product = P.id_product - AND NOT P.has_variations - WHERE I.active - ; - -- Product Permutation Images - INSERT INTO tmp_Shop_Image ( - id_product, - id_permutation, - id_image, - display_order - ) - SELECT t_P.id_product, - t_P.id_permutation, - I.id_image, - ROW_NUMBER() OVER W AS display_order - FROM Shop_Image I - INNER JOIN Shop_Product_Permutation PP - ON I.id_permutation = PP.id_permutation - INNER JOIN Shop_Product P - ON PP.id_product = P.id_product - AND P.has_variations - INNER JOIN tmp_Shop_Product t_P - ON P.id_product = t_P.id_product - AND PP.id_permutation = t_P.id_permutation - WHERE I.active - WINDOW W AS (ORDER BY P.display_order, PP.display_order, I.display_order) - ; - END IF; - - - -- Permissions - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid) AND EXISTS (SELECT * FROM tmp_Shop_Product LIMIT 1) THEN - -- SET v_id_user := (SELECT id_user FROM Shop_User WHERE name = CURRENT_USER()); - SET v_id_permission_product := (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_PRODUCT' LIMIT 1); - SET v_ids_product_permission := (SELECT GROUP_CONCAT(DISTINCT id_product SEPARATOR '|') FROM tmp_Shop_Product); - - SELECT v_guid, a_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_product_permission; - - CALL p_shop_user_eval(v_guid, a_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_product_permission); - - select * from shop_user_eval_temp; - - UPDATE tmp_Shop_Product t_P - INNER JOIN Shop_User_Eval_Temp UE_T - ON t_P.id_product = UE_T.id_product - AND UE_T.GUID = v_guid - SET t_P.can_view = UE_T.can_view, - t_P.can_edit = UE_T.can_edit, - t_P.can_admin = UE_T.can_admin; - - DELETE FROM tmp_Shop_Product - WHERE FIND_IN_SET(id_product, (SELECT GROUP_CONCAT(id_product SEPARATOR ',') FROM Shop_User_Eval_Temp)) = 0 -- id_product NOT LIKE CONCAT('%', (SELECT GROUP_CONCAT(id_product SEPARATOR '|') FROM Shop_User_Eval_Temp), '%'); - ; - - -- CALL p_shop_user_eval_clear_temp(v_guid); - -- DROP TABLE IF EXISTS Shop_User_Eval_Temp; - DELETE FROM Shop_User_Eval_Temp - WHERE GUID = v_guid; - END IF; - - - -- Returns - SET v_now := NOW(); - - -- Category - SELECT DISTINCT t_P.id_category, - C.name, - C.description, - C.display_order - FROM tmp_Shop_Product t_P - INNER JOIN Shop_Product_Category C - ON t_P.id_category = C.id_category - ORDER BY C.display_order - ; - - IF NOT v_has_product_permutations THEN - -- Products - SELECT t_P.id_product, - NULL AS id_permutation, - P.name, - P.description, - P.price_GBP_full, - P.has_variations, - P.id_category, - P.latency_manuf, - P.quantity_min, - P.quantity_max, - P.quantity_step, - P.quantity_stock, - P.id_stripe_product, - P.is_subscription, - RI.name AS name_interval_recurrence, - RI.name_plural AS name_plural_interval_recurrence, - P.count_interval_recurrence - FROM tmp_Shop_Product t_P - INNER JOIN Shop_Product P - ON t_P.id_product = P.id_product - LEFT JOIN Shop_Interval_Recurrence RI - ON P.id_unit_measurement_interval_recurrence = RI.id_interval - WHERE ISNULL(t_P.id_permutation) - ORDER BY t_P.display_order - ; - ELSE - -- Permutations - SELECT t_P.id_product, - t_P.id_permutation, - P.name, - P.description, - P.price_GBP_full, - P.has_variations, - P.id_category, - P.latency_manuf, - P.quantity_min, - P.quantity_max, - P.quantity_step, - P.quantity_stock, - P.id_stripe_product, - P.is_subscription, - RI.name AS name_interval_recurrence, - RI.name_plural AS name_plural_interval_recurrence, - P.count_interval_recurrence - FROM tmp_Shop_Product t_P - INNER JOIN Shop_Product_Permutation PP - ON t_P.id_permutation = PP.id_permutation - AND PP.active - INNER JOIN Shop_Product P - ON PP.id_product = P.id_product - LEFT JOIN Shop_Interval_Recurrence RI - ON P.id_unit_measurement_interval_recurrence = RI.id_interval - WHERE NOT ISNULL(t_P.id_permutation) - ORDER BY t_P.display_order - ; - END IF; - - -- Variations - IF v_has_product_permutations THEN - SELECT PPVL.id_variation, - t_P.id_product, - t_P.id_category, - VT.code AS code_variation_type, - VT.name AS name_variation_type, - V.code AS code_variation, - V.name AS name_variation - FROM Shop_Product_Permutation_Variation_Link PPVL - INNER JOIN tmp_Shop_Product t_P - ON PPVL.id_permutation = t_P.id_permutation - INNER JOIN Shop_Variation V - ON PPVL.id_variation = V.id_variation - INNER JOIN Shop_Variation_Type VT - ON V.id_type = VT.id_type - WHERE V.active - AND VT.active - AND PPVL.active - ORDER BY VT.display_order, V.display_order - ; - ELSE - SELECT NULL AS id_variation, - NULL AS id_product, - NULL AS id_category, - NULL AS code_variation_type, - NULL AS name_variation_type, - NULL AS code_variation, - NULL AS name_variation - ; - END IF; - - IF v_has_product_permutations THEN - -- Permutation Variations - SELECT t_P.id_permutation, - t_P.id_product, - t_P.id_category, - id_variation - FROM Shop_Product_Permutation_Variation_Link PPVL - INNER JOIN tmp_Shop_Product t_P - ON t_P.id_permutation = PPVL.id_permutation - ; - ELSE - SELECT NULL AS id_permutation, - NULL AS id_product, - NULL AS id_category, - NULL AS id_variation - ; - END IF; - - -- Images - SELECT I.id_image, - t_P.id_product, - I.id_permutation, - t_P.id_category, - I.url - FROM tmp_Shop_Image t_I - INNER JOIN Shop_Image I - ON t_I.id_image = I.id_image - INNER JOIN tmp_Shop_Product t_P - ON a_id_product = t_P.id_product - AND I.id_permutation = t_P.id_permutation - -- WHERE I.active - ORDER BY I.display_order - ; - - -- Delivery Regions - IF v_has_product_permutations THEN - SELECT DR.id_region, - t_P.id_category, - t_P.id_product, - t_P.id_permutation, - DR.code, - DR.name - FROM Shop_Delivery_Region DR - INNER JOIN Shop_Product_Delivery_Region_Link PDRL - ON DR.id_region = PDRL.id_region - AND PDRL.active - INNER JOIN tmp_Shop_Product t_P - ON PDRL.id_permutation = t_P.id_permutation - WHERE DR.active - ORDER BY t_P.id_permutation, DR.display_order - ; - ELSE - SELECT PDRL.id_region, - t_P.id_category, - t_P.id_product, - t_P.id_permutation, - DR.code, - DR.name - FROM Shop_Delivery_Region DR - INNER JOIN Shop_Product_Delivery_Region_Link PDRL - ON DR.id_region = PDRL.id_region - AND PDRL.active - INNER JOIN tmp_Shop_Product t_P - ON PDRL.id_product = t_P.id_product - WHERE DR.active - ORDER BY DR.display_order - ; - END IF; - - -- Delivery options - IF v_has_product_permutations THEN - SELECT _DO.id_option, - _DO.id_product, - _DO.id_permutation, - t_P.id_category, - DOT.code, - DOT.name, - DOT.latency_delivery_min, - DOT.latency_delivery_max, - DOT.quantity_min, - DOT.quantity_max, - GROUP_CONCAT(DR.code SEPARATOR ',') AS codes_region, - GROUP_CONCAT(DR.name SEPARATOR ',') AS names_region, - _DO.price_GBP, - DOT.display_order - FROM Shop_Delivery_Option _DO - INNER JOIN Shop_Delivery_Option_Type DOT - ON _DO.id_delivery_type = DOT.id_type - AND DOT.active - INNER JOIN tmp_Shop_Product t_P - ON _DO.id_permutation = t_P.id_permutation - INNER JOIN Shop_Product_Delivery_Region_Link PDRL - ON t_P.id_product = PDRL.id_product - AND PDRL.active - INNER JOIN Shop_Delivery_Region DR - ON PDRL.id_region = DR.id_region - AND DR.active - WHERE _DO.active - AND a_id_product = _DO.id_product - GROUP BY t_P.id_product, PDRL.id_region, _DO.id_option, t_P.id_category - ORDER BY DOT.display_order - ; - ELSE - SELECT _DO.id_option, - _DO.id_product, - _DO.id_permutation, - t_P.id_category, - DOT.code, - DOT.name, - DOT.latency_delivery_min, - DOT.latency_delivery_max, - DOT.quantity_min, - DOT.quantity_max, - GROUP_CONCAT(DR.code SEPARATOR ',') AS codes_region, - GROUP_CONCAT(DR.name SEPARATOR ',') AS names_region, - _DO.price_GBP, - DOT.display_order - FROM Shop_Delivery_Option _DO - INNER JOIN Shop_Delivery_Option_Type DOT - ON _DO.id_delivery_type = DOT.id_type - AND DOT.active - INNER JOIN tmp_Shop_Product t_P - ON _DO.id_product = t_P.id_product - INNER JOIN Shop_Product_Delivery_Region_Link PDRL - ON t_P.id_product = PDRL.id_product - AND PDRL.active - INNER JOIN Shop_Delivery_Region DR - ON PDRL.id_region = DR.id_region - AND DR.active - WHERE _DO.active - AND a_id_product = _DO.id_product - GROUP BY t_P.id_product, PDRL.id_region, _DO.id_option, t_P.id_category - ORDER BY DOT.display_order - ; - END IF; - - IF v_has_product_permutations THEN - -- Discounts - SELECT D.id_discount, - t_P.id_category, - a_id_product, - D.id_permutation, - D.code, - D.name, - D.multiplier, - D.quantity_min, - D.quantity_max, - D.date_start, - D.date_end, - D.display_order - FROM Shop_Discount D - INNER JOIN tmp_Shop_Product t_P - ON D.id_permutation = t_P.id_permutation - WHERE D.active - ; - ELSE - -- Discounts - SELECT D.id_discount, - t_P.id_category, - D.id_product, - NULL AS id_permutation, - D.code, - D.name, - D.multiplier, - D.quantity_min, - D.quantity_max, - D.date_start, - D.date_end, - D.display_order - FROM Shop_Discount D - INNER JOIN tmp_Shop_Product t_P - ON D.id_product = t_P.id_product - WHERE D.active - AND a_id_product = D.id_product - ; - END IF; - - IF v_has_product_permutations THEN - -- Discount Delivery Regions - SELECT DDRL.id_discount, - DDRL.id_region, - t_P.id_category, - t_P.id_product, - t_P.id_permutation, - DR.code, - DR.name, - DR.display_order - FROM Shop_Discount D - INNER JOIN tmp_Shop_Product t_P - ON D.id_permutation = t_P.id_permutation - INNER JOIN Shop_Discount_Delivery_Region_Link DDRL - ON D.id_discount = DDRL.id_discount - AND DDRL.active - INNER JOIN Shop_Delivery_Region DR - ON DDRL.id_region = DR.id_region - AND DR.active - WHERE D.active - ; - ELSE - -- Discount Delivery Regions - SELECT DDRL.id_discount, - DDRL.id_region, - t_P.id_category, - t_P.id_product, - NULL AS id_permutation, - DR.code, - DR.name, - DR.display_order - FROM Shop_Discount D - INNER JOIN tmp_Shop_Product t_P - ON D.id_product = t_P.id_product - INNER JOIN Shop_Discount_Delivery_Region_Link DDRL - ON D.id_discount = DDRL.id_discount - AND DDRL.active - INNER JOIN Shop_Delivery_Region DR - ON DDRL.id_region = DR.id_region - AND DR.active - WHERE D.active - AND a_id_product = D.id_product - ; - END IF; - - -- Errors - SELECT * - FROM tmp_Msg_Error - WHERE guid = v_guid - ; - - /* - -- Return arguments for test - SELECT - a_ids_category, - a_get_inactive_categories, - a_ids_product, - a_get_inactive_products, - a_get_first_product_only, - a_get_all_products, - a_ids_image, - a_get_inactive_images, - a_get_first_image_only, - a_get_all_images - ; - */ - - -- Clean up - DROP TABLE IF EXISTS tmp_Shop_Image; - DROP TABLE IF EXISTS tmp_Shop_Variation; - DROP TABLE IF EXISTS tmp_Shop_Product; -END // -DELIMITER ; - - - - -CALL p_shop_get_product ( - '', -- a_id_user - 1 -- a_id_product -); - -/* -drop table tmp_msg_error; -select * from shop_image; -select * from shop_discount; - -insert into shop_product_change_set (comment) - values ('set product not subscription - test bool output to python'); - update shop_product - set is_subscription = 0, - id_change_set = (select id_change_set from shop_product_change_set order by id_change_set desc limit 1) - where id_product = 1 -*/ diff --git a/static/MySQL/deprecated/9020_edit_permissions.sql b/static/MySQL/deprecated/9020_edit_permissions.sql deleted file mode 100644 index bacf7ecc..00000000 --- a/static/MySQL/deprecated/9020_edit_permissions.sql +++ /dev/null @@ -1,83 +0,0 @@ -SELECT URL.id_link, - URL.id_user, - U.name AS name, - URL.id_role, - R.name AS role -FROM Shop_User_Role_Link URL -INNER JOIN Shop_User U - ON URL.id_user = U.id_user -INNER JOIN Shop_Role R - ON URL.id_role = R.id_role -; -SELECT * -FROM Shop_Role_Permission_Link -; -SELECT * -FROM Shop_Access_Level -; -SELECT * -FROM Shop_Permission -; -SELECT * -FROM Shop_Access_Level -; - - -select * from shop_user; -select * from shop_user_audit; -select * from Shop_User_Change_Set; -/* -INSERT INTO Shop_User_Change_Set ( comment ) -VALUES ('Demotion'); -*/ -UPDATE Shop_User -SET is_super_user = 0, - id_change_set = (SELECT id_change_set FROM Shop_User_Change_Set LIMIT 1) -WHERE id_user = 1 -; -select * from shop_user; -select * from shop_user_audit; - - -drop procedure if exists p_test; -delimiter // -create procedure p_test () -begin - declare b0 int; - declare b1 int; - SET b0 = 0; - SET b1 = 1; - select b0, b1; - select cast(b0 as char), cast(b1 as char); - select cast(b0 as char character set utf8), cast(b1 as char character set utf8); - select convert(b0, char), convert(b1, char); - select convert(b0, char character set utf8), convert(b1, char character set utf8); - select convert(convert(b0, signed), char), convert(convert(b1, signed), char); - select convert(convert(b0, signed), char character set utf8), convert(convert(b1, signed), char character set utf8); -end // -delimiter ; -call p_test(); -drop procedure if exists p_test; - -INSERT INTO Shop_User_Audit ( - id_user, - name_field, - value_prev, - value_new, - id_change_set -) -SELECT id_user, name_field, value_prev, value_new, id_change_set -FROM Shop_User_Audit -WHERE id_audit = 1 -UNION -SELECT id_user, name_field, value_prev, value_new, id_change_set -FROM Shop_User_Audit -WHERE id_audit = 1 -; - -select * from shop_user_audit; - - -SELECT * FROM Shop_Access_Level; - -SELECT * FROM Shop_Product; \ No newline at end of file diff --git a/static/MySQL/deprecated/dump.sql b/static/MySQL/deprecated/dump.sql deleted file mode 100644 index 7fc0217d..00000000 --- a/static/MySQL/deprecated/dump.sql +++ /dev/null @@ -1,8235 +0,0 @@ -CREATE DATABASE IF NOT EXISTS `partsltd_prod` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci */ /*!80016 DEFAULT ENCRYPTION='N' */; -USE `partsltd_prod`; --- MySQL dump 10.13 Distrib 8.0.36, for Win64 (x86_64) --- --- Host: localhost Database: partsltd_prod --- ------------------------------------------------------ --- Server version 8.0.35 - -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!50503 SET NAMES utf8 */; -/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; -/*!40103 SET TIME_ZONE='+00:00' */; -/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; -/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; -/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; -/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; - --- --- Table structure for table `file_type` --- - -DROP TABLE IF EXISTS `file_type`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `file_type` ( - `id_type` int NOT NULL AUTO_INCREMENT, - `code` varchar(50) DEFAULT NULL, - `name` varchar(100) DEFAULT NULL, - `extension` varchar(50) DEFAULT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `updated_last_on` datetime DEFAULT NULL, - `updated_last_by` varchar(100) DEFAULT NULL, - PRIMARY KEY (`id_type`) -) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `file_type` --- - -LOCK TABLES `file_type` WRITE; -/*!40000 ALTER TABLE `file_type` DISABLE KEYS */; -INSERT INTO `file_type` VALUES (1,'JPEG','Joint Photographic Export Group','jpg','2024-04-28 19:03:07','root@localhost',NULL,NULL),(2,'PNG','Portable Network Graphic','png','2024-04-28 19:03:07','root@localhost',NULL,NULL),(3,'GIF','GIF','gif','2024-04-28 19:03:07','root@localhost',NULL,NULL),(4,'MPEG-4','Multimedia Photographic Export Group 4','mp4','2024-04-28 19:03:07','root@localhost',NULL,NULL); -/*!40000 ALTER TABLE `file_type` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_File_Type` BEFORE INSERT ON `file_type` FOR EACH ROW BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_File_Type` BEFORE UPDATE ON `file_type` FOR EACH ROW BEGIN - INSERT INTO File_Type_Audit ( - id_type, - name_field, - value_prev, - value_new - ) - -- Changed code - SELECT NEW.id_type, 'code', OLD.code, NEW.code - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_type, 'name', OLD.name, NEW.name - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed extension - SELECT NEW.id_type, 'extension', CONVERT(OLD.extension, CHAR), CONVERT(NEW.extension, CHAR) - WHERE NOT OLD.extension <=> NEW.extension - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `file_type_audit` --- - -DROP TABLE IF EXISTS `file_type_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `file_type_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_type` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `updated_last_on` datetime DEFAULT NULL, - `updated_last_by` varchar(100) DEFAULT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_File_Type_Audit_id_type` (`id_type`), - CONSTRAINT `FK_File_Type_Audit_id_type` FOREIGN KEY (`id_type`) REFERENCES `file_type` (`id_type`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `file_type_audit` --- - -LOCK TABLES `file_type_audit` WRITE; -/*!40000 ALTER TABLE `file_type_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `file_type_audit` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_File_Type_Audit` BEFORE INSERT ON `file_type_audit` FOR EACH ROW BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_File_Type_Audit` BEFORE UPDATE ON `file_type_audit` FOR EACH ROW BEGIN - SET NEW.updated_last_on = NOW(); - SET NEW.updated_last_by = CURRENT_USER(); -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_access_level` --- - -DROP TABLE IF EXISTS `shop_access_level`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_access_level` ( - `id_access_level` int NOT NULL AUTO_INCREMENT, - `code` varchar(50) DEFAULT NULL, - `name` varchar(255) DEFAULT NULL, - `priority` int NOT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `display_order` int NOT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_access_level`), - KEY `FK_Shop_Access_Level_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Access_Level_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_user_change_set` (`id_change_set`) -) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_access_level` --- - -LOCK TABLES `shop_access_level` WRITE; -/*!40000 ALTER TABLE `shop_access_level` DISABLE KEYS */; -INSERT INTO `shop_access_level` VALUES (1,'VIEW','View',3,_binary '',1,'2024-04-28 19:03:07','root@localhost',NULL),(2,'EDIT','Edit',2,_binary '',2,'2024-04-28 19:03:07','root@localhost',NULL),(3,'ADMIN','Admin',1,_binary '',3,'2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_access_level` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Access_Level` BEFORE INSERT ON `shop_access_level` FOR EACH ROW BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Access_Level` BEFORE UPDATE ON `shop_access_level` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Access_Level_Audit ( - id_access_level, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_access_level, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT (OLD.code <=> NEW.code) - UNION - -- Changed name - SELECT NEW.id_access_level, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT (OLD.name <=> NEW.name) - UNION - -- Changed priority - SELECT NEW.id_access_level, 'priority', CONVERT(OLD.priority, CHAR), CONVERT(NEW.priority, CHAR), NEW.id_change_set - WHERE NOT (OLD.priority <=> NEW.priority) - UNION - -- Changed active - SELECT NEW.id_access_level, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_access_level, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_access_level_audit` --- - -DROP TABLE IF EXISTS `shop_access_level_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_access_level_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_access_level` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Access_Level_Audit_id_access_level` (`id_access_level`), - KEY `FK_Shop_Access_Level_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Access_Level_Audit_id_access_level` FOREIGN KEY (`id_access_level`) REFERENCES `shop_access_level` (`id_access_level`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Access_Level_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_user_change_set` (`id_change_set`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_access_level_audit` --- - -LOCK TABLES `shop_access_level_audit` WRITE; -/*!40000 ALTER TABLE `shop_access_level_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_access_level_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_address` --- - -DROP TABLE IF EXISTS `shop_address`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_address` ( - `id_address` int NOT NULL AUTO_INCREMENT, - `id_user` varchar(200) NOT NULL, - `id_region` int NOT NULL, - `name_full` varchar(255) NOT NULL, - `phone_number` varchar(20) NOT NULL, - `postcode` varchar(20) NOT NULL, - `address_line_1` varchar(100) NOT NULL, - `address_line_2` varchar(100) NOT NULL, - `city` varchar(50) NOT NULL, - `county` varchar(100) NOT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_address`), - KEY `FK_Shop_Address_id_user` (`id_user`), - KEY `FK_Shop_Address_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Address_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_user_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Address_id_user` FOREIGN KEY (`id_user`) REFERENCES `shop_user` (`id_user`) ON UPDATE RESTRICT -) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_address` --- - -LOCK TABLES `shop_address` WRITE; -/*!40000 ALTER TABLE `shop_address` DISABLE KEYS */; -INSERT INTO `shop_address` VALUES (1,'auth0|6582b95c895d09a70ba10fef',1,'Teddy','07375 571430','NN6 6EB','The Laurels','Cold Ashby Road','Cold Ashby','Northamptonshire',_binary '','2024-04-28 19:03:07','root@localhost',NULL),(2,'parts_guest',1,'Guest','07375 571430','NN6 6EB','The Laurels','Cold Ashby Road','Cold Ashby','Northamptonshire',_binary '','2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_address` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Address` BEFORE INSERT ON `shop_address` FOR EACH ROW BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Address` BEFORE UPDATE ON `shop_address` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Address_Audit ( - id_address, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed region - SELECT NEW.id_address, 'id_region', OLD.id_region, NEW.id_region, NEW.id_change_set - WHERE NOT OLD.id_region <=> NEW.id_region - UNION - -- Changed name_full - SELECT NEW.id_address, 'name_full', OLD.name_full, NEW.name_full, NEW.id_change_set - WHERE NOT OLD.name_full <=> NEW.name_full - UNION - -- Changed phone_number - SELECT NEW.id_address, 'phone_number', OLD.phone_number, NEW.phone_number, NEW.id_change_set - WHERE NOT OLD.phone_number <=> NEW.phone_number - UNION - -- Changed postcode - SELECT NEW.id_address, 'postcode', OLD.postcode, NEW.postcode, NEW.id_change_set - WHERE NOT OLD.postcode <=> NEW.postcode - UNION - -- Changed address_line_1 - SELECT NEW.id_address, 'address_line_1', OLD.address_line_1, NEW.address_line_1, NEW.id_change_set - WHERE NOT OLD.address_line_1 <=> NEW.address_line_1 - UNION - -- Changed address_line_2 - SELECT NEW.id_address, 'address_line_2', OLD.address_line_2, NEW.address_line_2, NEW.id_change_set - WHERE NOT OLD.address_line_2 <=> NEW.address_line_2 - UNION - -- Changed city - SELECT NEW.id_address, 'city', OLD.city, NEW.city, NEW.id_change_set - WHERE NOT OLD.city <=> NEW.city - UNION - -- Changed county - SELECT NEW.id_address, 'county', OLD.county, NEW.county, NEW.id_change_set - WHERE NOT OLD.county <=> NEW.county - UNION - -- Changed active - SELECT NEW.id_address, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_address_audit` --- - -DROP TABLE IF EXISTS `shop_address_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_address_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_address` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Address_Audit_id_address` (`id_address`), - KEY `FK_Shop_Address_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Address_Audit_id_address` FOREIGN KEY (`id_address`) REFERENCES `shop_address` (`id_address`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Address_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_user_change_set` (`id_change_set`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_address_audit` --- - -LOCK TABLES `shop_address_audit` WRITE; -/*!40000 ALTER TABLE `shop_address_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_address_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_category` --- - -DROP TABLE IF EXISTS `shop_category`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_category` ( - `id_category` int NOT NULL AUTO_INCREMENT, - `code` varchar(50) DEFAULT NULL, - `name` varchar(255) DEFAULT NULL, - `description` varchar(4000) DEFAULT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `display_order` int NOT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_category`), - KEY `FK_Shop_Product_Category_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Category_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`) -) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_category` --- - -LOCK TABLES `shop_category` WRITE; -/*!40000 ALTER TABLE `shop_category` DISABLE KEYS */; -INSERT INTO `shop_category` VALUES (1,'ASS','Assistive Devices','Braille product line and other assistive devices',_binary '',1,'2024-04-28 19:03:07','root@localhost',NULL),(2,'MISC','Miscellaneous','Not category allocated products',_binary '',99,'2024-04-28 19:03:07','root@localhost',NULL),(3,'TECH','Technology','Technological devices',_binary '',2,'2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_category` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Product_Category` BEFORE INSERT ON `shop_category` FOR EACH ROW BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Product_Category` BEFORE UPDATE ON `shop_category` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Product_Category_Audit ( - id_category, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_category, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_category, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed description - SELECT NEW.id_category, 'description', OLD.description, NEW.description, NEW.id_change_set - WHERE NOT OLD.description <=> NEW.description - UNION - -- Changed active - SELECT NEW.id_category, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_category, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_category_audit` --- - -DROP TABLE IF EXISTS `shop_category_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_category_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_category` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Product_Category_Audit_id_category` (`id_category`), - KEY `FK_Shop_Product_Category_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Category_Audit_id_category` FOREIGN KEY (`id_category`) REFERENCES `shop_category` (`id_category`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Product_Category_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_category_audit` --- - -LOCK TABLES `shop_category_audit` WRITE; -/*!40000 ALTER TABLE `shop_category_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_category_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_currency` --- - -DROP TABLE IF EXISTS `shop_currency`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_currency` ( - `id_currency` int NOT NULL AUTO_INCREMENT, - `code` varchar(50) NOT NULL, - `name` varchar(255) NOT NULL, - `symbol` varchar(1) NOT NULL, - `factor_from_GBP` float NOT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `display_order` int NOT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_currency`), - KEY `FK_Shop_Currency_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Currency_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`) ON UPDATE RESTRICT -) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_currency` --- - -LOCK TABLES `shop_currency` WRITE; -/*!40000 ALTER TABLE `shop_currency` DISABLE KEYS */; -INSERT INTO `shop_currency` VALUES (1,'GBP','Great British Pound','£',1,_binary '',1,'2024-04-28 19:03:07','root@localhost',NULL),(2,'EUR','Euro','€',1.17,_binary '',2,'2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_currency` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Currency` BEFORE INSERT ON `shop_currency` FOR EACH ROW BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Currency` BEFORE UPDATE ON `shop_currency` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Currency_Audit ( - id_currency, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_currency, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_currency, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed symbol - SELECT NEW.id_currency, 'symbol', OLD.symbol, NEW.symbol, NEW.id_change_set - WHERE NOT OLD.symbol <=> NEW.symbol - UNION - -- Changed ratio_2_GBP - SELECT NEW.id_currency, 'factor_from_GBP', OLD.factor_from_GBP, NEW.factor_from_GBP, NEW.id_change_set - WHERE NOT OLD.factor_from_GBP <=> NEW.factor_from_GBP - UNION - -- Changed active - SELECT NEW.id_currency, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_currency, 'display_order', CONVERT(display_order, CHAR), CONVERT(display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_currency_audit` --- - -DROP TABLE IF EXISTS `shop_currency_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_currency_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_currency` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Currency_Audit_id_currency` (`id_currency`), - KEY `FK_Shop_Currency_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Currency_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_user_change_set` (`id_change_set`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Currency_Audit_id_currency` FOREIGN KEY (`id_currency`) REFERENCES `shop_currency` (`id_currency`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_currency_audit` --- - -LOCK TABLES `shop_currency_audit` WRITE; -/*!40000 ALTER TABLE `shop_currency_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_currency_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_delivery_option` --- - -DROP TABLE IF EXISTS `shop_delivery_option`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_delivery_option` ( - `id_option` int NOT NULL AUTO_INCREMENT, - `code` varchar(50) NOT NULL, - `name` varchar(100) NOT NULL, - `description` varchar(4000) DEFAULT NULL, - `latency_delivery_min` int NOT NULL, - `latency_delivery_max` int NOT NULL, - `quantity_min` int NOT NULL, - `quantity_max` int NOT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `display_order` int NOT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_option`), - KEY `FK_Shop_Delivery_Option_Type_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Delivery_Option_Type_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`) -) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_delivery_option` --- - -LOCK TABLES `shop_delivery_option` WRITE; -/*!40000 ALTER TABLE `shop_delivery_option` DISABLE KEYS */; -INSERT INTO `shop_delivery_option` VALUES (1,'COLLECT','Collection',NULL,0,0,0,1,_binary '',1,'2024-04-28 19:03:07','root@localhost',NULL),(2,'SIGNED_1','First Class Signed-For',NULL,2,4,0,1,_binary '',2,'2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_delivery_option` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Delivery_Option` BEFORE INSERT ON `shop_delivery_option` FOR EACH ROW BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Delivery_Option` BEFORE UPDATE ON `shop_delivery_option` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Delivery_Option_Audit ( - id_option, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_option, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_option, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed latency_delivery_min - SELECT NEW.id_option, 'latency_delivery_min', CONVERT(OLD.latency_delivery_min, CHAR), CONVERT(NEW.latency_delivery_min, CHAR), NEW.id_change_set - WHERE NOT OLD.latency_delivery_min <=> NEW.latency_delivery_min - UNION - -- Changed latency_delivery_max - SELECT NEW.id_option, 'latency_delivery_max', CONVERT(OLD.latency_delivery_max, CHAR), CONVERT(NEW.latency_delivery_max, CHAR), NEW.id_change_set - WHERE NOT OLD.latency_delivery_max <=> NEW.latency_delivery_max - UNION - -- Changed quantity_min - SELECT NEW.id_option, 'quantity_min', CONVERT(OLD.quantity_min, CHAR), CONVERT(NEW.quantity_min, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_min <=> NEW.quantity_min - UNION - -- Changed quantity_max - SELECT NEW.id_option, 'quantity_max', CONVERT(OLD.quantity_max, CHAR), CONVERT(NEW.quantity_max, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - UNION - -- Changed active - SELECT NEW.id_option, 'active', CONVERT(OLD.active, CHAR), CONVERT(NEW.active, CHAR), NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - UNION - -- Changed display_order - SELECT NEW.id_option, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_delivery_option_audit` --- - -DROP TABLE IF EXISTS `shop_delivery_option_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_delivery_option_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_option` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Delivery_Option_Audit_id_option` (`id_option`), - KEY `FK_Shop_Delivery_Option_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Delivery_Option_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Delivery_Option_Audit_id_option` FOREIGN KEY (`id_option`) REFERENCES `shop_delivery_option` (`id_option`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_delivery_option_audit` --- - -LOCK TABLES `shop_delivery_option_audit` WRITE; -/*!40000 ALTER TABLE `shop_delivery_option_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_delivery_option_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_discount` --- - -DROP TABLE IF EXISTS `shop_discount`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_discount` ( - `id_discount` int NOT NULL AUTO_INCREMENT, - `code` varchar(50) NOT NULL, - `name` varchar(200) NOT NULL, - `id_product` int NOT NULL, - `id_permutation` int DEFAULT NULL, - `multiplier` float NOT NULL DEFAULT '1', - `subtractor` float NOT NULL DEFAULT '0', - `apply_multiplier_first` bit(1) DEFAULT b'1', - `quantity_min` float NOT NULL DEFAULT '0', - `quantity_max` float NOT NULL, - `date_start` datetime NOT NULL, - `date_end` datetime NOT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `display_order` int NOT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_discount`), - KEY `FK_Shop_Discount_id_product` (`id_product`), - KEY `FK_Shop_Discount_id_permutation` (`id_permutation`), - KEY `FK_Shop_Discount_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Discount_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Discount_id_permutation` FOREIGN KEY (`id_permutation`) REFERENCES `shop_product_permutation` (`id_permutation`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Discount_id_product` FOREIGN KEY (`id_product`) REFERENCES `shop_product` (`id_product`), - CONSTRAINT `shop_discount_chk_1` CHECK ((`multiplier` > 0)) -) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_discount` --- - -LOCK TABLES `shop_discount` WRITE; -/*!40000 ALTER TABLE `shop_discount` DISABLE KEYS */; -INSERT INTO `shop_discount` VALUES (1,'CRIMBO50','Christmas 50% off sale!',1,1,0.5,0,_binary '',3,9,'2024-04-28 19:03:07','2023-12-31 23:59:59',_binary '',1,'2024-04-28 19:03:07','root@localhost',NULL),(2,'CRIMBO50','Christmas 50% off sale!',1,2,0.5,0,_binary '',3,9,'2024-04-28 19:03:07','2023-12-31 23:59:59',_binary '',1,'2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_discount` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Discount` BEFORE INSERT ON `shop_discount` FOR EACH ROW BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Discount` BEFORE UPDATE ON `shop_discount` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Discount_Audit ( - id_discount, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_discount, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_discount, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed multiplier - SELECT NEW.id_discount, 'multiplier', OLD.multiplier, NEW.multiplier, NEW.id_change_set - WHERE NOT OLD.multiplier <=> NEW.multiplier - UNION - -- Changed subtractor - SELECT NEW.id_discount, 'subtractor', OLD.subtractor, NEW.subtractor, NEW.id_change_set - WHERE NOT OLD.subtractor <=> NEW.subtractor - UNION - -- Changed apply_multiplier_first - SELECT NEW.id_discount, 'apply_multiplier_first', CONVERT(CONVERT(OLD.apply_multiplier_first, SIGNED), CHAR), CONVERT(CONVERT(NEW.apply_multiplier_first, SIGNED), CHAR), NEW.id_change_set - WHERE NOT OLD.apply_multiplier_first <=> NEW.apply_multiplier_first - UNION - -- Changed quantity_min - SELECT NEW.id_discount, 'quantity_min', OLD.quantity_min, NEW.quantity_min, NEW.id_change_set - WHERE NOT OLD.quantity_min <=> NEW.quantity_min - UNION - -- Changed quantity_max - SELECT NEW.id_discount, 'quantity_max', OLD.quantity_max, NEW.quantity_max, NEW.id_change_set - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - UNION - -- Changed date_start - SELECT NEW.id_discount, 'date_start', OLD.date_start, NEW.date_start, NEW.id_change_set - WHERE NOT OLD.date_start <=> NEW.date_start - UNION - -- Changed date_end - SELECT NEW.id_discount, 'date_end', OLD.date_end, NEW.date_end, NEW.id_change_set - WHERE NOT OLD.date_end <=> NEW.date_end - UNION - -- Changed display_order - SELECT NEW.id_discount, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - UNION - -- Changed active - SELECT NEW.id_discount, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_discount_audit` --- - -DROP TABLE IF EXISTS `shop_discount_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_discount_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_discount` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Discount_Audit_id_discount` (`id_discount`), - KEY `FK_Shop_Discount_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Discount_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Discount_Audit_id_discount` FOREIGN KEY (`id_discount`) REFERENCES `shop_discount` (`id_discount`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_discount_audit` --- - -LOCK TABLES `shop_discount_audit` WRITE; -/*!40000 ALTER TABLE `shop_discount_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_discount_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_discount_region_currency_link` --- - -DROP TABLE IF EXISTS `shop_discount_region_currency_link`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_discount_region_currency_link` ( - `id_link` int NOT NULL AUTO_INCREMENT, - `id_discount` int NOT NULL, - `id_region` int NOT NULL, - `id_currency` int NOT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_link`), - KEY `FK_Shop_Discount_Region_Currency_Link_id_discount` (`id_discount`), - KEY `FK_Shop_Discount_Region_Currency_Link_id_region` (`id_region`), - KEY `FK_Shop_Discount_Region_Currency_Link_id_currency` (`id_currency`), - KEY `FK_Shop_Discount_Region_Currency_Link_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Discount_Region_Currency_Link_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Discount_Region_Currency_Link_id_currency` FOREIGN KEY (`id_currency`) REFERENCES `shop_currency` (`id_currency`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Discount_Region_Currency_Link_id_discount` FOREIGN KEY (`id_discount`) REFERENCES `shop_discount` (`id_discount`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Discount_Region_Currency_Link_id_region` FOREIGN KEY (`id_region`) REFERENCES `shop_region` (`id_region`) ON UPDATE RESTRICT -) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_discount_region_currency_link` --- - -LOCK TABLES `shop_discount_region_currency_link` WRITE; -/*!40000 ALTER TABLE `shop_discount_region_currency_link` DISABLE KEYS */; -INSERT INTO `shop_discount_region_currency_link` VALUES (1,1,1,1,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(2,2,1,1,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(3,1,1,2,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(4,2,1,2,_binary '','2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_discount_region_currency_link` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Discount_Region_Currency_Link` BEFORE INSERT ON `shop_discount_region_currency_link` FOR EACH ROW BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Discount_Region_Currency_Link` BEFORE UPDATE ON `shop_discount_region_currency_link` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Discount_Region_Currency_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_discount - SELECT NEW.id_link, 'id_discount', CONVERT(OLD.id_discount, CHAR), CONVERT(NEW.id_discount, CHAR), NEW.id_change_set - WHERE NOT OLD.id_discount <=> NEW.id_discount - UNION - -- Changed id_region - SELECT NEW.id_link, 'id_region', CONVERT(OLD.id_region, CHAR), CONVERT(NEW.id_region, CHAR), NEW.id_change_set - WHERE NOT OLD.id_region <=> NEW.id_region - UNION - */ - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_discount_region_currency_link_audit` --- - -DROP TABLE IF EXISTS `shop_discount_region_currency_link_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_discount_region_currency_link_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_link` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Discount_Region_Currency_Link_Audit_id_link` (`id_link`), - KEY `FK_Shop_Discount_Region_Currency_Link_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Discount_Region_Currency_Link_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Discount_Region_Currency_Link_Audit_id_link` FOREIGN KEY (`id_link`) REFERENCES `shop_discount_region_currency_link` (`id_link`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_discount_region_currency_link_audit` --- - -LOCK TABLES `shop_discount_region_currency_link_audit` WRITE; -/*!40000 ALTER TABLE `shop_discount_region_currency_link_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_discount_region_currency_link_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_general` --- - -DROP TABLE IF EXISTS `shop_general`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_general` ( - `id_general` int NOT NULL AUTO_INCREMENT, - `quantity_max` float DEFAULT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_general`), - KEY `CHK_Shop_General_id_change_set` (`id_change_set`), - CONSTRAINT `CHK_Shop_General_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`) -) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_general` --- - -LOCK TABLES `shop_general` WRITE; -/*!40000 ALTER TABLE `shop_general` DISABLE KEYS */; -INSERT INTO `shop_general` VALUES (1,10,'2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_general` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_General` BEFORE INSERT ON `shop_general` FOR EACH ROW BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_General` BEFORE UPDATE ON `shop_general` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_General_Audit ( - id_general, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed quantity max - SELECT NEW.id_general, 'quantity_max', CONVERT(OLD.quantity_max, CHAR), CONVERT(NEW.quantity_max, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_general_audit` --- - -DROP TABLE IF EXISTS `shop_general_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_general_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_general` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_General_Audit_id_general` (`id_general`), - KEY `FK_Shop_General_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_General_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_General_Audit_id_general` FOREIGN KEY (`id_general`) REFERENCES `shop_general` (`id_general`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_general_audit` --- - -LOCK TABLES `shop_general_audit` WRITE; -/*!40000 ALTER TABLE `shop_general_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_general_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_image` --- - -DROP TABLE IF EXISTS `shop_image`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_image` ( - `id_image` int NOT NULL AUTO_INCREMENT, - `id_type_image` int NOT NULL, - `id_type_file` int NOT NULL, - `id_product` int DEFAULT NULL, - `id_permutation` int DEFAULT NULL, - `url` varchar(255) DEFAULT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `display_order` int NOT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_image`), - KEY `FK_Shop_Image_id_type_image` (`id_type_image`), - KEY `FK_Shop_Image_id_type_file` (`id_type_file`), - KEY `FK_Shop_Image_id_product` (`id_product`), - KEY `FK_Shop_Image_id_permutation` (`id_permutation`), - KEY `FK_Shop_Image_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Image_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Image_id_permutation` FOREIGN KEY (`id_permutation`) REFERENCES `shop_product_permutation` (`id_permutation`), - CONSTRAINT `FK_Shop_Image_id_product` FOREIGN KEY (`id_product`) REFERENCES `shop_product` (`id_product`), - CONSTRAINT `FK_Shop_Image_id_type_file` FOREIGN KEY (`id_type_file`) REFERENCES `file_type` (`id_type`), - CONSTRAINT `FK_Shop_Image_id_type_image` FOREIGN KEY (`id_type_image`) REFERENCES `shop_image_type` (`id_type`) -) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_image` --- - -LOCK TABLES `shop_image` WRITE; -/*!40000 ALTER TABLE `shop_image` DISABLE KEYS */; -INSERT INTO `shop_image` VALUES (1,1,1,1,1,'/static/images/prod_PB0NUOSEs06ymG.jpg',_binary '',1,'2024-04-28 19:03:07','root@localhost',NULL),(2,1,1,1,2,'/static/images/prod_PB0NUOSEs06ymG.jpg',_binary '',2,'2024-04-28 19:03:07','root@localhost',NULL),(3,1,1,2,3,'/static/images/prod_PB0NUOSEs06ymG.jpg',_binary '',3,'2024-04-28 19:03:07','root@localhost',NULL),(4,1,1,3,4,'/static/images/prod_.jpg',_binary '',4,'2024-04-28 19:03:07','root@localhost',NULL),(5,1,1,4,5,'/static/images/prod_1.jpg',_binary '',5,'2024-04-28 19:03:07','root@localhost',NULL),(6,1,1,5,6,'/static/images/prod_2.jpg',_binary '',6,'2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_image` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Image` BEFORE INSERT ON `shop_image` FOR EACH ROW BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Image` BEFORE UPDATE ON `shop_image` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change set ID must be provided.'; - END IF; - IF ISNULL(NEW.id_product) AND ISNULL(NEW.id_permutation) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Image must NOT have ID for product AND product permutation.'; - END IF; - - INSERT INTO Shop_Image_Audit ( - id_image, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_type_image - SELECT NEW.id_image, 'id_type_image', CONVERT(OLD.id_type_image, CHAR), CONVERT(NEW.id_type_image, CHAR), NEW.id_change_set - WHERE NOT OLD.id_type_image <=> NEW.id_type_image - UNION - -- Changed id_type_file - SELECT NEW.id_image, 'id_type_file', CONVERT(OLD.id_type_file, CHAR), CONVERT(NEW.id_type_file, CHAR), NEW.id_change_set - WHERE NOT OLD.id_type_file <=> NEW.id_type_file - UNION - -- Changed id_product - SELECT NEW.id_image, 'id_product', CONVERT(OLD.id_product, CHAR), CONVERT(NEW.id_product, CHAR), NEW.id_change_set - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed id_permutation - SELECT NEW.id_image, 'id_permutation', CONVERT(OLD.id_permutation, CHAR), CONVERT(NEW.id_permutation, CHAR), NEW.id_change_set - WHERE NOT OLD.id_permutation <=> NEW.id_permutation - UNION - -- Changed url - SELECT NEW.id_image, 'url', OLD.url, NEW.url, NEW.id_change_set - WHERE NOT OLD.url <=> NEW.url - UNION - -- Changed active - SELECT NEW.id_image, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_image, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_image_audit` --- - -DROP TABLE IF EXISTS `shop_image_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_image_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_image` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Image_Audit_id_image` (`id_image`), - KEY `FK_Shop_Image_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Image_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Image_Audit_id_image` FOREIGN KEY (`id_image`) REFERENCES `shop_image` (`id_image`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_image_audit` --- - -LOCK TABLES `shop_image_audit` WRITE; -/*!40000 ALTER TABLE `shop_image_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_image_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_image_type` --- - -DROP TABLE IF EXISTS `shop_image_type`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_image_type` ( - `id_type` int NOT NULL AUTO_INCREMENT, - `code` varchar(50) DEFAULT NULL, - `name` varchar(255) DEFAULT NULL, - `name_plural` varchar(256) DEFAULT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `display_order` int NOT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_type`), - KEY `FK_Shop_Image_Type_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Image_Type_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`) -) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_image_type` --- - -LOCK TABLES `shop_image_type` WRITE; -/*!40000 ALTER TABLE `shop_image_type` DISABLE KEYS */; -INSERT INTO `shop_image_type` VALUES (1,'FULL','Full Quality Image','Full Quality Images',_binary '',1,'2024-04-28 19:03:07','root@localhost',NULL),(2,'LOW','Low Quality Image','Low Quality Images',_binary '',2,'2024-04-28 19:03:07','root@localhost',NULL),(3,'THUMBNAIL','Thumbnail Image','Thumbnail Images',_binary '',3,'2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_image_type` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Image_Type` BEFORE INSERT ON `shop_image_type` FOR EACH ROW BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Image_Type` BEFORE UPDATE ON `shop_image_type` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Image_Type_Audit ( - id_type, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_type, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_type, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed name_plural - SELECT NEW.id_type, 'name_plural', OLD.name_plural, NEW.name_plural, NEW.id_change_set - WHERE NOT OLD.name_plural <=> NEW.name_plural - UNION - -- Changed active - SELECT NEW.id_type, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_type, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_image_type_audit` --- - -DROP TABLE IF EXISTS `shop_image_type_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_image_type_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_type` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Image_Type_Audit_id_type` (`id_type`), - KEY `FK_Shop_Image_Type_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Image_Type_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Image_Type_Audit_id_type` FOREIGN KEY (`id_type`) REFERENCES `shop_image_type` (`id_type`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_image_type_audit` --- - -LOCK TABLES `shop_image_type_audit` WRITE; -/*!40000 ALTER TABLE `shop_image_type_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_image_type_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_msg_error_type` --- - -DROP TABLE IF EXISTS `shop_msg_error_type`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_msg_error_type` ( - `id_type` int NOT NULL AUTO_INCREMENT, - `code` varchar(50) NOT NULL, - `name` varchar(500) NOT NULL, - `description` varchar(1000) DEFAULT NULL, - PRIMARY KEY (`id_type`) -) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_msg_error_type` --- - -LOCK TABLES `shop_msg_error_type` WRITE; -/*!40000 ALTER TABLE `shop_msg_error_type` DISABLE KEYS */; -INSERT INTO `shop_msg_error_type` VALUES (1,'BAD_DATA','Invalid data','Rubbish data'),(2,'NO_PERMISSION','No permission','Not authorised'),(3,'PRODUCT_AVAILABILITY','Product not available','Product not available'); -/*!40000 ALTER TABLE `shop_msg_error_type` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_permission` --- - -DROP TABLE IF EXISTS `shop_permission`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_permission` ( - `id_permission` int NOT NULL AUTO_INCREMENT, - `code` varchar(50) DEFAULT NULL, - `name` varchar(255) DEFAULT NULL, - `id_permission_group` int NOT NULL, - `id_access_level_required` int NOT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `display_order` int NOT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_permission`), - KEY `FK_Shop_Permission_id_permission_group` (`id_permission_group`), - KEY `FK_Shop_Permission_id_access_level_required` (`id_access_level_required`), - KEY `FK_Shop_Permission_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Permission_id_access_level_required` FOREIGN KEY (`id_access_level_required`) REFERENCES `shop_access_level` (`id_access_level`), - CONSTRAINT `FK_Shop_Permission_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_user_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Permission_id_permission_group` FOREIGN KEY (`id_permission_group`) REFERENCES `shop_permission_group` (`id_group`) ON UPDATE RESTRICT -) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_permission` --- - -LOCK TABLES `shop_permission` WRITE; -/*!40000 ALTER TABLE `shop_permission` DISABLE KEYS */; -INSERT INTO `shop_permission` VALUES (1,'HOME','Home Page',2,1,_binary '',1,'2024-04-28 19:03:07','root@localhost',NULL),(2,'STORE_PRODUCT','Store Product Page',3,1,_binary '',2,'2024-04-28 19:03:07','root@localhost',NULL),(3,'STORE_USER','Store User Account Page',4,2,_binary '',3,'2024-04-28 19:03:07','root@localhost',NULL),(4,'STORE_ADMIN','Store Admin Page',1,3,_binary '',4,'2024-04-28 19:03:07','root@localhost',NULL),(5,'CONTACT_US','Contact Us Page',2,1,_binary '',99,'2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_permission` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Permission` BEFORE INSERT ON `shop_permission` FOR EACH ROW BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Permission` BEFORE UPDATE ON `shop_permission` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Permission_Audit ( - id_permission, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_permission, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_permission, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed id_permission_group - SELECT NEW.id_permission, 'id_permission_group', CONVERT(OLD.id_permission_group, CHAR), CONVERT(NEW.id_permission_group, CHAR), NEW.id_change_set - WHERE NOT OLD.id_permission_group <=> NEW.id_permission_group - UNION - -- Changed Id_access_level_required - SELECT NEW.id_permission, 'Id_access_level_required', CONVERT(OLD.Id_access_level_required, CHAR), CONVERT(NEW.Id_access_level_required, CHAR), NEW.id_change_set - WHERE NOT OLD.Id_access_level_required <=> NEW.Id_access_level_required - UNION - -- Changed active - SELECT NEW.id_permission, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_permission, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_permission_audit` --- - -DROP TABLE IF EXISTS `shop_permission_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_permission_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_permission` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Permission_Audit_id_permission` (`id_permission`), - KEY `FK_Shop_Permission_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Permission_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_user_change_set` (`id_change_set`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Permission_Audit_id_permission` FOREIGN KEY (`id_permission`) REFERENCES `shop_permission` (`id_permission`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_permission_audit` --- - -LOCK TABLES `shop_permission_audit` WRITE; -/*!40000 ALTER TABLE `shop_permission_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_permission_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_permission_group` --- - -DROP TABLE IF EXISTS `shop_permission_group`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_permission_group` ( - `id_group` int NOT NULL AUTO_INCREMENT, - `code` varchar(50) DEFAULT NULL, - `name` varchar(255) DEFAULT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `display_order` int NOT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_group`), - KEY `FK_Shop_Permission_Group_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Permission_Group_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_user_change_set` (`id_change_set`) ON UPDATE RESTRICT -) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_permission_group` --- - -LOCK TABLES `shop_permission_group` WRITE; -/*!40000 ALTER TABLE `shop_permission_group` DISABLE KEYS */; -INSERT INTO `shop_permission_group` VALUES (1,'ADMIN','Website Admin',_binary '',0,'2024-04-28 19:03:07','root@localhost',NULL),(2,'HOME','Home, Contact Us, and other public information',_binary '',1,'2024-04-28 19:03:07','root@localhost',NULL),(3,'PRODUCT','Store Products',_binary '',2,'2024-04-28 19:03:07','root@localhost',NULL),(4,'USER','Store User',_binary '',3,'2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_permission_group` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Permission_Group` BEFORE INSERT ON `shop_permission_group` FOR EACH ROW BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Permission_Group` BEFORE UPDATE ON `shop_permission_group` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Permission_Group_Audit ( - id_group, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_group, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_group, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed active - SELECT NEW.id_group, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_group, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_permission_group_audit` --- - -DROP TABLE IF EXISTS `shop_permission_group_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_permission_group_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_group` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Permission_Group_Audit_id_group` (`id_group`), - KEY `FK_Shop_Permission_Group_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Permission_Group_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_user_change_set` (`id_change_set`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Permission_Group_Audit_id_group` FOREIGN KEY (`id_group`) REFERENCES `shop_permission_group` (`id_group`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_permission_group_audit` --- - -LOCK TABLES `shop_permission_group_audit` WRITE; -/*!40000 ALTER TABLE `shop_permission_group_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_permission_group_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_product` --- - -DROP TABLE IF EXISTS `shop_product`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_product` ( - `id_product` int NOT NULL AUTO_INCREMENT, - `name` varchar(255) NOT NULL, - `id_category` int NOT NULL, - `has_variations` bit(1) NOT NULL, - `id_access_level_required` int NOT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `display_order` int NOT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_product`), - KEY `FK_Shop_Product_id_access_level_required` (`id_access_level_required`), - KEY `FK_Shop_Product_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_id_access_level_required` FOREIGN KEY (`id_access_level_required`) REFERENCES `shop_access_level` (`id_access_level`), - CONSTRAINT `FK_Shop_Product_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`) -) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_product` --- - -LOCK TABLES `shop_product` WRITE; -/*!40000 ALTER TABLE `shop_product` DISABLE KEYS */; -INSERT INTO `shop_product` VALUES (1,'Braille Keyboard Translator',1,_binary '',3,_binary '',1,'2024-04-28 19:03:07','root@localhost',NULL),(2,'Test product 1',2,_binary '\0',3,_binary '',2,'2024-04-28 19:03:07','root@localhost',NULL),(3,'Phone',3,_binary '\0',1,_binary '',3,'2024-04-28 19:03:07','root@localhost',NULL),(4,'Laptop',3,_binary '\0',1,_binary '',4,'2024-04-28 19:03:07','root@localhost',NULL),(5,'Smart Watch',3,_binary '\0',1,_binary '',5,'2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_product` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Product` BEFORE INSERT ON `shop_product` FOR EACH ROW BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Product` BEFORE UPDATE ON `shop_product` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - /* - IF NOT NEW.has_variations THEN - IF ISNULL(NEW.price_GBP_full) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have price or variations (with prices).'; - END IF; - IF ISNULL(NEW.price_GBP_min) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have minimum price or variations (with prices).'; - END IF; - IF ISNULL(NEW.latency_manuf) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have manufacturing latency or variations (with manufacturing latencies).'; - END IF; - IF ISNULL(NEW.quantity_min) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have minimum quantity or variations (with minimum quantities).'; - END IF; - IF ISNULL(NEW.quantity_max) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have maximum quantity or variations (with maximum quantities).'; - END IF; - IF ISNULL(NEW.quantity_step) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have increment of quantity or variations (with increments of quantities).'; - END IF; - IF ISNULL(NEW.quantity_stock) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have stock quantity or variations (with stock quantities).'; - END IF; - IF ISNULL(NEW.is_subscription) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have subscription status or variations (with subscription statuses).'; - END IF; - IF ISNULL(NEW.id_unit_measurement_interval_recurrence) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have recurrence interval or variations (with recurrence intervals).'; - END IF; - IF ISNULL(NEW.count_interval_recurrence) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have recurrence interval count or variations (with recurrence interval counts).'; - END IF; - END IF; - */ - - INSERT INTO Shop_Product_Audit ( - id_product, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed name - SELECT NEW.id_product, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - /* - UNION - -- Changed description - SELECT NEW.id_product, 'description', OLD.description, NEW.description, NEW.id_change_set - WHERE NOT OLD.description <=> NEW.description - UNION - -- Changed price_GBP_full - SELECT NEW.id_product, 'price_GBP_full', CONVERT(OLD.price_GBP_full, CHAR), CONVERT(NEW.price_GBP_full, CHAR), NEW.id_change_set - WHERE NOT OLD.price_GBP_full <=> NEW.price_GBP_full - UNION - -- Changed price_GBP_min - SELECT NEW.id_product, 'price_GBP_min', CONVERT(OLD.price_GBP_min, CHAR), CONVERT(NEW.price_GBP_min, CHAR), NEW.id_change_set - WHERE NOT OLD.price_GBP_min <=> NEW.price_GBP_min - UNION - -- Changed has_variations - SELECT NEW.id_product, 'has_variations', CONVERT(CONVERT(NEW.has_variations, SIGNED), CHAR), CONVERT(CONVERT(NEW.has_variations, SIGNED), CHAR), NEW.id_change_set - WHERE NOT OLD.has_variations <=> NEW.has_variations - UNION - /* - -- Changed discount - SELECT NEW.id_product, 'discount', CONVERT(OLD.discount, CHAR), CONVERT(NEW.discount, CHAR), NEW.id_change_set - WHERE NOT OLD.discount <=> NEW.discount - */ - UNION - -- Changed id_category - SELECT NEW.id_product, 'id_category', CONVERT(OLD.id_category, CHAR), CONVERT(NEW.id_category, CHAR), NEW.id_change_set - WHERE NOT OLD.id_category <=> NEW.id_category - /* - UNION - -- Changed latency_manuf - SELECT NEW.id_product, 'latency_manuf', CONVERT(OLD.latency_manuf, CHAR), CONVERT(NEW.latency_manuf, CHAR), NEW.id_change_set - WHERE NOT OLD.latency_manuf <=> NEW.latency_manuf - UNION - -- Changed quantity_min - SELECT NEW.id_product, 'quantity_min', CONVERT(OLD.quantity_min, CHAR), CONVERT(NEW.quantity_min, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_min <=> NEW.quantity_min - UNION - -- Changed quantity_max - SELECT NEW.id_product, 'quantity_max', CONVERT(OLD.quantity_max, CHAR), CONVERT(NEW.quantity_max, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - UNION - -- Changed quantity_step - SELECT NEW.id_product, 'quantity_step', CONVERT(OLD.quantity_step, CHAR), CONVERT(NEW.quantity_step, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_step <=> NEW.quantity_step - UNION - -- Changed quantity_stock - SELECT NEW.id_product, 'quantity_stock', CONVERT(OLD.quantity_stock, CHAR), CONVERT(NEW.quantity_stock, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_stock <=> NEW.quantity_stock - UNION - -- Changed is_subscription - SELECT NEW.id_product, 'is_subscription', CONVERT(CONVERT(OLD.is_subscription, SIGNED), CHAR), CONVERT(CONVERT(NEW.is_subscription, SIGNED), CHAR), NEW.id_change_set - WHERE NOT OLD.is_subscription <=> NEW.is_subscription - UNION - -- Changed id_unit_measurement_interval_recurrence - SELECT NEW.id_product, 'id_unit_measurement_interval_recurrence', CONVERT(OLD.id_unit_measurement_interval_recurrence, CHAR), CONVERT(NEW.id_unit_measurement_interval_recurrence, CHAR), NEW.id_change_set - WHERE NOT OLD.id_unit_measurement_interval_recurrence <=> NEW.id_unit_measurement_interval_recurrence - UNION - -- Changed count_interval_recurrence - SELECT NEW.id_product, 'count_interval_recurrence', CONVERT(OLD.count_interval_recurrence, CHAR), CONVERT(NEW.count_interval_recurrence, CHAR), NEW.id_change_set - WHERE NOT OLD.count_interval_recurrence <=> NEW.count_interval_recurrence - UNION - -- Changed id_access_level_required - SELECT NEW.id_product, 'id_access_level_required', CONVERT(OLD.id_access_level_required, CHAR), CONVERT(NEW.id_access_level_required, CHAR), NEW.id_change_set - WHERE NOT OLD.id_access_level_required <=> NEW.id_access_level_required - UNION - -- Changed id_stripe_product - SELECT NEW.id_product, 'id_stripe_product', OLD.id_stripe_product, NEW.id_stripe_product, NEW.id_change_set - WHERE NOT OLD.id_stripe_product <=> NEW.id_stripe_product - /* - UNION - -- Changed id_stripe_price - SELECT NEW.id_product, 'id_stripe_price', OLD.id_stripe_price, NEW.id_stripe_price, NEW.id_change_set - WHERE NOT OLD.id_stripe_price <=> NEW.id_stripe_price - */ - UNION - -- Changed active - SELECT NEW.id_product, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_product, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_product_audit` --- - -DROP TABLE IF EXISTS `shop_product_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_product_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_product` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Product_Audit_id_product` (`id_product`), - KEY `FK_Shop_Product_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Audit_id_product` FOREIGN KEY (`id_product`) REFERENCES `shop_product` (`id_product`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_product_audit` --- - -LOCK TABLES `shop_product_audit` WRITE; -/*!40000 ALTER TABLE `shop_product_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_product_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_product_change_set` --- - -DROP TABLE IF EXISTS `shop_product_change_set`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_product_change_set` ( - `id_change_set` int NOT NULL AUTO_INCREMENT, - `comment` varchar(500) DEFAULT NULL, - `updated_last_on` datetime DEFAULT NULL, - `updated_last_by` varchar(100) DEFAULT NULL, - PRIMARY KEY (`id_change_set`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_product_change_set` --- - -LOCK TABLES `shop_product_change_set` WRITE; -/*!40000 ALTER TABLE `shop_product_change_set` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_product_change_set` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Product_Change_Set` BEFORE INSERT ON `shop_product_change_set` FOR EACH ROW BEGIN - IF NEW.updated_last_on <=> NULL THEN - SET NEW.updated_last_on = NOW(); - END IF; - IF NEW.updated_last_by <=> NULL THEN - SET NEW.updated_last_by = CURRENT_USER(); - END IF; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_product_currency_link` --- - -DROP TABLE IF EXISTS `shop_product_currency_link`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_product_currency_link` ( - `id_link` int NOT NULL AUTO_INCREMENT, - `id_product` int NOT NULL, - `id_permutation` int DEFAULT NULL, - `id_currency` int NOT NULL, - `id_region_purchase` int NOT NULL, - `price_local_VAT_incl` float DEFAULT NULL, - `price_local_VAT_excl` float DEFAULT NULL, - `id_stripe_price` varchar(200) DEFAULT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_link`), - KEY `FK_Shop_Product_Currency_Link_id_product` (`id_product`), - KEY `FK_Shop_Product_Currency_Link_id_permutation` (`id_permutation`), - KEY `FK_Shop_Product_Currency_Link_id_currency` (`id_currency`), - KEY `FK_Shop_Product_Currency_Link_id_region_purchase` (`id_region_purchase`), - KEY `FK_Shop_Product_Currency_Link_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Currency_Link_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Currency_Link_id_currency` FOREIGN KEY (`id_currency`) REFERENCES `shop_currency` (`id_currency`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Product_Currency_Link_id_permutation` FOREIGN KEY (`id_permutation`) REFERENCES `shop_product_permutation` (`id_permutation`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Product_Currency_Link_id_product` FOREIGN KEY (`id_product`) REFERENCES `shop_product` (`id_product`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Product_Currency_Link_id_region_purchase` FOREIGN KEY (`id_region_purchase`) REFERENCES `shop_region` (`id_region`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_product_currency_link` --- - -LOCK TABLES `shop_product_currency_link` WRITE; -/*!40000 ALTER TABLE `shop_product_currency_link` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_product_currency_link` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Product_Currency_Link` BEFORE INSERT ON `shop_product_currency_link` FOR EACH ROW BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; - /* - SET NEW.price_local = ( - SELECT PP.price_GBP_full * C.factor_from_GBP - FROM Shop_Product_Permutation PP - INNER JOIN Shop_Product P ON PP.id_product = P.id_product - INNER JOIN Shop_Currency C ON NEW.id_currency = C.id_currency - WHERE NEW.id_product = P.id_product - LIMIT 1 - ); - */ -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Product_Currency_Link` BEFORE UPDATE ON `shop_product_currency_link` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - /* - SET NEW.price_local = ( - SELECT P.price_GBP_full * C.factor_from_GBP - FROM Shop_Product P - INNER JOIN Shop_Currency C ON NEW.id_currency = C.id_currency - WHERE NEW.id_product = P.id_product - LIMIT 1 - ); - */ - - INSERT INTO Shop_Product_Currency_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_product - SELECT NEW.id_link, 'id_product', CONVERT(OLD.id_product, CHAR), CONVERT(NEW.id_product, CHAR), NEW.id_change_set - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed id_currency - SELECT NEW.id_link, 'id_currency', CONVERT(OLD.id_currency, CHAR), CONVERT(NEW.id_currency, CHAR), NEW.id_change_set - WHERE NOT OLD.id_currency <=> NEW.id_currency - UNION - -- Changed price_local - SELECT NEW.id_link, 'price_local', OLD.price_local, NEW.price_local, NEW.id_change_set - WHERE NOT OLD.price_local <=> NEW.price_local - UNION - */ - -- Changed price_local_VAT_incl - SELECT NEW.id_link, 'price_local_VAT_incl', OLD.price_local_VAT_incl, NEW.price_local_VAT_incl, NEW.id_change_set - WHERE NOT OLD.price_local_VAT_incl <=> NEW.price_local_VAT_incl - UNION - -- Changed price_local_VAT_excl - SELECT NEW.id_link, 'price_local_VAT_excl', OLD.price_local_VAT_excl, NEW.price_local_VAT_excl, NEW.id_change_set - WHERE NOT OLD.price_local_VAT_excl <=> NEW.price_local_VAT_excl - UNION - -- Changed id_stripe_price - SELECT NEW.id_link, 'id_stripe_price', OLD.id_stripe_price, NEW.id_stripe_price, NEW.id_change_set - WHERE NOT OLD.id_stripe_price <=> NEW.id_stripe_price - UNION - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_product_currency_link_audit` --- - -DROP TABLE IF EXISTS `shop_product_currency_link_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_product_currency_link_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_link` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Product_Currency_Link_Audit_id_link` (`id_link`), - KEY `FK_Shop_Product_Currency_Link_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Currency_Link_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Currency_Link_Audit_id_link` FOREIGN KEY (`id_link`) REFERENCES `shop_product_currency_link` (`id_link`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_product_currency_link_audit` --- - -LOCK TABLES `shop_product_currency_link_audit` WRITE; -/*!40000 ALTER TABLE `shop_product_currency_link_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_product_currency_link_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_product_currency_region_link` --- - -DROP TABLE IF EXISTS `shop_product_currency_region_link`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_product_currency_region_link` ( - `id_link` int NOT NULL AUTO_INCREMENT, - `id_product` int NOT NULL, - `id_permutation` int DEFAULT NULL, - `id_currency` int NOT NULL, - `id_region_purchase` int NOT NULL, - `price_local_VAT_incl` float DEFAULT NULL, - `price_local_VAT_excl` float DEFAULT NULL, - `id_stripe_price` varchar(200) DEFAULT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_link`), - KEY `FK_Shop_Product_Currency_Region_Link_id_product` (`id_product`), - KEY `FK_Shop_Product_Currency_Region_Link_id_permutation` (`id_permutation`), - KEY `FK_Shop_Product_Currency_Region_Link_id_currency` (`id_currency`), - KEY `FK_Shop_Product_Currency_Region_Link_id_region_purchase` (`id_region_purchase`), - KEY `FK_Shop_Product_Currency_Region_Link_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Currency_Region_Link_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Currency_Region_Link_id_currency` FOREIGN KEY (`id_currency`) REFERENCES `shop_currency` (`id_currency`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Product_Currency_Region_Link_id_permutation` FOREIGN KEY (`id_permutation`) REFERENCES `shop_product_permutation` (`id_permutation`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Product_Currency_Region_Link_id_product` FOREIGN KEY (`id_product`) REFERENCES `shop_product` (`id_product`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Product_Currency_Region_Link_id_region_purchase` FOREIGN KEY (`id_region_purchase`) REFERENCES `shop_region` (`id_region`) ON UPDATE RESTRICT -) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_product_currency_region_link` --- - -LOCK TABLES `shop_product_currency_region_link` WRITE; -/*!40000 ALTER TABLE `shop_product_currency_region_link` DISABLE KEYS */; -INSERT INTO `shop_product_currency_region_link` VALUES (1,1,1,1,1,24,20,NULL,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(2,1,1,2,1,48,40,NULL,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(3,1,2,1,1,96,80,NULL,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(4,2,3,1,1,144,120,NULL,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(5,3,4,1,1,600,500,NULL,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(6,4,5,1,1,1500,1200,NULL,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(7,5,6,1,1,180,150,NULL,_binary '','2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_product_currency_region_link` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Product_Currency_Region_Link` BEFORE INSERT ON `shop_product_currency_region_link` FOR EACH ROW BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; - /* - SET NEW.price_local = ( - SELECT PP.price_GBP_full * C.factor_from_GBP - FROM Shop_Product_Permutation PP - INNER JOIN Shop_Product P ON PP.id_product = P.id_product - INNER JOIN Shop_Currency C ON NEW.id_currency = C.id_currency - WHERE NEW.id_product = P.id_product - LIMIT 1 - ); - */ -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Product_Currency_Region_Link` BEFORE UPDATE ON `shop_product_currency_region_link` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - /* - SET NEW.price_local = ( - SELECT P.price_GBP_full * C.factor_from_GBP - FROM Shop_Product P - INNER JOIN Shop_Currency C ON NEW.id_currency = C.id_currency - WHERE NEW.id_product = P.id_product - LIMIT 1 - ); - */ - - INSERT INTO Shop_Product_Currency_Region_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_product - SELECT NEW.id_link, 'id_product', CONVERT(OLD.id_product, CHAR), CONVERT(NEW.id_product, CHAR), NEW.id_change_set - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed id_currency - SELECT NEW.id_link, 'id_currency', CONVERT(OLD.id_currency, CHAR), CONVERT(NEW.id_currency, CHAR), NEW.id_change_set - WHERE NOT OLD.id_currency <=> NEW.id_currency - UNION - -- Changed price_local - SELECT NEW.id_link, 'price_local', OLD.price_local, NEW.price_local, NEW.id_change_set - WHERE NOT OLD.price_local <=> NEW.price_local - UNION - */ - -- Changed price_local_VAT_incl - SELECT NEW.id_link, 'price_local_VAT_incl', OLD.price_local_VAT_incl, NEW.price_local_VAT_incl, NEW.id_change_set - WHERE NOT OLD.price_local_VAT_incl <=> NEW.price_local_VAT_incl - UNION - -- Changed price_local_VAT_excl - SELECT NEW.id_link, 'price_local_VAT_excl', OLD.price_local_VAT_excl, NEW.price_local_VAT_excl, NEW.id_change_set - WHERE NOT OLD.price_local_VAT_excl <=> NEW.price_local_VAT_excl - UNION - -- Changed id_stripe_price - SELECT NEW.id_link, 'id_stripe_price', OLD.id_stripe_price, NEW.id_stripe_price, NEW.id_change_set - WHERE NOT OLD.id_stripe_price <=> NEW.id_stripe_price - UNION - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_product_currency_region_link_audit` --- - -DROP TABLE IF EXISTS `shop_product_currency_region_link_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_product_currency_region_link_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_link` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Product_Currency_Region_Link_Audit_id_link` (`id_link`), - KEY `FK_Shop_Product_Currency_Region_Link_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Currency_Region_Link_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Currency_Region_Link_Audit_id_link` FOREIGN KEY (`id_link`) REFERENCES `shop_product_currency_region_link` (`id_link`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_product_currency_region_link_audit` --- - -LOCK TABLES `shop_product_currency_region_link_audit` WRITE; -/*!40000 ALTER TABLE `shop_product_currency_region_link_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_product_currency_region_link_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_product_delivery_option_link` --- - -DROP TABLE IF EXISTS `shop_product_delivery_option_link`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_product_delivery_option_link` ( - `id_link` int NOT NULL AUTO_INCREMENT, - `id_product` int NOT NULL, - `id_permutation` int DEFAULT NULL, - `id_delivery_option` int NOT NULL, - `id_region` int NOT NULL, - `id_currency` int NOT NULL, - `price_local` float NOT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `display_order` int NOT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_link`), - KEY `FK_Shop_Product_Delivery_Option_Link_id_product` (`id_product`), - KEY `FK_Shop_Product_Delivery_Option_Link_id_permutation` (`id_permutation`), - KEY `FK_Shop_Product_Delivery_Option_Link_id_delivery_option` (`id_delivery_option`), - KEY `FK_Shop_Product_Delivery_Option_Link_id_region` (`id_region`), - KEY `FK_Shop_Product_Delivery_Option_Link_id_currency` (`id_currency`), - KEY `FK_Shop_Product_Delivery_Option_Link_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Delivery_Option_Link_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Delivery_Option_Link_id_currency` FOREIGN KEY (`id_currency`) REFERENCES `shop_currency` (`id_currency`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Product_Delivery_Option_Link_id_delivery_option` FOREIGN KEY (`id_delivery_option`) REFERENCES `shop_delivery_option` (`id_option`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Product_Delivery_Option_Link_id_permutation` FOREIGN KEY (`id_permutation`) REFERENCES `shop_product_permutation` (`id_permutation`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Product_Delivery_Option_Link_id_product` FOREIGN KEY (`id_product`) REFERENCES `shop_product` (`id_product`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Product_Delivery_Option_Link_id_region` FOREIGN KEY (`id_region`) REFERENCES `shop_region` (`id_region`) ON UPDATE RESTRICT -) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_product_delivery_option_link` --- - -LOCK TABLES `shop_product_delivery_option_link` WRITE; -/*!40000 ALTER TABLE `shop_product_delivery_option_link` DISABLE KEYS */; -INSERT INTO `shop_product_delivery_option_link` VALUES (1,1,1,1,1,1,5,_binary '',1,'2024-04-28 19:03:07','root@localhost',NULL),(2,1,2,1,1,1,9,_binary '',2,'2024-04-28 19:03:07','root@localhost',NULL),(3,2,NULL,1,1,1,10,_binary '',3,'2024-04-28 19:03:07','root@localhost',NULL),(4,3,4,1,1,1,10,_binary '',4,'2024-04-28 19:03:07','root@localhost',NULL),(5,4,5,1,1,1,10,_binary '',5,'2024-04-28 19:03:07','root@localhost',NULL),(6,5,6,1,1,1,10,_binary '',6,'2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_product_delivery_option_link` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Product_Delivery_Option_Link` BEFORE INSERT ON `shop_product_delivery_option_link` FOR EACH ROW BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Product_Delivery_Option_Link` BEFORE UPDATE ON `shop_product_delivery_option_link` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Product_Delivery_Option_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_product - SELECT NEW.id_link, 'id_product', CONVERT(OLD.id_product, CHAR), CONVERT(NEW.id_product, CHAR), NEW.id_change_set - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed id_permutation - SELECT NEW.id_link, 'id_permutation', CONVERT(OLD.id_permutation, CHAR), CONVERT(NEW.id_permutation, CHAR), NEW.id_change_set - WHERE NOT OLD.id_permutation <=> NEW.id_permutation - UNION - -- Changed id_option - SELECT NEW.id_link, 'id_option', CONVERT(OLD.id_option, CHAR), CONVERT(NEW.id_option, CHAR), NEW.id_change_set - WHERE NOT OLD.id_option <=> NEW.id_option - UNION - -- Changed id_region - SELECT NEW.id_link, 'id_region', CONVERT(OLD.id_region, CHAR), CONVERT(NEW.id_region, CHAR), NEW.id_change_set - WHERE NOT OLD.id_region <=> NEW.id_region - UNION - */ - -- Changed price_local - SELECT NEW.id_link, 'price_local', CONVERT(OLD.price_local, CHAR), CONVERT(NEW.price_local, CHAR), NEW.id_change_set - WHERE NOT OLD.price_local <=> NEW.price_local - UNION - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_link, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_product_delivery_option_link_audit` --- - -DROP TABLE IF EXISTS `shop_product_delivery_option_link_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_product_delivery_option_link_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_link` int NOT NULL, - `name_field` varchar(64) NOT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Product_Delivery_Option_Link_Audit_id_link` (`id_link`), - KEY `FK_Shop_Product_Delivery_Option_Link_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Delivery_Option_Link_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Delivery_Option_Link_Audit_id_link` FOREIGN KEY (`id_link`) REFERENCES `shop_product_delivery_option_link` (`id_link`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_product_delivery_option_link_audit` --- - -LOCK TABLES `shop_product_delivery_option_link_audit` WRITE; -/*!40000 ALTER TABLE `shop_product_delivery_option_link_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_product_delivery_option_link_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_product_permutation` --- - -DROP TABLE IF EXISTS `shop_product_permutation`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_product_permutation` ( - `id_permutation` int NOT NULL AUTO_INCREMENT, - `id_product` int NOT NULL, - `description` varchar(4000) NOT NULL, - `cost_local_manufacturing` float NOT NULL, - `id_currency_cost_manufacturing` int NOT NULL, - `profit_local_min` float NOT NULL, - `id_currency_profit_min` int NOT NULL, - `latency_manufacture` int NOT NULL, - `quantity_min` float NOT NULL, - `quantity_max` float NOT NULL, - `quantity_step` float NOT NULL, - `quantity_stock` float NOT NULL, - `is_subscription` bit(1) NOT NULL, - `id_unit_measurement_interval_recurrence` int DEFAULT NULL, - `count_interval_recurrence` int DEFAULT NULL, - `id_access_level_required` int NOT NULL, - `id_stripe_product` varchar(100) DEFAULT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `display_order` int NOT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_permutation`), - KEY `FK_Shop_Product_Variation_Link_id_product` (`id_product`), - KEY `FK_Shop_Product_Permutation_id_unit_measurement_interval_recurrence` (`id_unit_measurement_interval_recurrence`), - KEY `FK_Shop_Product_Permutation_id_access_level_required` (`id_access_level_required`), - KEY `FK_Shop_Product_Variation_Link_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Permutation_id_access_level_required` FOREIGN KEY (`id_access_level_required`) REFERENCES `shop_access_level` (`id_access_level`), - CONSTRAINT `FK_Shop_Product_Permutation_id_unit_measurement_interval_recurrence` FOREIGN KEY (`id_unit_measurement_interval_recurrence`) REFERENCES `shop_interval_recurrence` (`id_interval`), - CONSTRAINT `FK_Shop_Product_Variation_Link_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Variation_Link_id_product` FOREIGN KEY (`id_product`) REFERENCES `shop_product` (`id_product`) ON UPDATE RESTRICT -) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_product_permutation` --- - -LOCK TABLES `shop_product_permutation` WRITE; -/*!40000 ALTER TABLE `shop_product_permutation` DISABLE KEYS */; -INSERT INTO `shop_product_permutation` VALUES (1,1,'Good Red',5,1,3,1,14,1,3,1,99,_binary '\0',NULL,NULL,1,NULL,_binary '',1,'2024-04-28 19:03:07','root@localhost',NULL),(2,1,'Good Blue',6,1,4,1,14,1,3,1,99,_binary '\0',NULL,NULL,1,NULL,_binary '',2,'2024-04-28 19:03:07','root@localhost',NULL),(3,2,'Test product describes good',10,1,5,1,14,1,2,1,99,_binary '\0',NULL,NULL,1,NULL,_binary '',3,'2024-04-28 19:03:07','root@localhost',NULL),(4,3,'Phone describes good',10,1,5,1,14,1,2,1,99,_binary '\0',NULL,NULL,1,NULL,_binary '',4,'2024-04-28 19:03:07','root@localhost',NULL),(5,4,'Laptop describes good',10,1,5,1,14,1,2,1,99,_binary '\0',NULL,NULL,1,NULL,_binary '',5,'2024-04-28 19:03:07','root@localhost',NULL),(6,5,'Smart watch describes good',10,1,5,1,14,1,2,1,99,_binary '\0',NULL,NULL,1,NULL,_binary '',6,'2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_product_permutation` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Product_Permutation` BEFORE INSERT ON `shop_product_permutation` FOR EACH ROW BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Product_Permutation` BEFORE UPDATE ON `shop_product_permutation` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Product_Permutation_Audit ( - id_permutation, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_product - SELECT NEW.id_permutation, 'id_product', OLD.id_product, NEW.id_product, NEW.id_change_set - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed id_variation - SELECT NEW.id_permutation, 'id_variation', OLD.id_variation, NEW.id_variation, NEW.id_change_set - WHERE NOT OLD.id_variation <=> NEW.id_variation - UNION - -- Changed name - SELECT NEW.id_permutation, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT (OLD.name <=> NEW.name) - UNION - */ - -- Changed description - SELECT NEW.id_permutation, 'description', OLD.description, NEW.description, NEW.id_change_set - WHERE NOT (OLD.description <=> NEW.description) - UNION - -- Changed cost_local_manufacturing - SELECT NEW.id_permutation, 'cost_local_manufacturing', CONVERT(OLD.cost_local_manufacturing, CHAR), CONVERT(NEW.cost_local_manufacturing, CHAR), NEW.id_change_set - WHERE NOT (OLD.cost_local_manufacturing <=> NEW.cost_local_manufacturing) - UNION - -- Changed id_currency_cost_manufacturing - SELECT NEW.id_permutation, 'id_currency_cost_manufacturing', CONVERT(OLD.id_currency_cost_manufacturing, CHAR), CONVERT(NEW.id_currency_cost_manufacturing, CHAR), NEW.id_change_set - WHERE NOT (OLD.id_currency_cost_manufacturing <=> NEW.id_currency_cost_manufacturing) - UNION - -- Changed profit_local_min - SELECT NEW.id_permutation, 'profit_local_min', CONVERT(OLD.profit_local_min, CHAR), CONVERT(NEW.profit_local_min, CHAR), NEW.id_change_set - WHERE NOT (OLD.profit_local_min <=> NEW.profit_local_min) - UNION - -- Changed id_currency_profit_min - SELECT NEW.id_permutation, 'id_currency_profit_min', CONVERT(OLD.id_currency_profit_min, CHAR), CONVERT(NEW.id_currency_profit_min, CHAR), NEW.id_change_set - WHERE NOT (OLD.id_currency_profit_min <=> NEW.id_currency_profit_min) - UNION - /* - -- Changed price_GBP_min - SELECT NEW.id_permutation, 'price_GBP_min', CONVERT(OLD.price_GBP_min, CHAR), CONVERT(NEW.price_GBP_min, CHAR), NEW.id_change_set - WHERE NOT (OLD.price_GBP_min <=> NEW.price_GBP_min) - UNION - */ - -- Changed latency_manufacture - SELECT NEW.id_product, 'latency_manufacture', CONVERT(OLD.latency_manufacture, CHAR), CONVERT(NEW.latency_manufacture, CHAR), NEW.id_change_set - WHERE NOT OLD.latency_manufacture <=> NEW.latency_manufacture - UNION - -- Changed quantity_min - SELECT NEW.id_product, 'quantity_min', CONVERT(OLD.quantity_min, CHAR), CONVERT(NEW.quantity_min, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_min <=> NEW.quantity_min - UNION - -- Changed quantity_max - SELECT NEW.id_product, 'quantity_max', CONVERT(OLD.quantity_max, CHAR), CONVERT(NEW.quantity_max, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - UNION - -- Changed quantity_step - SELECT NEW.id_product, 'quantity_step', CONVERT(OLD.quantity_step, CHAR), CONVERT(NEW.quantity_step, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_step <=> NEW.quantity_step - UNION - -- Changed quantity_stock - SELECT NEW.id_product, 'quantity_stock', CONVERT(OLD.quantity_stock, CHAR), CONVERT(NEW.quantity_stock, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_stock <=> NEW.quantity_stock - UNION - -- Changed is_subscription - SELECT NEW.id_product, 'is_subscription', CONVERT(CONVERT(OLD.is_subscription, SIGNED), CHAR), CONVERT(CONVERT(NEW.is_subscription, SIGNED), CHAR), NEW.id_change_set - WHERE NOT OLD.is_subscription <=> NEW.is_subscription - UNION - -- Changed id_unit_measurement_interval_recurrence - SELECT NEW.id_product, 'id_unit_measurement_interval_recurrence', CONVERT(OLD.id_unit_measurement_interval_recurrence, CHAR), CONVERT(NEW.id_unit_measurement_interval_recurrence, CHAR), NEW.id_change_set - WHERE NOT OLD.id_unit_measurement_interval_recurrence <=> NEW.id_unit_measurement_interval_recurrence - UNION - -- Changed count_interval_recurrence - SELECT NEW.id_product, 'count_interval_recurrence', CONVERT(OLD.count_interval_recurrence, CHAR), CONVERT(NEW.count_interval_recurrence, CHAR), NEW.id_change_set - WHERE NOT OLD.count_interval_recurrence <=> NEW.count_interval_recurrence - UNION - -- Changed id_stripe_product - SELECT NEW.id_permutation, 'id_stripe_product', OLD.id_stripe_product, NEW.id_stripe_product, NEW.id_change_set - WHERE NOT (OLD.id_stripe_product <=> NEW.id_stripe_product) - UNION - -- Changed active - SELECT NEW.id_permutation, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_permutation, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_product_permutation_audit` --- - -DROP TABLE IF EXISTS `shop_product_permutation_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_product_permutation_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_permutation` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Product_Permutation_Audit_id_permutation` (`id_permutation`), - KEY `FK_Shop_Product_Permutation_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Permutation_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Product_Permutation_Audit_id_permutation` FOREIGN KEY (`id_permutation`) REFERENCES `shop_product_permutation` (`id_permutation`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_product_permutation_audit` --- - -LOCK TABLES `shop_product_permutation_audit` WRITE; -/*!40000 ALTER TABLE `shop_product_permutation_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_product_permutation_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_product_permutation_variation_link` --- - -DROP TABLE IF EXISTS `shop_product_permutation_variation_link`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_product_permutation_variation_link` ( - `id_link` int NOT NULL AUTO_INCREMENT, - `id_permutation` int NOT NULL, - `id_variation` int NOT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `display_order` int NOT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_link`), - KEY `FK_Shop_Product_Permutation_Variation_Link_id_permutation` (`id_permutation`), - KEY `FK_Shop_Product_Permutation_Variation_Link_id_variation` (`id_variation`), - KEY `FK_Shop_Product_Permutation_Variation_Link_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Permutation_Variation_Link_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Permutation_Variation_Link_id_permutation` FOREIGN KEY (`id_permutation`) REFERENCES `shop_product_permutation` (`id_permutation`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Product_Permutation_Variation_Link_id_variation` FOREIGN KEY (`id_variation`) REFERENCES `shop_variation` (`id_variation`) ON UPDATE RESTRICT -) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_product_permutation_variation_link` --- - -LOCK TABLES `shop_product_permutation_variation_link` WRITE; -/*!40000 ALTER TABLE `shop_product_permutation_variation_link` DISABLE KEYS */; -INSERT INTO `shop_product_permutation_variation_link` VALUES (1,1,1,_binary '',1,'2024-04-28 19:03:07','root@localhost',NULL),(2,2,2,_binary '',2,'2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_product_permutation_variation_link` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Product_Permutation_Variation_Link` BEFORE INSERT ON `shop_product_permutation_variation_link` FOR EACH ROW BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Product_Permutation_Variation_Link` BEFORE UPDATE ON `shop_product_permutation_variation_link` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Product_Permutation_Variation_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_product - SELECT NEW.id_link, 'id_product', OLD.id_product, NEW.id_product, NEW.id_change_set - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed id_variation - SELECT NEW.id_link, 'id_variation', OLD.id_variation, NEW.id_variation, NEW.id_change_set - WHERE NOT OLD.id_variation <=> NEW.id_variation - UNION - */ - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_link, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_product_permutation_variation_link_audit` --- - -DROP TABLE IF EXISTS `shop_product_permutation_variation_link_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_product_permutation_variation_link_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_link` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Product_Permutation_Variation_Link_Audit_id_link` (`id_link`), - KEY `FK_Shop_Product_Permutation_Variation_Link_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Permutation_Variation_Link_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Product_Permutation_Variation_Link_Audit_id_link` FOREIGN KEY (`id_link`) REFERENCES `shop_product_permutation_variation_link` (`id_link`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_product_permutation_variation_link_audit` --- - -LOCK TABLES `shop_product_permutation_variation_link_audit` WRITE; -/*!40000 ALTER TABLE `shop_product_permutation_variation_link_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_product_permutation_variation_link_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_interval_recurrence` --- - -DROP TABLE IF EXISTS `shop_interval_recurrence`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_interval_recurrence` ( - `id_interval` int NOT NULL AUTO_INCREMENT, - `code` varchar(50) DEFAULT NULL, - `name` varchar(255) DEFAULT NULL, - `name_plural` varchar(256) DEFAULT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_interval`), - KEY `FK_Shop_Interval_Recurrence_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Interval_Recurrence_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`) -) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_interval_recurrence` --- - -LOCK TABLES `shop_interval_recurrence` WRITE; -/*!40000 ALTER TABLE `shop_interval_recurrence` DISABLE KEYS */; -INSERT INTO `shop_interval_recurrence` VALUES (1,'WEEK','Week','Weeks',_binary '','2024-04-28 19:03:07','root@localhost',NULL),(2,'MONTH','Month','Months',_binary '','2024-04-28 19:03:07','root@localhost',NULL),(3,'YEAR','Year','Years',_binary '','2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_interval_recurrence` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Interval_Recurrence` BEFORE INSERT ON `shop_interval_recurrence` FOR EACH ROW BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Interval_Recurrence` BEFORE UPDATE ON `shop_interval_recurrence` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Interval_Recurrence_Audit ( - id_interval, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_interval, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_interval, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed name_plural - SELECT NEW.id_interval, 'name_plural', OLD.name_plural, NEW.name_plural, NEW.id_change_set - WHERE NOT OLD.name_plural <=> NEW.name_plural - UNION - -- Changed name - SELECT NEW.id_interval, 'active', OLD.active, NEW.active, NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_interval_recurrence_audit` --- - -DROP TABLE IF EXISTS `shop_interval_recurrence_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_interval_recurrence_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_interval` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(256) DEFAULT NULL, - `value_new` varchar(256) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Interval_Recurrence_Audit_id_interval` (`id_interval`), - KEY `FK_Shop_Interval_Recurrence_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Interval_Recurrence_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Interval_Recurrence_Audit_id_interval` FOREIGN KEY (`id_interval`) REFERENCES `shop_interval_recurrence` (`id_interval`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_interval_recurrence_audit` --- - -LOCK TABLES `shop_interval_recurrence_audit` WRITE; -/*!40000 ALTER TABLE `shop_interval_recurrence_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_interval_recurrence_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_region` --- - -DROP TABLE IF EXISTS `shop_region`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_region` ( - `id_region` int NOT NULL AUTO_INCREMENT, - `code` varchar(50) NOT NULL, - `name` varchar(200) NOT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `display_order` int NOT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_region`), - KEY `FK_Shop_Region_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Region_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`) -) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_region` --- - -LOCK TABLES `shop_region` WRITE; -/*!40000 ALTER TABLE `shop_region` DISABLE KEYS */; -INSERT INTO `shop_region` VALUES (1,'UK','United Kingdom',_binary '',1,'2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_region` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Region` BEFORE INSERT ON `shop_region` FOR EACH ROW BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Region` BEFORE UPDATE ON `shop_region` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Region_Audit ( - id_region, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_region, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_region, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed active - SELECT NEW.id_region, 'active', CONVERT(OLD.active, CHAR), CONVERT(NEW.active, CHAR), NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - UNION - -- Changed display_order - SELECT NEW.id_region, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_region_audit` --- - -DROP TABLE IF EXISTS `shop_region_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_region_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_region` int NOT NULL, - `name_field` varchar(64) NOT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Region_Audit_id_region` (`id_region`), - KEY `FK_Shop_Region_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Region_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Region_Audit_id_region` FOREIGN KEY (`id_region`) REFERENCES `shop_region` (`id_region`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_region_audit` --- - -LOCK TABLES `shop_region_audit` WRITE; -/*!40000 ALTER TABLE `shop_region_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_region_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_region_branch` --- - -DROP TABLE IF EXISTS `shop_region_branch`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_region_branch` ( - `id_branch` int NOT NULL AUTO_INCREMENT, - `id_region_parent` int NOT NULL, - `id_region_child` int NOT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `display_order` int NOT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_branch`), - KEY `FK_Shop_Region_Branch_id_region_parent` (`id_region_parent`), - KEY `FK_Shop_Region_Branch_id_region_child` (`id_region_child`), - KEY `FK_Shop_Region_Branch_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Region_Branch_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Region_Branch_id_region_child` FOREIGN KEY (`id_region_child`) REFERENCES `shop_region` (`id_region`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Region_Branch_id_region_parent` FOREIGN KEY (`id_region_parent`) REFERENCES `shop_region` (`id_region`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_region_branch` --- - -LOCK TABLES `shop_region_branch` WRITE; -/*!40000 ALTER TABLE `shop_region_branch` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_region_branch` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Region_Branch` BEFORE INSERT ON `shop_region_branch` FOR EACH ROW BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Region_Branch` BEFORE UPDATE ON `shop_region_branch` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Region_Branch_Audit ( - id_branch, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed depth - SELECT NEW.id_branch, 'depth', CONVERT(OLD.depth, CHAR), CONVERT(NEW.depth, CHAR), NEW.id_change_set - WHERE NOT OLD.depth <=> NEW.depth - UNION - */ - -- Changed active - SELECT NEW.id_branch, 'active', CONVERT(OLD.active, CHAR), CONVERT(NEW.active, CHAR), NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - UNION - -- Changed display_order - SELECT NEW.id_branch, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_region_branch_audit` --- - -DROP TABLE IF EXISTS `shop_region_branch_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_region_branch_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_branch` int NOT NULL, - `name_field` varchar(64) NOT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Region_Branch_Audit_id_branch` (`id_branch`), - KEY `FK_Shop_Region_Branch_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Region_Branch_Audit_id_branch` FOREIGN KEY (`id_branch`) REFERENCES `shop_region_branch` (`id_branch`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Region_Branch_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_region_branch_audit` --- - -LOCK TABLES `shop_region_branch_audit` WRITE; -/*!40000 ALTER TABLE `shop_region_branch_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_region_branch_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_role` --- - -DROP TABLE IF EXISTS `shop_role`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_role` ( - `id_role` int NOT NULL AUTO_INCREMENT, - `code` varchar(50) DEFAULT NULL, - `name` varchar(255) DEFAULT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `display_order` int NOT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_role`), - KEY `FK_Shop_Role_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Role_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_user_change_set` (`id_change_set`) -) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_role` --- - -LOCK TABLES `shop_role` WRITE; -/*!40000 ALTER TABLE `shop_role` DISABLE KEYS */; -INSERT INTO `shop_role` VALUES (1,'DIRECTOR','Director',_binary '',1,'2024-04-28 19:03:07','root@localhost',NULL),(2,'USER','User',_binary '',2,'2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_role` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Role` BEFORE INSERT ON `shop_role` FOR EACH ROW BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Role` BEFORE UPDATE ON `shop_role` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Role_Audit ( - id_role, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_role, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_role, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed active - SELECT NEW.id_role, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_role, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_role_audit` --- - -DROP TABLE IF EXISTS `shop_role_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_role_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_role` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Role_Audit_id_role` (`id_role`), - KEY `FK_Shop_Role_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Role_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_user_change_set` (`id_change_set`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Role_Audit_id_role` FOREIGN KEY (`id_role`) REFERENCES `shop_role` (`id_role`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_role_audit` --- - -LOCK TABLES `shop_role_audit` WRITE; -/*!40000 ALTER TABLE `shop_role_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_role_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_role_permission_link` --- - -DROP TABLE IF EXISTS `shop_role_permission_link`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_role_permission_link` ( - `id_link` int NOT NULL AUTO_INCREMENT, - `id_role` int DEFAULT NULL, - `id_permission` int DEFAULT NULL, - `id_access_level` int DEFAULT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_link`), - KEY `FK_Shop_Role_Permission_Link_id_role` (`id_role`), - KEY `FK_Shop_Role_Permission_Link_id_permission` (`id_permission`), - KEY `FK_Shop_Role_Permission_Link_id_access_level` (`id_access_level`), - KEY `FK_Shop_Role_Permission_Link_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Role_Permission_Link_id_access_level` FOREIGN KEY (`id_access_level`) REFERENCES `shop_access_level` (`id_access_level`), - CONSTRAINT `FK_Shop_Role_Permission_Link_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_user_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Role_Permission_Link_id_permission` FOREIGN KEY (`id_permission`) REFERENCES `shop_permission` (`id_permission`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Role_Permission_Link_id_role` FOREIGN KEY (`id_role`) REFERENCES `shop_role` (`id_role`) ON UPDATE RESTRICT -) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_role_permission_link` --- - -LOCK TABLES `shop_role_permission_link` WRITE; -/*!40000 ALTER TABLE `shop_role_permission_link` DISABLE KEYS */; -INSERT INTO `shop_role_permission_link` VALUES (1,1,1,3,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(2,1,2,3,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(3,1,3,3,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(4,1,4,3,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(5,1,5,3,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(6,2,1,1,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(7,2,2,1,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(8,2,3,1,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(9,2,4,1,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(10,2,5,1,_binary '','2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_role_permission_link` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Role_Permission_Link` BEFORE INSERT ON `shop_role_permission_link` FOR EACH ROW BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Role_Permission_Link` BEFORE UPDATE ON `shop_role_permission_link` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Role_Permission_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_role - SELECT NEW.id_link, 'id_role', CONVERT(OLD.id_role, CHAR), CONVERT(NEW.id_role, CHAR), NEW.id_change_set - WHERE NOT OLD.id_role <=> NEW.id_role - UNION - -- Changed id_permission - SELECT NEW.id_link, 'id_permission', CONVERT(OLD.id_permission, CHAR), CONVERT(NEW.id_permission, CHAR), NEW.id_change_set - WHERE NOT OLD.id_permission <=> NEW.id_permission - UNION - */ - -- Changed id_access_level - SELECT NEW.id_link, 'id_access_level', CONVERT(OLD.id_access_level, CHAR), CONVERT(NEW.id_access_level, CHAR), NEW.id_change_set - WHERE NOT OLD.id_access_level <=> NEW.id_access_level - UNION - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_role_permission_link_audit` --- - -DROP TABLE IF EXISTS `shop_role_permission_link_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_role_permission_link_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_link` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Role_Permission_Link_Audit_id_link` (`id_link`), - KEY `FK_Shop_Role_Permission_Link_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Role_Permission_Link_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_user_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Role_Permission_Link_Audit_id_link` FOREIGN KEY (`id_link`) REFERENCES `shop_role_permission_link` (`id_link`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_role_permission_link_audit` --- - -LOCK TABLES `shop_role_permission_link_audit` WRITE; -/*!40000 ALTER TABLE `shop_role_permission_link_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_role_permission_link_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_tax_or_surcharge` --- - -DROP TABLE IF EXISTS `shop_tax_or_surcharge`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_tax_or_surcharge` ( - `id_tax` int NOT NULL AUTO_INCREMENT, - `code` varchar(50) NOT NULL, - `name` varchar(200) NOT NULL, - `id_region_buyer` int NOT NULL, - `id_region_seller` int NOT NULL, - `id_currency` int DEFAULT NULL, - `fixed_fee` float NOT NULL DEFAULT '0', - `multiplier` float NOT NULL DEFAULT '1', - `apply_fixed_fee_before_multiplier` bit(1) DEFAULT b'1', - `quantity_min` float NOT NULL DEFAULT '0', - `quantity_max` float NOT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `display_order` int NOT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_tax`), - KEY `FK_Shop_Tax_Or_Surcharge_id_region_buyer` (`id_region_buyer`), - KEY `FK_Shop_Tax_Or_Surcharge_id_region_seller` (`id_region_seller`), - KEY `FK_Shop_Tax_Or_Surcharge_id_currency` (`id_currency`), - KEY `FK_Shop_Tax_Or_Surcharge_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Tax_Or_Surcharge_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Tax_Or_Surcharge_id_currency` FOREIGN KEY (`id_currency`) REFERENCES `shop_currency` (`id_currency`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Tax_Or_Surcharge_id_region_buyer` FOREIGN KEY (`id_region_buyer`) REFERENCES `shop_region` (`id_region`), - CONSTRAINT `FK_Shop_Tax_Or_Surcharge_id_region_seller` FOREIGN KEY (`id_region_seller`) REFERENCES `shop_region` (`id_region`), - CONSTRAINT `shop_tax_or_surcharge_chk_1` CHECK ((`multiplier` > 0)) -) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_tax_or_surcharge` --- - -LOCK TABLES `shop_tax_or_surcharge` WRITE; -/*!40000 ALTER TABLE `shop_tax_or_surcharge` DISABLE KEYS */; -INSERT INTO `shop_tax_or_surcharge` VALUES (1,'VAT','Value Added Tax',1,1,NULL,0,0.2,_binary '',0,1,_binary '',1,'2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_tax_or_surcharge` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Tax_Or_Surcharge` BEFORE INSERT ON `shop_tax_or_surcharge` FOR EACH ROW BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Tax_Or_Surcharge` BEFORE UPDATE ON `shop_tax_or_surcharge` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Tax_Or_Surcharge_Audit ( - id_tax, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_tax, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_tax, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed fixed_fee - SELECT NEW.id_tax, 'fixed_fee', OLD.fixed_fee, NEW.fixed_fee, NEW.id_change_set - WHERE NOT OLD.fixed_fee <=> NEW.fixed_fee - UNION - -- Changed multiplier - SELECT NEW.id_tax, 'multiplier', OLD.multiplier, NEW.multiplier, NEW.id_change_set - WHERE NOT OLD.multiplier <=> NEW.multiplier - UNION - -- Changed apply_fixed_fee_before_multiplier - SELECT NEW.id_tax, 'apply_fixed_fee_before_multiplier', CONVERT(CONVERT(OLD.apply_fixed_fee_before_multiplier, SIGNED), CHAR), CONVERT(CONVERT(NEW.apply_fixed_fee_before_multiplier, SIGNED), CHAR), NEW.id_change_set - WHERE NOT OLD.apply_fixed_fee_before_multiplier <=> NEW.apply_fixed_fee_before_multiplier - UNION - -- Changed quantity_min - SELECT NEW.id_tax, 'quantity_min', OLD.quantity_min, NEW.quantity_min, NEW.id_change_set - WHERE NOT OLD.quantity_min <=> NEW.quantity_min - UNION - -- Changed quantity_max - SELECT NEW.id_tax, 'quantity_max', OLD.quantity_max, NEW.quantity_max, NEW.id_change_set - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - UNION - -- Changed display_order - SELECT NEW.id_tax, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - UNION - -- Changed active - SELECT NEW.id_tax, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_tax_or_surcharge_audit` --- - -DROP TABLE IF EXISTS `shop_tax_or_surcharge_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_tax_or_surcharge_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_tax` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Tax_Or_Surcharge_Audit_id_discount` (`id_tax`), - KEY `FK_Shop_Tax_Or_Surcharge_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Tax_Or_Surcharge_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Tax_Or_Surcharge_Audit_id_discount` FOREIGN KEY (`id_tax`) REFERENCES `shop_tax_or_surcharge` (`id_tax`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_tax_or_surcharge_audit` --- - -LOCK TABLES `shop_tax_or_surcharge_audit` WRITE; -/*!40000 ALTER TABLE `shop_tax_or_surcharge_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_tax_or_surcharge_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_user` --- - -DROP TABLE IF EXISTS `shop_user`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_user` ( - `id_user` varchar(200) NOT NULL, - `name` varchar(255) NOT NULL, - `email` varchar(254) NOT NULL, - `email_verified` bit(1) NOT NULL DEFAULT b'0', - `is_super_user` bit(1) NOT NULL DEFAULT b'0', - `active` bit(1) NOT NULL DEFAULT b'1', - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_user`), - KEY `FK_Shop_User_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_User_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_user_change_set` (`id_change_set`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_user` --- - -LOCK TABLES `shop_user` WRITE; -/*!40000 ALTER TABLE `shop_user` DISABLE KEYS */; -INSERT INTO `shop_user` VALUES ('auth0|6582b95c895d09a70ba10fef','Teddy','edward.middletonsmith@gmail.com',_binary '\0',_binary '',_binary '','2024-04-28 19:03:07','root@localhost',NULL),('parts_guest','Guest','',_binary '\0',_binary '\0',_binary '','2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_user` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_User` BEFORE INSERT ON `shop_user` FOR EACH ROW BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_User` BEFORE UPDATE ON `shop_user` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_User_Audit ( - id_user, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed name - SELECT NEW.id_user, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT (OLD.name <=> NEW.name) - UNION - -- Changed is_super_user - SELECT NEW.id_user, 'is_super_user', CONVERT(CONVERT(OLD.is_super_user, SIGNED), CHAR), CONVERT(CONVERT(NEW.is_super_user, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.is_super_user <=> NEW.is_super_user) - UNION - -- Changed active - SELECT NEW.id_user, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_user_audit` --- - -DROP TABLE IF EXISTS `shop_user_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_user_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_user` varchar(200) NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_User_Audit_id_user` (`id_user`), - KEY `FK_Shop_User_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_User_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_user_change_set` (`id_change_set`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_User_Audit_id_user` FOREIGN KEY (`id_user`) REFERENCES `shop_user` (`id_user`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_user_audit` --- - -LOCK TABLES `shop_user_audit` WRITE; -/*!40000 ALTER TABLE `shop_user_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_user_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_user_basket` --- - -DROP TABLE IF EXISTS `shop_user_basket`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_user_basket` ( - `id_item` int NOT NULL AUTO_INCREMENT, - `id_user` varchar(200) NOT NULL, - `id_product` int NOT NULL, - `id_permutation` int DEFAULT NULL, - `quantity` int NOT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set_user` int DEFAULT NULL, - PRIMARY KEY (`id_item`), - KEY `FK_Shop_User_Basket_id_user` (`id_user`), - KEY `FK_Shop_User_Basket_id_product` (`id_product`), - KEY `FK_Shop_User_Basket_id_permutation` (`id_permutation`), - KEY `FK_Shop_User_Basket_id_change_set_user` (`id_change_set_user`), - CONSTRAINT `FK_Shop_User_Basket_id_change_set_user` FOREIGN KEY (`id_change_set_user`) REFERENCES `shop_user_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_User_Basket_id_permutation` FOREIGN KEY (`id_permutation`) REFERENCES `shop_product_permutation` (`id_permutation`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_User_Basket_id_product` FOREIGN KEY (`id_product`) REFERENCES `shop_product` (`id_product`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_User_Basket_id_user` FOREIGN KEY (`id_user`) REFERENCES `shop_user` (`id_user`) ON UPDATE RESTRICT -) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_user_basket` --- - -LOCK TABLES `shop_user_basket` WRITE; -/*!40000 ALTER TABLE `shop_user_basket` DISABLE KEYS */; -INSERT INTO `shop_user_basket` VALUES (1,'auth0|6582b95c895d09a70ba10fef',1,1,69,_binary '','2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_user_basket` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_User_Basket` BEFORE INSERT ON `shop_user_basket` FOR EACH ROW BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_User_Basket` BEFORE UPDATE ON `shop_user_basket` FOR EACH ROW BEGIN - IF NEW.id_change_set_user <=> OLD.id_change_set_user THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_User_Basket_Audit ( - id_item, - name_field, - value_prev, - value_new, - id_change_set_user - ) - -- Changed id_user - SELECT NEW.id_item, 'id_user', OLD.id_user, NEW.id_user, NEW.id_change_set_user - WHERE NOT OLD.id_user <=> NEW.id_user - UNION - -- Changed id_product - SELECT NEW.id_item, 'id_product', OLD.id_product, NEW.id_product, NEW.id_change_set_user - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed quantity - SELECT NEW.id_item, 'quantity', CONVERT(OLD.quantity, CHAR), CONVERT(NEW.quantity, CHAR), NEW.id_change_set_user - WHERE NOT (OLD.quantity <=> NEW.quantity) - UNION - -- Changed active - SELECT NEW.id_item, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set_user - WHERE NOT (OLD.active <=> NEW.active) - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_user_basket_audit` --- - -DROP TABLE IF EXISTS `shop_user_basket_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_user_basket_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_item` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set_user` int DEFAULT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_User_Basket_Audit_id_link` (`id_item`), - KEY `FK_Shop_User_Basket_Audit_id_change_set_user` (`id_change_set_user`), - CONSTRAINT `FK_Shop_User_Basket_Audit_id_change_set_user` FOREIGN KEY (`id_change_set_user`) REFERENCES `shop_user_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_User_Basket_Audit_id_link` FOREIGN KEY (`id_item`) REFERENCES `shop_user_basket` (`id_item`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_user_basket_audit` --- - -LOCK TABLES `shop_user_basket_audit` WRITE; -/*!40000 ALTER TABLE `shop_user_basket_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_user_basket_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_user_change_set` --- - -DROP TABLE IF EXISTS `shop_user_change_set`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_user_change_set` ( - `id_change_set` int NOT NULL AUTO_INCREMENT, - `comment` varchar(500) DEFAULT NULL, - `updated_last_on` datetime DEFAULT NULL, - `updated_last_by` varchar(100) DEFAULT NULL, - PRIMARY KEY (`id_change_set`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_user_change_set` --- - -LOCK TABLES `shop_user_change_set` WRITE; -/*!40000 ALTER TABLE `shop_user_change_set` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_user_change_set` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_User_Change_Set` BEFORE INSERT ON `shop_user_change_set` FOR EACH ROW BEGIN - IF NEW.updated_last_on <=> NULL THEN - SET NEW.updated_last_on = NOW(); - END IF; - IF NEW.updated_last_by <=> NULL THEN - SET NEW.updated_last_by = CURRENT_USER(); - END IF; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_user_order` --- - -DROP TABLE IF EXISTS `shop_user_order`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_user_order` ( - `id_order` int NOT NULL AUTO_INCREMENT, - `id_user` varchar(200) NOT NULL, - `value_total` float DEFAULT NULL, - `id_order_status` int NOT NULL, - `id_checkout_session` varchar(200) NOT NULL, - `id_currency` int NOT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set_user` int DEFAULT NULL, - PRIMARY KEY (`id_order`), - KEY `FK_Shop_User_Order_id_user` (`id_user`), - KEY `FK_Shop_User_Order_id_order_status` (`id_order_status`), - KEY `FK_Shop_User_Order_id_currency` (`id_currency`), - KEY `FK_Shop_User_Order_id_change_set_user` (`id_change_set_user`), - CONSTRAINT `FK_Shop_User_Order_id_change_set_user` FOREIGN KEY (`id_change_set_user`) REFERENCES `shop_user_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_User_Order_id_currency` FOREIGN KEY (`id_currency`) REFERENCES `shop_currency` (`id_currency`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_User_Order_id_order_status` FOREIGN KEY (`id_order_status`) REFERENCES `shop_user_order_status` (`id_status`), - CONSTRAINT `FK_Shop_User_Order_id_user` FOREIGN KEY (`id_user`) REFERENCES `shop_user` (`id_user`) ON UPDATE RESTRICT -) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_user_order` --- - -LOCK TABLES `shop_user_order` WRITE; -/*!40000 ALTER TABLE `shop_user_order` DISABLE KEYS */; -INSERT INTO `shop_user_order` VALUES (1,'auth0|6582b95c895d09a70ba10fef',25,1,'noods',1,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(2,'auth0|6582b95c895d09a70ba10fef',25,1,'noods',1,_binary '','2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_user_order` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_User_Order` BEFORE INSERT ON `shop_user_order` FOR EACH ROW BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_User_Order` BEFORE UPDATE ON `shop_user_order` FOR EACH ROW BEGIN - IF OLD.id_change_set_user <=> NEW.id_change_set_user THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - IF NOT (NEW.id_checkout_session <=> OLD.id_checkout_session) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Checkout session ID must not change.'; - END IF; - - INSERT INTO Shop_User_Order_Audit ( - id_order, - name_field, - value_prev, - value_new, - id_change_set_user - ) - -- Changed id_user - SELECT NEW.id_order, 'id_user', OLD.id_user, NEW.id_user, NEW.id_change_set_user - WHERE NOT OLD.id_user <=> NEW.id_user - UNION - -- Changed value_total - SELECT NEW.id_order, 'value_total', CONVERT(OLD.value_total, CHAR), CONVERT(NEW.value_total, CHAR), NEW.id_change_set_user - WHERE NOT (OLD.value_total <=> NEW.value_total) - UNION - -- Changed id_order_status - SELECT NEW.id_order, 'id_order_status', CONVERT(OLD.id_order_status, CHAR), CONVERT(NEW.id_order_status, CHAR), NEW.id_change_set_user - WHERE NOT (OLD.id_order_status <=> NEW.id_order_status) - UNION - -- Changed id_checkout_session - SELECT NEW.id_order, 'id_checkout_session', OLD.id_checkout_session, NEW.id_checkout_session, NEW.id_change_set_user - WHERE NOT (OLD.id_checkout_session <=> NEW.id_checkout_session) - UNION - -- Changed active - SELECT NEW.id_order, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set_user - WHERE NOT (OLD.active <=> NEW.active) - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_user_order_audit` --- - -DROP TABLE IF EXISTS `shop_user_order_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_user_order_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_order` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set_user` int DEFAULT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_User_Order_Audit_id_order` (`id_order`), - KEY `FK_Shop_User_Order_Audit_id_change_set_user` (`id_change_set_user`), - CONSTRAINT `FK_Shop_User_Order_Audit_id_change_set_user` FOREIGN KEY (`id_change_set_user`) REFERENCES `shop_user_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_User_Order_Audit_id_order` FOREIGN KEY (`id_order`) REFERENCES `shop_user_order` (`id_order`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_user_order_audit` --- - -LOCK TABLES `shop_user_order_audit` WRITE; -/*!40000 ALTER TABLE `shop_user_order_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_user_order_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_user_order_product_link` --- - -DROP TABLE IF EXISTS `shop_user_order_product_link`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_user_order_product_link` ( - `id_link` int NOT NULL AUTO_INCREMENT, - `id_order` int NOT NULL, - `id_product` int NOT NULL, - `id_permutation` int DEFAULT NULL, - `quantity` float NOT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_link`), - KEY `FK_Shop_User_Order_Product_Link_id_order` (`id_order`), - KEY `FK_Shop_User_Order_Product_Link_id_product` (`id_product`), - KEY `FK_Shop_User_Order_Product_Link_id_permutation` (`id_permutation`), - KEY `FK_Shop_User_Order_Product_Link_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_User_Order_Product_Link_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_user_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_User_Order_Product_Link_id_order` FOREIGN KEY (`id_order`) REFERENCES `shop_user_order` (`id_order`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_User_Order_Product_Link_id_permutation` FOREIGN KEY (`id_permutation`) REFERENCES `shop_product_permutation` (`id_permutation`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_User_Order_Product_Link_id_product` FOREIGN KEY (`id_product`) REFERENCES `shop_product` (`id_product`) ON UPDATE RESTRICT -) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_user_order_product_link` --- - -LOCK TABLES `shop_user_order_product_link` WRITE; -/*!40000 ALTER TABLE `shop_user_order_product_link` DISABLE KEYS */; -INSERT INTO `shop_user_order_product_link` VALUES (1,1,1,1,69,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(2,1,2,NULL,69,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(3,1,1,2,69,_binary '','2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_user_order_product_link` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_User_Order_Product_Link` BEFORE INSERT ON `shop_user_order_product_link` FOR EACH ROW BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_User_Order_Product_Link` BEFORE UPDATE ON `shop_user_order_product_link` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_User_Order_Product_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_product - SELECT NEW.id_link, 'active', CONVERT(OLD.id_product, CHAR), CONVERT(NEW.id_product, CHAR), NEW.id_change_set - WHERE NOT (OLD.id_product <=> NEW.id_product) - UNION - -- Changed quantity - SELECT NEW.id_link, 'quantity', CONVERT(OLD.quantity, CHAR), CONVERT(NEW.quantity, CHAR), NEW.id_change_set - WHERE NOT (OLD.quantity <=> NEW.quantity) - UNION - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_user_order_product_link_audit` --- - -DROP TABLE IF EXISTS `shop_user_order_product_link_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_user_order_product_link_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_link` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_User_Order_Product_Link_Audit_id_link` (`id_link`), - KEY `FK_Shop_User_Order_Product_Link_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_User_Order_Product_Link_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_user_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_User_Order_Product_Link_Audit_id_link` FOREIGN KEY (`id_link`) REFERENCES `shop_user_order_product_link` (`id_link`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_user_order_product_link_audit` --- - -LOCK TABLES `shop_user_order_product_link_audit` WRITE; -/*!40000 ALTER TABLE `shop_user_order_product_link_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_user_order_product_link_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_user_order_status` --- - -DROP TABLE IF EXISTS `shop_user_order_status`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_user_order_status` ( - `id_status` int NOT NULL AUTO_INCREMENT, - `code` varchar(50) DEFAULT NULL, - `name` varchar(255) DEFAULT NULL, - `name_plural` varchar(256) DEFAULT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `display_order` int NOT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_status`), - KEY `FK_Shop_User_Order_Status_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_User_Order_Status_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_user_change_set` (`id_change_set`) -) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_user_order_status` --- - -LOCK TABLES `shop_user_order_status` WRITE; -/*!40000 ALTER TABLE `shop_user_order_status` DISABLE KEYS */; -INSERT INTO `shop_user_order_status` VALUES (1,'SUCCESS','Success','Successes',_binary '',1,'2024-04-28 19:03:07','root@localhost',NULL),(2,'FAIL','Failure','Failures',_binary '',2,'2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_user_order_status` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_User_Order_Status` BEFORE INSERT ON `shop_user_order_status` FOR EACH ROW BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_User_Order_Status` BEFORE UPDATE ON `shop_user_order_status` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_User_Order_Status_Audit ( - id_Status, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_Status, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_Status, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed name_plural - SELECT NEW.id_Status, 'name_plural', OLD.name_plural, NEW.name_plural, NEW.id_change_set - WHERE NOT OLD.name_plural <=> NEW.name_plural - UNION - -- Changed active - SELECT NEW.id_Status, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_Status, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_user_order_status_audit` --- - -DROP TABLE IF EXISTS `shop_user_order_status_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_user_order_status_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_status` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_User_Order_Status_Audit_id_status` (`id_status`), - KEY `FK_Shop_User_Order_Status_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_User_Order_Status_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_User_Order_Status_Audit_id_status` FOREIGN KEY (`id_status`) REFERENCES `shop_user_order_status` (`id_status`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_user_order_status_audit` --- - -LOCK TABLES `shop_user_order_status_audit` WRITE; -/*!40000 ALTER TABLE `shop_user_order_status_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_user_order_status_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_user_role_link` --- - -DROP TABLE IF EXISTS `shop_user_role_link`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_user_role_link` ( - `id_link` int NOT NULL AUTO_INCREMENT, - `id_user` varchar(200) NOT NULL, - `id_role` int NOT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_link`), - KEY `FK_Shop_User_Role_Link_id_user` (`id_user`), - KEY `FK_Shop_User_Role_Link_id_role` (`id_role`), - KEY `FK_Shop_User_Role_Link_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_User_Role_Link_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_user_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_User_Role_Link_id_role` FOREIGN KEY (`id_role`) REFERENCES `shop_role` (`id_role`), - CONSTRAINT `FK_Shop_User_Role_Link_id_user` FOREIGN KEY (`id_user`) REFERENCES `shop_user` (`id_user`) ON UPDATE RESTRICT -) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_user_role_link` --- - -LOCK TABLES `shop_user_role_link` WRITE; -/*!40000 ALTER TABLE `shop_user_role_link` DISABLE KEYS */; -INSERT INTO `shop_user_role_link` VALUES (1,'auth0|6582b95c895d09a70ba10fef',1,_binary '','2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_user_role_link` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_User_Role_Link` BEFORE INSERT ON `shop_user_role_link` FOR EACH ROW BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_User_Role_Link` BEFORE UPDATE ON `shop_user_role_link` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_User_Role_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_user_role_link_audit` --- - -DROP TABLE IF EXISTS `shop_user_role_link_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_user_role_link_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_link` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_User_Role_Link_Audit_id_link` (`id_link`), - KEY `FK_Shop_User_Role_Link_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_User_Role_Link_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_user_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_User_Role_Link_Audit_id_link` FOREIGN KEY (`id_link`) REFERENCES `shop_user_role_link` (`id_link`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_user_role_link_audit` --- - -LOCK TABLES `shop_user_role_link_audit` WRITE; -/*!40000 ALTER TABLE `shop_user_role_link_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_user_role_link_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_variation` --- - -DROP TABLE IF EXISTS `shop_variation`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_variation` ( - `id_variation` int NOT NULL AUTO_INCREMENT, - `id_type` int NOT NULL, - `code` varchar(50) DEFAULT NULL, - `name` varchar(255) DEFAULT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `display_order` int NOT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_variation`), - KEY `FK_Shop_Variation_id_type` (`id_type`), - KEY `FK_Shop_Variation_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Variation_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Variation_id_type` FOREIGN KEY (`id_type`) REFERENCES `shop_variation_type` (`id_type`) ON UPDATE RESTRICT -) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_variation` --- - -LOCK TABLES `shop_variation` WRITE; -/*!40000 ALTER TABLE `shop_variation` DISABLE KEYS */; -INSERT INTO `shop_variation` VALUES (1,1,'RED','Red',_binary '',1,'2024-04-28 19:03:07','root@localhost',NULL),(2,1,'BLUE','Blue',_binary '',2,'2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_variation` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Variation` BEFORE INSERT ON `shop_variation` FOR EACH ROW BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Variation` BEFORE UPDATE ON `shop_variation` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Variation_Audit ( - id_variation, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_variation, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_variation, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed active - SELECT NEW.id_variation, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_variation, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_variation_audit` --- - -DROP TABLE IF EXISTS `shop_variation_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_variation_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_variation` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Variation_Audit_id_variation` (`id_variation`), - KEY `FK_Shop_Variation_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Variation_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Variation_Audit_id_variation` FOREIGN KEY (`id_variation`) REFERENCES `shop_variation` (`id_variation`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_variation_audit` --- - -LOCK TABLES `shop_variation_audit` WRITE; -/*!40000 ALTER TABLE `shop_variation_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_variation_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_variation_type` --- - -DROP TABLE IF EXISTS `shop_variation_type`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_variation_type` ( - `id_type` int NOT NULL AUTO_INCREMENT, - `code` varchar(50) DEFAULT NULL, - `name` varchar(255) DEFAULT NULL, - `name_plural` varchar(256) DEFAULT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `display_order` int NOT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_type`), - KEY `FK_Shop_Variation_Type_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Variation_Type_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`) -) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_variation_type` --- - -LOCK TABLES `shop_variation_type` WRITE; -/*!40000 ALTER TABLE `shop_variation_type` DISABLE KEYS */; -INSERT INTO `shop_variation_type` VALUES (1,'COLOUR','Colour','Colours',_binary '',1,'2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_variation_type` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Variation_Type` BEFORE INSERT ON `shop_variation_type` FOR EACH ROW BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Variation_Type` BEFORE UPDATE ON `shop_variation_type` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Variation_Type_Audit ( - id_type, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_type, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_type, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed name_plural - SELECT NEW.id_type, 'name_plural', OLD.name_plural, NEW.name_plural, NEW.id_change_set - WHERE NOT OLD.name_plural <=> NEW.name_plural - UNION - -- Changed active - SELECT NEW.id_type, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_type, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_variation_type_audit` --- - -DROP TABLE IF EXISTS `shop_variation_type_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_variation_type_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_type` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Variation_Type_Audit_id_type` (`id_type`), - KEY `FK_Shop_Variation_Type_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Variation_Type_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Variation_Type_Audit_id_type` FOREIGN KEY (`id_type`) REFERENCES `shop_variation_type` (`id_type`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_variation_type_audit` --- - -LOCK TABLES `shop_variation_type_audit` WRITE; -/*!40000 ALTER TABLE `shop_variation_type_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_variation_type_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `tmp_msg_error` --- - -DROP TABLE IF EXISTS `tmp_msg_error`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `tmp_msg_error` ( - `display_order` int NOT NULL AUTO_INCREMENT, - `guid` varchar(36) NOT NULL, - `id_type` int NOT NULL, - `msg` varchar(4000) NOT NULL, - PRIMARY KEY (`display_order`), - KEY `FK_tmp_Msg_Error_id_type` (`id_type`), - CONSTRAINT `FK_tmp_Msg_Error_id_type` FOREIGN KEY (`id_type`) REFERENCES `shop_msg_error_type` (`id_type`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `tmp_msg_error` --- - -LOCK TABLES `tmp_msg_error` WRITE; -/*!40000 ALTER TABLE `tmp_msg_error` DISABLE KEYS */; -/*!40000 ALTER TABLE `tmp_msg_error` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping events for database 'partsltd_prod' --- - --- --- Dumping routines for database 'partsltd_prod' --- -/*!50003 DROP PROCEDURE IF EXISTS `p_shop_edit_user` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `p_shop_edit_user`( - IN a_id_user INT, - IN a_name VARCHAR(255), - IN a_email VARCHAR(254), - IN a_email_verified BIT -) -BEGIN - -- Argument redeclaration - -- Variable declaration - DECLARE v_has_filter_user BIT; - -- DECLARE v_now DATETIME; - - - -- Argument validation + default values - IF a_id_user IS NULL THEN - SET a_id_user = ''; - ELSE - SET a_id_user = TRIM(a_id_user); - END IF; - IF a_name IS NULL THEN - SET a_name = ''; - ELSE - SET a_name = TRIM(a_name); - END IF; - IF a_email IS NULL THEN - SET a_email = ''; - ELSE - SET a_email = TRIM(a_email); - END IF; - IF a_email_verified IS NULL THEN - SET a_email_verified = 0; - END IF; - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Msg_Error; - DROP TABLE IF EXISTS tmp_Shop_User; - - CREATE TABLE tmp_Shop_User ( - id_user INT NOT NULL, - CONSTRAINT FK_tmp_Shop_User_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user), - active BIT NOT NULL - ); - - CREATE TABLE tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - id_type INT NOT NULL, - -- code VARCHAR(50) NOT NULL, - -- CONSTRAINT chk_tmp_Msg_Error_code CHECK (code IN (SELECT code FROM Shop_Msg_Error_Type)), - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type(id_type), - msg VARCHAR(4000) NOT NULL - ); - - - -- Parse filters - SET v_has_filter_user = CASE WHEN a_id_user = '' THEN 0 ELSE 1 END; - - - -- User - IF v_has_filter_user THEN - INSERT INTO tmp_Shop_User ( - id_user, - active - ) - SELECT id_user, - active - FROM Shop_User - WHERE id_user LIKE CONCAT('%', a_id_user, '%') - AND active - LIMIT 1 - ; - - IF NOT EXISTS (SELECT id_user FROM tmp_Shop_User LIMIT 1) THEN - INSERT INTO Shop_User ( - id_user, - name, - email, - email_verified - ) - VALUES ( - a_id_user, - a_name, - a_email, - a_email_verified - ); - - INSERT INTO tmp_Shop_User ( - id_user, - active - ) - SELECT id_user, - active - FROM Shop_User - WHERE id_user LIKE CONCAT('%', a_id_user, '%') - AND active - LIMIT 1 - ; - END IF; - - SET a_id_user := (SELECT id_user FROM tmp_Shop_User LIMIT 1); - ELSE - INSERT INTO tmp_Msg_Error ( - id_type, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - 'No user ID provided.' - ) - ; - END IF; - - - /* - IF NOT EXISTS (SELECT msg FROM tmp_Msg_Error LIMIT 1) THEN - END IF; - */ - - - -- Returns - -- User - SELECT * - FROM tmp_Shop_User - ; - - -- Errors - SELECT * - FROM tmp_Msg_Error - ; - - /* - -- Return arguments for test - SELECT a_id_user, - a_name, - a_email, - a_email_verified - ; - */ - - -- Clean up - DROP TABLE IF EXISTS tmp_Msg_Error; - DROP TABLE IF EXISTS tmp_Shop_User; -END ;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `p_shop_edit_user_basket` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `p_shop_edit_user_basket`( - IN a_id_user INT, - IN a_ids_permutation_basket VARCHAR(4000), - IN a_quantities_permutation_basket VARCHAR(4000), - IN a_id_permutation_edit INT, - IN a_quantity_permutation_edit INT, - IN a_sum_not_edit BIT, - IN a_id_currency INT, - IN a_id_region_purchase INT -) -BEGIN - -- Argument redeclaration - -- Variable declaration - DECLARE v_has_filter_user BIT; - DECLARE v_has_filter_permutation_basket BIT; - DECLARE v_has_filter_permutation_edit BIT; - DECLARE v_has_filter_region BIT; - DECLARE v_has_filter_currency BIT; - DECLARE v_n_id_permutation_basket INT; - DECLARE v_n_quantity_permutation_basket INT; - DECLARE v_row_number INT; - DECLARE v_guid BINARY(36); - -- DECLARE v_id_user VARCHAR(100); - DECLARE v_id_permission_product INT; - DECLARE v_ids_permutation_permission VARCHAR(4000); - DECLARE v_now DATETIME; - -- DECLARE v_quantity_new INT; - DECLARE v_change_set_used BIT; - DECLARE v_id_change_set INT; - - SET v_guid = UUID(); - - -- Argument validation + default values - IF a_id_user IS NULL THEN - SET a_id_user = ''; - ELSE - SET a_id_user = TRIM(a_id_user); - END IF; - IF a_ids_permutation_basket IS NULL THEN - SET a_ids_permutation_basket = ''; - ELSE - SET a_ids_permutation_basket = TRIM(a_ids_permutation_basket); - END IF; - IF a_quantities_permutation_basket IS NULL THEN - SET a_quantities_permutation_basket = ''; - ELSE - SET a_quantities_permutation_basket = TRIM(a_quantities_permutation_basket); - END IF; - IF a_sum_not_edit IS NULL THEN - SET a_sum_not_edit = 1; - END IF; - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Msg_Error; - DROP TABLE IF EXISTS tmp_Shop_Basket; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Quantity; - DROP TABLE IF EXISTS tmp_Shop_Product; - DROP TABLE IF EXISTS tmp_Shop_User; - - CREATE TABLE tmp_Shop_User ( - id_user INT NOT NULL, - CONSTRAINT FK_tmp_Shop_User_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user), - active BIT NOT NULL - ); - - CREATE TABLE tmp_Shop_Product ( - id_product INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - id_permutation INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - display_order INT NOT NULL, - active INT NOT NULL DEFAULT 1 - ); - - CREATE TEMPORARY TABLE tmp_Shop_Quantity( - quantity INT NOT NULL, - display_order INT NOT NULL, - active INT NOT NULL DEFAULT 1 - ); - - CREATE TABLE tmp_Shop_Basket ( - id_category INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Basket_id_category - FOREIGN KEY (id_category) - REFERENCES Shop_Product_Category(id_category), - id_product INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Basket_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - id_permutation INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Basket_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - id_region_purchase INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Basket_id_region_purchase - FOREIGN KEY (id_region_purchase) - REFERENCES Shop_Region(id_region), - id_currency INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Basket_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency), - quantity INT NOT NULL, - active BIT NOT NULL DEFAULT 1 - /* - display_order_category INT NOT NULL, - display_order_product INT NOT NULL - */ - ); - - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - guid BINARY(36) NOT NULL, - id_type INT NOT NULL, - -- code VARCHAR(50) NOT NULL, - -- CONSTRAINT chk_tmp_Msg_Error_code CHECK (code IN (SELECT code FROM Shop_Msg_Error_Type)), - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type(id_type), - msg VARCHAR(4000) NOT NULL - ); - - - -- Parse filters - SET v_has_filter_user = NOT (a_id_user = ''); - SET v_has_filter_permutation_basket = NOT (a_ids_permutation_basket = ''); - SET v_has_filter_permutation_edit = NOT ISNULL(a_id_permutation_edit); - SET v_has_filter_currency = NOT ISNULL(a_id_currency); - SET v_has_filter_region = NOT ISNULL(a_id_region_purchase); - -- SET v_quantity_new = CASE WHEN a_sum_not_edit THEN quantity + a_quantity_product_edit ELSE a_quantity_product_edit END; - /* - SELECT v_has_filter_user, v_has_filter_basket - ; - - */ - - -- Currency - IF NOT v_has_filter_currency THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - 'Currency ID not provided.' - ) - ; - END IF; - IF v_has_filter_currency AND NOT EXISTS ( SELECT * FROM Shop_Currency WHERE id_currency = a_id_currency) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('Currency ID not found: ', a_id_currency, '.') - ) - ; - END IF; - - -- Region - IF NOT v_has_filter_region THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - 'Region ID not provided.' - ) - ; - END IF; - IF v_has_filter_region AND NOT EXISTS ( SELECT * FROM Shop_Region WHERE id_region = a_id_region_purchase) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('Region ID not found: ', a_id_region_purchase, '.') - ) - ; - END IF; - - -- User - IF v_has_filter_user THEN - INSERT INTO tmp_Shop_User ( - id_user, - active - ) - SELECT id_user, - active - FROM Shop_User - WHERE id_user LIKE CONCAT('%', a_id_user, '%') - AND active - LIMIT 1 - ; - - IF NOT EXISTS (SELECT id_user FROM tmp_Shop_User LIMIT 1) THEN - SET v_has_filter_user = 0; - - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('User ID not found: ', a_id_user, '.') - ) - ; - END IF; - - SET a_id_user := (SELECT id_user FROM tmp_Shop_User LIMIT 1); - END IF; - - IF v_has_filter_user AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - SET v_change_set_used = 0; - INSERT INTO Shop_User_Change_Set ( - comment - ) - VALUES ( - 'edit basket' - ); - SET v_id_change_set := (SELECT id_change_set FROM Shop_User_Change_Set ORDER BY id_change_set DESC LIMIT 1); - END IF; - - -- Get basket - -- User - IF v_has_filter_user AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - INSERT INTO tmp_Shop_Basket ( - id_category, - id_product, - id_permutation, - id_region_purchase, - id_currency, - quantity, - active - /* - display_order_category, - display_order_product - */ - ) - SELECT - C.id_category, - UB.id_product, - UB.id_permutation, - UB.id_region_purchase, - UB.id_currency, - UB.quantity, - UB.active - /* - C.display_order, - P.display_order - */ - FROM Shop_User_Basket UB - /* - INNER JOIN tmp_Shop_User t_U - ON UB.id_user = t_U.id_user - */ - INNER JOIN Shop_Product_Permutation PP - ON UB.id_product = PP.id_product - AND PP.active - INNER JOIN Shop_Product P - ON PP.id_product = P.id_product - AND P.active - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - AND C.active - WHERE UB.id_user = a_id_user - ; - END IF; - - -- Currency - IF EXISTS (SELECT * FROM tmp_Shop_Basket WHERE active LIMIT 1) - AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - IF EXISTS (SELECT * FROM tmp_Shop_Basket WHERE active AND id_currency != a_id_currency) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT( - 'Currency ID does not match currency of other items in basket. Basket currency: ', - (SELECT code FROM Shop_Currency WHERE id_currency = ( - SELECT - id_currency - FROM tmp_Shop_Basket - WHERE active - AND id_currency != a_id_currency - LIMIT 1 - )), - ', new currency: ', - (SELECT code FROM Shop_Currency WHERE id_currency = a_id_currency), - '.' - ) - ) - ; - END IF; - END IF; - - -- Region - IF EXISTS (SELECT * FROM tmp_Shop_Basket WHERE active LIMIT 1) - AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Shop_Basket - WHERE - active - AND id_region_purchase != a_id_region_purchase - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('Purchase region ID does not match region of other items in basket. Basket currency: ', - (SELECT code FROM Shop_Region WHERE id_region = ( - SELECT - id_region_purchase - FROM tmp_Shop_Basket - WHERE active - AND id_region != a_id_region_purchase - LIMIT 1 - )), - ', new currency: ', - (SELECT code FROM Shop_Region WHERE id_region = a_id_region_purchase), - '.' - ) - ) - ; - END IF; - END IF; - - -- String product id, permutation id, quantity list - IF NOT EXISTS (SELECT * FROM tmp_Shop_Basket WHERE active LIMIT 1) AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN -- NOT v_has_filter_user AND - -- Get product ids - CALL p_split(a_ids_permutation_basket, ','); - INSERT INTO tmp_Shop_Product ( - id_product, id_permutation, display_order - ) - SELECT PP.id_product, ST.substring, ST.display_order - FROM Split_Temp ST - INNER JOIN Shop_Product_Permutation PP - ON ST.substring = PP.id_permutation - -- AND PP.active - ; - /* - SELECT substring as id_product, display_order - FROM Split_Temp - ; - */ - DROP TABLE Split_Temp; - - -- Get product quantities - CALL p_split(a_quantities_permutation_basket, ','); - INSERT INTO tmp_Shop_Quantity ( - quantity, display_order - ) - SELECT substring, display_order - FROM Split_Temp - ; - /* - SELECT substring AS quantity_product, display_order - FROM Split_Temp - ; - */ - DROP TABLE Split_Temp; - - -- Compare number of product ids to number of quantities - SET v_n_id_permutation_basket := (SELECT display_order FROM tmp_Shop_Product ORDER BY display_order DESC LIMIT 1); - SET v_n_quantity_permutation_basket := (SELECT display_order FROM tmp_Shop_Quantity ORDER BY display_order DESC LIMIT 1); - IF NOT v_n_id_permutation_basket = v_n_quantity_permutation_basket THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('Number of permutations (', v_n_id_permutation_basket, ') does not equal number of quantities (', v_n_quantity_permutation_basket, ') for basket.') - ) - ; - ELSE - INSERT INTO tmp_Shop_Basket ( - id_category, - id_product, - id_permutation, - id_region_purchase, - id_currency, - quantity - ) - SELECT - C.id_category, - P.id_product, - t_P.id_permutation, - a_id_region_purchase, - a_id_currency, - t_Q.quantity - FROM tmp_Shop_Product t_P - INNER JOIN tmp_Shop_Quantity t_Q - ON t_P.display_order = t_Q.display_order - INNER JOIN Shop_Product_Permutation PP - ON t_P.id_permutation = PP.id_permutation - AND PP.active - INNER JOIN Shop_Product P - ON PP.id_product = P.id_product - AND P.active - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - AND C.active - -- RIGHT JOIN tmp_Shop_Basket t_UB ON ISNULL(t_UB.id_product) - -- WHERE t_P.id_product NOT IN (SELECT id_product FROM tmp_Shop_Basket) - ; - - /* - IF EXISTS( - SELECT * - FROM Shop_Product P - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - INNER JOIN tmp_Shop_Basket t_B - ON P.id_product = t_B.id_product - WHERE C.active = 0 OR P.active = 0 LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('No valid product IDs in list: ', a_ids_permutation_basket, '.') - ) - ; - END IF; - */ - END IF; - END IF; - - /* - select v_has_filter_edit; - select * from tmp_Shop_Basket; - select * from tmp_Msg_Error; - */ - - - -- Edit basket product - IF v_has_filter_permutation_edit AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM Shop_Product_Permutation PP - INNER JOIN Shop_Product P - ON PP.id_product = P.id_product - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - WHERE - ( - C.active = 0 - OR P.active = 0 - OR PP.active = 0 - ) - AND PP.id_permutation = a_id_permutation_edit - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('Invalid product ID to edit: ', a_id_product_edit, '.') - ) - ; - END IF; - END IF; - IF v_has_filter_permutation_edit AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Shop_Basket - WHERE - id_permutation = a_id_permutation_edit - ) THEN - UPDATE tmp_Shop_Basket - SET quantity = CASE WHEN a_sum_not_edit = 1 THEN IFNULL(quantity, 0) + a_quantity_permutation_edit ELSE a_quantity_permutation_edit END, - active = CASE WHEN CASE WHEN a_sum_not_edit = 1 THEN IFNULL(quantity, 0) + a_quantity_permutation_edit ELSE a_quantity_permutation_edit END = 0 THEN 0 ELSE 1 END - WHERE id_permutation = a_id_permutation_edit - ; - - IF EXISTS ( - SELECT * - FROM tmp_Shop_Basket t_B - WHERE t_B.quantity < 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - 'Invalid basket quantity.' - ) - ; - END IF; - - IF v_has_filter_user AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - SET v_change_set_used = 1; - - UPDATE Shop_User_Basket UB - INNER JOIN tmp_Shop_Basket t_UB - ON UB.id_permutation = a_id_permutation_edit - SET UB.quantity = t_UB.quantity, - UB.active = t_UB.active, - UB.id_change_set_user = v_id_change_set - WHERE UB.id_permutation = a_id_permutation_edit - AND id_user = a_id_user - ; - END IF; - ELSE - IF a_quantity_permutation_edit < 0 THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - 'Invalid basket quantity.' - ) - ; - ELSE - INSERT INTO tmp_Shop_Basket ( - id_category, - id_product, - id_permutation, - id_region_purchase, - id_currency, - quantity, - active - ) - SELECT - P.id_category, - P.id_product, - PP.id_permutation, - a_id_region_purchase, - a_id_currency, - a_quantity_permutation_edit, - CASE WHEN a_quantity_permutation_edit > 0 THEN 1 ELSE 0 END - FROM Shop_Product_Permutation PP - INNER JOIN Shop_Product P - ON PP.id_product = P.id_product - WHERE id_permutation = a_id_permutation_edit - ; - IF v_has_filter_user THEN - IF EXISTS ( - SELECT * - FROM Shop_User_Basket UB - WHERE - UB.id_permutation = a_id_permutation_edit - ) THEN - SET v_change_set_used = 1; - - UPDATE Shop_User_Basket - INNER JOIN tmp_Shop_Basket t_UB ON UB.id_permutation = t_UB.id_permutation - SET UB.quantity = t_UB.quantity, - UB.active = t_UB.active, - UB.id_change_set_user = v_id_change_set - WHERE UB.id_permutation = a_id_permutation_edit - AND id_user = a_id_user - ; - ELSE - INSERT INTO Shop_User_Basket ( - id_user, - id_product, - id_permutation, - id_region_purchase, - id_currency, - quantity, - active - ) - SELECT a_id_user, - t_UB.id_product, - t_UB.id_permutation, - t_UB.id_region_purchase, - t_UB.id_currency, - t_UB.quantity, - t_UB.active - FROM tmp_Shop_Basket t_UB - WHERE id_permutation = a_id_permutation_edit - ; - END IF; - END IF; - END IF; - END IF; - END IF; - - - -- Checks - /* - SELECT * FROM tmp_Shop_Basket; - SELECT - GROUP_CONCAT(t_UB.id_product SEPARATOR ',') AS basket_product_ids - FROM tmp_Shop_Basket t_UB - -- WHERE ISNULL(t_UB.id_permutation) - ; - SELECT - GROUP_CONCAT(t_UB.id_permutation SEPARATOR ',') AS basket_permutation_ids - FROM tmp_Shop_Basket t_UB - WHERE NOT ISNULL(t_UB.id_permutation) - ; - */ - -- Returns - CALL p_shop_get_many_product ( - a_id_user, -- a_id_user - 1, -- a_get_all_categories - '', -- a_ids_category - 0, -- a_get_inactive_categories - 0, -- a_get_all_products - ( - SELECT - GROUP_CONCAT(t_B.id_product SEPARATOR ',') - FROM tmp_Shop_Basket t_B - WHERE active = 1 - ), -- a_ids_product - 0, -- a_get_inactive_products - 0, -- a_get_first_product_only - 0, -- a_get_all_product_permutations - ( - SELECT - GROUP_CONCAT(t_B.id_permutation SEPARATOR ',') - FROM tmp_Shop_Basket t_B - WHERE NOT ISNULL(t_B.id_permutation) - AND active = 1 - ), -- a_ids_permutation - 0, -- a_get_inactive_permutations - 0, -- a_get_all_images - '', -- a_ids_image - 0, -- a_get_inactive_images - 1, -- a_get_first_image_only - 0, -- a_get_all_delivery_region - a_id_region_purchase, -- a_ids_delivery_region - 0, -- a_get_inactive_delivery_region - 0, -- a_get_all_currency - a_id_currency, -- a_ids_currency - 0, -- a_get_inactive_currency - 1, -- a_get_all_discount - '', -- a_ids_discount - 0 -- a_get_inactive_discount - ); - - -- Basket - SELECT t_UB.id_category, - t_UB.id_product, - t_UB.id_permutation, - P.name, - PCL.price_local_VAT_incl, - PCL.price_local_VAT_excl, - PCL.id_currency, - t_UB.quantity - FROM tmp_Shop_Basket t_UB - INNER JOIN Shop_Product_Permutation PP - ON t_UB.id_permutation = PP.id_permutation - INNER JOIN Shop_Product P - ON PP.id_product = P.id_product - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - INNER JOIN Shop_Product_Currency_Link PCL - ON PP.id_permutation = PCL.id_permutation - AND PCL.id_region_purchase = a_id_region_purchase - AND PCL.id_currency = a_id_currency - WHERE t_UB.active = 1 - ORDER BY C.display_order, P.display_order - ; - - -- Errors - /* Completed by product get many */ - SELECT - t_ME.display_order, - t_ME.guid, - t_ME.id_type, - t_ME.msg, - MET.code, - MET.name, - MET.description - FROM tmp_Msg_Error t_ME - INNER JOIN Shop_Msg_Error_Type MET - ON t_ME.id_type = MET.id_type - WHERE GUID = v_guid - ; - - /* - -- Return arguments for test - SELECT - a_ids_category, - a_get_inactive_categories, - a_ids_product, - a_get_inactive_products, - a_get_first_product_only, - a_get_all_products, - a_ids_image, - a_get_inactive_images, - a_get_first_image_only, - a_get_all_images - ; - */ - - -- Clean up - IF NOT v_change_set_used THEN - DELETE FROM Shop_User_Change_Set - WHERE id_change_set = v_id_change_set - ; - END IF; - - -- DROP TABLE IF EXISTS tmp_Msg_Error; - DELETE FROM tmp_Msg_Error WHERE guid = v_guid; - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - DROP TABLE tmp_Msg_Error; - END IF; - DROP TABLE IF EXISTS tmp_Shop_Basket; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Quantity; - DROP TABLE IF EXISTS tmp_Shop_Product; - DROP TABLE IF EXISTS tmp_Shop_User; -END ;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `p_shop_get_many_currency` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `p_shop_get_many_currency`( - IN a_get_inactive_currency BIT -) -BEGIN - IF a_get_inactive_currency IS NULL THEN - SET a_get_inactive_currency = 0; - END IF; - - SELECT - C.id_currency, - C.code, - C.name, - C.factor_from_GBP, - C.active, - C.display_order - FROM Shop_Currency C - WHERE a_get_inactive_currency - OR C.active - ORDER BY C.display_order - ; -END ;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `p_shop_get_many_product` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `p_shop_get_many_product`( - IN a_id_user INT, - IN a_get_all_category BIT, - IN a_ids_category VARCHAR(500), - IN a_get_inactive_category BIT, - IN a_get_all_product BIT, - IN a_ids_product VARCHAR(500), - IN a_get_inactive_product BIT, - IN a_get_first_product_only BIT, - IN a_get_all_product_permutation BIT, - IN a_ids_permutation VARCHAR(4000), - IN a_get_inactive_permutation BIT, - IN a_get_all_image BIT, - IN a_ids_image VARCHAR(4000), - IN a_get_inactive_image BIT, - IN a_get_first_image_only BIT, - IN a_get_all_delivery_region BIT, - IN a_ids_delivery_region VARCHAR(4000), - IN a_get_inactive_delivery_region BIT, - IN a_get_all_currency BIT, - IN a_ids_currency VARCHAR(4000), - IN a_get_inactive_currency BIT, - IN a_get_all_discount BIT, - IN a_ids_discount VARCHAR(4000), - IN a_get_inactive_discount BIT -) -BEGIN - -- Argument redeclaration - -- Variable declaration - DECLARE v_has_filter_category BIT; - DECLARE v_has_filter_product BIT; - DECLARE v_has_filter_permutation BIT; - DECLARE v_has_filter_image BIT; - DECLARE v_has_filter_delivery_region BIT; - DECLARE v_has_filter_currency BIT; - DECLARE v_has_filter_discount BIT; - DECLARE v_guid BINARY(36); - -- DECLARE v_id_user VARCHAR(100); - DECLARE v_ids_permutation_unavailable VARCHAR(4000); - DECLARE v_id_permission_product INT; - DECLARE v_ids_product_permission VARCHAR(4000); - DECLARE v_ids_permutation_permission VARCHAR(4000); - DECLARE v_id_access_level_view INT; - DECLARE v_now DATETIME; - DECLARE v_id_minimum INT; - - SET v_guid := UUID(); - SET v_id_access_level_view := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW'); - - - -- Argument validation + default values - IF a_id_user IS NULL THEN - SET a_id_user = ''; - ELSE - SET a_id_user = TRIM(a_id_user); - END IF; - IF a_get_all_category IS NULL THEN - SET a_get_all_category = 0; - END IF; - IF a_ids_category IS NULL THEN - SET a_ids_category = ''; - ELSE - SET a_ids_category = REPLACE(TRIM(a_ids_category), '|', ','); - END IF; - IF a_get_inactive_category IS NULL THEN - SET a_get_inactive_category = 0; - END IF; - IF a_ids_product IS NULL THEN - SET a_ids_product = ''; - ELSE - SET a_ids_product = REPLACE(TRIM(a_ids_product), '|', ','); - END IF; - IF a_get_inactive_product IS NULL THEN - SET a_get_inactive_product = 0; - END IF; - IF a_get_first_product_only IS NULL THEN - SET a_get_first_product_only = 1; - END IF; - IF a_get_all_product IS NULL THEN - SET a_get_all_product = 0; - END IF; - IF a_ids_permutation IS NULL THEN - SET a_ids_permutation = ''; - ELSE - SET a_ids_permutation = REPLACE(TRIM(a_ids_permutation), '|', ','); - END IF; - IF a_get_inactive_permutation IS NULL THEN - SET a_get_inactive_permutation = 0; - END IF; - IF a_get_all_image IS NULL THEN - SET a_get_all_image = 1; - END IF; - IF a_ids_image IS NULL THEN - SET a_ids_image = ''; - ELSE - SET a_ids_image = REPLACE(TRIM(a_ids_image), '|', ','); - END IF; - IF a_get_inactive_image IS NULL THEN - SET a_get_inactive_image = 0; - END IF; - IF a_get_first_image_only IS NULL THEN - SET a_get_first_image_only = 0; - END IF; - IF a_get_inactive_image IS NULL THEN - SET a_get_inactive_image = 0; - END IF; - IF a_get_all_delivery_region IS NULL THEN - SET a_get_all_delivery_region = 1; - END IF; - IF a_ids_delivery_region IS NULL THEN - SET a_ids_delivery_region = ''; - ELSE - SET a_ids_delivery_region = REPLACE(TRIM(a_ids_delivery_region), '|', ','); - END IF; - IF a_get_inactive_delivery_region IS NULL THEN - SET a_get_inactive_delivery_region = 0; - END IF; - IF a_get_all_currency IS NULL THEN - SET a_get_all_currency = 1; - END IF; - IF a_ids_currency IS NULL THEN - SET a_ids_currency = ''; - ELSE - SET a_ids_currency = REPLACE(TRIM(a_ids_currency), '|', ','); - END IF; - IF a_get_inactive_currency IS NULL THEN - SET a_get_inactive_currency = 0; - END IF; - IF a_get_all_discount IS NULL THEN - SET a_get_all_discount = 1; - END IF; - IF a_ids_discount IS NULL THEN - SET a_ids_discount = ''; - ELSE - SET a_ids_discount = REPLACE(TRIM(a_ids_discount), '|', ','); - END IF; - IF a_get_inactive_discount IS NULL THEN - SET a_get_inactive_discount = 0; - END IF; - - /* - SELECT a_id_user, a_get_all_category, a_ids_category, a_get_inactive_category, a_get_all_product, - a_ids_product, a_get_inactive_product, a_get_first_product_only, a_get_all_product_permutation, a_ids_permutation, - a_get_inactive_permutation, a_get_all_image, a_ids_image, a_get_inactive_image, a_get_first_image_only, - a_get_all_delivery_region, a_ids_delivery_region, a_get_inactive_delivery_region, a_get_all_currency, a_ids_currency, - a_get_inactive_currency, a_get_all_discount, a_ids_discount, a_get_inactive_discount - ; - */ - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Discount; - DROP TABLE IF EXISTS tmp_Currency; - DROP TABLE IF EXISTS tmp_Delivery_Region; - DROP TABLE IF EXISTS tmp_Shop_Image; - DROP TABLE IF EXISTS tmp_Shop_Variation; - DROP TABLE IF EXISTS tmp_Shop_Product; - DROP TABLE IF EXISTS tmp_Shop_Product_Category; - - CREATE TABLE tmp_Shop_Product_Category ( - id_category INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_Category_id_category - FOREIGN KEY (id_category) - REFERENCES Shop_Product_Category(id_category), - active BIT NOT NULL, - display_order INT NOT NULL, - can_view BIT, - can_edit BIT, - can_admin BIT - ); - - CREATE TABLE tmp_Shop_Product ( - id_category INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_category - FOREIGN KEY (id_category) - REFERENCES Shop_Product_Category(id_category), - id_product INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - -- product_has_variations BIT NOT NULL, - id_permutation INT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - active_category BIT NOT NULL, - active_product BIT NOT NULL, - active_permutation BIT NULL, - display_order_category INT NOT NULL, - display_order_product INT NOT NULL, - display_order_permutation INT NULL, - rank_permutation INT NOT NULL, -- _in_category - name VARCHAR(255) NOT NULL, - description VARCHAR(4000) NOT NULL, - /* - price_GBP_full FLOAT NOT NULL, - price_GBP_min FLOAT NOT NULL, - */ - latency_manufacture INT NOT NULL, - quantity_min FLOAT NOT NULL, - quantity_max FLOAT NOT NULL, - quantity_step FLOAT NOT NULL, - quantity_stock FLOAT NOT NULL, - is_subscription BIT NOT NULL, - id_unit_measurement_interval_recurrence INT, - CONSTRAINT FK_tmp_Shop_Product_id_unit_measurement_interval_recurrence - FOREIGN KEY (id_unit_measurement_interval_recurrence) - REFERENCES Shop_Interval_Recurrence(id_interval), - count_interval_recurrence INT, - id_stripe_product VARCHAR(100), - product_has_variations INT NOT NULL, - can_view BIT, - can_edit BIT, - can_admin BIT - ); - - /* - CREATE TEMPORARY TABLE tmp_Shop_Variation ( - id_variation INT NOT NULL, - id_product INT NOT NULL, - display_order INT NOT NULL - ); - */ - - CREATE TABLE tmp_Shop_Image ( - id_image INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Image_id_image - FOREIGN KEY (id_image) - REFERENCES Shop_Image(id_image), - id_product INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Image_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - id_permutation INT NULL, - CONSTRAINT FK_tmp_Shop_Image_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - active BIT NOT NULL, - display_order INT NOT NULL, - rank_in_product_permutation INT NOT NULL - ); - - CREATE TABLE tmp_Delivery_Region ( - id_region INT NOT NULL, - CONSTRAINT FK_tmp_Delivery_Region_id_region - FOREIGN KEY (id_region) - REFERENCES Shop_Region(id_region), - active BIT NOT NULL, - display_order INT NOT NULL, - requires_delivery_option BIT NOT NULL DEFAULT 0 - ); - - CREATE TABLE tmp_Currency ( - id_currency INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Currency_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency), - active BIT NOT NULL, - display_order INT NOT NULL - ); - - CREATE TABLE tmp_Discount ( - id_discount INT NOT NULL, - CONSTRAINT FK_tmp_Discount_id_discount - FOREIGN KEY (id_discount) - REFERENCES Shop_Discount(id_discount), - active BIT NOT NULL, - display_order INT NOT NULL - ); - - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( -- IF NOT EXISTS - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - guid BINARY(36) NOT NULL, - -- code VARCHAR(50) NOT NULL, - -- CONSTRAINT chk_tmp_Msg_Error_code CHECK (code IN (SELECT code FROM Shop_Msg_Error_Type)), - id_type INT NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type(id_type), - msg VARCHAR(4000) NOT NULL - ); - - - -- Parse filters - SET v_has_filter_category = CASE WHEN a_ids_category = '' THEN 0 ELSE 1 END; - SET v_has_filter_product = CASE WHEN a_ids_product = '' THEN 0 ELSE 1 END; - SET v_has_filter_permutation = CASE WHEN a_ids_permutation = '' THEN 0 ELSE 1 END; - SET v_has_filter_image = CASE WHEN a_ids_image = '' THEN 0 ELSE 1 END; - SET v_has_filter_delivery_region = CASE WHEN a_ids_delivery_region = '' THEN 0 ELSE 1 END; - SET v_has_filter_currency = CASE WHEN a_ids_currency = '' THEN 0 ELSE 1 END; - SET v_has_filter_discount = CASE WHEN a_ids_discount = '' THEN 0 ELSE 1 END; - - -- select v_has_filter_product, v_has_filter_permutation; - - INSERT INTO tmp_Shop_Product ( - id_category, - id_product, - id_permutation, - active_category, - active_product, - active_permutation, - display_order_category, - display_order_product, - display_order_permutation, - rank_permutation, - name, - description, - /* - price_GBP_VAT_incl, - price_GBP_VAT_excl, - price_GBP_min, - */ - latency_manufacture, - quantity_min, - quantity_max, - quantity_step, - quantity_stock, - is_subscription, - id_unit_measurement_interval_recurrence, - count_interval_recurrence, - id_stripe_product, - product_has_variations - ) - SELECT - P.id_category, - P.id_product, - -- P.has_variations AS product_has_variations, - PP.id_permutation, - C.active AS active_category, - P.active AS active_product, - PP.active AS active_permutation, - C.display_order AS display_order_category, - P.display_order AS display_order_product, - PP.display_order AS display_order_permutation, - RANK() OVER (ORDER BY C.display_order, P.display_order, PP.display_order) AS rank_permutation, --PARTITION BY P.id_category -- _in_category - P.name, - PP.description, - /* - PP.price_GBP_VAT_incl, - PP.price_GBP_VAT_excl, - PP.price_GBP_min, - */ - PP.latency_manufacture, - PP.quantity_min, - PP.quantity_max, - PP.quantity_step, - PP.quantity_stock, - PP.is_subscription, - PP.id_unit_measurement_interval_recurrence, - PP.count_interval_recurrence, - PP.id_stripe_product, - P.has_variations - FROM Shop_Product P - INNER JOIN Shop_Product_Permutation PP - ON P.id_product = PP.id_product - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - WHERE - -- permutations - ( - ( - a_get_all_product_permutation - OR v_has_filter_permutation AND FIND_IN_SET(PP.id_permutation, a_ids_permutation) > 0 - ) - AND (a_get_inactive_permutation OR PP.active) - ) - -- categories - AND ( - ( - a_get_all_category - OR v_has_filter_category AND FIND_IN_SET(P.id_category, a_ids_category) > 0 - ) - AND (a_get_inactive_category OR C.active) - ) - -- products - AND ( - ( - a_get_all_product - OR v_has_filter_product AND FIND_IN_SET(P.id_product, a_ids_product) > 0 - ) - AND (a_get_inactive_product OR P.active) - ) - ; - - -- select * from tmp_Shop_Product; - - IF a_get_first_product_only THEN - DELETE FROM tmp_Shop_Product t_P - WHERE t_P.rank_permutation > 1 - ; - END IF; - - INSERT INTO tmp_Shop_Product_Category ( - id_category, - active, - display_order - ) - SELECT DISTINCT C.id_category, - C.active, - C.display_order - FROM tmp_Shop_Product t_P - INNER JOIN Shop_Product_Category C - ON t_P.id_category = C.id_category - ORDER BY C.display_order - ; - - /* - INSERT INTO tmp_Shop_Variation ( - id_variation, id_product -- , display_order - ) - SELECT P.id_variation, P.id_product -- , P.display_order - FROM Shop_Variation V - INNER JOIN tmp_Shop_Product t_P - ON V.id_product = t_P.id_product - WHERE V.active; - */ - - -- Product Images - INSERT INTO tmp_Shop_Image ( - id_product, - id_permutation, - id_image, - active, - display_order, - rank_in_product_permutation - ) - SELECT id_product, - id_permutation, - id_image, - active, - ROW_NUMBER() OVER (ORDER BY display_order_product_temp, display_order_image), - RANK() OVER (PARTITION BY id_product, id_permutation ORDER BY display_order_product_temp, display_order_image) - FROM ( - SELECT t_P.id_product, - I.id_permutation, - I.id_image, - I.active, - I.display_order AS display_order_image, - t_P.rank_permutation AS display_order_product_temp - FROM Shop_Image I - INNER JOIN tmp_Shop_Product t_P - ON I.id_product = t_P.id_product - AND NOT t_P.product_has_variations - UNION - SELECT t_P.id_product, - I.id_permutation, - I.id_image, - I.active, - I.display_order AS display_order_image, - t_P.rank_permutation AS display_order_product_temp - FROM Shop_Image I - INNER JOIN tmp_Shop_Product t_P - ON I.id_permutation = t_P.id_permutation - AND t_P.product_has_variations - ) IPP - WHERE (a_get_all_image OR a_get_first_image_only OR FIND_IN_SET(id_image, a_ids_image) > 0) - AND (a_get_inactive_image OR IPP.active) - ; - - IF a_get_first_image_only THEN - DELETE FROM tmp_Shop_Image - WHERE rank_in_product_permutation > 1 - ; - END IF; - - /* - IF v_has_filter_image THEN - DELETE FROM tmp_Shop_Product - WHERE id_product NOT IN (SELECT DISTINCT id_product FROM tmp_Shop_Image); - DELETE FROM tmp_Shop_Product_Category - WHERE id_category NOT IN (SELECT DISTINCT id_category FROM tmp_Shop_Product); - END IF; - */ - - -- Delivery Regions - INSERT INTO tmp_Delivery_Region ( - id_region, - active, - display_order, - requires_delivery_option - ) - WITH RECURSIVE Recursive_CTE_Delivery_Region AS ( - SELECT - DR.id_region AS id_region_parent, - NULL AS id_region_child, - CASE WHEN FIND_IN_SET(DR.id_region, a_ids_delivery_region) > 0 THEN 1 ELSE 0 END AS requires_delivery_option - FROM Shop_Product_Currency_Region_Link PCRL - INNER JOIN Shop_Currency C ON PCRL.id_currency = C.id_currency - INNER JOIN tmp_Shop_Product t_P - ON PCRL.id_product <=> t_P.id_product - AND PCRL.id_permutation <=> t_P.id_permutation - INNER JOIN Shop_Region DR ON PCRL.id_region_purchase = DR.id_region - WHERE - ( - a_get_all_delivery_region - OR FIND_IN_SET(DR.id_region, a_ids_delivery_region) > 0 - ) - AND ( - a_get_inactive_delivery_region - OR DR.active = 1 - ) - UNION - SELECT - DRB.id_region_parent, - DRB.id_region_child, - 0 AS requires_delivery_option - FROM Shop_Region_Branch DRB - INNER JOIN Recursive_CTE_Delivery_Region r_DR - ON DRB.id_region_parent = r_DR.id_region_child - AND ( - a_get_inactive_delivery_region - OR DRB.active = 1 - ) - ) - SELECT - DR.id_region, - DR.active, - DR.display_order, - requires_delivery_option - FROM Shop_Region DR - INNER JOIN Recursive_CTE_Delivery_Region r_DR - ON DR.id_region = r_DR.id_region_parent - OR DR.id_region = r_DR.id_region_child - ; - /* - select * from tmp_delivery_region; - SELECT * - FROM tmp_Shop_Product t_P - WHERE - /*( - a_get_all_category - OR a_get_all_product - OR a_get_all_product_permutation - )* - FIND_IN_SET(t_P.id_category, a_ids_category) > 0 - OR FIND_IN_SET(t_P.id_product, a_ids_product) > 0 - OR FIND_IN_SET(t_P.id_permutation, a_ids_permutation) > 0 - ; - */ - - IF v_has_filter_delivery_region THEN - SET v_ids_permutation_unavailable = ( - SELECT GROUP_CONCAT(t_P.id_permutation SEPARATOR ', ') - FROM ( - SELECT * - FROM tmp_Shop_Product t_P - WHERE - /*( - a_get_all_category - OR a_get_all_produc - OR a_get_all_product_permutation - )*/ - FIND_IN_SET(t_P.id_category, a_ids_category) > 0 - OR FIND_IN_SET(t_P.id_product, a_ids_product) > 0 - OR FIND_IN_SET(t_P.id_permutation, a_ids_permutation) > 0 - ) t_P - LEFT JOIN ( - SELECT * - FROM Shop_Product_Currency_Region_Link PCRL - WHERE - ( - a_get_all_delivery_region - OR FIND_IN_SET(PCRL.id_region_purchase, a_ids_delivery_region) > 0 - ) - ) PCRL - ON t_P.id_product <=> PCRL.id_product - AND t_P.id_permutation <=> PCRL.id_permutation - LEFT JOIN tmp_Delivery_Region t_DR - ON PCRL.id_region_purchase = t_DR.id_region - AND t_DR.requires_delivery_option = 1 - WHERE - ISNULL(t_DR.id_region) - ); - IF NOT ISNULL(v_ids_permutation_unavailable) THEN - INSERT INTO tmp_Msg_Error ( - guid, - id_type, - msg - ) - VALUES ( - v_guid, - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'PRODUCT_AVAILABILITY' LIMIT 1), - CONCAT('Error: The following permutation IDs are not available in this region: ', v_ids_permutation_unavailable) - ); - END IF; - /* - DELETE FROM tmp_Shop_Product t_P - WHERE t_P.id_permutation NOT IN ( - SELECT - id_permutation - FROM Shop_Product_Currency_Region_Link PCL - INNER JOIN tmp_Delivery_Region t_DR - ON PCRL.id_region_purchase = t_DR.id_region - ); - */ - END IF; - - -- select * from tmp_Shop_Product; - - -- Currencies - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid) THEN - INSERT INTO tmp_Currency ( - id_currency, - active, - display_order - ) - SELECT - C.id_currency, - C.active, - C.display_order - FROM Shop_Product_Currency_Region_Link PCRL - INNER JOIN Shop_Currency C ON PCRL.id_currency = C.id_currency - INNER JOIN tmp_Shop_Product t_P - ON PCRL.id_product <=> t_P.id_product - AND PCRL.id_permutation <=> t_P.id_permutation - INNER JOIN tmp_Delivery_Region t_DR ON PCRL.id_region_purchase = t_DR.id_region - WHERE - ( - a_get_all_currency - OR FIND_IN_SET(C.id_currency, a_ids_currency) > 0 - ) - AND ( - a_get_inactive_currency - OR ( - C.active - AND PCRL.active - ) - ) - ; - - -- select * from tmp_Currency; - - IF v_has_filter_currency THEN - SET v_ids_permutation_unavailable = ( - SELECT GROUP_CONCAT(t_P.id_permutation SEPARATOR ', ') - FROM ( - SELECT * - FROM tmp_Shop_Product t_P - WHERE - /*( - a_get_all_category - OR a_get_all_product - OR a_get_all_product_permutation - )*/ - FIND_IN_SET(t_P.id_category, a_ids_category) > 0 - OR FIND_IN_SET(t_P.id_product, a_ids_product) > 0 - OR FIND_IN_SET(t_P.id_permutation, a_ids_permutation) > 0 - ) t_P - INNER JOIN ( - SELECT * - FROM Shop_Product_Currency_Region_Link PCRL - WHERE - ( - a_get_all_currency - OR FIND_IN_SET(PCRL.id_currency, a_ids_currency) > 0 - ) - ) PCRL - ON t_P.id_permutation = PCRL.id_permutation - LEFT JOIN tmp_Currency t_C - ON PCRL.id_currency = t_C.id_currency - WHERE ISNULL(t_C.id_currency) - ); - IF NOT ISNULL(v_ids_permutation_unavailable) THEN - INSERT INTO tmp_Msg_Error ( - guid, - id_type, - msg - ) - VALUES ( - v_guid, - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'PRODUCT_AVAILABILITY' LIMIT 1), - CONCAT('Error: The following permutation IDs are not available in this currency: ', v_ids_permutation_unavailable) - ); - END IF; - /* - DELETE FROM tmp_Shop_Product t_P - WHERE t_P.id_permutation NOT IN ( - SELECT - id_permutation - FROM Shop_Product_Currency_Region_Link PCL - INNER JOIN tmp_Currency t_C - ON PCRL.id_currency = t_C.id_currency - ); - */ - END IF; - END IF; - - -- Discounts - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid) THEN - INSERT INTO tmp_Discount ( - id_discount, - active, - display_order - ) - SELECT - D.id_discount, - D.active, - D.display_order - FROM Shop_Discount D - INNER JOIN tmp_Shop_Product t_P - ON D.id_product = t_P.id_product - AND D.id_permutation <=> t_P.id_permutation - WHERE - ( - a_get_all_discount - OR FIND_IN_SET(D.id_discount, a_ids_discount) > 0 - ) - AND ( - a_get_inactive_discount - OR D.active - ) - ; - END IF; - -- select 'pre-permission results'; - -- select * from tmp_Shop_Product; - - -- Permissions - IF EXISTS (SELECT * FROM tmp_Shop_Product_Category LIMIT 1) THEN - -- SET v_id_user := (SELECT id_user FROM Shop_User WHERE name = CURRENT_USER()); - SET v_id_permission_product := (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_PRODUCT' LIMIT 1); - -- SET v_ids_product_permission := (SELECT GROUP_CONCAT(id_product SEPARATOR ',') FROM tmp_Shop_Product); - SET v_ids_permutation_permission := (SELECT GROUP_CONCAT(id_permutation SEPARATOR ',') FROM tmp_Shop_Product WHERE NOT ISNULL(id_permutation)); - - -- SELECT v_guid, a_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_permutation_permission; - -- select * from Shop_User_Eval_Temp; - - CALL p_shop_user_eval(v_guid, a_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_permutation_permission); - - -- select * from Shop_User_Eval_Temp; - - UPDATE tmp_Shop_Product t_P - INNER JOIN Shop_User_Eval_Temp UE_T - ON t_P.id_permutation = UE_T.id_permutation - AND UE_T.GUID = v_guid - SET t_P.can_view = UE_T.can_view, - t_P.can_edit = UE_T.can_edit, - t_P.can_admin = UE_T.can_admin; - - DELETE FROM tmp_Shop_Product t_P - WHERE - FIND_IN_SET(t_P.id_permutation, (SELECT GROUP_CONCAT(UET.id_permutation SEPARATOR ',') FROM Shop_User_Eval_Temp UET)) = 0 -- id_product NOT LIKE CONCAT('%', (SELECT GROUP_CONCAT(id_product SEPARATOR '|') FROM Shop_User_Eval_Temp), '%'); - OR ( - ISNULL(t_P.can_view) - AND ( - NOT v_has_filter_category - OR FIND_IN_SET(t_P.id_category, a_ids_category) = 0 - ) - AND ( - NOT v_has_filter_product - OR FIND_IN_SET(t_P.id_product, a_ids_product) = 0 - ) - AND ( - NOT v_has_filter_permutation - OR FIND_IN_SET(t_P.id_permutation, a_ids_permutation) = 0 - ) - ) - ; - - -- CALL p_shop_user_eval_clear_temp(v_guid); - -- DROP TABLE IF EXISTS Shop_User_Eval_Temp; - DELETE FROM Shop_User_Eval_Temp - WHERE GUID = v_guid - ; - END IF; - - - -- select * from tmp_Shop_Product; - - -- Returns - SET v_now := NOW(); - - -- Categories - SELECT - DISTINCT t_C.id_category, - C.name, - C.description, - C.display_order - FROM tmp_Shop_Product_Category t_C - INNER JOIN Shop_Product_Category C - ON t_C.id_category = C.id_category - INNER JOIN tmp_Shop_Product t_P - ON t_C.id_category = t_P.id_category - ORDER BY C.display_order - ; - - -- Products - SELECT - t_P.id_product, - t_P.id_permutation, - t_P.name, - t_P.description, - P.has_variations, - P.id_category, - t_P.latency_manufacture, - t_P.quantity_min, - t_P.quantity_max, - t_P.quantity_step, - t_P.quantity_stock, - t_P.id_stripe_product, - t_P.is_subscription, - RI.name AS name_interval_recurrence, - RI.name_plural AS name_plural_interval_recurrence, - t_P.count_interval_recurrence, - t_P.display_order_category, - t_P.display_order_product, - t_P.display_order_permutation, - IFNULL(t_P.can_view, 0), - IFNULL(t_P.can_edit, 0), - IFNULL(t_P.can_admin, 0) - FROM tmp_Shop_Product t_P - INNER JOIN Shop_Product P - ON t_P.id_product = P.id_product - LEFT JOIN Shop_Interval_Recurrence RI - ON t_P.id_unit_measurement_interval_recurrence = RI.id_interval - ORDER BY t_P.rank_permutation - ; - - -- Variations - SELECT - V.id_variation, - t_P.id_product, - t_P.id_permutation, - t_P.id_category, - VT.code AS code_variation_type, - VT.name AS name_variation_type, - V.code AS code_variation, - V.name AS name_variation, - RANK() OVER (ORDER BY t_P.rank_permutation, PPVL.display_order) AS display_order - FROM Shop_Variation V - INNER JOIN Shop_Variation_Type VT - ON V.id_type = VT.id_type - INNER JOIN Shop_Product_Permutation_Variation_Link PPVL ON V.id_variation = PPVL.id_variation - INNER JOIN tmp_Shop_Product t_P ON PPVL.id_permutation <=> t_P.id_permutation - WHERE V.active - AND PPVL.active - ; - - /* - -- Permutation variations output - SELECT t_P.id_permutation, - t_P.id_product, - t_P.id_category, - id_variation - FROM Shop_Product_Permutation_Variation_Link PPVL - INNER JOIN tmp_Shop_Product t_P - ON t_P.id_permutation = PPVL.id_permutation - ORDER BY t_P.display_order - ; - */ - -- select * from Shop_Product_Currency_Region_Link; - -- select * from shop_currency; - /* - select * from tmp_Currency; - select * from tmp_delivery_region; - select * from tmp_shop_product; - */ - - -- Product Price - SELECT - PCRL.id_link AS id_price, - t_P.id_permutation, - t_P.id_product, - t_P.id_category, - t_C.id_currency, - C.code AS code_currency, - C.name AS name_currency, - C.symbol AS symbol_currency, - t_DR.id_region, - PCRL.price_local_VAT_incl, - PCRL.price_local_VAT_excl, - ROW_NUMBER() OVER(ORDER BY t_P.rank_permutation, C.display_order) AS display_order - FROM Shop_Product_Currency_Region_Link PCRL - INNER JOIN tmp_Shop_Product t_P - ON PCRL.id_product <=> t_P.id_product - AND PCRL.id_permutation <=> t_P.id_permutation - -- INNER JOIN Shop_Product P ON PCRL.id_product = P.id_product - INNER JOIN tmp_Currency t_C ON PCRL.id_currency = t_C.id_currency - INNER JOIN Shop_Currency C ON t_C.id_currency = C.id_currency - INNER JOIN tmp_Delivery_Region t_DR ON PCRL.id_region_purchase = t_DR.id_region - WHERE ( - a_get_inactive_product - AND a_get_inactive_permutation - AND a_get_inactive_currency - AND a_get_inactive_delivery_region - OR PCRL.active - ) - ORDER BY t_P.rank_permutation - ; - - /* - -- Currency - SELECT - DISTINCT C.id_currency, - C.code, - C.name, - C.factor_from_GBP, - t_C.display_order - FROM Shop_Currency C - INNER JOIN tmp_Currency t_C ON C.id_currency = t_C.id_currency - GROUP BY C.id_currency, t_C.display_order - ORDER BY t_C.display_order - ; - */ - - -- Images - SELECT - t_I.id_image, - t_I.id_product, - t_I.id_permutation, - t_P.id_category, - I.url, - I.active, - I.display_order - FROM tmp_Shop_Image t_I - INNER JOIN Shop_Image I - ON t_I.id_image = I.id_image - INNER JOIN tmp_Shop_Product t_P - ON t_I.id_product = t_P.id_product - AND t_I.id_permutation <=> t_P.id_permutation - ORDER BY t_P.rank_permutation, I.display_order - ; - - -- Delivery options - SELECT - _DO.id_option, - PDOL.id_product, - PDOL.id_permutation, - t_P.id_category, - _DO.code, - _DO.name, - _DO.latency_delivery_min, - _DO.latency_delivery_max, - _DO.quantity_min, - _DO.quantity_max, - GROUP_CONCAT(DR.code SEPARATOR ',') AS codes_region, - GROUP_CONCAT(DR.name SEPARATOR ',') AS names_region, - PDOL.price_local, - PDOL.display_order - FROM Shop_Delivery_Option _DO - INNER JOIN Shop_Product_Delivery_Option_Link PDOL - ON _DO.id_option = PDOL.id_delivery_option - AND ( - a_get_inactive_delivery_region - OR PDOL.active - ) - INNER JOIN tmp_Shop_Product t_P - ON PDOL.id_product = t_P.id_product - AND PDOL.id_permutation <=> t_P.id_permutation - INNER JOIN tmp_Delivery_Region t_DR ON PDOL.id_region = t_DR.id_region - INNER JOIN Shop_Region DR ON t_DR.id_region = DR.id_region - WHERE ( - a_get_inactive_delivery_region - OR _DO.active - ) - GROUP BY t_P.id_category, t_P.id_product, PDOL.id_permutation, t_P.rank_permutation, DR.id_region, _DO.id_option, PDOL.id_link - ORDER BY t_P.rank_permutation, PDOL.display_order - ; - - -- Discounts - SELECT - D.id_discount, - P.id_category, - D.id_product, - D.id_permutation, - DR.id_region, - C.id_currency, - D.code AS code_discount, - D.name AS name_discount, - D.multiplier, - D.subtractor, - D.apply_multiplier_first, - D.quantity_min, - D.quantity_max, - D.date_start, - D.date_end, - GROUP_CONCAT(DR.code) AS codes_region, - GROUP_CONCAT(DR.name) AS names_region, - GROUP_CONCAT(C.code) AS codes_currency, - GROUP_CONCAT(C.name) AS names_currency, - ROW_NUMBER() OVER(ORDER BY D.display_order) AS display_order - FROM tmp_Discount t_D - INNER JOIN Shop_Discount D ON t_D.id_discount = D.id_discount - INNER JOIN Shop_Product P ON D.id_product = P.id_product - INNER JOIN tmp_Shop_Product t_P - ON D.id_product = t_P.id_product - -- AND D.id_permutation <=> t_P.id_permutation - INNER JOIN Shop_Discount_Region_Currency_Link DRCL - ON D.id_discount = DRCL.id_discount - INNER JOIN tmp_Delivery_Region t_DR ON DRCL.id_region = t_DR.id_region - INNER JOIN Shop_Region DR ON t_DR.id_region = DR.id_region - INNER JOIN tmp_Currency t_C ON DRCL.id_currency = t_C.id_currency - INNER JOIN Shop_Currency C ON t_C.id_currency = C.id_currency - GROUP BY D.id_discount, DR.id_region, C.id_currency - ORDER BY D.display_order, DR.display_order, C.display_order - ; - - /* - -- Delivery Regions - SELECT - t_DR.id_region, - t_P.id_category, - t_P.id_product, - t_P.id_permutation, - DR.code, - DR.name - FROM tmp_Delivery_Region t_DR - INNER JOIN Shop_Delivery_Region DR ON t_DR.id_region = DR.id_region - INNER JOIN Shop_Product_Region_Currency_Link PDRL - ON DR.id_region = PDRL.id_region - AND ( - a_get_inactive_delivery_region - OR PDRL.active - ) - INNER JOIN tmp_Shop_Product t_P - ON PDRL.id_product = t_P.id_product - AND PDRL.id_permutation <=> t_P.id_permutation - INNER JOIN tmp_Currency t_C ON PDRL.id_currency = t_C.id_currency - ORDER BY t_DR.display_order - ; - */ - - -- Errors - SELECT - t_ME.display_order, - t_ME.guid, - t_ME.id_type, - t_ME.msg, - MET.code, - MET.name, - MET.description - FROM tmp_Msg_Error t_ME - INNER JOIN Shop_Msg_Error_Type MET - ON t_ME.id_type = MET.id_type - WHERE guid = v_guid - ; - - /* - -- Return arguments for test - SELECT - a_ids_category, - a_get_inactive_category, - a_ids_product, - a_get_inactive_product, - a_get_first_product_only, - a_get_all_product, - a_ids_image, - a_get_inactive_image, - a_get_first_image_only, - a_get_all_image - ; - */ - - -- select 'other outputs'; - -- select * from tmp_Shop_Product; - - -- Clean up - DROP TABLE IF EXISTS tmp_Discount; - DROP TABLE IF EXISTS tmp_Currency; - DROP TABLE IF EXISTS tmp_Delivery_Region; - DROP TABLE IF EXISTS tmp_Shop_Image; - DROP TABLE IF EXISTS tmp_Shop_Variation; - DROP TABLE IF EXISTS tmp_Shop_Product; - DROP TABLE IF EXISTS tmp_Shop_Product_Category; -END ;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `p_shop_get_many_region` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `p_shop_get_many_region`( - IN a_get_inactive_region BIT -) -BEGIN - IF a_get_inactive_region IS NULL THEN - SET a_get_inactive_region = 0; - END IF; - - SELECT - R.id_region, - R.code, - R.name, - R.active, - R.display_order - FROM Shop_Region R - WHERE a_get_inactive_region - OR R.active - ORDER BY R.display_order - ; -END ;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `p_shop_get_many_stripe_price_new` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `p_shop_get_many_stripe_price_new`( - IN a_id_user INT -) -BEGIN - DECLARE v_has_filter_user BIT; - DECLARE v_code_error_data VARCHAR(200); - DECLARE v_code_error_permission VARCHAR(200); - DECLARE v_guid BINARY(36); - - SET v_code_error_data := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 1); - SET v_code_error_permission := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 2); - SET v_guid = UUID(); - - - - IF a_id_user IS NULL THEN - SET a_id_user = ''; - ELSE - SET a_id_user = TRIM(a_id_user); - END IF; - - - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Shop_Product_Currency_Link; - DROP TABLE IF EXISTS tmp_Shop_User; - - CREATE TABLE tmp_Shop_User( - id_user INT NOT NULL PRIMARY KEY, - CONSTRAINT FK_tmp_Shop_User_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user), - active BIT NOT NULL - ); - - CREATE TABLE tmp_Shop_Product_Currency_Link ( - id_link INT NOT NULL PRIMARY KEY, - CONSTRAINT FK_tmp_Shop_Product_Currency_Link_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Product_Currency_Link(id_link), - id_product INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_Currency_Link_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - id_permutation INT NULL, - CONSTRAINT FK_tmp_Shop_Product_Currency_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - id_currency INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_Currency_Link_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency), - active BIT NOT NULL - ); - - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( -- IF NOT EXISTS - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - guid BINARY(36) NOT NULL, - code VARCHAR(50) NOT NULL, - -- CONSTRAINT chk_tmp_Msg_Error_code CHECK (code IN (SELECT code FROM Shop_Msg_Error_Type)), - /* - id_type INT NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type(id_type), - */ - msg VARCHAR(4000) NOT NULL - ); - - - - -- Parse filters - SET v_has_filter_user = CASE WHEN a_id_user = '' THEN 0 ELSE 1 END; - - - - -- User permissions - IF v_has_filter_user THEN - INSERT INTO tmp_Shop_User ( - id_user, - active - ) - SELECT id_user, - active - FROM Shop_User - WHERE id_user LIKE CONCAT('%', a_id_user, '%') - AND active - LIMIT 1 - ; - - SET v_has_filter_user = EXISTS (SELECT id_user FROM tmp_Shop_User LIMIT 1); - SET a_id_user := (SELECT id_user FROM tmp_Shop_User LIMIT 1); - END IF; - IF NOT v_has_filter_user THEN - INSERT INTO tmp_Msg_Error ( - guid, - code, - msg - ) - VALUES ( - v_guid, - v_code_error_data, - 'Valid user ID not provided.' - ) - ; - END IF; - - -- Get products - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - INSERT INTO tmp_Shop_Product_Currency_Link ( - id_link, - id_product, - id_permutation, - id_currency, - active - ) - SELECT id_link, - id_product, - id_permutation, - id_currency, - active - FROM Shop_Product_Currency_Link - WHERE ISNULL(id_stripe_price) - AND active - ; - END IF; - - -- Permissions - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - -- SELECT * FROM tmp_Msg_Error LIMIT 1; - CALL p_shop_user_eval ( - v_guid, -- a_guid - a_id_user, -- a_id_user - 0, -- a_get_inactive_users - CONVERT((SELECT id_permission FROM Shop_Permission WHERE 'STORE_ADMIN' = code), CHAR), -- a_ids_permission - (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'ADMIN' AND active), -- a_ids_access_level - (SELECT GROUP_CONCAT(DISTINCT id_product SEPARATOR ',') FROM tmp_Shop_Product_Currency_Link), -- (SELECT DISTINCT id_product FROM tmp_Shop_Product_Currency_Link) calc_PCL) -- a_ids_product - (SELECT GROUP_CONCAT(DISTINCT id_permutation SEPARATOR ',') FROM tmp_Shop_Product_Currency_Link) -- a_ids_permutation - ); - -- SELECT * FROM tmp_Msg_Error LIMIT 1; - - IF EXISTS (SELECT can_admin FROM Shop_User_Eval_Temp WHERE guid = v_guid AND NOT can_admin LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - guid, - code, - msg - ) - VALUES ( - v_guid, - v_code_error_permission, - 'User ID does not have permission to get all new stripe prices.' - ) - ; - END IF; - - DELETE FROM Shop_User_Eval_Temp - WHERE guid = v_guid - ; - END IF; - - - - -- Returns - IF EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - DELETE FROM tmp_Shop_Product_Currency_Link; - END IF; - /* - SELECT * - FROM tmp_Shop_User - ; - */ - - - SELECT t_PCL.id_product, - t_PCL.id_permutation, - P.price_GBP_full * C.factor_from_GBP AS unit_price, - C.code AS code_currency, - P.id_stripe_product, - P.is_subscription, - LOWER(RI.code) AS name_recurring_interval, - P.count_interval_recurrence - FROM tmp_Shop_Product_Currency_Link t_PCL - INNER JOIN Shop_Product P - ON t_PCL.id_product = P.id_product - AND P.active - INNER JOIN Shop_Interval_Recurrence RI - ON P.id_unit_measurement_interval_recurrence = RI.id_interval - AND RI.active - INNER JOIN Shop_Currency C - ON t_PCL.id_currency = C.id_currency - AND C.active - WHERE t_PCL.active - ; - - - -- Errors - SELECT * - FROM tmp_Msg_Error - WHERE guid = v_guid - ; - - - /* - -- Return arguments for test - SELECT - a_id_user - ; - */ - - -- Clean up - DROP TABLE IF EXISTS tmp_Shop_User; - DROP TABLE IF EXISTS tmp_Shop_Product_Currency_Link; -END ;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `p_shop_get_many_stripe_product_new` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `p_shop_get_many_stripe_product_new`( - IN a_id_user INT -) -BEGIN - DECLARE v_has_filter_user BIT; - DECLARE v_code_error_data VARCHAR(200); - DECLARE v_code_error_permission VARCHAR(200); - DECLARE v_guid BINARY(36); - - SET v_code_error_data := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 1); - SET v_code_error_permission := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 2); - SET v_guid = UUID(); - - - IF a_id_user IS NULL THEN - SET a_id_user = ''; - ELSE - SET a_id_user = TRIM(a_id_user); - END IF; - - - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Shop_Product; - DROP TABLE IF EXISTS tmp_Shop_User; - - CREATE TABLE tmp_Shop_User( - id_user INT NOT NULL PRIMARY KEY, - CONSTRAINT FK_tmp_Shop_User_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user), - active BIT NOT NULL - ); - - CREATE TABLE tmp_Shop_Product ( - id_product INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - id_permutation INT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - active BIT NOT NULL, - display_order_product INT NOT NULL, - display_order_permutation INT NOT NULL, - name VARCHAR(200) NOT NULL, - description VARCHAR(4000) NOT NULL - ); - - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( -- IF NOT EXISTS - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - guid BINARY(36) NOT NULL, - code VARCHAR(50) NOT NULL, - -- CONSTRAINT chk_tmp_Msg_Error_code CHECK (code IN (SELECT code FROM Shop_Msg_Error_Type)), - /* - id_type INT NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type(id_type), - */ - msg VARCHAR(4000) NOT NULL - ); - - - - -- Parse filters - SET v_has_filter_user = CASE WHEN a_id_user = '' THEN 0 ELSE 1 END; - - - - -- User - IF v_has_filter_user THEN - INSERT INTO tmp_Shop_User ( - id_user, - active - ) - SELECT id_user, - active - FROM Shop_User - WHERE id_user LIKE CONCAT('%', a_id_user, '%') - AND active - LIMIT 1 - ; - - SET v_has_filter_user = EXISTS (SELECT id_user FROM tmp_Shop_User LIMIT 1); - SET a_id_user := (SELECT id_user FROM tmp_Shop_User LIMIT 1); - END IF; - - IF NOT v_has_filter_user THEN - INSERT INTO tmp_Msg_Error ( - guid, - code, - msg - ) - VALUES ( - v_guid, - v_code_error_data, - 'User ID not valid.' - ) - ; - END IF; - - -- Get products - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - INSERT INTO tmp_Shop_Product ( - id_product, - id_permutation, - active, - display_order_product, - display_order_permutation, - name, - description - ) - SELECT id_product, - id_permutation, - active, - display_order_product, - display_order_permutation, - name, - description - FROM ( - SELECT id_product, - NULL AS id_permutation, - active, - display_order AS display_order_product, - NULL AS display_order_permutation, - name, - description, - id_stripe_product - FROM Shop_Product P - UNION - SELECT t_PPPV.id_product, - id_permutation, - t_PPPV.active, - display_order_product, - display_order_permutation, - CONCAT(P.name, ': ', names_variation) AS name, - CONCAT(P.description, ' With variations: ', type_name_pairs_variation) AS description, - t_PPPV.id_stripe_product - FROM ( - SELECT P.id_product, - PP.id_permutation, - PP.active, - P.display_order AS display_order_product, - PP.display_order AS display_order_permutation, - GROUP_CONCAT(V.name SEPARATOR ' ') AS names_variation, - GROUP_CONCAT(CONCAT(VT.name, ': ', V.name) SEPARATOR ', ') AS type_name_pairs_variation, - PP.id_stripe_product - FROM Shop_Product_Permutation PP - INNER JOIN Shop_Product P - ON PP.id_product = P.id_product - AND P.active - INNER JOIN Shop_Product_Permutation_Variation_Link PPVL - ON PP.id_permutation = PPVL.id_permutation - AND PPVL.active - INNER JOIN Shop_Variation V - ON PPVL.id_variation = V.id_variation - AND V.active - INNER JOIN Shop_Variation_Type VT - ON V.id_type = VT.id_type - AND VT.active - GROUP BY id_product, id_permutation -- , VT.id_type, V.id_variation - ) t_PPPV - INNER JOIN Shop_Product P - ON t_PPPV.id_product = P.id_product - ) t_PPP - WHERE ISNULL(id_stripe_product) - AND active - ; - END IF; - - -- Permissions - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - CALL p_shop_user_eval ( - v_guid, -- a_guid - a_id_user, -- a_id_user - 0, -- a_get_inactive_users - CONVERT((SELECT id_permission FROM Shop_Permission WHERE 'STORE_ADMIN' = code), CHAR), -- a_ids_permission - (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'ADMIN' AND active), -- a_ids_access_level - (SELECT GROUP_CONCAT(id_product SEPARATOR ',') From tmp_Shop_Product), -- a_ids_product - (SELECT GROUP_CONCAT(id_permutation SEPARATOR ',') From tmp_Shop_Product) -- a_ids_permutation -- WHERE NOT ISNULL(id_permutation) - ); - - IF EXISTS (SELECT can_admin FROM Shop_User_Eval_Temp WHERE guid = v_guid AND NOT can_admin) THEN - INSERT INTO tmp_Msg_Error ( - guid, - code, - msg - ) - VALUES ( - v_guid, - v_code_error_permission, - 'User ID does not have permission to get all new stripe products.' - ) - ; - END IF; - - DELETE FROM Shop_User_Eval_Temp - WHERE guid = v_guid - ; - END IF; - - - - - -- Returns - /* - SELECT * - FROM tmp_Shop_User - ; - */ - - IF EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - DELETE FROM tmp_Shop_Product; - END IF; - - SELECT id_product, - id_permutation, - name, - description - FROM tmp_Shop_Product - ORDER BY display_order_product, display_order_permutation - ; - SELECT PP.id_permutation, - V.id_variation, - V.name AS name_variation, - VT.id_type AS id_type_variation, - VT.name as name_variation_type - FROM tmp_Shop_Product t_P - INNER JOIN Shop_Product_Permutation PP - ON t_P.id_permutation = PP.id_permutation - INNER JOIN Shop_Product_Permutation_Variation_Link PPVL - ON PP.id_permutation = PPVL.id_permutation - AND PPVL.active - INNER JOIN Shop_Variation V - ON PPVL.id_variation = V.id_variation - AND V.active - INNER JOIN Shop_Variation_Type VT - ON V.id_type = VT.id_type - AND VT.active - ; - - - -- Errors - SELECT * - FROM tmp_Msg_Error - WHERE guid = v_guid - ; - - - /* - -- Return arguments for test - SELECT - a_id_user - ; - */ - - -- Clean up - DROP TABLE IF EXISTS tmp_Shop_Product; - DROP TABLE IF EXISTS tmp_Shop_User; -END ;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `p_shop_get_many_user_order` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `p_shop_get_many_user_order`( - IN a_id_user INT, - IN a_ids_order VARCHAR(4000), - IN a_n_order_max INT, - IN a_id_checkout_session VARCHAR(200) -) -BEGIN - -- Argument redeclaration - -- Variable declaration - DECLARE v_has_filter_user BIT; - DECLARE v_has_filter_order BIT; - DECLARE v_has_filter_session BIT; - DECLARE v_code_error_data VARCHAR(200); - DECLARE v_code_error_permission VARCHAR(200); - DECLARE v_guid BINARY(36); - - SET v_code_error_data := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 1); - SET v_code_error_permission := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 2); - SET v_guid = UUID(); - - -- Argument validation + default values - IF a_id_user IS NULL THEN - SET a_id_user = ''; - ELSE - SET a_id_user = TRIM(a_id_user); - END IF; - IF a_ids_order IS NULL THEN - SET a_ids_order = ''; - ELSE - SET a_ids_order = TRIM(a_ids_order); - END IF; - IF a_n_order_max IS NULL THEN - SET a_n_order_max = 1; - END IF; - IF a_id_checkout_session IS NULL THEN - SET a_id_checkout_session = ''; - ELSE - SET a_id_checkout_session = TRIM(a_id_checkout_session); - END IF; - - - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Shop_User; - DROP TABLE IF EXISTS tmp_Shop_Order; - - CREATE TABLE tmp_Shop_User( - id_user INT NOT NULL PRIMARY KEY, - CONSTRAINT FK_tmp_Shop_User_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user), - active BIT NOT NULL - ); - - CREATE TABLE tmp_Shop_Order ( - id_order INT NOT NULL PRIMARY KEY, - CONSTRAINT FK_tmp_Shop_Order_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_User_Order(id_order), - active BIT NOT NULL - ); - - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - guid BINARY(36) NOT NULL, - -- id_type INT NOT NULL, - -- CONSTRAINT FK_tmp_Msg_Error_id_type FOREIGN KEY (id_type) - -- REFERENCES Shop_Msg_Error_Type (id_type), - code VARCHAR(50), - msg VARCHAR(4000) NOT NULL - ); - - - -- Parse filters - SET v_has_filter_user = CASE WHEN a_id_user = '' THEN 0 ELSE 1 END; - SET a_ids_order = REPLACE(a_ids_order, '|', ','); - SET v_has_filter_order = CASE WHEN a_ids_order = '' THEN 0 ELSE 1 END; - SET v_has_filter_session = CASE WHEN a_id_checkout_session = '' THEN 0 ELSE 1 END; - - -- User - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF v_has_filter_user THEN - INSERT INTO tmp_Shop_User ( - id_user, - active - ) - SELECT id_user, - active - FROM Shop_User - WHERE id_user LIKE CONCAT('%', a_id_user, '%') - AND active - LIMIT 1 - ; - - SET v_has_filter_user = EXISTS (SELECT id_user FROM tmp_Shop_User LIMIT 1); - SET a_id_user := (SELECT id_user FROM tmp_Shop_User LIMIT 1); - END IF; - END IF; - IF NOT v_has_filter_user THEN - INSERT INTO tmp_Msg_Error ( - guid, - code, - msg - ) - VALUES ( - v_guid, - v_code_error_data, - 'User ID not valid.' - ) - ; - END IF; - - -- Permissions - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - CALL p_shop_user_eval ( - v_guid, -- a_guid - a_id_user, -- a_id_user - 0, -- a_get_inactive_users - CONVERT((SELECT id_permission FROM Shop_Permission WHERE 'STORE_USER' = code), CHAR), -- a_ids_permission - (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW' AND active), -- a_ids_access_level - '', -- a_ids_product - '' -- a_ids_permutation - ); - - IF NOT (SELECT can_edit FROM Shop_User_Eval_Temp WHERE guid = v_guid) THEN - INSERT INTO tmp_Msg_Error ( - guid, - code, - msg - ) - VALUES ( - v_guid, - v_code_error_permission, - 'User ID does not have permission to access orders.' - ) - ; - END IF; - - DELETE FROM Shop_User_Eval_Temp - WHERE guid = v_guid - ; - END IF; - - -- Invalid Orders - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - -- Invalid Order IDs - IF EXISTS (SELECT * FROM Shop_User_Order WHERE NOT (id_user = a_id_user) AND v_has_filter_order AND FIND_IN_SET(id_order, a_ids_order) > 0) THEN -- id_order LIKE CONCAT('%', a_ids_order, '%') LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - guid, - code, - msg - ) - VALUES ( - v_guid, - v_code_error_data, - CONCAT('You do not have access to the following order IDs: ', (SELECT GROUP_CONCAT(id_order SEPARATOR ', ') FROM Shop_User_Order WHERE NOT (id_user = a_id_user) AND FIND_IN_SET(id_order, a_ids_order) > 0)) -- id_order LIKE CONCAT('%', a_ids_order, '%'))) -- AND v_has_filter_order -- filtered by parent condition - ) - ; - END IF; - -- Invalid Checkout Session IDs - IF EXISTS (SELECT * FROM Shop_User_Order WHERE NOT (id_user = a_id_user) AND v_has_filter_session AND id_checkout_session = a_id_checkout_session) THEN - INSERT INTO tmp_Msg_Error ( - guid, - code, - msg - ) - VALUES ( - v_guid, - v_code_error_data, - CONCAT('You do not have access to the following checkout session IDs: ', (SELECT GROUP_CONCAT(id_order SEPARATOR ', ') FROM Shop_User_Order WHERE NOT (id_user = a_id_user) AND id_checkout_session = a_id_checkout_session)) -- AND v_has_filter_order -- filtered by parent condition - ) - ; - END IF; - END IF; - - -- Valid Orders - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - - INSERT INTO tmp_Shop_Order ( - id_order, - active - ) - SELECT UO.id_order, - UO.active - FROM Shop_User_Order UO - INNER JOIN tmp_Shop_User t_U - ON UO.id_user = t_U.id_user - AND t_U.active - WHERE ((NOT v_has_filter_order OR FIND_IN_SET(UO.id_order, a_ids_order) > 0) -- UO.id_order LIKE CONCAT('%', a_ids_order, '%')) - OR (NOT v_has_filter_session OR UO.id_checkout_session = a_id_checkout_session)) - AND UO.active - ; - END IF; - - - - -- Returns - /* - SELECT * - FROM tmp_Shop_User - ; - */ - - SELECT t_O.id_order, - UOPL.id_product, - UOPL.id_permutation, - UOPL.quantity - FROM tmp_Shop_Order t_O - INNER JOIN Shop_User_Order UO - ON t_O.id_order = UO.id_order - INNER JOIN Shop_User_Order_Product_Link UOPL - ON UO.id_order = UOPL.id_order - WHERE t_O.active - ; - - - -- Errors - SELECT * - FROM tmp_Msg_Error - WHERE guid = v_guid - ; - - - /* - -- Return arguments for test - SELECT - a_id_user, - a_ids_order, - a_n_order_max, - a_id_checkout_session - ; - */ - - -- Clean up - DROP TABLE IF EXISTS tmp_Shop_User; - DROP TABLE IF EXISTS tmp_Shop_Order; -END ;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `p_shop_user_eval` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `p_shop_user_eval`( - IN a_guid BINARY(36), - IN a_id_user INT, - IN a_get_inactive_users BIT, - IN a_ids_permission VARCHAR(500), - IN a_ids_access_level VARCHAR(100), - IN a_ids_permutation VARCHAR(4000) -) -BEGIN - -- Variable declaration - DECLARE v_has_filter_permission BIT; - DECLARE v_has_filter_user BIT; - DECLARE v_has_filter_access_level BIT; - DECLARE v_has_filter_permutation BIT; - DECLARE v_id_permission_product INT; - DECLARE v_id_permission INT; - -- DECLARE v_ids_product VARCHAR(500); - DECLARE v_id_access_level_view INT; - -- DECLARE v_id_access_level_product_required INT; - DECLARE v_priority_access_level_view INT; - DECLARE v_priority_access_level_edit INT; - DECLARE v_priority_access_level_admin INT; - DECLARE v_id_access_level INT; - DECLARE v_priority_access_level INT; - DECLARE v_now DATETIME; - DECLARE v_ids_row_delete VARCHAR(500); - DECLARE v_code_error_data VARCHAR(200); - DECLARE v_id_error_data INT; - DECLARE v_code_error_permission VARCHAR(200); - - SET v_id_error_data = 1; - SET v_code_error_data := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = v_id_error_data); - - SET v_code_error_permission := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 2); - - -- Clear previous proc results - -- DROP TABLE IF EXISTS tmp_User_Role_Link; - -- DROP TEMPORARY TABLE IF EXISTS tmp_User_Role_Link; - DROP TABLE IF EXISTS tmp_Shop_Product_p_Shop_User_Eval; - -- DROP TABLE IF EXISTS Shop_User_Eval_Temp; - - - -- Parse arguments + get default values - /* - IF a_guid IS NULL THEN - SET a_guid = UUID(); - END IF; - */ - IF a_id_user IS NULL THEN - SET a_id_user = ''; - ELSE - SET a_id_user = TRIM(a_id_user); - END IF; - IF a_get_inactive_users IS NULL THEN - SET a_get_inactive_users = 0; - END IF; - /* - IF a_get_user_permissions IS NULL THEN - SET a_get_user_permissions = 0; - END IF; - */ - IF a_ids_permission IS NULL THEN - SET a_ids_permission = ''; - ELSE - SET a_ids_permission = TRIM(a_ids_permission); - END IF; - IF a_ids_access_level IS NULL THEN - SET a_ids_access_level = ''; - ELSE - SET a_ids_access_level = TRIM(a_ids_access_level); - END IF; - IF a_ids_permutation IS NULL THEN - SET a_ids_permutation = ''; - ELSE - SET a_ids_permutation = TRIM(a_ids_permutation); - END IF; - - -- Permanent Table - CREATE TABLE IF NOT EXISTS Shop_User_Eval_Temp ( - id_row INT PRIMARY KEY AUTO_INCREMENT NOT NULL, - guid BINARY(36) NOT NULL, - id_user INT, - id_permission_required INT NOT NULL, - CONSTRAINT FK_Shop_User_Eval_Temp_id_permission_required - FOREIGN KEY (id_permission_required) - REFERENCES Shop_Permission (id_permission), - /* - id_access_level_required INT NOT NULL, - CONSTRAINT FK_Shop_User_Eval_Temp_id_access_level_required - FOREIGN KEY (id_access_level_required) - REFERENCES Shop_Access_Level (id_access_level), - */ - priority_access_level_required INT NOT NULL, - /* - CONSTRAINT FK_Shop_User_Eval_Temp_priority_access_level_required - FOREIGN KEY (priority_access_level_required) - REFERENCES Shop_Access_Level (priority), - */ - id_product INT NULL, - CONSTRAINT FK_Shop_User_Eval_Temp_id_product - FOREIGN KEY (id_product) - REFERENCES partsltd_prod.Shop_Product (id_product), - id_permutation INT NULL, - CONSTRAINT FK_Shop_User_Eval_Temp_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES partsltd_prod.Shop_Product_Permutation (id_permutation), - is_super_user BIT NULL, - priority_access_level_user INT NULL, - /* - CONSTRAINT FK_Shop_User_Eval_Temp_priority_access_level_minimum - FOREIGN KEY (priority_access_level_minimum) - REFERENCES Shop_Access_Level (priority) - */ - can_view BIT, - can_edit BIT, - can_admin BIT -- DEFAULT 0 - ); - - CREATE TABLE IF NOT EXISTS tmp_Shop_Product_p_Shop_User_Eval ( - id_row INT PRIMARY KEY AUTO_INCREMENT NOT NULL, - id_product INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_p_Shop_User_Eval_id_product FOREIGN KEY (id_product) - REFERENCES partsltd_prod.Shop_Product (id_product), - id_permutation INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_p_Shop_User_Eval_id_permutation FOREIGN KEY (id_permutation) - REFERENCES partsltd_prod.Shop_Product_Permutation (id_permutation), - id_access_level_required INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_p_Shop_User_Eval_id_access_level_required FOREIGN KEY (id_access_level_required) - REFERENCES Shop_Access_Level (id_access_level), - guid BINARY(36) NOT NULL, - rank_permutation INT NOT NULL - ); - - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - guid BINARY(36) NOT NULL, - id_type INT NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type (id_type), - code VARCHAR(50), - msg VARCHAR(4000) NOT NULL - ); - - -- select * from Shop_Msg_Error_Type; - - -- Parse filters - IF a_guid IS NULL OR EXISTS (SELECT * FROM Shop_User_Eval_Temp WHERE a_guid = guid) THEN - INSERT INTO tmp_Msg_Error ( - guid, - code, - msg - ) - VALUES ( - a_guid, - v_code_error_data, - 'Invalid guid argument.' - ) - ; - END IF; - SET v_has_filter_user = CASE WHEN a_id_user = '' THEN 0 ELSE 1 END; - SET a_ids_permission = REPLACE(a_ids_permission, '|', ','); - SET v_has_filter_permission = CASE WHEN a_ids_permission = '' THEN 0 ELSE 1 END; - SET a_ids_access_level = REPLACE(a_ids_access_level, '|', ','); - SET v_has_filter_access_level = CASE WHEN a_ids_access_level = '' THEN 0 ELSE 1 END; - SET a_ids_permutation = REPLACE(a_ids_permutation, '|', ','); - SET v_has_filter_permutation = CASE WHEN a_ids_permutation = '' THEN 0 ELSE 1 END; - SET v_id_access_level_view = (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW' LIMIT 1); - SET v_priority_access_level_view = (SELECT priority FROM Shop_Access_Level WHERE id_access_level = v_id_access_level_view); - SET v_priority_access_level_edit = (SELECT priority FROM Shop_Access_Level WHERE code = 'EDIT' LIMIT 1); - SET v_priority_access_level_admin = (SELECT priority FROM Shop_Access_Level WHERE code = 'ADMIN' LIMIT 1); - - /* - select v_priority_access_level_view, - v_priority_access_level_edit, - v_priority_access_level_admin - ; - */ - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE GUID = a_guid) THEN - IF v_has_filter_access_level THEN - CALL p_split(a_ids_access_level, ','); - SET v_id_access_level := ( - SELECT AL.id_access_level - FROM Split_Temp ST - INNER JOIN Shop_Access_Level AL - ON CONVERT(ST.substring, DECIMAL(10,0)) = AL.id_access_level - AND AL.active - ORDER BY AL.priority ASC - LIMIT 1 - ); - DROP TABLE Split_Temp; - IF 0 = v_id_access_level OR v_id_access_level <=> NULL THEN - -- SET v_has_filter_access_level = 0; - INSERT INTO tmp_Msg_Error ( - guid, - code, - msg - ) - VALUES ( - a_guid, - v_code_error_data, - 'Access level ID not found.' - ) - ; - END IF; - /* - END IF; - IF NOT v_has_filter_access_level THEN - */ - ELSE - SET v_id_access_level = v_id_access_level_view; - END IF; - END IF; - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE GUID = a_guid) THEN - IF v_has_filter_permutation THEN - INSERT INTO tmp_Shop_Product_p_Shop_User_Eval ( - id_product, - id_permutation, - id_access_level_required, - guid, - rank_permutation - ) - SELECT - PP.id_product, - PP.id_permutation, - PP.id_access_level_required, - a_guid, - RANK() OVER (ORDER BY PP.id_product, PP.id_permutation, AL.priority) AS rank_permutation - FROM Shop_Product_Permutation PP - INNER JOIN Shop_Access_Level AL - ON PP.id_access_level_required = AL.id_access_level - AND AL.active - WHERE FIND_IN_SET(PP.id_permutation, a_ids_permutation) > 0 - -- AND P.active -- not worried as we want users to be able to see their order history - ; - /* - DELETE FROM tmp_Shop_Product_p_Shop_User_Eval - WHERE rank_permutation > 1 - ; - */ - SET v_has_filter_permutation = EXISTS (SELECT * FROM tmp_Shop_Product_p_Shop_User_Eval WHERE a_guid = guid); - END IF; - - IF v_has_filter_permission THEN - -- Invalid permission IDs - IF EXISTS (SELECT id_permission FROM Shop_Permission WHERE FIND_IN_SET(id_permission, a_ids_permission) > 0 AND NOT active) THEN - INSERT INTO tmp_Msg_Error ( - guid, - code, - msg - ) - VALUES ( - a_guid, - v_code_error_data, - CONCAT('The following permissions are no longer active: ', (SELECT GROUP_CONCAT(name SEPARATOR ', ') FROM Shop_Permission WHERE FIND_IN_SET(id_permission, a_ids_permission) > 0 AND NOT active)) - ) - ; - END IF; - END IF; - END IF; - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE GUID = a_guid) THEN - IF v_has_filter_user THEN - SET a_id_user := (SELECT id_user FROM Shop_User WHERE id_user LIKE a_id_user AND active); - SET v_has_filter_user = NOT (a_id_user <=> NULL); - IF NOT v_has_filter_user THEN - INSERT INTO tmp_Msg_Error ( - guid, - code, - msg - ) - VALUES ( - a_guid, - v_code_error_data, - 'User ID not found.' - ) - ; - END IF; - END IF; - END IF; - - -- Get users - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE GUID = a_guid) THEN - INSERT INTO Shop_User_Eval_Temp ( - guid, - id_user, - id_permission_required, - priority_access_level_required - /* - priority_access_level_user, - is_super_user, - can_view, - can_edit, - can_admin - */ - ) - SELECT a_guid, - a_id_user, - P.id_permission, - AL.priority - FROM partsltd_prod.Shop_Permission P - INNER JOIN Shop_Access_Level AL - ON P.id_access_level_required = AL.id_access_level - AND AL.active - WHERE FIND_IN_SET(P.id_permission, a_ids_permission) > 0 - ; - - IF v_has_filter_permutation THEN - SET v_ids_row_delete := (SELECT GROUP_CONCAT(id_row SEPARATOR ',') FROM Shop_User_Eval_Temp WHERE a_guid = guid); - - INSERT INTO Shop_User_Eval_Temp ( - guid, - id_user, - id_permission_required, - id_product, - id_permutation, - priority_access_level_required - ) - SELECT UE_T.guid, - UE_T.id_user, - UE_T.id_permission_required, - t_P.id_product, - t_P.id_permutation, - CASE WHEN UE_T.priority_access_level_required < AL.priority THEN UE_T.priority_access_level_required ELSE AL.priority END -- UE_T.priority_access_level_required - FROM tmp_Shop_Product_p_Shop_User_Eval t_P - INNER JOIN Shop_Access_Level AL - ON t_P.id_access_leveL_required = AL.id_access_level - AND AL.active - CROSS JOIN Shop_User_Eval_Temp UE_T - ON a_id_user = UE_T.id_user - WHERE a_guid = t_P.guid - ; - - DELETE FROM Shop_User_Eval_Temp - WHERE FIND_IN_SET(id_row, v_ids_row_delete) > 0 - ; - END IF; - - /* - INSERT INTO Shop_User_Eval_Temp ( - guid, - id_user, - id_permission_required, - -- id_access_level_required, - priority_access_level_required, - priority_access_level_user, - is_super_user - /* - can_view, - can_edit, - can_admin - * - ) - SELECT a_guid, - U.id_user, - P.id_permission, - AL.priority, - /* - v_id_permission, - v_id_access_level, - * - MIN(AL.priority), - U.is_super_user - /* - CASE WHEN U.is_super_user THEN 1 ELSE CASE WHEN priority_access_level_minimum <= v_priority_access_level_view THEN 1 ELSE 0 END END, - CASE WHEN U.is_super_user THEN 1 ELSE CASE WHEN priority_access_level_minimum <= v_priority_access_level_edit THEN 1 ELSE 0 END END, - CASE WHEN U.is_super_user THEN 1 ELSE CASE WHEN priority_access_level_minimum <= v_priority_access_level_admin THEN 1 ELSE 0 END END - * - FROM partsltd_prod.Shop_User U - INNER JOIN Shop_User_Role_Link URL - ON U.id_user = URL.id_user - AND URL.active - INNER JOIN Shop_Role_Permission_Link RPL - ON URL.id_role = RPL.id_role - AND RPL.active - INNER JOIN Shop_Permission P - ON RPL.id_permission = P.id_permission - AND P.active - INNER JOIN Shop_Access_Level AL - ON RPL.id_access_level = AL.id_access_level - AND AL.active - WHERE U.id_user = a_id_user - AND (a_get_inactive_users OR U.active) - AND FIND_IN_SET(P.id_permission, a_ids_permission) > 0 - -- AND v_id_permission = P.id_permission - -- AND v_id_access_level = AL.id_access_leveld - GROUP BY U.id_user, P.id_permission -- , is_super_user - ; - */ - - IF v_has_filter_user THEN - UPDATE Shop_User_Eval_Temp UE_T - INNER JOIN Shop_User U - ON UE_T.id_user = U.id_user - AND U.active - INNER JOIN Shop_User_Role_Link URL - ON U.id_user = URL.id_user - AND URL.active - INNER JOIN Shop_Role_Permission_Link RPL - ON URL.id_role = RPL.id_role - AND RPL.active - INNER JOIN Shop_Access_Level AL - ON RPL.id_access_level = AL.id_access_level - AND AL.active - SET UE_T.priority_access_level_user = AL.priority, - UE_T.is_super_user = U.is_super_user, - UE_T.can_view = CASE WHEN U.is_super_user THEN 1 ELSE CASE WHEN ISNULL(AL.priority) THEN 1 ELSE CASE WHEN AL.priority <= v_priority_access_level_view AND AL.priority <= UE_T.priority_access_level_required THEN 1 ELSE 0 END END END, - UE_T.can_edit = CASE WHEN U.is_super_user THEN 1 ELSE CASE WHEN NOT ISNULL(AL.priority) AND AL.priority <= v_priority_access_level_edit AND AL.priority <= UE_T.priority_access_level_required THEN 1 ELSE 0 END END, - UE_T.can_admin = CASE WHEN U.is_super_user THEN 1 ELSE CASE WHEN NOT ISNULL(AL.priority) AND AL.priority <= v_priority_access_level_admin AND AL.priority <= UE_T.priority_access_level_required THEN 1 ELSE 0 END END - WHERE UE_T.guid = a_guid - AND UE_T.id_user = a_id_user - AND RPL.id_permission = UE_T.id_permission_required - -- GROUP BY UE_T.id_user - ; - ELSE - UPDATE Shop_User_Eval_Temp UE_T - SET UE_T.priority_access_level_user = v_priority_access_level_view, - UE_T.is_super_user = 0, - UE_T.can_view = (v_priority_access_level_view <= UE_T.priority_access_level_required), - UE_T.can_edit = 0, - UE_T.can_admin = 0 - WHERE UE_T.guid = a_guid - AND UE_T.id_user = a_id_user - -- GROUP BY UE_T.id_user - ; - END IF; - END IF; - - -- Clean up - DROP TABLE IF EXISTS tmp_Shop_Product_p_Shop_User_Eval; - -- DROP TEMPORARY TABLE IF EXISTS tmp_User_Role_Link; - -- DROP TABLE IF EXISTS tmp_Msg_Error; -END ;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; - -/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; -/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; -/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; -/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; -/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; - --- Dump completed on 2024-04-28 19:04:05 diff --git a/static/MySQL/deprecated/dump2.sql b/static/MySQL/deprecated/dump2.sql deleted file mode 100644 index c3b3c18d..00000000 --- a/static/MySQL/deprecated/dump2.sql +++ /dev/null @@ -1,8235 +0,0 @@ -CREATE DATABASE IF NOT EXISTS `partsltd_prod` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci */ /*!80016 DEFAULT ENCRYPTION='N' */; -USE `partsltd_prod`; --- MySQL dump 10.13 Distrib 8.0.36, for Win64 (x86_64) --- --- Host: localhost Database: partsltd_prod --- ------------------------------------------------------ --- Server version 8.0.35 - -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!50503 SET NAMES utf8 */; -/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; -/*!40103 SET TIME_ZONE='+00:00' */; -/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; -/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; -/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; -/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; - --- --- Table structure for table `file_type` --- - -DROP TABLE IF EXISTS `file_type`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `file_type` ( - `id_type` int NOT NULL AUTO_INCREMENT, - `code` varchar(50) DEFAULT NULL, - `name` varchar(100) DEFAULT NULL, - `extension` varchar(50) DEFAULT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `updated_last_on` datetime DEFAULT NULL, - `updated_last_by` varchar(100) DEFAULT NULL, - PRIMARY KEY (`id_type`) -) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `file_type` --- - -LOCK TABLES `file_type` WRITE; -/*!40000 ALTER TABLE `file_type` DISABLE KEYS */; -INSERT INTO `file_type` VALUES (1,'JPEG','Joint Photographic Export Group','jpg','2024-04-28 19:03:07','root@localhost',NULL,NULL),(2,'PNG','Portable Network Graphic','png','2024-04-28 19:03:07','root@localhost',NULL,NULL),(3,'GIF','GIF','gif','2024-04-28 19:03:07','root@localhost',NULL,NULL),(4,'MPEG-4','Multimedia Photographic Export Group 4','mp4','2024-04-28 19:03:07','root@localhost',NULL,NULL); -/*!40000 ALTER TABLE `file_type` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_File_Type` BEFORE INSERT ON `file_type` FOR EACH ROW BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_File_Type` BEFORE UPDATE ON `file_type` FOR EACH ROW BEGIN - INSERT INTO File_Type_Audit ( - id_type, - name_field, - value_prev, - value_new - ) - -- Changed code - SELECT NEW.id_type, 'code', OLD.code, NEW.code - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_type, 'name', OLD.name, NEW.name - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed extension - SELECT NEW.id_type, 'extension', CONVERT(OLD.extension, CHAR), CONVERT(NEW.extension, CHAR) - WHERE NOT OLD.extension <=> NEW.extension - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `file_type_audit` --- - -DROP TABLE IF EXISTS `file_type_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `file_type_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_type` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `updated_last_on` datetime DEFAULT NULL, - `updated_last_by` varchar(100) DEFAULT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_File_Type_Audit_id_type` (`id_type`), - CONSTRAINT `FK_File_Type_Audit_id_type` FOREIGN KEY (`id_type`) REFERENCES `file_type` (`id_type`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `file_type_audit` --- - -LOCK TABLES `file_type_audit` WRITE; -/*!40000 ALTER TABLE `file_type_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `file_type_audit` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_File_Type_Audit` BEFORE INSERT ON `file_type_audit` FOR EACH ROW BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_File_Type_Audit` BEFORE UPDATE ON `file_type_audit` FOR EACH ROW BEGIN - SET NEW.updated_last_on = NOW(); - SET NEW.updated_last_by = CURRENT_USER(); -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_access_level` --- - -DROP TABLE IF EXISTS `shop_access_level`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_access_level` ( - `id_access_level` int NOT NULL AUTO_INCREMENT, - `code` varchar(50) DEFAULT NULL, - `name` varchar(255) DEFAULT NULL, - `priority` int NOT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `display_order` int NOT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_access_level`), - KEY `FK_Shop_Access_Level_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Access_Level_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_user_change_set` (`id_change_set`) -) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_access_level` --- - -LOCK TABLES `shop_access_level` WRITE; -/*!40000 ALTER TABLE `shop_access_level` DISABLE KEYS */; -INSERT INTO `shop_access_level` VALUES (1,'VIEW','View',3,_binary '',1,'2024-04-28 19:03:07','root@localhost',NULL),(2,'EDIT','Edit',2,_binary '',2,'2024-04-28 19:03:07','root@localhost',NULL),(3,'ADMIN','Admin',1,_binary '',3,'2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_access_level` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Access_Level` BEFORE INSERT ON `shop_access_level` FOR EACH ROW BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Access_Level` BEFORE UPDATE ON `shop_access_level` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Access_Level_Audit ( - id_access_level, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_access_level, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT (OLD.code <=> NEW.code) - UNION - -- Changed name - SELECT NEW.id_access_level, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT (OLD.name <=> NEW.name) - UNION - -- Changed priority - SELECT NEW.id_access_level, 'priority', CONVERT(OLD.priority, CHAR), CONVERT(NEW.priority, CHAR), NEW.id_change_set - WHERE NOT (OLD.priority <=> NEW.priority) - UNION - -- Changed active - SELECT NEW.id_access_level, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_access_level, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_access_level_audit` --- - -DROP TABLE IF EXISTS `shop_access_level_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_access_level_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_access_level` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Access_Level_Audit_id_access_level` (`id_access_level`), - KEY `FK_Shop_Access_Level_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Access_Level_Audit_id_access_level` FOREIGN KEY (`id_access_level`) REFERENCES `shop_access_level` (`id_access_level`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Access_Level_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_user_change_set` (`id_change_set`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_access_level_audit` --- - -LOCK TABLES `shop_access_level_audit` WRITE; -/*!40000 ALTER TABLE `shop_access_level_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_access_level_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_address` --- - -DROP TABLE IF EXISTS `shop_address`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_address` ( - `id_address` int NOT NULL AUTO_INCREMENT, - `id_user` varchar(200) NOT NULL, - `id_region` int NOT NULL, - `name_full` varchar(255) NOT NULL, - `phone_number` varchar(20) NOT NULL, - `postcode` varchar(20) NOT NULL, - `address_line_1` varchar(100) NOT NULL, - `address_line_2` varchar(100) NOT NULL, - `city` varchar(50) NOT NULL, - `county` varchar(100) NOT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_address`), - KEY `FK_Shop_Address_id_user` (`id_user`), - KEY `FK_Shop_Address_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Address_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_user_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Address_id_user` FOREIGN KEY (`id_user`) REFERENCES `shop_user` (`id_user`) ON UPDATE RESTRICT -) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_address` --- - -LOCK TABLES `shop_address` WRITE; -/*!40000 ALTER TABLE `shop_address` DISABLE KEYS */; -INSERT INTO `shop_address` VALUES (1,'auth0|6582b95c895d09a70ba10fef',1,'Teddy','07375 571430','NN6 6EB','The Laurels','Cold Ashby Road','Cold Ashby','Northamptonshire',_binary '','2024-04-28 19:03:07','root@localhost',NULL),(2,'parts_guest',1,'Guest','07375 571430','NN6 6EB','The Laurels','Cold Ashby Road','Cold Ashby','Northamptonshire',_binary '','2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_address` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Address` BEFORE INSERT ON `shop_address` FOR EACH ROW BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Address` BEFORE UPDATE ON `shop_address` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Address_Audit ( - id_address, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed region - SELECT NEW.id_address, 'id_region', OLD.id_region, NEW.id_region, NEW.id_change_set - WHERE NOT OLD.id_region <=> NEW.id_region - UNION - -- Changed name_full - SELECT NEW.id_address, 'name_full', OLD.name_full, NEW.name_full, NEW.id_change_set - WHERE NOT OLD.name_full <=> NEW.name_full - UNION - -- Changed phone_number - SELECT NEW.id_address, 'phone_number', OLD.phone_number, NEW.phone_number, NEW.id_change_set - WHERE NOT OLD.phone_number <=> NEW.phone_number - UNION - -- Changed postcode - SELECT NEW.id_address, 'postcode', OLD.postcode, NEW.postcode, NEW.id_change_set - WHERE NOT OLD.postcode <=> NEW.postcode - UNION - -- Changed address_line_1 - SELECT NEW.id_address, 'address_line_1', OLD.address_line_1, NEW.address_line_1, NEW.id_change_set - WHERE NOT OLD.address_line_1 <=> NEW.address_line_1 - UNION - -- Changed address_line_2 - SELECT NEW.id_address, 'address_line_2', OLD.address_line_2, NEW.address_line_2, NEW.id_change_set - WHERE NOT OLD.address_line_2 <=> NEW.address_line_2 - UNION - -- Changed city - SELECT NEW.id_address, 'city', OLD.city, NEW.city, NEW.id_change_set - WHERE NOT OLD.city <=> NEW.city - UNION - -- Changed county - SELECT NEW.id_address, 'county', OLD.county, NEW.county, NEW.id_change_set - WHERE NOT OLD.county <=> NEW.county - UNION - -- Changed active - SELECT NEW.id_address, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_address_audit` --- - -DROP TABLE IF EXISTS `shop_address_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_address_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_address` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Address_Audit_id_address` (`id_address`), - KEY `FK_Shop_Address_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Address_Audit_id_address` FOREIGN KEY (`id_address`) REFERENCES `shop_address` (`id_address`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Address_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_user_change_set` (`id_change_set`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_address_audit` --- - -LOCK TABLES `shop_address_audit` WRITE; -/*!40000 ALTER TABLE `shop_address_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_address_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_category` --- - -DROP TABLE IF EXISTS `shop_category`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_category` ( - `id_category` int NOT NULL AUTO_INCREMENT, - `code` varchar(50) DEFAULT NULL, - `name` varchar(255) DEFAULT NULL, - `description` varchar(4000) DEFAULT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `display_order` int NOT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_category`), - KEY `FK_Shop_Product_Category_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Category_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`) -) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_category` --- - -LOCK TABLES `shop_category` WRITE; -/*!40000 ALTER TABLE `shop_category` DISABLE KEYS */; -INSERT INTO `shop_category` VALUES (1,'ASS','Assistive Devices','Braille product line and other assistive devices',_binary '',1,'2024-04-28 19:03:07','root@localhost',NULL),(2,'MISC','Miscellaneous','Not category allocated products',_binary '',99,'2024-04-28 19:03:07','root@localhost',NULL),(3,'TECH','Technology','Technological devices',_binary '',2,'2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_category` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Product_Category` BEFORE INSERT ON `shop_category` FOR EACH ROW BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Product_Category` BEFORE UPDATE ON `shop_category` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Product_Category_Audit ( - id_category, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_category, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_category, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed description - SELECT NEW.id_category, 'description', OLD.description, NEW.description, NEW.id_change_set - WHERE NOT OLD.description <=> NEW.description - UNION - -- Changed active - SELECT NEW.id_category, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_category, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_category_audit` --- - -DROP TABLE IF EXISTS `shop_category_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_category_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_category` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Product_Category_Audit_id_category` (`id_category`), - KEY `FK_Shop_Product_Category_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Category_Audit_id_category` FOREIGN KEY (`id_category`) REFERENCES `shop_category` (`id_category`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Product_Category_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_category_audit` --- - -LOCK TABLES `shop_category_audit` WRITE; -/*!40000 ALTER TABLE `shop_category_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_category_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_currency` --- - -DROP TABLE IF EXISTS `shop_currency`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_currency` ( - `id_currency` int NOT NULL AUTO_INCREMENT, - `code` varchar(50) NOT NULL, - `name` varchar(255) NOT NULL, - `symbol` varchar(1) NOT NULL, - `factor_from_GBP` float NOT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `display_order` int NOT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_currency`), - KEY `FK_Shop_Currency_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Currency_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`) ON UPDATE RESTRICT -) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_currency` --- - -LOCK TABLES `shop_currency` WRITE; -/*!40000 ALTER TABLE `shop_currency` DISABLE KEYS */; -INSERT INTO `shop_currency` VALUES (1,'GBP','Great British Pound','£',1,_binary '',1,'2024-04-28 19:03:07','root@localhost',NULL),(2,'EUR','Euro','€',1.17,_binary '',2,'2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_currency` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Currency` BEFORE INSERT ON `shop_currency` FOR EACH ROW BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Currency` BEFORE UPDATE ON `shop_currency` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Currency_Audit ( - id_currency, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_currency, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_currency, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed symbol - SELECT NEW.id_currency, 'symbol', OLD.symbol, NEW.symbol, NEW.id_change_set - WHERE NOT OLD.symbol <=> NEW.symbol - UNION - -- Changed ratio_2_GBP - SELECT NEW.id_currency, 'factor_from_GBP', OLD.factor_from_GBP, NEW.factor_from_GBP, NEW.id_change_set - WHERE NOT OLD.factor_from_GBP <=> NEW.factor_from_GBP - UNION - -- Changed active - SELECT NEW.id_currency, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_currency, 'display_order', CONVERT(display_order, CHAR), CONVERT(display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_currency_audit` --- - -DROP TABLE IF EXISTS `shop_currency_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_currency_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_currency` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Currency_Audit_id_currency` (`id_currency`), - KEY `FK_Shop_Currency_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Currency_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_user_change_set` (`id_change_set`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Currency_Audit_id_currency` FOREIGN KEY (`id_currency`) REFERENCES `shop_currency` (`id_currency`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_currency_audit` --- - -LOCK TABLES `shop_currency_audit` WRITE; -/*!40000 ALTER TABLE `shop_currency_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_currency_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_delivery_option` --- - -DROP TABLE IF EXISTS `shop_delivery_option`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_delivery_option` ( - `id_option` int NOT NULL AUTO_INCREMENT, - `code` varchar(50) NOT NULL, - `name` varchar(100) NOT NULL, - `description` varchar(4000) DEFAULT NULL, - `latency_delivery_min` int NOT NULL, - `latency_delivery_max` int NOT NULL, - `quantity_min` int NOT NULL, - `quantity_max` int NOT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `display_order` int NOT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_option`), - KEY `FK_Shop_Delivery_Option_Type_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Delivery_Option_Type_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`) -) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_delivery_option` --- - -LOCK TABLES `shop_delivery_option` WRITE; -/*!40000 ALTER TABLE `shop_delivery_option` DISABLE KEYS */; -INSERT INTO `shop_delivery_option` VALUES (1,'COLLECT','Collection',NULL,0,0,0,1,_binary '',1,'2024-04-28 19:03:07','root@localhost',NULL),(2,'SIGNED_1','First Class Signed-For',NULL,2,4,0,1,_binary '',2,'2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_delivery_option` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Delivery_Option` BEFORE INSERT ON `shop_delivery_option` FOR EACH ROW BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Delivery_Option` BEFORE UPDATE ON `shop_delivery_option` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Delivery_Option_Audit ( - id_option, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_option, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_option, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed latency_delivery_min - SELECT NEW.id_option, 'latency_delivery_min', CONVERT(OLD.latency_delivery_min, CHAR), CONVERT(NEW.latency_delivery_min, CHAR), NEW.id_change_set - WHERE NOT OLD.latency_delivery_min <=> NEW.latency_delivery_min - UNION - -- Changed latency_delivery_max - SELECT NEW.id_option, 'latency_delivery_max', CONVERT(OLD.latency_delivery_max, CHAR), CONVERT(NEW.latency_delivery_max, CHAR), NEW.id_change_set - WHERE NOT OLD.latency_delivery_max <=> NEW.latency_delivery_max - UNION - -- Changed quantity_min - SELECT NEW.id_option, 'quantity_min', CONVERT(OLD.quantity_min, CHAR), CONVERT(NEW.quantity_min, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_min <=> NEW.quantity_min - UNION - -- Changed quantity_max - SELECT NEW.id_option, 'quantity_max', CONVERT(OLD.quantity_max, CHAR), CONVERT(NEW.quantity_max, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - UNION - -- Changed active - SELECT NEW.id_option, 'active', CONVERT(OLD.active, CHAR), CONVERT(NEW.active, CHAR), NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - UNION - -- Changed display_order - SELECT NEW.id_option, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_delivery_option_audit` --- - -DROP TABLE IF EXISTS `shop_delivery_option_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_delivery_option_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_option` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Delivery_Option_Audit_id_option` (`id_option`), - KEY `FK_Shop_Delivery_Option_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Delivery_Option_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Delivery_Option_Audit_id_option` FOREIGN KEY (`id_option`) REFERENCES `shop_delivery_option` (`id_option`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_delivery_option_audit` --- - -LOCK TABLES `shop_delivery_option_audit` WRITE; -/*!40000 ALTER TABLE `shop_delivery_option_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_delivery_option_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_discount` --- - -DROP TABLE IF EXISTS `shop_discount`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_discount` ( - `id_discount` int NOT NULL AUTO_INCREMENT, - `code` varchar(50) NOT NULL, - `name` varchar(200) NOT NULL, - `id_product` int NOT NULL, - `id_permutation` int DEFAULT NULL, - `multiplier` float NOT NULL DEFAULT '1', - `subtractor` float NOT NULL DEFAULT '0', - `apply_multiplier_first` bit(1) DEFAULT b'1', - `quantity_min` float NOT NULL DEFAULT '0', - `quantity_max` float NOT NULL, - `date_start` datetime NOT NULL, - `date_end` datetime NOT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `display_order` int NOT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_discount`), - KEY `FK_Shop_Discount_id_product` (`id_product`), - KEY `FK_Shop_Discount_id_permutation` (`id_permutation`), - KEY `FK_Shop_Discount_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Discount_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Discount_id_permutation` FOREIGN KEY (`id_permutation`) REFERENCES `shop_product_permutation` (`id_permutation`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Discount_id_product` FOREIGN KEY (`id_product`) REFERENCES `shop_product` (`id_product`), - CONSTRAINT `shop_discount_chk_1` CHECK ((`multiplier` > 0)) -) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_discount` --- - -LOCK TABLES `shop_discount` WRITE; -/*!40000 ALTER TABLE `shop_discount` DISABLE KEYS */; -INSERT INTO `shop_discount` VALUES (1,'CRIMBO50','Christmas 50% off sale!',1,1,0.5,0,_binary '',3,9,'2024-04-28 19:03:07','2023-12-31 23:59:59',_binary '',1,'2024-04-28 19:03:07','root@localhost',NULL),(2,'CRIMBO50','Christmas 50% off sale!',1,2,0.5,0,_binary '',3,9,'2024-04-28 19:03:07','2023-12-31 23:59:59',_binary '',1,'2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_discount` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Discount` BEFORE INSERT ON `shop_discount` FOR EACH ROW BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Discount` BEFORE UPDATE ON `shop_discount` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Discount_Audit ( - id_discount, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_discount, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_discount, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed multiplier - SELECT NEW.id_discount, 'multiplier', OLD.multiplier, NEW.multiplier, NEW.id_change_set - WHERE NOT OLD.multiplier <=> NEW.multiplier - UNION - -- Changed subtractor - SELECT NEW.id_discount, 'subtractor', OLD.subtractor, NEW.subtractor, NEW.id_change_set - WHERE NOT OLD.subtractor <=> NEW.subtractor - UNION - -- Changed apply_multiplier_first - SELECT NEW.id_discount, 'apply_multiplier_first', CONVERT(CONVERT(OLD.apply_multiplier_first, SIGNED), CHAR), CONVERT(CONVERT(NEW.apply_multiplier_first, SIGNED), CHAR), NEW.id_change_set - WHERE NOT OLD.apply_multiplier_first <=> NEW.apply_multiplier_first - UNION - -- Changed quantity_min - SELECT NEW.id_discount, 'quantity_min', OLD.quantity_min, NEW.quantity_min, NEW.id_change_set - WHERE NOT OLD.quantity_min <=> NEW.quantity_min - UNION - -- Changed quantity_max - SELECT NEW.id_discount, 'quantity_max', OLD.quantity_max, NEW.quantity_max, NEW.id_change_set - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - UNION - -- Changed date_start - SELECT NEW.id_discount, 'date_start', OLD.date_start, NEW.date_start, NEW.id_change_set - WHERE NOT OLD.date_start <=> NEW.date_start - UNION - -- Changed date_end - SELECT NEW.id_discount, 'date_end', OLD.date_end, NEW.date_end, NEW.id_change_set - WHERE NOT OLD.date_end <=> NEW.date_end - UNION - -- Changed display_order - SELECT NEW.id_discount, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - UNION - -- Changed active - SELECT NEW.id_discount, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_discount_audit` --- - -DROP TABLE IF EXISTS `shop_discount_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_discount_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_discount` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Discount_Audit_id_discount` (`id_discount`), - KEY `FK_Shop_Discount_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Discount_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Discount_Audit_id_discount` FOREIGN KEY (`id_discount`) REFERENCES `shop_discount` (`id_discount`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_discount_audit` --- - -LOCK TABLES `shop_discount_audit` WRITE; -/*!40000 ALTER TABLE `shop_discount_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_discount_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_discount_region_currency_link` --- - -DROP TABLE IF EXISTS `shop_discount_region_currency_link`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_discount_region_currency_link` ( - `id_link` int NOT NULL AUTO_INCREMENT, - `id_discount` int NOT NULL, - `id_region` int NOT NULL, - `id_currency` int NOT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_link`), - KEY `FK_Shop_Discount_Region_Currency_Link_id_discount` (`id_discount`), - KEY `FK_Shop_Discount_Region_Currency_Link_id_region` (`id_region`), - KEY `FK_Shop_Discount_Region_Currency_Link_id_currency` (`id_currency`), - KEY `FK_Shop_Discount_Region_Currency_Link_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Discount_Region_Currency_Link_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Discount_Region_Currency_Link_id_currency` FOREIGN KEY (`id_currency`) REFERENCES `shop_currency` (`id_currency`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Discount_Region_Currency_Link_id_discount` FOREIGN KEY (`id_discount`) REFERENCES `shop_discount` (`id_discount`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Discount_Region_Currency_Link_id_region` FOREIGN KEY (`id_region`) REFERENCES `shop_region` (`id_region`) ON UPDATE RESTRICT -) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_discount_region_currency_link` --- - -LOCK TABLES `shop_discount_region_currency_link` WRITE; -/*!40000 ALTER TABLE `shop_discount_region_currency_link` DISABLE KEYS */; -INSERT INTO `shop_discount_region_currency_link` VALUES (1,1,1,1,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(2,2,1,1,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(3,1,1,2,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(4,2,1,2,_binary '','2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_discount_region_currency_link` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Discount_Region_Currency_Link` BEFORE INSERT ON `shop_discount_region_currency_link` FOR EACH ROW BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Discount_Region_Currency_Link` BEFORE UPDATE ON `shop_discount_region_currency_link` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Discount_Region_Currency_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_discount - SELECT NEW.id_link, 'id_discount', CONVERT(OLD.id_discount, CHAR), CONVERT(NEW.id_discount, CHAR), NEW.id_change_set - WHERE NOT OLD.id_discount <=> NEW.id_discount - UNION - -- Changed id_region - SELECT NEW.id_link, 'id_region', CONVERT(OLD.id_region, CHAR), CONVERT(NEW.id_region, CHAR), NEW.id_change_set - WHERE NOT OLD.id_region <=> NEW.id_region - UNION - */ - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_discount_region_currency_link_audit` --- - -DROP TABLE IF EXISTS `shop_discount_region_currency_link_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_discount_region_currency_link_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_link` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Discount_Region_Currency_Link_Audit_id_link` (`id_link`), - KEY `FK_Shop_Discount_Region_Currency_Link_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Discount_Region_Currency_Link_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Discount_Region_Currency_Link_Audit_id_link` FOREIGN KEY (`id_link`) REFERENCES `shop_discount_region_currency_link` (`id_link`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_discount_region_currency_link_audit` --- - -LOCK TABLES `shop_discount_region_currency_link_audit` WRITE; -/*!40000 ALTER TABLE `shop_discount_region_currency_link_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_discount_region_currency_link_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_general` --- - -DROP TABLE IF EXISTS `shop_general`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_general` ( - `id_general` int NOT NULL AUTO_INCREMENT, - `quantity_max` float DEFAULT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_general`), - KEY `CHK_Shop_General_id_change_set` (`id_change_set`), - CONSTRAINT `CHK_Shop_General_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`) -) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_general` --- - -LOCK TABLES `shop_general` WRITE; -/*!40000 ALTER TABLE `shop_general` DISABLE KEYS */; -INSERT INTO `shop_general` VALUES (1,10,'2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_general` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_General` BEFORE INSERT ON `shop_general` FOR EACH ROW BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_General` BEFORE UPDATE ON `shop_general` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_General_Audit ( - id_general, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed quantity max - SELECT NEW.id_general, 'quantity_max', CONVERT(OLD.quantity_max, CHAR), CONVERT(NEW.quantity_max, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_general_audit` --- - -DROP TABLE IF EXISTS `shop_general_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_general_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_general` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_General_Audit_id_general` (`id_general`), - KEY `FK_Shop_General_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_General_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_General_Audit_id_general` FOREIGN KEY (`id_general`) REFERENCES `shop_general` (`id_general`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_general_audit` --- - -LOCK TABLES `shop_general_audit` WRITE; -/*!40000 ALTER TABLE `shop_general_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_general_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_image` --- - -DROP TABLE IF EXISTS `shop_image`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_image` ( - `id_image` int NOT NULL AUTO_INCREMENT, - `id_type_image` int NOT NULL, - `id_type_file` int NOT NULL, - `id_product` int DEFAULT NULL, - `id_permutation` int DEFAULT NULL, - `url` varchar(255) DEFAULT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `display_order` int NOT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_image`), - KEY `FK_Shop_Image_id_type_image` (`id_type_image`), - KEY `FK_Shop_Image_id_type_file` (`id_type_file`), - KEY `FK_Shop_Image_id_product` (`id_product`), - KEY `FK_Shop_Image_id_permutation` (`id_permutation`), - KEY `FK_Shop_Image_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Image_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Image_id_permutation` FOREIGN KEY (`id_permutation`) REFERENCES `shop_product_permutation` (`id_permutation`), - CONSTRAINT `FK_Shop_Image_id_product` FOREIGN KEY (`id_product`) REFERENCES `shop_product` (`id_product`), - CONSTRAINT `FK_Shop_Image_id_type_file` FOREIGN KEY (`id_type_file`) REFERENCES `file_type` (`id_type`), - CONSTRAINT `FK_Shop_Image_id_type_image` FOREIGN KEY (`id_type_image`) REFERENCES `shop_image_type` (`id_type`) -) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_image` --- - -LOCK TABLES `shop_image` WRITE; -/*!40000 ALTER TABLE `shop_image` DISABLE KEYS */; -INSERT INTO `shop_image` VALUES (1,1,1,1,1,'/static/images/prod_PB0NUOSEs06ymG.jpg',_binary '',1,'2024-04-28 19:03:07','root@localhost',NULL),(2,1,1,1,2,'/static/images/prod_PB0NUOSEs06ymG.jpg',_binary '',2,'2024-04-28 19:03:07','root@localhost',NULL),(3,1,1,2,3,'/static/images/prod_PB0NUOSEs06ymG.jpg',_binary '',3,'2024-04-28 19:03:07','root@localhost',NULL),(4,1,1,3,4,'/static/images/prod_.jpg',_binary '',4,'2024-04-28 19:03:07','root@localhost',NULL),(5,1,1,4,5,'/static/images/prod_1.jpg',_binary '',5,'2024-04-28 19:03:07','root@localhost',NULL),(6,1,1,5,6,'/static/images/prod_2.jpg',_binary '',6,'2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_image` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Image` BEFORE INSERT ON `shop_image` FOR EACH ROW BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Image` BEFORE UPDATE ON `shop_image` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change set ID must be provided.'; - END IF; - IF ISNULL(NEW.id_product) AND ISNULL(NEW.id_permutation) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Image must NOT have ID for product AND product permutation.'; - END IF; - - INSERT INTO Shop_Image_Audit ( - id_image, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_type_image - SELECT NEW.id_image, 'id_type_image', CONVERT(OLD.id_type_image, CHAR), CONVERT(NEW.id_type_image, CHAR), NEW.id_change_set - WHERE NOT OLD.id_type_image <=> NEW.id_type_image - UNION - -- Changed id_type_file - SELECT NEW.id_image, 'id_type_file', CONVERT(OLD.id_type_file, CHAR), CONVERT(NEW.id_type_file, CHAR), NEW.id_change_set - WHERE NOT OLD.id_type_file <=> NEW.id_type_file - UNION - -- Changed id_product - SELECT NEW.id_image, 'id_product', CONVERT(OLD.id_product, CHAR), CONVERT(NEW.id_product, CHAR), NEW.id_change_set - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed id_permutation - SELECT NEW.id_image, 'id_permutation', CONVERT(OLD.id_permutation, CHAR), CONVERT(NEW.id_permutation, CHAR), NEW.id_change_set - WHERE NOT OLD.id_permutation <=> NEW.id_permutation - UNION - -- Changed url - SELECT NEW.id_image, 'url', OLD.url, NEW.url, NEW.id_change_set - WHERE NOT OLD.url <=> NEW.url - UNION - -- Changed active - SELECT NEW.id_image, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_image, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_image_audit` --- - -DROP TABLE IF EXISTS `shop_image_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_image_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_image` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Image_Audit_id_image` (`id_image`), - KEY `FK_Shop_Image_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Image_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Image_Audit_id_image` FOREIGN KEY (`id_image`) REFERENCES `shop_image` (`id_image`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_image_audit` --- - -LOCK TABLES `shop_image_audit` WRITE; -/*!40000 ALTER TABLE `shop_image_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_image_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_image_type` --- - -DROP TABLE IF EXISTS `shop_image_type`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_image_type` ( - `id_type` int NOT NULL AUTO_INCREMENT, - `code` varchar(50) DEFAULT NULL, - `name` varchar(255) DEFAULT NULL, - `name_plural` varchar(256) DEFAULT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `display_order` int NOT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_type`), - KEY `FK_Shop_Image_Type_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Image_Type_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`) -) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_image_type` --- - -LOCK TABLES `shop_image_type` WRITE; -/*!40000 ALTER TABLE `shop_image_type` DISABLE KEYS */; -INSERT INTO `shop_image_type` VALUES (1,'FULL','Full Quality Image','Full Quality Images',_binary '',1,'2024-04-28 19:03:07','root@localhost',NULL),(2,'LOW','Low Quality Image','Low Quality Images',_binary '',2,'2024-04-28 19:03:07','root@localhost',NULL),(3,'THUMBNAIL','Thumbnail Image','Thumbnail Images',_binary '',3,'2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_image_type` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Image_Type` BEFORE INSERT ON `shop_image_type` FOR EACH ROW BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Image_Type` BEFORE UPDATE ON `shop_image_type` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Image_Type_Audit ( - id_type, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_type, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_type, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed name_plural - SELECT NEW.id_type, 'name_plural', OLD.name_plural, NEW.name_plural, NEW.id_change_set - WHERE NOT OLD.name_plural <=> NEW.name_plural - UNION - -- Changed active - SELECT NEW.id_type, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_type, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_image_type_audit` --- - -DROP TABLE IF EXISTS `shop_image_type_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_image_type_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_type` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Image_Type_Audit_id_type` (`id_type`), - KEY `FK_Shop_Image_Type_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Image_Type_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Image_Type_Audit_id_type` FOREIGN KEY (`id_type`) REFERENCES `shop_image_type` (`id_type`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_image_type_audit` --- - -LOCK TABLES `shop_image_type_audit` WRITE; -/*!40000 ALTER TABLE `shop_image_type_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_image_type_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_msg_error_type` --- - -DROP TABLE IF EXISTS `shop_msg_error_type`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_msg_error_type` ( - `id_type` int NOT NULL AUTO_INCREMENT, - `code` varchar(50) NOT NULL, - `name` varchar(500) NOT NULL, - `description` varchar(1000) DEFAULT NULL, - PRIMARY KEY (`id_type`) -) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_msg_error_type` --- - -LOCK TABLES `shop_msg_error_type` WRITE; -/*!40000 ALTER TABLE `shop_msg_error_type` DISABLE KEYS */; -INSERT INTO `shop_msg_error_type` VALUES (1,'BAD_DATA','Invalid data','Rubbish data'),(2,'NO_PERMISSION','No permission','Not authorised'),(3,'PRODUCT_AVAILABILITY','Product not available','Product not available'); -/*!40000 ALTER TABLE `shop_msg_error_type` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_permission` --- - -DROP TABLE IF EXISTS `shop_permission`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_permission` ( - `id_permission` int NOT NULL AUTO_INCREMENT, - `code` varchar(50) DEFAULT NULL, - `name` varchar(255) DEFAULT NULL, - `id_permission_group` int NOT NULL, - `id_access_level_required` int NOT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `display_order` int NOT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_permission`), - KEY `FK_Shop_Permission_id_permission_group` (`id_permission_group`), - KEY `FK_Shop_Permission_id_access_level_required` (`id_access_level_required`), - KEY `FK_Shop_Permission_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Permission_id_access_level_required` FOREIGN KEY (`id_access_level_required`) REFERENCES `shop_access_level` (`id_access_level`), - CONSTRAINT `FK_Shop_Permission_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_user_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Permission_id_permission_group` FOREIGN KEY (`id_permission_group`) REFERENCES `shop_permission_group` (`id_group`) ON UPDATE RESTRICT -) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_permission` --- - -LOCK TABLES `shop_permission` WRITE; -/*!40000 ALTER TABLE `shop_permission` DISABLE KEYS */; -INSERT INTO `shop_permission` VALUES (1,'HOME','Home Page',2,1,_binary '',1,'2024-04-28 19:03:07','root@localhost',NULL),(2,'STORE_PRODUCT','Store Product Page',3,1,_binary '',2,'2024-04-28 19:03:07','root@localhost',NULL),(3,'STORE_USER','Store User Account Page',4,2,_binary '',3,'2024-04-28 19:03:07','root@localhost',NULL),(4,'STORE_ADMIN','Store Admin Page',1,3,_binary '',4,'2024-04-28 19:03:07','root@localhost',NULL),(5,'CONTACT_US','Contact Us Page',2,1,_binary '',99,'2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_permission` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Permission` BEFORE INSERT ON `shop_permission` FOR EACH ROW BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Permission` BEFORE UPDATE ON `shop_permission` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Permission_Audit ( - id_permission, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_permission, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_permission, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed id_permission_group - SELECT NEW.id_permission, 'id_permission_group', CONVERT(OLD.id_permission_group, CHAR), CONVERT(NEW.id_permission_group, CHAR), NEW.id_change_set - WHERE NOT OLD.id_permission_group <=> NEW.id_permission_group - UNION - -- Changed Id_access_level_required - SELECT NEW.id_permission, 'Id_access_level_required', CONVERT(OLD.Id_access_level_required, CHAR), CONVERT(NEW.Id_access_level_required, CHAR), NEW.id_change_set - WHERE NOT OLD.Id_access_level_required <=> NEW.Id_access_level_required - UNION - -- Changed active - SELECT NEW.id_permission, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_permission, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_permission_audit` --- - -DROP TABLE IF EXISTS `shop_permission_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_permission_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_permission` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Permission_Audit_id_permission` (`id_permission`), - KEY `FK_Shop_Permission_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Permission_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_user_change_set` (`id_change_set`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Permission_Audit_id_permission` FOREIGN KEY (`id_permission`) REFERENCES `shop_permission` (`id_permission`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_permission_audit` --- - -LOCK TABLES `shop_permission_audit` WRITE; -/*!40000 ALTER TABLE `shop_permission_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_permission_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_permission_group` --- - -DROP TABLE IF EXISTS `shop_permission_group`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_permission_group` ( - `id_group` int NOT NULL AUTO_INCREMENT, - `code` varchar(50) DEFAULT NULL, - `name` varchar(255) DEFAULT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `display_order` int NOT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_group`), - KEY `FK_Shop_Permission_Group_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Permission_Group_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_user_change_set` (`id_change_set`) ON UPDATE RESTRICT -) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_permission_group` --- - -LOCK TABLES `shop_permission_group` WRITE; -/*!40000 ALTER TABLE `shop_permission_group` DISABLE KEYS */; -INSERT INTO `shop_permission_group` VALUES (1,'ADMIN','Website Admin',_binary '',0,'2024-04-28 19:03:07','root@localhost',NULL),(2,'HOME','Home, Contact Us, and other public information',_binary '',1,'2024-04-28 19:03:07','root@localhost',NULL),(3,'PRODUCT','Store Products',_binary '',2,'2024-04-28 19:03:07','root@localhost',NULL),(4,'USER','Store User',_binary '',3,'2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_permission_group` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Permission_Group` BEFORE INSERT ON `shop_permission_group` FOR EACH ROW BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Permission_Group` BEFORE UPDATE ON `shop_permission_group` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Permission_Group_Audit ( - id_group, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_group, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_group, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed active - SELECT NEW.id_group, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_group, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_permission_group_audit` --- - -DROP TABLE IF EXISTS `shop_permission_group_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_permission_group_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_group` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Permission_Group_Audit_id_group` (`id_group`), - KEY `FK_Shop_Permission_Group_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Permission_Group_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_user_change_set` (`id_change_set`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Permission_Group_Audit_id_group` FOREIGN KEY (`id_group`) REFERENCES `shop_permission_group` (`id_group`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_permission_group_audit` --- - -LOCK TABLES `shop_permission_group_audit` WRITE; -/*!40000 ALTER TABLE `shop_permission_group_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_permission_group_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_product` --- - -DROP TABLE IF EXISTS `shop_product`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_product` ( - `id_product` int NOT NULL AUTO_INCREMENT, - `name` varchar(255) NOT NULL, - `id_category` int NOT NULL, - `has_variations` bit(1) NOT NULL, - `id_access_level_required` int NOT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `display_order` int NOT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_product`), - KEY `FK_Shop_Product_id_access_level_required` (`id_access_level_required`), - KEY `FK_Shop_Product_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_id_access_level_required` FOREIGN KEY (`id_access_level_required`) REFERENCES `shop_access_level` (`id_access_level`), - CONSTRAINT `FK_Shop_Product_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`) -) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_product` --- - -LOCK TABLES `shop_product` WRITE; -/*!40000 ALTER TABLE `shop_product` DISABLE KEYS */; -INSERT INTO `shop_product` VALUES (1,'Braille Keyboard Translator',1,_binary '',3,_binary '',1,'2024-04-28 19:03:07','root@localhost',NULL),(2,'Test product 1',2,_binary '\0',3,_binary '',2,'2024-04-28 19:03:07','root@localhost',NULL),(3,'Phone',3,_binary '\0',1,_binary '',3,'2024-04-28 19:03:07','root@localhost',NULL),(4,'Laptop',3,_binary '\0',1,_binary '',4,'2024-04-28 19:03:07','root@localhost',NULL),(5,'Smart Watch',3,_binary '\0',1,_binary '',5,'2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_product` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Product` BEFORE INSERT ON `shop_product` FOR EACH ROW BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Product` BEFORE UPDATE ON `shop_product` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - /* - IF NOT NEW.has_variations THEN - IF ISNULL(NEW.price_GBP_full) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have price or variations (with prices).'; - END IF; - IF ISNULL(NEW.price_GBP_min) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have minimum price or variations (with prices).'; - END IF; - IF ISNULL(NEW.latency_manuf) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have manufacturing latency or variations (with manufacturing latencies).'; - END IF; - IF ISNULL(NEW.quantity_min) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have minimum quantity or variations (with minimum quantities).'; - END IF; - IF ISNULL(NEW.quantity_max) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have maximum quantity or variations (with maximum quantities).'; - END IF; - IF ISNULL(NEW.quantity_step) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have increment of quantity or variations (with increments of quantities).'; - END IF; - IF ISNULL(NEW.quantity_stock) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have stock quantity or variations (with stock quantities).'; - END IF; - IF ISNULL(NEW.is_subscription) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have subscription status or variations (with subscription statuses).'; - END IF; - IF ISNULL(NEW.id_unit_measurement_interval_recurrence) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have recurrence interval or variations (with recurrence intervals).'; - END IF; - IF ISNULL(NEW.count_interval_recurrence) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have recurrence interval count or variations (with recurrence interval counts).'; - END IF; - END IF; - */ - - INSERT INTO Shop_Product_Audit ( - id_product, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed name - SELECT NEW.id_product, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - /* - UNION - -- Changed description - SELECT NEW.id_product, 'description', OLD.description, NEW.description, NEW.id_change_set - WHERE NOT OLD.description <=> NEW.description - UNION - -- Changed price_GBP_full - SELECT NEW.id_product, 'price_GBP_full', CONVERT(OLD.price_GBP_full, CHAR), CONVERT(NEW.price_GBP_full, CHAR), NEW.id_change_set - WHERE NOT OLD.price_GBP_full <=> NEW.price_GBP_full - UNION - -- Changed price_GBP_min - SELECT NEW.id_product, 'price_GBP_min', CONVERT(OLD.price_GBP_min, CHAR), CONVERT(NEW.price_GBP_min, CHAR), NEW.id_change_set - WHERE NOT OLD.price_GBP_min <=> NEW.price_GBP_min - UNION - -- Changed has_variations - SELECT NEW.id_product, 'has_variations', CONVERT(CONVERT(NEW.has_variations, SIGNED), CHAR), CONVERT(CONVERT(NEW.has_variations, SIGNED), CHAR), NEW.id_change_set - WHERE NOT OLD.has_variations <=> NEW.has_variations - UNION - /* - -- Changed discount - SELECT NEW.id_product, 'discount', CONVERT(OLD.discount, CHAR), CONVERT(NEW.discount, CHAR), NEW.id_change_set - WHERE NOT OLD.discount <=> NEW.discount - */ - UNION - -- Changed id_category - SELECT NEW.id_product, 'id_category', CONVERT(OLD.id_category, CHAR), CONVERT(NEW.id_category, CHAR), NEW.id_change_set - WHERE NOT OLD.id_category <=> NEW.id_category - /* - UNION - -- Changed latency_manuf - SELECT NEW.id_product, 'latency_manuf', CONVERT(OLD.latency_manuf, CHAR), CONVERT(NEW.latency_manuf, CHAR), NEW.id_change_set - WHERE NOT OLD.latency_manuf <=> NEW.latency_manuf - UNION - -- Changed quantity_min - SELECT NEW.id_product, 'quantity_min', CONVERT(OLD.quantity_min, CHAR), CONVERT(NEW.quantity_min, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_min <=> NEW.quantity_min - UNION - -- Changed quantity_max - SELECT NEW.id_product, 'quantity_max', CONVERT(OLD.quantity_max, CHAR), CONVERT(NEW.quantity_max, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - UNION - -- Changed quantity_step - SELECT NEW.id_product, 'quantity_step', CONVERT(OLD.quantity_step, CHAR), CONVERT(NEW.quantity_step, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_step <=> NEW.quantity_step - UNION - -- Changed quantity_stock - SELECT NEW.id_product, 'quantity_stock', CONVERT(OLD.quantity_stock, CHAR), CONVERT(NEW.quantity_stock, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_stock <=> NEW.quantity_stock - UNION - -- Changed is_subscription - SELECT NEW.id_product, 'is_subscription', CONVERT(CONVERT(OLD.is_subscription, SIGNED), CHAR), CONVERT(CONVERT(NEW.is_subscription, SIGNED), CHAR), NEW.id_change_set - WHERE NOT OLD.is_subscription <=> NEW.is_subscription - UNION - -- Changed id_unit_measurement_interval_recurrence - SELECT NEW.id_product, 'id_unit_measurement_interval_recurrence', CONVERT(OLD.id_unit_measurement_interval_recurrence, CHAR), CONVERT(NEW.id_unit_measurement_interval_recurrence, CHAR), NEW.id_change_set - WHERE NOT OLD.id_unit_measurement_interval_recurrence <=> NEW.id_unit_measurement_interval_recurrence - UNION - -- Changed count_interval_recurrence - SELECT NEW.id_product, 'count_interval_recurrence', CONVERT(OLD.count_interval_recurrence, CHAR), CONVERT(NEW.count_interval_recurrence, CHAR), NEW.id_change_set - WHERE NOT OLD.count_interval_recurrence <=> NEW.count_interval_recurrence - UNION - -- Changed id_access_level_required - SELECT NEW.id_product, 'id_access_level_required', CONVERT(OLD.id_access_level_required, CHAR), CONVERT(NEW.id_access_level_required, CHAR), NEW.id_change_set - WHERE NOT OLD.id_access_level_required <=> NEW.id_access_level_required - UNION - -- Changed id_stripe_product - SELECT NEW.id_product, 'id_stripe_product', OLD.id_stripe_product, NEW.id_stripe_product, NEW.id_change_set - WHERE NOT OLD.id_stripe_product <=> NEW.id_stripe_product - /* - UNION - -- Changed id_stripe_price - SELECT NEW.id_product, 'id_stripe_price', OLD.id_stripe_price, NEW.id_stripe_price, NEW.id_change_set - WHERE NOT OLD.id_stripe_price <=> NEW.id_stripe_price - */ - UNION - -- Changed active - SELECT NEW.id_product, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_product, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_product_audit` --- - -DROP TABLE IF EXISTS `shop_product_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_product_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_product` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Product_Audit_id_product` (`id_product`), - KEY `FK_Shop_Product_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Audit_id_product` FOREIGN KEY (`id_product`) REFERENCES `shop_product` (`id_product`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_product_audit` --- - -LOCK TABLES `shop_product_audit` WRITE; -/*!40000 ALTER TABLE `shop_product_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_product_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_product_change_set` --- - -DROP TABLE IF EXISTS `shop_product_change_set`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_product_change_set` ( - `id_change_set` int NOT NULL AUTO_INCREMENT, - `comment` varchar(500) DEFAULT NULL, - `updated_last_on` datetime DEFAULT NULL, - `updated_last_by` varchar(100) DEFAULT NULL, - PRIMARY KEY (`id_change_set`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_product_change_set` --- - -LOCK TABLES `shop_product_change_set` WRITE; -/*!40000 ALTER TABLE `shop_product_change_set` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_product_change_set` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Product_Change_Set` BEFORE INSERT ON `shop_product_change_set` FOR EACH ROW BEGIN - IF NEW.updated_last_on <=> NULL THEN - SET NEW.updated_last_on = NOW(); - END IF; - IF NEW.updated_last_by <=> NULL THEN - SET NEW.updated_last_by = CURRENT_USER(); - END IF; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_product_currency_link` --- - -DROP TABLE IF EXISTS `shop_product_currency_link`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_product_currency_link` ( - `id_link` int NOT NULL AUTO_INCREMENT, - `id_product` int NOT NULL, - `id_permutation` int DEFAULT NULL, - `id_currency` int NOT NULL, - `id_region_purchase` int NOT NULL, - `price_local_VAT_incl` float DEFAULT NULL, - `price_local_VAT_excl` float DEFAULT NULL, - `id_stripe_price` varchar(200) DEFAULT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_link`), - KEY `FK_Shop_Product_Currency_Link_id_product` (`id_product`), - KEY `FK_Shop_Product_Currency_Link_id_permutation` (`id_permutation`), - KEY `FK_Shop_Product_Currency_Link_id_currency` (`id_currency`), - KEY `FK_Shop_Product_Currency_Link_id_region_purchase` (`id_region_purchase`), - KEY `FK_Shop_Product_Currency_Link_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Currency_Link_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Currency_Link_id_currency` FOREIGN KEY (`id_currency`) REFERENCES `shop_currency` (`id_currency`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Product_Currency_Link_id_permutation` FOREIGN KEY (`id_permutation`) REFERENCES `shop_product_permutation` (`id_permutation`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Product_Currency_Link_id_product` FOREIGN KEY (`id_product`) REFERENCES `shop_product` (`id_product`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Product_Currency_Link_id_region_purchase` FOREIGN KEY (`id_region_purchase`) REFERENCES `shop_region` (`id_region`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_product_currency_link` --- - -LOCK TABLES `shop_product_currency_link` WRITE; -/*!40000 ALTER TABLE `shop_product_currency_link` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_product_currency_link` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Product_Currency_Link` BEFORE INSERT ON `shop_product_currency_link` FOR EACH ROW BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; - /* - SET NEW.price_local = ( - SELECT PP.price_GBP_full * C.factor_from_GBP - FROM Shop_Product_Permutation PP - INNER JOIN Shop_Product P ON PP.id_product = P.id_product - INNER JOIN Shop_Currency C ON NEW.id_currency = C.id_currency - WHERE NEW.id_product = P.id_product - LIMIT 1 - ); - */ -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Product_Currency_Link` BEFORE UPDATE ON `shop_product_currency_link` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - /* - SET NEW.price_local = ( - SELECT P.price_GBP_full * C.factor_from_GBP - FROM Shop_Product P - INNER JOIN Shop_Currency C ON NEW.id_currency = C.id_currency - WHERE NEW.id_product = P.id_product - LIMIT 1 - ); - */ - - INSERT INTO Shop_Product_Currency_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_product - SELECT NEW.id_link, 'id_product', CONVERT(OLD.id_product, CHAR), CONVERT(NEW.id_product, CHAR), NEW.id_change_set - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed id_currency - SELECT NEW.id_link, 'id_currency', CONVERT(OLD.id_currency, CHAR), CONVERT(NEW.id_currency, CHAR), NEW.id_change_set - WHERE NOT OLD.id_currency <=> NEW.id_currency - UNION - -- Changed price_local - SELECT NEW.id_link, 'price_local', OLD.price_local, NEW.price_local, NEW.id_change_set - WHERE NOT OLD.price_local <=> NEW.price_local - UNION - */ - -- Changed price_local_VAT_incl - SELECT NEW.id_link, 'price_local_VAT_incl', OLD.price_local_VAT_incl, NEW.price_local_VAT_incl, NEW.id_change_set - WHERE NOT OLD.price_local_VAT_incl <=> NEW.price_local_VAT_incl - UNION - -- Changed price_local_VAT_excl - SELECT NEW.id_link, 'price_local_VAT_excl', OLD.price_local_VAT_excl, NEW.price_local_VAT_excl, NEW.id_change_set - WHERE NOT OLD.price_local_VAT_excl <=> NEW.price_local_VAT_excl - UNION - -- Changed id_stripe_price - SELECT NEW.id_link, 'id_stripe_price', OLD.id_stripe_price, NEW.id_stripe_price, NEW.id_change_set - WHERE NOT OLD.id_stripe_price <=> NEW.id_stripe_price - UNION - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_product_currency_link_audit` --- - -DROP TABLE IF EXISTS `shop_product_currency_link_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_product_currency_link_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_link` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Product_Currency_Link_Audit_id_link` (`id_link`), - KEY `FK_Shop_Product_Currency_Link_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Currency_Link_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Currency_Link_Audit_id_link` FOREIGN KEY (`id_link`) REFERENCES `shop_product_currency_link` (`id_link`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_product_currency_link_audit` --- - -LOCK TABLES `shop_product_currency_link_audit` WRITE; -/*!40000 ALTER TABLE `shop_product_currency_link_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_product_currency_link_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_product_currency_region_link` --- - -DROP TABLE IF EXISTS `shop_product_currency_region_link`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_product_currency_region_link` ( - `id_link` int NOT NULL AUTO_INCREMENT, - `id_product` int NOT NULL, - `id_permutation` int DEFAULT NULL, - `id_currency` int NOT NULL, - `id_region_purchase` int NOT NULL, - `price_local_VAT_incl` float DEFAULT NULL, - `price_local_VAT_excl` float DEFAULT NULL, - `id_stripe_price` varchar(200) DEFAULT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_link`), - KEY `FK_Shop_Product_Currency_Region_Link_id_product` (`id_product`), - KEY `FK_Shop_Product_Currency_Region_Link_id_permutation` (`id_permutation`), - KEY `FK_Shop_Product_Currency_Region_Link_id_currency` (`id_currency`), - KEY `FK_Shop_Product_Currency_Region_Link_id_region_purchase` (`id_region_purchase`), - KEY `FK_Shop_Product_Currency_Region_Link_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Currency_Region_Link_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Currency_Region_Link_id_currency` FOREIGN KEY (`id_currency`) REFERENCES `shop_currency` (`id_currency`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Product_Currency_Region_Link_id_permutation` FOREIGN KEY (`id_permutation`) REFERENCES `shop_product_permutation` (`id_permutation`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Product_Currency_Region_Link_id_product` FOREIGN KEY (`id_product`) REFERENCES `shop_product` (`id_product`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Product_Currency_Region_Link_id_region_purchase` FOREIGN KEY (`id_region_purchase`) REFERENCES `shop_region` (`id_region`) ON UPDATE RESTRICT -) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_product_currency_region_link` --- - -LOCK TABLES `shop_product_currency_region_link` WRITE; -/*!40000 ALTER TABLE `shop_product_currency_region_link` DISABLE KEYS */; -INSERT INTO `shop_product_currency_region_link` VALUES (1,1,1,1,1,24,20,NULL,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(2,1,1,2,1,48,40,NULL,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(3,1,2,1,1,96,80,NULL,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(4,2,3,1,1,144,120,NULL,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(5,3,4,1,1,600,500,NULL,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(6,4,5,1,1,1500,1200,NULL,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(7,5,6,1,1,180,150,NULL,_binary '','2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_product_currency_region_link` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Product_Currency_Region_Link` BEFORE INSERT ON `shop_product_currency_region_link` FOR EACH ROW BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; - /* - SET NEW.price_local = ( - SELECT PP.price_GBP_full * C.factor_from_GBP - FROM Shop_Product_Permutation PP - INNER JOIN Shop_Product P ON PP.id_product = P.id_product - INNER JOIN Shop_Currency C ON NEW.id_currency = C.id_currency - WHERE NEW.id_product = P.id_product - LIMIT 1 - ); - */ -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Product_Currency_Region_Link` BEFORE UPDATE ON `shop_product_currency_region_link` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - /* - SET NEW.price_local = ( - SELECT P.price_GBP_full * C.factor_from_GBP - FROM Shop_Product P - INNER JOIN Shop_Currency C ON NEW.id_currency = C.id_currency - WHERE NEW.id_product = P.id_product - LIMIT 1 - ); - */ - - INSERT INTO Shop_Product_Currency_Region_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_product - SELECT NEW.id_link, 'id_product', CONVERT(OLD.id_product, CHAR), CONVERT(NEW.id_product, CHAR), NEW.id_change_set - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed id_currency - SELECT NEW.id_link, 'id_currency', CONVERT(OLD.id_currency, CHAR), CONVERT(NEW.id_currency, CHAR), NEW.id_change_set - WHERE NOT OLD.id_currency <=> NEW.id_currency - UNION - -- Changed price_local - SELECT NEW.id_link, 'price_local', OLD.price_local, NEW.price_local, NEW.id_change_set - WHERE NOT OLD.price_local <=> NEW.price_local - UNION - */ - -- Changed price_local_VAT_incl - SELECT NEW.id_link, 'price_local_VAT_incl', OLD.price_local_VAT_incl, NEW.price_local_VAT_incl, NEW.id_change_set - WHERE NOT OLD.price_local_VAT_incl <=> NEW.price_local_VAT_incl - UNION - -- Changed price_local_VAT_excl - SELECT NEW.id_link, 'price_local_VAT_excl', OLD.price_local_VAT_excl, NEW.price_local_VAT_excl, NEW.id_change_set - WHERE NOT OLD.price_local_VAT_excl <=> NEW.price_local_VAT_excl - UNION - -- Changed id_stripe_price - SELECT NEW.id_link, 'id_stripe_price', OLD.id_stripe_price, NEW.id_stripe_price, NEW.id_change_set - WHERE NOT OLD.id_stripe_price <=> NEW.id_stripe_price - UNION - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_product_currency_region_link_audit` --- - -DROP TABLE IF EXISTS `shop_product_currency_region_link_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_product_currency_region_link_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_link` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Product_Currency_Region_Link_Audit_id_link` (`id_link`), - KEY `FK_Shop_Product_Currency_Region_Link_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Currency_Region_Link_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Currency_Region_Link_Audit_id_link` FOREIGN KEY (`id_link`) REFERENCES `shop_product_currency_region_link` (`id_link`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_product_currency_region_link_audit` --- - -LOCK TABLES `shop_product_currency_region_link_audit` WRITE; -/*!40000 ALTER TABLE `shop_product_currency_region_link_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_product_currency_region_link_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_product_delivery_option_link` --- - -DROP TABLE IF EXISTS `shop_product_delivery_option_link`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_product_delivery_option_link` ( - `id_link` int NOT NULL AUTO_INCREMENT, - `id_product` int NOT NULL, - `id_permutation` int DEFAULT NULL, - `id_delivery_option` int NOT NULL, - `id_region` int NOT NULL, - `id_currency` int NOT NULL, - `price_local` float NOT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `display_order` int NOT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_link`), - KEY `FK_Shop_Product_Delivery_Option_Link_id_product` (`id_product`), - KEY `FK_Shop_Product_Delivery_Option_Link_id_permutation` (`id_permutation`), - KEY `FK_Shop_Product_Delivery_Option_Link_id_delivery_option` (`id_delivery_option`), - KEY `FK_Shop_Product_Delivery_Option_Link_id_region` (`id_region`), - KEY `FK_Shop_Product_Delivery_Option_Link_id_currency` (`id_currency`), - KEY `FK_Shop_Product_Delivery_Option_Link_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Delivery_Option_Link_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Delivery_Option_Link_id_currency` FOREIGN KEY (`id_currency`) REFERENCES `shop_currency` (`id_currency`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Product_Delivery_Option_Link_id_delivery_option` FOREIGN KEY (`id_delivery_option`) REFERENCES `shop_delivery_option` (`id_option`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Product_Delivery_Option_Link_id_permutation` FOREIGN KEY (`id_permutation`) REFERENCES `shop_product_permutation` (`id_permutation`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Product_Delivery_Option_Link_id_product` FOREIGN KEY (`id_product`) REFERENCES `shop_product` (`id_product`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Product_Delivery_Option_Link_id_region` FOREIGN KEY (`id_region`) REFERENCES `shop_region` (`id_region`) ON UPDATE RESTRICT -) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_product_delivery_option_link` --- - -LOCK TABLES `shop_product_delivery_option_link` WRITE; -/*!40000 ALTER TABLE `shop_product_delivery_option_link` DISABLE KEYS */; -INSERT INTO `shop_product_delivery_option_link` VALUES (1,1,1,1,1,1,5,_binary '',1,'2024-04-28 19:03:07','root@localhost',NULL),(2,1,2,1,1,1,9,_binary '',2,'2024-04-28 19:03:07','root@localhost',NULL),(3,2,NULL,1,1,1,10,_binary '',3,'2024-04-28 19:03:07','root@localhost',NULL),(4,3,4,1,1,1,10,_binary '',4,'2024-04-28 19:03:07','root@localhost',NULL),(5,4,5,1,1,1,10,_binary '',5,'2024-04-28 19:03:07','root@localhost',NULL),(6,5,6,1,1,1,10,_binary '',6,'2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_product_delivery_option_link` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Product_Delivery_Option_Link` BEFORE INSERT ON `shop_product_delivery_option_link` FOR EACH ROW BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Product_Delivery_Option_Link` BEFORE UPDATE ON `shop_product_delivery_option_link` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Product_Delivery_Option_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_product - SELECT NEW.id_link, 'id_product', CONVERT(OLD.id_product, CHAR), CONVERT(NEW.id_product, CHAR), NEW.id_change_set - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed id_permutation - SELECT NEW.id_link, 'id_permutation', CONVERT(OLD.id_permutation, CHAR), CONVERT(NEW.id_permutation, CHAR), NEW.id_change_set - WHERE NOT OLD.id_permutation <=> NEW.id_permutation - UNION - -- Changed id_option - SELECT NEW.id_link, 'id_option', CONVERT(OLD.id_option, CHAR), CONVERT(NEW.id_option, CHAR), NEW.id_change_set - WHERE NOT OLD.id_option <=> NEW.id_option - UNION - -- Changed id_region - SELECT NEW.id_link, 'id_region', CONVERT(OLD.id_region, CHAR), CONVERT(NEW.id_region, CHAR), NEW.id_change_set - WHERE NOT OLD.id_region <=> NEW.id_region - UNION - */ - -- Changed price_local - SELECT NEW.id_link, 'price_local', CONVERT(OLD.price_local, CHAR), CONVERT(NEW.price_local, CHAR), NEW.id_change_set - WHERE NOT OLD.price_local <=> NEW.price_local - UNION - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_link, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_product_delivery_option_link_audit` --- - -DROP TABLE IF EXISTS `shop_product_delivery_option_link_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_product_delivery_option_link_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_link` int NOT NULL, - `name_field` varchar(64) NOT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Product_Delivery_Option_Link_Audit_id_link` (`id_link`), - KEY `FK_Shop_Product_Delivery_Option_Link_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Delivery_Option_Link_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Delivery_Option_Link_Audit_id_link` FOREIGN KEY (`id_link`) REFERENCES `shop_product_delivery_option_link` (`id_link`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_product_delivery_option_link_audit` --- - -LOCK TABLES `shop_product_delivery_option_link_audit` WRITE; -/*!40000 ALTER TABLE `shop_product_delivery_option_link_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_product_delivery_option_link_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_product_permutation` --- - -DROP TABLE IF EXISTS `shop_product_permutation`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_product_permutation` ( - `id_permutation` int NOT NULL AUTO_INCREMENT, - `id_product` int NOT NULL, - `description` varchar(4000) NOT NULL, - `cost_local_manufacturing` float NOT NULL, - `id_currency_cost_manufacturing` int NOT NULL, - `profit_local_min` float NOT NULL, - `id_currency_profit_min` int NOT NULL, - `latency_manufacture` int NOT NULL, - `quantity_min` float NOT NULL, - `quantity_max` float NOT NULL, - `quantity_step` float NOT NULL, - `quantity_stock` float NOT NULL, - `is_subscription` bit(1) NOT NULL, - `id_unit_measurement_interval_recurrence` int DEFAULT NULL, - `count_interval_recurrence` int DEFAULT NULL, - `id_access_level_required` int NOT NULL, - `id_stripe_product` varchar(100) DEFAULT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `display_order` int NOT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_permutation`), - KEY `FK_Shop_Product_Variation_Link_id_product` (`id_product`), - KEY `FK_Shop_Product_Permutation_id_unit_measurement_interval_recurrence` (`id_unit_measurement_interval_recurrence`), - KEY `FK_Shop_Product_Permutation_id_access_level_required` (`id_access_level_required`), - KEY `FK_Shop_Product_Variation_Link_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Permutation_id_access_level_required` FOREIGN KEY (`id_access_level_required`) REFERENCES `shop_access_level` (`id_access_level`), - CONSTRAINT `FK_Shop_Product_Permutation_id_unit_measurement_interval_recurrence` FOREIGN KEY (`id_unit_measurement_interval_recurrence`) REFERENCES `shop_interval_recurrence` (`id_interval`), - CONSTRAINT `FK_Shop_Product_Variation_Link_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Variation_Link_id_product` FOREIGN KEY (`id_product`) REFERENCES `shop_product` (`id_product`) ON UPDATE RESTRICT -) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_product_permutation` --- - -LOCK TABLES `shop_product_permutation` WRITE; -/*!40000 ALTER TABLE `shop_product_permutation` DISABLE KEYS */; -INSERT INTO `shop_product_permutation` VALUES (1,1,'Good Red',5,1,3,1,14,1,3,1,99,_binary '\0',NULL,NULL,1,NULL,_binary '',1,'2024-04-28 19:03:07','root@localhost',NULL),(2,1,'Good Blue',6,1,4,1,14,1,3,1,99,_binary '\0',NULL,NULL,1,NULL,_binary '',2,'2024-04-28 19:03:07','root@localhost',NULL),(3,2,'Test product describes good',10,1,5,1,14,1,2,1,99,_binary '\0',NULL,NULL,1,NULL,_binary '',3,'2024-04-28 19:03:07','root@localhost',NULL),(4,3,'Phone describes good',10,1,5,1,14,1,2,1,99,_binary '\0',NULL,NULL,1,NULL,_binary '',4,'2024-04-28 19:03:07','root@localhost',NULL),(5,4,'Laptop describes good',10,1,5,1,14,1,2,1,99,_binary '\0',NULL,NULL,1,NULL,_binary '',5,'2024-04-28 19:03:07','root@localhost',NULL),(6,5,'Smart watch describes good',10,1,5,1,14,1,2,1,99,_binary '\0',NULL,NULL,1,NULL,_binary '',6,'2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_product_permutation` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Product_Permutation` BEFORE INSERT ON `shop_product_permutation` FOR EACH ROW BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Product_Permutation` BEFORE UPDATE ON `shop_product_permutation` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Product_Permutation_Audit ( - id_permutation, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_product - SELECT NEW.id_permutation, 'id_product', OLD.id_product, NEW.id_product, NEW.id_change_set - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed id_variation - SELECT NEW.id_permutation, 'id_variation', OLD.id_variation, NEW.id_variation, NEW.id_change_set - WHERE NOT OLD.id_variation <=> NEW.id_variation - UNION - -- Changed name - SELECT NEW.id_permutation, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT (OLD.name <=> NEW.name) - UNION - */ - -- Changed description - SELECT NEW.id_permutation, 'description', OLD.description, NEW.description, NEW.id_change_set - WHERE NOT (OLD.description <=> NEW.description) - UNION - -- Changed cost_local_manufacturing - SELECT NEW.id_permutation, 'cost_local_manufacturing', CONVERT(OLD.cost_local_manufacturing, CHAR), CONVERT(NEW.cost_local_manufacturing, CHAR), NEW.id_change_set - WHERE NOT (OLD.cost_local_manufacturing <=> NEW.cost_local_manufacturing) - UNION - -- Changed id_currency_cost_manufacturing - SELECT NEW.id_permutation, 'id_currency_cost_manufacturing', CONVERT(OLD.id_currency_cost_manufacturing, CHAR), CONVERT(NEW.id_currency_cost_manufacturing, CHAR), NEW.id_change_set - WHERE NOT (OLD.id_currency_cost_manufacturing <=> NEW.id_currency_cost_manufacturing) - UNION - -- Changed profit_local_min - SELECT NEW.id_permutation, 'profit_local_min', CONVERT(OLD.profit_local_min, CHAR), CONVERT(NEW.profit_local_min, CHAR), NEW.id_change_set - WHERE NOT (OLD.profit_local_min <=> NEW.profit_local_min) - UNION - -- Changed id_currency_profit_min - SELECT NEW.id_permutation, 'id_currency_profit_min', CONVERT(OLD.id_currency_profit_min, CHAR), CONVERT(NEW.id_currency_profit_min, CHAR), NEW.id_change_set - WHERE NOT (OLD.id_currency_profit_min <=> NEW.id_currency_profit_min) - UNION - /* - -- Changed price_GBP_min - SELECT NEW.id_permutation, 'price_GBP_min', CONVERT(OLD.price_GBP_min, CHAR), CONVERT(NEW.price_GBP_min, CHAR), NEW.id_change_set - WHERE NOT (OLD.price_GBP_min <=> NEW.price_GBP_min) - UNION - */ - -- Changed latency_manufacture - SELECT NEW.id_product, 'latency_manufacture', CONVERT(OLD.latency_manufacture, CHAR), CONVERT(NEW.latency_manufacture, CHAR), NEW.id_change_set - WHERE NOT OLD.latency_manufacture <=> NEW.latency_manufacture - UNION - -- Changed quantity_min - SELECT NEW.id_product, 'quantity_min', CONVERT(OLD.quantity_min, CHAR), CONVERT(NEW.quantity_min, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_min <=> NEW.quantity_min - UNION - -- Changed quantity_max - SELECT NEW.id_product, 'quantity_max', CONVERT(OLD.quantity_max, CHAR), CONVERT(NEW.quantity_max, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - UNION - -- Changed quantity_step - SELECT NEW.id_product, 'quantity_step', CONVERT(OLD.quantity_step, CHAR), CONVERT(NEW.quantity_step, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_step <=> NEW.quantity_step - UNION - -- Changed quantity_stock - SELECT NEW.id_product, 'quantity_stock', CONVERT(OLD.quantity_stock, CHAR), CONVERT(NEW.quantity_stock, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_stock <=> NEW.quantity_stock - UNION - -- Changed is_subscription - SELECT NEW.id_product, 'is_subscription', CONVERT(CONVERT(OLD.is_subscription, SIGNED), CHAR), CONVERT(CONVERT(NEW.is_subscription, SIGNED), CHAR), NEW.id_change_set - WHERE NOT OLD.is_subscription <=> NEW.is_subscription - UNION - -- Changed id_unit_measurement_interval_recurrence - SELECT NEW.id_product, 'id_unit_measurement_interval_recurrence', CONVERT(OLD.id_unit_measurement_interval_recurrence, CHAR), CONVERT(NEW.id_unit_measurement_interval_recurrence, CHAR), NEW.id_change_set - WHERE NOT OLD.id_unit_measurement_interval_recurrence <=> NEW.id_unit_measurement_interval_recurrence - UNION - -- Changed count_interval_recurrence - SELECT NEW.id_product, 'count_interval_recurrence', CONVERT(OLD.count_interval_recurrence, CHAR), CONVERT(NEW.count_interval_recurrence, CHAR), NEW.id_change_set - WHERE NOT OLD.count_interval_recurrence <=> NEW.count_interval_recurrence - UNION - -- Changed id_stripe_product - SELECT NEW.id_permutation, 'id_stripe_product', OLD.id_stripe_product, NEW.id_stripe_product, NEW.id_change_set - WHERE NOT (OLD.id_stripe_product <=> NEW.id_stripe_product) - UNION - -- Changed active - SELECT NEW.id_permutation, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_permutation, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_product_permutation_audit` --- - -DROP TABLE IF EXISTS `shop_product_permutation_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_product_permutation_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_permutation` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Product_Permutation_Audit_id_permutation` (`id_permutation`), - KEY `FK_Shop_Product_Permutation_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Permutation_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Product_Permutation_Audit_id_permutation` FOREIGN KEY (`id_permutation`) REFERENCES `shop_product_permutation` (`id_permutation`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_product_permutation_audit` --- - -LOCK TABLES `shop_product_permutation_audit` WRITE; -/*!40000 ALTER TABLE `shop_product_permutation_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_product_permutation_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_product_permutation_variation_link` --- - -DROP TABLE IF EXISTS `shop_product_permutation_variation_link`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_product_permutation_variation_link` ( - `id_link` int NOT NULL AUTO_INCREMENT, - `id_permutation` int NOT NULL, - `id_variation` int NOT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `display_order` int NOT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_link`), - KEY `FK_Shop_Product_Permutation_Variation_Link_id_permutation` (`id_permutation`), - KEY `FK_Shop_Product_Permutation_Variation_Link_id_variation` (`id_variation`), - KEY `FK_Shop_Product_Permutation_Variation_Link_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Permutation_Variation_Link_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Permutation_Variation_Link_id_permutation` FOREIGN KEY (`id_permutation`) REFERENCES `shop_product_permutation` (`id_permutation`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Product_Permutation_Variation_Link_id_variation` FOREIGN KEY (`id_variation`) REFERENCES `shop_variation` (`id_variation`) ON UPDATE RESTRICT -) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_product_permutation_variation_link` --- - -LOCK TABLES `shop_product_permutation_variation_link` WRITE; -/*!40000 ALTER TABLE `shop_product_permutation_variation_link` DISABLE KEYS */; -INSERT INTO `shop_product_permutation_variation_link` VALUES (1,1,1,_binary '',1,'2024-04-28 19:03:07','root@localhost',NULL),(2,2,2,_binary '',2,'2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_product_permutation_variation_link` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Product_Permutation_Variation_Link` BEFORE INSERT ON `shop_product_permutation_variation_link` FOR EACH ROW BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Product_Permutation_Variation_Link` BEFORE UPDATE ON `shop_product_permutation_variation_link` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Product_Permutation_Variation_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_product - SELECT NEW.id_link, 'id_product', OLD.id_product, NEW.id_product, NEW.id_change_set - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed id_variation - SELECT NEW.id_link, 'id_variation', OLD.id_variation, NEW.id_variation, NEW.id_change_set - WHERE NOT OLD.id_variation <=> NEW.id_variation - UNION - */ - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_link, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_product_permutation_variation_link_audit` --- - -DROP TABLE IF EXISTS `shop_product_permutation_variation_link_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_product_permutation_variation_link_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_link` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Product_Permutation_Variation_Link_Audit_id_link` (`id_link`), - KEY `FK_Shop_Product_Permutation_Variation_Link_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Product_Permutation_Variation_Link_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Product_Permutation_Variation_Link_Audit_id_link` FOREIGN KEY (`id_link`) REFERENCES `shop_product_permutation_variation_link` (`id_link`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_product_permutation_variation_link_audit` --- - -LOCK TABLES `shop_product_permutation_variation_link_audit` WRITE; -/*!40000 ALTER TABLE `shop_product_permutation_variation_link_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_product_permutation_variation_link_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_interval_recurrence` --- - -DROP TABLE IF EXISTS `shop_interval_recurrence`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_interval_recurrence` ( - `id_interval` int NOT NULL AUTO_INCREMENT, - `code` varchar(50) DEFAULT NULL, - `name` varchar(255) DEFAULT NULL, - `name_plural` varchar(256) DEFAULT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_interval`), - KEY `FK_Shop_Interval_Recurrence_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Interval_Recurrence_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`) -) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_interval_recurrence` --- - -LOCK TABLES `shop_interval_recurrence` WRITE; -/*!40000 ALTER TABLE `shop_interval_recurrence` DISABLE KEYS */; -INSERT INTO `shop_interval_recurrence` VALUES (1,'WEEK','Week','Weeks',_binary '','2024-04-28 19:03:07','root@localhost',NULL),(2,'MONTH','Month','Months',_binary '','2024-04-28 19:03:07','root@localhost',NULL),(3,'YEAR','Year','Years',_binary '','2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_interval_recurrence` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Interval_Recurrence` BEFORE INSERT ON `shop_interval_recurrence` FOR EACH ROW BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Interval_Recurrence` BEFORE UPDATE ON `shop_interval_recurrence` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Interval_Recurrence_Audit ( - id_interval, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_interval, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_interval, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed name_plural - SELECT NEW.id_interval, 'name_plural', OLD.name_plural, NEW.name_plural, NEW.id_change_set - WHERE NOT OLD.name_plural <=> NEW.name_plural - UNION - -- Changed name - SELECT NEW.id_interval, 'active', OLD.active, NEW.active, NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_interval_recurrence_audit` --- - -DROP TABLE IF EXISTS `shop_interval_recurrence_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_interval_recurrence_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_interval` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(256) DEFAULT NULL, - `value_new` varchar(256) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Interval_Recurrence_Audit_id_interval` (`id_interval`), - KEY `FK_Shop_Interval_Recurrence_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Interval_Recurrence_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Interval_Recurrence_Audit_id_interval` FOREIGN KEY (`id_interval`) REFERENCES `shop_interval_recurrence` (`id_interval`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_interval_recurrence_audit` --- - -LOCK TABLES `shop_interval_recurrence_audit` WRITE; -/*!40000 ALTER TABLE `shop_interval_recurrence_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_interval_recurrence_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_region` --- - -DROP TABLE IF EXISTS `shop_region`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_region` ( - `id_region` int NOT NULL AUTO_INCREMENT, - `code` varchar(50) NOT NULL, - `name` varchar(200) NOT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `display_order` int NOT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_region`), - KEY `FK_Shop_Region_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Region_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`) -) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_region` --- - -LOCK TABLES `shop_region` WRITE; -/*!40000 ALTER TABLE `shop_region` DISABLE KEYS */; -INSERT INTO `shop_region` VALUES (1,'UK','United Kingdom',_binary '',1,'2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_region` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Region` BEFORE INSERT ON `shop_region` FOR EACH ROW BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Region` BEFORE UPDATE ON `shop_region` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Region_Audit ( - id_region, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_region, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_region, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed active - SELECT NEW.id_region, 'active', CONVERT(OLD.active, CHAR), CONVERT(NEW.active, CHAR), NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - UNION - -- Changed display_order - SELECT NEW.id_region, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_region_audit` --- - -DROP TABLE IF EXISTS `shop_region_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_region_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_region` int NOT NULL, - `name_field` varchar(64) NOT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Region_Audit_id_region` (`id_region`), - KEY `FK_Shop_Region_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Region_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Region_Audit_id_region` FOREIGN KEY (`id_region`) REFERENCES `shop_region` (`id_region`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_region_audit` --- - -LOCK TABLES `shop_region_audit` WRITE; -/*!40000 ALTER TABLE `shop_region_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_region_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_region_branch` --- - -DROP TABLE IF EXISTS `shop_region_branch`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_region_branch` ( - `id_branch` int NOT NULL AUTO_INCREMENT, - `id_region_parent` int NOT NULL, - `id_region_child` int NOT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `display_order` int NOT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_branch`), - KEY `FK_Shop_Region_Branch_id_region_parent` (`id_region_parent`), - KEY `FK_Shop_Region_Branch_id_region_child` (`id_region_child`), - KEY `FK_Shop_Region_Branch_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Region_Branch_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Region_Branch_id_region_child` FOREIGN KEY (`id_region_child`) REFERENCES `shop_region` (`id_region`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Region_Branch_id_region_parent` FOREIGN KEY (`id_region_parent`) REFERENCES `shop_region` (`id_region`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_region_branch` --- - -LOCK TABLES `shop_region_branch` WRITE; -/*!40000 ALTER TABLE `shop_region_branch` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_region_branch` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Region_Branch` BEFORE INSERT ON `shop_region_branch` FOR EACH ROW BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Region_Branch` BEFORE UPDATE ON `shop_region_branch` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Region_Branch_Audit ( - id_branch, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed depth - SELECT NEW.id_branch, 'depth', CONVERT(OLD.depth, CHAR), CONVERT(NEW.depth, CHAR), NEW.id_change_set - WHERE NOT OLD.depth <=> NEW.depth - UNION - */ - -- Changed active - SELECT NEW.id_branch, 'active', CONVERT(OLD.active, CHAR), CONVERT(NEW.active, CHAR), NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - UNION - -- Changed display_order - SELECT NEW.id_branch, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_region_branch_audit` --- - -DROP TABLE IF EXISTS `shop_region_branch_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_region_branch_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_branch` int NOT NULL, - `name_field` varchar(64) NOT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Region_Branch_Audit_id_branch` (`id_branch`), - KEY `FK_Shop_Region_Branch_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Region_Branch_Audit_id_branch` FOREIGN KEY (`id_branch`) REFERENCES `shop_region_branch` (`id_branch`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Region_Branch_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_region_branch_audit` --- - -LOCK TABLES `shop_region_branch_audit` WRITE; -/*!40000 ALTER TABLE `shop_region_branch_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_region_branch_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_role` --- - -DROP TABLE IF EXISTS `shop_role`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_role` ( - `id_role` int NOT NULL AUTO_INCREMENT, - `code` varchar(50) DEFAULT NULL, - `name` varchar(255) DEFAULT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `display_order` int NOT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_role`), - KEY `FK_Shop_Role_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Role_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_user_change_set` (`id_change_set`) -) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_role` --- - -LOCK TABLES `shop_role` WRITE; -/*!40000 ALTER TABLE `shop_role` DISABLE KEYS */; -INSERT INTO `shop_role` VALUES (1,'DIRECTOR','Director',_binary '',1,'2024-04-28 19:03:07','root@localhost',NULL),(2,'USER','User',_binary '',2,'2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_role` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Role` BEFORE INSERT ON `shop_role` FOR EACH ROW BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Role` BEFORE UPDATE ON `shop_role` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Role_Audit ( - id_role, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_role, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_role, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed active - SELECT NEW.id_role, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_role, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_role_audit` --- - -DROP TABLE IF EXISTS `shop_role_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_role_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_role` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Role_Audit_id_role` (`id_role`), - KEY `FK_Shop_Role_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Role_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_user_change_set` (`id_change_set`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Role_Audit_id_role` FOREIGN KEY (`id_role`) REFERENCES `shop_role` (`id_role`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_role_audit` --- - -LOCK TABLES `shop_role_audit` WRITE; -/*!40000 ALTER TABLE `shop_role_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_role_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_role_permission_link` --- - -DROP TABLE IF EXISTS `shop_role_permission_link`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_role_permission_link` ( - `id_link` int NOT NULL AUTO_INCREMENT, - `id_role` int DEFAULT NULL, - `id_permission` int DEFAULT NULL, - `id_access_level` int DEFAULT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_link`), - KEY `FK_Shop_Role_Permission_Link_id_role` (`id_role`), - KEY `FK_Shop_Role_Permission_Link_id_permission` (`id_permission`), - KEY `FK_Shop_Role_Permission_Link_id_access_level` (`id_access_level`), - KEY `FK_Shop_Role_Permission_Link_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Role_Permission_Link_id_access_level` FOREIGN KEY (`id_access_level`) REFERENCES `shop_access_level` (`id_access_level`), - CONSTRAINT `FK_Shop_Role_Permission_Link_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_user_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Role_Permission_Link_id_permission` FOREIGN KEY (`id_permission`) REFERENCES `shop_permission` (`id_permission`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Role_Permission_Link_id_role` FOREIGN KEY (`id_role`) REFERENCES `shop_role` (`id_role`) ON UPDATE RESTRICT -) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_role_permission_link` --- - -LOCK TABLES `shop_role_permission_link` WRITE; -/*!40000 ALTER TABLE `shop_role_permission_link` DISABLE KEYS */; -INSERT INTO `shop_role_permission_link` VALUES (1,1,1,3,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(2,1,2,3,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(3,1,3,3,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(4,1,4,3,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(5,1,5,3,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(6,2,1,1,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(7,2,2,1,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(8,2,3,1,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(9,2,4,1,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(10,2,5,1,_binary '','2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_role_permission_link` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Role_Permission_Link` BEFORE INSERT ON `shop_role_permission_link` FOR EACH ROW BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Role_Permission_Link` BEFORE UPDATE ON `shop_role_permission_link` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Role_Permission_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_role - SELECT NEW.id_link, 'id_role', CONVERT(OLD.id_role, CHAR), CONVERT(NEW.id_role, CHAR), NEW.id_change_set - WHERE NOT OLD.id_role <=> NEW.id_role - UNION - -- Changed id_permission - SELECT NEW.id_link, 'id_permission', CONVERT(OLD.id_permission, CHAR), CONVERT(NEW.id_permission, CHAR), NEW.id_change_set - WHERE NOT OLD.id_permission <=> NEW.id_permission - UNION - */ - -- Changed id_access_level - SELECT NEW.id_link, 'id_access_level', CONVERT(OLD.id_access_level, CHAR), CONVERT(NEW.id_access_level, CHAR), NEW.id_change_set - WHERE NOT OLD.id_access_level <=> NEW.id_access_level - UNION - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_role_permission_link_audit` --- - -DROP TABLE IF EXISTS `shop_role_permission_link_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_role_permission_link_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_link` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Role_Permission_Link_Audit_id_link` (`id_link`), - KEY `FK_Shop_Role_Permission_Link_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Role_Permission_Link_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_user_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Role_Permission_Link_Audit_id_link` FOREIGN KEY (`id_link`) REFERENCES `shop_role_permission_link` (`id_link`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_role_permission_link_audit` --- - -LOCK TABLES `shop_role_permission_link_audit` WRITE; -/*!40000 ALTER TABLE `shop_role_permission_link_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_role_permission_link_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_tax_or_surcharge` --- - -DROP TABLE IF EXISTS `shop_tax_or_surcharge`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_tax_or_surcharge` ( - `id_tax` int NOT NULL AUTO_INCREMENT, - `code` varchar(50) NOT NULL, - `name` varchar(200) NOT NULL, - `id_region_buyer` int NOT NULL, - `id_region_seller` int NOT NULL, - `id_currency` int DEFAULT NULL, - `fixed_fee` float NOT NULL DEFAULT '0', - `multiplier` float NOT NULL DEFAULT '1', - `apply_fixed_fee_before_multiplier` bit(1) DEFAULT b'1', - `quantity_min` float NOT NULL DEFAULT '0', - `quantity_max` float NOT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `display_order` int NOT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_tax`), - KEY `FK_Shop_Tax_Or_Surcharge_id_region_buyer` (`id_region_buyer`), - KEY `FK_Shop_Tax_Or_Surcharge_id_region_seller` (`id_region_seller`), - KEY `FK_Shop_Tax_Or_Surcharge_id_currency` (`id_currency`), - KEY `FK_Shop_Tax_Or_Surcharge_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Tax_Or_Surcharge_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Tax_Or_Surcharge_id_currency` FOREIGN KEY (`id_currency`) REFERENCES `shop_currency` (`id_currency`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Tax_Or_Surcharge_id_region_buyer` FOREIGN KEY (`id_region_buyer`) REFERENCES `shop_region` (`id_region`), - CONSTRAINT `FK_Shop_Tax_Or_Surcharge_id_region_seller` FOREIGN KEY (`id_region_seller`) REFERENCES `shop_region` (`id_region`), - CONSTRAINT `shop_tax_or_surcharge_chk_1` CHECK ((`multiplier` > 0)) -) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_tax_or_surcharge` --- - -LOCK TABLES `shop_tax_or_surcharge` WRITE; -/*!40000 ALTER TABLE `shop_tax_or_surcharge` DISABLE KEYS */; -INSERT INTO `shop_tax_or_surcharge` VALUES (1,'VAT','Value Added Tax',1,1,NULL,0,0.2,_binary '',0,1,_binary '',1,'2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_tax_or_surcharge` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Tax_Or_Surcharge` BEFORE INSERT ON `shop_tax_or_surcharge` FOR EACH ROW BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Tax_Or_Surcharge` BEFORE UPDATE ON `shop_tax_or_surcharge` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Tax_Or_Surcharge_Audit ( - id_tax, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_tax, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_tax, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed fixed_fee - SELECT NEW.id_tax, 'fixed_fee', OLD.fixed_fee, NEW.fixed_fee, NEW.id_change_set - WHERE NOT OLD.fixed_fee <=> NEW.fixed_fee - UNION - -- Changed multiplier - SELECT NEW.id_tax, 'multiplier', OLD.multiplier, NEW.multiplier, NEW.id_change_set - WHERE NOT OLD.multiplier <=> NEW.multiplier - UNION - -- Changed apply_fixed_fee_before_multiplier - SELECT NEW.id_tax, 'apply_fixed_fee_before_multiplier', CONVERT(CONVERT(OLD.apply_fixed_fee_before_multiplier, SIGNED), CHAR), CONVERT(CONVERT(NEW.apply_fixed_fee_before_multiplier, SIGNED), CHAR), NEW.id_change_set - WHERE NOT OLD.apply_fixed_fee_before_multiplier <=> NEW.apply_fixed_fee_before_multiplier - UNION - -- Changed quantity_min - SELECT NEW.id_tax, 'quantity_min', OLD.quantity_min, NEW.quantity_min, NEW.id_change_set - WHERE NOT OLD.quantity_min <=> NEW.quantity_min - UNION - -- Changed quantity_max - SELECT NEW.id_tax, 'quantity_max', OLD.quantity_max, NEW.quantity_max, NEW.id_change_set - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - UNION - -- Changed display_order - SELECT NEW.id_tax, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - UNION - -- Changed active - SELECT NEW.id_tax, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_tax_or_surcharge_audit` --- - -DROP TABLE IF EXISTS `shop_tax_or_surcharge_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_tax_or_surcharge_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_tax` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Tax_Or_Surcharge_Audit_id_discount` (`id_tax`), - KEY `FK_Shop_Tax_Or_Surcharge_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Tax_Or_Surcharge_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_Tax_Or_Surcharge_Audit_id_discount` FOREIGN KEY (`id_tax`) REFERENCES `shop_tax_or_surcharge` (`id_tax`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_tax_or_surcharge_audit` --- - -LOCK TABLES `shop_tax_or_surcharge_audit` WRITE; -/*!40000 ALTER TABLE `shop_tax_or_surcharge_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_tax_or_surcharge_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_user` --- - -DROP TABLE IF EXISTS `shop_user`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_user` ( - `id_user` varchar(200) NOT NULL, - `name` varchar(255) NOT NULL, - `email` varchar(254) NOT NULL, - `email_verified` bit(1) NOT NULL DEFAULT b'0', - `is_super_user` bit(1) NOT NULL DEFAULT b'0', - `active` bit(1) NOT NULL DEFAULT b'1', - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_user`), - KEY `FK_Shop_User_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_User_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_user_change_set` (`id_change_set`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_user` --- - -LOCK TABLES `shop_user` WRITE; -/*!40000 ALTER TABLE `shop_user` DISABLE KEYS */; -INSERT INTO `shop_user` VALUES ('auth0|6582b95c895d09a70ba10fef','Teddy','edward.middletonsmith@gmail.com',_binary '\0',_binary '',_binary '','2024-04-28 19:03:07','root@localhost',NULL),('parts_guest','Guest','',_binary '\0',_binary '\0',_binary '','2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_user` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_User` BEFORE INSERT ON `shop_user` FOR EACH ROW BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_User` BEFORE UPDATE ON `shop_user` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_User_Audit ( - id_user, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed name - SELECT NEW.id_user, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT (OLD.name <=> NEW.name) - UNION - -- Changed is_super_user - SELECT NEW.id_user, 'is_super_user', CONVERT(CONVERT(OLD.is_super_user, SIGNED), CHAR), CONVERT(CONVERT(NEW.is_super_user, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.is_super_user <=> NEW.is_super_user) - UNION - -- Changed active - SELECT NEW.id_user, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_user_audit` --- - -DROP TABLE IF EXISTS `shop_user_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_user_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_user` varchar(200) NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_User_Audit_id_user` (`id_user`), - KEY `FK_Shop_User_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_User_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_user_change_set` (`id_change_set`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_User_Audit_id_user` FOREIGN KEY (`id_user`) REFERENCES `shop_user` (`id_user`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_user_audit` --- - -LOCK TABLES `shop_user_audit` WRITE; -/*!40000 ALTER TABLE `shop_user_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_user_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_user_basket` --- - -DROP TABLE IF EXISTS `shop_user_basket`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_user_basket` ( - `id_item` int NOT NULL AUTO_INCREMENT, - `id_user` varchar(200) NOT NULL, - `id_product` int NOT NULL, - `id_permutation` int DEFAULT NULL, - `quantity` int NOT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set_user` int DEFAULT NULL, - PRIMARY KEY (`id_item`), - KEY `FK_Shop_User_Basket_id_user` (`id_user`), - KEY `FK_Shop_User_Basket_id_product` (`id_product`), - KEY `FK_Shop_User_Basket_id_permutation` (`id_permutation`), - KEY `FK_Shop_User_Basket_id_change_set_user` (`id_change_set_user`), - CONSTRAINT `FK_Shop_User_Basket_id_change_set_user` FOREIGN KEY (`id_change_set_user`) REFERENCES `shop_user_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_User_Basket_id_permutation` FOREIGN KEY (`id_permutation`) REFERENCES `shop_product_permutation` (`id_permutation`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_User_Basket_id_product` FOREIGN KEY (`id_product`) REFERENCES `shop_product` (`id_product`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_User_Basket_id_user` FOREIGN KEY (`id_user`) REFERENCES `shop_user` (`id_user`) ON UPDATE RESTRICT -) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_user_basket` --- - -LOCK TABLES `shop_user_basket` WRITE; -/*!40000 ALTER TABLE `shop_user_basket` DISABLE KEYS */; -INSERT INTO `shop_user_basket` VALUES (1,'auth0|6582b95c895d09a70ba10fef',1,1,69,_binary '','2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_user_basket` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_User_Basket` BEFORE INSERT ON `shop_user_basket` FOR EACH ROW BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_User_Basket` BEFORE UPDATE ON `shop_user_basket` FOR EACH ROW BEGIN - IF NEW.id_change_set_user <=> OLD.id_change_set_user THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_User_Basket_Audit ( - id_item, - name_field, - value_prev, - value_new, - id_change_set_user - ) - -- Changed id_user - SELECT NEW.id_item, 'id_user', OLD.id_user, NEW.id_user, NEW.id_change_set_user - WHERE NOT OLD.id_user <=> NEW.id_user - UNION - -- Changed id_product - SELECT NEW.id_item, 'id_product', OLD.id_product, NEW.id_product, NEW.id_change_set_user - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed quantity - SELECT NEW.id_item, 'quantity', CONVERT(OLD.quantity, CHAR), CONVERT(NEW.quantity, CHAR), NEW.id_change_set_user - WHERE NOT (OLD.quantity <=> NEW.quantity) - UNION - -- Changed active - SELECT NEW.id_item, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set_user - WHERE NOT (OLD.active <=> NEW.active) - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_user_basket_audit` --- - -DROP TABLE IF EXISTS `shop_user_basket_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_user_basket_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_item` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set_user` int DEFAULT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_User_Basket_Audit_id_link` (`id_item`), - KEY `FK_Shop_User_Basket_Audit_id_change_set_user` (`id_change_set_user`), - CONSTRAINT `FK_Shop_User_Basket_Audit_id_change_set_user` FOREIGN KEY (`id_change_set_user`) REFERENCES `shop_user_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_User_Basket_Audit_id_link` FOREIGN KEY (`id_item`) REFERENCES `shop_user_basket` (`id_item`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_user_basket_audit` --- - -LOCK TABLES `shop_user_basket_audit` WRITE; -/*!40000 ALTER TABLE `shop_user_basket_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_user_basket_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_user_change_set` --- - -DROP TABLE IF EXISTS `shop_user_change_set`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_user_change_set` ( - `id_change_set` int NOT NULL AUTO_INCREMENT, - `comment` varchar(500) DEFAULT NULL, - `updated_last_on` datetime DEFAULT NULL, - `updated_last_by` varchar(100) DEFAULT NULL, - PRIMARY KEY (`id_change_set`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_user_change_set` --- - -LOCK TABLES `shop_user_change_set` WRITE; -/*!40000 ALTER TABLE `shop_user_change_set` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_user_change_set` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_User_Change_Set` BEFORE INSERT ON `shop_user_change_set` FOR EACH ROW BEGIN - IF NEW.updated_last_on <=> NULL THEN - SET NEW.updated_last_on = NOW(); - END IF; - IF NEW.updated_last_by <=> NULL THEN - SET NEW.updated_last_by = CURRENT_USER(); - END IF; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_user_order` --- - -DROP TABLE IF EXISTS `shop_user_order`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_user_order` ( - `id_order` int NOT NULL AUTO_INCREMENT, - `id_user` varchar(200) NOT NULL, - `value_total` float DEFAULT NULL, - `id_order_status` int NOT NULL, - `id_checkout_session` varchar(200) NOT NULL, - `id_currency` int NOT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set_user` int DEFAULT NULL, - PRIMARY KEY (`id_order`), - KEY `FK_Shop_User_Order_id_user` (`id_user`), - KEY `FK_Shop_User_Order_id_order_status` (`id_order_status`), - KEY `FK_Shop_User_Order_id_currency` (`id_currency`), - KEY `FK_Shop_User_Order_id_change_set_user` (`id_change_set_user`), - CONSTRAINT `FK_Shop_User_Order_id_change_set_user` FOREIGN KEY (`id_change_set_user`) REFERENCES `shop_user_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_User_Order_id_currency` FOREIGN KEY (`id_currency`) REFERENCES `shop_currency` (`id_currency`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_User_Order_id_order_status` FOREIGN KEY (`id_order_status`) REFERENCES `shop_user_order_status` (`id_status`), - CONSTRAINT `FK_Shop_User_Order_id_user` FOREIGN KEY (`id_user`) REFERENCES `shop_user` (`id_user`) ON UPDATE RESTRICT -) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_user_order` --- - -LOCK TABLES `shop_user_order` WRITE; -/*!40000 ALTER TABLE `shop_user_order` DISABLE KEYS */; -INSERT INTO `shop_user_order` VALUES (1,'auth0|6582b95c895d09a70ba10fef',25,1,'noods',1,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(2,'auth0|6582b95c895d09a70ba10fef',25,1,'noods',1,_binary '','2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_user_order` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_User_Order` BEFORE INSERT ON `shop_user_order` FOR EACH ROW BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_User_Order` BEFORE UPDATE ON `shop_user_order` FOR EACH ROW BEGIN - IF OLD.id_change_set_user <=> NEW.id_change_set_user THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - IF NOT (NEW.id_checkout_session <=> OLD.id_checkout_session) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Checkout session ID must not change.'; - END IF; - - INSERT INTO Shop_User_Order_Audit ( - id_order, - name_field, - value_prev, - value_new, - id_change_set_user - ) - -- Changed id_user - SELECT NEW.id_order, 'id_user', OLD.id_user, NEW.id_user, NEW.id_change_set_user - WHERE NOT OLD.id_user <=> NEW.id_user - UNION - -- Changed value_total - SELECT NEW.id_order, 'value_total', CONVERT(OLD.value_total, CHAR), CONVERT(NEW.value_total, CHAR), NEW.id_change_set_user - WHERE NOT (OLD.value_total <=> NEW.value_total) - UNION - -- Changed id_order_status - SELECT NEW.id_order, 'id_order_status', CONVERT(OLD.id_order_status, CHAR), CONVERT(NEW.id_order_status, CHAR), NEW.id_change_set_user - WHERE NOT (OLD.id_order_status <=> NEW.id_order_status) - UNION - -- Changed id_checkout_session - SELECT NEW.id_order, 'id_checkout_session', OLD.id_checkout_session, NEW.id_checkout_session, NEW.id_change_set_user - WHERE NOT (OLD.id_checkout_session <=> NEW.id_checkout_session) - UNION - -- Changed active - SELECT NEW.id_order, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set_user - WHERE NOT (OLD.active <=> NEW.active) - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_user_order_audit` --- - -DROP TABLE IF EXISTS `shop_user_order_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_user_order_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_order` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set_user` int DEFAULT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_User_Order_Audit_id_order` (`id_order`), - KEY `FK_Shop_User_Order_Audit_id_change_set_user` (`id_change_set_user`), - CONSTRAINT `FK_Shop_User_Order_Audit_id_change_set_user` FOREIGN KEY (`id_change_set_user`) REFERENCES `shop_user_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_User_Order_Audit_id_order` FOREIGN KEY (`id_order`) REFERENCES `shop_user_order` (`id_order`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_user_order_audit` --- - -LOCK TABLES `shop_user_order_audit` WRITE; -/*!40000 ALTER TABLE `shop_user_order_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_user_order_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_user_order_product_link` --- - -DROP TABLE IF EXISTS `shop_user_order_product_link`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_user_order_product_link` ( - `id_link` int NOT NULL AUTO_INCREMENT, - `id_order` int NOT NULL, - `id_product` int NOT NULL, - `id_permutation` int DEFAULT NULL, - `quantity` float NOT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_link`), - KEY `FK_Shop_User_Order_Product_Link_id_order` (`id_order`), - KEY `FK_Shop_User_Order_Product_Link_id_product` (`id_product`), - KEY `FK_Shop_User_Order_Product_Link_id_permutation` (`id_permutation`), - KEY `FK_Shop_User_Order_Product_Link_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_User_Order_Product_Link_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_user_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_User_Order_Product_Link_id_order` FOREIGN KEY (`id_order`) REFERENCES `shop_user_order` (`id_order`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_User_Order_Product_Link_id_permutation` FOREIGN KEY (`id_permutation`) REFERENCES `shop_product_permutation` (`id_permutation`) ON UPDATE RESTRICT, - CONSTRAINT `FK_Shop_User_Order_Product_Link_id_product` FOREIGN KEY (`id_product`) REFERENCES `shop_product` (`id_product`) ON UPDATE RESTRICT -) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_user_order_product_link` --- - -LOCK TABLES `shop_user_order_product_link` WRITE; -/*!40000 ALTER TABLE `shop_user_order_product_link` DISABLE KEYS */; -INSERT INTO `shop_user_order_product_link` VALUES (1,1,1,1,69,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(2,1,2,NULL,69,_binary '','2024-04-28 19:03:07','root@localhost',NULL),(3,1,1,2,69,_binary '','2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_user_order_product_link` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_User_Order_Product_Link` BEFORE INSERT ON `shop_user_order_product_link` FOR EACH ROW BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_User_Order_Product_Link` BEFORE UPDATE ON `shop_user_order_product_link` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_User_Order_Product_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_product - SELECT NEW.id_link, 'active', CONVERT(OLD.id_product, CHAR), CONVERT(NEW.id_product, CHAR), NEW.id_change_set - WHERE NOT (OLD.id_product <=> NEW.id_product) - UNION - -- Changed quantity - SELECT NEW.id_link, 'quantity', CONVERT(OLD.quantity, CHAR), CONVERT(NEW.quantity, CHAR), NEW.id_change_set - WHERE NOT (OLD.quantity <=> NEW.quantity) - UNION - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_user_order_product_link_audit` --- - -DROP TABLE IF EXISTS `shop_user_order_product_link_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_user_order_product_link_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_link` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_User_Order_Product_Link_Audit_id_link` (`id_link`), - KEY `FK_Shop_User_Order_Product_Link_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_User_Order_Product_Link_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_user_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_User_Order_Product_Link_Audit_id_link` FOREIGN KEY (`id_link`) REFERENCES `shop_user_order_product_link` (`id_link`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_user_order_product_link_audit` --- - -LOCK TABLES `shop_user_order_product_link_audit` WRITE; -/*!40000 ALTER TABLE `shop_user_order_product_link_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_user_order_product_link_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_user_order_status` --- - -DROP TABLE IF EXISTS `shop_user_order_status`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_user_order_status` ( - `id_status` int NOT NULL AUTO_INCREMENT, - `code` varchar(50) DEFAULT NULL, - `name` varchar(255) DEFAULT NULL, - `name_plural` varchar(256) DEFAULT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `display_order` int NOT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_status`), - KEY `FK_Shop_User_Order_Status_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_User_Order_Status_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_user_change_set` (`id_change_set`) -) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_user_order_status` --- - -LOCK TABLES `shop_user_order_status` WRITE; -/*!40000 ALTER TABLE `shop_user_order_status` DISABLE KEYS */; -INSERT INTO `shop_user_order_status` VALUES (1,'SUCCESS','Success','Successes',_binary '',1,'2024-04-28 19:03:07','root@localhost',NULL),(2,'FAIL','Failure','Failures',_binary '',2,'2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_user_order_status` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_User_Order_Status` BEFORE INSERT ON `shop_user_order_status` FOR EACH ROW BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_User_Order_Status` BEFORE UPDATE ON `shop_user_order_status` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_User_Order_Status_Audit ( - id_Status, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_Status, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_Status, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed name_plural - SELECT NEW.id_Status, 'name_plural', OLD.name_plural, NEW.name_plural, NEW.id_change_set - WHERE NOT OLD.name_plural <=> NEW.name_plural - UNION - -- Changed active - SELECT NEW.id_Status, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_Status, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_user_order_status_audit` --- - -DROP TABLE IF EXISTS `shop_user_order_status_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_user_order_status_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_status` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_User_Order_Status_Audit_id_status` (`id_status`), - KEY `FK_Shop_User_Order_Status_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_User_Order_Status_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_User_Order_Status_Audit_id_status` FOREIGN KEY (`id_status`) REFERENCES `shop_user_order_status` (`id_status`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_user_order_status_audit` --- - -LOCK TABLES `shop_user_order_status_audit` WRITE; -/*!40000 ALTER TABLE `shop_user_order_status_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_user_order_status_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_user_role_link` --- - -DROP TABLE IF EXISTS `shop_user_role_link`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_user_role_link` ( - `id_link` int NOT NULL AUTO_INCREMENT, - `id_user` varchar(200) NOT NULL, - `id_role` int NOT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_link`), - KEY `FK_Shop_User_Role_Link_id_user` (`id_user`), - KEY `FK_Shop_User_Role_Link_id_role` (`id_role`), - KEY `FK_Shop_User_Role_Link_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_User_Role_Link_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_user_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_User_Role_Link_id_role` FOREIGN KEY (`id_role`) REFERENCES `shop_role` (`id_role`), - CONSTRAINT `FK_Shop_User_Role_Link_id_user` FOREIGN KEY (`id_user`) REFERENCES `shop_user` (`id_user`) ON UPDATE RESTRICT -) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_user_role_link` --- - -LOCK TABLES `shop_user_role_link` WRITE; -/*!40000 ALTER TABLE `shop_user_role_link` DISABLE KEYS */; -INSERT INTO `shop_user_role_link` VALUES (1,'auth0|6582b95c895d09a70ba10fef',1,_binary '','2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_user_role_link` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_User_Role_Link` BEFORE INSERT ON `shop_user_role_link` FOR EACH ROW BEGIN - IF NEW.created_on <=> NULL THEN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - END IF; - IF NEW.created_by <=> NULL THEN - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); - END IF; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_User_Role_Link` BEFORE UPDATE ON `shop_user_role_link` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_User_Role_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_user_role_link_audit` --- - -DROP TABLE IF EXISTS `shop_user_role_link_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_user_role_link_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_link` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_User_Role_Link_Audit_id_link` (`id_link`), - KEY `FK_Shop_User_Role_Link_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_User_Role_Link_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_user_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_User_Role_Link_Audit_id_link` FOREIGN KEY (`id_link`) REFERENCES `shop_user_role_link` (`id_link`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_user_role_link_audit` --- - -LOCK TABLES `shop_user_role_link_audit` WRITE; -/*!40000 ALTER TABLE `shop_user_role_link_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_user_role_link_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_variation` --- - -DROP TABLE IF EXISTS `shop_variation`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_variation` ( - `id_variation` int NOT NULL AUTO_INCREMENT, - `id_type` int NOT NULL, - `code` varchar(50) DEFAULT NULL, - `name` varchar(255) DEFAULT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `display_order` int NOT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_variation`), - KEY `FK_Shop_Variation_id_type` (`id_type`), - KEY `FK_Shop_Variation_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Variation_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Variation_id_type` FOREIGN KEY (`id_type`) REFERENCES `shop_variation_type` (`id_type`) ON UPDATE RESTRICT -) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_variation` --- - -LOCK TABLES `shop_variation` WRITE; -/*!40000 ALTER TABLE `shop_variation` DISABLE KEYS */; -INSERT INTO `shop_variation` VALUES (1,1,'RED','Red',_binary '',1,'2024-04-28 19:03:07','root@localhost',NULL),(2,1,'BLUE','Blue',_binary '',2,'2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_variation` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Variation` BEFORE INSERT ON `shop_variation` FOR EACH ROW BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Variation` BEFORE UPDATE ON `shop_variation` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Variation_Audit ( - id_variation, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_variation, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_variation, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed active - SELECT NEW.id_variation, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_variation, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_variation_audit` --- - -DROP TABLE IF EXISTS `shop_variation_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_variation_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_variation` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Variation_Audit_id_variation` (`id_variation`), - KEY `FK_Shop_Variation_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Variation_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Variation_Audit_id_variation` FOREIGN KEY (`id_variation`) REFERENCES `shop_variation` (`id_variation`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_variation_audit` --- - -LOCK TABLES `shop_variation_audit` WRITE; -/*!40000 ALTER TABLE `shop_variation_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_variation_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `shop_variation_type` --- - -DROP TABLE IF EXISTS `shop_variation_type`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_variation_type` ( - `id_type` int NOT NULL AUTO_INCREMENT, - `code` varchar(50) DEFAULT NULL, - `name` varchar(255) DEFAULT NULL, - `name_plural` varchar(256) DEFAULT NULL, - `active` bit(1) NOT NULL DEFAULT b'1', - `display_order` int NOT NULL, - `created_on` datetime DEFAULT NULL, - `created_by` varchar(100) DEFAULT NULL, - `id_change_set` int DEFAULT NULL, - PRIMARY KEY (`id_type`), - KEY `FK_Shop_Variation_Type_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Variation_Type_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`) -) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_variation_type` --- - -LOCK TABLES `shop_variation_type` WRITE; -/*!40000 ALTER TABLE `shop_variation_type` DISABLE KEYS */; -INSERT INTO `shop_variation_type` VALUES (1,'COLOUR','Colour','Colours',_binary '',1,'2024-04-28 19:03:07','root@localhost',NULL); -/*!40000 ALTER TABLE `shop_variation_type` ENABLE KEYS */; -UNLOCK TABLES; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_insert_Shop_Variation_Type` BEFORE INSERT ON `shop_variation_type` FOR EACH ROW BEGIN - SET NEW.created_on := IFNULL(NEW.created_on, NOW()); - SET NEW.created_by := IFNULL(NEW.created_by, IFNULL((SELECT id_user FROM Shop_User WHERE firstname = CURRENT_USER()), -1)); -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `before_update_Shop_Variation_Type` BEFORE UPDATE ON `shop_variation_type` FOR EACH ROW BEGIN - IF OLD.id_change_set <=> NEW.id_change_set THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'New change Set ID must be provided.'; - END IF; - - INSERT INTO Shop_Variation_Type_Audit ( - id_type, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_type, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_type, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed name_plural - SELECT NEW.id_type, 'name_plural', OLD.name_plural, NEW.name_plural, NEW.id_change_set - WHERE NOT OLD.name_plural <=> NEW.name_plural - UNION - -- Changed active - SELECT NEW.id_type, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_type, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; -END */;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; - --- --- Table structure for table `shop_variation_type_audit` --- - -DROP TABLE IF EXISTS `shop_variation_type_audit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `shop_variation_type_audit` ( - `id_audit` int NOT NULL AUTO_INCREMENT, - `id_type` int NOT NULL, - `name_field` varchar(50) DEFAULT NULL, - `value_prev` varchar(500) DEFAULT NULL, - `value_new` varchar(500) DEFAULT NULL, - `id_change_set` int NOT NULL, - PRIMARY KEY (`id_audit`), - KEY `FK_Shop_Variation_Type_Audit_id_type` (`id_type`), - KEY `FK_Shop_Variation_Type_Audit_id_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Variation_Type_Audit_id_change_set` FOREIGN KEY (`id_change_set`) REFERENCES `shop_product_change_set` (`id_change_set`), - CONSTRAINT `FK_Shop_Variation_Type_Audit_id_type` FOREIGN KEY (`id_type`) REFERENCES `shop_variation_type` (`id_type`) ON UPDATE RESTRICT -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `shop_variation_type_audit` --- - -LOCK TABLES `shop_variation_type_audit` WRITE; -/*!40000 ALTER TABLE `shop_variation_type_audit` DISABLE KEYS */; -/*!40000 ALTER TABLE `shop_variation_type_audit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `tmp_msg_error` --- - -DROP TABLE IF EXISTS `tmp_msg_error`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `tmp_msg_error` ( - `display_order` int NOT NULL AUTO_INCREMENT, - `guid` varchar(36) NOT NULL, - `id_type` int NOT NULL, - `msg` varchar(4000) NOT NULL, - PRIMARY KEY (`display_order`), - KEY `FK_tmp_Msg_Error_id_type` (`id_type`), - CONSTRAINT `FK_tmp_Msg_Error_id_type` FOREIGN KEY (`id_type`) REFERENCES `shop_msg_error_type` (`id_type`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `tmp_msg_error` --- - -LOCK TABLES `tmp_msg_error` WRITE; -/*!40000 ALTER TABLE `tmp_msg_error` DISABLE KEYS */; -/*!40000 ALTER TABLE `tmp_msg_error` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping events for database 'partsltd_prod' --- - --- --- Dumping routines for database 'partsltd_prod' --- -/*!50003 DROP PROCEDURE IF EXISTS `p_shop_edit_user` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `p_shop_edit_user`( - IN a_id_user INT, - IN a_name VARCHAR(255), - IN a_email VARCHAR(254), - IN a_email_verified BIT -) -BEGIN - -- Argument redeclaration - -- Variable declaration - DECLARE v_has_filter_user BIT; - -- DECLARE v_now DATETIME; - - - -- Argument validation + default values - IF a_id_user IS NULL THEN - SET a_id_user = ''; - ELSE - SET a_id_user = TRIM(a_id_user); - END IF; - IF a_name IS NULL THEN - SET a_name = ''; - ELSE - SET a_name = TRIM(a_name); - END IF; - IF a_email IS NULL THEN - SET a_email = ''; - ELSE - SET a_email = TRIM(a_email); - END IF; - IF a_email_verified IS NULL THEN - SET a_email_verified = 0; - END IF; - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Msg_Error; - DROP TABLE IF EXISTS tmp_Shop_User; - - CREATE TABLE tmp_Shop_User ( - id_user INT NOT NULL, - CONSTRAINT FK_tmp_Shop_User_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user), - active BIT NOT NULL - ); - - CREATE TABLE tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - id_type INT NOT NULL, - -- code VARCHAR(50) NOT NULL, - -- CONSTRAINT chk_tmp_Msg_Error_code CHECK (code IN (SELECT code FROM Shop_Msg_Error_Type)), - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type(id_type), - msg VARCHAR(4000) NOT NULL - ); - - - -- Parse filters - SET v_has_filter_user = CASE WHEN a_id_user = '' THEN 0 ELSE 1 END; - - - -- User - IF v_has_filter_user THEN - INSERT INTO tmp_Shop_User ( - id_user, - active - ) - SELECT id_user, - active - FROM Shop_User - WHERE id_user LIKE CONCAT('%', a_id_user, '%') - AND active - LIMIT 1 - ; - - IF NOT EXISTS (SELECT id_user FROM tmp_Shop_User LIMIT 1) THEN - INSERT INTO Shop_User ( - id_user, - name, - email, - email_verified - ) - VALUES ( - a_id_user, - a_name, - a_email, - a_email_verified - ); - - INSERT INTO tmp_Shop_User ( - id_user, - active - ) - SELECT id_user, - active - FROM Shop_User - WHERE id_user LIKE CONCAT('%', a_id_user, '%') - AND active - LIMIT 1 - ; - END IF; - - SET a_id_user := (SELECT id_user FROM tmp_Shop_User LIMIT 1); - ELSE - INSERT INTO tmp_Msg_Error ( - id_type, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - 'No user ID provided.' - ) - ; - END IF; - - - /* - IF NOT EXISTS (SELECT msg FROM tmp_Msg_Error LIMIT 1) THEN - END IF; - */ - - - -- Returns - -- User - SELECT * - FROM tmp_Shop_User - ; - - -- Errors - SELECT * - FROM tmp_Msg_Error - ; - - /* - -- Return arguments for test - SELECT a_id_user, - a_name, - a_email, - a_email_verified - ; - */ - - -- Clean up - DROP TABLE IF EXISTS tmp_Msg_Error; - DROP TABLE IF EXISTS tmp_Shop_User; -END ;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `p_shop_edit_user_basket` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `p_shop_edit_user_basket`( - IN a_id_user INT, - IN a_ids_permutation_basket VARCHAR(4000), - IN a_quantities_permutation_basket VARCHAR(4000), - IN a_id_permutation_edit INT, - IN a_quantity_permutation_edit INT, - IN a_sum_not_edit BIT, - IN a_id_currency INT, - IN a_id_region_purchase INT -) -BEGIN - -- Argument redeclaration - -- Variable declaration - DECLARE v_has_filter_user BIT; - DECLARE v_has_filter_permutation_basket BIT; - DECLARE v_has_filter_permutation_edit BIT; - DECLARE v_has_filter_region BIT; - DECLARE v_has_filter_currency BIT; - DECLARE v_n_id_permutation_basket INT; - DECLARE v_n_quantity_permutation_basket INT; - DECLARE v_row_number INT; - DECLARE v_guid BINARY(36); - -- DECLARE v_id_user VARCHAR(100); - DECLARE v_id_permission_product INT; - DECLARE v_ids_permutation_permission VARCHAR(4000); - DECLARE v_now DATETIME; - -- DECLARE v_quantity_new INT; - DECLARE v_change_set_used BIT; - DECLARE v_id_change_set INT; - - SET v_guid = UUID(); - - -- Argument validation + default values - IF a_id_user IS NULL THEN - SET a_id_user = ''; - ELSE - SET a_id_user = TRIM(a_id_user); - END IF; - IF a_ids_permutation_basket IS NULL THEN - SET a_ids_permutation_basket = ''; - ELSE - SET a_ids_permutation_basket = TRIM(a_ids_permutation_basket); - END IF; - IF a_quantities_permutation_basket IS NULL THEN - SET a_quantities_permutation_basket = ''; - ELSE - SET a_quantities_permutation_basket = TRIM(a_quantities_permutation_basket); - END IF; - IF a_sum_not_edit IS NULL THEN - SET a_sum_not_edit = 1; - END IF; - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Msg_Error; - DROP TABLE IF EXISTS tmp_Shop_Basket; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Quantity; - DROP TABLE IF EXISTS tmp_Shop_Product; - DROP TABLE IF EXISTS tmp_Shop_User; - - CREATE TABLE tmp_Shop_User ( - id_user INT NOT NULL, - CONSTRAINT FK_tmp_Shop_User_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user), - active BIT NOT NULL - ); - - CREATE TABLE tmp_Shop_Product ( - id_product INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - id_permutation INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - display_order INT NOT NULL, - active INT NOT NULL DEFAULT 1 - ); - - CREATE TEMPORARY TABLE tmp_Shop_Quantity( - quantity INT NOT NULL, - display_order INT NOT NULL, - active INT NOT NULL DEFAULT 1 - ); - - CREATE TABLE tmp_Shop_Basket ( - id_category INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Basket_id_category - FOREIGN KEY (id_category) - REFERENCES Shop_Product_Category(id_category), - id_product INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Basket_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - id_permutation INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Basket_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - id_region_purchase INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Basket_id_region_purchase - FOREIGN KEY (id_region_purchase) - REFERENCES Shop_Region(id_region), - id_currency INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Basket_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency), - quantity INT NOT NULL, - active BIT NOT NULL DEFAULT 1 - /* - display_order_category INT NOT NULL, - display_order_product INT NOT NULL - */ - ); - - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - guid BINARY(36) NOT NULL, - id_type INT NOT NULL, - -- code VARCHAR(50) NOT NULL, - -- CONSTRAINT chk_tmp_Msg_Error_code CHECK (code IN (SELECT code FROM Shop_Msg_Error_Type)), - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type(id_type), - msg VARCHAR(4000) NOT NULL - ); - - - -- Parse filters - SET v_has_filter_user = NOT (a_id_user = ''); - SET v_has_filter_permutation_basket = NOT (a_ids_permutation_basket = ''); - SET v_has_filter_permutation_edit = NOT ISNULL(a_id_permutation_edit); - SET v_has_filter_currency = NOT ISNULL(a_id_currency); - SET v_has_filter_region = NOT ISNULL(a_id_region_purchase); - -- SET v_quantity_new = CASE WHEN a_sum_not_edit THEN quantity + a_quantity_product_edit ELSE a_quantity_product_edit END; - /* - SELECT v_has_filter_user, v_has_filter_basket - ; - - */ - - -- Currency - IF NOT v_has_filter_currency THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - 'Currency ID not provided.' - ) - ; - END IF; - IF v_has_filter_currency AND NOT EXISTS ( SELECT * FROM Shop_Currency WHERE id_currency = a_id_currency) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('Currency ID not found: ', a_id_currency, '.') - ) - ; - END IF; - - -- Region - IF NOT v_has_filter_region THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - 'Region ID not provided.' - ) - ; - END IF; - IF v_has_filter_region AND NOT EXISTS ( SELECT * FROM Shop_Region WHERE id_region = a_id_region_purchase) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('Region ID not found: ', a_id_region_purchase, '.') - ) - ; - END IF; - - -- User - IF v_has_filter_user THEN - INSERT INTO tmp_Shop_User ( - id_user, - active - ) - SELECT id_user, - active - FROM Shop_User - WHERE id_user LIKE CONCAT('%', a_id_user, '%') - AND active - LIMIT 1 - ; - - IF NOT EXISTS (SELECT id_user FROM tmp_Shop_User LIMIT 1) THEN - SET v_has_filter_user = 0; - - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('User ID not found: ', a_id_user, '.') - ) - ; - END IF; - - SET a_id_user := (SELECT id_user FROM tmp_Shop_User LIMIT 1); - END IF; - - IF v_has_filter_user AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - SET v_change_set_used = 0; - INSERT INTO Shop_User_Change_Set ( - comment - ) - VALUES ( - 'edit basket' - ); - SET v_id_change_set := (SELECT id_change_set FROM Shop_User_Change_Set ORDER BY id_change_set DESC LIMIT 1); - END IF; - - -- Get basket - -- User - IF v_has_filter_user AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - INSERT INTO tmp_Shop_Basket ( - id_category, - id_product, - id_permutation, - id_region_purchase, - id_currency, - quantity, - active - /* - display_order_category, - display_order_product - */ - ) - SELECT - C.id_category, - UB.id_product, - UB.id_permutation, - UB.id_region_purchase, - UB.id_currency, - UB.quantity, - UB.active - /* - C.display_order, - P.display_order - */ - FROM Shop_User_Basket UB - /* - INNER JOIN tmp_Shop_User t_U - ON UB.id_user = t_U.id_user - */ - INNER JOIN Shop_Product_Permutation PP - ON UB.id_product = PP.id_product - AND PP.active - INNER JOIN Shop_Product P - ON PP.id_product = P.id_product - AND P.active - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - AND C.active - WHERE UB.id_user = a_id_user - ; - END IF; - - -- Currency - IF EXISTS (SELECT * FROM tmp_Shop_Basket WHERE active LIMIT 1) - AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - IF EXISTS (SELECT * FROM tmp_Shop_Basket WHERE active AND id_currency != a_id_currency) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT( - 'Currency ID does not match currency of other items in basket. Basket currency: ', - (SELECT code FROM Shop_Currency WHERE id_currency = ( - SELECT - id_currency - FROM tmp_Shop_Basket - WHERE active - AND id_currency != a_id_currency - LIMIT 1 - )), - ', new currency: ', - (SELECT code FROM Shop_Currency WHERE id_currency = a_id_currency), - '.' - ) - ) - ; - END IF; - END IF; - - -- Region - IF EXISTS (SELECT * FROM tmp_Shop_Basket WHERE active LIMIT 1) - AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Shop_Basket - WHERE - active - AND id_region_purchase != a_id_region_purchase - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('Purchase region ID does not match region of other items in basket. Basket currency: ', - (SELECT code FROM Shop_Region WHERE id_region = ( - SELECT - id_region_purchase - FROM tmp_Shop_Basket - WHERE active - AND id_region != a_id_region_purchase - LIMIT 1 - )), - ', new currency: ', - (SELECT code FROM Shop_Region WHERE id_region = a_id_region_purchase), - '.' - ) - ) - ; - END IF; - END IF; - - -- String product id, permutation id, quantity list - IF NOT EXISTS (SELECT * FROM tmp_Shop_Basket WHERE active LIMIT 1) AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN -- NOT v_has_filter_user AND - -- Get product ids - CALL p_split(a_ids_permutation_basket, ','); - INSERT INTO tmp_Shop_Product ( - id_product, id_permutation, display_order - ) - SELECT PP.id_product, ST.substring, ST.display_order - FROM Split_Temp ST - INNER JOIN Shop_Product_Permutation PP - ON ST.substring = PP.id_permutation - -- AND PP.active - ; - /* - SELECT substring as id_product, display_order - FROM Split_Temp - ; - */ - DROP TABLE Split_Temp; - - -- Get product quantities - CALL p_split(a_quantities_permutation_basket, ','); - INSERT INTO tmp_Shop_Quantity ( - quantity, display_order - ) - SELECT substring, display_order - FROM Split_Temp - ; - /* - SELECT substring AS quantity_product, display_order - FROM Split_Temp - ; - */ - DROP TABLE Split_Temp; - - -- Compare number of product ids to number of quantities - SET v_n_id_permutation_basket := (SELECT display_order FROM tmp_Shop_Product ORDER BY display_order DESC LIMIT 1); - SET v_n_quantity_permutation_basket := (SELECT display_order FROM tmp_Shop_Quantity ORDER BY display_order DESC LIMIT 1); - IF NOT v_n_id_permutation_basket = v_n_quantity_permutation_basket THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('Number of permutations (', v_n_id_permutation_basket, ') does not equal number of quantities (', v_n_quantity_permutation_basket, ') for basket.') - ) - ; - ELSE - INSERT INTO tmp_Shop_Basket ( - id_category, - id_product, - id_permutation, - id_region_purchase, - id_currency, - quantity - ) - SELECT - C.id_category, - P.id_product, - t_P.id_permutation, - a_id_region_purchase, - a_id_currency, - t_Q.quantity - FROM tmp_Shop_Product t_P - INNER JOIN tmp_Shop_Quantity t_Q - ON t_P.display_order = t_Q.display_order - INNER JOIN Shop_Product_Permutation PP - ON t_P.id_permutation = PP.id_permutation - AND PP.active - INNER JOIN Shop_Product P - ON PP.id_product = P.id_product - AND P.active - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - AND C.active - -- RIGHT JOIN tmp_Shop_Basket t_UB ON ISNULL(t_UB.id_product) - -- WHERE t_P.id_product NOT IN (SELECT id_product FROM tmp_Shop_Basket) - ; - - /* - IF EXISTS( - SELECT * - FROM Shop_Product P - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - INNER JOIN tmp_Shop_Basket t_B - ON P.id_product = t_B.id_product - WHERE C.active = 0 OR P.active = 0 LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('No valid product IDs in list: ', a_ids_permutation_basket, '.') - ) - ; - END IF; - */ - END IF; - END IF; - - /* - select v_has_filter_edit; - select * from tmp_Shop_Basket; - select * from tmp_Msg_Error; - */ - - - -- Edit basket product - IF v_has_filter_permutation_edit AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM Shop_Product_Permutation PP - INNER JOIN Shop_Product P - ON PP.id_product = P.id_product - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - WHERE - ( - C.active = 0 - OR P.active = 0 - OR PP.active = 0 - ) - AND PP.id_permutation = a_id_permutation_edit - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('Invalid product ID to edit: ', a_id_product_edit, '.') - ) - ; - END IF; - END IF; - IF v_has_filter_permutation_edit AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Shop_Basket - WHERE - id_permutation = a_id_permutation_edit - ) THEN - UPDATE tmp_Shop_Basket - SET quantity = CASE WHEN a_sum_not_edit = 1 THEN IFNULL(quantity, 0) + a_quantity_permutation_edit ELSE a_quantity_permutation_edit END, - active = CASE WHEN CASE WHEN a_sum_not_edit = 1 THEN IFNULL(quantity, 0) + a_quantity_permutation_edit ELSE a_quantity_permutation_edit END = 0 THEN 0 ELSE 1 END - WHERE id_permutation = a_id_permutation_edit - ; - - IF EXISTS ( - SELECT * - FROM tmp_Shop_Basket t_B - WHERE t_B.quantity < 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - 'Invalid basket quantity.' - ) - ; - END IF; - - IF v_has_filter_user AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - SET v_change_set_used = 1; - - UPDATE Shop_User_Basket UB - INNER JOIN tmp_Shop_Basket t_UB - ON UB.id_permutation = a_id_permutation_edit - SET UB.quantity = t_UB.quantity, - UB.active = t_UB.active, - UB.id_change_set_user = v_id_change_set - WHERE UB.id_permutation = a_id_permutation_edit - AND id_user = a_id_user - ; - END IF; - ELSE - IF a_quantity_permutation_edit < 0 THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - 'Invalid basket quantity.' - ) - ; - ELSE - INSERT INTO tmp_Shop_Basket ( - id_category, - id_product, - id_permutation, - id_region_purchase, - id_currency, - quantity, - active - ) - SELECT - P.id_category, - P.id_product, - PP.id_permutation, - a_id_region_purchase, - a_id_currency, - a_quantity_permutation_edit, - CASE WHEN a_quantity_permutation_edit > 0 THEN 1 ELSE 0 END - FROM Shop_Product_Permutation PP - INNER JOIN Shop_Product P - ON PP.id_product = P.id_product - WHERE id_permutation = a_id_permutation_edit - ; - IF v_has_filter_user THEN - IF EXISTS ( - SELECT * - FROM Shop_User_Basket UB - WHERE - UB.id_permutation = a_id_permutation_edit - ) THEN - SET v_change_set_used = 1; - - UPDATE Shop_User_Basket - INNER JOIN tmp_Shop_Basket t_UB ON UB.id_permutation = t_UB.id_permutation - SET UB.quantity = t_UB.quantity, - UB.active = t_UB.active, - UB.id_change_set_user = v_id_change_set - WHERE UB.id_permutation = a_id_permutation_edit - AND id_user = a_id_user - ; - ELSE - INSERT INTO Shop_User_Basket ( - id_user, - id_product, - id_permutation, - id_region_purchase, - id_currency, - quantity, - active - ) - SELECT a_id_user, - t_UB.id_product, - t_UB.id_permutation, - t_UB.id_region_purchase, - t_UB.id_currency, - t_UB.quantity, - t_UB.active - FROM tmp_Shop_Basket t_UB - WHERE id_permutation = a_id_permutation_edit - ; - END IF; - END IF; - END IF; - END IF; - END IF; - - - -- Checks - /* - SELECT * FROM tmp_Shop_Basket; - SELECT - GROUP_CONCAT(t_UB.id_product SEPARATOR ',') AS basket_product_ids - FROM tmp_Shop_Basket t_UB - -- WHERE ISNULL(t_UB.id_permutation) - ; - SELECT - GROUP_CONCAT(t_UB.id_permutation SEPARATOR ',') AS basket_permutation_ids - FROM tmp_Shop_Basket t_UB - WHERE NOT ISNULL(t_UB.id_permutation) - ; - */ - -- Returns - CALL p_shop_get_many_product ( - a_id_user, -- a_id_user - 1, -- a_get_all_categories - '', -- a_ids_category - 0, -- a_get_inactive_categories - 0, -- a_get_all_products - ( - SELECT - GROUP_CONCAT(t_B.id_product SEPARATOR ',') - FROM tmp_Shop_Basket t_B - WHERE active = 1 - ), -- a_ids_product - 0, -- a_get_inactive_products - 0, -- a_get_first_product_only - 0, -- a_get_all_product_permutations - ( - SELECT - GROUP_CONCAT(t_B.id_permutation SEPARATOR ',') - FROM tmp_Shop_Basket t_B - WHERE NOT ISNULL(t_B.id_permutation) - AND active = 1 - ), -- a_ids_permutation - 0, -- a_get_inactive_permutations - 0, -- a_get_all_images - '', -- a_ids_image - 0, -- a_get_inactive_images - 1, -- a_get_first_image_only - 0, -- a_get_all_delivery_region - a_id_region_purchase, -- a_ids_delivery_region - 0, -- a_get_inactive_delivery_region - 0, -- a_get_all_currency - a_id_currency, -- a_ids_currency - 0, -- a_get_inactive_currency - 1, -- a_get_all_discount - '', -- a_ids_discount - 0 -- a_get_inactive_discount - ); - - -- Basket - SELECT t_UB.id_category, - t_UB.id_product, - t_UB.id_permutation, - P.name, - PCL.price_local_VAT_incl, - PCL.price_local_VAT_excl, - PCL.id_currency, - t_UB.quantity - FROM tmp_Shop_Basket t_UB - INNER JOIN Shop_Product_Permutation PP - ON t_UB.id_permutation = PP.id_permutation - INNER JOIN Shop_Product P - ON PP.id_product = P.id_product - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - INNER JOIN Shop_Product_Currency_Link PCL - ON PP.id_permutation = PCL.id_permutation - AND PCL.id_region_purchase = a_id_region_purchase - AND PCL.id_currency = a_id_currency - WHERE t_UB.active = 1 - ORDER BY C.display_order, P.display_order - ; - - -- Errors - /* Completed by product get many */ - SELECT - t_ME.display_order, - t_ME.guid, - t_ME.id_type, - t_ME.msg, - MET.code, - MET.name, - MET.description - FROM tmp_Msg_Error t_ME - INNER JOIN Shop_Msg_Error_Type MET - ON t_ME.id_type = MET.id_type - WHERE GUID = v_guid - ; - - /* - -- Return arguments for test - SELECT - a_ids_category, - a_get_inactive_categories, - a_ids_product, - a_get_inactive_products, - a_get_first_product_only, - a_get_all_products, - a_ids_image, - a_get_inactive_images, - a_get_first_image_only, - a_get_all_images - ; - */ - - -- Clean up - IF NOT v_change_set_used THEN - DELETE FROM Shop_User_Change_Set - WHERE id_change_set = v_id_change_set - ; - END IF; - - -- DROP TABLE IF EXISTS tmp_Msg_Error; - DELETE FROM tmp_Msg_Error WHERE guid = v_guid; - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - DROP TABLE tmp_Msg_Error; - END IF; - DROP TABLE IF EXISTS tmp_Shop_Basket; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Quantity; - DROP TABLE IF EXISTS tmp_Shop_Product; - DROP TABLE IF EXISTS tmp_Shop_User; -END ;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `p_shop_get_many_currency` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `p_shop_get_many_currency`( - IN a_get_inactive_currency BIT -) -BEGIN - IF a_get_inactive_currency IS NULL THEN - SET a_get_inactive_currency = 0; - END IF; - - SELECT - C.id_currency, - C.code, - C.name, - C.factor_from_GBP, - C.active, - C.display_order - FROM Shop_Currency C - WHERE a_get_inactive_currency - OR C.active - ORDER BY C.display_order - ; -END ;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `p_shop_get_many_product` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `p_shop_get_many_product`( - IN a_id_user INT, - IN a_get_all_category BIT, - IN a_ids_category VARCHAR(500), - IN a_get_inactive_category BIT, - IN a_get_all_product BIT, - IN a_ids_product VARCHAR(500), - IN a_get_inactive_product BIT, - IN a_get_first_product_only BIT, - IN a_get_all_product_permutation BIT, - IN a_ids_permutation VARCHAR(4000), - IN a_get_inactive_permutation BIT, - IN a_get_all_image BIT, - IN a_ids_image VARCHAR(4000), - IN a_get_inactive_image BIT, - IN a_get_first_image_only BIT, - IN a_get_all_delivery_region BIT, - IN a_ids_delivery_region VARCHAR(4000), - IN a_get_inactive_delivery_region BIT, - IN a_get_all_currency BIT, - IN a_ids_currency VARCHAR(4000), - IN a_get_inactive_currency BIT, - IN a_get_all_discount BIT, - IN a_ids_discount VARCHAR(4000), - IN a_get_inactive_discount BIT -) -BEGIN - -- Argument redeclaration - -- Variable declaration - DECLARE v_has_filter_category BIT; - DECLARE v_has_filter_product BIT; - DECLARE v_has_filter_permutation BIT; - DECLARE v_has_filter_image BIT; - DECLARE v_has_filter_delivery_region BIT; - DECLARE v_has_filter_currency BIT; - DECLARE v_has_filter_discount BIT; - DECLARE v_guid BINARY(36); - -- DECLARE v_id_user VARCHAR(100); - DECLARE v_ids_permutation_unavailable VARCHAR(4000); - DECLARE v_id_permission_product INT; - DECLARE v_ids_product_permission VARCHAR(4000); - DECLARE v_ids_permutation_permission VARCHAR(4000); - DECLARE v_id_access_level_view INT; - DECLARE v_now DATETIME; - DECLARE v_id_minimum INT; - - SET v_guid := UUID(); - SET v_id_access_level_view := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW'); - - - -- Argument validation + default values - IF a_id_user IS NULL THEN - SET a_id_user = ''; - ELSE - SET a_id_user = TRIM(a_id_user); - END IF; - IF a_get_all_category IS NULL THEN - SET a_get_all_category = 0; - END IF; - IF a_ids_category IS NULL THEN - SET a_ids_category = ''; - ELSE - SET a_ids_category = REPLACE(TRIM(a_ids_category), '|', ','); - END IF; - IF a_get_inactive_category IS NULL THEN - SET a_get_inactive_category = 0; - END IF; - IF a_ids_product IS NULL THEN - SET a_ids_product = ''; - ELSE - SET a_ids_product = REPLACE(TRIM(a_ids_product), '|', ','); - END IF; - IF a_get_inactive_product IS NULL THEN - SET a_get_inactive_product = 0; - END IF; - IF a_get_first_product_only IS NULL THEN - SET a_get_first_product_only = 1; - END IF; - IF a_get_all_product IS NULL THEN - SET a_get_all_product = 0; - END IF; - IF a_ids_permutation IS NULL THEN - SET a_ids_permutation = ''; - ELSE - SET a_ids_permutation = REPLACE(TRIM(a_ids_permutation), '|', ','); - END IF; - IF a_get_inactive_permutation IS NULL THEN - SET a_get_inactive_permutation = 0; - END IF; - IF a_get_all_image IS NULL THEN - SET a_get_all_image = 1; - END IF; - IF a_ids_image IS NULL THEN - SET a_ids_image = ''; - ELSE - SET a_ids_image = REPLACE(TRIM(a_ids_image), '|', ','); - END IF; - IF a_get_inactive_image IS NULL THEN - SET a_get_inactive_image = 0; - END IF; - IF a_get_first_image_only IS NULL THEN - SET a_get_first_image_only = 0; - END IF; - IF a_get_inactive_image IS NULL THEN - SET a_get_inactive_image = 0; - END IF; - IF a_get_all_delivery_region IS NULL THEN - SET a_get_all_delivery_region = 1; - END IF; - IF a_ids_delivery_region IS NULL THEN - SET a_ids_delivery_region = ''; - ELSE - SET a_ids_delivery_region = REPLACE(TRIM(a_ids_delivery_region), '|', ','); - END IF; - IF a_get_inactive_delivery_region IS NULL THEN - SET a_get_inactive_delivery_region = 0; - END IF; - IF a_get_all_currency IS NULL THEN - SET a_get_all_currency = 1; - END IF; - IF a_ids_currency IS NULL THEN - SET a_ids_currency = ''; - ELSE - SET a_ids_currency = REPLACE(TRIM(a_ids_currency), '|', ','); - END IF; - IF a_get_inactive_currency IS NULL THEN - SET a_get_inactive_currency = 0; - END IF; - IF a_get_all_discount IS NULL THEN - SET a_get_all_discount = 1; - END IF; - IF a_ids_discount IS NULL THEN - SET a_ids_discount = ''; - ELSE - SET a_ids_discount = REPLACE(TRIM(a_ids_discount), '|', ','); - END IF; - IF a_get_inactive_discount IS NULL THEN - SET a_get_inactive_discount = 0; - END IF; - - /* - SELECT a_id_user, a_get_all_category, a_ids_category, a_get_inactive_category, a_get_all_product, - a_ids_product, a_get_inactive_product, a_get_first_product_only, a_get_all_product_permutation, a_ids_permutation, - a_get_inactive_permutation, a_get_all_image, a_ids_image, a_get_inactive_image, a_get_first_image_only, - a_get_all_delivery_region, a_ids_delivery_region, a_get_inactive_delivery_region, a_get_all_currency, a_ids_currency, - a_get_inactive_currency, a_get_all_discount, a_ids_discount, a_get_inactive_discount - ; - */ - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Discount; - DROP TABLE IF EXISTS tmp_Currency; - DROP TABLE IF EXISTS tmp_Delivery_Region; - DROP TABLE IF EXISTS tmp_Shop_Image; - DROP TABLE IF EXISTS tmp_Shop_Variation; - DROP TABLE IF EXISTS tmp_Shop_Product; - DROP TABLE IF EXISTS tmp_Shop_Product_Category; - - CREATE TABLE tmp_Shop_Product_Category ( - id_category INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_Category_id_category - FOREIGN KEY (id_category) - REFERENCES Shop_Product_Category(id_category), - active BIT NOT NULL, - display_order INT NOT NULL, - can_view BIT, - can_edit BIT, - can_admin BIT - ); - - CREATE TABLE tmp_Shop_Product ( - id_category INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_category - FOREIGN KEY (id_category) - REFERENCES Shop_Product_Category(id_category), - id_product INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - -- product_has_variations BIT NOT NULL, - id_permutation INT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - active_category BIT NOT NULL, - active_product BIT NOT NULL, - active_permutation BIT NULL, - display_order_category INT NOT NULL, - display_order_product INT NOT NULL, - display_order_permutation INT NULL, - rank_permutation INT NOT NULL, -- _in_category - name VARCHAR(255) NOT NULL, - description VARCHAR(4000) NOT NULL, - /* - price_GBP_full FLOAT NOT NULL, - price_GBP_min FLOAT NOT NULL, - */ - latency_manufacture INT NOT NULL, - quantity_min FLOAT NOT NULL, - quantity_max FLOAT NOT NULL, - quantity_step FLOAT NOT NULL, - quantity_stock FLOAT NOT NULL, - is_subscription BIT NOT NULL, - id_unit_measurement_interval_recurrence INT, - CONSTRAINT FK_tmp_Shop_Product_id_unit_measurement_interval_recurrence - FOREIGN KEY (id_unit_measurement_interval_recurrence) - REFERENCES Shop_Interval_Recurrence(id_interval), - count_interval_recurrence INT, - id_stripe_product VARCHAR(100), - product_has_variations INT NOT NULL, - can_view BIT, - can_edit BIT, - can_admin BIT - ); - - /* - CREATE TEMPORARY TABLE tmp_Shop_Variation ( - id_variation INT NOT NULL, - id_product INT NOT NULL, - display_order INT NOT NULL - ); - */ - - CREATE TABLE tmp_Shop_Image ( - id_image INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Image_id_image - FOREIGN KEY (id_image) - REFERENCES Shop_Image(id_image), - id_product INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Image_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - id_permutation INT NULL, - CONSTRAINT FK_tmp_Shop_Image_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - active BIT NOT NULL, - display_order INT NOT NULL, - rank_in_product_permutation INT NOT NULL - ); - - CREATE TABLE tmp_Delivery_Region ( - id_region INT NOT NULL, - CONSTRAINT FK_tmp_Delivery_Region_id_region - FOREIGN KEY (id_region) - REFERENCES Shop_Region(id_region), - active BIT NOT NULL, - display_order INT NOT NULL, - requires_delivery_option BIT NOT NULL DEFAULT 0 - ); - - CREATE TABLE tmp_Currency ( - id_currency INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Currency_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency), - active BIT NOT NULL, - display_order INT NOT NULL - ); - - CREATE TABLE tmp_Discount ( - id_discount INT NOT NULL, - CONSTRAINT FK_tmp_Discount_id_discount - FOREIGN KEY (id_discount) - REFERENCES Shop_Discount(id_discount), - active BIT NOT NULL, - display_order INT NOT NULL - ); - - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( -- IF NOT EXISTS - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - guid BINARY(36) NOT NULL, - -- code VARCHAR(50) NOT NULL, - -- CONSTRAINT chk_tmp_Msg_Error_code CHECK (code IN (SELECT code FROM Shop_Msg_Error_Type)), - id_type INT NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type(id_type), - msg VARCHAR(4000) NOT NULL - ); - - - -- Parse filters - SET v_has_filter_category = CASE WHEN a_ids_category = '' THEN 0 ELSE 1 END; - SET v_has_filter_product = CASE WHEN a_ids_product = '' THEN 0 ELSE 1 END; - SET v_has_filter_permutation = CASE WHEN a_ids_permutation = '' THEN 0 ELSE 1 END; - SET v_has_filter_image = CASE WHEN a_ids_image = '' THEN 0 ELSE 1 END; - SET v_has_filter_delivery_region = CASE WHEN a_ids_delivery_region = '' THEN 0 ELSE 1 END; - SET v_has_filter_currency = CASE WHEN a_ids_currency = '' THEN 0 ELSE 1 END; - SET v_has_filter_discount = CASE WHEN a_ids_discount = '' THEN 0 ELSE 1 END; - - -- select v_has_filter_product, v_has_filter_permutation; - - INSERT INTO tmp_Shop_Product ( - id_category, - id_product, - id_permutation, - active_category, - active_product, - active_permutation, - display_order_category, - display_order_product, - display_order_permutation, - rank_permutation, - name, - description, - /* - price_GBP_VAT_incl, - price_GBP_VAT_excl, - price_GBP_min, - */ - latency_manufacture, - quantity_min, - quantity_max, - quantity_step, - quantity_stock, - is_subscription, - id_unit_measurement_interval_recurrence, - count_interval_recurrence, - id_stripe_product, - product_has_variations - ) - SELECT - P.id_category, - P.id_product, - -- P.has_variations AS product_has_variations, - PP.id_permutation, - C.active AS active_category, - P.active AS active_product, - PP.active AS active_permutation, - C.display_order AS display_order_category, - P.display_order AS display_order_product, - PP.display_order AS display_order_permutation, - RANK() OVER (ORDER BY C.display_order, P.display_order, PP.display_order) AS rank_permutation, --PARTITION BY P.id_category -- _in_category - P.name, - PP.description, - /* - PP.price_GBP_VAT_incl, - PP.price_GBP_VAT_excl, - PP.price_GBP_min, - */ - PP.latency_manufacture, - PP.quantity_min, - PP.quantity_max, - PP.quantity_step, - PP.quantity_stock, - PP.is_subscription, - PP.id_unit_measurement_interval_recurrence, - PP.count_interval_recurrence, - PP.id_stripe_product, - P.has_variations - FROM Shop_Product P - INNER JOIN Shop_Product_Permutation PP - ON P.id_product = PP.id_product - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - WHERE - -- permutations - ( - ( - a_get_all_product_permutation - OR v_has_filter_permutation AND FIND_IN_SET(PP.id_permutation, a_ids_permutation) > 0 - ) - AND (a_get_inactive_permutation OR PP.active) - ) - -- categories - AND ( - ( - a_get_all_category - OR v_has_filter_category AND FIND_IN_SET(P.id_category, a_ids_category) > 0 - ) - AND (a_get_inactive_category OR C.active) - ) - -- products - AND ( - ( - a_get_all_product - OR v_has_filter_product AND FIND_IN_SET(P.id_product, a_ids_product) > 0 - ) - AND (a_get_inactive_product OR P.active) - ) - ; - - -- select * from tmp_Shop_Product; - - IF a_get_first_product_only THEN - DELETE FROM tmp_Shop_Product t_P - WHERE t_P.rank_permutation > 1 - ; - END IF; - - INSERT INTO tmp_Shop_Product_Category ( - id_category, - active, - display_order - ) - SELECT DISTINCT C.id_category, - C.active, - C.display_order - FROM tmp_Shop_Product t_P - INNER JOIN Shop_Product_Category C - ON t_P.id_category = C.id_category - ORDER BY C.display_order - ; - - /* - INSERT INTO tmp_Shop_Variation ( - id_variation, id_product -- , display_order - ) - SELECT P.id_variation, P.id_product -- , P.display_order - FROM Shop_Variation V - INNER JOIN tmp_Shop_Product t_P - ON V.id_product = t_P.id_product - WHERE V.active; - */ - - -- Product Images - INSERT INTO tmp_Shop_Image ( - id_product, - id_permutation, - id_image, - active, - display_order, - rank_in_product_permutation - ) - SELECT id_product, - id_permutation, - id_image, - active, - ROW_NUMBER() OVER (ORDER BY display_order_product_temp, display_order_image), - RANK() OVER (PARTITION BY id_product, id_permutation ORDER BY display_order_product_temp, display_order_image) - FROM ( - SELECT t_P.id_product, - I.id_permutation, - I.id_image, - I.active, - I.display_order AS display_order_image, - t_P.rank_permutation AS display_order_product_temp - FROM Shop_Image I - INNER JOIN tmp_Shop_Product t_P - ON I.id_product = t_P.id_product - AND NOT t_P.product_has_variations - UNION - SELECT t_P.id_product, - I.id_permutation, - I.id_image, - I.active, - I.display_order AS display_order_image, - t_P.rank_permutation AS display_order_product_temp - FROM Shop_Image I - INNER JOIN tmp_Shop_Product t_P - ON I.id_permutation = t_P.id_permutation - AND t_P.product_has_variations - ) IPP - WHERE (a_get_all_image OR a_get_first_image_only OR FIND_IN_SET(id_image, a_ids_image) > 0) - AND (a_get_inactive_image OR IPP.active) - ; - - IF a_get_first_image_only THEN - DELETE FROM tmp_Shop_Image - WHERE rank_in_product_permutation > 1 - ; - END IF; - - /* - IF v_has_filter_image THEN - DELETE FROM tmp_Shop_Product - WHERE id_product NOT IN (SELECT DISTINCT id_product FROM tmp_Shop_Image); - DELETE FROM tmp_Shop_Product_Category - WHERE id_category NOT IN (SELECT DISTINCT id_category FROM tmp_Shop_Product); - END IF; - */ - - -- Delivery Regions - INSERT INTO tmp_Delivery_Region ( - id_region, - active, - display_order, - requires_delivery_option - ) - WITH RECURSIVE Recursive_CTE_Delivery_Region AS ( - SELECT - DR.id_region AS id_region_parent, - NULL AS id_region_child, - CASE WHEN FIND_IN_SET(DR.id_region, a_ids_delivery_region) > 0 THEN 1 ELSE 0 END AS requires_delivery_option - FROM Shop_Product_Currency_Region_Link PCRL - INNER JOIN Shop_Currency C ON PCRL.id_currency = C.id_currency - INNER JOIN tmp_Shop_Product t_P - ON PCRL.id_product <=> t_P.id_product - AND PCRL.id_permutation <=> t_P.id_permutation - INNER JOIN Shop_Region DR ON PCRL.id_region_purchase = DR.id_region - WHERE - ( - a_get_all_delivery_region - OR FIND_IN_SET(DR.id_region, a_ids_delivery_region) > 0 - ) - AND ( - a_get_inactive_delivery_region - OR DR.active = 1 - ) - UNION - SELECT - DRB.id_region_parent, - DRB.id_region_child, - 0 AS requires_delivery_option - FROM Shop_Region_Branch DRB - INNER JOIN Recursive_CTE_Delivery_Region r_DR - ON DRB.id_region_parent = r_DR.id_region_child - AND ( - a_get_inactive_delivery_region - OR DRB.active = 1 - ) - ) - SELECT - DR.id_region, - DR.active, - DR.display_order, - requires_delivery_option - FROM Shop_Region DR - INNER JOIN Recursive_CTE_Delivery_Region r_DR - ON DR.id_region = r_DR.id_region_parent - OR DR.id_region = r_DR.id_region_child - ; - /* - select * from tmp_delivery_region; - SELECT * - FROM tmp_Shop_Product t_P - WHERE - /*( - a_get_all_category - OR a_get_all_product - OR a_get_all_product_permutation - )* - FIND_IN_SET(t_P.id_category, a_ids_category) > 0 - OR FIND_IN_SET(t_P.id_product, a_ids_product) > 0 - OR FIND_IN_SET(t_P.id_permutation, a_ids_permutation) > 0 - ; - */ - - IF v_has_filter_delivery_region THEN - SET v_ids_permutation_unavailable = ( - SELECT GROUP_CONCAT(t_P.id_permutation SEPARATOR ', ') - FROM ( - SELECT * - FROM tmp_Shop_Product t_P - WHERE - /*( - a_get_all_category - OR a_get_all_produc - OR a_get_all_product_permutation - )*/ - FIND_IN_SET(t_P.id_category, a_ids_category) > 0 - OR FIND_IN_SET(t_P.id_product, a_ids_product) > 0 - OR FIND_IN_SET(t_P.id_permutation, a_ids_permutation) > 0 - ) t_P - LEFT JOIN ( - SELECT * - FROM Shop_Product_Currency_Region_Link PCRL - WHERE - ( - a_get_all_delivery_region - OR FIND_IN_SET(PCRL.id_region_purchase, a_ids_delivery_region) > 0 - ) - ) PCRL - ON t_P.id_product <=> PCRL.id_product - AND t_P.id_permutation <=> PCRL.id_permutation - LEFT JOIN tmp_Delivery_Region t_DR - ON PCRL.id_region_purchase = t_DR.id_region - AND t_DR.requires_delivery_option = 1 - WHERE - ISNULL(t_DR.id_region) - ); - IF NOT ISNULL(v_ids_permutation_unavailable) THEN - INSERT INTO tmp_Msg_Error ( - guid, - id_type, - msg - ) - VALUES ( - v_guid, - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'PRODUCT_AVAILABILITY' LIMIT 1), - CONCAT('Error: The following permutation IDs are not available in this region: ', v_ids_permutation_unavailable) - ); - END IF; - /* - DELETE FROM tmp_Shop_Product t_P - WHERE t_P.id_permutation NOT IN ( - SELECT - id_permutation - FROM Shop_Product_Currency_Region_Link PCL - INNER JOIN tmp_Delivery_Region t_DR - ON PCRL.id_region_purchase = t_DR.id_region - ); - */ - END IF; - - -- select * from tmp_Shop_Product; - - -- Currencies - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid) THEN - INSERT INTO tmp_Currency ( - id_currency, - active, - display_order - ) - SELECT - C.id_currency, - C.active, - C.display_order - FROM Shop_Product_Currency_Region_Link PCRL - INNER JOIN Shop_Currency C ON PCRL.id_currency = C.id_currency - INNER JOIN tmp_Shop_Product t_P - ON PCRL.id_product <=> t_P.id_product - AND PCRL.id_permutation <=> t_P.id_permutation - INNER JOIN tmp_Delivery_Region t_DR ON PCRL.id_region_purchase = t_DR.id_region - WHERE - ( - a_get_all_currency - OR FIND_IN_SET(C.id_currency, a_ids_currency) > 0 - ) - AND ( - a_get_inactive_currency - OR ( - C.active - AND PCRL.active - ) - ) - ; - - -- select * from tmp_Currency; - - IF v_has_filter_currency THEN - SET v_ids_permutation_unavailable = ( - SELECT GROUP_CONCAT(t_P.id_permutation SEPARATOR ', ') - FROM ( - SELECT * - FROM tmp_Shop_Product t_P - WHERE - /*( - a_get_all_category - OR a_get_all_product - OR a_get_all_product_permutation - )*/ - FIND_IN_SET(t_P.id_category, a_ids_category) > 0 - OR FIND_IN_SET(t_P.id_product, a_ids_product) > 0 - OR FIND_IN_SET(t_P.id_permutation, a_ids_permutation) > 0 - ) t_P - INNER JOIN ( - SELECT * - FROM Shop_Product_Currency_Region_Link PCRL - WHERE - ( - a_get_all_currency - OR FIND_IN_SET(PCRL.id_currency, a_ids_currency) > 0 - ) - ) PCRL - ON t_P.id_permutation = PCRL.id_permutation - LEFT JOIN tmp_Currency t_C - ON PCRL.id_currency = t_C.id_currency - WHERE ISNULL(t_C.id_currency) - ); - IF NOT ISNULL(v_ids_permutation_unavailable) THEN - INSERT INTO tmp_Msg_Error ( - guid, - id_type, - msg - ) - VALUES ( - v_guid, - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'PRODUCT_AVAILABILITY' LIMIT 1), - CONCAT('Error: The following permutation IDs are not available in this currency: ', v_ids_permutation_unavailable) - ); - END IF; - /* - DELETE FROM tmp_Shop_Product t_P - WHERE t_P.id_permutation NOT IN ( - SELECT - id_permutation - FROM Shop_Product_Currency_Region_Link PCL - INNER JOIN tmp_Currency t_C - ON PCRL.id_currency = t_C.id_currency - ); - */ - END IF; - END IF; - - -- Discounts - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid) THEN - INSERT INTO tmp_Discount ( - id_discount, - active, - display_order - ) - SELECT - D.id_discount, - D.active, - D.display_order - FROM Shop_Discount D - INNER JOIN tmp_Shop_Product t_P - ON D.id_product = t_P.id_product - AND D.id_permutation <=> t_P.id_permutation - WHERE - ( - a_get_all_discount - OR FIND_IN_SET(D.id_discount, a_ids_discount) > 0 - ) - AND ( - a_get_inactive_discount - OR D.active - ) - ; - END IF; - -- select 'pre-permission results'; - -- select * from tmp_Shop_Product; - - -- Permissions - IF EXISTS (SELECT * FROM tmp_Shop_Product_Category LIMIT 1) THEN - -- SET v_id_user := (SELECT id_user FROM Shop_User WHERE name = CURRENT_USER()); - SET v_id_permission_product := (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_PRODUCT' LIMIT 1); - -- SET v_ids_product_permission := (SELECT GROUP_CONCAT(id_product SEPARATOR ',') FROM tmp_Shop_Product); - SET v_ids_permutation_permission := (SELECT GROUP_CONCAT(id_permutation SEPARATOR ',') FROM tmp_Shop_Product WHERE NOT ISNULL(id_permutation)); - - -- SELECT v_guid, a_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_permutation_permission; - -- select * from Shop_User_Eval_Temp; - - CALL p_shop_user_eval(v_guid, a_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_permutation_permission); - - -- select * from Shop_User_Eval_Temp; - - UPDATE tmp_Shop_Product t_P - INNER JOIN Shop_User_Eval_Temp UE_T - ON t_P.id_permutation = UE_T.id_permutation - AND UE_T.GUID = v_guid - SET t_P.can_view = UE_T.can_view, - t_P.can_edit = UE_T.can_edit, - t_P.can_admin = UE_T.can_admin; - - DELETE FROM tmp_Shop_Product t_P - WHERE - FIND_IN_SET(t_P.id_permutation, (SELECT GROUP_CONCAT(UET.id_permutation SEPARATOR ',') FROM Shop_User_Eval_Temp UET)) = 0 -- id_product NOT LIKE CONCAT('%', (SELECT GROUP_CONCAT(id_product SEPARATOR '|') FROM Shop_User_Eval_Temp), '%'); - OR ( - ISNULL(t_P.can_view) - AND ( - NOT v_has_filter_category - OR FIND_IN_SET(t_P.id_category, a_ids_category) = 0 - ) - AND ( - NOT v_has_filter_product - OR FIND_IN_SET(t_P.id_product, a_ids_product) = 0 - ) - AND ( - NOT v_has_filter_permutation - OR FIND_IN_SET(t_P.id_permutation, a_ids_permutation) = 0 - ) - ) - ; - - -- CALL p_shop_user_eval_clear_temp(v_guid); - -- DROP TABLE IF EXISTS Shop_User_Eval_Temp; - DELETE FROM Shop_User_Eval_Temp - WHERE GUID = v_guid - ; - END IF; - - - -- select * from tmp_Shop_Product; - - -- Returns - SET v_now := NOW(); - - -- Categories - SELECT - DISTINCT t_C.id_category, - C.name, - C.description, - C.display_order - FROM tmp_Shop_Product_Category t_C - INNER JOIN Shop_Product_Category C - ON t_C.id_category = C.id_category - INNER JOIN tmp_Shop_Product t_P - ON t_C.id_category = t_P.id_category - ORDER BY C.display_order - ; - - -- Products - SELECT - t_P.id_product, - t_P.id_permutation, - t_P.name, - t_P.description, - P.has_variations, - P.id_category, - t_P.latency_manufacture, - t_P.quantity_min, - t_P.quantity_max, - t_P.quantity_step, - t_P.quantity_stock, - t_P.id_stripe_product, - t_P.is_subscription, - RI.name AS name_interval_recurrence, - RI.name_plural AS name_plural_interval_recurrence, - t_P.count_interval_recurrence, - t_P.display_order_category, - t_P.display_order_product, - t_P.display_order_permutation, - IFNULL(t_P.can_view, 0), - IFNULL(t_P.can_edit, 0), - IFNULL(t_P.can_admin, 0) - FROM tmp_Shop_Product t_P - INNER JOIN Shop_Product P - ON t_P.id_product = P.id_product - LEFT JOIN Shop_Interval_Recurrence RI - ON t_P.id_unit_measurement_interval_recurrence = RI.id_interval - ORDER BY t_P.rank_permutation - ; - - -- Variations - SELECT - V.id_variation, - t_P.id_product, - t_P.id_permutation, - t_P.id_category, - VT.code AS code_variation_type, - VT.name AS name_variation_type, - V.code AS code_variation, - V.name AS name_variation, - RANK() OVER (ORDER BY t_P.rank_permutation, PPVL.display_order) AS display_order - FROM Shop_Variation V - INNER JOIN Shop_Variation_Type VT - ON V.id_type = VT.id_type - INNER JOIN Shop_Product_Permutation_Variation_Link PPVL ON V.id_variation = PPVL.id_variation - INNER JOIN tmp_Shop_Product t_P ON PPVL.id_permutation <=> t_P.id_permutation - WHERE V.active - AND PPVL.active - ; - - /* - -- Permutation variations output - SELECT t_P.id_permutation, - t_P.id_product, - t_P.id_category, - id_variation - FROM Shop_Product_Permutation_Variation_Link PPVL - INNER JOIN tmp_Shop_Product t_P - ON t_P.id_permutation = PPVL.id_permutation - ORDER BY t_P.display_order - ; - */ - -- select * from Shop_Product_Currency_Region_Link; - -- select * from shop_currency; - /* - select * from tmp_Currency; - select * from tmp_delivery_region; - select * from tmp_shop_product; - */ - - -- Product Price - SELECT - PCRL.id_link AS id_price, - t_P.id_permutation, - t_P.id_product, - t_P.id_category, - t_C.id_currency, - C.code AS code_currency, - C.name AS name_currency, - C.symbol AS symbol_currency, - t_DR.id_region, - PCRL.price_local_VAT_incl, - PCRL.price_local_VAT_excl, - ROW_NUMBER() OVER(ORDER BY t_P.rank_permutation, C.display_order) AS display_order - FROM Shop_Product_Currency_Region_Link PCRL - INNER JOIN tmp_Shop_Product t_P - ON PCRL.id_product <=> t_P.id_product - AND PCRL.id_permutation <=> t_P.id_permutation - -- INNER JOIN Shop_Product P ON PCRL.id_product = P.id_product - INNER JOIN tmp_Currency t_C ON PCRL.id_currency = t_C.id_currency - INNER JOIN Shop_Currency C ON t_C.id_currency = C.id_currency - INNER JOIN tmp_Delivery_Region t_DR ON PCRL.id_region_purchase = t_DR.id_region - WHERE ( - a_get_inactive_product - AND a_get_inactive_permutation - AND a_get_inactive_currency - AND a_get_inactive_delivery_region - OR PCRL.active - ) - ORDER BY t_P.rank_permutation - ; - - /* - -- Currency - SELECT - DISTINCT C.id_currency, - C.code, - C.name, - C.factor_from_GBP, - t_C.display_order - FROM Shop_Currency C - INNER JOIN tmp_Currency t_C ON C.id_currency = t_C.id_currency - GROUP BY C.id_currency, t_C.display_order - ORDER BY t_C.display_order - ; - */ - - -- Images - SELECT - t_I.id_image, - t_I.id_product, - t_I.id_permutation, - t_P.id_category, - I.url, - I.active, - I.display_order - FROM tmp_Shop_Image t_I - INNER JOIN Shop_Image I - ON t_I.id_image = I.id_image - INNER JOIN tmp_Shop_Product t_P - ON t_I.id_product = t_P.id_product - AND t_I.id_permutation <=> t_P.id_permutation - ORDER BY t_P.rank_permutation, I.display_order - ; - - -- Delivery options - SELECT - _DO.id_option, - PDOL.id_product, - PDOL.id_permutation, - t_P.id_category, - _DO.code, - _DO.name, - _DO.latency_delivery_min, - _DO.latency_delivery_max, - _DO.quantity_min, - _DO.quantity_max, - GROUP_CONCAT(DR.code SEPARATOR ',') AS codes_region, - GROUP_CONCAT(DR.name SEPARATOR ',') AS names_region, - PDOL.price_local, - PDOL.display_order - FROM Shop_Delivery_Option _DO - INNER JOIN Shop_Product_Delivery_Option_Link PDOL - ON _DO.id_option = PDOL.id_delivery_option - AND ( - a_get_inactive_delivery_region - OR PDOL.active - ) - INNER JOIN tmp_Shop_Product t_P - ON PDOL.id_product = t_P.id_product - AND PDOL.id_permutation <=> t_P.id_permutation - INNER JOIN tmp_Delivery_Region t_DR ON PDOL.id_region = t_DR.id_region - INNER JOIN Shop_Region DR ON t_DR.id_region = DR.id_region - WHERE ( - a_get_inactive_delivery_region - OR _DO.active - ) - GROUP BY t_P.id_category, t_P.id_product, PDOL.id_permutation, t_P.rank_permutation, DR.id_region, _DO.id_option, PDOL.id_link - ORDER BY t_P.rank_permutation, PDOL.display_order - ; - - -- Discounts - SELECT - D.id_discount, - P.id_category, - D.id_product, - D.id_permutation, - DR.id_region, - C.id_currency, - D.code AS code_discount, - D.name AS name_discount, - D.multiplier, - D.subtractor, - D.apply_multiplier_first, - D.quantity_min, - D.quantity_max, - D.date_start, - D.date_end, - GROUP_CONCAT(DR.code) AS codes_region, - GROUP_CONCAT(DR.name) AS names_region, - GROUP_CONCAT(C.code) AS codes_currency, - GROUP_CONCAT(C.name) AS names_currency, - ROW_NUMBER() OVER(ORDER BY D.display_order) AS display_order - FROM tmp_Discount t_D - INNER JOIN Shop_Discount D ON t_D.id_discount = D.id_discount - INNER JOIN Shop_Product P ON D.id_product = P.id_product - INNER JOIN tmp_Shop_Product t_P - ON D.id_product = t_P.id_product - -- AND D.id_permutation <=> t_P.id_permutation - INNER JOIN Shop_Discount_Region_Currency_Link DRCL - ON D.id_discount = DRCL.id_discount - INNER JOIN tmp_Delivery_Region t_DR ON DRCL.id_region = t_DR.id_region - INNER JOIN Shop_Region DR ON t_DR.id_region = DR.id_region - INNER JOIN tmp_Currency t_C ON DRCL.id_currency = t_C.id_currency - INNER JOIN Shop_Currency C ON t_C.id_currency = C.id_currency - GROUP BY D.id_discount, DR.id_region, C.id_currency - ORDER BY D.display_order, DR.display_order, C.display_order - ; - - /* - -- Delivery Regions - SELECT - t_DR.id_region, - t_P.id_category, - t_P.id_product, - t_P.id_permutation, - DR.code, - DR.name - FROM tmp_Delivery_Region t_DR - INNER JOIN Shop_Delivery_Region DR ON t_DR.id_region = DR.id_region - INNER JOIN Shop_Product_Region_Currency_Link PDRL - ON DR.id_region = PDRL.id_region - AND ( - a_get_inactive_delivery_region - OR PDRL.active - ) - INNER JOIN tmp_Shop_Product t_P - ON PDRL.id_product = t_P.id_product - AND PDRL.id_permutation <=> t_P.id_permutation - INNER JOIN tmp_Currency t_C ON PDRL.id_currency = t_C.id_currency - ORDER BY t_DR.display_order - ; - */ - - -- Errors - SELECT - t_ME.display_order, - t_ME.guid, - t_ME.id_type, - t_ME.msg, - MET.code, - MET.name, - MET.description - FROM tmp_Msg_Error t_ME - INNER JOIN Shop_Msg_Error_Type MET - ON t_ME.id_type = MET.id_type - WHERE guid = v_guid - ; - - /* - -- Return arguments for test - SELECT - a_ids_category, - a_get_inactive_category, - a_ids_product, - a_get_inactive_product, - a_get_first_product_only, - a_get_all_product, - a_ids_image, - a_get_inactive_image, - a_get_first_image_only, - a_get_all_image - ; - */ - - -- select 'other outputs'; - -- select * from tmp_Shop_Product; - - -- Clean up - DROP TABLE IF EXISTS tmp_Discount; - DROP TABLE IF EXISTS tmp_Currency; - DROP TABLE IF EXISTS tmp_Delivery_Region; - DROP TABLE IF EXISTS tmp_Shop_Image; - DROP TABLE IF EXISTS tmp_Shop_Variation; - DROP TABLE IF EXISTS tmp_Shop_Product; - DROP TABLE IF EXISTS tmp_Shop_Product_Category; -END ;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `p_shop_get_many_region` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `p_shop_get_many_region`( - IN a_get_inactive_region BIT -) -BEGIN - IF a_get_inactive_region IS NULL THEN - SET a_get_inactive_region = 0; - END IF; - - SELECT - R.id_region, - R.code, - R.name, - R.active, - R.display_order - FROM Shop_Region R - WHERE a_get_inactive_region - OR R.active - ORDER BY R.display_order - ; -END ;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `p_shop_get_many_stripe_price_new` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `p_shop_get_many_stripe_price_new`( - IN a_id_user INT -) -BEGIN - DECLARE v_has_filter_user BIT; - DECLARE v_code_error_data VARCHAR(200); - DECLARE v_code_error_permission VARCHAR(200); - DECLARE v_guid BINARY(36); - - SET v_code_error_data := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 1); - SET v_code_error_permission := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 2); - SET v_guid = UUID(); - - - - IF a_id_user IS NULL THEN - SET a_id_user = ''; - ELSE - SET a_id_user = TRIM(a_id_user); - END IF; - - - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Shop_Product_Currency_Link; - DROP TABLE IF EXISTS tmp_Shop_User; - - CREATE TABLE tmp_Shop_User( - id_user INT NOT NULL PRIMARY KEY, - CONSTRAINT FK_tmp_Shop_User_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user), - active BIT NOT NULL - ); - - CREATE TABLE tmp_Shop_Product_Currency_Link ( - id_link INT NOT NULL PRIMARY KEY, - CONSTRAINT FK_tmp_Shop_Product_Currency_Link_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Product_Currency_Link(id_link), - id_product INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_Currency_Link_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - id_permutation INT NULL, - CONSTRAINT FK_tmp_Shop_Product_Currency_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - id_currency INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_Currency_Link_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency), - active BIT NOT NULL - ); - - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( -- IF NOT EXISTS - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - guid BINARY(36) NOT NULL, - code VARCHAR(50) NOT NULL, - -- CONSTRAINT chk_tmp_Msg_Error_code CHECK (code IN (SELECT code FROM Shop_Msg_Error_Type)), - /* - id_type INT NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type(id_type), - */ - msg VARCHAR(4000) NOT NULL - ); - - - - -- Parse filters - SET v_has_filter_user = CASE WHEN a_id_user = '' THEN 0 ELSE 1 END; - - - - -- User permissions - IF v_has_filter_user THEN - INSERT INTO tmp_Shop_User ( - id_user, - active - ) - SELECT id_user, - active - FROM Shop_User - WHERE id_user LIKE CONCAT('%', a_id_user, '%') - AND active - LIMIT 1 - ; - - SET v_has_filter_user = EXISTS (SELECT id_user FROM tmp_Shop_User LIMIT 1); - SET a_id_user := (SELECT id_user FROM tmp_Shop_User LIMIT 1); - END IF; - IF NOT v_has_filter_user THEN - INSERT INTO tmp_Msg_Error ( - guid, - code, - msg - ) - VALUES ( - v_guid, - v_code_error_data, - 'Valid user ID not provided.' - ) - ; - END IF; - - -- Get products - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - INSERT INTO tmp_Shop_Product_Currency_Link ( - id_link, - id_product, - id_permutation, - id_currency, - active - ) - SELECT id_link, - id_product, - id_permutation, - id_currency, - active - FROM Shop_Product_Currency_Link - WHERE ISNULL(id_stripe_price) - AND active - ; - END IF; - - -- Permissions - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - -- SELECT * FROM tmp_Msg_Error LIMIT 1; - CALL p_shop_user_eval ( - v_guid, -- a_guid - a_id_user, -- a_id_user - 0, -- a_get_inactive_users - CONVERT((SELECT id_permission FROM Shop_Permission WHERE 'STORE_ADMIN' = code), CHAR), -- a_ids_permission - (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'ADMIN' AND active), -- a_ids_access_level - (SELECT GROUP_CONCAT(DISTINCT id_product SEPARATOR ',') FROM tmp_Shop_Product_Currency_Link), -- (SELECT DISTINCT id_product FROM tmp_Shop_Product_Currency_Link) calc_PCL) -- a_ids_product - (SELECT GROUP_CONCAT(DISTINCT id_permutation SEPARATOR ',') FROM tmp_Shop_Product_Currency_Link) -- a_ids_permutation - ); - -- SELECT * FROM tmp_Msg_Error LIMIT 1; - - IF EXISTS (SELECT can_admin FROM Shop_User_Eval_Temp WHERE guid = v_guid AND NOT can_admin LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - guid, - code, - msg - ) - VALUES ( - v_guid, - v_code_error_permission, - 'User ID does not have permission to get all new stripe prices.' - ) - ; - END IF; - - DELETE FROM Shop_User_Eval_Temp - WHERE guid = v_guid - ; - END IF; - - - - -- Returns - IF EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - DELETE FROM tmp_Shop_Product_Currency_Link; - END IF; - /* - SELECT * - FROM tmp_Shop_User - ; - */ - - - SELECT t_PCL.id_product, - t_PCL.id_permutation, - P.price_GBP_full * C.factor_from_GBP AS unit_price, - C.code AS code_currency, - P.id_stripe_product, - P.is_subscription, - LOWER(RI.code) AS name_recurring_interval, - P.count_interval_recurrence - FROM tmp_Shop_Product_Currency_Link t_PCL - INNER JOIN Shop_Product P - ON t_PCL.id_product = P.id_product - AND P.active - INNER JOIN Shop_Interval_Recurrence RI - ON P.id_unit_measurement_interval_recurrence = RI.id_interval - AND RI.active - INNER JOIN Shop_Currency C - ON t_PCL.id_currency = C.id_currency - AND C.active - WHERE t_PCL.active - ; - - - -- Errors - SELECT * - FROM tmp_Msg_Error - WHERE guid = v_guid - ; - - - /* - -- Return arguments for test - SELECT - a_id_user - ; - */ - - -- Clean up - DROP TABLE IF EXISTS tmp_Shop_User; - DROP TABLE IF EXISTS tmp_Shop_Product_Currency_Link; -END ;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `p_shop_get_many_stripe_product_new` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `p_shop_get_many_stripe_product_new`( - IN a_id_user INT -) -BEGIN - DECLARE v_has_filter_user BIT; - DECLARE v_code_error_data VARCHAR(200); - DECLARE v_code_error_permission VARCHAR(200); - DECLARE v_guid BINARY(36); - - SET v_code_error_data := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 1); - SET v_code_error_permission := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 2); - SET v_guid = UUID(); - - - IF a_id_user IS NULL THEN - SET a_id_user = ''; - ELSE - SET a_id_user = TRIM(a_id_user); - END IF; - - - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Shop_Product; - DROP TABLE IF EXISTS tmp_Shop_User; - - CREATE TABLE tmp_Shop_User( - id_user INT NOT NULL PRIMARY KEY, - CONSTRAINT FK_tmp_Shop_User_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user), - active BIT NOT NULL - ); - - CREATE TABLE tmp_Shop_Product ( - id_product INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - id_permutation INT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - active BIT NOT NULL, - display_order_product INT NOT NULL, - display_order_permutation INT NOT NULL, - name VARCHAR(200) NOT NULL, - description VARCHAR(4000) NOT NULL - ); - - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( -- IF NOT EXISTS - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - guid BINARY(36) NOT NULL, - code VARCHAR(50) NOT NULL, - -- CONSTRAINT chk_tmp_Msg_Error_code CHECK (code IN (SELECT code FROM Shop_Msg_Error_Type)), - /* - id_type INT NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type(id_type), - */ - msg VARCHAR(4000) NOT NULL - ); - - - - -- Parse filters - SET v_has_filter_user = CASE WHEN a_id_user = '' THEN 0 ELSE 1 END; - - - - -- User - IF v_has_filter_user THEN - INSERT INTO tmp_Shop_User ( - id_user, - active - ) - SELECT id_user, - active - FROM Shop_User - WHERE id_user LIKE CONCAT('%', a_id_user, '%') - AND active - LIMIT 1 - ; - - SET v_has_filter_user = EXISTS (SELECT id_user FROM tmp_Shop_User LIMIT 1); - SET a_id_user := (SELECT id_user FROM tmp_Shop_User LIMIT 1); - END IF; - - IF NOT v_has_filter_user THEN - INSERT INTO tmp_Msg_Error ( - guid, - code, - msg - ) - VALUES ( - v_guid, - v_code_error_data, - 'User ID not valid.' - ) - ; - END IF; - - -- Get products - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - INSERT INTO tmp_Shop_Product ( - id_product, - id_permutation, - active, - display_order_product, - display_order_permutation, - name, - description - ) - SELECT id_product, - id_permutation, - active, - display_order_product, - display_order_permutation, - name, - description - FROM ( - SELECT id_product, - NULL AS id_permutation, - active, - display_order AS display_order_product, - NULL AS display_order_permutation, - name, - description, - id_stripe_product - FROM Shop_Product P - UNION - SELECT t_PPPV.id_product, - id_permutation, - t_PPPV.active, - display_order_product, - display_order_permutation, - CONCAT(P.name, ': ', names_variation) AS name, - CONCAT(P.description, ' With variations: ', type_name_pairs_variation) AS description, - t_PPPV.id_stripe_product - FROM ( - SELECT P.id_product, - PP.id_permutation, - PP.active, - P.display_order AS display_order_product, - PP.display_order AS display_order_permutation, - GROUP_CONCAT(V.name SEPARATOR ' ') AS names_variation, - GROUP_CONCAT(CONCAT(VT.name, ': ', V.name) SEPARATOR ', ') AS type_name_pairs_variation, - PP.id_stripe_product - FROM Shop_Product_Permutation PP - INNER JOIN Shop_Product P - ON PP.id_product = P.id_product - AND P.active - INNER JOIN Shop_Product_Permutation_Variation_Link PPVL - ON PP.id_permutation = PPVL.id_permutation - AND PPVL.active - INNER JOIN Shop_Variation V - ON PPVL.id_variation = V.id_variation - AND V.active - INNER JOIN Shop_Variation_Type VT - ON V.id_type = VT.id_type - AND VT.active - GROUP BY id_product, id_permutation -- , VT.id_type, V.id_variation - ) t_PPPV - INNER JOIN Shop_Product P - ON t_PPPV.id_product = P.id_product - ) t_PPP - WHERE ISNULL(id_stripe_product) - AND active - ; - END IF; - - -- Permissions - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - CALL p_shop_user_eval ( - v_guid, -- a_guid - a_id_user, -- a_id_user - 0, -- a_get_inactive_users - CONVERT((SELECT id_permission FROM Shop_Permission WHERE 'STORE_ADMIN' = code), CHAR), -- a_ids_permission - (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'ADMIN' AND active), -- a_ids_access_level - (SELECT GROUP_CONCAT(id_product SEPARATOR ',') From tmp_Shop_Product), -- a_ids_product - (SELECT GROUP_CONCAT(id_permutation SEPARATOR ',') From tmp_Shop_Product) -- a_ids_permutation -- WHERE NOT ISNULL(id_permutation) - ); - - IF EXISTS (SELECT can_admin FROM Shop_User_Eval_Temp WHERE guid = v_guid AND NOT can_admin) THEN - INSERT INTO tmp_Msg_Error ( - guid, - code, - msg - ) - VALUES ( - v_guid, - v_code_error_permission, - 'User ID does not have permission to get all new stripe products.' - ) - ; - END IF; - - DELETE FROM Shop_User_Eval_Temp - WHERE guid = v_guid - ; - END IF; - - - - - -- Returns - /* - SELECT * - FROM tmp_Shop_User - ; - */ - - IF EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - DELETE FROM tmp_Shop_Product; - END IF; - - SELECT id_product, - id_permutation, - name, - description - FROM tmp_Shop_Product - ORDER BY display_order_product, display_order_permutation - ; - SELECT PP.id_permutation, - V.id_variation, - V.name AS name_variation, - VT.id_type AS id_type_variation, - VT.name as name_variation_type - FROM tmp_Shop_Product t_P - INNER JOIN Shop_Product_Permutation PP - ON t_P.id_permutation = PP.id_permutation - INNER JOIN Shop_Product_Permutation_Variation_Link PPVL - ON PP.id_permutation = PPVL.id_permutation - AND PPVL.active - INNER JOIN Shop_Variation V - ON PPVL.id_variation = V.id_variation - AND V.active - INNER JOIN Shop_Variation_Type VT - ON V.id_type = VT.id_type - AND VT.active - ; - - - -- Errors - SELECT * - FROM tmp_Msg_Error - WHERE guid = v_guid - ; - - - /* - -- Return arguments for test - SELECT - a_id_user - ; - */ - - -- Clean up - DROP TABLE IF EXISTS tmp_Shop_Product; - DROP TABLE IF EXISTS tmp_Shop_User; -END ;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `p_shop_get_many_user_order` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `p_shop_get_many_user_order`( - IN a_id_user INT, - IN a_ids_order VARCHAR(4000), - IN a_n_order_max INT, - IN a_id_checkout_session VARCHAR(200) -) -BEGIN - -- Argument redeclaration - -- Variable declaration - DECLARE v_has_filter_user BIT; - DECLARE v_has_filter_order BIT; - DECLARE v_has_filter_session BIT; - DECLARE v_code_error_data VARCHAR(200); - DECLARE v_code_error_permission VARCHAR(200); - DECLARE v_guid BINARY(36); - - SET v_code_error_data := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 1); - SET v_code_error_permission := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 2); - SET v_guid = UUID(); - - -- Argument validation + default values - IF a_id_user IS NULL THEN - SET a_id_user = ''; - ELSE - SET a_id_user = TRIM(a_id_user); - END IF; - IF a_ids_order IS NULL THEN - SET a_ids_order = ''; - ELSE - SET a_ids_order = TRIM(a_ids_order); - END IF; - IF a_n_order_max IS NULL THEN - SET a_n_order_max = 1; - END IF; - IF a_id_checkout_session IS NULL THEN - SET a_id_checkout_session = ''; - ELSE - SET a_id_checkout_session = TRIM(a_id_checkout_session); - END IF; - - - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Shop_User; - DROP TABLE IF EXISTS tmp_Shop_Order; - - CREATE TABLE tmp_Shop_User( - id_user INT NOT NULL PRIMARY KEY, - CONSTRAINT FK_tmp_Shop_User_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user), - active BIT NOT NULL - ); - - CREATE TABLE tmp_Shop_Order ( - id_order INT NOT NULL PRIMARY KEY, - CONSTRAINT FK_tmp_Shop_Order_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_User_Order(id_order), - active BIT NOT NULL - ); - - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - guid BINARY(36) NOT NULL, - -- id_type INT NOT NULL, - -- CONSTRAINT FK_tmp_Msg_Error_id_type FOREIGN KEY (id_type) - -- REFERENCES Shop_Msg_Error_Type (id_type), - code VARCHAR(50), - msg VARCHAR(4000) NOT NULL - ); - - - -- Parse filters - SET v_has_filter_user = CASE WHEN a_id_user = '' THEN 0 ELSE 1 END; - SET a_ids_order = REPLACE(a_ids_order, '|', ','); - SET v_has_filter_order = CASE WHEN a_ids_order = '' THEN 0 ELSE 1 END; - SET v_has_filter_session = CASE WHEN a_id_checkout_session = '' THEN 0 ELSE 1 END; - - -- User - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error LIMIT 1) THEN - IF v_has_filter_user THEN - INSERT INTO tmp_Shop_User ( - id_user, - active - ) - SELECT id_user, - active - FROM Shop_User - WHERE id_user LIKE CONCAT('%', a_id_user, '%') - AND active - LIMIT 1 - ; - - SET v_has_filter_user = EXISTS (SELECT id_user FROM tmp_Shop_User LIMIT 1); - SET a_id_user := (SELECT id_user FROM tmp_Shop_User LIMIT 1); - END IF; - END IF; - IF NOT v_has_filter_user THEN - INSERT INTO tmp_Msg_Error ( - guid, - code, - msg - ) - VALUES ( - v_guid, - v_code_error_data, - 'User ID not valid.' - ) - ; - END IF; - - -- Permissions - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - CALL p_shop_user_eval ( - v_guid, -- a_guid - a_id_user, -- a_id_user - 0, -- a_get_inactive_users - CONVERT((SELECT id_permission FROM Shop_Permission WHERE 'STORE_USER' = code), CHAR), -- a_ids_permission - (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW' AND active), -- a_ids_access_level - '', -- a_ids_product - '' -- a_ids_permutation - ); - - IF NOT (SELECT can_edit FROM Shop_User_Eval_Temp WHERE guid = v_guid) THEN - INSERT INTO tmp_Msg_Error ( - guid, - code, - msg - ) - VALUES ( - v_guid, - v_code_error_permission, - 'User ID does not have permission to access orders.' - ) - ; - END IF; - - DELETE FROM Shop_User_Eval_Temp - WHERE guid = v_guid - ; - END IF; - - -- Invalid Orders - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - -- Invalid Order IDs - IF EXISTS (SELECT * FROM Shop_User_Order WHERE NOT (id_user = a_id_user) AND v_has_filter_order AND FIND_IN_SET(id_order, a_ids_order) > 0) THEN -- id_order LIKE CONCAT('%', a_ids_order, '%') LIMIT 1) THEN - INSERT INTO tmp_Msg_Error ( - guid, - code, - msg - ) - VALUES ( - v_guid, - v_code_error_data, - CONCAT('You do not have access to the following order IDs: ', (SELECT GROUP_CONCAT(id_order SEPARATOR ', ') FROM Shop_User_Order WHERE NOT (id_user = a_id_user) AND FIND_IN_SET(id_order, a_ids_order) > 0)) -- id_order LIKE CONCAT('%', a_ids_order, '%'))) -- AND v_has_filter_order -- filtered by parent condition - ) - ; - END IF; - -- Invalid Checkout Session IDs - IF EXISTS (SELECT * FROM Shop_User_Order WHERE NOT (id_user = a_id_user) AND v_has_filter_session AND id_checkout_session = a_id_checkout_session) THEN - INSERT INTO tmp_Msg_Error ( - guid, - code, - msg - ) - VALUES ( - v_guid, - v_code_error_data, - CONCAT('You do not have access to the following checkout session IDs: ', (SELECT GROUP_CONCAT(id_order SEPARATOR ', ') FROM Shop_User_Order WHERE NOT (id_user = a_id_user) AND id_checkout_session = a_id_checkout_session)) -- AND v_has_filter_order -- filtered by parent condition - ) - ; - END IF; - END IF; - - -- Valid Orders - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - - INSERT INTO tmp_Shop_Order ( - id_order, - active - ) - SELECT UO.id_order, - UO.active - FROM Shop_User_Order UO - INNER JOIN tmp_Shop_User t_U - ON UO.id_user = t_U.id_user - AND t_U.active - WHERE ((NOT v_has_filter_order OR FIND_IN_SET(UO.id_order, a_ids_order) > 0) -- UO.id_order LIKE CONCAT('%', a_ids_order, '%')) - OR (NOT v_has_filter_session OR UO.id_checkout_session = a_id_checkout_session)) - AND UO.active - ; - END IF; - - - - -- Returns - /* - SELECT * - FROM tmp_Shop_User - ; - */ - - SELECT t_O.id_order, - UOPL.id_product, - UOPL.id_permutation, - UOPL.quantity - FROM tmp_Shop_Order t_O - INNER JOIN Shop_User_Order UO - ON t_O.id_order = UO.id_order - INNER JOIN Shop_User_Order_Product_Link UOPL - ON UO.id_order = UOPL.id_order - WHERE t_O.active - ; - - - -- Errors - SELECT * - FROM tmp_Msg_Error - WHERE guid = v_guid - ; - - - /* - -- Return arguments for test - SELECT - a_id_user, - a_ids_order, - a_n_order_max, - a_id_checkout_session - ; - */ - - -- Clean up - DROP TABLE IF EXISTS tmp_Shop_User; - DROP TABLE IF EXISTS tmp_Shop_Order; -END ;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `p_shop_user_eval` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `p_shop_user_eval`( - IN a_guid BINARY(36), - IN a_id_user INT, - IN a_get_inactive_users BIT, - IN a_ids_permission VARCHAR(500), - IN a_ids_access_level VARCHAR(100), - IN a_ids_permutation VARCHAR(4000) -) -BEGIN - -- Variable declaration - DECLARE v_has_filter_permission BIT; - DECLARE v_has_filter_user BIT; - DECLARE v_has_filter_access_level BIT; - DECLARE v_has_filter_permutation BIT; - DECLARE v_id_permission_product INT; - DECLARE v_id_permission INT; - -- DECLARE v_ids_product VARCHAR(500); - DECLARE v_id_access_level_view INT; - -- DECLARE v_id_access_level_product_required INT; - DECLARE v_priority_access_level_view INT; - DECLARE v_priority_access_level_edit INT; - DECLARE v_priority_access_level_admin INT; - DECLARE v_id_access_level INT; - DECLARE v_priority_access_level INT; - DECLARE v_now DATETIME; - DECLARE v_ids_row_delete VARCHAR(500); - DECLARE v_code_error_data VARCHAR(200); - DECLARE v_id_error_data INT; - DECLARE v_code_error_permission VARCHAR(200); - - SET v_id_error_data = 1; - SET v_code_error_data := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = v_id_error_data); - - SET v_code_error_permission := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 2); - - -- Clear previous proc results - -- DROP TABLE IF EXISTS tmp_User_Role_Link; - -- DROP TEMPORARY TABLE IF EXISTS tmp_User_Role_Link; - DROP TABLE IF EXISTS tmp_Shop_Product_p_Shop_User_Eval; - -- DROP TABLE IF EXISTS Shop_User_Eval_Temp; - - - -- Parse arguments + get default values - /* - IF a_guid IS NULL THEN - SET a_guid = UUID(); - END IF; - */ - IF a_id_user IS NULL THEN - SET a_id_user = ''; - ELSE - SET a_id_user = TRIM(a_id_user); - END IF; - IF a_get_inactive_users IS NULL THEN - SET a_get_inactive_users = 0; - END IF; - /* - IF a_get_user_permissions IS NULL THEN - SET a_get_user_permissions = 0; - END IF; - */ - IF a_ids_permission IS NULL THEN - SET a_ids_permission = ''; - ELSE - SET a_ids_permission = TRIM(a_ids_permission); - END IF; - IF a_ids_access_level IS NULL THEN - SET a_ids_access_level = ''; - ELSE - SET a_ids_access_level = TRIM(a_ids_access_level); - END IF; - IF a_ids_permutation IS NULL THEN - SET a_ids_permutation = ''; - ELSE - SET a_ids_permutation = TRIM(a_ids_permutation); - END IF; - - -- Permanent Table - CREATE TABLE IF NOT EXISTS Shop_User_Eval_Temp ( - id_row INT PRIMARY KEY AUTO_INCREMENT NOT NULL, - guid BINARY(36) NOT NULL, - id_user INT, - id_permission_required INT NOT NULL, - CONSTRAINT FK_Shop_User_Eval_Temp_id_permission_required - FOREIGN KEY (id_permission_required) - REFERENCES Shop_Permission (id_permission), - /* - id_access_level_required INT NOT NULL, - CONSTRAINT FK_Shop_User_Eval_Temp_id_access_level_required - FOREIGN KEY (id_access_level_required) - REFERENCES Shop_Access_Level (id_access_level), - */ - priority_access_level_required INT NOT NULL, - /* - CONSTRAINT FK_Shop_User_Eval_Temp_priority_access_level_required - FOREIGN KEY (priority_access_level_required) - REFERENCES Shop_Access_Level (priority), - */ - id_product INT NULL, - CONSTRAINT FK_Shop_User_Eval_Temp_id_product - FOREIGN KEY (id_product) - REFERENCES partsltd_prod.Shop_Product (id_product), - id_permutation INT NULL, - CONSTRAINT FK_Shop_User_Eval_Temp_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES partsltd_prod.Shop_Product_Permutation (id_permutation), - is_super_user BIT NULL, - priority_access_level_user INT NULL, - /* - CONSTRAINT FK_Shop_User_Eval_Temp_priority_access_level_minimum - FOREIGN KEY (priority_access_level_minimum) - REFERENCES Shop_Access_Level (priority) - */ - can_view BIT, - can_edit BIT, - can_admin BIT -- DEFAULT 0 - ); - - CREATE TABLE IF NOT EXISTS tmp_Shop_Product_p_Shop_User_Eval ( - id_row INT PRIMARY KEY AUTO_INCREMENT NOT NULL, - id_product INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_p_Shop_User_Eval_id_product FOREIGN KEY (id_product) - REFERENCES partsltd_prod.Shop_Product (id_product), - id_permutation INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_p_Shop_User_Eval_id_permutation FOREIGN KEY (id_permutation) - REFERENCES partsltd_prod.Shop_Product_Permutation (id_permutation), - id_access_level_required INT NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_p_Shop_User_Eval_id_access_level_required FOREIGN KEY (id_access_level_required) - REFERENCES Shop_Access_Level (id_access_level), - guid BINARY(36) NOT NULL, - rank_permutation INT NOT NULL - ); - - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - guid BINARY(36) NOT NULL, - id_type INT NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type (id_type), - code VARCHAR(50), - msg VARCHAR(4000) NOT NULL - ); - - -- select * from Shop_Msg_Error_Type; - - -- Parse filters - IF a_guid IS NULL OR EXISTS (SELECT * FROM Shop_User_Eval_Temp WHERE a_guid = guid) THEN - INSERT INTO tmp_Msg_Error ( - guid, - code, - msg - ) - VALUES ( - a_guid, - v_code_error_data, - 'Invalid guid argument.' - ) - ; - END IF; - SET v_has_filter_user = CASE WHEN a_id_user = '' THEN 0 ELSE 1 END; - SET a_ids_permission = REPLACE(a_ids_permission, '|', ','); - SET v_has_filter_permission = CASE WHEN a_ids_permission = '' THEN 0 ELSE 1 END; - SET a_ids_access_level = REPLACE(a_ids_access_level, '|', ','); - SET v_has_filter_access_level = CASE WHEN a_ids_access_level = '' THEN 0 ELSE 1 END; - SET a_ids_permutation = REPLACE(a_ids_permutation, '|', ','); - SET v_has_filter_permutation = CASE WHEN a_ids_permutation = '' THEN 0 ELSE 1 END; - SET v_id_access_level_view = (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW' LIMIT 1); - SET v_priority_access_level_view = (SELECT priority FROM Shop_Access_Level WHERE id_access_level = v_id_access_level_view); - SET v_priority_access_level_edit = (SELECT priority FROM Shop_Access_Level WHERE code = 'EDIT' LIMIT 1); - SET v_priority_access_level_admin = (SELECT priority FROM Shop_Access_Level WHERE code = 'ADMIN' LIMIT 1); - - /* - select v_priority_access_level_view, - v_priority_access_level_edit, - v_priority_access_level_admin - ; - */ - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE GUID = a_guid) THEN - IF v_has_filter_access_level THEN - CALL p_split(a_ids_access_level, ','); - SET v_id_access_level := ( - SELECT AL.id_access_level - FROM Split_Temp ST - INNER JOIN Shop_Access_Level AL - ON CONVERT(ST.substring, DECIMAL(10,0)) = AL.id_access_level - AND AL.active - ORDER BY AL.priority ASC - LIMIT 1 - ); - DROP TABLE Split_Temp; - IF 0 = v_id_access_level OR v_id_access_level <=> NULL THEN - -- SET v_has_filter_access_level = 0; - INSERT INTO tmp_Msg_Error ( - guid, - code, - msg - ) - VALUES ( - a_guid, - v_code_error_data, - 'Access level ID not found.' - ) - ; - END IF; - /* - END IF; - IF NOT v_has_filter_access_level THEN - */ - ELSE - SET v_id_access_level = v_id_access_level_view; - END IF; - END IF; - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE GUID = a_guid) THEN - IF v_has_filter_permutation THEN - INSERT INTO tmp_Shop_Product_p_Shop_User_Eval ( - id_product, - id_permutation, - id_access_level_required, - guid, - rank_permutation - ) - SELECT - PP.id_product, - PP.id_permutation, - PP.id_access_level_required, - a_guid, - RANK() OVER (ORDER BY PP.id_product, PP.id_permutation, AL.priority) AS rank_permutation - FROM Shop_Product_Permutation PP - INNER JOIN Shop_Access_Level AL - ON PP.id_access_level_required = AL.id_access_level - AND AL.active - WHERE FIND_IN_SET(PP.id_permutation, a_ids_permutation) > 0 - -- AND P.active -- not worried as we want users to be able to see their order history - ; - /* - DELETE FROM tmp_Shop_Product_p_Shop_User_Eval - WHERE rank_permutation > 1 - ; - */ - SET v_has_filter_permutation = EXISTS (SELECT * FROM tmp_Shop_Product_p_Shop_User_Eval WHERE a_guid = guid); - END IF; - - IF v_has_filter_permission THEN - -- Invalid permission IDs - IF EXISTS (SELECT id_permission FROM Shop_Permission WHERE FIND_IN_SET(id_permission, a_ids_permission) > 0 AND NOT active) THEN - INSERT INTO tmp_Msg_Error ( - guid, - code, - msg - ) - VALUES ( - a_guid, - v_code_error_data, - CONCAT('The following permissions are no longer active: ', (SELECT GROUP_CONCAT(name SEPARATOR ', ') FROM Shop_Permission WHERE FIND_IN_SET(id_permission, a_ids_permission) > 0 AND NOT active)) - ) - ; - END IF; - END IF; - END IF; - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE GUID = a_guid) THEN - IF v_has_filter_user THEN - SET a_id_user := (SELECT id_user FROM Shop_User WHERE id_user LIKE a_id_user AND active); - SET v_has_filter_user = NOT (a_id_user <=> NULL); - IF NOT v_has_filter_user THEN - INSERT INTO tmp_Msg_Error ( - guid, - code, - msg - ) - VALUES ( - a_guid, - v_code_error_data, - 'User ID not found.' - ) - ; - END IF; - END IF; - END IF; - - -- Get users - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE GUID = a_guid) THEN - INSERT INTO Shop_User_Eval_Temp ( - guid, - id_user, - id_permission_required, - priority_access_level_required - /* - priority_access_level_user, - is_super_user, - can_view, - can_edit, - can_admin - */ - ) - SELECT a_guid, - a_id_user, - P.id_permission, - AL.priority - FROM partsltd_prod.Shop_Permission P - INNER JOIN Shop_Access_Level AL - ON P.id_access_level_required = AL.id_access_level - AND AL.active - WHERE FIND_IN_SET(P.id_permission, a_ids_permission) > 0 - ; - - IF v_has_filter_permutation THEN - SET v_ids_row_delete := (SELECT GROUP_CONCAT(id_row SEPARATOR ',') FROM Shop_User_Eval_Temp WHERE a_guid = guid); - - INSERT INTO Shop_User_Eval_Temp ( - guid, - id_user, - id_permission_required, - id_product, - id_permutation, - priority_access_level_required - ) - SELECT UE_T.guid, - UE_T.id_user, - UE_T.id_permission_required, - t_P.id_product, - t_P.id_permutation, - CASE WHEN UE_T.priority_access_level_required < AL.priority THEN UE_T.priority_access_level_required ELSE AL.priority END -- UE_T.priority_access_level_required - FROM tmp_Shop_Product_p_Shop_User_Eval t_P - INNER JOIN Shop_Access_Level AL - ON t_P.id_access_leveL_required = AL.id_access_level - AND AL.active - CROSS JOIN Shop_User_Eval_Temp UE_T - ON a_id_user = UE_T.id_user - WHERE a_guid = t_P.guid - ; - - DELETE FROM Shop_User_Eval_Temp - WHERE FIND_IN_SET(id_row, v_ids_row_delete) > 0 - ; - END IF; - - /* - INSERT INTO Shop_User_Eval_Temp ( - guid, - id_user, - id_permission_required, - -- id_access_level_required, - priority_access_level_required, - priority_access_level_user, - is_super_user - /* - can_view, - can_edit, - can_admin - * - ) - SELECT a_guid, - U.id_user, - P.id_permission, - AL.priority, - /* - v_id_permission, - v_id_access_level, - * - MIN(AL.priority), - U.is_super_user - /* - CASE WHEN U.is_super_user THEN 1 ELSE CASE WHEN priority_access_level_minimum <= v_priority_access_level_view THEN 1 ELSE 0 END END, - CASE WHEN U.is_super_user THEN 1 ELSE CASE WHEN priority_access_level_minimum <= v_priority_access_level_edit THEN 1 ELSE 0 END END, - CASE WHEN U.is_super_user THEN 1 ELSE CASE WHEN priority_access_level_minimum <= v_priority_access_level_admin THEN 1 ELSE 0 END END - * - FROM partsltd_prod.Shop_User U - INNER JOIN Shop_User_Role_Link URL - ON U.id_user = URL.id_user - AND URL.active - INNER JOIN Shop_Role_Permission_Link RPL - ON URL.id_role = RPL.id_role - AND RPL.active - INNER JOIN Shop_Permission P - ON RPL.id_permission = P.id_permission - AND P.active - INNER JOIN Shop_Access_Level AL - ON RPL.id_access_level = AL.id_access_level - AND AL.active - WHERE U.id_user = a_id_user - AND (a_get_inactive_users OR U.active) - AND FIND_IN_SET(P.id_permission, a_ids_permission) > 0 - -- AND v_id_permission = P.id_permission - -- AND v_id_access_level = AL.id_access_leveld - GROUP BY U.id_user, P.id_permission -- , is_super_user - ; - */ - - IF v_has_filter_user THEN - UPDATE Shop_User_Eval_Temp UE_T - INNER JOIN Shop_User U - ON UE_T.id_user = U.id_user - AND U.active - INNER JOIN Shop_User_Role_Link URL - ON U.id_user = URL.id_user - AND URL.active - INNER JOIN Shop_Role_Permission_Link RPL - ON URL.id_role = RPL.id_role - AND RPL.active - INNER JOIN Shop_Access_Level AL - ON RPL.id_access_level = AL.id_access_level - AND AL.active - SET UE_T.priority_access_level_user = AL.priority, - UE_T.is_super_user = U.is_super_user, - UE_T.can_view = CASE WHEN U.is_super_user THEN 1 ELSE CASE WHEN ISNULL(AL.priority) THEN 1 ELSE CASE WHEN AL.priority <= v_priority_access_level_view AND AL.priority <= UE_T.priority_access_level_required THEN 1 ELSE 0 END END END, - UE_T.can_edit = CASE WHEN U.is_super_user THEN 1 ELSE CASE WHEN NOT ISNULL(AL.priority) AND AL.priority <= v_priority_access_level_edit AND AL.priority <= UE_T.priority_access_level_required THEN 1 ELSE 0 END END, - UE_T.can_admin = CASE WHEN U.is_super_user THEN 1 ELSE CASE WHEN NOT ISNULL(AL.priority) AND AL.priority <= v_priority_access_level_admin AND AL.priority <= UE_T.priority_access_level_required THEN 1 ELSE 0 END END - WHERE UE_T.guid = a_guid - AND UE_T.id_user = a_id_user - AND RPL.id_permission = UE_T.id_permission_required - -- GROUP BY UE_T.id_user - ; - ELSE - UPDATE Shop_User_Eval_Temp UE_T - SET UE_T.priority_access_level_user = v_priority_access_level_view, - UE_T.is_super_user = 0, - UE_T.can_view = (v_priority_access_level_view <= UE_T.priority_access_level_required), - UE_T.can_edit = 0, - UE_T.can_admin = 0 - WHERE UE_T.guid = a_guid - AND UE_T.id_user = a_id_user - -- GROUP BY UE_T.id_user - ; - END IF; - END IF; - - -- Clean up - DROP TABLE IF EXISTS tmp_Shop_Product_p_Shop_User_Eval; - -- DROP TEMPORARY TABLE IF EXISTS tmp_User_Role_Link; - -- DROP TABLE IF EXISTS tmp_Msg_Error; -END ;; -DELIMITER ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; - -/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; -/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; -/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; -/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; -/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; - --- Dump completed on 2024-04-28 19:04:05 diff --git a/static/MySQL/file_list.txt b/static/MySQL/file_list.txt deleted file mode 100644 index c987460e..00000000 --- a/static/MySQL/file_list.txt +++ /dev/null @@ -1,221 +0,0 @@ -0001_destroy.sql -1000_tbl_Shop_Product_Change_Set.sql -1000_tbl_Split_Temp.sql -1001_tbl_Shop_User_Change_Set.sql -1001_tbl_Split_Key_Value_Pair_Csv_Temp.sql -1002_tbl_Shop_Sales_And_Purchasing_Change_Set.sql -1003_tbl_Shop_Access_Level.sql -1004_tbl_Shop_Access_Level_Audit.sql -1005_tbl_Msg_Error_Type.sql -1010_tbl_File_Type.sql -1011_tbl_File_Type_Audit.sql -1012_tbl_Shop_General.sql -1013_tbl_Shop_General_Audit.sql -1014_tbl_Shop_Image_Type.sql -1015_tbl_Shop_Image_Type_Audit.sql -1100_tbl_Shop_Region.sql -1101_tbl_Shop_Region_Audit.sql -1102_tbl_Shop_Region_Temp.sql -1103_tbl_Shop_Region_Branch.sql -1104_tbl_Shop_Region_Branch_Audit.sql -1105_tbl_Shop_Region_Branch_Temp.sql -1106_tbl_Shop_Address.sql -1106_tbl_Shop_Plant.sql -1107_tbl_Shop_Address_Audit.sql -1107_tbl_Shop_Plant_Audit.sql -1108_tbl_Shop_Plant_Temp.sql -1109_tbl_Shop_Storage_Location.sql -1110_tbl_Shop_Storage_Location_Audit.sql -1111_tbl_Shop_Storage_Location_Temp.sql -1112_tbl_Shop_Storage_Location_Branch.sql -1113_tbl_Shop_Storage_Location_Branch_Audit.sql -1114_tbl_Shop_Storage_Location_Branch_Temp.sql -1115_tbl_Shop_Currency.sql -1116_tbl_Shop_Currency_Audit.sql -1117_tbl_Shop_Currency_Temp.sql -1118_tbl_Shop_Tax_Or_Surcharge.sql -1119_tbl_Shop_Tax_Or_Surcharge_Audit.sql -1120_tbl_Shop_Tax_Or_Surcharge_Temp.sql -1121_tbl_Shop_Unit_Measurement.sql -1122_tbl_Shop_Unit_Measurement_Audit.sql -1124_tbl_Shop_Unit_Measurement_Conversion.sql -1125_tbl_Shop_Unit_Measurement_Conversion_Audit.sql -1200_tbl_Shop_Product_Category.sql -1201_tbl_Shop_Product_Category_Audit.sql -1202_tbl_Shop_Product_Category_Temp.sql -1203_tbl_Shop_Product.sql -1204_tbl_Shop_Product_Audit.sql -1205_tbl_Shop_Product_Temp.sql -1206_tbl_Shop_Product_Permutation.sql -1207_tbl_Shop_Product_Permutation_Audit.sql -1208_tbl_Shop_Product_Permutation_Temp.sql -1209_tbl_Shop_Variation_Type.sql -1210_tbl_Shop_Variation_Type_Audit.sql -1211_tbl_Shop_Variation_Type_Temp.sql -1212_tbl_Shop_Variation.sql -1213_tbl_Shop_Variation_Audit.sql -1214_tbl_Shop_Variation_Temp.sql -1215_tbl_Shop_Product_Permutation_Variation_Link.sql -1216_tbl_Shop_Product_Permutation_Variation_Link_Audit.sql -1217_tbl_Shop_Product_Permutation_Variation_Link_Temp.sql -1218_tbl_Shop_Stock_Item.sql -1219_tbl_Shop_Stock_Item_Audit.sql -1220_tbl_Shop_Stock_Item_Temp.sql -1221_tbl_Shop_Product_Price.sql -1222_tbl_Shop_Product_Price_Audit.sql -1223_tbl_Shop_Product_Price_Temp.sql -1224_tbl_Shop_Product_Image.sql -1225_tbl_Shop_Product_Image_Audit.sql -1227_tbl_Shop_Delivery_Option.sql -1228_tbl_Shop_Delivery_Option_Audit.sql -1230_tbl_Shop_Product_Permutation_Delivery_Option_Link.sql -1231_tbl_Shop_Product_Permutation_Delivery_Option_Link_Audit.sql -1233_tbl_Shop_Discount.sql -1234_tbl_Shop_Discount_Audit.sql -1236_tbl_Shop_Discount_Region_Currency_Link.sql -1237_tbl_Shop_Discount_Region_Currency_Link_Audit.sql -1300_tbl_Shop_Permission_Group.sql -1301_tbl_Shop_Permission_Group_Audit.sql -1303_tbl_Shop_Permission.sql -1304_tbl_Shop_Permission_Audit.sql -1306_tbl_Shop_Role.sql -1307_tbl_Shop_Role_Audit.sql -1309_tbl_Shop_Role_Permission_Link.sql -1310_tbl_Shop_Role_Permission_Link_Audit.sql -1312_tbl_Shop_User.sql -1313_tbl_Shop_User_Audit.sql -1315_tbl_Shop_User_Role_Link.sql -1316_tbl_Shop_User_Role_Link_Audit.sql -1318_tbl_Shop_User_Address.sql -1319_tbl_Shop_User_Address_Audit.sql -1321_tbl_Shop_User_Basket.sql -1322_tbl_Shop_User_Basket_Audit.sql -1397_tbl_Shop_Order_Status.sql -1398_tbl_Shop_Order_Status_Audit.sql -1400_tbl_Shop_Supplier.sql -1401_tbl_Shop_Supplier_Audit.sql -1402_tbl_Shop_Supplier_Temp.sql -1403_tbl_Shop_Supplier_Address.sql -1404_tbl_Shop_Supplier_Address_Audit.sql -1405_tbl_Shop_Supplier_Address_Temp.sql -1409_tbl_Shop_Supplier_Purchase_Order.sql -1410_tbl_Shop_Supplier_Purchase_Order_Audit.sql -1411_tbl_Shop_Supplier_Purchase_Order_Temp.sql -1412_tbl_Shop_Supplier_Purchase_Order_Product_Link.sql -1413_tbl_Shop_Supplier_Purchase_Order_Product_Link_Audit.sql -1414_tbl_Shop_Supplier_Purchase_Order_Product_Link_Temp.sql -1415_tbl_Shop_Manufacturing_Purchase_Order.sql -1416_tbl_Shop_Manufacturing_Purchase_Order_Audit.sql -1417_tbl_Shop_Manufacturing_Purchase_Order_Temp.sql -1418_tbl_Shop_Manufacturing_Purchase_Order_Product_Link.sql -1419_tbl_Shop_Manufacturing_Purchase_Order_Product_Link_Audit.sql -1420_tbl_Shop_Manufacturing_Purchase_Order_Product_Link_Temp.sql -1421_tbl_Shop_Customer.sql -1422_tbl_Shop_Customer_Audit.sql -1424_tbl_Shop_Customer_Sales_Order.sql -1425_tbl_Shop_Customer_Sales_Order_Audit.sql -1427_tbl_Shop_Customer_Sales_Order_Product_Link.sql -1428_tbl_Shop_Customer_Sales_Order_Product_Link_Audit.sql -1429_tbl_Shop_Customer_Sales_Order_Product_Link_Temp.sql -1500_tbl_Shop_Calc_User_Temp.sql -3000_tri_Shop_Access_Level.sql -3000_tri_Shop_Product_Change_Set.sql -3001_tri_Shop_User_Change_Set.sql -3002_tri_Shop_Sales_And_Purchasing_Change_Set.sql -3010_tri_File_Type.sql -3011_tri_File_Type_Audit.sql -3012_tri_Shop_General.sql -3014_tri_Shop_Image_Type.sql -3100_tri_Shop_Region.sql -3103_tri_Shop_Region_Branch.sql -3106_tri_Shop_Address.sql -3109_tri_Shop_Storage_Location.sql -3115_tri_Shop_Currency.sql -3118_tri_Shop_Tax_Or_Surcharge.sql -3200_tri_Shop_Category.sql -3203_tri_Shop_Product.sql -3206_tri_Shop_Product_Permutation.sql -3209_tri_Shop_Variation_Type.sql -3212_tri_Shop_Variation.sql -3215_tri_Shop_Product_Permutation_Variation_Link.sql -3218_tri_Shop_Stock_Item.sql -3221_tri_Shop_Product_Price.sql -3224_tri_Shop_Product_Image.sql -3227_tri_Shop_Delivery_Option.sql -3230_tri_Shop_Product_Permutation_Delivery_Option_Link.sql -3233_tri_Shop_Discount.sql -3236_tri_Shop_Discount_Region_Currency_Link.sql -3300_tri_Shop_Permission_Group.sql -3303_tri_Shop_Permission.sql -3306_tri_Shop_Role.sql -3309_tri_Shop_Role_Permission_Link.sql -3312_tri_Shop_User.sql -3315_tri_Shop_User_Role_Link.sql -3318_tri_Shop_User_Address.sql -3321_tri_Shop_User_Basket.sql -3324_tri_Shop_User_Order_Status.sql -3400_tri_Shop_Supplier.sql -3403_tri_Shop_Supplier_Address.sql -3403_tri_Shop_Unit_Measurement.sql -3406_tri_Shop_Unit_Of_Measurement_Conversion.sql -3409_tri_Shop_Supplier_Purchase_Order.sql -3412_tri_Shop_Supplier_Purchase_Order_Product_Link.sql -3415_tri_Shop_Manufacturing_Purchase_Order.sql -3418_tri_Shop_Manufacturing_Purchase_Order_Product_Link.sql -3421_tri_Shop_Customer.sql -3424_tri_Shop_Customer_Sales_Order.sql -3427_tri_Shop_Customer_Sales_Order_Product_Link.sql -6000_p_debug_timing_reporting.sql -6000_p_split.sql -6001_p_clear_split_temp.sql -6001_p_validate_guid.sql -6003_p_split_key_value_pair_csv.sql -6004_p_clear_split_key_value_pair_csv_temp.sql -6206_fn_shop_get_product_permutation_name.sql -6210_fn_shop_get_id_product_permutation_from_variation_csv_list.sql -6211_fn_shop_get_product_variations_from_id_csv_list.sql -6500_p_shop_calc_user.sql -6501_p_shop_clear_calc_user.sql -7003_p_shop_get_many_access_level.sql -7101_p_shop_get_many_region.sql -7106_p_shop_get_many_plant.sql -7109_p_shop_get_many_storage_location.sql -7116_p_shop_get_many_currency.sql -7122_p_shop_get_many_unit_measurement.sql -7200_p_shop_save_product_category.sql -7200_p_shop_save_product_category_test.sql -7202_p_shop_clear_calc_product_permutation.sql -7203_p_shop_save_product.sql -7203_p_shop_save_product_test.sql -7204_p_shop_calc_product_permutation.sql -7204_p_shop_get_many_product.sql -7205_p_shop_get_many_stripe_product_new.sql -7206_p_shop_save_product_permutation.sql -7206_p_shop_save_product_permutation_test.sql -7210_p_shop_get_many_product_variation.sql -7212_p_shop_save_product_variation.sql -7212_p_shop_save_product_variation_test.sql -7219_p_shop_get_many_stock_item.sql -7220_p_shop_save_stock_item.sql -7220_p_shop_save_stock_item_test.sql -7221_p_get_many_shop_product_price_and_discount_and_delivery_option.sql -7223_p_shop_get_many_stripe_price_new.sql -7312_p_shop_save_user.sql -7313_p_get_many_user.sql -7321_p_shop_save_user_basket.sql -7400_p_shop_save_supplier.sql -7400_p_shop_save_supplier_temp.sql -7401_p_shop_get_many_supplier.sql -7403_p_shop_save_supplier_purchase_order.sql -7403_p_shop_save_supplier_purchase_order_test.sql -7404_p_shop_get_many_supplier_purchase_order.sql -7415_p_shop_save_manufacturing_purchase_order.sql -7415_p_shop_save_Manufacturing_purchase_order_test.sql -7416_p_shop_get_many_manufacturing_purchase_order.sql -7421_p_shop_save_customer.sql -7422_p_shop_get_many_customer.sql -7424_p_shop_save_customer_sales_order.sql -7425_p_shop_get_many_customer_sales_order.sql -9000_populate.sql -9001_view.sql -9010_anal.sql diff --git a/static/MySQL/temp.txt b/static/MySQL/temp.txt deleted file mode 100644 index c987460e..00000000 --- a/static/MySQL/temp.txt +++ /dev/null @@ -1,221 +0,0 @@ -0001_destroy.sql -1000_tbl_Shop_Product_Change_Set.sql -1000_tbl_Split_Temp.sql -1001_tbl_Shop_User_Change_Set.sql -1001_tbl_Split_Key_Value_Pair_Csv_Temp.sql -1002_tbl_Shop_Sales_And_Purchasing_Change_Set.sql -1003_tbl_Shop_Access_Level.sql -1004_tbl_Shop_Access_Level_Audit.sql -1005_tbl_Msg_Error_Type.sql -1010_tbl_File_Type.sql -1011_tbl_File_Type_Audit.sql -1012_tbl_Shop_General.sql -1013_tbl_Shop_General_Audit.sql -1014_tbl_Shop_Image_Type.sql -1015_tbl_Shop_Image_Type_Audit.sql -1100_tbl_Shop_Region.sql -1101_tbl_Shop_Region_Audit.sql -1102_tbl_Shop_Region_Temp.sql -1103_tbl_Shop_Region_Branch.sql -1104_tbl_Shop_Region_Branch_Audit.sql -1105_tbl_Shop_Region_Branch_Temp.sql -1106_tbl_Shop_Address.sql -1106_tbl_Shop_Plant.sql -1107_tbl_Shop_Address_Audit.sql -1107_tbl_Shop_Plant_Audit.sql -1108_tbl_Shop_Plant_Temp.sql -1109_tbl_Shop_Storage_Location.sql -1110_tbl_Shop_Storage_Location_Audit.sql -1111_tbl_Shop_Storage_Location_Temp.sql -1112_tbl_Shop_Storage_Location_Branch.sql -1113_tbl_Shop_Storage_Location_Branch_Audit.sql -1114_tbl_Shop_Storage_Location_Branch_Temp.sql -1115_tbl_Shop_Currency.sql -1116_tbl_Shop_Currency_Audit.sql -1117_tbl_Shop_Currency_Temp.sql -1118_tbl_Shop_Tax_Or_Surcharge.sql -1119_tbl_Shop_Tax_Or_Surcharge_Audit.sql -1120_tbl_Shop_Tax_Or_Surcharge_Temp.sql -1121_tbl_Shop_Unit_Measurement.sql -1122_tbl_Shop_Unit_Measurement_Audit.sql -1124_tbl_Shop_Unit_Measurement_Conversion.sql -1125_tbl_Shop_Unit_Measurement_Conversion_Audit.sql -1200_tbl_Shop_Product_Category.sql -1201_tbl_Shop_Product_Category_Audit.sql -1202_tbl_Shop_Product_Category_Temp.sql -1203_tbl_Shop_Product.sql -1204_tbl_Shop_Product_Audit.sql -1205_tbl_Shop_Product_Temp.sql -1206_tbl_Shop_Product_Permutation.sql -1207_tbl_Shop_Product_Permutation_Audit.sql -1208_tbl_Shop_Product_Permutation_Temp.sql -1209_tbl_Shop_Variation_Type.sql -1210_tbl_Shop_Variation_Type_Audit.sql -1211_tbl_Shop_Variation_Type_Temp.sql -1212_tbl_Shop_Variation.sql -1213_tbl_Shop_Variation_Audit.sql -1214_tbl_Shop_Variation_Temp.sql -1215_tbl_Shop_Product_Permutation_Variation_Link.sql -1216_tbl_Shop_Product_Permutation_Variation_Link_Audit.sql -1217_tbl_Shop_Product_Permutation_Variation_Link_Temp.sql -1218_tbl_Shop_Stock_Item.sql -1219_tbl_Shop_Stock_Item_Audit.sql -1220_tbl_Shop_Stock_Item_Temp.sql -1221_tbl_Shop_Product_Price.sql -1222_tbl_Shop_Product_Price_Audit.sql -1223_tbl_Shop_Product_Price_Temp.sql -1224_tbl_Shop_Product_Image.sql -1225_tbl_Shop_Product_Image_Audit.sql -1227_tbl_Shop_Delivery_Option.sql -1228_tbl_Shop_Delivery_Option_Audit.sql -1230_tbl_Shop_Product_Permutation_Delivery_Option_Link.sql -1231_tbl_Shop_Product_Permutation_Delivery_Option_Link_Audit.sql -1233_tbl_Shop_Discount.sql -1234_tbl_Shop_Discount_Audit.sql -1236_tbl_Shop_Discount_Region_Currency_Link.sql -1237_tbl_Shop_Discount_Region_Currency_Link_Audit.sql -1300_tbl_Shop_Permission_Group.sql -1301_tbl_Shop_Permission_Group_Audit.sql -1303_tbl_Shop_Permission.sql -1304_tbl_Shop_Permission_Audit.sql -1306_tbl_Shop_Role.sql -1307_tbl_Shop_Role_Audit.sql -1309_tbl_Shop_Role_Permission_Link.sql -1310_tbl_Shop_Role_Permission_Link_Audit.sql -1312_tbl_Shop_User.sql -1313_tbl_Shop_User_Audit.sql -1315_tbl_Shop_User_Role_Link.sql -1316_tbl_Shop_User_Role_Link_Audit.sql -1318_tbl_Shop_User_Address.sql -1319_tbl_Shop_User_Address_Audit.sql -1321_tbl_Shop_User_Basket.sql -1322_tbl_Shop_User_Basket_Audit.sql -1397_tbl_Shop_Order_Status.sql -1398_tbl_Shop_Order_Status_Audit.sql -1400_tbl_Shop_Supplier.sql -1401_tbl_Shop_Supplier_Audit.sql -1402_tbl_Shop_Supplier_Temp.sql -1403_tbl_Shop_Supplier_Address.sql -1404_tbl_Shop_Supplier_Address_Audit.sql -1405_tbl_Shop_Supplier_Address_Temp.sql -1409_tbl_Shop_Supplier_Purchase_Order.sql -1410_tbl_Shop_Supplier_Purchase_Order_Audit.sql -1411_tbl_Shop_Supplier_Purchase_Order_Temp.sql -1412_tbl_Shop_Supplier_Purchase_Order_Product_Link.sql -1413_tbl_Shop_Supplier_Purchase_Order_Product_Link_Audit.sql -1414_tbl_Shop_Supplier_Purchase_Order_Product_Link_Temp.sql -1415_tbl_Shop_Manufacturing_Purchase_Order.sql -1416_tbl_Shop_Manufacturing_Purchase_Order_Audit.sql -1417_tbl_Shop_Manufacturing_Purchase_Order_Temp.sql -1418_tbl_Shop_Manufacturing_Purchase_Order_Product_Link.sql -1419_tbl_Shop_Manufacturing_Purchase_Order_Product_Link_Audit.sql -1420_tbl_Shop_Manufacturing_Purchase_Order_Product_Link_Temp.sql -1421_tbl_Shop_Customer.sql -1422_tbl_Shop_Customer_Audit.sql -1424_tbl_Shop_Customer_Sales_Order.sql -1425_tbl_Shop_Customer_Sales_Order_Audit.sql -1427_tbl_Shop_Customer_Sales_Order_Product_Link.sql -1428_tbl_Shop_Customer_Sales_Order_Product_Link_Audit.sql -1429_tbl_Shop_Customer_Sales_Order_Product_Link_Temp.sql -1500_tbl_Shop_Calc_User_Temp.sql -3000_tri_Shop_Access_Level.sql -3000_tri_Shop_Product_Change_Set.sql -3001_tri_Shop_User_Change_Set.sql -3002_tri_Shop_Sales_And_Purchasing_Change_Set.sql -3010_tri_File_Type.sql -3011_tri_File_Type_Audit.sql -3012_tri_Shop_General.sql -3014_tri_Shop_Image_Type.sql -3100_tri_Shop_Region.sql -3103_tri_Shop_Region_Branch.sql -3106_tri_Shop_Address.sql -3109_tri_Shop_Storage_Location.sql -3115_tri_Shop_Currency.sql -3118_tri_Shop_Tax_Or_Surcharge.sql -3200_tri_Shop_Category.sql -3203_tri_Shop_Product.sql -3206_tri_Shop_Product_Permutation.sql -3209_tri_Shop_Variation_Type.sql -3212_tri_Shop_Variation.sql -3215_tri_Shop_Product_Permutation_Variation_Link.sql -3218_tri_Shop_Stock_Item.sql -3221_tri_Shop_Product_Price.sql -3224_tri_Shop_Product_Image.sql -3227_tri_Shop_Delivery_Option.sql -3230_tri_Shop_Product_Permutation_Delivery_Option_Link.sql -3233_tri_Shop_Discount.sql -3236_tri_Shop_Discount_Region_Currency_Link.sql -3300_tri_Shop_Permission_Group.sql -3303_tri_Shop_Permission.sql -3306_tri_Shop_Role.sql -3309_tri_Shop_Role_Permission_Link.sql -3312_tri_Shop_User.sql -3315_tri_Shop_User_Role_Link.sql -3318_tri_Shop_User_Address.sql -3321_tri_Shop_User_Basket.sql -3324_tri_Shop_User_Order_Status.sql -3400_tri_Shop_Supplier.sql -3403_tri_Shop_Supplier_Address.sql -3403_tri_Shop_Unit_Measurement.sql -3406_tri_Shop_Unit_Of_Measurement_Conversion.sql -3409_tri_Shop_Supplier_Purchase_Order.sql -3412_tri_Shop_Supplier_Purchase_Order_Product_Link.sql -3415_tri_Shop_Manufacturing_Purchase_Order.sql -3418_tri_Shop_Manufacturing_Purchase_Order_Product_Link.sql -3421_tri_Shop_Customer.sql -3424_tri_Shop_Customer_Sales_Order.sql -3427_tri_Shop_Customer_Sales_Order_Product_Link.sql -6000_p_debug_timing_reporting.sql -6000_p_split.sql -6001_p_clear_split_temp.sql -6001_p_validate_guid.sql -6003_p_split_key_value_pair_csv.sql -6004_p_clear_split_key_value_pair_csv_temp.sql -6206_fn_shop_get_product_permutation_name.sql -6210_fn_shop_get_id_product_permutation_from_variation_csv_list.sql -6211_fn_shop_get_product_variations_from_id_csv_list.sql -6500_p_shop_calc_user.sql -6501_p_shop_clear_calc_user.sql -7003_p_shop_get_many_access_level.sql -7101_p_shop_get_many_region.sql -7106_p_shop_get_many_plant.sql -7109_p_shop_get_many_storage_location.sql -7116_p_shop_get_many_currency.sql -7122_p_shop_get_many_unit_measurement.sql -7200_p_shop_save_product_category.sql -7200_p_shop_save_product_category_test.sql -7202_p_shop_clear_calc_product_permutation.sql -7203_p_shop_save_product.sql -7203_p_shop_save_product_test.sql -7204_p_shop_calc_product_permutation.sql -7204_p_shop_get_many_product.sql -7205_p_shop_get_many_stripe_product_new.sql -7206_p_shop_save_product_permutation.sql -7206_p_shop_save_product_permutation_test.sql -7210_p_shop_get_many_product_variation.sql -7212_p_shop_save_product_variation.sql -7212_p_shop_save_product_variation_test.sql -7219_p_shop_get_many_stock_item.sql -7220_p_shop_save_stock_item.sql -7220_p_shop_save_stock_item_test.sql -7221_p_get_many_shop_product_price_and_discount_and_delivery_option.sql -7223_p_shop_get_many_stripe_price_new.sql -7312_p_shop_save_user.sql -7313_p_get_many_user.sql -7321_p_shop_save_user_basket.sql -7400_p_shop_save_supplier.sql -7400_p_shop_save_supplier_temp.sql -7401_p_shop_get_many_supplier.sql -7403_p_shop_save_supplier_purchase_order.sql -7403_p_shop_save_supplier_purchase_order_test.sql -7404_p_shop_get_many_supplier_purchase_order.sql -7415_p_shop_save_manufacturing_purchase_order.sql -7415_p_shop_save_Manufacturing_purchase_order_test.sql -7416_p_shop_get_many_manufacturing_purchase_order.sql -7421_p_shop_save_customer.sql -7422_p_shop_get_many_customer.sql -7424_p_shop_save_customer_sales_order.sql -7425_p_shop_get_many_customer_sales_order.sql -9000_populate.sql -9001_view.sql -9010_anal.sql diff --git a/static/PostgreSQL/000_combine.sql b/static/PostgreSQL/000_combine.sql deleted file mode 100644 index 02960719..00000000 --- a/static/PostgreSQL/000_combine.sql +++ /dev/null @@ -1,15113 +0,0 @@ - -/* Clear Store DataBase */ - - - --- Drop dependencies -DROP TABLE IF EXISTS Shop_Calc_User_Temp; -DROP TABLE IF EXISTS tmp_Msg_Error; -DROP TABLE IF EXISTS tmp_Currency; -DROP TABLE IF EXISTS tmp_Delivery_Region; -DROP TABLE IF EXISTS tmp_Region; -DROP TABLE IF EXISTS tmp_Shop_User; -DROP TABLE IF EXISTS tmp_Shop_Order; -DROP TABLE IF EXISTS tmp_Shop_Product; -DROP TABLE IF EXISTS tmp_Shop_Product_p_shop_calc_user; -DROP TABLE IF EXISTS tmp_Shop_Image; -DROP TABLE IF EXISTS tmp_Shop_Variation; -DROP TABLE IF EXISTS tmp_Shop_Discount; -DROP TABLE IF EXISTS tmp_Discount; -DROP TABLE IF EXISTS tmp_Shop_Product_Category; -DROP TABLE IF EXISTS tmp_Shop_Product_Currency_Region_Link; -DROP TABLE IF EXISTS tmp_Shop_Product_Currency_Link; -DROP TABLE IF EXISTS tmp_User_Role_Link; -DROP TABLE IF EXISTS tmp_Shop_Basket; -DROP TABLE IF EXISTS tmp_Shop_Supplier_Purchase_Order_Product_Link; -DROP TABLE IF EXISTS tmp_Shop_Supplier_Purchase_Order; -DROP TABLE IF EXISTS tmp_Shop_Supplier; -DROP TABLE IF EXISTS tmp_Shop_Manufacturing_Purchase_Order_Product_Link; -DROP TABLE IF EXISTS tmp_Shop_Manufacturing_Purchase_Order; -DROP TABLE IF EXISTS tmp_Shop_Customer; - - - --- Delete old tables -DROP TABLE IF EXISTS Shop_Customer_Sales_Order_Product_Link_Temp; -DROP TABLE IF EXISTS Shop_Customer_Sales_Order_Product_Link_Audit; -DROP TABLE IF EXISTS Shop_Customer_Sales_Order_Product_Link; - -DROP TABLE IF EXISTS Shop_Customer_Sales_Order_Audit; -DROP TABLE IF EXISTS Shop_Customer_Sales_Order; - -DROP TABLE IF EXISTS Shop_Customer_Audit; -DROP TABLE IF EXISTS Shop_Customer; - -DROP TABLE IF EXISTS Shop_Manufacturing_Purchase_Order_Product_Link_Temp; -DROP TABLE IF EXISTS Shop_Manufacturing_Purchase_Order_Product_Link_Audit; -DROP TABLE IF EXISTS Shop_Manufacturing_Purchase_Order_Product_Link; - -DROP TABLE IF EXISTS Shop_Manufacturing_Purchase_Order_Audit; -DROP TABLE IF EXISTS Shop_Manufacturing_Purchase_Order; - -DROP TABLE IF EXISTS Shop_Supplier_Purchase_Order_Product_Link_Temp; -DROP TABLE IF EXISTS Shop_Supplier_Purchase_Order_Product_Link_Audit; -DROP TABLE IF EXISTS Shop_Supplier_Purchase_Order_Product_Link; - -DROP TABLE IF EXISTS Shop_Supplier_Purchase_Order_Audit; -DROP TABLE IF EXISTS Shop_Supplier_Purchase_Order; - -DROP TABLE IF EXISTS Shop_Unit_Measurement_Conversion_Audit; -DROP TABLE IF EXISTS Shop_Unit_Measurement_Conversion; - -DROP TABLE IF EXISTS Shop_Unit_Measurement_Audit; -DROP TABLE IF EXISTS Shop_Unit_Measurement; - -DROP TABLE IF EXISTS Shop_Supplier_Audit; -DROP TABLE IF EXISTS Shop_Supplier; - -DROP TABLE IF EXISTS Shop_User_Order_Product_Link_Audit; -DROP TABLE IF EXISTS Shop_User_Order_Product_Link; - -DROP TABLE IF EXISTS Shop_User_Order_Audit; -DROP TABLE IF EXISTS Shop_User_Order; - -DROP TABLE IF EXISTS Shop_User_Order_Status_Audit; -DROP TABLE IF EXISTS Shop_User_Order_Status; - -DROP TABLE IF EXISTS Shop_User_Basket_Audit; -DROP TABLE IF EXISTS Shop_User_Basket; - -DROP TABLE IF EXISTS Shop_Address_Audit; -DROP TABLE IF EXISTS Shop_Address; - -DROP TABLE IF EXISTS Shop_User_Role_Link_Audit; -DROP TABLE IF EXISTS Shop_User_Role_Link; - -DROP TABLE IF EXISTS Shop_User_Audit; -DROP TABLE IF EXISTS Shop_User; - -DROP TABLE IF EXISTS Shop_Role_Permission_Link_Audit; -DROP TABLE IF EXISTS Shop_Role_Permission_Link; - -DROP TABLE IF EXISTS Shop_Role_Audit; -DROP TABLE IF EXISTS Shop_Role; - -DROP TABLE IF EXISTS Shop_Permission_Audit; -DROP TABLE IF EXISTS Shop_Permission; - -DROP TABLE IF EXISTS Shop_Permission_Group_Audit; -DROP TABLE IF EXISTS Shop_Permission_Group; - - -DROP TABLE IF EXISTS Shop_Discount_Region_Currency_Link_Audit; -DROP TABLE IF EXISTS Shop_Discount_Region_Currency_Link; - -DROP TABLE IF EXISTS Shop_Discount_Audit; -DROP TABLE IF EXISTS Shop_Discount; - -DROP TABLE IF EXISTS Shop_Product_Permutation_Delivery_Option_Link_Audit; -DROP TABLE IF EXISTS Shop_Product_Permutation_Delivery_Option_Link; - -DROP TABLE IF EXISTS Shop_Delivery_Option_Audit; -DROP TABLE IF EXISTS Shop_Delivery_Option; - -DROP TABLE IF EXISTS Shop_Image_Audit; -DROP TABLE IF EXISTS Shop_Image; - -DROP TABLE IF EXISTS Shop_Image_Type_Audit; -DROP TABLE IF EXISTS Shop_Image_Type; - -DROP TABLE IF EXISTS Shop_Product_Currency_Region_Link_Audit; -DROP TABLE IF EXISTS Shop_Product_Currency_Region_Link; -DROP TABLE IF EXISTS Shop_Product_Currency_Link_Audit; -DROP TABLE IF EXISTS Shop_Product_Currency_Link; - -DROP TABLE IF EXISTS Shop_Product_Variation_Link_Audit; -DROP TABLE IF EXISTS Shop_Product_Variation_Link; -DROP TABLE IF EXISTS Shop_Product_Permutation_Variation_Link_Audit; -DROP TABLE IF EXISTS Shop_Product_Permutation_Variation_Link; - -DROP TABLE IF EXISTS Shop_Product_Permutation_Audit; -DROP TABLE IF EXISTS Shop_Product_Permutation; - -DROP TABLE IF EXISTS Shop_Variation_Audit; -DROP TABLE IF EXISTS Shop_Variation; -DROP TABLE IF EXISTS Shop_Product_Variation_Type_Link_Audit; -DROP TABLE IF EXISTS Shop_Product_Variation_Type_Link; - -DROP TABLE IF EXISTS Shop_Variation_Type_Audit; -DROP TABLE IF EXISTS Shop_Variation_Type; - -DROP TABLE IF EXISTS Shop_Product_Audit; -DROP TABLE IF EXISTS Shop_Product; - -DROP TABLE IF EXISTS Shop_Tax_Or_Surcharge_Audit; -DROP TABLE IF EXISTS Shop_Tax_Or_Surcharge; - -DROP TABLE IF EXISTS Shop_Currency_Audit; -DROP TABLE IF EXISTS Shop_Currency; - -DROP TABLE IF EXISTS Shop_Delivery_Region_Branch_Audit; -DROP TABLE IF EXISTS Shop_Delivery_Region_Branch; -DROP TABLE IF EXISTS Shop_Region_Branch_Audit; -DROP TABLE IF EXISTS Shop_Region_Branch; - -DROP TABLE IF EXISTS Shop_Delivery_Region_Audit; -DROP TABLE IF EXISTS Shop_Delivery_Region; -DROP TABLE IF EXISTS Shop_Region_Audit; -DROP TABLE IF EXISTS Shop_Region; - -DROP TABLE IF EXISTS Shop_Interval_Recurrence_Audit; -DROP TABLE IF EXISTS Shop_Interval_Recurrence; - -DROP TABLE IF EXISTS Shop_Product_Category_Audit; -DROP TABLE IF EXISTS Shop_Product_Category; - -DROP TABLE IF EXISTS Shop_General_Audit; -DROP TABLE IF EXISTS Shop_General; - -DROP TABLE IF EXISTS File_Type_Audit; -DROP TABLE IF EXISTS File_Type; - -DROP TABLE IF EXISTS Msg_Error_Type; - -DROP TABLE IF EXISTS Shop_Access_Level_Audit; -DROP TABLE IF EXISTS Shop_Access_Level; - -DROP TABLE IF EXISTS Shop_Sales_And_Purchasing_Change_Set; -DROP TABLE IF EXISTS Shop_User_Change_Set; - -DROP TABLE IF EXISTS Shop_Msg_Error_Type; - -DROP TABLE IF EXISTS Shop_Product_Change_Set; - -DO $$ -BEGIN - RAISE NOTICE 'TABLE DELETION COMPLETE'; -END $$; - - -DROP FUNCTION IF EXISTS fn_shop_user_eval; -DROP FUNCTION IF EXISTS p_shop_calc_user; -DROP PROCEDURE IF EXISTS fn_shop_user_eval; -DROP PROCEDURE IF EXISTS p_shop_calc_user; - -DROP FUNCTION IF EXISTS fn_shop_save_product; -DROP FUNCTION IF EXISTS p_shop_save_product; -DROP PROCEDURE IF EXISTS fn_shop_save_product; -DROP PROCEDURE IF EXISTS p_shop_save_product; - -DROP FUNCTION IF EXISTS fn_shop_save_supplier; -DROP FUNCTION IF EXISTS p_shop_save_supplier; -DROP PROCEDURE IF EXISTS fn_shop_save_supplier; -DROP PROCEDURE IF EXISTS p_shop_save_supplier; - -DROP FUNCTION IF EXISTS fn_shop_save_supplier_purchase_order; -DROP FUNCTION IF EXISTS p_shop_save_supplier_purchase_order; -DROP PROCEDURE IF EXISTS fn_shop_save_supplier_purchase_order; -DROP PROCEDURE IF EXISTS p_shop_save_supplier_purchase_order; - -DROP FUNCTION IF EXISTS fn_shop_save_manufacturing_purchase_order; -DROP FUNCTION IF EXISTS p_shop_save_manufacturing_purchase_order; -DROP PROCEDURE IF EXISTS fn_shop_save_manufacturing_purchase_order; -DROP PROCEDURE IF EXISTS p_shop_save_manufacturing_purchase_order; - -DROP FUNCTION IF EXISTS fn_shop_save_customer; -DROP FUNCTION IF EXISTS p_shop_save_customer; -DROP PROCEDURE IF EXISTS fn_shop_save_customer; -DROP PROCEDURE IF EXISTS p_shop_save_customer; - -DROP FUNCTION IF EXISTS fn_shop_save_customer_sales_order; -DROP FUNCTION IF EXISTS p_shop_save_customer_sales_order; -DROP PROCEDURE IF EXISTS fn_shop_save_customer_sales_order; -DROP PROCEDURE IF EXISTS p_shop_save_customer_sales_order; - -DROP FUNCTION IF EXISTS fn_shop_save_user; -DROP FUNCTION IF EXISTS p_shop_save_user; -DROP PROCEDURE IF EXISTS fn_shop_save_user; -DROP PROCEDURE IF EXISTS p_shop_save_user; - -DROP FUNCTION IF EXISTS fn_shop_save_user_basket; -DROP FUNCTION IF EXISTS p_shop_save_user_basket; -DROP PROCEDURE IF EXISTS fn_shop_save_user_basket; -DROP PROCEDURE IF EXISTS p_shop_save_user_basket; - -DROP FUNCTION IF EXISTS fn_shop_get_many_product; -DROP FUNCTION IF EXISTS p_shop_get_many_product; -DROP PROCEDURE IF EXISTS fn_shop_get_many_product; -DROP PROCEDURE IF EXISTS p_shop_get_many_product; - -DROP FUNCTION IF EXISTS fn_shop_get_many_role_permission; -DROP FUNCTION IF EXISTS p_shop_get_many_role_permission; -DROP PROCEDURE IF EXISTS fn_shop_get_many_role_permission; -DROP PROCEDURE IF EXISTS p_shop_get_many_role_permission; - -DROP FUNCTION IF EXISTS fn_shop_get_many_currency; -DROP FUNCTION IF EXISTS p_shop_get_many_currency; -DROP PROCEDURE IF EXISTS fn_shop_get_many_currency; -DROP PROCEDURE IF EXISTS p_shop_get_many_currency; - -DROP FUNCTION IF EXISTS fn_shop_get_many_region; -DROP FUNCTION IF EXISTS p_shop_get_many_region; -DROP PROCEDURE IF EXISTS fn_shop_get_many_region; -DROP PROCEDURE IF EXISTS p_shop_get_many_region; - -DROP FUNCTION IF EXISTS fn_shop_get_many_user_order; -DROP FUNCTION IF EXISTS p_shop_get_many_user_order; -DROP PROCEDURE IF EXISTS fn_shop_get_many_user_order; -DROP PROCEDURE IF EXISTS p_shop_get_many_user_order; - -DROP FUNCTION IF EXISTS fn_shop_get_many_stripe_product_new; -DROP FUNCTION IF EXISTS p_shop_get_many_stripe_product_new; -DROP PROCEDURE IF EXISTS fn_shop_get_many_stripe_product_new; -DROP PROCEDURE IF EXISTS p_shop_get_many_stripe_product_new; - -DROP FUNCTION IF EXISTS fn_shop_get_many_stripe_price_new; -DROP FUNCTION IF EXISTS p_shop_get_many_stripe_price_new; -DROP PROCEDURE IF EXISTS fn_shop_get_many_stripe_price_new; -DROP PROCEDURE IF EXISTS p_shop_get_many_stripe_price_new; - -DROP FUNCTION IF EXISTS fn_shop_get_many_supplier; -DROP FUNCTION IF EXISTS p_shop_get_many_supplier; -DROP PROCEDURE IF EXISTS fn_shop_get_many_supplier; -DROP PROCEDURE IF EXISTS p_shop_get_many_supplier; - -DROP FUNCTION IF EXISTS fn_shop_get_many_supplier_purchase_order; -DROP FUNCTION IF EXISTS p_shop_get_many_supplier_purchase_order; -DROP PROCEDURE IF EXISTS fn_shop_get_many_supplier_purchase_order; -DROP PROCEDURE IF EXISTS p_shop_get_many_supplier_purchase_order; - -DROP FUNCTION IF EXISTS fn_shop_get_many_manufacturing_purchase_order; -DROP FUNCTION IF EXISTS p_shop_get_many_manufacturing_purchase_order; -DROP PROCEDURE IF EXISTS fn_shop_get_many_manufacturing_purchase_order; -DROP PROCEDURE IF EXISTS p_shop_get_many_manufacturing_purchase_order; - -DROP FUNCTION IF EXISTS fn_shop_get_many_customer; -DROP FUNCTION IF EXISTS p_shop_get_many_customer; -DROP PROCEDURE IF EXISTS fn_shop_get_many_customer; -DROP PROCEDURE IF EXISTS p_shop_get_many_customer; - -DROP FUNCTION IF EXISTS fn_shop_get_many_customer_sales_order; -DROP FUNCTION IF EXISTS p_shop_get_many_customer_sales_order; -DROP PROCEDURE IF EXISTS fn_shop_get_many_customer_sales_order; -DROP PROCEDURE IF EXISTS p_shop_get_many_customer_sales_order; --- Product Change Sets - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Change_Set'; - -CREATE TABLE Shop_Product_Change_Set ( - id_change_set INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - comment VARCHAR(4000), - updated_last_on TIMESTAMP, - updated_last_by VARCHAR(100) -); --- User Change Sets - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Change_Set'; - -CREATE TABLE IF NOT EXISTS Shop_User_Change_Set ( - id_change_set INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - comment VARCHAR(4000), - updated_last_on TIMESTAMP, - updated_last_by VARCHAR(100) -); --- Access Levels - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Access_Level'; - -CREATE TABLE IF NOT EXISTS Shop_Access_Level ( - id_access_level INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - code VARCHAR(50), - name VARCHAR(255), - priority INTEGER NOT NULL, - active BOOLEAN NOT NULL DEFAULT TRUE, - display_order INTEGER NOT NULL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Access_Level_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); --- Sales And Purchasing Change Sets - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Sales_And_Purchasing_Change_Set'; - -CREATE TABLE Shop_Sales_And_Purchasing_Change_Set ( - id_change_set INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - comment VARCHAR(4000), - updated_last_on TIMESTAMP, - updated_last_by VARCHAR(100) -); --- Access Level Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Access_Level_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Access_Level_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_access_level INTEGER NOT NULL, - CONSTRAINT FK_Shop_Access_Level_Audit_id_access_level - FOREIGN KEY (id_access_level) - REFERENCES Shop_Access_Level(id_access_level) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(255), - value_new VARCHAR(255), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Access_Level_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); --- Error Message Type - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Msg_Error_Type'; - -CREATE TABLE IF NOT EXISTS Shop_Msg_Error_Type ( - id_type INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - code VARCHAR(50) NOT NULL, - name VARCHAR(200) NOT NULL, - description VARCHAR(1000) -); - --- File Types - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'File_Type'; - -CREATE TABLE IF NOT EXISTS File_Type ( - id_type INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - code VARCHAR(50), - name VARCHAR(100), - extension VARCHAR(50), - created_on TIMESTAMP, - created_by INT, - updated_last_on TIMESTAMP, - updated_last_by VARCHAR(100) -); - --- File Type Audit - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'File_Type_Audit'; - -CREATE TABLE IF NOT EXISTS File_Type_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_type INTEGER NOT NULL, - CONSTRAINT FK_File_Type_Audit_id_type - FOREIGN KEY (id_type) - REFERENCES File_Type(id_type) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(100), - value_new VARCHAR(100), - created_on TIMESTAMP, - created_by INT, - updated_last_on TIMESTAMP, - updated_last_by VARCHAR(100) -); --- Generic / shared properties - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_General'; - -CREATE TABLE IF NOT EXISTS Shop_General ( - id_general INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - quantity_max REAL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT CHK_Shop_General_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); --- Shop General Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_General_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_General_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_general INTEGER NOT NULL, - CONSTRAINT FK_Shop_General_Audit_id_general - FOREIGN KEY (id_general) - REFERENCES Shop_General(id_general) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(100), - value_new VARCHAR(100), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_General_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); --- Categories - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Category'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Category ( - id_category INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - code VARCHAR(50), - name VARCHAR(255), - description VARCHAR(4000), - active BOOLEAN NOT NULL DEFAULT TRUE, - display_order INTEGER NOT NULL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Product_Category_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - --- Category Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Category_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Category_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_category INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Category_Audit_id_category - FOREIGN KEY (id_category) - REFERENCES Shop_Product_Category(id_category) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(4000), - value_new VARCHAR(4000), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Category_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - --- Recurrence Interval - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Interval_Recurrence'; - -CREATE TABLE IF NOT EXISTS Shop_Interval_Recurrence ( - id_interval INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - code VARCHAR(50), - name VARCHAR(255), - name_plural VARCHAR(256), - active BOOLEAN NOT NULL DEFAULT TRUE, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Interval_Recurrence_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - --- Recurrence Interval Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Interval_Recurrence_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Interval_Recurrence_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_interval INTEGER NOT NULL, - CONSTRAINT FK_Shop_Interval_Recurrence_Audit_id_interval - FOREIGN KEY (id_interval) - REFERENCES Shop_Interval_Recurrence(id_interval) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(256), - value_new VARCHAR(256), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Interval_Recurrence_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - --- Regions - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Region'; - -CREATE TABLE IF NOT EXISTS Shop_Region ( - id_region INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - code VARCHAR(50) NOT NULL, - name VARCHAR(200) NOT NULL, - active BOOLEAN NOT NULL DEFAULT TRUE, - display_order INTEGER NOT NULL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Region_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); --- Region Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Region_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Region_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_region INTEGER NOT NULL, - CONSTRAINT FK_Shop_Region_Audit_id_region - FOREIGN KEY (id_region) - REFERENCES Shop_Region(id_region) - ON UPDATE RESTRICT, - name_field VARCHAR(64) NOT NULL, - value_prev VARCHAR(200), - value_new VARCHAR(200), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Region_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); --- Region Branchs - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Region_Branch'; - -CREATE TABLE IF NOT EXISTS Shop_Region_Branch ( - id_branch INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_region_parent INTEGER NOT NULL, - CONSTRAINT FK_Shop_Region_Branch_id_region_parent - FOREIGN KEY (id_region_parent) - REFERENCES Shop_Region(id_region) - ON UPDATE RESTRICT, - id_region_child INTEGER NOT NULL, - CONSTRAINT FK_Shop_Region_Branch_id_region_child - FOREIGN KEY (id_region_child) - REFERENCES Shop_Region(id_region) - ON UPDATE RESTRICT, - -- depth INTEGER NOT NULL, - active BOOLEAN NOT NULL DEFAULT TRUE, - display_order INTEGER NOT NULL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Region_Branch_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); --- Region Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Region_Branch_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Region_Branch_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_branch INTEGER NOT NULL, - CONSTRAINT FK_Shop_Region_Branch_Audit_id_branch - FOREIGN KEY (id_branch) - REFERENCES Shop_Region_Branch(id_branch) - ON UPDATE RESTRICT, - name_field VARCHAR(64) NOT NULL, - value_prev VARCHAR(10), - value_new VARCHAR(10), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Region_Branch_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); --- Currencies - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Currency'; - -CREATE TABLE IF NOT EXISTS Shop_Currency ( - id_currency INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - code VARCHAR(50) NOT NULL, - name VARCHAR(255) NOT NULL, - symbol VARCHAR(1) NOT NULL, - factor_from_GBP REAL NOT NULL, - active BOOLEAN NOT NULL DEFAULT TRUE, - display_order INTEGER NOT NULL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Currency_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) - ON UPDATE RESTRICT -); --- Currency Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Currency_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Currency_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_currency INTEGER NOT NULL, - CONSTRAINT FK_Shop_Currency_Audit_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(255), - value_new VARCHAR(255), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Currency_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - ON UPDATE RESTRICT -); --- Taxes and Surcharges - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Tax_Or_Surcharge'; - -CREATE TABLE Shop_Tax_Or_Surcharge ( - id_tax INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - code VARCHAR(50) NOT NULL, - name VARCHAR(200) NOT NULL, - id_region_buyer INTEGER NOT NULL, - CONSTRAINT FK_Shop_Tax_Or_Surcharge_id_region_buyer - FOREIGN KEY (id_region_buyer) - REFERENCES Shop_Region(id_region), - id_region_seller INTEGER NOT NULL, - CONSTRAINT FK_Shop_Tax_Or_Surcharge_id_region_seller - FOREIGN KEY (id_region_seller) - REFERENCES Shop_Region(id_region), - id_currency INTEGER, - CONSTRAINT FK_Shop_Tax_Or_Surcharge_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency) - ON UPDATE RESTRICT, - fixed_fee REAL NOT NULL DEFAULT 0, - multiplier REAL NOT NULL DEFAULT 1 CHECK (multiplier > 0), - apply_fixed_fee_before_multiplier BOOLEAN NOT NULL DEFAULT TRUE, - quantity_min REAL NOT NULL DEFAULT 0, - quantity_max REAL NOT NULL, - active BOOLEAN NOT NULL DEFAULT TRUE, - display_order INTEGER NOT NULL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Tax_Or_Surcharge_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - --- Tax Or Surcharge Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Tax_Or_Surcharge_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Tax_Or_Surcharge_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_tax INTEGER NOT NULL, - CONSTRAINT FK_Shop_Tax_Or_Surcharge_Audit_id_discount - FOREIGN KEY (id_tax) - REFERENCES Shop_Tax_Or_Surcharge(id_tax) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(200), - value_new VARCHAR(200), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Tax_Or_Surcharge_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) - ON UPDATE RESTRICT -); --- Products - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product'; - -CREATE TABLE IF NOT EXISTS Shop_Product ( - id_product INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - name VARCHAR(255) NOT NULL, - -- description VARCHAR(4000), - id_category INTEGER NOT NULL, - has_variations BOOLEAN NOT NULL, - /* - price_GBP_full REAL, - price_GBP_min REAL, - -- ratio_discount_overall REAL NOT NULL DEFAULT 0, - CONSTRAINT FK_Shop_Product_id_category - FOREIGN KEY (id_category) - REFERENCES Shop_Product_Category(id_category) - ON UPDATE RESTRICT, - latency_manuf INTEGER, - quantity_min REAL, - quantity_max REAL, - quantity_step REAL, - quantity_stock REAL, - is_subscription BOOLEAN, - id_unit_measurement_interval_recurrence INTEGER, - CONSTRAINT FK_Shop_Product_id_unit_measurement_interval_recurrence - FOREIGN KEY (id_unit_measurement_interval_recurrence) - REFERENCES Shop_Interval_Recurrence(id_interval), - count_interval_recurrence INTEGER, - */ - id_access_level_required INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_id_access_level_required - FOREIGN KEY (id_access_level_required) - REFERENCES Shop_Access_Level(id_access_level), - -- id_stripe_product VARCHAR(100), - -- id_stripe_price VARCHAR(100) NOT NULL, - active BOOLEAN NOT NULL DEFAULT TRUE, - display_order INTEGER NOT NULL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Product_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - --- Products - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_product INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Audit_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(255), - value_new VARCHAR(255), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); --- Variation Types - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Variation_Type'; - -CREATE TABLE IF NOT EXISTS Shop_Variation_Type ( - id_type INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - code VARCHAR(50), - name VARCHAR(255), - name_plural VARCHAR(256), - active BOOLEAN NOT NULL DEFAULT TRUE, - display_order INTEGER NOT NULL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Variation_Type_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); --- Variation Type Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Variation_Type_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Variation_Type_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_type INTEGER NOT NULL, - CONSTRAINT FK_Shop_Variation_Type_Audit_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Variation_Type(id_type) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(256), - value_new VARCHAR(256), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Variation_Type_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - --- Variations - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Variation'; - -CREATE TABLE Shop_Variation ( - id_variation INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_type INTEGER NOT NULL, - CONSTRAINT FK_Shop_Variation_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Variation_Type(id_type) - ON UPDATE RESTRICT, - code VARCHAR(50), - name VARCHAR(255), - active BOOLEAN NOT NULL DEFAULT TRUE, - display_order INTEGER NOT NULL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Variation_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - --- Variation Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Variation_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Variation_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_variation INTEGER NOT NULL, - CONSTRAINT FK_Shop_Variation_Audit_id_variation - FOREIGN KEY (id_variation) - REFERENCES Shop_Variation(id_variation) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(255), - value_new VARCHAR(255), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Variation_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - --- Product Permutation - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Permutation'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Permutation ( - id_permutation INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_product INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Variation_Link_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product) - ON UPDATE RESTRICT, - -- name VARCHAR(255) NOT NULL, - description VARCHAR(4000) NOT NULL, - cost_local REAL NOT NULL, - id_currency_cost INTEGER NOT NULL, - profit_local_min REAL NOT NULL, - -- id_currency_profit_min INTEGER NOT NULL, - latency_manufacture INTEGER NOT NULL, - quantity_min REAL NOT NULL, - quantity_max REAL NOT NULL, - quantity_step REAL NOT NULL, - quantity_stock REAL NOT NULL, - is_subscription BOOLEAN NOT NULL, - id_unit_measurement_interval_recurrence INTEGER, - CONSTRAINT FK_Shop_Product_Permutation_id_unit_measurement_interval_recurrence - FOREIGN KEY (id_unit_measurement_interval_recurrence) - REFERENCES Shop_Interval_Recurrence(id_interval), - count_interval_recurrence INTEGER, - /* - id_access_level_required INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_id_access_level_required - FOREIGN KEY (id_access_level_required) - REFERENCES Shop_Access_Level(id_access_level), - */ - id_stripe_product VARCHAR(100) NULL, - active BOOLEAN NOT NULL DEFAULT TRUE, - display_order INTEGER NOT NULL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Product_Variation_Link_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - --- Product Permutation Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Permutation_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Permutation_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_permutation INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_Audit_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(4000), - value_new VARCHAR(4000), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) - ON UPDATE RESTRICT -); - --- Product Permutation Variation Link - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Permutation_Variation_Link'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Permutation_Variation_Link ( - id_link INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_permutation INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_Variation_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation) - ON UPDATE RESTRICT, - id_variation INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_Variation_Link_id_variation - FOREIGN KEY (id_variation) - REFERENCES Shop_Variation(id_variation) - ON UPDATE RESTRICT, - active BOOLEAN NOT NULL DEFAULT TRUE, - display_order INTEGER NOT NULL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Product_Permutation_Variation_Link_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - --- Product Permutation Variation Link Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Permutation_Variation_Link_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Permutation_Variation_Link_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_link INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_Variation_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Product_Permutation_Variation_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(10), - value_new VARCHAR(10), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_Variation_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) - ON UPDATE RESTRICT -); --- Product Currency Region link - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Currency_Region_Link'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Currency_Region_Link ( - id_link INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_product INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Currency_Region_Link_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product) - ON UPDATE RESTRICT, - id_permutation INTEGER NULL, - CONSTRAINT FK_Shop_Product_Currency_Region_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation) - ON UPDATE RESTRICT, - id_currency INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Currency_Region_Link_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency) - ON UPDATE RESTRICT, - id_region_purchase INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Currency_Region_Link_id_region_purchase - FOREIGN KEY (id_region_purchase) - REFERENCES Shop_Region(id_region) - ON UPDATE RESTRICT, - price_local_VAT_incl REAL NULL, - price_local_VAT_excl REAL NULL, - id_stripe_price VARCHAR(200), - active BOOLEAN NOT NULL DEFAULT TRUE, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Product_Currency_Region_Link_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); --- Product Currency Region Link Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Currency_Region_Link_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Currency_Region_Link_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_link INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Currency_Region_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Product_Currency_Region_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(10), - value_new VARCHAR(10), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Currency_Region_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - --- Image Types - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Image_Type'; - -CREATE TABLE IF NOT EXISTS Shop_Image_Type ( - id_type INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - code VARCHAR(50), - name VARCHAR(255), - name_plural VARCHAR(256), - active BOOLEAN NOT NULL DEFAULT TRUE, - display_order INTEGER NOT NULL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Image_Type_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - --- Image Type Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Image_Type_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Image_Type_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_type INTEGER NOT NULL, - CONSTRAINT FK_Shop_Image_Type_Audit_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Image_Type(id_type) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(256), - value_new VARCHAR(256), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Image_Type_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); --- Images - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Image'; - -CREATE TABLE IF NOT EXISTS Shop_Image ( - id_image INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_type_image INTEGER NOT NULL, - CONSTRAINT FK_Shop_Image_id_type_image - FOREIGN KEY (id_type_image) - REFERENCES Shop_Image_Type(id_type), - id_type_file INTEGER NOT NULL, - CONSTRAINT FK_Shop_Image_id_type_file - FOREIGN KEY (id_type_file) - REFERENCES File_Type(id_type), - id_product INTEGER NULL, - CONSTRAINT FK_Shop_Image_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - id_permutation INTEGER NULL, - CONSTRAINT FK_Shop_Image_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - url VARCHAR(255), - active BOOLEAN NOT NULL DEFAULT TRUE, - display_order INTEGER NOT NULL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Image_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); --- Image Type Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Image_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Image_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_image INTEGER NOT NULL, - CONSTRAINT FK_Shop_Image_Audit_id_image - FOREIGN KEY (id_image) - REFERENCES Shop_Image(id_image), - name_field VARCHAR(50), - value_prev VARCHAR(10), - value_new VARCHAR(10), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Image_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); --- Delivery Options - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Delivery_Option'; - -CREATE TABLE IF NOT EXISTS Shop_Delivery_Option ( - id_option INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - code VARCHAR(50) NOT NULL, - name VARCHAR(100) NOT NULL, - description VARCHAR(4000), - latency_delivery_min INTEGER NOT NULL, - latency_delivery_max INTEGER NOT NULL, - quantity_min INTEGER NOT NULL, - quantity_max INTEGER NOT NULL, - active BOOLEAN NOT NULL DEFAULT TRUE, - display_order INTEGER NOT NULL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Delivery_Option_Type_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - --- Delivery Option Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Delivery_Option_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Delivery_Option_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_option INTEGER NOT NULL, - CONSTRAINT FK_Shop_Delivery_Option_Audit_id_option - FOREIGN KEY (id_option) - REFERENCES Shop_Delivery_Option(id_option) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(4000), - value_new VARCHAR(4000), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Delivery_Option_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); --- Delivery Option - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Permutation_Delivery_Option_Link'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Permutation_Delivery_Option_Link ( - id_link INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_product INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_Delivery_Option_Link_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product) - ON UPDATE RESTRICT, - id_permutation INTEGER, - CONSTRAINT FK_Shop_Product_Permutation_Delivery_Option_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation) - ON UPDATE RESTRICT, - id_delivery_option INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_Delivery_Option_Link_id_delivery_option - FOREIGN KEY (id_delivery_option) - REFERENCES Shop_Delivery_Option(id_option) - ON UPDATE RESTRICT, - id_region INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_Delivery_Option_Link_id_region - FOREIGN KEY (id_region) - REFERENCES Shop_Region(id_region) - ON UPDATE RESTRICT, - id_currency INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_Delivery_Option_Link_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency) - ON UPDATE RESTRICT, - price_local REAL NOT NULL, - active BOOLEAN NOT NULL DEFAULT TRUE, - display_order INTEGER NOT NULL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Product_Permutation_Delivery_Option_Link_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); --- Delivery Option Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Permutation_Delivery_Option_Link_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Permutation_Delivery_Option_Link_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_link INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_Delivery_Option_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Product_Permutation_Delivery_Option_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(64) NOT NULL, - value_prev VARCHAR(10), - value_new VARCHAR(10), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_Delivery_Option_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); --- Discounts - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Discount'; - -CREATE TABLE Shop_Discount ( - id_discount INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - code VARCHAR(50) NOT NULL, - name VARCHAR(200) NOT NULL, - id_product INTEGER NOT NULL, - CONSTRAINT FK_Shop_Discount_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - id_permutation INTEGER, - CONSTRAINT FK_Shop_Discount_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation) - ON UPDATE RESTRICT, - /* - id_delivery_region INTEGER, - CONSTRAINT FK_Shop_Discount_id_delivery_region - FOREIGN KEY (id_delivery_region) - REFERENCES Shop_Delivery_Region(id_region) - ON UPDATE RESTRICT, - id_currency INTEGER, - CONSTRAINT FK_Shop_Discount_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency) - ON UPDATE RESTRICT, - */ - multiplier REAL NOT NULL DEFAULT 1 CHECK (multiplier > 0), - subtractor REAL NOT NULL DEFAULT 0, - apply_multiplier_first BOOLEAN NOT NULL DEFAULT TRUE, - quantity_min REAL NOT NULL DEFAULT 0, - quantity_max REAL NOT NULL, - date_start TIMESTAMP NOT NULL, - date_end TIMESTAMP NOT NULL, - active BOOLEAN NOT NULL DEFAULT TRUE, - display_order INTEGER NOT NULL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Discount_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - --- Discount Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Discount_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Discount_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_discount INTEGER NOT NULL, - CONSTRAINT FK_Shop_Discount_Audit_id_discount - FOREIGN KEY (id_discount) - REFERENCES Shop_Discount(id_discount) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(200), - value_new VARCHAR(200), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Discount_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) - ON UPDATE RESTRICT -); --- Discount Region Currency Link - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Discount_Region_Currency_Link'; - -CREATE TABLE IF NOT EXISTS Shop_Discount_Region_Currency_Link ( - id_link INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_discount INTEGER NOT NULL, - CONSTRAINT FK_Shop_Discount_Region_Currency_Link_id_discount - FOREIGN KEY (id_discount) - REFERENCES Shop_Discount(id_discount) - ON UPDATE RESTRICT, - id_region INTEGER NOT NULL, - CONSTRAINT FK_Shop_Discount_Region_Currency_Link_id_region - FOREIGN KEY (id_region) - REFERENCES Shop_Region(id_region) - ON UPDATE RESTRICT, - id_currency INTEGER NOT NULL, - CONSTRAINT FK_Shop_Discount_Region_Currency_Link_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency) - ON UPDATE RESTRICT, - active BOOLEAN NOT NULL DEFAULT TRUE, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Discount_Region_Currency_Link_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); --- Discount Region Currency Link Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Discount_Region_Currency_Link_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Discount_Region_Currency_Link_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_link INTEGER NOT NULL, - CONSTRAINT FK_Shop_Discount_Region_Currency_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Discount_Region_Currency_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(10), - value_new VARCHAR(10), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Discount_Region_Currency_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) - ON UPDATE RESTRICT -); --- Permission Groups - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Permission_Group'; - -CREATE TABLE IF NOT EXISTS Shop_Permission_Group ( - id_group INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - code VARCHAR(50), - name VARCHAR(255), - active BOOLEAN NOT NULL DEFAULT TRUE, - display_order INTEGER NOT NULL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Permission_Group_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - ON UPDATE RESTRICT -); --- Permission Group Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Permission_Group_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Permission_Group_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_group INTEGER NOT NULL, - CONSTRAINT FK_Shop_Permission_Group_Audit_id_group - FOREIGN KEY (id_group) - REFERENCES Shop_Permission_Group(id_group) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(255), - value_new VARCHAR(255), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Permission_Group_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - ON UPDATE RESTRICT -); --- Permissions - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Permission'; - -CREATE TABLE IF NOT EXISTS Shop_Permission ( - id_permission INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - code VARCHAR(50), - name VARCHAR(255), - id_permission_group INTEGER NOT NULL, - CONSTRAINT FK_Shop_Permission_id_permission_group - FOREIGN KEY (id_permission_group) - REFERENCES Shop_Permission_Group(id_group) - ON UPDATE RESTRICT, - id_access_level_required INTEGER NOT NULL, - CONSTRAINT FK_Shop_Permission_id_access_level_required - FOREIGN KEY (id_access_level_required) - REFERENCES Shop_Access_Level(id_access_level), - active BOOLEAN NOT NULL DEFAULT TRUE, - display_order INTEGER NOT NULL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Permission_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); --- Permission Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Permission_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Permission_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_permission INTEGER NOT NULL, - CONSTRAINT FK_Shop_Permission_Audit_id_permission - FOREIGN KEY (id_permission) - REFERENCES Shop_Permission(id_permission) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(255), - value_new VARCHAR(255), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Permission_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - ON UPDATE RESTRICT -); --- Roles - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Role'; - -CREATE TABLE IF NOT EXISTS Shop_Role ( - id_role INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - code VARCHAR(50), - name VARCHAR(255), - active BOOLEAN NOT NULL DEFAULT TRUE, - display_order INTEGER NOT NULL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Role_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); --- Role Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Role_Audit'; - -CREATE TABLE Shop_Role_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_role INTEGER NOT NULL, - CONSTRAINT FK_Shop_Role_Audit_id_role - FOREIGN KEY (id_role) - REFERENCES Shop_Role(id_role) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(255), - value_new VARCHAR(255), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Role_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - ON UPDATE RESTRICT -); --- Role Permission link - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Role_Permission_Link'; - -CREATE TABLE IF NOT EXISTS Shop_Role_Permission_Link ( - id_link INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_role INTEGER, - CONSTRAINT FK_Shop_Role_Permission_Link_id_role - FOREIGN KEY (id_role) - REFERENCES Shop_Role(id_role) - ON UPDATE RESTRICT, - id_permission INTEGER, - CONSTRAINT FK_Shop_Role_Permission_Link_id_permission - FOREIGN KEY (id_permission) - REFERENCES Shop_Permission(id_permission) - ON UPDATE RESTRICT, - id_access_level INTEGER, - CONSTRAINT FK_Shop_Role_Permission_Link_id_access_level - FOREIGN KEY (id_access_level) - REFERENCES Shop_Access_Level(id_access_level), - active BOOLEAN NOT NULL DEFAULT TRUE, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Role_Permission_Link_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); --- Role Permission link Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Role_Permission_Link_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Role_Permission_Link_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_link INTEGER NOT NULL, - CONSTRAINT FK_Shop_Role_Permission_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Role_Permission_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(10), - value_new VARCHAR(10), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Role_Permission_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); --- Users - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User'; - -CREATE TABLE IF NOT EXISTS Shop_User ( - id_user INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_user_oauth VARCHAR(200) NOT NULL, - name VARCHAR(255) NOT NULL, - email VARCHAR(254) NOT NULL, - is_email_verified BOOLEAN NOT NULL DEFAULT FALSE, - is_super_user BOOLEAN NOT NULL DEFAULT FALSE, - active BOOLEAN NOT NULL DEFAULT TRUE, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_User_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); - --- User Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_User_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_user INTEGER, - CONSTRAINT FK_Shop_User_Audit_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(255), - value_new VARCHAR(255), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_User_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - ON UPDATE RESTRICT -); --- User Role link - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Role_Link'; - -CREATE TABLE IF NOT EXISTS Shop_User_Role_Link ( - id_link INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_user INTEGER, - CONSTRAINT FK_Shop_User_Role_Link_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user) - ON UPDATE RESTRICT, - id_role INTEGER NOT NULL, - CONSTRAINT FK_Shop_User_Role_Link_id_role - FOREIGN KEY (id_role) - REFERENCES Shop_Role(id_role), - active BOOLEAN NOT NULL DEFAULT TRUE, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_User_Role_Link_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); --- User Role Link Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Role_Link_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_User_Role_Link_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_link INTEGER NOT NULL, - CONSTRAINT FK_Shop_User_Role_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_User_Role_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(200), - value_new VARCHAR(200), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_User_Role_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); - --- Addresses - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Address'; - -CREATE TABLE Shop_Address ( - id_address INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - /* - a_id_user INTEGER, - CONSTRAINT FK_Shop_Address_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user) - ON UPDATE RESTRICT, - */ - -- region VARCHAR(100) NOT NULL, - id_region INTEGER NOT NULL, - name_full VARCHAR(255) NOT NULL, - phone_number VARCHAR(20) NOT NULL, - postcode VARCHAR(20) NOT NULL, - address_line_1 VARCHAR(100) NOT NULL, - address_line_2 VARCHAR(100) NOT NULL, - city VARCHAR(50) NOT NULL, - county VARCHAR(100) NOT NULL, - active BOOLEAN NOT NULL DEFAULT TRUE, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Address_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); --- Address Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Address_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Address_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_address INTEGER NOT NULL, - CONSTRAINT FK_Shop_Address_Audit_id_address - FOREIGN KEY (id_address) - REFERENCES Shop_Address(id_address) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(255), - value_new VARCHAR(255), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Address_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - ON UPDATE RESTRICT -); --- User Basket (Product Link) - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Basket'; - -CREATE TABLE IF NOT EXISTS Shop_User_Basket ( - id_item INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_user INTEGER, - CONSTRAINT FK_Shop_User_Basket_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user) - ON UPDATE RESTRICT, - id_product INTEGER NOT NULL, - CONSTRAINT FK_Shop_User_Basket_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product) - ON UPDATE RESTRICT, - id_permutation INTEGER, - CONSTRAINT FK_Shop_User_Basket_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation) - ON UPDATE RESTRICT, - quantity INTEGER NOT NULL, - active BOOLEAN NOT NULL DEFAULT TRUE, - created_on TIMESTAMP, - created_by INT, - id_change_set_user INTEGER, - CONSTRAINT FK_Shop_User_Basket_id_change_set_user - FOREIGN KEY (id_change_set_user) - REFERENCES Shop_User_Change_Set(id_change_set) - /* - id_change_set_product INTEGER, - CONSTRAINT FK_Shop_User_Basket_id_change_set_product - FOREIGN KEY (id_change_set_product) - REFERENCES Shop_Product_Change_Set(id_change_set) - */ -); - --- Product Basket Audits - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Basket_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_User_Basket_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_item INTEGER NOT NULL, - CONSTRAINT FK_Shop_User_Basket_Audit_id_link - FOREIGN KEY (id_item) - REFERENCES Shop_User_Basket(id_item) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(200), - value_new VARCHAR(200), - id_change_set_user INTEGER, - CONSTRAINT FK_Shop_User_Basket_Audit_id_change_set_user - FOREIGN KEY (id_change_set_user) - REFERENCES Shop_User_Change_Set(id_change_set) - /* - id_change_set_product INTEGER, - CONSTRAINT FK_Shop_User_Basket_Audit_id_change_set_product - FOREIGN KEY (id_change_set_product) - REFERENCES Shop_Product_Change_Set(id_change_set) - */ -); - --- User Order Types - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Order_Status'; - -CREATE TABLE IF NOT EXISTS Shop_User_Order_Status ( - id_status INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - code VARCHAR(50), - name VARCHAR(255), - name_plural VARCHAR(256), - active BOOLEAN NOT NULL DEFAULT TRUE, - display_order INTEGER NOT NULL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_User_Order_Status_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); - --- Order Type Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Order_Status_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_User_Order_Status_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_status INTEGER NOT NULL, - CONSTRAINT FK_Shop_User_Order_Status_Audit_id_status - FOREIGN KEY (id_status) - REFERENCES Shop_User_Order_Status(id_status) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(256), - value_new VARCHAR(256), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_User_Order_Status_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); --- Supplier - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Supplier'; - -CREATE TABLE IF NOT EXISTS Shop_Supplier ( - id_supplier INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - name_company VARCHAR(255) NOT NULL, - name_contact VARCHAR(255) NULL, - department_contact VARCHAR(255) NULL, - id_address INTEGER NOT NULL, - CONSTRAINT FK_Shop_Supplier_id_address - FOREIGN KEY (id_address) - REFERENCES Shop_Address(id_address), - phone_number VARCHAR(50) NULL, - fax VARCHAR(50) NULL, - email VARCHAR(255) NOT NULL, - website VARCHAR(255) NULL, - id_currency INTEGER NOT NULL, - CONSTRAINT FK_Shop_Supplier_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency), - active BOOLEAN NOT NULL DEFAULT TRUE, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Supplier_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); - --- Supplier Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Supplier_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Supplier_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_supplier INTEGER NOT NULL, - CONSTRAINT FK_Shop_Supplier_Audit_id_supplier - FOREIGN KEY (id_supplier) - REFERENCES Shop_Supplier(id_supplier) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(255), - value_new VARCHAR(255), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Supplier_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); - --- Unit of Measurement - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Unit_Measurement'; - -CREATE TABLE IF NOT EXISTS Shop_Unit_Measurement ( - id_unit_measurement INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - name_singular VARCHAR(255) NOT NULL, - name_plural VARCHAR(256) NOT NULL, - symbol VARCHAR(50) NOT NULL, - is_base_unit BOOLEAN NOT NULL DEFAULT FALSE, - - active BOOLEAN NOT NULL DEFAULT TRUE, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Unit_Measurement_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - --- Unit of Measurement Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Unit_Measurement_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Unit_Measurement_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_unit_measurement INTEGER NOT NULL, - CONSTRAINT FK_Shop_Unit_Measurement_Audit_id_unit_measurement - FOREIGN KEY (id_unit_measurement) - REFERENCES Shop_Unit_Measurement(id_unit_measurement) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(256), - value_new VARCHAR(256), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Unit_Measurement_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - --- Unit of Measurement Conversion - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Unit_Measurement_Conversion'; - -CREATE TABLE IF NOT EXISTS Shop_Unit_Measurement_Conversion ( - id_conversion INTEGER NOT NULL PRIMARY KEY, - id_unit_derived INTEGER NOT NULL, - id_unit_base INTEGER NOT NULL, - power_unit_base REAL NOT NULL, - multiplier_unit_base REAL NOT NULL, - increment_unit_base REAL NOT NULL, - active BOOLEAN NOT NULL DEFAULT TRUE, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Unit_Measurement_Conversion_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - --- Unit of Measurement Conversion Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Unit_Measurement_Conversion_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Unit_Measurement_Conversion_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_conversion INTEGER NOT NULL, - CONSTRAINT FK_Shop_Unit_Measurement_Conversion_Audit_id_conversion - FOREIGN KEY (id_conversion) - REFERENCES Shop_Unit_Measurement_Conversion(id_conversion) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(100), - value_new VARCHAR(100), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Unit_Measurement_Conversion_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); - --- Supplier Purchase Order - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Supplier_Purchase_Order'; - -CREATE TABLE IF NOT EXISTS Shop_Supplier_Purchase_Order ( - id_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_supplier_ordered INTEGER NOT NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_id_supplier_ordered - FOREIGN KEY (id_supplier_ordered) - REFERENCES Shop_Supplier(id_supplier), - /* - id_supplier_fulfilled INTEGER NOT NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_id_supplier_fulfilled - FOREIGN KEY (id_supplier_fulfilled) - REFERENCES Shop_Supplier(id_supplier), - */ - cost_total_local REAL NOT NULL, - id_currency_cost INTEGER NOT NULL, - /* - latency_delivery INTEGER NOT NULL, - quantity_ordered REAL NOT NULL, - id_unit_quantity INTEGER NOT NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit), - -- quantity_received INTEGER NULL, - display_order INTEGER NOT NULL, - */ - active BOOLEAN NOT NULL DEFAULT TRUE, - created_on TIMESTAMP, - created_by INT, - updated_last_on TIMESTAMP NULL, - created_last_by VARCHAR(100) NULL, - id_change_set INTEGER NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); - --- Supplier Purchase Order Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Supplier_Purchase_Order_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Supplier_Purchase_Order_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_order INTEGER NOT NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_Audit_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Supplier_Purchase_Order(id_order) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(10), - value_new VARCHAR(10), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); - --- Supplier Purchase Order Product Link - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Supplier_Purchase_Order_Product_Link'; - -CREATE TABLE IF NOT EXISTS Shop_Supplier_Purchase_Order_Product_Link ( - id_link INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_order INTEGER NOT NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_Product_Link_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Supplier_Purchase_Order(id_order), - id_permutation INTEGER NOT NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_Product_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - cost_total_local REAL NOT NULL, - id_currency_cost INTEGER NOT NULL, - quantity_ordered REAL NOT NULL, - id_unit_quantity INTEGER NOT NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_Product_Link_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - quantity_received REAL NULL, - latency_delivery_days INTEGER NOT NULL, - display_order INTEGER NOT NULL, - active BOOLEAN NOT NULL, - created_on TIMESTAMP, - created_by INT, - updated_last_on TIMESTAMP NULL, - created_last_by VARCHAR(100) NULL, - id_change_set INTEGER NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_Product_Link_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); - --- Supplier Purchase Order Product Link Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Supplier_Purchase_Order_Product_Link_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Supplier_Purchase_Order_Product_Link_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_link INTEGER NOT NULL, - CONSTRAINT FK_Supplier_Purch_Order_Product_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Supplier_Purchase_Order_Product_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(10), - value_new VARCHAR(10), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Supplier_Purch_Order_Product_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); - --- Supplier Purchase Order Product Link Temp - - - --- drop table Shop_Supplier_Purchase_Order_Product_Link_Temp; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Supplier_Purchase_Order_Product_Link_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Supplier_Purchase_Order_Product_Link_Temp ( - id_link INTEGER NOT NULL PRIMARY KEY, - GUID UUID NOT NULL, - id_order INTEGER NOT NULL, - /* - CONSTRAINT FK_Supplier_Purchase_Order_Product_Link_Temp_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Supplier_Purchase_Order(id_order), - */ - id_permutation INTEGER NOT NULL, - CONSTRAINT FK_Supplier_Purchase_Order_Product_Link_Temp_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - cost_total_local REAL NOT NULL, - id_currency_cost INTEGER NOT NULL, - quantity_ordered REAL NOT NULL, - id_unit_quantity INTEGER NOT NULL, - CONSTRAINT FK_Supplier_Purchase_Order_Product_Link_Temp_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - quantity_received REAL NULL, - latency_delivery_days INTEGER NOT NULL, - display_order INTEGER NOT NULL, - active BOOLEAN NOT NULL -); - - --- Manufacturing Purchase Order - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Manufacturing_Purchase_Order'; - -CREATE TABLE IF NOT EXISTS Shop_Manufacturing_Purchase_Order ( - id_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - cost_total_local REAL NOT NULL, - id_currency_cost INTEGER NOT NULL, - value_produced_total_local REAL NOT NULL, - /* - latency_delivery INTEGER NOT NULL, - quantity_ordered REAL NOT NULL, - id_unit_quantity INTEGER NOT NULL, - CONSTRAINT FK_Shop_Manufacturing_Purchase_Order_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit), - quantity_received INTEGER NULL, - display_order INTEGER NOT NULL, - */ - active BOOLEAN NOT NULL DEFAULT TRUE, - created_on TIMESTAMP, - created_by INT, - updated_last_on TIMESTAMP NULL, - created_last_by VARCHAR(100) NULL, - id_change_set INTEGER NULL, - CONSTRAINT FK_Shop_Manufacturing_Purchase_Order_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); - --- Manufacturing Purchase Order Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Manufacturing_Purchase_Order_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Manufacturing_Purchase_Order_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_order INTEGER NOT NULL, - CONSTRAINT FK_Shop_Manufacturing_Purchase_Order_Audit_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Manufacturing_Purchase_Order(id_order) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(10), - value_new VARCHAR(10), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Manufacturing_Purchase_Order_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); - --- Manufacturing Purchase Order Product Link - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Manufacturing_Purchase_Order_Product_Link'; - -CREATE TABLE IF NOT EXISTS Shop_Manufacturing_Purchase_Order_Product_Link ( - id_link INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_order INTEGER NOT NULL, - CONSTRAINT FK_Manufacturing_Purchase_Order_Product_Link_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Manufacturing_Purchase_Order(id_order), - id_permutation INTEGER NOT NULL, - CONSTRAINT FK_Manufacturing_Purchase_Order_Product_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - cost_total_local REAL NOT NULL, - id_currency_cost INTEGER NOT NULL, - value_produced_total_local REAL NOT NULL, - quantity_used REAL NOT NULL, - id_unit_quantity INTEGER NOT NULL, - CONSTRAINT FK_Manufacturing_Purchase_Order_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - latency_manufacture INTEGER NOT NULL, - quantity_produced REAL NOT NULL, - display_order INTEGER NOT NULL, - active BOOLEAN NOT NULL, - created_on TIMESTAMP, - created_by INT, - updated_last_on TIMESTAMP NULL, - created_last_by VARCHAR(100) NULL, - id_change_set INTEGER NULL, - CONSTRAINT FK_Manufacturing_Purchase_Order_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); - --- Manufacturing Purchase Order Product Link Temp - - - --- DROP TABLE Shop_Manufacturing_Purchase_Order_Product_Link_Temp; --- SELECT * FROM Shop_Manufacturing_Purchase_Order_Product_Link_Temp; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Manufacturing_Purchase_Order_Product_Link_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Manufacturing_Purchase_Order_Product_Link_Temp ( - id_link INTEGER NOT NULL PRIMARY KEY, - GUID UUID NOT NULL, - id_order INTEGER NOT NULL, - /* - CONSTRAINT FK_Manuf_Purch_Order_Product_Link_Temp_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Manufacturing_Purchase_Order(id_order), - */ - id_permutation INTEGER NOT NULL, - CONSTRAINT FK_Manuf_Purch_Order_Product_Link_Temp_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - cost_total_local REAL NOT NULL, - id_currency_cost INTEGER NOT NULL, - quantity_used REAL NOT NULL, - id_unit_quantity INTEGER NOT NULL, - CONSTRAINT FK_Manuf_Purch_Order_Product_Link_Temp_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - quantity_produced REAL NULL, - latency_manufacture INTEGER NOT NULL, - display_order INTEGER NOT NULL, - active BOOLEAN NOT NULL -); - --- Manufacturing Purchase Order Product Link Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Manufacturing_Purchase_Order_Product_Link_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Manufacturing_Purchase_Order_Product_Link_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_link INTEGER NOT NULL, - CONSTRAINT FK_Manufacturing_Purch_Order_Product_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Manufacturing_Purchase_Order_Product_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(10), - value_new VARCHAR(10), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Manufacturing_Purch_Order_Product_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); --- Customer - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Customer'; - -CREATE TABLE IF NOT EXISTS Shop_Customer ( - id_customer INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - name_company VARCHAR(255) NOT NULL, - name_contact VARCHAR(255) NULL, - department_contact VARCHAR(255) NULL, - id_address INTEGER NOT NULL, - CONSTRAINT FK_Shop_Customer_id_address - FOREIGN KEY (id_address) - REFERENCES Shop_Address(id_address), - phone_number VARCHAR(50) NULL, - email VARCHAR(255) NOT NULL, - id_currency INTEGER NOT NULL, - CONSTRAINT FK_Shop_Customer_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency), - active BOOLEAN NOT NULL DEFAULT TRUE, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Customer_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); - --- Customer Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Customer_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Customer_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_customer INTEGER NOT NULL, - CONSTRAINT FK_Shop_Customer_Audit_id_customer - FOREIGN KEY (id_customer) - REFERENCES Shop_Customer(id_customer) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(255), - value_new VARCHAR(255), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Customer_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); - --- Customer Sales Purchase Order - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Customer_Sales_Order'; - -CREATE TABLE IF NOT EXISTS Shop_Customer_Sales_Order ( - id_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_customer INTEGER NOT NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_id_customer - FOREIGN KEY (id_customer) - REFERENCES Shop_Customer(id_customer), - price_total_local REAL NOT NULL, - id_currency_price INTEGER NOT NULL, - /* - latency_delivery INTEGER NOT NULL, - quantity_ordered REAL NOT NULL, - id_unit_quantity INTEGER NOT NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit), - quantity_received INTEGER NULL, - display_order INTEGER NOT NULL, - */ - active BOOLEAN NOT NULL DEFAULT TRUE, - created_on TIMESTAMP, - created_by INT, - updated_last_on TIMESTAMP NULL, - created_last_by VARCHAR(100) NULL, - id_change_set INTEGER NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); - --- Customer Sales Order Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Customer_Sales_Order_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Customer_Sales_Order_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_order INTEGER NOT NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_Audit_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Customer_Sales_Order(id_order) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(10), - value_new VARCHAR(10), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); - --- Customer Sales Order Product Link - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Customer_Sales_Order_Product_Link'; - -CREATE TABLE IF NOT EXISTS Shop_Customer_Sales_Order_Product_Link ( - id_link INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_order INTEGER NOT NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_Product_Link_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Customer_Sales_Order(id_order), - id_permutation INTEGER NOT NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_Product_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - price_total_local REAL NOT NULL, - id_currency_price INTEGER NOT NULL, - quantity_ordered REAL NOT NULL, - id_unit_quantity INTEGER NOT NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_Product_Link_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - quantity_delivered REAL NOT NULL, - latency_delivery_days INTEGER NOT NULL, - display_order INTEGER NOT NULL, - - active BOOLEAN NOT NULL, - created_on TIMESTAMP, - created_by INT, - updated_last_on TIMESTAMP NULL, - created_last_by VARCHAR(100) NULL, - id_change_set INTEGER NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_Product_Link_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); - --- Customer Sales Order Product Link Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Customer_Sales_Order_Product_Link_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Customer_Sales_Order_Product_Link_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_link INTEGER NOT NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_Product_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Customer_Sales_Order_Product_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(10), - value_new VARCHAR(10), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_Product_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); - --- Customer Sales Order Product Link Temp - - - --- DROP TABLE Shop_Customer_Sales_Order_Product_Link_Temp; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Customer_Sales_Order_Product_Link_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Customer_Sales_Order_Product_Link_Temp ( - id_link INTEGER NOT NULL PRIMARY KEY, - GUID UUID NOT NULL, - id_order INTEGER NOT NULL, - /* - CONSTRAINT FK_Customer_Sales_Order_Product_Link_Temp_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Customer_Sales_Order(id_order), - */ - id_permutation INTEGER NOT NULL, - CONSTRAINT FK_Customer_Sales_Order_Product_Link_Temp_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - price_total_local REAL NOT NULL, - id_currency_price INTEGER NOT NULL, - quantity_ordered REAL NOT NULL, - id_unit_quantity INTEGER NOT NULL, - CONSTRAINT FK_Customer_Sales_Order_Product_Link_Temp_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - quantity_delivered REAL NULL, - latency_delivery_days INTEGER NOT NULL, - display_order INTEGER NOT NULL, - active BOOLEAN NOT NULL -); - -DO $$ -BEGIN - RAISE NOTICE 'TABLE CREATION COMPLETE'; -END $$; - --- Product Change Set - -CREATE OR REPLACE FUNCTION before_insert_Shop_Sales_And_Purchasing_Change_Set() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.updated_last_on IS NULL THEN - NEW.updated_last_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.updated_last_by IS NULL THEN - NEW.updated_last_by = CURRENT_USER; - END IF; - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Sales_And_Purchasing_Change_Set -BEFORE INSERT ON Shop_Sales_And_Purchasing_Change_Set -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Sales_And_Purchasing_Change_Set(); - - --- Shop User Change Set - -CREATE OR REPLACE FUNCTION before_insert_Shop_User_Change_Set() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.updated_last_on IS NULL THEN - NEW.updated_last_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.updated_last_by IS NULL THEN - NEW.updated_last_by = CURRENT_USER; - END IF; - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_User_Change_Set -BEFORE INSERT ON Shop_User_Change_Set -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_User_Change_Set(); - --- Shop Access Level - -CREATE OR REPLACE FUNCTION before_insert_Shop_Access_Level() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Access_Level -BEFORE INSERT ON Shop_Access_Level -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Access_Level(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Access_Level() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Access_Level_Audit ( - id_access_level, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_access_level, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT (OLD.code <=> NEW.code) - UNION - -- Changed name - SELECT NEW.id_access_level, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT (OLD.name <=> NEW.name) - UNION - -- Changed priority - SELECT NEW.id_access_level, 'priority', CONVERT(OLD.priority, CHAR), CONVERT(NEW.priority, CHAR), NEW.id_change_set - WHERE NOT (OLD.priority <=> NEW.priority) - UNION - -- Changed active - SELECT NEW.id_access_level, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_access_level, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Access_Level -BEFORE UPDATE ON Shop_Access_Level -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Access_Level(); - --- Product Change Set - - - -CREATE OR REPLACE FUNCTION before_insert_Shop_Product_Change_Set() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.updated_last_on IS NULL THEN - NEW.updated_last_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.updated_last_by IS NULL THEN - NEW.updated_last_by = CURRENT_USER; - END IF; - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Product_Change_Set -BEFORE INSERT ON Shop_Product_Change_Set -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Product_Change_Set(); - --- File Type - -CREATE OR REPLACE FUNCTION before_insert_File_Type() -RETURNS TRIGGER AS $$ -BEGIN - NEW.created_on = CURRENT_TIMESTAMP; - NEW.created_by = CURRENT_USER; - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_File_Type -BEFORE INSERT ON File_Type -FOR EACH ROW -EXECUTE FUNCTION before_insert_File_Type(); - - -CREATE OR REPLACE FUNCTION before_update_File_Type() -RETURNS TRIGGER AS $$ -BEGIN - INSERT INTO File_Type_Audit ( - id_type, - name_field, - value_prev, - value_new - ) - -- Changed code - SELECT NEW.id_type, 'code', OLD.code, NEW.code - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_type, 'name', OLD.name, NEW.name - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed extension - SELECT NEW.id_type, 'extension', CONVERT(OLD.extension, CHAR), CONVERT(NEW.extension, CHAR) - WHERE NOT OLD.extension <=> NEW.extension - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_File_Type -BEFORE UPDATE ON File_Type -FOR EACH ROW -EXECUTE FUNCTION before_update_File_Type(); - --- File Type Audits - -CREATE OR REPLACE FUNCTION before_insert_File_Type_Audit() -RETURNS TRIGGER AS $$ -BEGIN - NEW.created_on = CURRENT_TIMESTAMP; - NEW.created_by = CURRENT_USER; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_File_Type_Audit -BEFORE INSERT ON File_Type_Audit -FOR EACH ROW -EXECUTE FUNCTION before_insert_File_Type_Audit(); - - -CREATE OR REPLACE FUNCTION before_update_File_Type_Audit() -RETURNS TRIGGER AS $$ -BEGIN - NEW.updated_last_on = CURRENT_TIMESTAMP; - NEW.updated_last_by = CURRENT_USER; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_File_Type_Audit -BEFORE UPDATE ON File_Type_Audit -FOR EACH ROW -EXECUTE FUNCTION before_update_File_Type_Audit(); --- Shop General - -CREATE OR REPLACE FUNCTION before_insert_Shop_General() -RETURNS TRIGGER AS $$ -BEGIN - NEW.created_on = CURRENT_TIMESTAMP; - NEW.created_by = CURRENT_USER; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_General -BEFORE INSERT ON Shop_General -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_General(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_General() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_General_Audit ( - id_general, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed quantity max - SELECT NEW.id_general, 'quantity_max', CONVERT(OLD.quantity_max, CHAR), CONVERT(NEW.quantity_max, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_General -BEFORE UPDATE ON Shop_General -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_General(); --- Shop Category - -CREATE OR REPLACE FUNCTION before_insert_Shop_Product_Category() -RETURNS TRIGGER AS $$ -BEGIN - NEW.created_on = CURRENT_TIMESTAMP; - NEW.created_by = CURRENT_USER; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Product_Category -BEFORE INSERT ON Shop_Product_Category -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Product_Category(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Product_Category() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Product_Category_Audit ( - id_category, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_category, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_category, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed description - SELECT NEW.id_category, 'description', OLD.description, NEW.description, NEW.id_change_set - WHERE NOT OLD.description <=> NEW.description - UNION - -- Changed active - SELECT NEW.id_category, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_category, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Product_Category -BEFORE UPDATE ON Shop_Product_Category -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Product_Category(); - --- Shop Recurrence Interval - -CREATE OR REPLACE FUNCTION before_insert_Shop_Interval_Recurrence() -RETURNS TRIGGER AS $$ -BEGIN - NEW.created_on = CURRENT_TIMESTAMP; - NEW.created_by = CURRENT_USER; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Interval_Recurrence -BEFORE INSERT ON Shop_Interval_Recurrence -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Interval_Recurrence(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Interval_Recurrence() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Interval_Recurrence_Audit ( - id_interval, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_interval, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_interval, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed name_plural - SELECT NEW.id_interval, 'name_plural', OLD.name_plural, NEW.name_plural, NEW.id_change_set - WHERE NOT OLD.name_plural <=> NEW.name_plural - UNION - -- Changed name - SELECT NEW.id_interval, 'active', OLD.active, NEW.active, NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Interval_Recurrence -BEFORE UPDATE ON Shop_Interval_Recurrence -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Interval_Recurrence(); - --- Shop Delivery Region - -CREATE OR REPLACE FUNCTION before_insert_Shop_Region() -RETURNS TRIGGER AS $$ -BEGIN - NEW.created_on = CURRENT_TIMESTAMP; - NEW.created_by = CURRENT_USER; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Region -BEFORE INSERT ON Shop_Region -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Region(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Region() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Region_Audit ( - id_region, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_region, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_region, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed active - SELECT NEW.id_region, 'active', CONVERT(OLD.active, CHAR), CONVERT(NEW.active, CHAR), NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - UNION - -- Changed display_order - SELECT NEW.id_region, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Region -BEFORE UPDATE ON Shop_Region -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Region(); - --- Shop Region Branch - -CREATE OR REPLACE FUNCTION before_insert_Shop_Region_Branch() -RETURNS TRIGGER AS $$ -BEGIN - NEW.created_on = CURRENT_TIMESTAMP; - NEW.created_by = CURRENT_USER; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Region_Branch -BEFORE INSERT ON Shop_Region_Branch -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Region_Branch(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Region_Branch() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Region_Branch_Audit ( - id_branch, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed depth - SELECT NEW.id_branch, 'depth', CONVERT(OLD.depth, CHAR), CONVERT(NEW.depth, CHAR), NEW.id_change_set - WHERE NOT OLD.depth <=> NEW.depth - UNION - */ - -- Changed active - SELECT NEW.id_branch, 'active', CONVERT(OLD.active, CHAR), CONVERT(NEW.active, CHAR), NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - UNION - -- Changed display_order - SELECT NEW.id_branch, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Region_Branch -BEFORE UPDATE ON Shop_Region_Branch -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Region_Branch(); - --- Shop Currency - -CREATE OR REPLACE FUNCTION before_insert_Shop_Currency() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Currency -BEFORE INSERT ON Shop_Currency -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Currency(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Currency() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Currency_Audit ( - id_currency, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_currency, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_currency, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed symbol - SELECT NEW.id_currency, 'symbol', OLD.symbol, NEW.symbol, NEW.id_change_set - WHERE NOT OLD.symbol <=> NEW.symbol - UNION - -- Changed ratio_2_GBP - SELECT NEW.id_currency, 'factor_from_GBP', OLD.factor_from_GBP, NEW.factor_from_GBP, NEW.id_change_set - WHERE NOT OLD.factor_from_GBP <=> NEW.factor_from_GBP - UNION - -- Changed active - SELECT NEW.id_currency, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_currency, 'display_order', CONVERT(display_order, CHAR), CONVERT(display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Currency -BEFORE UPDATE ON Shop_Currency -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Currency(); - --- Shop Tax_Or_Surcharge - -CREATE OR REPLACE FUNCTION before_insert_Shop_Tax_Or_Surcharge() -RETURNS TRIGGER AS $$ -BEGIN - NEW.created_on = CURRENT_TIMESTAMP; - NEW.created_by = CURRENT_USER; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Tax_Or_Surcharge -BEFORE INSERT ON Shop_Tax_Or_Surcharge -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Tax_Or_Surcharge(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Tax_Or_Surcharge() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Tax_Or_Surcharge_Audit ( - id_tax, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_tax, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_tax, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed fixed_fee - SELECT NEW.id_tax, 'fixed_fee', OLD.fixed_fee, NEW.fixed_fee, NEW.id_change_set - WHERE NOT OLD.fixed_fee <=> NEW.fixed_fee - UNION - -- Changed multiplier - SELECT NEW.id_tax, 'multiplier', OLD.multiplier, NEW.multiplier, NEW.id_change_set - WHERE NOT OLD.multiplier <=> NEW.multiplier - UNION - -- Changed apply_fixed_fee_before_multiplier - SELECT NEW.id_tax, 'apply_fixed_fee_before_multiplier', CONVERT(CONVERT(OLD.apply_fixed_fee_before_multiplier, SIGNED), CHAR), CONVERT(CONVERT(NEW.apply_fixed_fee_before_multiplier, SIGNED), CHAR), NEW.id_change_set - WHERE NOT OLD.apply_fixed_fee_before_multiplier <=> NEW.apply_fixed_fee_before_multiplier - UNION - -- Changed quantity_min - SELECT NEW.id_tax, 'quantity_min', OLD.quantity_min, NEW.quantity_min, NEW.id_change_set - WHERE NOT OLD.quantity_min <=> NEW.quantity_min - UNION - -- Changed quantity_max - SELECT NEW.id_tax, 'quantity_max', OLD.quantity_max, NEW.quantity_max, NEW.id_change_set - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - UNION - -- Changed display_order - SELECT NEW.id_tax, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - UNION - -- Changed active - SELECT NEW.id_tax, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Tax_Or_Surcharge -BEFORE UPDATE ON Shop_Tax_Or_Surcharge -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Tax_Or_Surcharge(); - - --- Shop Product - -CREATE OR REPLACE FUNCTION before_insert_Shop_Product() -RETURNS TRIGGER AS $$ -BEGIN - NEW.created_on = CURRENT_TIMESTAMP; - NEW.created_by = CURRENT_USER; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Product -BEFORE INSERT ON Shop_Product -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Product(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Product() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - /* - IF NOT NEW.has_variations THEN - IF ISNULL(NEW.price_GBP_full) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have price or variations (with prices).'; - END IF; - IF ISNULL(NEW.price_GBP_min) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have minimum price or variations (with prices).'; - END IF; - IF ISNULL(NEW.latency_manuf) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have manufacturing latency or variations (with manufacturing latencies).'; - END IF; - IF ISNULL(NEW.quantity_min) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have minimum quantity or variations (with minimum quantities).'; - END IF; - IF ISNULL(NEW.quantity_max) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have maximum quantity or variations (with maximum quantities).'; - END IF; - IF ISNULL(NEW.quantity_step) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have increment of quantity or variations (with increments of quantities).'; - END IF; - IF ISNULL(NEW.quantity_stock) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have stock quantity or variations (with stock quantities).'; - END IF; - IF ISNULL(NEW.is_subscription) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have subscription status or variations (with subscription statuses).'; - END IF; - IF ISNULL(NEW.id_unit_measurement_interval_recurrence) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have recurrence interval or variations (with recurrence intervals).'; - END IF; - IF ISNULL(NEW.count_interval_recurrence) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have recurrence interval count or variations (with recurrence interval counts).'; - END IF; - END IF; - */ - - INSERT INTO Shop_Product_Audit ( - id_product, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed name - SELECT NEW.id_product, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - /* - UNION - -- Changed description - SELECT NEW.id_product, 'description', OLD.description, NEW.description, NEW.id_change_set - WHERE NOT OLD.description <=> NEW.description - UNION - -- Changed price_GBP_full - SELECT NEW.id_product, 'price_GBP_full', CONVERT(OLD.price_GBP_full, CHAR), CONVERT(NEW.price_GBP_full, CHAR), NEW.id_change_set - WHERE NOT OLD.price_GBP_full <=> NEW.price_GBP_full - UNION - -- Changed price_GBP_min - SELECT NEW.id_product, 'price_GBP_min', CONVERT(OLD.price_GBP_min, CHAR), CONVERT(NEW.price_GBP_min, CHAR), NEW.id_change_set - WHERE NOT OLD.price_GBP_min <=> NEW.price_GBP_min - UNION - / - -- Changed discount - SELECT NEW.id_product, 'discount', CONVERT(OLD.discount, CHAR), CONVERT(NEW.discount, CHAR), NEW.id_change_set - WHERE NOT OLD.discount <=> NEW.discount - */ - UNION - -- Changed id_category - SELECT NEW.id_product, 'id_category', CONVERT(OLD.id_category, CHAR), CONVERT(NEW.id_category, CHAR), NEW.id_change_set - WHERE NOT OLD.id_category <=> NEW.id_category - UNION - -- Changed has_variations - SELECT NEW.id_product, 'has_variations', CONVERT(CONVERT(NEW.has_variations, SIGNED), CHAR), CONVERT(CONVERT(NEW.has_variations, SIGNED), CHAR), NEW.id_change_set - WHERE NOT OLD.has_variations <=> NEW.has_variations - /* - UNION - -- Changed latency_manuf - SELECT NEW.id_product, 'latency_manuf', CONVERT(OLD.latency_manuf, CHAR), CONVERT(NEW.latency_manuf, CHAR), NEW.id_change_set - WHERE NOT OLD.latency_manuf <=> NEW.latency_manuf - UNION - -- Changed quantity_min - SELECT NEW.id_product, 'quantity_min', CONVERT(OLD.quantity_min, CHAR), CONVERT(NEW.quantity_min, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_min <=> NEW.quantity_min - UNION - -- Changed quantity_max - SELECT NEW.id_product, 'quantity_max', CONVERT(OLD.quantity_max, CHAR), CONVERT(NEW.quantity_max, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - UNION - -- Changed quantity_step - SELECT NEW.id_product, 'quantity_step', CONVERT(OLD.quantity_step, CHAR), CONVERT(NEW.quantity_step, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_step <=> NEW.quantity_step - UNION - -- Changed quantity_stock - SELECT NEW.id_product, 'quantity_stock', CONVERT(OLD.quantity_stock, CHAR), CONVERT(NEW.quantity_stock, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_stock <=> NEW.quantity_stock - UNION - -- Changed is_subscription - SELECT NEW.id_product, 'is_subscription', CONVERT(CONVERT(OLD.is_subscription, SIGNED), CHAR), CONVERT(CONVERT(NEW.is_subscription, SIGNED), CHAR), NEW.id_change_set - WHERE NOT OLD.is_subscription <=> NEW.is_subscription - UNION - -- Changed id_unit_measurement_interval_recurrence - SELECT NEW.id_product, 'id_unit_measurement_interval_recurrence', CONVERT(OLD.id_unit_measurement_interval_recurrence, CHAR), CONVERT(NEW.id_unit_measurement_interval_recurrence, CHAR), NEW.id_change_set - WHERE NOT OLD.id_unit_measurement_interval_recurrence <=> NEW.id_unit_measurement_interval_recurrence - UNION - -- Changed count_interval_recurrence - SELECT NEW.id_product, 'count_interval_recurrence', CONVERT(OLD.count_interval_recurrence, CHAR), CONVERT(NEW.count_interval_recurrence, CHAR), NEW.id_change_set - WHERE NOT OLD.count_interval_recurrence <=> NEW.count_interval_recurrence - UNION - -- Changed id_stripe_product - SELECT NEW.id_product, 'id_stripe_product', OLD.id_stripe_product, NEW.id_stripe_product, NEW.id_change_set - WHERE NOT OLD.id_stripe_product <=> NEW.id_stripe_product - / - UNION - -- Changed id_stripe_price - SELECT NEW.id_product, 'id_stripe_price', OLD.id_stripe_price, NEW.id_stripe_price, NEW.id_change_set - WHERE NOT OLD.id_stripe_price <=> NEW.id_stripe_price - */ - UNION - -- Changed id_access_level_required - SELECT NEW.id_product, 'id_access_level_required', CONVERT(OLD.id_access_level_required, CHAR), CONVERT(NEW.id_access_level_required, CHAR), NEW.id_change_set - WHERE NOT OLD.id_access_level_required <=> NEW.id_access_level_required - UNION - -- Changed active - SELECT NEW.id_product, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_product, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Product -BEFORE UPDATE ON Shop_Product -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Product(); - --- Shop Variation Type - -CREATE OR REPLACE FUNCTION before_insert_Shop_Variation_Type() -RETURNS TRIGGER AS $$ -BEGIN - NEW.created_on = CURRENT_TIMESTAMP; - NEW.created_by = CURRENT_USER; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Variation_Type -BEFORE INSERT ON Shop_Variation_Type -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Variation_Type(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Variation_Type() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Variation_Type_Audit ( - id_type, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_type, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_type, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed name_plural - SELECT NEW.id_type, 'name_plural', OLD.name_plural, NEW.name_plural, NEW.id_change_set - WHERE NOT OLD.name_plural <=> NEW.name_plural - UNION - -- Changed active - SELECT NEW.id_type, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_type, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Variation_Type -BEFORE UPDATE ON Shop_Variation_Type -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Variation_Type(); - --- Shop Variation - -CREATE OR REPLACE FUNCTION before_insert_Shop_Variation() -RETURNS TRIGGER AS $$ -BEGIN - NEW.created_on = CURRENT_TIMESTAMP; - NEW.created_by = CURRENT_USER; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Variation -BEFORE INSERT ON Shop_Variation -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Variation(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Variation() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Variation_Audit ( - id_variation, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_variation, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_variation, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed active - SELECT NEW.id_variation, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_variation, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Variation -BEFORE UPDATE ON Shop_Variation -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Variation(); - --- Shop Product Permutation - -CREATE OR REPLACE FUNCTION before_insert_Shop_Product_Permutation() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Product_Permutation -BEFORE INSERT ON Shop_Product_Permutation -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Product_Permutation(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Product_Permutation() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Product_Permutation_Audit ( - id_permutation, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_product - SELECT NEW.id_permutation, 'id_product', OLD.id_product, NEW.id_product, NEW.id_change_set - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed id_variation - SELECT NEW.id_permutation, 'id_variation', OLD.id_variation, NEW.id_variation, NEW.id_change_set - WHERE NOT OLD.id_variation <=> NEW.id_variation - UNION - -- Changed name - SELECT NEW.id_permutation, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT (OLD.name <=> NEW.name) - UNION - */ - -- Changed description - SELECT NEW.id_permutation, 'description', OLD.description, NEW.description, NEW.id_change_set - WHERE NOT (OLD.description <=> NEW.description) - UNION - -- Changed cost_local - SELECT NEW.id_permutation, 'cost_local', CONVERT(OLD.cost_local, CHAR), CONVERT(NEW.cost_local, CHAR), NEW.id_change_set - WHERE NOT (OLD.cost_local <=> NEW.cost_local) - UNION - -- Changed id_currency_cost - SELECT NEW.id_permutation, 'id_currency_cost', CONVERT(OLD.id_currency_cost, CHAR), CONVERT(NEW.id_currency_cost, CHAR), NEW.id_change_set - WHERE NOT (OLD.id_currency_cost <=> NEW.id_currency_cost) - UNION - -- Changed profit_local_min - SELECT NEW.id_permutation, 'profit_local_min', CONVERT(OLD.profit_local_min, CHAR), CONVERT(NEW.profit_local_min, CHAR), NEW.id_change_set - WHERE NOT (OLD.profit_local_min <=> NEW.profit_local_min) - UNION - /* - -- Changed id_currency_profit_min - SELECT NEW.id_permutation, 'id_currency_profit_min', CONVERT(OLD.id_currency_profit_min, CHAR), CONVERT(NEW.id_currency_profit_min, CHAR), NEW.id_change_set - WHERE NOT (OLD.id_currency_profit_min <=> NEW.id_currency_profit_min) - UNION - */ - /* - -- Changed price_GBP_min - SELECT NEW.id_permutation, 'price_GBP_min', CONVERT(OLD.price_GBP_min, CHAR), CONVERT(NEW.price_GBP_min, CHAR), NEW.id_change_set - WHERE NOT (OLD.price_GBP_min <=> NEW.price_GBP_min) - UNION - */ - -- Changed latency_manufacture - SELECT NEW.id_product, 'latency_manufacture', CONVERT(OLD.latency_manufacture, CHAR), CONVERT(NEW.latency_manufacture, CHAR), NEW.id_change_set - WHERE NOT OLD.latency_manufacture <=> NEW.latency_manufacture - UNION - -- Changed quantity_min - SELECT NEW.id_product, 'quantity_min', CONVERT(OLD.quantity_min, CHAR), CONVERT(NEW.quantity_min, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_min <=> NEW.quantity_min - UNION - -- Changed quantity_max - SELECT NEW.id_product, 'quantity_max', CONVERT(OLD.quantity_max, CHAR), CONVERT(NEW.quantity_max, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - UNION - -- Changed quantity_step - SELECT NEW.id_product, 'quantity_step', CONVERT(OLD.quantity_step, CHAR), CONVERT(NEW.quantity_step, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_step <=> NEW.quantity_step - UNION - -- Changed quantity_stock - SELECT NEW.id_product, 'quantity_stock', CONVERT(OLD.quantity_stock, CHAR), CONVERT(NEW.quantity_stock, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_stock <=> NEW.quantity_stock - UNION - -- Changed is_subscription - SELECT NEW.id_product, 'is_subscription', CONVERT(CONVERT(OLD.is_subscription, SIGNED), CHAR), CONVERT(CONVERT(NEW.is_subscription, SIGNED), CHAR), NEW.id_change_set - WHERE NOT OLD.is_subscription <=> NEW.is_subscription - UNION - -- Changed id_unit_measurement_interval_recurrence - SELECT NEW.id_product, 'id_unit_measurement_interval_recurrence', CONVERT(OLD.id_unit_measurement_interval_recurrence, CHAR), CONVERT(NEW.id_unit_measurement_interval_recurrence, CHAR), NEW.id_change_set - WHERE NOT OLD.id_unit_measurement_interval_recurrence <=> NEW.id_unit_measurement_interval_recurrence - UNION - -- Changed count_interval_recurrence - SELECT NEW.id_product, 'count_interval_recurrence', CONVERT(OLD.count_interval_recurrence, CHAR), CONVERT(NEW.count_interval_recurrence, CHAR), NEW.id_change_set - WHERE NOT OLD.count_interval_recurrence <=> NEW.count_interval_recurrence - UNION - -- Changed id_stripe_product - SELECT NEW.id_permutation, 'id_stripe_product', OLD.id_stripe_product, NEW.id_stripe_product, NEW.id_change_set - WHERE NOT (OLD.id_stripe_product <=> NEW.id_stripe_product) - UNION - -- Changed active - SELECT NEW.id_permutation, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_permutation, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Product_Permutation -BEFORE UPDATE ON Shop_Product_Permutation -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Product_Permutation(); - --- Shop Product Permutation Variation Link - -CREATE OR REPLACE FUNCTION before_insert_Shop_Product_Permutation_Variation_Link() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Product_Permutation_Variation_Link -BEFORE INSERT ON Shop_Product_Permutation_Variation_Link -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Product_Permutation_Variation_Link(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Product_Permutation_Variation_Link() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Product_Permutation_Variation_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_product - SELECT NEW.id_link, 'id_product', OLD.id_product, NEW.id_product, NEW.id_change_set - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed id_variation - SELECT NEW.id_link, 'id_variation', OLD.id_variation, NEW.id_variation, NEW.id_change_set - WHERE NOT OLD.id_variation <=> NEW.id_variation - UNION - */ - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_link, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Product_Permutation_Variation_Link -BEFORE UPDATE ON Shop_Product_Permutation_Variation_Link -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Product_Permutation_Variation_Link(); - --- Shop Product Currency Region Link - -CREATE OR REPLACE FUNCTION before_insert_Shop_Product_Currency_Region_Link() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - /* - NEW.price_local = ( - SELECT PP.price_GBP_full * C.factor_from_GBP - FROM Shop_Product_Permutation PP - INNER JOIN Shop_Product P ON PP.id_product = P.id_product - INNER JOIN Shop_Currency C ON NEW.id_currency = C.id_currency - WHERE NEW.id_product = P.id_product - LIMIT 1 - ); - */ - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Product_Currency_Region_Link -BEFORE INSERT ON Shop_Product_Currency_Region_Link -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Product_Currency_Region_Link(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Product_Currency_Region_Link() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - /* - NEW.price_local = ( - SELECT P.price_GBP_full * C.factor_from_GBP - FROM Shop_Product P - INNER JOIN Shop_Currency C ON NEW.id_currency = C.id_currency - WHERE NEW.id_product = P.id_product - LIMIT 1 - ); - */ - - INSERT INTO Shop_Product_Currency_Region_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_product - SELECT NEW.id_link, 'id_product', CONVERT(OLD.id_product, CHAR), CONVERT(NEW.id_product, CHAR), NEW.id_change_set - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed id_currency - SELECT NEW.id_link, 'id_currency', CONVERT(OLD.id_currency, CHAR), CONVERT(NEW.id_currency, CHAR), NEW.id_change_set - WHERE NOT OLD.id_currency <=> NEW.id_currency - UNION - -- Changed price_local - SELECT NEW.id_link, 'price_local', OLD.price_local, NEW.price_local, NEW.id_change_set - WHERE NOT OLD.price_local <=> NEW.price_local - UNION - */ - -- Changed price_local_VAT_incl - SELECT NEW.id_link, 'price_local_VAT_incl', OLD.price_local_VAT_incl, NEW.price_local_VAT_incl, NEW.id_change_set - WHERE NOT OLD.price_local_VAT_incl <=> NEW.price_local_VAT_incl - UNION - -- Changed price_local_VAT_excl - SELECT NEW.id_link, 'price_local_VAT_excl', OLD.price_local_VAT_excl, NEW.price_local_VAT_excl, NEW.id_change_set - WHERE NOT OLD.price_local_VAT_excl <=> NEW.price_local_VAT_excl - UNION - -- Changed id_stripe_price - SELECT NEW.id_link, 'id_stripe_price', OLD.id_stripe_price, NEW.id_stripe_price, NEW.id_change_set - WHERE NOT OLD.id_stripe_price <=> NEW.id_stripe_price - UNION - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Product_Currency_Region_Link -BEFORE UPDATE ON Shop_Product_Currency_Region_Link -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Product_Currency_Region_Link(); - --- Shop Image Type - -CREATE OR REPLACE FUNCTION before_insert_Shop_Image_Type() -RETURNS TRIGGER AS $$ -BEGIN - NEW.created_on = CURRENT_TIMESTAMP; - NEW.created_by = CURRENT_USER; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Image_Type -BEFORE INSERT ON Shop_Image_Type -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Image_Type(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Image_Type() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Image_Type_Audit ( - id_type, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_type, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_type, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed name_plural - SELECT NEW.id_type, 'name_plural', OLD.name_plural, NEW.name_plural, NEW.id_change_set - WHERE NOT OLD.name_plural <=> NEW.name_plural - UNION - -- Changed active - SELECT NEW.id_type, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_type, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Image_Type -BEFORE UPDATE ON Shop_Image_Type -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Image_Type(); - --- Shop Image - -CREATE OR REPLACE FUNCTION before_insert_Shop_Image() -RETURNS TRIGGER AS $$ -BEGIN - NEW.created_on = CURRENT_TIMESTAMP; - NEW.created_by = CURRENT_USER; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Image -BEFORE INSERT ON Shop_Image -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Image(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Image() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - IF ISNULL(NEW.id_product) AND ISNULL(NEW.id_permutation) THEN - RAISE EXCEPTION 'Image must NOT have ID for product AND product permutation.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Image_Audit ( - id_image, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_type_image - SELECT NEW.id_image, 'id_type_image', CONVERT(OLD.id_type_image, CHAR), CONVERT(NEW.id_type_image, CHAR), NEW.id_change_set - WHERE NOT OLD.id_type_image <=> NEW.id_type_image - UNION - -- Changed id_type_file - SELECT NEW.id_image, 'id_type_file', CONVERT(OLD.id_type_file, CHAR), CONVERT(NEW.id_type_file, CHAR), NEW.id_change_set - WHERE NOT OLD.id_type_file <=> NEW.id_type_file - UNION - -- Changed id_product - SELECT NEW.id_image, 'id_product', CONVERT(OLD.id_product, CHAR), CONVERT(NEW.id_product, CHAR), NEW.id_change_set - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed id_permutation - SELECT NEW.id_image, 'id_permutation', CONVERT(OLD.id_permutation, CHAR), CONVERT(NEW.id_permutation, CHAR), NEW.id_change_set - WHERE NOT OLD.id_permutation <=> NEW.id_permutation - UNION - -- Changed url - SELECT NEW.id_image, 'url', OLD.url, NEW.url, NEW.id_change_set - WHERE NOT OLD.url <=> NEW.url - UNION - -- Changed active - SELECT NEW.id_image, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_image, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Image -BEFORE UPDATE ON Shop_Image -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Image(); - --- Shop Delivery Option Type - -CREATE OR REPLACE FUNCTION before_insert_Shop_Delivery_Option() -RETURNS TRIGGER AS $$ -BEGIN - NEW.created_on = CURRENT_TIMESTAMP; - NEW.created_by = CURRENT_USER; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Delivery_Option -BEFORE INSERT ON Shop_Delivery_Option -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Delivery_Option(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Delivery_Option() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Delivery_Option_Audit ( - id_option, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_option, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_option, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed latency_delivery_min - SELECT NEW.id_option, 'latency_delivery_min', CONVERT(OLD.latency_delivery_min, CHAR), CONVERT(NEW.latency_delivery_min, CHAR), NEW.id_change_set - WHERE NOT OLD.latency_delivery_min <=> NEW.latency_delivery_min - UNION - -- Changed latency_delivery_max - SELECT NEW.id_option, 'latency_delivery_max', CONVERT(OLD.latency_delivery_max, CHAR), CONVERT(NEW.latency_delivery_max, CHAR), NEW.id_change_set - WHERE NOT OLD.latency_delivery_max <=> NEW.latency_delivery_max - UNION - -- Changed quantity_min - SELECT NEW.id_option, 'quantity_min', CONVERT(OLD.quantity_min, CHAR), CONVERT(NEW.quantity_min, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_min <=> NEW.quantity_min - UNION - -- Changed quantity_max - SELECT NEW.id_option, 'quantity_max', CONVERT(OLD.quantity_max, CHAR), CONVERT(NEW.quantity_max, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - UNION - -- Changed active - SELECT NEW.id_option, 'active', CONVERT(OLD.active, CHAR), CONVERT(NEW.active, CHAR), NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - UNION - -- Changed display_order - SELECT NEW.id_option, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Delivery_Option -BEFORE UPDATE ON Shop_Delivery_Option -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Delivery_Option(); - --- Shop Product Delivery Option Link - -CREATE OR REPLACE FUNCTION before_insert_Shop_Product_Permutation_Delivery_Option_Link() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Product_Permutation_Delivery_Option_Link -BEFORE INSERT ON Shop_Product_Permutation_Delivery_Option_Link -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Product_Permutation_Delivery_Option_Link(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Product_Permutation_Delivery_Option_Link() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Product_Permutation_Delivery_Option_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_product - SELECT NEW.id_link, 'id_product', CONVERT(OLD.id_product, CHAR), CONVERT(NEW.id_product, CHAR), NEW.id_change_set - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed id_permutation - SELECT NEW.id_link, 'id_permutation', CONVERT(OLD.id_permutation, CHAR), CONVERT(NEW.id_permutation, CHAR), NEW.id_change_set - WHERE NOT OLD.id_permutation <=> NEW.id_permutation - UNION - -- Changed id_option - SELECT NEW.id_link, 'id_option', CONVERT(OLD.id_option, CHAR), CONVERT(NEW.id_option, CHAR), NEW.id_change_set - WHERE NOT OLD.id_option <=> NEW.id_option - UNION - -- Changed id_region - SELECT NEW.id_link, 'id_region', CONVERT(OLD.id_region, CHAR), CONVERT(NEW.id_region, CHAR), NEW.id_change_set - WHERE NOT OLD.id_region <=> NEW.id_region - UNION - */ - -- Changed price_local - SELECT NEW.id_link, 'price_local', CONVERT(OLD.price_local, CHAR), CONVERT(NEW.price_local, CHAR), NEW.id_change_set - WHERE NOT OLD.price_local <=> NEW.price_local - UNION - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_link, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Product_Permutation_Delivery_Option_Link -BEFORE UPDATE ON Shop_Product_Permutation_Delivery_Option_Link -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Product_Permutation_Delivery_Option_Link(); - --- Shop Discount - -CREATE OR REPLACE FUNCTION before_insert_Shop_Discount() -RETURNS TRIGGER AS $$ -BEGIN - NEW.created_on = CURRENT_TIMESTAMP; - NEW.created_by = CURRENT_USER; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Discount -BEFORE INSERT ON Shop_Discount -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Discount(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Discount() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Discount_Audit ( - id_discount, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_discount, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_discount, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed multiplier - SELECT NEW.id_discount, 'multiplier', OLD.multiplier, NEW.multiplier, NEW.id_change_set - WHERE NOT OLD.multiplier <=> NEW.multiplier - UNION - -- Changed subtractor - SELECT NEW.id_discount, 'subtractor', OLD.subtractor, NEW.subtractor, NEW.id_change_set - WHERE NOT OLD.subtractor <=> NEW.subtractor - UNION - -- Changed apply_multiplier_first - SELECT NEW.id_discount, 'apply_multiplier_first', CONVERT(CONVERT(OLD.apply_multiplier_first, SIGNED), CHAR), CONVERT(CONVERT(NEW.apply_multiplier_first, SIGNED), CHAR), NEW.id_change_set - WHERE NOT OLD.apply_multiplier_first <=> NEW.apply_multiplier_first - UNION - -- Changed quantity_min - SELECT NEW.id_discount, 'quantity_min', OLD.quantity_min, NEW.quantity_min, NEW.id_change_set - WHERE NOT OLD.quantity_min <=> NEW.quantity_min - UNION - -- Changed quantity_max - SELECT NEW.id_discount, 'quantity_max', OLD.quantity_max, NEW.quantity_max, NEW.id_change_set - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - UNION - -- Changed date_start - SELECT NEW.id_discount, 'date_start', OLD.date_start, NEW.date_start, NEW.id_change_set - WHERE NOT OLD.date_start <=> NEW.date_start - UNION - -- Changed date_end - SELECT NEW.id_discount, 'date_end', OLD.date_end, NEW.date_end, NEW.id_change_set - WHERE NOT OLD.date_end <=> NEW.date_end - UNION - -- Changed display_order - SELECT NEW.id_discount, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - UNION - -- Changed active - SELECT NEW.id_discount, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Discount -BEFORE UPDATE ON Shop_Discount -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Discount(); - --- Shop Discount Region Currency Link - -CREATE OR REPLACE FUNCTION before_insert_Shop_Discount_Region_Currency_Link() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Discount_Region_Currency_Link -BEFORE INSERT ON Shop_Discount_Region_Currency_Link -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Discount_Region_Currency_Link(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Discount_Region_Currency_Link() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Discount_Region_Currency_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_discount - SELECT NEW.id_link, 'id_discount', CONVERT(OLD.id_discount, CHAR), CONVERT(NEW.id_discount, CHAR), NEW.id_change_set - WHERE NOT OLD.id_discount <=> NEW.id_discount - UNION - -- Changed id_region - SELECT NEW.id_link, 'id_region', CONVERT(OLD.id_region, CHAR), CONVERT(NEW.id_region, CHAR), NEW.id_change_set - WHERE NOT OLD.id_region <=> NEW.id_region - UNION - */ - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Discount_Region_Currency_Link -BEFORE UPDATE ON Shop_Discount_Region_Currency_Link -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Discount_Region_Currency_Link(); - --- Shop Permission Group - -CREATE OR REPLACE FUNCTION before_insert_Shop_Permission_Group() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Permission_Group -BEFORE INSERT ON Shop_Permission_Group -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Permission_Group(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Permission_Group() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Permission_Group_Audit ( - id_group, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_group, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_group, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed active - SELECT NEW.id_group, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_group, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Permission_Group -BEFORE UPDATE ON Shop_Permission_Group -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Permission_Group(); - --- Shop Permission - -CREATE OR REPLACE FUNCTION before_insert_Shop_Permission() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Permission -BEFORE INSERT ON Shop_Permission -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Permission(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Permission() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Permission_Audit ( - id_permission, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_permission, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_permission, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed id_permission_group - SELECT NEW.id_permission, 'id_permission_group', CONVERT(OLD.id_permission_group, CHAR), CONVERT(NEW.id_permission_group, CHAR), NEW.id_change_set - WHERE NOT OLD.id_permission_group <=> NEW.id_permission_group - UNION - -- Changed Id_access_level_required - SELECT NEW.id_permission, 'Id_access_level_required', CONVERT(OLD.Id_access_level_required, CHAR), CONVERT(NEW.Id_access_level_required, CHAR), NEW.id_change_set - WHERE NOT OLD.Id_access_level_required <=> NEW.Id_access_level_required - UNION - -- Changed active - SELECT NEW.id_permission, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_permission, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Permission -BEFORE UPDATE ON Shop_Permission -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Permission(); - --- Shop Role - -CREATE OR REPLACE FUNCTION before_insert_Shop_Role() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Role -BEFORE INSERT ON Shop_Role -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Role(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Role() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Role_Audit ( - id_role, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_role, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_role, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed active - SELECT NEW.id_role, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_role, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Role -BEFORE UPDATE ON Shop_Role -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Role(); - --- Shop Role Permission Link - -CREATE OR REPLACE FUNCTION before_insert_Shop_Role_Permission_Link() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Role_Permission_Link -BEFORE INSERT ON Shop_Role_Permission_Link -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Role_Permission_Link(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Role_Permission_Link() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Role_Permission_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_role - SELECT NEW.id_link, 'id_role', CONVERT(OLD.id_role, CHAR), CONVERT(NEW.id_role, CHAR), NEW.id_change_set - WHERE NOT OLD.id_role <=> NEW.id_role - UNION - -- Changed id_permission - SELECT NEW.id_link, 'id_permission', CONVERT(OLD.id_permission, CHAR), CONVERT(NEW.id_permission, CHAR), NEW.id_change_set - WHERE NOT OLD.id_permission <=> NEW.id_permission - UNION - */ - -- Changed id_access_level - SELECT NEW.id_link, 'id_access_level', CONVERT(OLD.id_access_level, CHAR), CONVERT(NEW.id_access_level, CHAR), NEW.id_change_set - WHERE NOT OLD.id_access_level <=> NEW.id_access_level - UNION - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Role_Permission_Link -BEFORE UPDATE ON Shop_Role_Permission_Link -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Role_Permission_Link(); - --- Shop User - -CREATE OR REPLACE FUNCTION before_insert_Shop_User() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_User -BEFORE INSERT ON Shop_User -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_User(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_User() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_User_Audit ( - id_user, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_user_oauth - SELECT NEW.id_user, 'id_user_oauth', OLD.id_user_oauth, NEW.id_user_oauth, NEW.id_change_set - WHERE NOT (OLD.id_user_oauth <=> NEW.id_user_oauth) - UNION - -- Changed name - SELECT NEW.id_user, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT (OLD.name <=> NEW.name) - UNION - -- Changed email - SELECT NEW.id_user, 'email', OLD.email, NEW.email, NEW.id_change_set - WHERE NOT (OLD.email <=> NEW.email) - UNION - -- Changed is_email_verified - SELECT NEW.id_user, 'is_email_verified', OLD.is_email_verified, NEW.is_email_verified, NEW.id_change_set - WHERE NOT (OLD.is_email_verified <=> NEW.is_email_verified) - UNION - -- Changed is_super_user - SELECT NEW.id_user, 'is_super_user', CONVERT(CONVERT(OLD.is_super_user, SIGNED), CHAR), CONVERT(CONVERT(NEW.is_super_user, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.is_super_user <=> NEW.is_super_user) - UNION - -- Changed active - SELECT NEW.id_user, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_User -BEFORE UPDATE ON Shop_User -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_User(); - --- Shop User Role Link - -CREATE OR REPLACE FUNCTION before_insert_Shop_User_Role_Link() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_User_Role_Link -BEFORE INSERT ON Shop_User_Role_Link -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_User_Role_Link(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_User_Role_Link() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_User_Role_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_User_Role_Link -BEFORE UPDATE ON Shop_User_Role_Link -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_User_Role_Link(); - --- Shop Address - -CREATE OR REPLACE FUNCTION before_insert_Shop_Address() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Address -BEFORE INSERT ON Shop_Address -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Address(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Address() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Address_Audit ( - id_address, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed region - SELECT NEW.id_address, 'id_region', OLD.id_region, NEW.id_region, NEW.id_change_set - WHERE NOT OLD.id_region <=> NEW.id_region - UNION - -- Changed name_full - SELECT NEW.id_address, 'name_full', OLD.name_full, NEW.name_full, NEW.id_change_set - WHERE NOT OLD.name_full <=> NEW.name_full - UNION - -- Changed phone_number - SELECT NEW.id_address, 'phone_number', OLD.phone_number, NEW.phone_number, NEW.id_change_set - WHERE NOT OLD.phone_number <=> NEW.phone_number - UNION - -- Changed postcode - SELECT NEW.id_address, 'postcode', OLD.postcode, NEW.postcode, NEW.id_change_set - WHERE NOT OLD.postcode <=> NEW.postcode - UNION - -- Changed address_line_1 - SELECT NEW.id_address, 'address_line_1', OLD.address_line_1, NEW.address_line_1, NEW.id_change_set - WHERE NOT OLD.address_line_1 <=> NEW.address_line_1 - UNION - -- Changed address_line_2 - SELECT NEW.id_address, 'address_line_2', OLD.address_line_2, NEW.address_line_2, NEW.id_change_set - WHERE NOT OLD.address_line_2 <=> NEW.address_line_2 - UNION - -- Changed city - SELECT NEW.id_address, 'city', OLD.city, NEW.city, NEW.id_change_set - WHERE NOT OLD.city <=> NEW.city - UNION - -- Changed county - SELECT NEW.id_address, 'county', OLD.county, NEW.county, NEW.id_change_set - WHERE NOT OLD.county <=> NEW.county - UNION - -- Changed active - SELECT NEW.id_address, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Address -BEFORE UPDATE ON Shop_Address -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Address(); --- Shop Product Variation Link - -CREATE OR REPLACE FUNCTION before_insert_Shop_User_Basket() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_User_Basket -BEFORE INSERT ON Shop_User_Basket -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_User_Basket(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_User_Basket() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.id_change_set_user <=> OLD.id_change_set_user THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_User_Basket_Audit ( - id_item, - name_field, - value_prev, - value_new, - id_change_set_user - ) - -- Changed id_user - SELECT NEW.id_item, 'id_user', OLD.id_user, NEW.id_user, NEW.id_change_set_user - WHERE NOT OLD.id_user <=> NEW.id_user - UNION - -- Changed id_product - SELECT NEW.id_item, 'id_product', OLD.id_product, NEW.id_product, NEW.id_change_set_user - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed quantity - SELECT NEW.id_item, 'quantity', CONVERT(OLD.quantity, CHAR), CONVERT(NEW.quantity, CHAR), NEW.id_change_set_user - WHERE NOT (OLD.quantity <=> NEW.quantity) - UNION - -- Changed active - SELECT NEW.id_item, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set_user - WHERE NOT (OLD.active <=> NEW.active) - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_User_Basket -BEFORE UPDATE ON Shop_User_Basket -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_User_Basket(); - --- Shop User Order Type - -CREATE OR REPLACE FUNCTION before_insert_Shop_User_Order_Status() -RETURNS TRIGGER AS $$ -BEGIN - NEW.created_on = CURRENT_TIMESTAMP; - NEW.created_by = CURRENT_USER; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_User_Order_Status -BEFORE INSERT ON Shop_User_Order_Status -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_User_Order_Status(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_User_Order_Status() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_User_Order_Status_Audit ( - id_Status, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_Status, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_Status, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed name_plural - SELECT NEW.id_Status, 'name_plural', OLD.name_plural, NEW.name_plural, NEW.id_change_set - WHERE NOT OLD.name_plural <=> NEW.name_plural - UNION - -- Changed active - SELECT NEW.id_Status, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_Status, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_User_Order_Status -BEFORE UPDATE ON Shop_User_Order_Status -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_User_Order_Status(); - --- Shop Supplier - -CREATE OR REPLACE FUNCTION before_insert_Shop_Supplier() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Supplier -BEFORE INSERT ON Shop_Supplier -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Supplier(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Supplier() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Supplier_Audit ( - id_supplier, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed name_company - SELECT NEW.id_supplier, 'name_company', OLD.name_company, NEW.name_company, NEW.id_change_set - WHERE NOT OLD.name_company <=> NEW.name_company - UNION - -- Changed name_contact - SELECT NEW.id_supplier, 'name_contact', OLD.name_contact, NEW.name_contact, NEW.id_change_set - WHERE NOT OLD.name_contact <=> NEW.name_contact - UNION - -- Changed department_contact - SELECT NEW.id_supplier, 'department_contact', OLD.department_contact, NEW.department_contact, NEW.id_change_set - WHERE NOT OLD.department_contact <=> NEW.department_contact - UNION - -- Changed id_address - SELECT NEW.id_supplier, 'id_address', OLD.id_address, NEW.id_address, NEW.id_change_set - WHERE NOT OLD.id_address <=> NEW.id_address - UNION - -- Changed phone_number - SELECT NEW.id_supplier, 'phone_number', OLD.phone_number, NEW.phone_number, NEW.id_change_set - WHERE NOT OLD.phone_number <=> NEW.phone_number - UNION - -- Changed fax - SELECT NEW.id_supplier, 'fax', OLD.fax, NEW.fax, NEW.id_change_set - WHERE NOT OLD.fax <=> NEW.fax - UNION - -- Changed email - SELECT NEW.id_supplier, 'email', OLD.email, NEW.email, NEW.id_change_set - WHERE NOT OLD.email <=> NEW.email - UNION - -- Changed website - SELECT NEW.id_supplier, 'website', OLD.website, NEW.website, NEW.id_change_set - WHERE NOT OLD.website <=> NEW.website - UNION - -- Changed id_currency - SELECT NEW.id_supplier, 'id_currency', OLD.id_currency, NEW.id_currency, NEW.id_change_set - WHERE NOT OLD.id_currency <=> NEW.id_currency - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Supplier -BEFORE UPDATE ON Shop_Supplier -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Supplier(); - --- Shop Unit of Measurement - -CREATE OR REPLACE FUNCTION before_insert_Shop_Unit_Measurement() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Unit_Measurement -BEFORE INSERT ON Shop_Unit_Measurement -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Unit_Measurement(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Unit_Measurement() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Unit_Measurement_Audit ( - id_unit_measurement, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed name_singular - SELECT NEW.id_unit_measurement, 'name_singular', OLD.name_singular, NEW.name_singular, NEW.id_change_set - WHERE NOT OLD.name_singular <=> NEW.name_singular - UNION - -- Changed name_plural - SELECT NEW.id_unit_measurement, 'name_plural', OLD.name_plural, NEW.name_plural, NEW.id_change_set - WHERE NOT OLD.name_plural <=> NEW.name_plural - UNION - -- Changed symbol - SELECT NEW.id_unit_measurement, 'symbol', OLD.symbol, NEW.symbol, NEW.id_change_set - WHERE NOT OLD.symbol <=> NEW.symbol - UNION - -- Changed is_base_unit - SELECT NEW.id_unit_measurement, 'is_base_unit', OLD.is_base_unit, NEW.is_base_unit, NEW.id_change_set - WHERE NOT OLD.is_base_unit <=> NEW.is_base_unit - UNION - -- Changed active - SELECT NEW.id_unit_measurement, 'active', OLD.active, NEW.active, NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Unit_Measurement -BEFORE UPDATE ON Shop_Unit_Measurement -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Unit_Measurement(); - --- Shop Unit of Measurement Conversion - -CREATE OR REPLACE FUNCTION before_insert_Shop_Unit_Measurement_Conversion() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Unit_Measurement_Conversion -BEFORE INSERT ON Shop_Unit_Measurement_Conversion -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Unit_Measurement_Conversion(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Unit_Measurement_Conversion() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Unit_Measurement_Conversion_Audit ( - id_conversion, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_unit_derived - SELECT NEW.id_conversion, 'id_unit_derived', OLD.id_unit_derived, NEW.id_unit_derived, NEW.id_change_set - WHERE NOT OLD.id_unit_derived <=> NEW.id_unit_derived - UNION - -- Changed id_unit_base - SELECT NEW.id_conversion, 'id_unit_base', OLD.id_unit_base, NEW.id_unit_base, NEW.id_change_set - WHERE NOT OLD.id_unit_base <=> NEW.id_unit_base - UNION - -- Changed power_unit_base - SELECT NEW.id_conversion, 'power_unit_base', OLD.power_unit_base, NEW.power_unit_base, NEW.id_change_set - WHERE NOT OLD.power_unit_base <=> NEW.power_unit_base - UNION - -- Changed multiplier_unit_base - SELECT NEW.id_conversion, 'multiplier_unit_base', OLD.multiplier_unit_base, NEW.multiplier_unit_base, NEW.id_change_set - WHERE NOT OLD.multiplier_unit_base <=> NEW.multiplier_unit_base - UNION - -- Changed increment_unit_base - SELECT NEW.id_conversion, 'active', OLD.increment_unit_base, NEW.increment_unit_base, NEW.id_change_set - WHERE NOT OLD.increment_unit_base <=> NEW.increment_unit_base - UNION - -- Changed active - SELECT NEW.id_conversion, 'active', OLD.active, NEW.active, NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Unit_Measurement_Conversion -BEFORE UPDATE ON Shop_Unit_Measurement_Conversion -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Unit_Measurement_Conversion(); - --- Shop Supplier Purchase Order - -CREATE OR REPLACE FUNCTION before_insert_Shop_Supplier_Purchase_Order() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Supplier_Purchase_Order -BEFORE INSERT ON Shop_Supplier_Purchase_Order -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Supplier_Purchase_Order(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Supplier_Purchase_Order() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Supplier_Purchase_Order_Audit ( - id_order, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_supplier_ordered - SELECT NEW.id_order, 'id_supplier_ordered', OLD.id_supplier_ordered, NEW.id_supplier_ordered, NEW.id_change_set - WHERE NOT OLD.id_supplier_ordered <=> NEW.id_supplier_ordered - UNION - -- Changed cost_total_local - SELECT NEW.id_order, 'cost_total_local', OLD.cost_total_local, NEW.cost_total_local, NEW.id_change_set - WHERE NOT OLD.cost_total_local <=> NEW.cost_total_local - UNION - -- Changed id_currency_cost - SELECT NEW.id_order, 'id_currency_cost', OLD.id_currency_cost, NEW.id_currency_cost, NEW.id_change_set - WHERE NOT OLD.id_currency_cost <=> NEW.id_currency_cost - /* - UNION - -- Changed latency_delivery - SELECT NEW.id_order, 'latency_delivery', OLD.latency_delivery, NEW.latency_delivery, NEW.id_change_set - WHERE NOT OLD.latency_delivery <=> NEW.latency_delivery - UNION - -- Changed quantity_ordered - SELECT NEW.id_order, 'quantity_ordered', OLD.quantity_ordered, NEW.quantity_ordered, NEW.id_change_set - WHERE NOT OLD.quantity_ordered <=> NEW.quantity_ordered - UNION - -- Changed id_unit_quantity - SELECT NEW.id_order, 'id_unit_quantity', OLD.id_unit_quantity, NEW.id_unit_quantity, NEW.id_change_set - WHERE NOT OLD.id_unit_quantity <=> NEW.id_unit_quantity - UNION - -- Changed quantity_received - SELECT NEW.id_order, 'quantity_received', OLD.quantity_received, NEW.quantity_received, NEW.id_change_set - WHERE NOT OLD.quantity_received <=> NEW.quantity_received - */ - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Supplier_Purchase_Order -BEFORE UPDATE ON Shop_Supplier_Purchase_Order -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Supplier_Purchase_Order(); - - --- Shop Supplier Purchase Order Product Link - -CREATE OR REPLACE FUNCTION before_insert_Shop_Supplier_Purchase_Order_Product_Link() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Supplier_Purchase_Order_Product_Link -BEFORE INSERT ON Shop_Supplier_Purchase_Order_Product_Link -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Supplier_Purchase_Order_Product_Link(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Supplier_Purchase_Order_Product_Link() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Supplier_Purchase_Order_Product_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_order - SELECT NEW.id_link, 'id_order', OLD.id_order, NEW.id_order, NEW.id_change_set - WHERE NOT OLD.id_order <=> NEW.id_order - UNION - -- Changed id_permutation - SELECT NEW.id_link, 'id_permutation', OLD.id_permutation, NEW.id_permutation, NEW.id_change_set - WHERE NOT OLD.id_permutation <=> NEW.id_permutation - UNION - -- Changed cost_total_local - SELECT NEW.id_link, 'cost_total_local', OLD.cost_total_local, NEW.cost_total_local, NEW.id_change_set - WHERE NOT OLD.cost_total_local <=> NEW.cost_total_local - UNION - -- Changed id_currency_cost - SELECT NEW.id_link, 'id_currency_cost', OLD.id_currency_cost, NEW.id_currency_cost, NEW.id_change_set - WHERE NOT OLD.id_currency_cost <=> NEW.id_currency_cost - UNION - -- Changed quantity_ordered - SELECT NEW.id_link, 'quantity_ordered', OLD.quantity_ordered, NEW.quantity_ordered, NEW.id_change_set - WHERE NOT OLD.quantity_ordered <=> NEW.quantity_ordered - UNION - -- Changed id_unit_quantity - SELECT NEW.id_link, 'id_unit_quantity', OLD.id_unit_quantity, NEW.id_unit_quantity, NEW.id_change_set - WHERE NOT OLD.id_unit_quantity <=> NEW.id_unit_quantity - UNION - -- Changed quantity_received - SELECT NEW.id_link, 'quantity_received', OLD.quantity_received, NEW.quantity_received, NEW.id_change_set - WHERE NOT OLD.quantity_received <=> NEW.quantity_received - UNION - -- Changed latency_delivery_days - SELECT NEW.id_link, 'latency_delivery_days', OLD.latency_delivery_days, NEW.latency_delivery_days, NEW.id_change_set - WHERE NOT OLD.latency_delivery_days <=> NEW.latency_delivery_days - UNION - -- Changed display_order - SELECT NEW.id_link, 'display_order', OLD.display_order, NEW.display_order, NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - UNION - -- Changed active - SELECT NEW.id_link, 'active', OLD.active, NEW.active, NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Supplier_Purchase_Order_Product_Link -BEFORE UPDATE ON Shop_Supplier_Purchase_Order_Product_Link -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Supplier_Purchase_Order_Product_Link(); - --- Shop Manufacturing Purchase Order - -CREATE OR REPLACE FUNCTION before_insert_Shop_Manufacturing_Purchase_Order() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Manufacturing_Purchase_Order -BEFORE INSERT ON Shop_Manufacturing_Purchase_Order -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Manufacturing_Purchase_Order(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Manufacturing_Purchase_Order() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Manufacturing_Purchase_Order_Audit ( - id_order, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed cost_total_local - SELECT NEW.id_order, 'cost_total_local', OLD.cost_total_local, NEW.cost_total_local, NEW.id_change_set - WHERE NOT OLD.cost_total_local <=> NEW.cost_total_local - UNION - -- Changed value_produced_total_local - SELECT NEW.id_order, 'value_produced_total_local', OLD.value_produced_total_local, NEW.value_produced_total_local, NEW.id_change_set - WHERE NOT OLD.value_produced_total_local <=> NEW.value_produced_total_local - UNION - -- Changed id_currency_cost - SELECT NEW.id_order, 'id_currency_cost', OLD.id_currency_cost, NEW.id_currency_cost, NEW.id_change_set - WHERE NOT OLD.id_currency_cost <=> NEW.id_currency_cost - UNION - -- Changed active - SELECT NEW.id_order, 'active', OLD.active, NEW.active, NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Manufacturing_Purchase_Order -BEFORE UPDATE ON Shop_Manufacturing_Purchase_Order -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Manufacturing_Purchase_Order(); - --- Shop Manufacturing Purchase Order Product Link - -CREATE OR REPLACE FUNCTION before_insert_Shop_Manufacturing_Purchase_Order_Product_Link() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Manufacturing_Purch_Order_Product_Link -BEFORE INSERT ON Shop_Manufacturing_Purchase_Order_Product_Link -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Manufacturing_Purchase_Order_Product_Link(); - - -CREATE OR REPLACE FUNCTION before_update_Manufacturing_Purch_Order_Product_Link() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Manufacturing_Purchase_Order_Product_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_order - SELECT NEW.id_link, 'id_order', OLD.id_order, NEW.id_order, NEW.id_change_set - WHERE NOT OLD.id_order <=> NEW.id_order - UNION - -- Changed id_permutation - SELECT NEW.id_link, 'id_permutation', OLD.id_permutation, NEW.id_permutation, NEW.id_change_set - WHERE NOT OLD.id_permutation <=> NEW.id_permutation - UNION - -- Changed cost_total_local - SELECT NEW.id_link, 'cost_total_local', OLD.cost_total_local, NEW.cost_total_local, NEW.id_change_set - WHERE NOT OLD.cost_total_local <=> NEW.cost_total_local - UNION - -- Changed id_currency_cost - SELECT NEW.id_link, 'id_currency_cost', OLD.id_currency_cost, NEW.id_currency_cost, NEW.id_change_set - WHERE NOT OLD.id_currency_cost <=> NEW.id_currency_cost - UNION - -- Changed quantity_used - SELECT NEW.id_link, 'quantity_used', OLD.quantity_used, NEW.quantity_used, NEW.id_change_set - WHERE NOT OLD.quantity_used <=> NEW.quantity_used - UNION - -- Changed id_unit_quantity - SELECT NEW.id_link, 'id_unit_quantity', OLD.id_unit_quantity, NEW.id_unit_quantity, NEW.id_change_set - WHERE NOT OLD.id_unit_quantity <=> NEW.id_unit_quantity - UNION - -- Changed quantity_produced - SELECT NEW.id_link, 'quantity_produced', OLD.quantity_produced, NEW.quantity_produced, NEW.id_change_set - WHERE NOT OLD.quantity_produced <=> NEW.quantity_produced - UNION - -- Changed latency_manufacture - SELECT NEW.id_link, 'latency_manufacture', OLD.latency_manufacture, NEW.latency_manufacture, NEW.id_change_set - WHERE NOT OLD.latency_manufacture <=> NEW.latency_manufacture - UNION - -- Changed display_order - SELECT NEW.id_link, 'display_order', OLD.display_order, NEW.display_order, NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - UNION - -- Changed active - SELECT NEW.id_link, 'active', OLD.active, NEW.active, NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Manufacturing_Purch_Order_Product_Link -BEFORE UPDATE ON Shop_Manufacturing_Purchase_Order_Product_Link -FOR EACH ROW -EXECUTE FUNCTION before_update_Manufacturing_Purch_Order_Product_Link(); - - --- Shop Customer - -CREATE OR REPLACE FUNCTION before_insert_Shop_Customer() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Customer -BEFORE INSERT ON Shop_Customer -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Customer(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Customer() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Customer_Audit ( - id_customer, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed name_company - SELECT NEW.id_customer, 'name_company', OLD.name_company, NEW.name_company, NEW.id_change_set - WHERE NOT OLD.name_company <=> NEW.name_company - UNION - -- Changed name_contact - SELECT NEW.id_customer, 'name_contact', OLD.name_contact, NEW.name_contact, NEW.id_change_set - WHERE NOT OLD.name_contact <=> NEW.name_contact - UNION - -- Changed department_contact - SELECT NEW.id_customer, 'department_contact', OLD.department_contact, NEW.department_contact, NEW.id_change_set - WHERE NOT OLD.department_contact <=> NEW.department_contact - UNION - -- Changed id_address - SELECT NEW.id_customer, 'id_address', OLD.id_address, NEW.id_address, NEW.id_change_set - WHERE NOT OLD.id_address <=> NEW.id_address - UNION - -- Changed phone_number - SELECT NEW.id_customer, 'phone_number', OLD.phone_number, NEW.phone_number, NEW.id_change_set - WHERE NOT OLD.phone_number <=> NEW.phone_number - UNION - -- Changed email - SELECT NEW.id_customer, 'email', OLD.email, NEW.email, NEW.id_change_set - WHERE NOT OLD.email <=> NEW.email - UNION - -- Changed id_currency - SELECT NEW.id_customer, 'id_currency', OLD.id_currency, NEW.id_currency, NEW.id_change_set - WHERE NOT OLD.id_currency <=> NEW.id_currency - UNION - -- Changed active - SELECT NEW.id_customer, 'active', OLD.active, NEW.active, NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Customer -BEFORE UPDATE ON Shop_Customer -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Customer(); - - --- Shop Customer Sales Order - -CREATE OR REPLACE FUNCTION before_insert_Shop_Customer_Sales_Order() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Customer_Sales_Order -BEFORE INSERT ON Shop_Customer_Sales_Order -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Customer_Sales_Order(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Customer_Sales_Order() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Customer_Sales_Order_Audit ( - id_order, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_customer - SELECT NEW.id_order, 'id_customer', OLD.id_customer, NEW.id_customer, NEW.id_change_set - WHERE NOT OLD.id_customer <=> NEW.id_customer - UNION - -- Changed price_total_local - SELECT NEW.id_order, 'price_total_local', OLD.price_total_local, NEW.price_total_local, NEW.id_change_set - WHERE NOT OLD.price_total_local <=> NEW.price_total_local - UNION - -- Changed id_currency_price - SELECT NEW.id_order, 'id_currency_price', OLD.id_currency_price, NEW.id_currency_price, NEW.id_change_set - WHERE NOT OLD.id_currency_price <=> NEW.id_currency_price - UNION - -- Changed active - SELECT NEW.id_order, 'active', OLD.active, NEW.active, NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Customer_Sales_Order -BEFORE UPDATE ON Shop_Customer_Sales_Order -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Customer_Sales_Order(); - --- Shop Customer Sales Order Product Link - -CREATE OR REPLACE FUNCTION before_insert_Shop_Customer_Sales_Order_Product_Link() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Customer_Sales_Order_Product_Link -BEFORE INSERT ON Shop_Customer_Sales_Order_Product_Link -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Customer_Sales_Order_Product_Link(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Customer_Sales_Order_Product_Link() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Customer_Sales_Order_Product_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_order - SELECT NEW.id_link, 'id_order', OLD.id_order, NEW.id_order, NEW.id_change_set - WHERE NOT OLD.id_order <=> NEW.id_order - UNION - -- Changed id_permutation - SELECT NEW.id_link, 'id_permutation', OLD.id_permutation, NEW.id_permutation, NEW.id_change_set - WHERE NOT OLD.id_permutation <=> NEW.id_permutation - UNION - -- Changed price_total_local - SELECT NEW.id_link, 'price_total_local', OLD.price_total_local, NEW.price_total_local, NEW.id_change_set - WHERE NOT OLD.price_total_local <=> NEW.price_total_local - UNION - -- Changed id_currency_price - SELECT NEW.id_link, 'id_currency_price', OLD.id_currency_price, NEW.id_currency_price, NEW.id_change_set - WHERE NOT OLD.id_currency_price <=> NEW.id_currency_price - UNION - -- Changed quantity_ordered - SELECT NEW.id_link, 'quantity_ordered', OLD.quantity_ordered, NEW.quantity_ordered, NEW.id_change_set - WHERE NOT OLD.quantity_ordered <=> NEW.quantity_ordered - UNION - -- Changed id_unit_quantity - SELECT NEW.id_link, 'id_unit_quantity', OLD.id_unit_quantity, NEW.id_unit_quantity, NEW.id_change_set - WHERE NOT OLD.id_unit_quantity <=> NEW.id_unit_quantity - UNION - -- Changed quantity_delivered - SELECT NEW.id_link, 'quantity_delivered', OLD.quantity_delivered, NEW.quantity_delivered, NEW.id_change_set - WHERE NOT OLD.quantity_delivered <=> NEW.quantity_delivered - UNION - -- Changed latency_delivery_days - SELECT NEW.id_link, 'latency_delivery_days', OLD.latency_delivery_days, NEW.latency_delivery_days, NEW.id_change_set - WHERE NOT OLD.latency_delivery_days <=> NEW.latency_delivery_days - UNION - -- Changed display_order - SELECT NEW.id_link, 'display_order', OLD.display_order, NEW.display_order, NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - UNION - -- Changed active - SELECT NEW.id_link, 'active', OLD.active, NEW.active, NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Customer_Sales_Order_Product_Link -BEFORE UPDATE ON Shop_Customer_Sales_Order_Product_Link -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Customer_Sales_Order_Product_Link(); - -/* - -CALL p_shop_calc_user ( - gen_random_uuid(), -- a_guid - '', -- a_id_user - 0, -- a_get_inactive_users - '1', -- a_ids_permission - '', -- a_ids_access_level - '1' -- a_ids_product -) - -*/ - -CREATE OR REPLACE PROCEDURE p_shop_calc_user ( - IN a_guid UUID, - IN a_id_user INTEGER, - IN a_get_inactive_users BOOLEAN, - IN a_ids_permission INTEGER[], - IN a_ids_access_level INTEGER[], - IN a_ids_product INTEGER[] -- VARCHAR(4000) -- IN a_ids_permutation VARCHAR(4000) - /* - OUT result_errors TABLE ( - guid UUID, - id_type INTEGER, - code VARCHAR(50), - msg VARCHAR(4000) - ) - */ - -- INOUT a_error_msg TEXT -) -AS $$ -DECLARE - v_guid UUID; - v_id_user INTEGER; - v_get_inactive_users BOOLEAN; - v_ids_permission INTEGER[]; - v_ids_access_level INTEGER[]; - v_ids_product INTEGER[]; -- TEXT; -- VARCHAR(4000); -- IN a_ids_permutation VARCHAR(4000) - v_has_filter_user BOOLEAN; - v_has_filter_permission BOOLEAN; - v_has_filter_access_level BOOLEAN; - -- v_has_filter_permutation BOOLEAN; - v_has_filter_product BOOLEAN; - v_id_permission_product INTEGER; - v_id_permission INTEGER; - -- v_ids_product UUID; - v_id_access_level_view INTEGER; - -- v_id_access_level_product_required INTEGER; - v_priority_access_level_view INTEGER; - v_priority_access_level_edit INTEGER; - v_priority_access_level_admin INTEGER; - v_id_access_level INTEGER; - v_priority_access_level INTEGER; - v_now TIMESTAMP; - v_ids_row_delete UUID; - v_code_error_data VARCHAR(200); - v_id_error_data INTEGER; - v_code_error_permission VARCHAR(200); - -- result_errors REFCURSOR; - -- v_error_msg TEXT := NULL; -BEGIN - -- Parse arguments + get default values - v_guid := COALESCE(a_guid, gen_random_uuid()); - v_id_user := CASE WHEN a_id_user IS NULL THEN '' ELSE TRIM(a_id_user) END; - v_get_inactive_users := COALESCE(a_get_inactive_users, FALSE); - v_ids_permission := COALESCE(a_ids_permission, ARRAY[]::INTEGER[]); - v_ids_access_level := COALESCE(a_ids_access_level, ARRAY[]::INTEGER[]); - -- v_ids_permutation := CASE WHEN a_ids_permutation IS NULL THEN '' ELSE TRIM(a_ids_permutation) END; - v_ids_product := COALESCE(a_ids_product, ARRAY[]::INTEGER[]); - - v_id_error_data := 1; - v_code_error_data := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = v_id_error_data); - - v_code_error_permission := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 2); - - v_has_filter_user := (v_id_user <= 0); - v_has_filter_permission := (CARDINALITY(v_ids_permission) > 0); - v_has_filter_access_level := (CARDINALITY(v_ids_access_level) > 0); - /* - v_has_filter_permutation := CASE WHEN v_ids_permutation = '' THEN FALSE ELSE TRUE END; - */ - v_has_filter_product := (CARDINALITY(v_ids_product) = 0); - v_id_access_level_view := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW' LIMIT 1); - v_priority_access_level_view := (SELECT priority FROM Shop_Access_Level WHERE id_access_level = v_id_access_level_view); - v_priority_access_level_edit := (SELECT priority FROM Shop_Access_Level WHERE code = 'EDIT' LIMIT 1); - v_priority_access_level_admin := (SELECT priority FROM Shop_Access_Level WHERE code = 'ADMIN' LIMIT 1); - - v_id_permission_product := (SELECT v_id_permission FROM Shop_Permission WHERE code = 'SHOP_PRODUCT' LIMIT 1); - - -- Clear previous proc results - -- DROP TABLE IF EXISTS tmp_User_Role_Link; - -- DROP TEMPORARY TABLE IF EXISTS tmp_User_Role_Link; - DROP TABLE IF EXISTS tmp_Shop_Product_p_shop_calc_user; - -- DROP TABLE IF EXISTS Shop_Calc_User_Temp; - - - -- Permanent Table - CREATE TABLE IF NOT EXISTS Shop_Calc_User_Temp ( - id_row INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - guid UUID NOT NULL, - id_user INTEGER, - CONSTRAINT FK_Shop_Calc_User_Temp_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User (id_user), - id_permission_required INTEGER NOT NULL, - CONSTRAINT FK_Shop_Calc_User_Temp_id_permission_required - FOREIGN KEY (id_permission_required) - REFERENCES Shop_Permission (id_permission), - /* - id_access_level_required INTEGER NOT NULL, - CONSTRAINT FK_Shop_Calc_User_Temp_id_access_level_required - FOREIGN KEY (id_access_level_required) - REFERENCES Shop_Access_Level (id_access_level), - */ - priority_access_level_required INTEGER NOT NULL, - /* - CONSTRAINT FK_Shop_Calc_User_Temp_priority_access_level_required - FOREIGN KEY (priority_access_level_required) - REFERENCES Shop_Access_Level (priority), - */ - id_product INTEGER NULL, - CONSTRAINT FK_Shop_Calc_User_Temp_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product (id_product), - /* - id_permutation INTEGER NULL, - CONSTRAINT FK_Shop_Calc_User_Temp_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES parts.Shop_Product_Permutation (id_permutation), - */ - is_super_user BOOLEAN NULL, - priority_access_level_user INTEGER NULL, - /* - CONSTRAINT FK_Shop_Calc_User_Temp_priority_access_level_minimum - FOREIGN KEY (priority_access_level_minimum) - REFERENCES Shop_Access_Level (priority) - */ - can_view BOOLEAN, - can_edit BOOLEAN, - can_admin BOOLEAN, -- DEFAULT 0 - name_error VARCHAR(200) NULL - ); - - -- Temporary tables - CREATE TEMPORARY TABLE tmp_Shop_Product_p_shop_calc_user ( - id_row INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_product INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_p_shop_calc_user_id_product FOREIGN KEY (id_product) - REFERENCES Shop_Product (id_product), - /* - id_permutation INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_p_shop_calc_user_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES parts.Shop_Product_Permutation (id_permutation), - */ - id_access_level_required INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_p_shop_calc_user_id_access_level_required - FOREIGN KEY (id_access_level_required) - REFERENCES Shop_Access_Level (id_access_level), - guid UUID NOT NULL, - rank_product INTEGER NOT NULL - ); - - /* - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - guid UUID NOT NULL, - id_type INTEGER NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type (id_type), - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - */ - - - -- Permission IDs - IF v_has_filter_permission THEN - -- CALL p_split(a_guid, v_ids_permission, ','); - - -- Invalid - IF EXISTS ( - SELECT UNNEST(v_ids_permission) AS id_permission - EXCEPT - SELECT id_permission FROM Shop_Permission - ) THEN -- (SELECT PERM.id_permission FROM Split_Temp ST LEFT JOIN Shop_Permission PERM ON ST.substring = PERM.id_permission WHERE ISNULL(PERM.id_permission)) THEN - /* - INSERT INTO tmp_Msg_Error ( - guid, - id_type, - code, - msg - ) - SELECT - v_guid, - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_data LIMIT 1), - v_code_error_data, - 'Invalid permission IDs: ' || COALESCE(STRING_AGG(ST.substring, ', '), 'NULL') - FROM Split_Temp ST - LEFT JOIN Shop_Permission PERM ON ST.substring = PERM.id_permission - WHERE ISNULL(PERM.id_permission) - ; - */ - RAISE EXCEPTION 'Invalid permission IDs: %', ( - SELECT STRING_AGG(id_permission, ', ') - FROM ( - SELECT UNNEST(v_ids_permission) AS id_permission - EXCEPT - SELECT id_permission FROM Shop_Permission - ) Permission - ) - USING ERRCODE = '22000' - ; - END IF; - - -- Inactive - IF EXISTS ( - SELECT UNNEST(v_ids_permission) AS id_permission - EXCEPT - SELECT id_permission FROM Shop_Permission - WHERE active - ) THEN -- (SELECT PERM.id_permission FROM Split_Temp ST INNER JOIN Shop_Permission PERM ON ST.substring = PERM.id_permission WHERE PERM.active = FALSE) THEN - /* - INSERT INTO tmp_Msg_Error ( - guid, - id_type, - code, - msg - ) - SELECT - v_guid, - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_data LIMIT 1), - v_code_error_data, - 'The following permissions are not active: ' || COALESCE(STRING_AGG(ST.substring, ', '), 'NULL') - FROM Split_Temp ST - INNER JOIN Shop_Permission PERM ON ST.substring = PERM.id_permission - WHERE PERM.active = FALSE - ; - */ - RAISE EXCEPTION 'Inactive permission IDs: %', ( - SELECT STRING_AGG(id_permission, ', ') - FROM ( - SELECT UNNEST(v_ids_permission) AS id_permission - EXCEPT - SELECT id_permission FROM Shop_Permission - WHERE active - ) Permission - ) - USING ERRCODE = '22000' - ; - END IF; - - -- Get the permission with the highest priority access level required - v_id_permission := ( - SELECT PERMS.id_permission - FROM ( - SELECT PERM2.id_permission - FROM Split_Temp ST - INNER JOIN Shop_Permission PERM2 ON ST.substring = PERM2.id_permission - WHERE PERM.active - UNION - SELECT v_id_permission_product - ) PERMS - INNER JOIN Shop_Permission PERM1 ON PERMS.id_permission = PERM1.id_permission - INNER JOIN Shop_Access_Level AL ON PERM1.id_access_level_required = AL.id_access_level - ORDER BY AL.priority ASC - LIMIT 1 - ); - - -- DROP TABLE Split_Temp; - ELSIF v_has_filter_product THEN - v_id_permission := v_id_permission_product; - ELSE - /* - INSERT INTO tmp_Msg_Error ( - guid, - id_type, - code, - msg - ) - VALUES ( - v_guid, - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_data LIMIT 1), - v_code_error_data, - 'Permission ID required' - ) - ; - */ - RAISE EXCEPTION 'Permission ID required.' - USING ERRCODE = '22000' - ; - END IF; - - -- access level - IF v_has_filter_access_level THEN - IF EXISTS ( - /* - SELECT ST.substring - FROM Split_Temp ST - LEFT JOIN Shop_Access_Level AL - ON ST.substring = AL.id_access_level - WHERE - ISNULL(AL.id_access_level) - OR AL.active = FALSE - */ - SELECT UNNEST(v_ids_access_level) AS id_access_level - EXCEPT - SELECT id_access_level FROM Shop_Access_Level - ) THEN - /* - INSERT INTO tmp_Msg_Error ( - guid, - id_type, - code, - msg - ) - SELECT - v_guid, - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_data LIMIT 1), - v_code_error_data, - 'Invalid access level IDs: ' || STRING_AGG(ST.substring, ', ') - FROM Split_Temp ST - LEFT JOIN Shop_Access_Level AL ON ST.substring = AL.id_access_level - WHERE ISNULL(AL.id_access_level) - ; - */ - RAISE EXCEPTION 'Invalid access level IDs: %', ( - SELECT STRING_AGG(id_access_level, ', ') - FROM ( - SELECT UNNEST(v_ids_access_level) AS id_access_level - EXCEPT - SELECT id_access_level FROM Shop_Access_Level - ) AL - ) - USING ERRCODE = '22000' - ; - END IF; - - IF EXISTS ( - SELECT UNNEST(v_ids_access_level) AS id_access_level - EXCEPT - SELECT id_access_level FROM Shop_Access_Level - WHERE active - ) THEN - RAISE EXCEPTION 'Inactive access level IDs: %', ( - SELECT STRING_AGG(id_access_level, ', ') - FROM ( - SELECT UNNEST(v_ids_access_level) AS id_access_level - EXCEPT - SELECT id_access_level FROM Shop_Access_Level - ) AL - ) - USING ERRCODE = '22000' - ; - END IF; - - v_id_access_level := ( - SELECT AL.id_access_level - FROM Shop_Access_Level AL - WHERE - AL.active - AND AL.id_access_level = ANY(v_ids_access_level) - ORDER BY AL.priority ASC - LIMIT 1 - ); - ELSE - v_id_access_level := ( - SELECT id_access_level_required AS id_access_level - FROM ( - SELECT id_access_level - FROM Shop_Permission PERM - WHERE - PERM.id_permission = v_id_permission - UNION - SELECT v_id_access_level_view AS id_access_level - ) PERMS - INNER JOIN Shop_Access_Level AL ON PERMS.id_access_level = AL.id_access_level - ORDER BY AL.priority ASC - LIMIT 1 - ); -- v_id_access_level_view; - END IF; - - v_priority_access_level := (SELECT priority FROM Shop_Access_Level WHERE id_access_level = v_id_access_level); - - -- Invalid user ID - IF v_has_filter_user THEN - IF ISNULL((SELECT id_user FROM Shop_User WHERE id_user = v_id_user)) THEN -- NOT v_has_filter_user THEN - /* - INSERT INTO tmp_Msg_Error ( - guid, - id_type, - code, - msg - ) - VALUES ( - v_guid, - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_data LIMIT 1), - v_code_error_data, - 'Invalid user ID: ' || COALESCE(v_id_user, 'NULL') - ) - ; - */ - RAISE EXCEPTION 'Invalid user ID: %', v_id_user - USING ERRCODE = '22000' - ; - END IF; - - IF ISNULL((SELECT id_user FROM Shop_User WHERE id_user = v_id_user AND active)) THEN - RAISE EXCEPTION 'Inactive user ID: %', v_id_user - USING ERRCODE = '22000' - ; - END IF; - END IF; - - - -- Invalid products - IF v_has_filter_product THEN - -- Invalid product IDs - IF EXISTS ( - SELECT UNNEST(v_ids_product) AS id_product - EXCEPT - SELECT id_product FROM Shop_Product - ) THEN -- (SELECT * FROM Split_Temp ST LEFT JOIN Shop_Product P ON ST.substring = P.id_product WHERE ISNULL(P.id_product)) THEN - /* - INSERT INTO tmp_Msg_Error ( - guid, - id_type, - code, - msg - ) - SELECT - v_guid, - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_data LIMIT 1), - v_code_error_data, - 'Invalid product IDs: ' || COALESCE(STRING_AGG(ST.substring, ', '), 'NULL') - FROM Split_Temp ST - LEFT JOIN Shop_Product P ON ST.substring = P.id_product - WHERE ISNULL(P.id_product) - ; - */ - RAISE EXCEPTION 'Invalid product IDs: %', ( - SELECT STRING_AGG(id_product, ', ') - FROM ( - SELECT UNNEST(v_ids_product) AS id_product - EXCEPT - SELECT id_product FROM Shop_Product - ) Product - ) - USING ERRCODE = '22000' - ; - END IF; - - INSERT INTO tmp_Shop_Product_p_shop_calc_user ( - id_product, - -- id_permutation, - id_access_level_required, - guid, - rank_product -- rank_permutation - ) - SELECT - DISTINCT P.id_product, - -- PP.id_permutation, - P.id_access_level_required, - v_guid, - RANK() OVER (ORDER BY C.display_order, P.display_order) AS rank_product - FROM Shop_Product P -- ON ST.substring = P.id_product -- Shop_Product_Permutation PP - INNER JOIN Shop_Product_Category C ON P.id_category = C.id_category - INNER JOIN Shop_Access_Level AL - ON P.id_access_level_required = AL.id_access_level - AND AL.active - WHERE -- FIND_IN_SET(P.id_product, v_ids_product) > 0 -- FIND_IN_SET(PP.id_permutation, v_ids_permutation) > 0 - P.id_product = ANY(v_ids_product) - -- AND P.active -- not worried as we want users to be able to see their order history - ; - /* - DELETE FROM tmp_Shop_Product_p_shop_calc_user - WHERE rank_permutation > 1 - ; - */ - -- v_has_filter_product := EXISTS (SELECT * FROM tmp_Shop_Product_p_shop_calc_user WHERE v_guid = guid); - END IF; - - -- User permissions - /* - IF v_has_filter_product THEN - INSERT INTO Shop_Calc_User_Temp ( - guid, - id_user, - id_permission_required, - id_product, - -- id_permutation, - priority_access_level_required, - priority_access_level_user, - is_super_user, - can_view, - can_edit, - can_admin - ) - SELECT - v_guid, - v_id_user, - v_id_permission AS id_permission_required, - P.id_product, - -- t_P.id_permutation, - CASE WHEN v_priority_access_level <= AL_P.priority THEN v_priority_access_level ELSE AL_P.priority END AS priority_access_level_required, - AL_U.priority AS priority_access_level_user, - U.is_super_user, - CASE WHEN U.is_super_user THEN TRUE ELSE CASE WHEN NOT ISNULL(AL_U.priority) AND AL_U.priority <= v_priority_access_level_view AND AL_U.priority <= priority_access_level_required THEN TRUE ELSE FALSE END END AS can_view, - CASE WHEN U.is_super_user THEN TRUE ELSE CASE WHEN NOT ISNULL(AL_U.priority) AND AL_U.priority <= v_priority_access_level_edit AND AL_U.priority <= priority_access_level_required THEN TRUE ELSE FALSE END END AS can_edit, - CASE WHEN U.is_super_user THEN TRUE ELSE CASE WHEN NOT ISNULL(AL_U.priority) AND AL_U.priority <= v_priority_access_level_admin AND AL_U.priority <= priority_access_level_required THEN TRUE ELSE FALSE END END AS can_admin - FROM Shop_User U - /* - ON U.id_user = v_id_user - AND U.active - */ - LEFT JOIN Shop_User_Role_Link URL - ON U.id_user = URL.id_user - AND URL.active - LEFT JOIN Shop_Role_Permission_Link RPL - ON URL.id_role = RPL.id_role - AND RPL.active - INNER JOIN Shop_Access_Level AL_U - ON RPL.id_access_leveL = AL_U.id_access_level - AND AL_U.active - INNER JOIN tmp_Shop_Product_p_shop_calc_user t_P - ON t_P.guid = v_guid - AND AL.id_access_level = t_P.id_access_leveL_required - INNER JOIN Shop_Access_Level AL_P - ON t_P.id_access_leveL_required = AL_P.id_access_level - AND AL_P.active - WHERE - v_guid = t_P.guid - AND U.active - AND U.id_user = v_id_user - ; - ELSE - INSERT INTO Shop_Calc_User_Temp (--UE_T - guid, - id_user, - id_permission_required, - priority_access_level_required, - priority_access_level_user, - is_super_user, - can_view, - can_edit, - can_admin - ) - SELECT - v_guid, - v_id_user, - v_id_permission AS id_permission_required, - v_priority_access_level AS priority_access_level_required, - AL.priority AS priority_access_level_user, - U.is_super_user, - CASE WHEN U.is_super_user THEN TRUE ELSE CASE WHEN NOT ISNULL(AL.priority) AND AL.priority <= v_priority_access_level_view AND AL.priority <= v_priority_access_level THEN TRUE ELSE FALSE END END AS can_view, - CASE WHEN U.is_super_user THEN TRUE ELSE CASE WHEN NOT ISNULL(AL.priority) AND AL.priority <= v_priority_access_level_edit AND AL.priority <= v_priority_access_level THEN TRUE ELSE FALSE END END AS can_edit, - CASE WHEN U.is_super_user THEN TRUE ELSE CASE WHEN NOT ISNULL(AL.priority) AND AL.priority <= v_priority_access_level_admin AND AL.priority <= v_priority_access_level THEN TRUE ELSE FALSE END END AS can_admin - FROM Shop_User U - INNER JOIN Shop_User_Role_Link URL - ON U.id_user = URL.id_user - AND URL.active - INNER JOIN Shop_Role_Permission_Link RPL - ON URL.id_role = RPL.id_role - AND RPL.active - INNER JOIN Shop_Access_Level AL - ON RPL.id_access_level = AL.id_access_level - AND AL.active - WHERE - U.id_user = v_id_user - AND U.active - AND RPL.id_permission = v_id_permission - ORDER BY AL.priority ASC - ; - END IF; - */ - INSERT INTO Shop_Calc_User_Temp (--UE_T - guid, - id_user, - id_permission_required, - id_product, - priority_access_level_required, - priority_access_level_user, - is_super_user, - can_view, - can_edit, - can_admin, - name_error - ) - SELECT - v_guid, - v_id_user, - v_id_permission AS id_permission_required, - t_P.id_product, - MIN(v_priority_access_level, AL_P.priority) AS priority_access_level_required, - AL_U.priority AS priority_access_level_user, - U.is_super_user, - (U.is_super_user AND NOT ISNULL(priority_access_level_user) AND priority_access_level_user <= v_priority_access_level_view AND priority_access_level_user <= priority_access_level_required) AS can_view, - (U.is_super_user AND NOT ISNULL(priority_access_level_user) AND priority_access_level_user <= v_priority_access_level_edit AND priority_access_level_user <= priority_access_level_required) AS can_edit, - (U.is_super_user AND NOT ISNULL(priority_access_level_user) AND priority_access_level_user <= v_priority_access_level_admin AND priority_access_level_user <= priority_access_level_required) AS can_admin, - Permission.name || ' ' || (SELECT name FROM Shop_Access_Level WHERE priority = priority_access_level_required ORDER BY id_access_level ASC LIMIT 1) || ' permissions' || CASE WHEN ISNULL(t_P.id_product) THEN '' ELSE ' for product ' || P.name END AS name_error - FROM Shop_User U - INNER JOIN Shop_User_Role_Link URL - ON U.id_user = URL.id_user - AND URL.active - INNER JOIN Shop_Role_Permission_Link RPL - ON URL.id_role = RPL.id_role - AND RPL.active - INNER JOIN Shop_Access_Level AL_U - ON RPL.id_access_level = AL_U.id_access_level - AND AL_U.active - INNER JOIN Shop_Permission Permission - ON RPL.id_permission = Permission.id_permission - AND Permission.active - CROSS JOIN tmp_Shop_Product_p_shop_calc_user t_P -- ON t_P.guid = v_guid - INNER JOIN Shop_Product P ON t_P.id_product = P.id_product - INNER JOIN Shop_Access_Level AL_P - ON t_P.id_access_level_required = AL_P.id_access_level - -- AND AL_P.active - WHERE - U.id_user = v_id_user - AND U.active - AND RPL.id_permission = v_id_permission - AND t_P.guid = v_guid - ORDER BY AL_P.priority ASC, t_P.rank_product ASC - ; - - -- IF EXISTS (SELECT * FROM tmp_Msg_Error WHERE GUID = v_guid) THEN - /* - OPEN result_errors FOR - SELECT * - FROM tmp_Msg_Error - WHERE GUID = v_guid - ; - -- RETURN NEXT result_errors; - -- result_errors - a_error_msg := ( - SELECT - -- GUID, id_type, code, - msg - FROM tmp_Msg_Error - WHERE GUID = v_guid - LIMIT 1 - ); - */ - - -- select * from tmp_Shop_Product_p_shop_calc_user; - -- Clean up - DROP TABLE IF EXISTS tmp_Shop_Product_p_shop_calc_user; - -- DROP TEMPORARY TABLE IF EXISTS tmp_User_Role_Link; - -- DROP TABLE IF EXISTS tmp_Msg_Error; -END; -$$ LANGUAGE plpgsql; - - -/* - -CALL p_shop_calc_user ( - '56c9dfc1-e22f-11ee-aab4-b42e9986184a', -- v_guid - '', -- v_id_user -- 'auth0|6582b95c895d09a70ba10fef', - false, -- v_get_inactive_users - '4,5', -- v_ids_permission - '1', -- v_ids_access_level - -- null, -- v_ids_product - '1,2,3' -- v_ids_permutation -); - -SELECT * -FROM Shop_Calc_User_Temp -; - -DROP TABLE Shop_Calc_User_Temp; - -SELECT * -FROM Shop_Permission -; - -SELECT * -FROM Shop_Access_Level -; - -SELECT * -FROM Shop_Product -; - -SELECT * -FROM Shop_Product_Permutation -; - - -*/ - -/* -SELECT 'NOODS' AS guid, - U.id_user AS id_user, - P.id_permission AS id_permission_required, - AL.id_access_level AS id_access_level_required, - /* - v_id_permission, - v_id_access_level, - */ - AL.priority, -- MIN(AL.priority), - U.is_super_user - /* - CASE WHEN U.is_super_user THEN TRUE ELSE CASE WHEN priority_access_level_minimum <= v_priority_access_level_view THEN TRUE ELSE FALSE END END, - CASE WHEN U.is_super_user THEN TRUE ELSE CASE WHEN priority_access_level_minimum <= v_priority_access_level_edit THEN TRUE ELSE FALSE END END, - CASE WHEN U.is_super_user THEN TRUE ELSE CASE WHEN priority_access_level_minimum <= v_priority_access_level_admin THEN TRUE ELSE FALSE END END - */ -FROM parts.Shop_User U -INNER JOIN Shop_User_Role_Link URL - ON U.id_user = URL.id_user - AND URL.active -INNER JOIN Shop_Role_Permission_Link RPL - ON URL.id_role = RPL.id_role - AND RPL.active -INNER JOIN Shop_Permission P - ON RPL.id_permission = P.id_permission - AND P.active -inner JOIN Shop_Access_Level AL - -- ON P.id_access_level_required = AL.id_access_level - ON RPL.id_access_level = AL.id_access_level - AND AL.active -WHERE U.id_user = 'auth0|6582b95c895d09a70ba10fef' - AND U.active - AND FIND_IN_SET(P.id_permission, '1,2') > 0 - -- AND v_id_access_level = AL.id_access_leveld --- GROUP BY U.id_user, P.id_permission, AL.id_access_level -- , is_super_user - -*/ - - - --- DROP TABLE IF EXISTS tmp_Shop_Supplier_Purchase_Order_Product_Link; --- DROP TABLE IF EXISTS tmp_Msg_Error; - -CREATE OR REPLACE PROCEDURE p_shop_save_supplier_purchase_order ( - IN a_guid UUID, - IN a_id_user INTEGER, - IN a_comment UUID, - IN a_id_order INTEGER, - IN a_id_supplier_ordered INTEGER, - IN a_id_currency_cost INTEGER, - IN a_active BOOLEAN -) -AS $$ -DECLARE - v_guid UUID; - v_id_user INTEGER; - v_comment VARCHAR(4000); - v_id_order INTEGER; - v_id_supplier_ordered INTEGER; - v_id_currency_cost INTEGER; - v_active BOOLEAN; - v_id_error_type_bad_data INTEGER; - v_code_error_type_bad_data VARCHAR(50); - v_id_error_type_no_permission INTEGER; - v_code_error_type_no_permission VARCHAR(50); - v_guid_permission UUID; - -- v_id_user VARCHAR(100); - v_id_permission_supplier_purchase_order INTEGER; - v_id_access_level_EDIT INTEGER; - v_ids_product VARCHAR(4000); - v_ids_product_no_permission VARCHAR(4000); - -- v_id_order_new INTEGER; - v_id_change_set INTEGER; - v_is_new_supplier_purchase_order BOOLEAN; - -- result_orders REFCURSOR; - -- result_order_product_links REFCURSOR; - -- result_errors REFCURSOR; -BEGIN - -- SET SESSION sql_mode = sys.list_drop(@@session.sql_mode, 'ONLY_FULL_GROUP_BY'); - - v_guid := COALESCE(a_guid, gen_random_uuid()); - v_id_user := TRIM(COALESCE(a_id_user, '')); - v_comment := TRIM(COALESCE(a_comment, '')); - v_id_order := COALESCE(a_id_order, -1); - v_id_supplier_ordered := a_id_supplier_ordered; - v_id_currency_cost := a_id_currency_cost; - v_active := COALESCE(a_active, FALSE); - - v_code_error_type_bad_data = 'BAD_DATA'; - v_id_error_type_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_type_bad_data LIMIT 1); - v_code_error_type_no_permission = 'NO_PERMISSION'; - v_id_error_type_no_permission := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_type_no_permission LIMIT 1); - v_guid_permission = gen_random_uuid(); - -- v_id_user = CURRENT_USER; - v_id_permission_supplier_purchase_order := (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_SUPPLIER_PURCHASE_ORDER' LIMIT 1); - v_id_access_level_EDIT := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'EDIT'); - - v_is_new_supplier_purchase_order := CASE WHEN v_id_order <= 0 THEN TRUE ELSE FALSE END; - - -- Temporary tables - /* - CREATE TABLE tmp_Shop_Supplier_Purchase_Order ( - id_order INTEGER NOT NULL PRIMARY KEY, - id_supplier_ordered INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Supplier_Purchase_Order_id_supplier_ordered - FOREIGN KEY (id_supplier_ordered) - REFERENCES Shop_Supplier(id_supplier), - cost_total_local REAL NOT NULL, - id_currency_cost INTEGER NOT NULL - ); - */ - - CREATE TABLE tmp_Shop_Supplier_Purchase_Order_Product_Link ( - id_link INTEGER NOT NULL PRIMARY KEY, - id_order INTEGER NOT NULL, - /* - CONSTRAINT FK_tmp_Supplier_Purchase_Order_Product_Link_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Supplier_Purchase_Order(id_order), - */ - id_permutation INTEGER NOT NULL, - CONSTRAINT FK_tmp_Supplier_Purchase_Order_Product_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - cost_total_local REAL NOT NULL, - id_currency_cost INTEGER NOT NULL, - quantity_ordered REAL NOT NULL, - id_unit_quantity INTEGER NOT NULL, - CONSTRAINT FK_tmp_Supplier_Purchase_Order_Product_Link_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - quantity_received REAL NULL, - latency_delivery_days INTEGER NOT NULL, - display_order INTEGER NOT NULL, - active BOOLEAN NOT NULL, - name_error VARCHAR(200) NOT NULL - ); - - /* - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - guid UUID NOT NULL, - id_type INTEGER NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type (id_type), - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - */ - - - -- Argument validation - -- User ID - IF NOT EXISTS (SELECT * FROM Shop_User WHERE id_user = v_id_user) THEN - RAISE EXCEPTION 'Invalid User ID: %', COALESCE(v_id_user, 'NULL') - USING ERRCODE = '22000' - ; - END IF; - - -- Order ID - IF ((v_id_order > 0) AND NOT EXISTS (SELECT * FROM Shop_Supplier_Purchase_Order WHERE id_order = v_id_order)) THEN - RAISE EXCEPTION 'Invalid Supplier Purchase Order ID: %', COALESCE(v_id_order, 'NULL') - USING ERRCODE = '22000' - ; - END IF; - - -- Supplier ID - IF ISNULL(v_id_supplier_ordered) OR NOT EXISTS (SELECT * FROM Shop_Supplier WHERE id_supplier = v_id_supplier_ordered) THEN - RAISE EXCEPTION 'Invalid Supplier ID: %', COALESCE(v_id_supplier_ordered, 'NULL') - USING ERRCODE = '22000' - ; - END IF; - - -- Currency ID - IF ISNULL(v_id_currency_cost) OR NOT EXISTS (SELECT * FROM Shop_Currency WHERE id_currency = v_id_currency_cost) THEN - RAISE EXCEPTION 'Invalid currency ID: %', COALESCE(v_id_currency, 'NULL') - USING ERRCODE = '22000' - ; - END IF; - - -- Comment - IF v_comment = '' THEN - RAISE EXCEPTION 'A comment must be provided.' - USING ERRCODE = '22000' - ; - END IF; - - - -- Get data from Temp table - INSERT INTO tmp_Shop_Supplier_Purchase_Order_Product_Link ( - id_link, - id_order, - id_permutation, - cost_total_local, - id_currency_cost, - quantity_ordered, - id_unit_quantity, - quantity_received, - latency_delivery_days, - display_order, - active, - name_error - ) - SELECT - SPOPL_T.id_link, - SPOPL_T.id_order, - SPOPL_T.id_permutation, - PP.cost_local * quantity_ordered AS cost_total_local, - SPOPL_T.id_currency_cost, - SPOPL_T.quantity_ordered, - SPOPL_T.id_unit_quantity, - SPOPL_T.quantity_received, - SPOPL_T.latency_delivery_days, - SPOPL_T.display_order, - SPOPL_T.active, - CAST(PP.id_permutation AS VARCHAR(10)) || ' - ' || COALESCE(PP.name ,'') AS name_error - FROM Shop_Supplier_Purchase_Order_Product_Link_Temp SPOPL_T - INNER JOIN Shop_Product_Permutation PP ON SPOPL_T.id_permutation = PP.id_permutation - WHERE SPOPL_T.GUID = v_guid - ; - DELETE FROM Shop_Supplier_Purchase_Order_Product_Link_Temp SPOPL_T - WHERE SPOPL_T.GUID = v_guid - ; - - /* - UPDATE tmp_Shop_Supplier_Purchase_Order_Product_Link t_SPOPL - - cost_total_local - */ - - -- Invalid quantity ordered - IF EXISTS ( - SELECT * - FROM tmp_Shop_Supplier_Purchase_Order_Product_Link - WHERE - NOT ISNULL(quantity_ordered) - AND quantity_ordered < 0 - ) THEN - RAISE EXCEPTION 'Invalid quantity ordered property for the following permutations: %', ( - SELECT STRING_AGG(t_SPOPL.name_error, ', ') - FROM tmp_Shop_Supplier_Purchase_Order_Product_Link t_SPOPL - -- INNER JOIN Shop_Product_Permutation PP ON t_SPOPL.id_permutation = PP.id_permutation - WHERE t_SPOPL.quantity_ordered < 0 - ) - USING ERRCODE = '22000' - ; - END IF; - - -- Duplicates - IF EXISTS (SELECT id_permutation, name_error, COUNT(*) FROM tmp_Shop_Supplier_Purchase_Order_Product_Link t_SPOPL GROUP BY id_permutation HAVING COUNT(*) > 1) THEN - RAISE EXCEPTION 'Duplicate records: %', || ( - SELECT STRING_AGG(t_SPOPLC.name_error, ', ') - FROM (SELECT id_permutation, name_error, COUNT(*) FROM tmp_Shop_Supplier_Purchase_Order_Product_Link t_SPOPL GROUP BY id_permutation HAVING COUNT(*) > 1) t_SPOPLC - ) - USING ERRCODE = '22000' - ; - END IF; - - - - -- Permissions - v_ids_product := ( - SELECT STRING_AGG(DISTINCT PP.id_product, ',') - FROM tmp_Shop_Supplier_Purchase_Order_Product_Link t_SPO - INNER JOIN Shop_Product_Permutation PP ON t_SPO.id_permutation = PP.id_permutation - ); - - CALL p_shop_calc_user(v_guid_permission, v_id_user, 0, v_id_permission_supplier_purchase_order, v_id_access_level_edit, v_ids_product); - - /* - UPDATE tmp_Shop_Supplier t_S - INNER JOIN Shop_Calc_User_Temp TP - ON TP.GUID = v_guid_permission - SET tP.can_view = TP.can_view, - tP.can_edit = TP.can_edit, - tP.can_admin = TP.can_admin; - */ - /* - v_has_permission := ( - SELECT can_edit - FROM Shop_Calc_User_Temp - WHERE - GUID = v_guid_permission - AND can_edit = 0 - ); - - IF v_has_permission = FALSE THEN - v_id_error_type_no_permission := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'NO_PERMISSION'); - INSERT INTO tmp_Msg_Error ( - guid, id_type, msg - ) - SELECT - v_guid, - v_id_error_type_no_permission, - CONCAT('You do not have ', name, ' permissions.') - FROM Shop_Permission - WHERE id_permission = v_id_permission_supplier_purchase_order - ; - END IF; - */ - v_ids_product_no_permission := ( - SELECT STRING_AGG(PT.id_product, ',') - FROM Shop_Calc_User_Temp PT - WHERE - PT.can_edit = 0 - AND NOT ISNULL(PT.id_product) - ); - IF NOT ISNULL(v_ids_product_no_permission) THEN - RAISE EXCEPTION 'You do not have permission to edit the following product IDs: %', v_ids_product_no_permission - USING ERRCODE = '42501' - ; - END IF; - - DELETE FROM Shop_Calc_User_Temp - WHERE GUID = v_guid; - - -- Transaction - START TRANSACTION; - INSERT INTO Shop_Sales_And_Purchasing_Change_Set ( - comment, - updated_last_by, - updated_last_on - ) - VALUES ( - 'Save ' - || CASE WHEN v_is_new_supplier_purchase_order = TRUE THEN 'new ' ELSE '' END - || 'Supplier Purchase Order - ' - || v_comment, - v_id_user, - CURRENT_TIMESTAMP - ); - - v_id_change_set := (SELECT id_change_set FROM Shop_Sales_And_Purchasing_Change_Set ORDER BY id_change_set DESC LIMIT 1); - - IF (v_is_new_supplier_purchase_order = 1) THEN - INSERT INTO Shop_Supplier_Purchase_Order ( - id_supplier_ordered, - cost_total_local, - id_currency_cost, - created_by, - id_change_set, - active - ) - SELECT - v_id_supplier_ordered, - SUM(t_SPOPL.cost_total_local), - v_id_currency_cost, - v_id_user, - v_id_change_set, - v_active - FROM tmp_Shop_Supplier_Purchase_Order_Product_Link t_SPOPL - ; - -- v_id_order_new - v_id_order := (SELECT id_order FROM Shop_Supplier_Purchase_Order ORDER BY id_order DESC LIMIT 1); - INSERT INTO Shop_Supplier_Purchase_Order_Product_Link ( - id_order, - id_permutation, - cost_total_local, - id_currency_cost, - quantity_ordered, - id_unit_quantity, - quantity_received, - latency_delivery_days, - display_order, - active, - created_by, - id_change_set - ) - SELECT - v_id_order, -- v_id_order_new, - id_permutation, - cost_total_local, - id_currency_cost, - quantity_ordered, - id_unit_quantity, - quantity_received, - latency_delivery_days, - display_order, - active, - v_id_user, - v_id_change_set - FROM tmp_Shop_Supplier_Purchase_Order_Product_Link t_SPOPL - ; - ELSE - UPDATE Shop_Supplier_Purchase_Order SPO - SET - SPO.id_supplier_ordered = v_id_supplier_ordered, - SPO.cost_total_local = SUM(t_SPOPL.cost_total_local), - SPO.id_currency = v_id_currency_cost, - SPO.id_change_set = v_id_change_set, - SPO.active = v_active - FROM Shop_Supplier_Purchase_Order SPO - INNER JOIN tmp_Shop_Supplier_Purchase_Order_Product_Link t_SPOPL ON SPO.id_order = t_SPOPL.id_order - WHERE SPO.id_order = v_id_order - ; - IF EXISTS (SELECT * FROM tmp_Shop_Supplier_Purchase_Order_Product_Link t_SPOPL INNER JOIN Shop_Supplier_Purchase_Order_Product_Link SPOPL ON t_SPOPL.id_link = SPOPL.id_link) THEN - UPDATE Shop_Supplier_Purchase_Order_Product_Link SPOPL - SET - SPOPL.id_order = t_SPOPL.id_order, - SPOPL.id_permutation = t_SPOPL.id_permutation, - SPOPL.cost_total_local = t_SPOPL.cost_total_local, - SPOPL.id_currency_cost = t_SPOPL.id_currency_cost, - SPOPL.quantity_ordered = t_SPOPL.quantity_ordered, - SPOPL.id_unit_quantity = t_SPOPL.id_unit_quantity, - SPOPL.quantity_received = t_SPOPL.quantity_received, - SPOPL.latency_delivery_days = t_SPOPL.latency_delivery_days, - SPOPL.display_order = t_SPOPL.display_order, - SPOPL.active = t_SPOPL.active, - SPOPL.id_change_set = v_id_change_set - FROM Shop_Supplier_Purchase_Order_Product_Link SPOPL - INNER JOIN tmp_Shop_Supplier_Purchase_Order_Product_Link t_SPOPL - ON SPOPL.id_link = t_SPOPL.id_link - ; - ELSE - INSERT INTO Shop_Supplier_Purchase_Order_Product_Link ( - id_order, - id_permutation, - cost_total_local, - id_currency_cost, - quantity_ordered, - id_unit_quantity, - quantity_received, - latency_delivery_days, - display_order, - active, - created_by, - id_change_set - ) - SELECT - id_order, - id_permutation, - cost_total_local, - id_currency_cost, - quantity_ordered, - id_unit_quantity, - quantity_received, - latency_delivery_days, - display_order, - active, - v_id_user, - v_id_change_set - FROM tmp_Shop_Supplier_Purchase_Order_Product_Link t_SPOPL - WHERE t_SPOPL.id_link < 0 - ; - END IF; - END IF; - - COMMIT; - /* - IF EXISTS (SELECT * FROM tmp_Msg_Error) THEN - ROLLBACK; - ELSE - COMMIT; - END IF; - */ - - -- Returns - -- v_now = CURRENT_TIMESTAMP; - /* - -- Supplier Purchase Orders - OPEN result_orders FOR - SELECT * - FROM Shop_Supplier_Purchase_Order - WHERE id_order = v_id_order - ; - -- RETURN NEXT result_orders; - - -- Supplier Purchase Order Product Links - OPEN result_order_product_links FOR - SELECT * - FROM Shop_Supplier_Purchase_Order_Product_Link - WHERE id_order = v_id_order - ; - -- RETURN NEXT result_order_product_links; - */ - -- Errors - /* - OPEN result_errors FOR - SELECT * - FROM tmp_Msg_Error - ; - -- RETURN NEXT result_errors; - */ - - -- DROP TABLE tmp_Shop_Supplier_Purchase_Order; - DROP TABLE tmp_Shop_Supplier_Purchase_Order_Product_Link; - DROP TABLE tmp_Msg_Error; -END; -$$ LANGUAGE plpgsql; - - -/* - -DELETE FROM Shop_Supplier_Purchase_Order_Product_Link_Audit; -DELETE FROM Shop_Supplier_Purchase_Order_Product_Link; -DELETE FROM Shop_Supplier_Purchase_Order_Product_Link_Temp; -DELETE FROM Shop_Supplier_Purchase_Order_Audit; -DELETE FROM Shop_Supplier_Purchase_Order; - -INSERT INTO Shop_Supplier_Purchase_Order_Product_Link_Temp ( - guid, - id_link, - id_order, - id_permutation, - cost_total_local, - id_currency_cost, - quantity_ordered, - id_unit_quantity, - quantity_received, - latency_delivery_days, - display_order, - active -) -VALUES - ( - 'NIPS', -- guid - -1, -- id_link, - -1, -- id_order, - 1, -- id_permutation, - 100, -- cost_total_local, - 1, -- id_currency_cost, - 1, -- quantity_ordered, - 1, -- id_unit_quantity, - 1, -- quantity_received, - 14, -- latency_delivery_days , - 1, -- display_order - 1 -- active - ) -; - -SELECT * FROM Shop_Supplier_Purchase_Order_Product_Link_Temp; - -CALL p_shop_save_supplier_purchase_order ( - 'NIPS', -- a_guid - 'auth0|6582b95c895d09a70ba10fef', -- a_id_user - -1, -- a_id_order - 1, -- a_id_supplier_ordered - 1 -- a_id_currency_cost -); - -SELECT * FROM Shop_Supplier_Purchase_Order_Product_Link_Temp; - -DELETE FROM Shop_Supplier_Purchase_Order_Product_Link_Audit; -DELETE FROM Shop_Supplier_Purchase_Order_Product_Link; -DELETE FROM Shop_Supplier_Purchase_Order_Product_Link_Temp; -DELETE FROM Shop_Supplier_Purchase_Order_Audit; -DELETE FROM Shop_Supplier_Purchase_Order; - - -*/ - - - - - -CREATE OR REPLACE PROCEDURE p_shop_save_supplier ( - IN a_guid UUID, - IN a_id_user INTEGER, - IN a_comment UUID, - IN a_id_supplier INTEGER, - IN a_name_company VARCHAR(256), - IN a_name_contact VARCHAR(256), - IN a_department_contact VARCHAR(256), - IN a_id_address INTEGER, - IN a_phone_number VARCHAR(20), - IN a_fax VARCHAR(20), - IN a_email VARCHAR(515), - IN a_website VARCHAR(300), - IN a_id_currency INTEGER, - IN a_active BOOLEAN -) -AS $$ -DECLARE - v_guid UUID; - v_id_user INTEGER; - v_comment VARCHAR(4000); - v_id_supplier INTEGER; - v_name_company VARCHAR(256); - v_name_contact VARCHAR(256); - v_department_contact VARCHAR(256); - v_id_address INTEGER; - v_phone_number VARCHAR(256); - v_fax VARCHAR(256); - v_email VARCHAR(256); - v_website VARCHAR(256); - v_id_currency INTEGER; - v_active BOOLEAN; - v_id_error_type_bad_data INTEGER; - v_id_error_type_no_permission INTEGER; - v_guid_permission UUID; - v_id_permission_supplier INTEGER; - -- v_id_access_level_EDIT INTEGER; - v_has_permission BOOLEAN; - v_id_change_set INTEGER; - v_is_new_supplier BOOLEAN; - -- result_errors REFCURSOR; -BEGIN - -- SET SESSION sql_mode = sys.list_drop(@@session.sql_mode, 'ONLY_FULL_GROUP_BY'); - - v_guid := COALESCE(a_guid, gen_random_uuid()); - v_id_user := TRIM(COALESCE(a_id_user, '')); - v_comment := TRIM(COALESCE(a_comment, '')); - v_id_supplier := COALESCE(a_id_supplier, -1); - v_name_company := TRIM(COALESCE(a_name_company, '')); - v_name_contact := TRIM(COALESCE(a_name_contact, '')); - v_department_contact := TRIM(COALESCE(a_department_contact, '')); - v_id_address := a_id_address; - v_phone_number := TRIM(COALESCE(a_phone_number, '')); - v_fax := TRIM(COALESCE(a_fax, '')); - v_email := TRIM(COALESCE(a_email, '')); - v_website := TRIM(COALESCE(a_website, '')); - v_id_currency := a_id_currency; - v_active := COALESCE(a_active, FALSE); - - v_id_error_type_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA'); - v_guid_permission = gen_random_uuid(); - v_id_user = CURRENT_USER; - v_id_permission_supplier = (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_SUPPLIER' LIMIT 1); - -- v_id_access_level_EDIT = (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'EDIT'); - v_is_new_supplier := CASE WHEN v_id_supplier <= 0 THEN TRUE ELSE FALSE END; - - - -- Temporary tables - /* - CREATE TABLE tmp_Shop_Supplier ( - id_supplier INTEGER NOT NULL, - name_company VARCHAR(255) NOT NULL, - name_contact VARCHAR(255) NULL, - department_contact VARCHAR(255) NULL, - id_address INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Supplier_id_address - FOREIGN KEY (id_address) - REFERENCES Shop_Address(id_address), - phone_number VARCHAR(50) NULL, - fax VARCHAR(50) NULL, - email VARCHAR(255) NOT NULL, - website VARCHAR(255) NULL, - id_currency INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Supplier_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency), - active BOOLEAN NOT NULL, - can_view BOOLEAN NOT NULL, - can_edit BOOLEAN NOT NULL, - can_admin BOOLEAN NOT NULL - ); - */ - - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - guid UUID NOT NULL, - id_type INTEGER NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type (id_type), - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - - - -- Argument validation - IF v_name_company = '' THEN - /* - INSERT INTO tmp_Msg_Error ( - guid, id_type, msg - ) - VALUES - (v_guid, v_id_error_type_bad_data, 'Supplier company name must be provided') - ; - */ - RAISE EXCEPTION 'Supplier company name must be provided' - USING ERRCODE = '22000' - ; - END IF; - - IF v_id_address IS NULL THEN - /* - INSERT INTO tmp_Msg_Error ( - guid, id_type, msg - ) - VALUES - (v_guid, v_id_error_type_bad_data, 'Address ID must be provided') - ; - */ - RAISE EXCEPTION 'Address ID must be provided' - USING ERRCODE = '22000' - ; - END IF; - - IF v_email = '' THEN - /* - INSERT INTO tmp_Msg_Error ( - guid, id_type, msg - ) - VALUES - (v_guid, v_id_error_type_bad_data, 'Email must be provided') - ; - */ - RAISE EXCEPTION 'Email must be provided.' - USING ERRCODE = '22000' - ; - END IF; - - IF v_comment = '' THEN - RAISE EXCEPTION 'A comment must be provided.' - USING ERRCODE = '22000' - ; - END IF; - - - IF (v_is_new_supplier = FALSE AND NOT EXISTS (SELECT * FROM Shop_Supplier S WHERE S.id_supplier = v_id_supplier)) THEN - RAISE EXCEPTION 'Invalid supplier ID: %', v_id_supplier - USING ERRCODE = '22000' - ; - END IF; - - /* - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - INSERT INTO tmp_Shop_Supplier ( - id_supplier, name_company, name_contact, department_contact, id_address, phone_number, fax, email, website, id_currency, active - ) - VALUES - (v_id_supplier, v_name_company, v_name_contact, v_department_contact, v_id_address, v_phone_number, v_fax, v_email, v_website, v_id_currency, v_active) - /* - FROM Shop_Supplier S - WHERE (NOT v_has_filter_category OR C.id_category LIKE '%' || v_ids_category || '%') - AND (v_get_inactive_categories OR C.active) - */ - ; - END IF; - */ - - -- Permissions - CALL p_shop_calc_user(v_guid_permission, v_id_user, v_id_permission_supplier, ''); - - /* - UPDATE tmp_Shop_Supplier t_S - INNER JOIN Shop_Calc_User_Temp TP - ON TP.GUID = v_guid_permission - SET tP.can_view = TP.can_view, - tP.can_edit = TP.can_edit, - tP.can_admin = TP.can_admin; - */ - v_has_permission := (SELECT can_edit FROM Shop_Calc_User_Temp WHERE GUID = v_guid_permission); - - IF v_has_permission = FALSE THEN - v_id_error_type_no_permission := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'NO_PERMISSION'); - /* - INSERT INTO tmp_Msg_Error ( - guid, id_type, msg - ) - SELECT - v_guid, - v_id_error_type_no_permission, - 'You do not have %' || name || ' permissions.' - FROM Shop_Permission - WHERE id_permission = v_id_permission_supplier - ; - */ - RAISE EXCEPTION 'No permission: %', ( - SELECT name_error - FROM Shop_Calc_User_Temp - WHERE GUID = v_guid_permission - ) - USING ERRCODE = '42501' - ; - END IF; - - -- CALL p_shop_clear_calc_user(v_guid_permission); - - DELETE FROM Shop_Calc_User_Temp - WHERE GUID = v_guid; - - - -- Transaction - INSERT INTO Shop_Sales_And_Purchasing_Change_Set ( - comment, - updated_last_by, - updated_last_on - ) - VALUES ( - 'Save ' - || CASE WHEN v_is_new_supplier = TRUE THEN 'new ' ELSE '' END - || 'Supplier - ' - || v_comment, - v_id_user, - CURRENT_TIMESTAMP - ); - - v_id_change_set := (SELECT id_change_set FROM Shop_Sales_And_Purchasing_Change_Set ORDER BY id_change_set DESC LIMIT 1); - - START TRANSACTION; - IF (v_is_new_supplier = TRUE) THEN - INSERT INTO Shop_Supplier ( - -- id_supplier, - name_company, name_contact, department_contact, id_address, phone_number, fax, email, website, id_currency, active, id_change_set - ) - VALUES - ( - -- v_id_supplier, - v_name_company, v_name_contact, v_department_contact, v_id_address, v_phone_number, v_fax, v_email, v_website, v_id_currency, v_active, v_id_change_set - ) - /* - FROM Shop_Supplier S - WHERE (NOT v_has_filter_category OR C.id_category LIKE '%' || v_ids_category || '%') - AND (v_get_inactive_categories OR C.active) - */ - ; - ELSE - UPDATE Shop_Supplier S - -- INNER JOIN tmp_Shop_Supplier t_S ON S.id_supplier = t_S.id_supplier - SET - /* - S.name_company = t_S.name_company, - S.name_contact = t_S.name_contact, - S.department_contact = t_S.department_contact, - S.id_address = t_S.id_address, - S.phone_number = t_S.phone_number, - S.fax = t_S.fax, - S.email = t_S.email, - S.website = t_S.website, - S.id_currency = t_S.id_currency, - S.active = t_S.active - */ - S.name_company = v_name_company, - S.name_contact = v_name_contact, - S.department_contact = v_department_contact, - S.id_address = v_id_address, - S.phone_number = v_phone_number, - S.fax = v_fax, - S.email = v_email, - S.website = v_website, - S.id_currency = v_id_currency, - S.active = v_active, - S.id_change_set = v_id_change_set - ; - END IF; - COMMIT; - - -- Returns - -- v_now = CURRENT_TIMESTAMP; - - -- Errors - /* - OPEN result_errors FOR - SELECT * - FROM tmp_Msg_Error - ; - -- RETURN NEXT result_errors; - */ - - DROP TABLE tmp_Shop_Supplier; - -- DROP TABLE tmp_Msg_Error; -END; -$$ LANGUAGE plpgsql; - - - - - - --- DROP TABLE IF EXISTS tmp_Shop_Manufacturing_Purchase_Order_Product_Link; --- DROP TABLE IF EXISTS tmp_Msg_Error; - -CREATE OR REPLACE PROCEDURE p_shop_save_manufacturing_purchase_order ( - IN a_guid UUID, - IN a_id_user INTEGER, - IN a_id_order INTEGER, - -- IN a_id_supplier_ordered INTEGER, - IN a_id_currency_cost INTEGER, - IN a_active BOOLEAN, - IN a_comment UUID -) -AS $$ -DECLARE - v_guid UUID; - v_id_user INTEGER; - v_comment VARCHAR(4000); - v_id_order INTEGER; - v_id_currency_cost INTEGER; - v_active BOOLEAN; - v_id_error_type_bad_data INTEGER; - v_code_error_type_bad_data VARCHAR(50); - v_id_error_type_no_permission INTEGER; - v_code_error_type_no_permission VARCHAR(50); - v_guid_permission UUID; - -- v_id_user VARCHAR(100); - v_id_permission_manufacturing_purchase_order INTEGER; - v_id_access_level_EDIT INTEGER; - v_ids_product VARCHAR(4000); - v_ids_product_no_permission VARCHAR(4000); - -- v_id_order_new INTEGER; - v_id_change_set INTEGER; - v_is_new_manufacturing_purchase_order BOOLEAN; - result_errors REFCURSOR; -BEGIN - -- SET SESSION sql_mode = sys.list_drop(@@session.sql_mode, 'ONLY_FULL_GROUP_BY'); - - v_guid := COALESCE(a_guid, gen_random_uuid()); - v_id_user := TRIM(COALESCE(a_id_user, '')); - v_comment := TRIM(COALESCE(a_comment, '')); - v_id_order := COALESCE(a_id_order, -1); - v_id_currency_cost := a_id_currency_cost; - v_active := COALESCE(a_active, FALSE); - - v_code_error_type_bad_data = 'BAD_DATA'; - v_id_error_type_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_type_bad_data LIMIT 1); - v_code_error_type_no_permission = 'NO_PERMISSION'; - v_id_error_type_no_permission := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_type_no_permission LIMIT 1); - v_guid_permission = gen_random_uuid(); - -- v_id_user = CURRENT_USER; - v_id_permission_manufacturing_purchase_order := (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_MANUFACTURING_PURCHASE_ORDER' LIMIT 1); - v_id_access_level_EDIT := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'EDIT'); - v_is_new_manufacturing_purchase_order := CASE WHEN v_id_order <= 0 THEN TRUE ELSE FALSE END; - - -- Temporary tables - /* - CREATE TABLE tmp_Shop_Supplier_Purchase_Order ( - id_order INTEGER NOT NULL PRIMARY KEY, - id_supplier_ordered INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Supplier_Purchase_Order_id_supplier_ordered - FOREIGN KEY (id_supplier_ordered) - REFERENCES Shop_Supplier(id_supplier), - cost_total_local REAL NOT NULL, - id_currency_cost INTEGER NOT NULL - ); - */ - - CREATE TABLE tmp_Shop_Manufacturing_Purchase_Order_Product_Link ( - id_link INTEGER NOT NULL PRIMARY KEY, - id_order INTEGER NOT NULL, - /* - CONSTRAINT FK_tmp_Supplier_Purchase_Order_Product_Link_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Manufacturing_Purchase_Order(id_order), - */ - id_permutation INTEGER NOT NULL, - CONSTRAINT FK_tmp_Manuf_Purch_Order_Product_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - cost_total_local REAL NOT NULL, - id_currency_cost INTEGER NOT NULL, - value_produced_total_local REAL NOT NULL, - quantity_used REAL NOT NULL, - id_unit_quantity INTEGER NOT NULL, - CONSTRAINT FK_tmp_Manuf_Purch_Order_Product_Link_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - quantity_produced REAL NULL, - latency_manufacture INTEGER NOT NULL, - display_order INTEGER NOT NULL, - active BOOLEAN NOT NULL, - name_error VARCHAR(200) NOT NULL - ); - - /* - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - guid UUID NOT NULL, - id_type INTEGER NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type (id_type), - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - */ - - - -- Argument validation - -- User ID - IF NOT EXISTS (SELECT * FROM Shop_User WHERE id_user = v_id_user) THEN - RAISE EXCEPTION 'Invalid User ID: %', COALESCE(v_id_user, 'NULL') - USING ERRCODE = '22000' - ; - END IF; - - -- Order ID - IF ((v_id_order > 0) AND NOT EXISTS (SELECT * FROM Shop_Manufacturing_Purchase_Order WHERE id_order = v_id_order)) THEN - RAISE EXCEPTION 'Invalid Manufacturing Purchase Order ID: %', COALESCE(v_id_order, 'NULL') - USING ERRCODE = '22000' - ; - END IF; - - /* - -- Supplier ID - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF ISNULL(v_id_supplier_ordered) OR NOT EXISTS (SELECT * FROM Shop_Supplier WHERE id_supplier = v_id_supplier_ordered) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES - (v_guid, v_id_error_type_bad_data, v_code_error_type_bad_data, CONCAT('Invalid supplier ID: ', COALESCE(v_id_supplier_ordered, 'NULL'))) - ; - END IF; - END IF; - */ - - -- Currency ID - IF ISNULL(v_id_currency_cost) OR NOT EXISTS (SELECT * FROM Shop_Currency WHERE id_currency = v_id_currency_cost) THEN - RAISE EXCEPTION 'Invalid currency ID: %', COALESCE(v_id_currency, 'NULL') - USING ERRCODE = '22000' - ; - END IF; - - -- Comment - IF v_comment = '' THEN - /* - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES - (v_guid, v_id_error_type_bad_data, v_code_error_type_bad_data, 'A comment must be provided.') - ; - */ - RAISE EXCEPTION 'A comment must be provided.' - USING ERRCODE = '22000' - ; - END IF; - - - -- Get data from Temp table - INSERT INTO tmp_Shop_Manufacturing_Purchase_Order_Product_Link ( - id_link, - id_order, - id_permutation, - cost_total_local, - id_currency_cost, - quantity_used, - id_unit_quantity, - quantity_produced, - value_produced_total_local, - latency_manufacture, - display_order, - active, - name_error - ) - SELECT - MPOPL_T.id_link, - MPOPL_T.id_order, - MPOPL_T.id_permutation, - PP.cost_local * MPOPL_T.quantity_used AS cost_total_local, - MPOPL_T.id_currency_cost, - MPOPL_T.quantity_used, - MPOPL_T.id_unit_quantity, - MPOPL_T.quantity_produced, - (PP.cost_local + PP.profit_local_min) * MPOPL_T.quantity_produced AS value_produced_total_local, - MPOPL_T.latency_manufacture, - MPOPL_T.display_order, - MPOPL_T.active, - PP.id_permutation, ' - ' || COALESCE(P.name ,'') AS name_error - FROM Shop_Manufacturing_Purchase_Order_Product_Link_Temp MPOPL_T - INNER JOIN Shop_Product_Permutation PP ON MPOPL_T.id_permutation = PP.id_permutation - INNER JOIN Shop_Product P ON PP.id_product = P.id_product - WHERE MPOPL_T.GUID = v_guid - -- GROUP BY MPOPL_T.id_order, name_error, MPOPL_T.id_link - /* - group by - MPOPL_T.id_link, - MPOPL_T.id_order, - MPOPL_T.id_permutation, - cost_total_local, - MPOPL_T.id_currency_cost, - MPOPL_T.quantity_used, - MPOPL_T.id_unit_quantity, - MPOPL_T.quantity_produced, - value_produced_total_local, - MPOPL_T.latency_manufacture, - MPOPL_T.display_order, - MPOPL_T.active, - name_error - */ - -- GROUP BY id_link, P.id_product, PP.id_permutation - -- GROUP BY name_error, ID_LINK, cost_total_local, value_produced_total_local - ; - DELETE FROM Shop_Manufacturing_Purchase_Order_Product_Link_Temp MPOPL_T - WHERE MPOPL_T.GUID = v_guid - ; - - -- Invalid quantity used - IF EXISTS ( - SELECT * - FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link - WHERE - NOT ISNULL(quantity_used) - AND quantity_used < 0 - ) THEN - /* - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - SELECT - v_guid, - v_id_error_type_bad_data, - v_code_error_type_bad_data, - 'Invalid quantity used property for the following permutations: ' || STRING_AGG(t_MPOPL.name_error, ', ') - FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE t_MPOPL.quantity_used < 0 - ; - */ - RAISE EXCEPTION 'Invalid quantity used property for the following permutations: %', ( - SELECT STRING_AGG(t_MPOPL.name_error, ', ') - FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE t_MPOPL.quantity_used < 0 - ) - USING ERRCODE = '22000' - ; - END IF; - - -- Invalid quantity produced - IF EXISTS ( - SELECT * - FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link - WHERE - NOT ISNULL(quantity_produced) - AND quantity_produced < 0 - ) THEN - /* - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - SELECT - v_guid, - v_id_error_type_bad_data, - v_code_error_type_bad_data, - 'Invalid quantity produced property for the following permutations: ' || STRING_AGG(t_MPOPL.name_error, ', ') - FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE t_MPOPL.quantity_produced < 0 - ; - */ - RAISE EXCEPTION 'Invalid quantity produced property for the following permutations: %', ( - SELECT STRING_AGG(t_MPOPL.name_error, ', ') - FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE t_MPOPL.quantity_produced < 0 - ) - USING ERRCODE = '22000' - ; - END IF; - - -- Duplicates - IF EXISTS (SELECT id_permutation, name_error, COUNT(*) FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL GROUP BY id_permutation HAVING COUNT(*) > 1) THEN - /* - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - SELECT - v_guid, - v_id_error_type_bad_data, - v_code_error_type_bad_data, - 'Duplicate records: ' || STRING_AGG(t_MPOPLC.name_error, ', ') - FROM (SELECT id_permutation, name_error, COUNT(*) FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL GROUP BY id_permutation HAVING COUNT(*) > 1) t_MPOPLC - ; - */ - RAISE EXCEPTION 'Duplicate records: %', ( - SELECT STRING_AGG(t_MPOPLC.name_error, ', ') - FROM (SELECT id_permutation, name_error, COUNT(*) FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL GROUP BY id_permutation HAVING COUNT(*) > 1) t_MPOPLC - ) - USING ERRCODE = '22000' - ; - END IF; - - - -- Permissions - v_ids_product := ( - SELECT STRING_AGG(DISTINCT PP.id_product, ',') - FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPO - INNER JOIN Shop_Product_Permutation PP ON t_MPO.id_permutation = PP.id_permutation - ); - - CALL p_shop_calc_user(v_guid_permission, v_id_user, 0, v_id_permission_manufacturing_purchase_order, v_id_access_level_edit, v_ids_product); - - /* - UPDATE tmp_Shop_Supplier t_S - INNER JOIN Shop_Calc_User_Temp TP - ON TP.GUID = v_guid_permission - SET tP.can_view = TP.can_view, - tP.can_edit = TP.can_edit, - tP.can_admin = TP.can_admin; - */ - /* - v_has_permission := ( - SELECT can_edit - FROM Shop_Calc_User_Temp - WHERE - GUID = v_guid_permission - AND can_edit = 0 - ); - - IF v_has_permission = FALSE THEN - v_id_error_type_no_permission := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'NO_PERMISSION'); - INSERT INTO tmp_Msg_Error ( - guid, id_type, msg - ) - SELECT - v_guid, - v_id_error_type_no_permission, - CONCAT('You do not have ', name, ' permissions.') - FROM Shop_Permission - WHERE id_permission = v_id_permission_manufacturing_purchase_order - ; - END IF; - */ - v_ids_product_no_permission := ( - SELECT STRING_AGG(PT.id_product, ',') - FROM Shop_Calc_User_Temp PT - WHERE - PT.can_edit = 0 - AND NOT ISNULL(PT.id_product) - ); - IF NOT ISNULL(v_ids_product_no_permission) THEN - /* - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES ( - v_guid, - v_id_error_type_no_permission, - v_code_error_type_no_permission, - */ - RAISE EXCEPTION 'You do not have permission to edit the following product IDs: %', v_ids_product_no_permission - USING ERRCODE = '42501' - ; - END IF; - - -- Transaction - START TRANSACTION; - INSERT INTO Shop_Sales_And_Purchasing_Change_Set ( - comment, - updated_last_by, - updated_last_on - ) - VALUES ( - 'Save ' - || CASE WHEN v_is_new_manufacturing_purchase_order = TRUE THEN 'new ' ELSE '' END - || 'Manufacturing Purchase Order - ' - || v_comment, - v_id_user, - CURRENT_TIMESTAMP - ); - - v_id_change_set := (SELECT id_change_set FROM Shop_Sales_And_Purchasing_Change_Set ORDER BY id_change_set DESC LIMIT 1); - - IF (v_is_new_manufacturing_purchase_order = 1) THEN - INSERT INTO Shop_Manufacturing_Purchase_Order ( - -- id_supplier_ordered, - cost_total_local, - id_currency_cost, - value_produced_total_local, - created_by, - id_change_set, - active - ) - SELECT - -- v_id_supplier_ordered, - SUM(t_MPOPL.cost_total_local), - v_id_currency_cost, - SUM(t_MPOPL.value_produced_total_local), - v_id_user, - v_id_change_set, - v_active - FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL - ; - -- v_id_order_new - v_id_order := (SELECT id_order FROM Shop_Manufacturing_Purchase_Order ORDER BY id_order DESC LIMIT 1); - - INSERT INTO Shop_Manufacturing_Purchase_Order_Product_Link ( - id_order, - id_permutation, - cost_total_local, - value_produced_total_local, - id_currency_cost, - quantity_used, - id_unit_quantity, - quantity_produced, - latency_manufacture, - display_order, - active, - created_by, - id_change_set - ) - SELECT - v_id_order, -- v_id_order_new, - id_permutation, - cost_total_local, - value_produced_total_local, - id_currency_cost, - quantity_used, - id_unit_quantity, - quantity_produced, - latency_manufacture, - display_order, - active, - v_id_user, - v_id_change_set - FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL - ; - ELSE - UPDATE Shop_Manufacturing_Purchase_Order MPO - SET - -- MPO.id_supplier_ordered = v_id_supplier_ordered, - MPO.cost_total_local = SUM(t_MPOPL.cost_total_local), - MPO.value_produced_total_local = SUM(t_MPOPL.value_produced_total_local), - MPO.id_currency = v_id_currency_cost, - MPO.id_change_set = v_id_change_set, - MPO.active = v_active - FROM Shop_Manufacturing_Purchase_Order MPO - INNER JOIN tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL ON MPO.id_order = t_MPOPL.id_order - WHERE MPO.id_order = v_id_order - ; - IF EXISTS (SELECT * FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL INNER JOIN Shop_Manufacturing_Purchase_Order_Product_Link MPOPL ON t_MPOPL.id_link = MPOPL.id_link) THEN - UPDATE Shop_Manufacturing_Purchase_Order_Product_Link MPOPL - SET - MPOPL.id_order = t_MPOPL.id_order, - MPOPL.id_permutation = t_MPOPL.id_permutation, - MPOPL.cost_total_local = t_MPOPL.cost_total_local, - MPOPL.value_produced_total_local = t_MPOPL.value_produced_total_local, - MPOPL.id_currency_cost = t_MPOPL.id_currency_cost, - MPOPL.quantity_used = t_MPOPL.quantity_used, - MPOPL.id_unit_quantity = t_MPOPL.id_unit_quantity, - MPOPL.quantity_produced = t_MPOPL.quantity_produced, - MPOPL.latency_manufacture = t_MPOPL.latency_manufacture, - MPOPL.display_order = t_MPOPL.display_order, - MPOPL.active = t_MPOPL.active, - MPOPL.id_change_set = v_id_change_set - FROM Shop_Manufacturing_Purchase_Order_Product_Link MPOPL - INNER JOIN tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL - ON MPOPL.id_link = t_MPOPL.id_link - ; - ELSE - INSERT INTO Shop_Manufacturing_Purchase_Order_Product_Link ( - id_order, - id_permutation, - cost_total_local, - value_produced_total_local, - id_currency_cost, - quantity_used, - id_unit_quantity, - quantity_produced, - latency_manufacture, - display_order, - active, - created_by, - id_change_set - ) - SELECT - id_order, - id_permutation, - cost_total_local, - value_produced_total_local, - id_currency_cost, - quantity_used, - id_unit_quantity, - quantity_produced, - latency_manufacture, - display_order, - active, - v_id_user, - v_id_change_set - FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE t_MPOPL.id_link < 0 - ; - END IF; - END IF; - - COMMIT; - - -- Returns - -- v_now = CURRENT_TIMESTAMP; - /* - -- Manufacturing Purchase Orders - SELECT * - FROM Shop_Manufacturing_Purchase_Order - WHERE - id_order = v_id_order - -- GUID = v_guid - ; - - -- Manufacturing Purchase Order Product Links - SELECT * - FROM Shop_Manufacturing_Purchase_Order_Product_Link - WHERE - id_order = v_id_order - -- GUID = v_guid - ; - */ - - -- Errors - /* - OPEN result_errors FOR - SELECT * - FROM tmp_Msg_Error - ; - -- RETURN NEXT result_errors; - */ - - -- DROP TABLE tmp_Shop_Manufacturing_Purchase_Order; - DROP TABLE tmp_Shop_Manufacturing_Purchase_Order_Product_Link; - -- DROP TABLE tmp_Msg_Error; -END; -$$ LANGUAGE plpgsql; - - -/* - -DELETE FROM Shop_Manufacturing_Purchase_Order_Product_Link_Audit; -DELETE FROM Shop_Manufacturing_Purchase_Order_Product_Link; -DELETE FROM Shop_Manufacturing_Purchase_Order_Product_Link_Temp; -DELETE FROM Shop_Manufacturing_Purchase_Order_Audit; -DELETE FROM Shop_Manufacturing_Purchase_Order; - -INSERT INTO Shop_Manufacturing_Purchase_Order_Product_Link_Temp ( - guid, - id_link, - id_order, - id_permutation, - cost_total_local, - id_currency_cost, - quantity_used, - id_unit_quantity, - quantity_produced, - latency_manufacture, - display_order, - active -) -VALUES - ( - 'NIPS', -- guid - -1, -- id_link, - -1, -- id_order, - 1, -- id_permutation, - 100, -- cost_total_local, - 1, -- id_currency_cost, - 1, -- quantity_used, - 1, -- id_unit_quantity, - 1, -- quantity_produced, - 14, -- latency_manufacture , - 1, -- display_order - 1 -- active - ) -; - -SELECT * FROM Shop_Manufacturing_Purchase_Order_Product_Link_Temp; - -CALL p_shop_save_manufacturing_purchase_order ( - 'NIPS', -- a_guid - 'auth0|6582b95c895d09a70ba10fef', -- a_id_user - -1, -- a_id_order - 1, -- a_id_currency_cost - 1, -- a_active - 'Initial data' -- a_comment -); - -SELECT * FROM Shop_Manufacturing_Purchase_Order_Product_Link_Temp; - -DELETE FROM Shop_Manufacturing_Purchase_Order_Product_Link_Audit; -DELETE FROM Shop_Manufacturing_Purchase_Order_Product_Link; -DELETE FROM Shop_Manufacturing_Purchase_Order_Product_Link_Temp; -DELETE FROM Shop_Manufacturing_Purchase_Order_Audit; -DELETE FROM Shop_Manufacturing_Purchase_Order; - - -*/ - - - - - -CREATE OR REPLACE PROCEDURE p_shop_save_customer ( - IN a_guid UUID, - IN a_id_user INTEGER, - IN a_comment UUID, - IN a_id_customer INTEGER, - IN a_name_company VARCHAR(256), - IN a_name_contact VARCHAR(256), - IN a_department_contact VARCHAR(256), - IN a_id_address INTEGER, - IN a_phone_number VARCHAR(20), - IN a_email VARCHAR(515), - IN a_id_currency INTEGER, - IN a_active BOOLEAN -) -AS $$ -DECLARE - v_guid UUID; - v_id_user INTEGER; - v_comment VARCHAR(4000); - v_id_customer INTEGER; - v_name_company VARCHAR(256); - v_name_contact VARCHAR(256); - v_department_contact VARCHAR(256); - v_id_address INTEGER; - v_phone_number VARCHAR(256); - v_email VARCHAR(256); - v_id_currency INTEGER; - v_active BOOLEAN; - v_id_error_type_bad_data INTEGER; - v_id_error_type_no_permission INTEGER; - v_guid_permission UUID; - v_id_permission_customer INTEGER; - v_id_access_level_EDIT INTEGER; - v_has_permission BOOLEAN; - v_id_change_set INTEGER; - v_is_new_customer BOOLEAN; - -- result_errors REFCURSOR; -BEGIN - -- SET SESSION sql_mode = sys.list_drop(@@session.sql_mode, 'ONLY_FULL_GROUP_BY'); - - v_guid := COALESCE(a_guid, gen_random_uuid()); - v_id_user := TRIM(COALESCE(a_id_user, '')); - v_comment := TRIM(COALESCE(a_comment, '')); - v_id_customer := COALESCE(a_id_customer, -1); - v_name_company := TRIM(COALESCE(a_name_company, '')); - v_name_contact := TRIM(COALESCE(a_name_contact, '')); - v_department_contact := TRIM(COALESCE(a_department_contact, '')); - v_id_address := a_id_address; - v_phone_number := TRIM(COALESCE(a_phone_number, '')); - v_email := TRIM(COALESCE(a_email, '')); - v_id_currency := a_id_currency; - v_active := COALESCE(a_active, FALSE); - - v_id_error_type_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA'); - v_guid_permission = gen_random_uuid(); - v_id_permission_customer = (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_CUSTOMER' LIMIT 1); - v_id_access_level_EDIT = (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'EDIT'); - v_is_new_customer := CASE WHEN v_id_customer <= 0 THEN TRUE ELSE FALSE END; - - -- Temporary tables - /* - CREATE TABLE tmp_Shop_Customer ( - id_customer INTEGER NOT NULL, - name_company VARCHAR(255) NOT NULL, - name_contact VARCHAR(255) NULL, - department_contact VARCHAR(255) NULL, - id_address INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Customer_id_address - FOREIGN KEY (id_address) - REFERENCES Shop_Address(id_address), - phone_number VARCHAR(50) NULL, - fax VARCHAR(50) NULL, - email VARCHAR(255) NOT NULL, - website VARCHAR(255) NULL, - id_currency INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Customer_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency), - active BOOLEAN NOT NULL, - can_view BOOLEAN NOT NULL, - can_edit BOOLEAN NOT NULL, - can_admin BOOLEAN NOT NULL - ); - */ - /* - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - guid UUID NOT NULL, - id_type INTEGER NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type (id_type), - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - */ - - -- Argument validation - IF v_name_company = '' THEN - RAISE EXCEPTION 'Customer company name must be provided' - USING ERRCODE = '22000' - ; - END IF; - IF v_id_address IS NULL THEN - /* - INSERT INTO tmp_Msg_Error ( - guid, id_type, msg - ) - VALUES - (v_guid, v_id_error_type_bad_data, 'Customer address ID must be provided') - ; - */ - RAISE EXCEPTION 'Customer address ID must be provided' - USING ERRCODE = '22000' - ; - END IF; - IF v_email = '' THEN - /* - INSERT INTO tmp_Msg_Error ( - guid, id_type, msg - ) - VALUES - (v_guid, v_id_error_type_bad_data, 'Customer email must be provided') - ; - */ - RAISE EXCEPTION 'Customer email must be provided' - USING ERRCODE = '22000' - ; - END IF; - - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - /* - IF (v_is_new_customer = FALSE AND NOT EXISTS (SELECT * FROM Shop_Customer C WHERE C.id_customer = v_id_customer)) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, msg - ) - VALUES - (v_guid, v_id_error_type_bad_data, 'Invalid customer ID: ' || v_id_customer) - ; - END IF; - */ - RAISE EXCEPTION 'Invalid customer ID: %', v_id_customer - USING ERRCODE = '22000' - ; - END IF; - - /* - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - INSERT INTO tmp_Shop_Customer ( - id_customer, name_company, name_contact, department_contact, id_address, phone_number, fax, email, website, id_currency, active - ) - VALUES - (v_id_customer, v_name_company, v_name_contact, v_department_contact, v_id_address, v_phone_number, v_fax, v_email, v_website, v_id_currency, v_active) - /* - FROM Shop_Customer S - WHERE (NOT v_has_filter_category OR C.id_category LIKE '%' || v_ids_category || '%') - AND (v_get_inactive_categories OR C.active) - */ - ; - END IF; - */ - - -- Permissions - CALL p_shop_calc_user(v_guid_permission, v_id_user, 0, v_id_permission_customer, v_id_access_level_edit, ''); - - /* - UPDATE tmp_Shop_Customer t_S - INNER JOIN Shop_Calc_User_Temp TP - ON TP.GUID = v_guid_permission - SET tP.can_view = TP.can_view, - tP.can_edit = TP.can_edit, - tP.can_admin = TP.can_admin; - */ - v_has_permission := (SELECT can_edit FROM Shop_Calc_User_Temp WHERE GUID = v_guid_permission); - - IF v_has_permission = FALSE THEN - v_id_error_type_no_permission := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'NO_PERMISSION'); - /* - INSERT INTO tmp_Msg_Error ( - guid, id_type, msg - ) - SELECT - v_guid, - v_id_error_type_no_permission, - 'You do not have ' || name || ' permissions.' - FROM Shop_Permission - WHERE id_permission = v_id_permission_customer - ; - RAISE EXCEPTION 'You do not have ' || name || ' permissions.' - FROM Shop_Permission - WHERE id_permission = v_id_permission_customer - USING ERRCODE = '22000' - ; - */ - END IF; - - -- CALL p_shop_clear_calc_user(v_guid_permission); - - DELETE FROM Shop_Calc_User_Temp - WHERE GUID = v_guid; - - - -- Transaction - INSERT INTO Shop_Sales_And_Purchasing_Change_Set ( - comment, - updated_last_by, - updated_last_on - ) - VALUES ( - 'Save ' - || CASE WHEN v_is_new_customer = TRUE THEN 'new ' ELSE '' END - || 'Customer - ' - || v_comment, - v_id_user, - CURRENT_TIMESTAMP - ); - - v_id_change_set := (SELECT id_change_set FROM Shop_Sales_And_Purchasing_Change_Set ORDER BY id_change_set DESC LIMIT 1); - - START TRANSACTION; - IF (v_is_new_customer = TRUE) THEN - INSERT INTO Shop_Customer ( - -- id_customer, - name_company, name_contact, department_contact, id_address, phone_number, email, id_currency, active, id_change_set - ) - VALUES - ( - -- v_id_customer, - v_name_company, v_name_contact, v_department_contact, v_id_address, v_phone_number, v_email, v_id_currency, v_active, v_id_change_set - ) - /* - FROM Shop_Customer S - WHERE (NOT v_has_filter_category OR C.id_category LIKE '%' || v_ids_category || '%') - AND (v_get_inactive_categories OR C.active) - */ - ; - ELSE - UPDATE Shop_Customer C - -- INNER JOIN tmp_Shop_Customer t_S ON S.id_customer = t_S.id_customer - SET - /* - S.name_company = t_S.name_company, - S.name_contact = t_S.name_contact, - S.department_contact = t_S.department_contact, - S.id_address = t_S.id_address, - S.phone_number = t_S.phone_number, - S.fax = t_S.fax, - S.email = t_S.email, - S.website = t_S.website, - S.id_currency = t_S.id_currency, - S.active = t_S.active - */ - C.name_company = v_name_company, - C.name_contact = v_name_contact, - C.department_contact = v_department_contact, - C.id_address = v_id_address, - C.phone_number = v_phone_number, - C.email = v_email, - C.id_currency = v_id_currency, - C.active = v_active, - C.id_change_set = v_id_change_set - ; - END IF; - - COMMIT; - - -- Returns - -- v_now = CURRENT_TIMESTAMP; - - -- Errors - /* - OPEN result_errors FOR - SELECT * - FROM tmp_Msg_Error - ; - -- RETURN NEXT result_errors; - */ - - -- DROP TABLE tmp_Shop_Customer; - -- DROP TABLE tmp_Msg_Error; -END; -$$ LANGUAGE plpgsql; - - -/* - -CALL p_shop_save_customer ( - 'NIPS', -- a_guid - 'auth0|6582b95c895d09a70ba10fef', -- a_id_user - 'Initial Customer', -- a_comment - '-1', -- a_id_customer - 'good co', -- a_name_company - 'teddy', -- a_name_contact - 'manufacturing', -- a_department_contact - 1, -- a_id_address - 'BRING BRING', -- a_phone_number - 'e@mail.com', -- a_email - 1, -- a_id_currency_cost - 1 -- a_active -); - -SELECT * FROM Shop_Customer -; - -DELETE FROM Shop_Customer -; - -*/ - --- DROP TABLE IF EXISTS tmp_Shop_Customer_Sales_Order_Product_Link; --- DROP TABLE IF EXISTS tmp_Msg_Error; - -CREATE OR REPLACE PROCEDURE p_shop_save_customer_sales_order ( - IN a_guid UUID, - IN a_id_user INTEGER, - IN a_comment VARCHAR(4000), - IN a_id_order INTEGER, - IN a_id_customer INTEGER, - IN a_id_currency_price INTEGER, - IN a_active BOOLEAN -) -AS $$ -DECLARE - v_guid UUID; - v_id_user INTEGER; - v_comment VARCHAR(4000); - v_id_order INTEGER; - v_id_customer INTEGER; - v_id_currency_price INTEGER; - v_active BOOLEAN; - v_id_error_type_bad_data INTEGER; - v_code_error_type_bad_data VARCHAR(50); - v_id_error_type_no_permission INTEGER; - v_code_error_type_no_permission VARCHAR(50); - -- v_guid_permission UUID; - v_id_permission_Customer_Sales_order INTEGER; - v_id_access_level_EDIT INTEGER; - v_ids_product VARCHAR(4000); - v_ids_product_no_permission VARCHAR(4000); - -- v_id_order_new INTEGER; - v_id_change_set INTEGER; - v_is_new_Customer_Sales_order BOOLEAN; - result_errors REFCURSOR; -BEGIN - -- SET SESSION sql_mode = sys.list_drop(@@session.sql_mode, 'ONLY_FULL_GROUP_BY'); - - v_guid := COALESCE(a_guid, gen_random_uuid()); - v_id_user := TRIM(COALESCE(a_id_user, '')); - v_comment := TRIM(COALESCE(a_comment, '')); - v_id_order := COALESCE(a_id_order, -1); - v_id_customer := a_id_customer; - v_id_currency_price := a_id_currency_price; - v_active := COALESCE(a_active, FALSE); - - v_code_error_type_bad_data := 'BAD_DATA'; - v_id_error_type_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_type_bad_data LIMIT 1); - v_code_error_type_no_permission := 'NO_PERMISSION'; - v_id_error_type_no_permission := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_type_no_permission LIMIT 1); - -- v_guid_permission := gen_random_uuid(); - v_id_permission_Customer_Sales_order := (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_CUSTOMER_SALES_ORDER' LIMIT 1); - v_id_access_level_EDIT := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'EDIT'); - - v_is_new_Customer_Sales_order := CASE WHEN v_id_order <= 0 THEN TRUE ELSE FALSE END; - - -- Temporary tables - /* - CREATE TABLE tmp_Shop_Customer_Sales_Order ( - id_order INTEGER NOT NULL PRIMARY KEY, - id_supplier_ordered INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Customer_Sales_Order_id_supplier_ordered - FOREIGN KEY (id_supplier_ordered) - REFERENCES Shop_Supplier(id_supplier), - price_total_local REAL NOT NULL, - id_currency_price INTEGER NOT NULL - ); - */ - - CREATE TABLE tmp_Shop_Customer_Sales_Order_Product_Link ( - id_link INTEGER NOT NULL PRIMARY KEY, - id_order INTEGER NOT NULL, - /* - CONSTRAINT FK_tmp_Supplier_Purchase_Order_Product_Link_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Customer_Sales_Order(id_order), - */ - id_permutation INTEGER NOT NULL, - CONSTRAINT FK_tmp_Supplier_Purchase_Order_Product_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - price_total_local REAL NOT NULL, - id_currency_price INTEGER NOT NULL, - quantity_ordered REAL NOT NULL, - id_unit_quantity INTEGER NOT NULL, - CONSTRAINT FK_tmp_Supplier_Purchase_Order_Product_Link_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - quantity_delivered REAL NULL, - latency_delivery_days INTEGER NOT NULL, - display_order INTEGER NOT NULL, - active BOOLEAN NOT NULL, - name_error VARCHAR(200) NOT NULL - ); - - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - guid UUID NOT NULL, - id_type INTEGER NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type (id_type), - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - - - -- Argument validation - -- User ID - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF NOT EXISTS (SELECT * FROM Shop_User WHERE id_user = v_id_user) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES - (v_guid, v_id_error_type_bad_data, v_code_error_type_bad_data, CONCAT('Invalid User ID: ', COALESCE(v_id_user, 'NULL'))) - ; - END IF; - END IF; - - -- Order ID - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF (v_id_order > 0) AND NOT EXISTS (SELECT * FROM Shop_Customer_Sales_Order WHERE id_order = v_id_order) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES - (v_guid, v_id_error_type_bad_data, v_code_error_type_bad_data, CONCAT('Invalid Customer Sales Order ID: ', COALESCE(v_id_order, 'NULL'))) - ; - END IF; - END IF; - - -- Customer ID - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF ISNULL(v_id_customer) OR NOT EXISTS (SELECT * FROM Shop_Customer WHERE id_customer = v_id_customer) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES - (v_guid, v_id_error_type_bad_data, v_code_error_type_bad_data, CONCAT('Invalid Customer ID: ', COALESCE(v_id_customer, 'NULL'))) - ; - END IF; - END IF; - - -- Currency ID - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF ISNULL(v_id_currency_price) OR NOT EXISTS (SELECT * FROM Shop_Currency WHERE id_currency = v_id_currency_price) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES - (v_guid, v_id_error_type_bad_data, v_code_error_type_bad_data, CONCAT('Invalid currency ID: ', COALESCE(v_id_currency, 'NULL'))) - ; - END IF; - END IF; - - -- Comment - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF v_comment = '' THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES - (v_guid, v_id_error_type_bad_data, v_code_error_type_bad_data, 'A comment must be provided.') - ; - END IF; - END IF; - - - -- Get data from Temp table - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - INSERT INTO tmp_Shop_Customer_Sales_Order_Product_Link ( - id_link, - id_order, - id_permutation, - price_total_local, - id_currency_price, - quantity_ordered, - id_unit_quantity, - quantity_delivered, - latency_delivery_days, - display_order, - active, - name_error - ) - SELECT - CSOPL_T.id_link, - CSOPL_T.id_order, - CSOPL_T.id_permutation, - (PP.cost_local + PP.profit_local_min) * quantity_ordered AS price_total_local, - CSOPL_T.id_currency_price, - CSOPL_T.quantity_ordered, - CSOPL_T.id_unit_quantity, - CSOPL_T.quantity_delivered, - CSOPL_T.latency_delivery_days, - CSOPL_T.display_order, - CSOPL_T.active, - PP.id_permutation || ' - ' || COALESCE(P.name ,'') AS name_error - FROM Shop_Customer_Sales_Order_Product_Link_Temp CSOPL_T - INNER JOIN Shop_Product_Permutation PP ON CSOPL_T.id_permutation = PP.id_permutation - INNER JOIN Shop_Product P ON PP.id_product = P.id_product - WHERE CSOPL_T.GUID = v_guid - ; - DELETE FROM Shop_Customer_Sales_Order_Product_Link_Temp CSOPL_T - WHERE CSOPL_T.GUID = v_guid - ; - - /* - UPDATE tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL - SET - price_total_local - */ - END IF; - - -- Invalid quantity ordered - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF EXISTS ( - SELECT * - FROM tmp_Shop_Customer_Sales_Order_Product_Link - WHERE - NOT ISNULL(quantity_ordered) - AND quantity_ordered < 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - SELECT - v_guid, - v_id_error_type_bad_data, - v_code_error_type_bad_data, - 'Invalid quantity ordered property for the following permutations: ' || STRING_AGG(t_CSOPL.name_error, ', ') - FROM tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL - -- INNER JOIN Shop_Product_Permutation PP ON t_CSOPL.id_permutation = PP.id_permutation - WHERE t_CSOPL.quantity_ordered < 0 - ; - END IF; - END IF; - - -- Duplicates - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF EXISTS (SELECT id_permutation, name_error, COUNT(*) FROM tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL GROUP BY id_permutation HAVING COUNT(*) > 1) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - SELECT - v_guid, - v_id_error_type_bad_data, - v_code_error_type_bad_data, - 'Duplicate records: ' || STRING_AGG(t_CSOPLC.name_error, ', ') - FROM (SELECT id_permutation, name_error, COUNT(*) FROM tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL GROUP BY id_permutation HAVING COUNT(*) > 1) t_CSOPLC - ; - END IF; - END IF; - - - - -- Permissions - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - v_ids_product := ( - SELECT STRING_AGG(DISTINCT PP.id_product, ',') - FROM tmp_Shop_Customer_Sales_Order_Product_Link t_SPO - INNER JOIN Shop_Product_Permutation PP ON t_SPO.id_permutation = PP.id_permutation - ); - - CALL p_shop_calc_user(v_guid_permission, v_id_user, 0, v_id_permission_Customer_Sales_order, v_id_access_level_edit, v_ids_product); - - /* - UPDATE tmp_Shop_Supplier t_S - INNER JOIN Shop_Calc_User_Temp TP - ON TP.GUID = v_guid_permission - SET tP.can_view = TP.can_view, - tP.can_edit = TP.can_edit, - tP.can_admin = TP.can_admin; - */ - /* - SET v_has_permission := ( - SELECT can_edit - FROM Shop_Calc_User_Temp - WHERE - GUID = v_guid_permission - AND can_edit = 0 - ); - - IF v_has_permission = FALSE THEN - v_id_error_type_no_permission := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'NO_PERMISSION'); - INSERT INTO tmp_Msg_Error ( - guid, id_type, msg - ) - SELECT - v_guid, - v_id_error_type_no_permission, - CONCAT('You do not have ', name, ' permissions.') - FROM Shop_Permission - WHERE id_permission = v_id_permission_Customer_Sales_order - ; - END IF; - */ - v_ids_product_no_permission := ( - SELECT STRING_AGG(PT.id_product, ',') - FROM Shop_Calc_User_Temp PT - WHERE - PT.can_edit = 0 - AND NOT ISNULL(PT.id_product) - ); - IF NOT ISNULL(v_ids_product_no_permission) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES ( - v_guid, - v_id_error_type_no_permission, - v_code_error_type_no_permission, - 'You do not have permission to edit the following product IDs: ' || v_ids_product_no_permission - ) - ; - END IF; - - DELETE FROM Shop_Calc_User_Temp - WHERE GUID = v_guid; - END IF; - - -- Transaction - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - START TRANSACTION; - INSERT INTO Shop_Sales_And_Purchasing_Change_Set ( - comment, - updated_last_by, - updated_last_on - ) - VALUES ( - 'Save ' - || CASE WHEN v_is_new_Customer_Sales_order = TRUE THEN 'new ' ELSE '' END - || 'Customer Sales Order - ' - || v_comment, - v_id_user, - CURRENT_TIMESTAMP - ); - - v_id_change_set := (SELECT id_change_set FROM Shop_Sales_And_Purchasing_Change_Set ORDER BY id_change_set DESC LIMIT 1); - - IF (v_is_new_Customer_Sales_order = 1) THEN - INSERT INTO Shop_Customer_Sales_Order ( - id_customer, - price_total_local, - id_currency_price, - created_by, - id_change_set, - active - ) - SELECT - v_id_customer, - SUM(t_CSOPL.price_total_local), - v_id_currency_price, - v_id_user, - v_id_change_set, - v_active - FROM tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL - ; - -- v_id_order_new - v_id_order := (SELECT id_order FROM Shop_Customer_Sales_Order ORDER BY id_order DESC LIMIT 1); - INSERT INTO Shop_Customer_Sales_Order_Product_Link ( - id_order, - id_permutation, - price_total_local, - id_currency_price, - quantity_ordered, - id_unit_quantity, - quantity_delivered, - latency_delivery_days, - display_order, - active, - created_by, - id_change_set - ) - SELECT - v_id_order, -- v_id_order_new, - id_permutation, - price_total_local, - id_currency_price, - quantity_ordered, - id_unit_quantity, - quantity_delivered, - latency_delivery_days, - display_order, - active, - v_id_user, - v_id_change_set - FROM tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL - ; - ELSE - UPDATE Shop_Customer_Sales_Order CSO - SET - CSO.id_customer = v_id_customer, - CSO.price_total_local = SUM(t_CSOPL.price_total_local), - CSO.id_currency = v_id_currency_price, - CSO.id_change_set = v_id_change_set, - CSO.active = v_active - FROM Shop_Customer_Sales_Order CSO - INNER JOIN tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL ON CSO.id_order = t_CSOPL.id_order - WHERE SPO.id_order = v_id_order - ; - IF EXISTS (SELECT * FROM tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL INNER JOIN Shop_Customer_Sales_Order_Product_Link CSOPL ON t_CSOPL.id_link = CSOPL.id_link) THEN - UPDATE Shop_Customer_Sales_Order_Product_Link CSOPL - SET - CSOPL.id_order = t_CSOPL.id_order, - CSOPL.id_permutation = t_CSOPL.id_permutation, - CSOPL.price_total_local = t_CSOPL.price_total_local, - CSOPL.id_currency_price = t_CSOPL.id_currency_price, - CSOPL.quantity_ordered = t_CSOPL.quantity_ordered, - CSOPL.id_unit_quantity = t_CSOPL.id_unit_quantity, - CSOPL.quantity_delivered = t_CSOPL.quantity_delivered, - CSOPL.latency_delivery_days = t_CSOPL.latency_delivery_days, - CSOPL.display_order = t_CSOPL.display_order, - CSOPL.active = t_CSOPL.active, - CSOPL.id_change_set = v_id_change_set - FROM Shop_Customer_Sales_Order_Product_Link CSOPL - INNER JOIN tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL - ON CSOPL.id_link = t_CSOPL.id_link - ; - ELSE - INSERT INTO Shop_Customer_Sales_Order_Product_Link ( - id_order, - id_permutation, - price_total_local, - id_currency_price, - quantity_ordered, - id_unit_quantity, - quantity_delivered, - latency_delivery_days, - display_order, - active, - created_by, - id_change_set - ) - SELECT - id_order, - id_permutation, - price_total_local, - id_currency_price, - quantity_ordered, - id_unit_quantity, - quantity_delivered, - latency_delivery_days, - display_order, - active, - v_id_user, - v_id_change_set - FROM tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL - WHERE t_CSOPL.id_link < 0 - ; - END IF; - END IF; - - COMMIT; - /* - IF EXISTS (SELECT * FROM tmp_Msg_Error) THEN - ROLLBACK; - ELSE - COMMIT; - END IF; - */ - END IF; - - -- Returns - -- v_now := CURRENT_TIMESTAMP; - /* - -- Supplier Purchase Orders - SELECT * - FROM Shop_Customer_Sales_Order - WHERE id_order = v_id_order - ; - - -- Supplier Purchase Order Product Links - SELECT * - FROM Shop_Customer_Sales_Order_Product_Link - WHERE id_order = v_id_order - ; - */ - - -- Errors - OPEN result_errors FOR - SELECT * - FROM tmp_Msg_Error - ; - -- RETURN NEXT result_errors; - - -- DROP TABLE tmp_Shop_Customer_Sales_Order; - DROP TABLE tmp_Shop_Customer_Sales_Order_Product_Link; - DROP TABLE tmp_Msg_Error; -END; -$$ LANGUAGE plpgsql; - - -/* - -DELETE FROM Shop_Customer_Sales_Order_Product_Link_Audit; -DELETE FROM Shop_Customer_Sales_Order_Product_Link; -DELETE FROM Shop_Customer_Sales_Order_Product_Link_Temp; -DELETE FROM Shop_Customer_Sales_Order_Audit; -DELETE FROM Shop_Customer_Sales_Order; - -INSERT INTO Shop_Customer_Sales_Order_Product_Link_Temp ( - guid, - id_link, - id_order, - id_permutation, - price_total_local, - id_currency_price, - quantity_ordered, - id_unit_quantity, - quantity_delivered, - latency_delivery_days, - display_order, - active -) -VALUES - ( - 'NIPS', -- guid - -1, -- id_link, - -1, -- id_order, - 1, -- id_permutation, - 100, -- price_total_local, - 1, -- id_currency_price, - 1, -- quantity_ordered, - 1, -- id_unit_quantity, - 1, -- quantity_delivered, - 14, -- latency_delivery_days , - 1, -- display_order - 1 -- active - ) -; - -SELECT * FROM Shop_Customer_Sales_Order_Product_Link_Temp; - -CALL p_shop_save_customer_sales_order ( - 'NIPS', -- a_guid - 'auth0|6582b95c895d09a70ba10fef', -- a_id_user - 'Initial customer', -- a_comment - -1, -- a_id_order - 4, -- a_id_customer - 1, -- a_id_currency_price - 1 -- a_active -); - -SELECT * FROM Shop_Customer_Sales_Order_Product_Link_Temp; - -DELETE FROM Shop_Customer_Sales_Order_Product_Link_Audit; -DELETE FROM Shop_Customer_Sales_Order_Product_Link; -DELETE FROM Shop_Customer_Sales_Order_Product_Link_Temp; -DELETE FROM Shop_Customer_Sales_Order_Audit; -DELETE FROM Shop_Customer_Sales_Order; - - -*/ - - - - -/* - -CALL p_shop_save_user ( - 'auth0|6582b95c895d09a70ba10fef', -- a_id_user - '', -- a_name - '', -- a_email - 0 -- a_email_verified -) - -*/ - - -CREATE OR REPLACE PROCEDURE p_shop_save_user ( - IN a_id_user INTEGER, - IN a_name VARCHAR(255), - IN a_email VARCHAR(254), - IN a_email_verified BIT -) -AS $$ -DECLARE - v_id_user INTEGER; - v_name VARCHAR(255); - v_email VARCHAR(254); - v_email_verified BIT; - v_has_filter_user BOOLEAN; - result_errors REFCURSOR; -BEGIN - v_id_user := TRIM(COALESCE(a_id_user, '')); - v_name := TRIM(COALESCE(a_name, '')); - v_email := TRIM(COALESCE(a_email, '')); - v_email_verified := COALESCE(a_email_verified, FALSE); - - v_has_filter_user = CASE WHEN v_id_user = '' THEN FALSE ELSE TRUE END; - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Msg_Error; - DROP TABLE IF EXISTS tmp_Shop_User; - - CREATE TABLE tmp_Shop_User ( - id_user INTEGER, - CONSTRAINT FK_tmp_Shop_User_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user), - active BOOLEAN NOT NULL - ); - - CREATE TABLE tmp_Msg_Error ( - display_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_type INTEGER NOT NULL, - -- code VARCHAR(50) NOT NULL, - -- CONSTRAINT chk_tmp_Msg_Error_code CHECK (code IN (SELECT code FROM Shop_Msg_Error_Type)), - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type(id_type), - msg VARCHAR(4000) NOT NULL - ); - - - -- Parse filters - - - -- User - IF v_has_filter_user THEN - INSERT INTO tmp_Shop_User ( - id_user, - active - ) - SELECT id_user, - active - FROM Shop_User - WHERE id_user = v_id_user - AND active - LIMIT 1 - ; - - IF NOT EXISTS (SELECT id_user FROM tmp_Shop_User LIMIT 1) THEN - INSERT INTO Shop_User ( - id_user, - name, - email, - email_verified - ) - VALUES ( - v_id_user, - v_name, - v_email, - v_email_verified - ); - - INSERT INTO tmp_Shop_User ( - id_user, - active - ) - SELECT id_user, - active - FROM Shop_User - WHERE id_user = v_id_user - AND active - LIMIT 1 - ; - END IF; - - v_id_user := (SELECT id_user FROM tmp_Shop_User LIMIT 1); - ELSE - INSERT INTO tmp_Msg_Error ( - id_type, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - 'No user ID provided.' - ) - ; - END IF; - - - /* - IF NOT EXISTS (SELECT msg FROM tmp_Msg_Error LIMIT 1) THEN - END IF; - */ - - - -- Returns - /* - -- User - SELECT * - FROM tmp_Shop_User - ; - */ - - -- Errors - OPEN result_errors FOR - SELECT * - FROM tmp_Msg_Error - ; - -- RETURN NEXT result_errors; - - /* - -- Return arguments for test - SELECT a_id_user, - a_name, - a_email, - a_email_verified - ; - */ - - -- Clean up - DROP TABLE IF EXISTS tmp_Msg_Error; - DROP TABLE IF EXISTS tmp_Shop_User; -END; -$$ LANGUAGE plpgsql; - - -/* - -CALL p_shop_save_user ( - '', - '', - '', - 0 -) - -*/ - - - -/* - -CALL p_shop_edit_user_basket ( - '', -- a_id_user - '', -- a_ids_permutation_basket - '', -- a_quantities_permutation_basket - 1, -- a_id_permutation_edit - NULL, -- a_quantity_permutation_edit - 1, -- a_sum_not_edit - 1, -- a_id_currency_edit - 1 -- a_id_region_purchase -) - -* - - -CREATE OR REPLACE PROCEDURE p_shop_edit_user_basket ( - IN a_id_user INTEGER, - IN a_ids_permutation_basket VARCHAR(4000), - IN a_quantities_permutation_basket VARCHAR(4000), - IN a_id_permutation_edit INTEGER, - IN a_quantity_permutation_edit INTEGER, - IN a_sum_not_edit BOOLEAN, - IN a_id_currency INTEGER, - IN a_id_region_purchase INT -) -AS $$ -DECLARE - v_guid UUID; - v_id_user INTEGER; - v_ids_permutation_basket BOOLEAN; - v_quantities_permutation_basket VARCHAR -- REMAKE WITH TEMP TABLE -BEGIN - -- Argument redeclaration - -- Variable declaration - DECLARE v_has_filter_user BOOLEAN; - DECLARE v_has_filter_permutation_basket BOOLEAN; - DECLARE v_has_filter_permutation_edit BOOLEAN; - DECLARE v_has_filter_region BOOLEAN; - DECLARE v_has_filter_currency BOOLEAN; - DECLARE v_n_id_permutation_basket INTEGER; - DECLARE v_n_quantity_permutation_basket INTEGER; - DECLARE v_row_number INTEGER; - DECLARE v_guid UUID; - -- DECLARE v_id_user VARCHAR(100); - DECLARE v_id_permission_product INTEGER; - DECLARE v_ids_permutation_permission VARCHAR(4000); - DECLARE v_now TIMESTAMP; - -- DECLARE v_quantity_new INTEGER; - DECLARE v_change_set_used BOOLEAN; - DECLARE v_id_change_set INTEGER; - - SET v_guid = gen_random_uuid(); - - -- Argument validation + default values - IF a_id_user IS NULL THEN - SET a_id_user = ''; - ELSE - SET a_id_user = TRIM(a_id_user); - END IF; - IF a_ids_permutation_basket IS NULL THEN - SET a_ids_permutation_basket = ''; - ELSE - SET a_ids_permutation_basket = TRIM(a_ids_permutation_basket); - END IF; - IF a_quantities_permutation_basket IS NULL THEN - SET a_quantities_permutation_basket = ''; - ELSE - SET a_quantities_permutation_basket = TRIM(a_quantities_permutation_basket); - END IF; - IF a_sum_not_edit IS NULL THEN - SET a_sum_not_edit = TRUE; - END IF; - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Msg_Error; - DROP TABLE IF EXISTS tmp_Shop_Basket; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Quantity; - DROP TABLE IF EXISTS tmp_Shop_Product; - DROP TABLE IF EXISTS tmp_Shop_User; - - CREATE TABLE tmp_Shop_User ( - id_user INTEGER, - CONSTRAINT FK_tmp_Shop_User_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user), - active BOOLEAN NOT NULL - ); - - CREATE TABLE tmp_Shop_Product ( - id_product INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - id_permutation INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - display_order INTEGER NOT NULL, - active INTEGER NOT NULL DEFAULT 1 - ); - - CREATE TEMPORARY TABLE tmp_Shop_Quantity( - quantity INTEGER NOT NULL, - display_order INTEGER NOT NULL, - active INTEGER NOT NULL DEFAULT 1 - ); - - CREATE TABLE tmp_Shop_Basket ( - id_category INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Basket_id_category - FOREIGN KEY (id_category) - REFERENCES Shop_Product_Category(id_category), - id_product INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Basket_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - id_permutation INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Basket_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - id_region_purchase INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Basket_id_region_purchase - FOREIGN KEY (id_region_purchase) - REFERENCES Shop_Region(id_region), - id_currency INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Basket_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency), - quantity INTEGER NOT NULL, - active BOOLEAN NOT NULL DEFAULT TRUE - /* - display_order_category INTEGER NOT NULL, - display_order_product INTEGER NOT NULL - */ - ); - - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - guid UUID NOT NULL, - id_type INTEGER NOT NULL, - -- code VARCHAR(50) NOT NULL, - -- CONSTRAINT chk_tmp_Msg_Error_code CHECK (code IN (SELECT code FROM Shop_Msg_Error_Type)), - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type(id_type), - msg VARCHAR(4000) NOT NULL - ); - - - -- Parse filters - SET v_has_filter_user = NOT (a_id_user = ''); - SET v_has_filter_permutation_basket = NOT (a_ids_permutation_basket = ''); - SET v_has_filter_permutation_edit = NOT ISNULL(a_id_permutation_edit); - SET v_has_filter_currency = NOT ISNULL(a_id_currency); - SET v_has_filter_region = NOT ISNULL(a_id_region_purchase); - -- SET v_quantity_new = CASE WHEN a_sum_not_edit THEN quantity + a_quantity_product_edit ELSE a_quantity_product_edit END; - /* - SELECT v_has_filter_user, v_has_filter_basket - ; - - */ - - -- Currency - IF NOT v_has_filter_currency THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - 'Currency ID not provided.' - ) - ; - END IF; - IF v_has_filter_currency AND NOT EXISTS ( SELECT * FROM Shop_Currency WHERE id_currency = a_id_currency) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('Currency ID not found: ', a_id_currency, '.') - ) - ; - END IF; - - -- Region - IF NOT v_has_filter_region THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - 'Region ID not provided.' - ) - ; - END IF; - IF v_has_filter_region AND NOT EXISTS ( SELECT * FROM Shop_Region WHERE id_region = a_id_region_purchase) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('Region ID not found: ', a_id_region_purchase, '.') - ) - ; - END IF; - - -- User - IF v_has_filter_user THEN - INSERT INTO tmp_Shop_User ( - id_user, - active - ) - SELECT id_user, - active - FROM Shop_User - WHERE id_user LIKE CONCAT('%', a_id_user, '%') - AND active - LIMIT 1 - ; - - IF NOT EXISTS (SELECT id_user FROM tmp_Shop_User LIMIT 1) THEN - SET v_has_filter_user = FALSE; - - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('User ID not found: ', a_id_user, '.') - ) - ; - END IF; - - SET a_id_user := (SELECT id_user FROM tmp_Shop_User LIMIT 1); - END IF; - - IF v_has_filter_user AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - SET v_change_set_used = FALSE; - INSERT INTO Shop_User_Change_Set ( - comment - ) - VALUES ( - 'edit basket' - ); - SET v_id_change_set := (SELECT id_change_set FROM Shop_User_Change_Set ORDER BY id_change_set DESC LIMIT 1); - END IF; - - -- Get basket - -- User - IF v_has_filter_user AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - INSERT INTO tmp_Shop_Basket ( - id_category, - id_product, - id_permutation, - id_region_purchase, - id_currency, - quantity, - active - /* - display_order_category, - display_order_product - */ - ) - SELECT - C.id_category, - UB.id_product, - UB.id_permutation, - UB.id_region_purchase, - UB.id_currency, - UB.quantity, - UB.active - /* - C.display_order, - P.display_order - */ - FROM Shop_User_Basket UB - /* - INNER JOIN tmp_Shop_User t_U - ON UB.id_user = t_U.id_user - */ - INNER JOIN Shop_Product_Permutation PP - ON UB.id_product = PP.id_product - AND PP.active - INNER JOIN Shop_Product P - ON PP.id_product = P.id_product - AND P.active - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - AND C.active - WHERE UB.id_user = a_id_user - ; - END IF; - - -- Currency - IF EXISTS (SELECT * FROM tmp_Shop_Basket WHERE active LIMIT 1) - AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - IF EXISTS (SELECT * FROM tmp_Shop_Basket WHERE active AND id_currency != a_id_currency) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT( - 'Currency ID does not match currency of other items in basket. Basket currency: ', - (SELECT code FROM Shop_Currency WHERE id_currency = ( - SELECT - id_currency - FROM tmp_Shop_Basket - WHERE active - AND id_currency != a_id_currency - LIMIT 1 - )), - ', new currency: ', - (SELECT code FROM Shop_Currency WHERE id_currency = a_id_currency), - '.' - ) - ) - ; - END IF; - END IF; - - -- Region - IF EXISTS (SELECT * FROM tmp_Shop_Basket WHERE active LIMIT 1) - AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Shop_Basket - WHERE - active - AND id_region_purchase != a_id_region_purchase - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('Purchase region ID does not match region of other items in basket. Basket currency: ', - (SELECT code FROM Shop_Region WHERE id_region = ( - SELECT - id_region_purchase - FROM tmp_Shop_Basket - WHERE active - AND id_region != a_id_region_purchase - LIMIT 1 - )), - ', new currency: ', - (SELECT code FROM Shop_Region WHERE id_region = a_id_region_purchase), - '.' - ) - ) - ; - END IF; - END IF; - - -- String product id, permutation id, quantity list - IF NOT EXISTS (SELECT * FROM tmp_Shop_Basket WHERE active LIMIT 1) AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN -- NOT v_has_filter_user AND - -- Get product ids - CALL p_split(a_guid, a_ids_permutation_basket, ','); - INSERT INTO tmp_Shop_Product ( - id_product, id_permutation, display_order - ) - SELECT PP.id_product, ST.substring, ST.display_order - FROM Split_Temp ST - INNER JOIN Shop_Product_Permutation PP - ON ST.substring = PP.id_permutation - -- AND PP.active - ; - /* - SELECT substring as id_product, display_order - FROM Split_Temp - ; - */ - DROP TABLE Split_Temp; - - -- Get product quantities - CALL p_split(a_guid, a_quantities_permutation_basket, ','); - INSERT INTO tmp_Shop_Quantity ( - quantity, display_order - ) - SELECT substring, display_order - FROM Split_Temp - ; - /* - SELECT substring AS quantity_product, display_order - FROM Split_Temp - ; - */ - DROP TABLE Split_Temp; - - -- Compare number of product ids to number of quantities - SET v_n_id_permutation_basket := (SELECT display_order FROM tmp_Shop_Product ORDER BY display_order DESC LIMIT 1); - SET v_n_quantity_permutation_basket := (SELECT display_order FROM tmp_Shop_Quantity ORDER BY display_order DESC LIMIT 1); - IF NOT v_n_id_permutation_basket = v_n_quantity_permutation_basket THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('Number of permutations (', v_n_id_permutation_basket, ') does not equal number of quantities (', v_n_quantity_permutation_basket, ') for basket.') - ) - ; - ELSE - INSERT INTO tmp_Shop_Basket ( - id_category, - id_product, - id_permutation, - id_region_purchase, - id_currency, - quantity - ) - SELECT - C.id_category, - P.id_product, - t_P.id_permutation, - a_id_region_purchase, - a_id_currency, - t_Q.quantity - FROM tmp_Shop_Product t_P - INNER JOIN tmp_Shop_Quantity t_Q - ON t_P.display_order = t_Q.display_order - INNER JOIN Shop_Product_Permutation PP - ON t_P.id_permutation = PP.id_permutation - AND PP.active - INNER JOIN Shop_Product P - ON PP.id_product = P.id_product - AND P.active - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - AND C.active - -- RIGHT JOIN tmp_Shop_Basket t_UB ON ISNULL(t_UB.id_product) - -- WHERE t_P.id_product NOT IN (SELECT id_product FROM tmp_Shop_Basket) - ; - - /* - IF EXISTS( - SELECT * - FROM Shop_Product P - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - INNER JOIN tmp_Shop_Basket t_B - ON P.id_product = t_B.id_product - WHERE C.active = FALSE OR P.active = FALSE LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('No valid product IDs in list: ', a_ids_permutation_basket, '.') - ) - ; - END IF; - */ - END IF; - END IF; - - /* - select v_has_filter_edit; - select * from tmp_Shop_Basket; - select * from tmp_Msg_Error; - */ - - - -- Edit basket product - IF v_has_filter_permutation_edit AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM Shop_Product_Permutation PP - INNER JOIN Shop_Product P - ON PP.id_product = P.id_product - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - WHERE - ( - C.active = FALSE - OR P.active = FALSE - OR PP.active = FALSE - ) - AND PP.id_permutation = a_id_permutation_edit - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('Invalid product ID to edit: ', a_id_product_edit, '.') - ) - ; - END IF; - END IF; - IF v_has_filter_permutation_edit AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Shop_Basket - WHERE - id_permutation = a_id_permutation_edit - ) THEN - UPDATE tmp_Shop_Basket - SET quantity = CASE WHEN a_sum_not_edit = TRUE THEN COALESCE(quantity, 0) + a_quantity_permutation_edit ELSE a_quantity_permutation_edit END, - active = CASE WHEN CASE WHEN a_sum_not_edit = TRUE THEN COALESCE(quantity, 0) + a_quantity_permutation_edit ELSE a_quantity_permutation_edit END = FALSE THEN FALSE ELSE TRUE END - WHERE id_permutation = a_id_permutation_edit - ; - - IF EXISTS ( - SELECT * - FROM tmp_Shop_Basket t_B - WHERE t_B.quantity < 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - 'Invalid basket quantity.' - ) - ; - END IF; - - IF v_has_filter_user AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - SET v_change_set_used = TRUE; - - UPDATE Shop_User_Basket UB - INNER JOIN tmp_Shop_Basket t_UB - ON UB.id_permutation = a_id_permutation_edit - SET UB.quantity = t_UB.quantity, - UB.active = t_UB.active, - UB.id_change_set_user = v_id_change_set - WHERE UB.id_permutation = a_id_permutation_edit - AND id_user = a_id_user - ; - END IF; - ELSE - IF a_quantity_permutation_edit < 0 THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - 'Invalid basket quantity.' - ) - ; - ELSE - INSERT INTO tmp_Shop_Basket ( - id_category, - id_product, - id_permutation, - id_region_purchase, - id_currency, - quantity, - active - ) - SELECT - P.id_category, - P.id_product, - PP.id_permutation, - a_id_region_purchase, - a_id_currency, - a_quantity_permutation_edit, - CASE WHEN a_quantity_permutation_edit > 0 THEN TRUE ELSE FALSE END - FROM Shop_Product_Permutation PP - INNER JOIN Shop_Product P - ON PP.id_product = P.id_product - WHERE id_permutation = a_id_permutation_edit - ; - IF v_has_filter_user THEN - IF EXISTS ( - SELECT * - FROM Shop_User_Basket UB - WHERE - UB.id_permutation = a_id_permutation_edit - ) THEN - SET v_change_set_used = TRUE; - - UPDATE Shop_User_Basket - INNER JOIN tmp_Shop_Basket t_UB ON UB.id_permutation = t_UB.id_permutation - SET UB.quantity = t_UB.quantity, - UB.active = t_UB.active, - UB.id_change_set_user = v_id_change_set - WHERE UB.id_permutation = a_id_permutation_edit - AND id_user = a_id_user - ; - ELSE - INSERT INTO Shop_User_Basket ( - id_user, - id_product, - id_permutation, - id_region_purchase, - id_currency, - quantity, - active - ) - SELECT a_id_user, - t_UB.id_product, - t_UB.id_permutation, - t_UB.id_region_purchase, - t_UB.id_currency, - t_UB.quantity, - t_UB.active - FROM tmp_Shop_Basket t_UB - WHERE id_permutation = a_id_permutation_edit - ; - END IF; - END IF; - END IF; - END IF; - END IF; - - - -- Checks - /* - SELECT * FROM tmp_Shop_Basket; - SELECT - STRING_AGG(t_UB.id_product, ',') AS basket_product_ids - FROM tmp_Shop_Basket t_UB - -- WHERE ISNULL(t_UB.id_permutation) - ; - SELECT - STRING_AGG(t_UB.id_permutation, ',') AS basket_permutation_ids - FROM tmp_Shop_Basket t_UB - WHERE NOT ISNULL(t_UB.id_permutation) - ; - */ - -- Returns - CALL p_shop_get_many_product ( - a_id_user, -- a_id_user - 1, -- a_get_all_categories - '', -- a_ids_category - 0, -- a_get_inactive_categories - 0, -- a_get_all_products - ( - SELECT - STRING_AGG(t_B.id_product, ',') - FROM tmp_Shop_Basket t_B - WHERE active = TRUE - ), -- a_ids_product - 0, -- a_get_inactive_products - 0, -- a_get_first_product_only - 0, -- a_get_all_product_permutations - ( - SELECT - STRING_AGG(t_B.id_permutation, ',') - FROM tmp_Shop_Basket t_B - WHERE NOT ISNULL(t_B.id_permutation) - AND active = TRUE - ), -- a_ids_permutation - 0, -- a_get_inactive_permutations - 0, -- a_get_all_images - '', -- a_ids_image - 0, -- a_get_inactive_images - 1, -- a_get_first_image_only - 0, -- a_get_all_delivery_region - a_id_region_purchase, -- a_ids_delivery_region - 0, -- a_get_inactive_delivery_region - 0, -- a_get_all_currency - a_id_currency, -- a_ids_currency - 0, -- a_get_inactive_currency - 1, -- a_get_all_discount - '', -- a_ids_discount - 0 -- a_get_inactive_discount - ); - - -- Basket - SELECT t_UB.id_category, - t_UB.id_product, - t_UB.id_permutation, - P.name, - PCL.price_local_VAT_incl, - PCL.price_local_VAT_excl, - PCL.id_currency, - t_UB.quantity - FROM tmp_Shop_Basket t_UB - INNER JOIN Shop_Product_Permutation PP - ON t_UB.id_permutation = PP.id_permutation - INNER JOIN Shop_Product P - ON PP.id_product = P.id_product - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - INNER JOIN Shop_Product_Currency_Link PCL - ON PP.id_permutation = PCL.id_permutation - AND PCL.id_region_purchase = a_id_region_purchase - AND PCL.id_currency = a_id_currency - WHERE t_UB.active = TRUE - ORDER BY C.display_order, P.display_order - ; - - -- Errors - /* Completed by product get many */ - SELECT - t_ME.display_order, - t_ME.guid, - t_ME.id_type, - t_ME.msg, - MET.code, - MET.name, - MET.description - FROM tmp_Msg_Error t_ME - INNER JOIN Shop_Msg_Error_Type MET - ON t_ME.id_type = MET.id_type - WHERE GUID = v_guid - ; - - /* - -- Return arguments for test - SELECT - a_ids_category, - a_get_inactive_categories, - a_ids_product, - a_get_inactive_products, - a_get_first_product_only, - a_get_all_products, - a_ids_image, - a_get_inactive_images, - a_get_first_image_only, - a_get_all_images - ; - */ - - -- Clean up - IF NOT v_change_set_used THEN - DELETE FROM Shop_User_Change_Set - WHERE id_change_set = v_id_change_set - ; - END IF; - - -- DROP TABLE IF EXISTS tmp_Msg_Error; - DELETE FROM tmp_Msg_Error WHERE guid = v_guid; - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - DROP TABLE tmp_Msg_Error; - END IF; - DROP TABLE IF EXISTS tmp_Shop_Basket; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Quantity; - DROP TABLE IF EXISTS tmp_Shop_Product; - DROP TABLE IF EXISTS tmp_Shop_User; -END; -$$ LANGUAGE plpgsql; - -*/ - - -/* - -CALL p_shop_edit_user_basket ( - '', -- a_id_user - '', -- a_ids_permutation_basket - '', -- a_quantities_permutation_basket - 2, -- a_id_permutation_edit - 1, -- a_quantity_permutation_edit - 1, -- a_sum_not_edit - 2, -- a_id_currency_edit - 1 -- a_id_region_purchase -); - -CALL p_shop_edit_user_basket ( - '', -- a_id_user - '1', -- a_ids_permutation_basket - '9', -- a_quantities_permutation_basket - 1, -- a_id_permutation_edit - 69, -- a_quantity_permutation_edit - 1, -- a_sum_not_edit - 1, -- a_id_currency_edit - 1 -- a_id_region_purchase -); -CALL p_shop_edit_user_basket ( - 'auth0|6582b95c895d09a70ba10feF', -- a_id_user - '2', -- a_ids_permutation_basket - '7', -- a_quantities_permutation_basket - 2, -- a_id_permutation_edit - NULL, -- a_quantity_permutation_edit - 1, -- a_sum_not_edit - 1, -- a_id_currency_edit - 1 -- a_id_region_purchase -); - - - {'a_id_user': 'auth0|6582b95c895d09a70ba10fef', - 'a_ids_permutation_basket': '1', - '7', -- a_quantities_permutation_basket - 'a_id_permutation_edit': 1, - 'a_quantity_permutation_edit': 1, - 'a_sum_not_edit': 1} - - select * from shop_user_basket; - insert into shop_user_change_set (comment) - values( 'deactivate duplicates'); - update SHOP_USER_BASKET - set active = FALSE, - id_change_set_user = (select id_change_set from shop_user_change_set order by id_change_set desc limit 1) - where id_user = 'auth0|6582b95c895d09a70ba10fef' - and id_product = 1 - ; - select * from shop_user_basket; -*/ - - -CREATE OR REPLACE FUNCTION p_shop_get_many_product ( - IN a_id_user INTEGER, - IN a_get_all_category BOOLEAN, - IN a_get_inactive_category BOOLEAN, - IN a_get_first_category_only BOOLEAN, - IN a_ids_category INTEGER[], - IN a_get_all_product BOOLEAN, - IN a_get_inactive_product BOOLEAN, - IN a_get_first_product_only BOOLEAN, - IN a_ids_product INTEGER[], - IN a_get_all_product_permutation BOOLEAN, - IN a_get_inactive_permutation BOOLEAN, - IN a_get_first_permutation_only BOOLEAN, - IN a_ids_permutation INTEGER[], - IN a_get_all_image BOOLEAN, - IN a_get_inactive_image BOOLEAN, - IN a_get_first_image_only BOOLEAN, - IN a_ids_image INTEGER[], - IN a_get_all_delivery_region BOOLEAN, - IN a_get_inactive_delivery_region BOOLEAN, - IN a_ids_delivery_region INTEGER[], - IN a_get_all_currency BOOLEAN, - IN a_get_inactive_currency BOOLEAN, - IN a_ids_currency INTEGER[], - IN a_get_all_discount BOOLEAN, - IN a_get_inactive_discount BOOLEAN, - IN a_ids_discount INTEGER[] -) -RETURNS SETOF REFCURSOR -- categories, SETOF products, SETOF variations, SETOF prices, SETOF images, SETOF delivery_options, SETOF discounts -AS $$ -DECLARE - v_id_user INTEGER; - v_get_all_category BOOLEAN; - v_get_inactive_category BOOLEAN; - v_get_first_category_only BOOLEAN; - v_ids_category INTEGER[]; - v_get_all_product BOOLEAN; - v_get_inactive_product BOOLEAN; - v_get_first_product_only BOOLEAN; - v_ids_product INTEGER[]; - v_get_all_product_permutation BOOLEAN; - v_get_inactive_permutation BOOLEAN; - v_get_first_permutation_only BOOLEAN; - v_ids_permutation INTEGER[]; - v_get_all_image BOOLEAN; - v_get_inactive_image BOOLEAN; - v_get_first_image_only BOOLEAN; - v_ids_image INTEGER[]; - v_get_all_delivery_region BOOLEAN; - v_get_inactive_delivery_region BOOLEAN; - v_ids_delivery_region INTEGER[]; - v_get_all_currency BOOLEAN; - v_get_inactive_currency BOOLEAN; - v_ids_currency INTEGER[]; - v_get_all_discount BOOLEAN; - v_get_inactive_discount BOOLEAN; - v_ids_discount INTEGER[]; - - v_has_filter_category BOOLEAN; - v_has_filter_product BOOLEAN; - v_has_filter_permutation BOOLEAN; - v_has_filter_image BOOLEAN; - v_has_filter_delivery_region BOOLEAN; - v_has_filter_currency BOOLEAN; - v_has_filter_discount BOOLEAN; - v_guid UUID; - -- v_id_user VARCHAR(100); - v_ids_permutation_unavailable VARCHAR(4000); - v_id_permission_product INTEGER; - v_ids_product_permission VARCHAR(4000); - -- v_ids_permutation_permission VARCHAR(4000); - v_id_access_level_view INTEGER; - -- v_now TIMESTAMP; - v_id_minimum INTEGER; - - result_categories REFCURSOR; - result_products REFCURSOR; - result_variations REFCURSOR; - result_prices REFCURSOR; - result_images REFCURSOR; - result_delivery_options REFCURSOR; - result_discounts REFCURSOR; - /* - -- result_errors REFCURSOR; - */ -BEGIN - v_id_user := a_id_user; - v_get_all_category := COALESCE(a_get_all_category, FALSE); - v_get_inactive_category := COALESCE(a_get_inactive_category, FALSE); - v_get_first_category_only := COALESCE(a_get_first_category_only, TRUE); - v_ids_category := COALESCE(a_ids_category, ARRAY[]::INTEGER[]); - v_get_all_product := COALESCE(a_get_all_product, FALSE); - v_get_inactive_product := COALESCE(a_get_inactive_product, FALSE); - v_get_first_product_only := COALESCE(a_get_first_product_only, TRUE); - v_ids_product := COALESCE(a_ids_product, ARRAY[]::INTEGER[]); - v_get_all_product_permutation := COALESCE(a_get_all_product_permutation, FALSE); - v_get_inactive_permutation := COALESCE(a_get_inactive_permutation, FALSE); - v_get_first_permutation_only := COALESCE(a_get_first_permutation_only, TRUE); - v_ids_permutation := COALESCE(a_ids_permutation, ARRAY[]::INTEGER[]); - v_get_all_image := COALESCE(a_get_all_image, TRUE); - v_get_inactive_image := COALESCE(a_get_inactive_image, FALSE); - v_get_first_image_only := COALESCE(a_get_first_image_only, FALSE); - v_ids_image := COALESCE(a_ids_image, ARRAY[]::INTEGER[]); - v_get_all_delivery_region := COALESCE(a_get_all_delivery_region, TRUE); - v_get_inactive_delivery_region := COALESCE(a_get_inactive_delivery_region, FALSE); - v_ids_delivery_region := COALESCE(a_ids_delivery_region, ARRAY[]::INTEGER[]); - v_get_all_currency := COALESCE(a_get_all_currency, TRUE); - v_get_inactive_currency := COALESCE(a_get_inactive_currency, FALSE); - v_ids_currency := COALESCE(a_ids_currency, ARRAY[]::INTEGER[]); - v_get_all_discount := COALESCE(a_get_all_discount, TRUE); - v_get_inactive_discount := COALESCE(a_get_inactive_discount, FALSE); - v_ids_discount := COALESCE(a_ids_discount, ARRAY[]::INTEGER[]); - /* - ROLLBACK; - */ - v_guid := gen_random_uuid(); - v_id_access_level_view := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW'); - - v_has_filter_category = (CARDINALITY(v_ids_category) > 0); - v_has_filter_product = (CARDINALITY(v_ids_product) > 0); - v_has_filter_permutation = (CARDINALITY(v_ids_permutation) > 0); - v_has_filter_image = (CARDINALITY(v_ids_image) > 0); - v_has_filter_delivery_region = (CARDINALITY(v_ids_delivery_region) > 0); - v_has_filter_currency = (CARDINALITY(v_ids_currency) > 0); - v_has_filter_discount = (CARDINALITY(v_ids_discount) > 0); - - /* - SELECT v_id_user, v_get_all_category, v_ids_category, v_get_inactive_category, v_get_all_product, - v_ids_product, v_get_inactive_product, v_get_first_product_only, v_get_all_product_permutation, v_ids_permutation, - v_get_inactive_permutation, v_get_all_image, v_ids_image, v_get_inactive_image, v_get_first_image_only, - v_get_all_delivery_region, v_ids_delivery_region, v_get_inactive_delivery_region, v_get_all_currency, v_ids_currency, - v_get_inactive_currency, v_get_all_discount, v_ids_discount, v_get_inactive_discount - ; - */ - - -- Temporary tables - /* - DROP TEMPORARY TABLE IF EXISTS tmp_Discount; - DROP TEMPORARY TABLE IF EXISTS tmp_Currency; - DROP TEMPORARY TABLE IF EXISTS tmp_Delivery_Region; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Image; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Variation; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Product; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Product_Category; - */ - DROP TABLE IF EXISTS tmp_Discount; - DROP TABLE IF EXISTS tmp_Currency; - DROP TABLE IF EXISTS tmp_Delivery_Region; - DROP TABLE IF EXISTS tmp_Shop_Image; - DROP TABLE IF EXISTS tmp_Shop_Variation; - DROP TABLE IF EXISTS tmp_Shop_Product; - DROP TABLE IF EXISTS tmp_Shop_Product_Category; - - CREATE TEMPORARY TABLE tmp_Shop_Product_Category ( - id_category INTEGER NOT NULL, - /* - CONSTRAINT FK_tmp_Shop_Product_Category_id_category - FOREIGN KEY (id_category) - REFERENCES Shop_Product_Category(id_category), - */ - active BOOLEAN NOT NULL, - display_order INTEGER NOT NULL, - can_view BOOLEAN, - can_edit BOOLEAN, - can_admin BIT - ); - - CREATE TEMPORARY TABLE tmp_Shop_Product ( - id_category INTEGER NOT NULL, - /* - CONSTRAINT FK_tmp_Shop_Product_id_category - FOREIGN KEY (id_category) - REFERENCES Shop_Product_Category(id_category), - */ - id_product INTEGER NOT NULL, - /* - CONSTRAINT FK_tmp_Shop_Product_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - */ - -- product_has_variations BOOLEAN NOT NULL, - id_permutation INTEGER NULL, - /* - CONSTRAINT FK_tmp_Shop_Product_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - */ - active_category BOOLEAN NOT NULL, - active_product BOOLEAN NOT NULL, - active_permutation BOOLEAN NULL, - display_order_category INTEGER NOT NULL, - display_order_product INTEGER NOT NULL, - display_order_permutation INTEGER NULL, - -- rank_permutation INTEGER NOT NULL, -- _in_category - rank_category INTEGER NOT NULL, - rank_product INTEGER NOT NULL, - rank_permutation INTEGER NOT NULL, - name VARCHAR(255) NOT NULL, - description VARCHAR(4000) NOT NULL, - /* - price_GBP_full REAL NOT NULL, - price_GBP_min REAL NOT NULL, - */ - latency_manufacture INTEGER NOT NULL, - quantity_min REAL NOT NULL, - quantity_max REAL NOT NULL, - quantity_step REAL NOT NULL, - quantity_stock REAL NOT NULL, - is_subscription BOOLEAN NOT NULL, - id_unit_measurement_interval_recurrence INTEGER, - /* - CONSTRAINT FK_tmp_Shop_Product_id_unit_measurement_interval_recurrence - FOREIGN KEY (id_unit_measurement_interval_recurrence) - REFERENCES Shop_Interval_Recurrence(id_interval), - */ - count_interval_recurrence INTEGER, - id_stripe_product VARCHAR(100), - product_has_variations BOOLEAN NOT NULL, - can_view BOOLEAN, - can_edit BOOLEAN, - can_admin BOOLEAN - ); - - /* - CREATE TEMPORARY TABLE tmp_Shop_Variation ( - id_variation INTEGER NOT NULL, - id_product INTEGER NOT NULL, - display_order INTEGER NOT NULL - ); - */ - - CREATE TEMPORARY TABLE tmp_Shop_Image ( - id_image INTEGER NOT NULL, - /* - CONSTRAINT FK_tmp_Shop_Image_id_image - FOREIGN KEY (id_image) - REFERENCES Shop_Image(id_image), - */ - id_product INTEGER NOT NULL, - /* - CONSTRAINT FK_tmp_Shop_Image_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - */ - id_permutation INTEGER NULL, - /* - CONSTRAINT FK_tmp_Shop_Image_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - */ - active BOOLEAN NOT NULL, - display_order INTEGER NOT NULL, - rank_in_product_permutation INTEGER NOT NULL - ); - - CREATE TEMPORARY TABLE tmp_Delivery_Region ( - id_region INTEGER NOT NULL, - /* - CONSTRAINT FK_tmp_Delivery_Region_id_region - FOREIGN KEY (id_region) - REFERENCES Shop_Region(id_region), - */ - active BOOLEAN NOT NULL, - display_order INTEGER NOT NULL, - requires_delivery_option BOOLEAN NOT NULL DEFAULT FALSE - ); - - CREATE TEMPORARY TABLE tmp_Currency ( - id_currency INTEGER NOT NULL, - /* - CONSTRAINT FK_tmp_Shop_Currency_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency), - */ - active BOOLEAN NOT NULL, - display_order INTEGER NOT NULL - ); - - CREATE TEMPORARY TABLE tmp_Discount ( - id_discount INTEGER NOT NULL, - /* - CONSTRAINT FK_tmp_Discount_id_discount - FOREIGN KEY (id_discount) - REFERENCES Shop_Discount(id_discount), - */ - active BOOLEAN NOT NULL, - display_order INTEGER NOT NULL - ); - - /* - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - guid UUID NOT NULL, - id_type INTEGER NOT NULL, - /* - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type (id_type), - */ - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - */ - - - INSERT INTO tmp_Shop_Product ( - id_category, - id_product, - id_permutation, - active_category, - active_product, - active_permutation, - display_order_category, - display_order_product, - display_order_permutation, - -- rank_permutation, - rank_category, - rank_product, - rank_permutation, - name, - description, - /* - price_GBP_VAT_incl, - price_GBP_VAT_excl, - price_GBP_min, - */ - latency_manufacture, - quantity_min, - quantity_max, - quantity_step, - quantity_stock, - is_subscription, - id_unit_measurement_interval_recurrence, - count_interval_recurrence, - id_stripe_product, - product_has_variations - ) - SELECT - P.id_category, - P.id_product, - -- P.has_variations AS product_has_variations, - PP.id_permutation, - C.active AS active_category, - P.active AS active_product, - PP.active AS active_permutation, - C.display_order AS display_order_category, - P.display_order AS display_order_product, - PP.display_order AS display_order_permutation, - -- RANK() OVER (ORDER BY C.display_order, P.display_order, PP.display_order) AS rank_permutation, -- PARTITION BY P.id_category -- _in_category - RANK() OVER (ORDER BY C.display_order) AS rank_category, - RANK() OVER (PARTITION BY P.id_category ORDER BY P.display_order) AS rank_product, - RANK() OVER (PARTITION BY P.id_category, P.id_product ORDER BY PP.display_order) AS rank_permutation, - P.name, - PP.description, - /* - PP.price_GBP_VAT_incl, - PP.price_GBP_VAT_excl, - PP.price_GBP_min, - */ - PP.latency_manufacture, - PP.quantity_min, - PP.quantity_max, - PP.quantity_step, - PP.quantity_stock, - PP.is_subscription, - PP.id_unit_measurement_interval_recurrence, - PP.count_interval_recurrence, - PP.id_stripe_product, - P.has_variations - FROM Shop_Product P - INNER JOIN Shop_Product_Permutation PP - ON P.id_product = PP.id_product - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - WHERE - -- permutations - ( - ( - v_get_all_product_permutation - OR ( - v_has_filter_permutation - -- AND FIND_IN_SET(PP.id_permutation, v_ids_permutation) > 0 - AND PP.id_permutation = ANY(v_ids_permutation) - ) - ) - AND (v_get_inactive_permutation OR PP.active) - ) - -- categories - AND ( - ( - v_get_all_category - OR ( - v_has_filter_category - -- AND FIND_IN_SET(P.id_category, v_ids_category) > 0 - AND C.id_category = ANY(v_ids_category) - ) - ) - AND (v_get_inactive_category OR C.active) - ) - -- products - AND ( - ( - v_get_all_product - OR ( - v_has_filter_product - -- AND FIND_IN_SET(P.id_product, v_ids_product) > 0 - AND P.id_product = ANY(v_ids_product) - ) - ) - AND (v_get_inactive_product OR P.active) - ) - ; - - -- select * from tmp_Shop_Product; - - IF v_get_first_category_only THEN - DELETE FROM tmp_Shop_Product t_P - WHERE t_P.rank_category > 1 - ; - END IF; - - IF v_get_first_product_only THEN - DELETE FROM tmp_Shop_Product t_P - WHERE t_P.rank_product > 1 - ; - END IF; - - IF v_get_first_permutation_only THEN - DELETE FROM tmp_Shop_Product t_P - WHERE t_P.rank_permutation > 1 - ; - END IF; - - - INSERT INTO tmp_Shop_Product_Category ( - id_category, - active, - display_order - ) - SELECT DISTINCT C.id_category, - C.active, - C.display_order - FROM tmp_Shop_Product t_P - INNER JOIN Shop_Product_Category C - ON t_P.id_category = C.id_category - ORDER BY C.display_order - ; - - /* - INSERT INTO tmp_Shop_Variation ( - id_variation, id_product -- , display_order - ) - SELECT P.id_variation, P.id_product -- , P.display_order - FROM Shop_Variation V - INNER JOIN tmp_Shop_Product t_P - ON V.id_product = t_P.id_product - WHERE V.active; - */ - - -- Product Images - INSERT INTO tmp_Shop_Image ( - id_product, - id_permutation, - id_image, - active, - display_order, - rank_in_product_permutation - ) - SELECT id_product, - id_permutation, - id_image, - active, - ROW_NUMBER() OVER (ORDER BY display_order_product_temp, display_order_image), - RANK() OVER (PARTITION BY id_product, id_permutation ORDER BY display_order_product_temp, display_order_image) - FROM ( - SELECT t_P.id_product, - I.id_permutation, - I.id_image, - I.active, - I.display_order AS display_order_image, - t_P.rank_permutation AS display_order_product_temp - FROM Shop_Image I - INNER JOIN tmp_Shop_Product t_P - ON I.id_product = t_P.id_product - AND NOT t_P.product_has_variations - UNION - SELECT t_P.id_product, - I.id_permutation, - I.id_image, - I.active, - I.display_order AS display_order_image, - t_P.rank_permutation AS display_order_product_temp - FROM Shop_Image I - INNER JOIN tmp_Shop_Product t_P - ON I.id_permutation = t_P.id_permutation - AND t_P.product_has_variations - ) IPP - WHERE - ( - v_get_all_image - OR v_get_first_image_only - -- OR FIND_IN_SET(id_image, v_ids_image) > 0 - OR IPP.id_image = ANY(v_ids_image) - ) - AND (v_get_inactive_image OR IPP.active) - ; - - IF v_get_first_image_only THEN - DELETE FROM tmp_Shop_Image - WHERE rank_in_product_permutation > 1 - ; - END IF; - - /* - IF v_has_filter_image THEN - DELETE FROM tmp_Shop_Product - WHERE id_product NOT IN (SELECT DISTINCT id_product FROM tmp_Shop_Image); - DELETE FROM tmp_Shop_Product_Category - WHERE id_category NOT IN (SELECT DISTINCT id_category FROM tmp_Shop_Product); - END IF; - */ - - -- Delivery Regions - INSERT INTO tmp_Delivery_Region ( - id_region, - active, - display_order, - requires_delivery_option - ) - WITH RECURSIVE Recursive_CTE_Delivery_Region AS ( - SELECT - CAST(NULL AS INTEGER) AS id_region_parent, - DR.id_region AS id_region_child, - -- CASE WHEN FIND_IN_SET(DR.id_region, v_ids_delivery_region) > 0 THEN TRUE ELSE FALSE END AS requires_delivery_option - (DR.id_region = ANY(v_ids_delivery_region)) AS requires_delivery_option - FROM Shop_Product_Currency_Region_Link PCRL - INNER JOIN Shop_Currency C ON PCRL.id_currency = C.id_currency - INNER JOIN tmp_Shop_Product t_P - ON PCRL.id_product = t_P.id_product - AND PCRL.id_permutation = t_P.id_permutation - INNER JOIN Shop_Region DR ON PCRL.id_region_purchase = DR.id_region - WHERE - ( - v_get_all_delivery_region - -- OR FIND_IN_SET(DR.id_region, v_ids_delivery_region) > 0 - OR DR.id_region = ANY(v_ids_delivery_region) - ) - AND ( - v_get_inactive_delivery_region - OR DR.active = TRUE - ) - UNION - SELECT - DRB.id_region_parent, - DRB.id_region_child, - FALSE AS requires_delivery_option - FROM Shop_Region_Branch DRB - INNER JOIN Recursive_CTE_Delivery_Region r_DR - ON DRB.id_region_parent = r_DR.id_region_child - WHERE ( - v_get_inactive_delivery_region - OR DRB.active = TRUE - ) - ) - SELECT - DR.id_region, - DR.active, - DR.display_order, - requires_delivery_option - FROM Shop_Region DR - INNER JOIN Recursive_CTE_Delivery_Region r_DR - ON DR.id_region = r_DR.id_region_parent - OR DR.id_region = r_DR.id_region_child - ; - /* - select * from tmp_delivery_region; - SELECT * - FROM tmp_Shop_Product t_P - WHERE - /*( - v_get_all_category - OR v_get_all_product - OR v_get_all_product_permutation - ) */ - FIND_IN_SET(t_P.id_category, v_ids_category) > 0 - OR FIND_IN_SET(t_P.id_product, v_ids_product) > 0 - OR FIND_IN_SET(t_P.id_permutation, v_ids_permutation) > 0 - ; - */ - - IF v_has_filter_delivery_region THEN - v_ids_permutation_unavailable = ( - SELECT STRING_AGG(t_P.id_permutation, ', ') - FROM ( - SELECT * - FROM tmp_Shop_Product t_P - WHERE - /*( - v_get_all_category - OR v_get_all_produc - OR v_get_all_product_permutation - ) - FIND_IN_SET(t_P.id_category, v_ids_category) > 0 - OR FIND_IN_SET(t_P.id_product, v_ids_product) > 0 - OR FIND_IN_SET(t_P.id_permutation, v_ids_permutation) > 0 - */ - t_P.id_category = ANY(v_ids_category) - OR t_P.id_product = ANY(v_ids_product) - OR t_P.id_permutation = ANY(v_ids_permutation) - ) t_P - LEFT JOIN ( - SELECT * - FROM Shop_Product_Currency_Region_Link PCRL - WHERE - v_get_all_delivery_region - -- OR FIND_IN_SET(PCRL.id_region_purchase, v_ids_delivery_region) > 0 - OR PCRL.id_region_purchase = ANY(v_ids_delivery_region) - ) PCRL - ON t_P.id_product = PCRL.id_product - AND t_P.id_permutation = PCRL.id_permutation - LEFT JOIN tmp_Delivery_Region t_DR - ON PCRL.id_region_purchase = t_DR.id_region - AND t_DR.requires_delivery_option - WHERE - ISNULL(t_DR.id_region) - ); - IF NOT ISNULL(v_ids_permutation_unavailable) THEN - /* - INSERT INTO tmp_Msg_Error ( - guid, - id_type, - code, - msg - ) - VALUES ( - v_guid, - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'PRODUCT_AVAILABILITY' LIMIT 1), - 'PRODUCT_AVAILABILITY', - 'Error: The following permutation IDs are not available in this region: ' || COALESCE(v_ids_permutation_unavailable, 'NULL') - ); - */ - RAISE EXCEPTION 'The following permutation IDs are not available in this region: %', COALESCE(v_ids_permutation_unavailable, 'NULL') - USING ERRCODE = '22000'; - END IF; - /* - DELETE FROM tmp_Shop_Product t_P - WHERE t_P.id_permutation NOT IN ( - SELECT - id_permutation - FROM Shop_Product_Currency_Region_Link PCL - INNER JOIN tmp_Delivery_Region t_DR - ON PCRL.id_region_purchase = t_DR.id_region - ); - */ - END IF; - - -- select * from tmp_Shop_Product; - - -- Currencies - INSERT INTO tmp_Currency ( - id_currency, - active, - display_order - ) - SELECT - C.id_currency, - C.active, - C.display_order - FROM Shop_Product_Currency_Region_Link PCRL - INNER JOIN Shop_Currency C ON PCRL.id_currency = C.id_currency - INNER JOIN tmp_Shop_Product t_P - ON PCRL.id_product = t_P.id_product - AND PCRL.id_permutation = t_P.id_permutation - INNER JOIN tmp_Delivery_Region t_DR ON PCRL.id_region_purchase = t_DR.id_region - WHERE - ( - v_get_all_currency - -- R FIND_IN_SET(C.id_currency, v_ids_currency) > 0 - OR C.id_currency = ANY(v_ids_currency) - ) - AND ( - v_get_inactive_currency - OR ( - C.active - AND PCRL.active - ) - ) - ; - - -- select * from tmp_Currency; - - IF v_has_filter_currency THEN - v_ids_permutation_unavailable = ( - SELECT STRING_AGG(t_P.id_permutation, ', ') - FROM ( - SELECT * - FROM tmp_Shop_Product t_P - WHERE - /*( - v_get_all_category - OR v_get_all_product - OR v_get_all_product_permutation - ) - FIND_IN_SET(t_P.id_category, v_ids_category) > 0 - OR FIND_IN_SET(t_P.id_product, v_ids_product) > 0 - OR FIND_IN_SET(t_P.id_permutation, v_ids_permutation) > 0 - */ - t_P.id_category = ANY(v_ids_category) - OR t_P.id_product = ANY(v_ids_product) - OR t_P.id_permutation = ANY(v_ids_permutation) - ) t_P - INNER JOIN ( - SELECT * - FROM Shop_Product_Currency_Region_Link PCRL - WHERE - ( - v_get_all_currency - -- OR FIND_IN_SET(PCRL.id_currency, v_ids_currency) > 0 - OR PCRL.id_currency = ANY(v_ids_currency) - ) - ) PCRL - ON t_P.id_permutation = PCRL.id_permutation - LEFT JOIN tmp_Currency t_C - ON PCRL.id_currency = t_C.id_currency - WHERE ISNULL(t_C.id_currency) - ); - IF NOT ISNULL(v_ids_permutation_unavailable) THEN - /* - INSERT INTO tmp_Msg_Error ( - guid, - id_type, - code, - msg - ) - VALUES ( - v_guid, - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'PRODUCT_AVAILABILITY' LIMIT 1), - 'PRODUCT_AVAILABILITY', - 'Error: The following permutation IDs are not available in this currency: ' || COALESCE(v_ids_permutation_unavailable, 'NULL') - ); - */ - RAISE EXCEPTION 'The following permutation IDs are not available in this currency: %', COALESCE(v_ids_permutation_unavailable, 'NULL') - USING ERRCODE = '22000'; - END IF; - /* - DELETE FROM tmp_Shop_Product t_P - WHERE t_P.id_permutation NOT IN ( - SELECT - id_permutation - FROM Shop_Product_Currency_Region_Link PCL - INNER JOIN tmp_Currency t_C - ON PCRL.id_currency = t_C.id_currency - ); - */ - END IF; - - -- Discounts - INSERT INTO tmp_Discount ( - id_discount, - active, - display_order - ) - SELECT - D.id_discount, - D.active, - D.display_order - FROM Shop_Discount D - INNER JOIN tmp_Shop_Product t_P - ON D.id_product = t_P.id_product - AND D.id_permutation = t_P.id_permutation - WHERE - ( - v_get_all_discount - -- OR FIND_IN_SET(D.id_discount, v_ids_discount) > 0 - OR D.id_discount = ANY(v_ids_discount) - ) - AND ( - v_get_inactive_discount - OR D.active - ) - ; - -- select 'pre-permission results'; - -- select * from tmp_Shop_Product; - - -- Permissions - IF EXISTS (SELECT * FROM tmp_Shop_Product_Category LIMIT 1) THEN - -- v_id_user := (SELECT id_user FROM Shop_User WHERE name = CURRENT_USER); - v_id_permission_product := (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_PRODUCT' LIMIT 1); - v_ids_product_permission := (SELECT STRING_AGG(id_product, ',') FROM tmp_Shop_Product WHERE NOT ISNULL(id_product)); - -- v_ids_permutation_permission := (SELECT STRING_AGG(id_permutation, ',') FROM tmp_Shop_Product WHERE NOT ISNULL(id_permutation)); - - -- SELECT v_guid, v_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_product_permission; - -- select * from Shop_Calc_User_Temp; - - CALL p_shop_calc_user(v_guid, v_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_product_permission); - - -- select * from Shop_Calc_User_Temp; - - UPDATE tmp_Shop_Product t_P - SET t_P.can_view = UE_T.can_view, - t_P.can_edit = UE_T.can_edit, - t_P.can_admin = UE_T.can_admin - FROM tmp_Shop_Product t_P - INNER JOIN Shop_Calc_User_Temp UE_T - ON t_P.id_product = UE_T.id_product - AND UE_T.GUID = v_guid - ; - -- select * from Shop_Calc_User_Temp; - -- select * from tmp_Shop_Product; - - DELETE FROM tmp_Shop_Product t_P - WHERE - -- FIND_IN_SET(t_P.id_product, (SELECT STRING_AGG(UET.id_product, ',') FROM Shop_Calc_User_Temp UET)) = FALSE -- id_product NOT LIKE CONCAT('%', (SELECT STRING_AGG(id_product, '|') FROM Shop_Calc_User_Temp), '%'); - t_P.id_product NOT IN ( - SELECT id_product - FROM Shop_Calc_User_Temp UET - WHERE UET.GUID = v_guid - ) - OR ISNULL(t_P.can_view) - OR t_P.can_view = FALSE - ; - - -- CALL p_shop_clear_calc_user(v_guid); - -- DROP TABLE IF EXISTS Shop_Calc_User_Temp; - DELETE FROM Shop_Calc_User_Temp - WHERE GUID = v_guid - ; - END IF; - - - -- select * from tmp_Shop_Product; - - -- Returns - -- v_now := CURRENT_TIMESTAMP; - - -- Categories - OPEN result_categories FOR - -- RETURN QUERY - SELECT - DISTINCT t_C.id_category, - C.name, - C.description, - C.display_order - FROM tmp_Shop_Product_Category t_C - INNER JOIN Shop_Product_Category C - ON t_C.id_category = C.id_category - INNER JOIN tmp_Shop_Product t_P - ON t_C.id_category = t_P.id_category - ORDER BY C.display_order - ; - RETURN NEXT result_categories; - -- CLOSE result_categories; - - -- Products - OPEN result_products FOR - -- RETURN QUERY - SELECT - t_P.id_product, - t_P.id_permutation, - t_P.name, - t_P.description, - P.has_variations, - P.id_category, - PP.cost_local, - PP.id_currency_cost, - PP.profit_local_min, - t_P.latency_manufacture, - t_P.quantity_min, - t_P.quantity_max, - t_P.quantity_step, - t_P.quantity_stock, - t_P.id_stripe_product, - t_P.is_subscription, - RI.name AS name_interval_recurrence, - RI.name_plural AS name_plural_interval_recurrence, - t_P.count_interval_recurrence, - t_P.display_order_category, - t_P.display_order_product, - t_P.display_order_permutation, - COALESCE(t_P.can_view, FALSE), - COALESCE(t_P.can_edit, FALSE), - COALESCE(t_P.can_admin, FALSE) - FROM tmp_Shop_Product t_P - INNER JOIN Shop_Product P ON t_P.id_product = P.id_product - INNER JOIN Shop_Product_Permutation PP ON t_P.id_permutation = PP.id_permutation - LEFT JOIN Shop_Interval_Recurrence RI ON t_P.id_unit_measurement_interval_recurrence = RI.id_interval - ORDER BY t_P.rank_permutation - ; - RETURN NEXT result_products; - -- CLOSE result_products; - - -- Variations - OPEN result_variations FOR - -- RETURN QUERY - SELECT - V.id_variation, - t_P.id_product, - t_P.id_permutation, - t_P.id_category, - VT.code AS code_variation_type, - VT.name AS name_variation_type, - V.code AS code_variation, - V.name AS name_variation, - RANK() OVER (ORDER BY t_P.rank_permutation, PPVL.display_order) AS display_order - FROM Shop_Variation V - INNER JOIN Shop_Variation_Type VT - ON V.id_type = VT.id_type - INNER JOIN Shop_Product_Permutation_Variation_Link PPVL ON V.id_variation = PPVL.id_variation - INNER JOIN tmp_Shop_Product t_P ON PPVL.id_permutation = t_P.id_permutation - WHERE V.active - AND PPVL.active - ; - RETURN NEXT result_variations; - -- CLOSE result_variations; - - /* - -- Permutation variations output - SELECT t_P.id_permutation, - t_P.id_product, - t_P.id_category, - id_variation - FROM Shop_Product_Permutation_Variation_Link PPVL - INNER JOIN tmp_Shop_Product t_P - ON t_P.id_permutation = PPVL.id_permutation - ORDER BY t_P.display_order - ; - */ - -- select * from Shop_Product_Currency_Region_Link; - -- select * from shop_currency; - /* - select * from tmp_Currency; - select * from tmp_delivery_region; - select * from tmp_shop_product; - */ - - -- Product Price - OPEN result_prices FOR - -- RETURN QUERY - SELECT - PCRL.id_link AS id_price, - t_P.id_permutation, - t_P.id_product, - t_P.id_category, - t_C.id_currency, - C.code AS code_currency, - C.name AS name_currency, - C.symbol AS symbol_currency, - t_DR.id_region, - PCRL.price_local_VAT_incl, - PCRL.price_local_VAT_excl, - ROW_NUMBER() OVER(ORDER BY t_P.rank_permutation, C.display_order) AS display_order - FROM Shop_Product_Currency_Region_Link PCRL - INNER JOIN tmp_Shop_Product t_P - ON PCRL.id_product = t_P.id_product - AND PCRL.id_permutation = t_P.id_permutation - -- INNER JOIN Shop_Product P ON PCRL.id_product = P.id_product - INNER JOIN tmp_Currency t_C ON PCRL.id_currency = t_C.id_currency - INNER JOIN Shop_Currency C ON t_C.id_currency = C.id_currency - INNER JOIN tmp_Delivery_Region t_DR ON PCRL.id_region_purchase = t_DR.id_region - WHERE ( - v_get_inactive_product - AND v_get_inactive_permutation - AND v_get_inactive_currency - AND v_get_inactive_delivery_region - OR PCRL.active - ) - ORDER BY t_P.rank_permutation - ; - RETURN NEXT result_prices; - -- CLOSE result_prices; - - /* - -- Currency - SELECT - DISTINCT C.id_currency, - C.code, - C.name, - C.factor_from_GBP, - t_C.display_order - FROM Shop_Currency C - INNER JOIN tmp_Currency t_C ON C.id_currency = t_C.id_currency - GROUP BY C.id_currency, t_C.display_order - ORDER BY t_C.display_order - ; - */ - - -- Images - OPEN result_images FOR - -- RETURN QUERY - SELECT - t_I.id_image, - t_I.id_product, - t_I.id_permutation, - t_P.id_category, - I.url, - I.active, - I.display_order - FROM tmp_Shop_Image t_I - INNER JOIN Shop_Image I - ON t_I.id_image = I.id_image - INNER JOIN tmp_Shop_Product t_P - ON t_I.id_product = t_P.id_product - AND t_I.id_permutation = t_P.id_permutation - ORDER BY t_P.rank_permutation, I.display_order - ; - RETURN NEXT result_images; - -- CLOSE result_images; - - -- Delivery options - OPEN result_delivery_options FOR - -- RETURN QUERY - SELECT - _DO.id_option, - PDOL.id_product, - PDOL.id_permutation, - t_P.id_category, - _DO.code, - _DO.name, - _DO.latency_delivery_min, - _DO.latency_delivery_max, - _DO.quantity_min, - _DO.quantity_max, - STRING_AGG(DR.code, ',') AS codes_region, - STRING_AGG(DR.name, ',') AS names_region, - PDOL.price_local, - PDOL.display_order - FROM Shop_Delivery_Option _DO - INNER JOIN Shop_Product_Permutation_Delivery_Option_Link PDOL - ON _DO.id_option = PDOL.id_delivery_option - AND ( - v_get_inactive_delivery_region - OR PDOL.active - ) - INNER JOIN tmp_Shop_Product t_P - ON PDOL.id_product = t_P.id_product - AND PDOL.id_permutation = t_P.id_permutation - INNER JOIN tmp_Delivery_Region t_DR ON PDOL.id_region = t_DR.id_region - INNER JOIN Shop_Region DR ON t_DR.id_region = DR.id_region - WHERE ( - v_get_inactive_delivery_region - OR _DO.active - ) - GROUP BY t_P.id_category, t_P.id_product, PDOL.id_permutation, t_P.rank_permutation, DR.id_region, _DO.id_option, PDOL.id_link - ORDER BY t_P.rank_permutation, PDOL.display_order - ; - RETURN NEXT result_delivery_options; - -- CLOSE result_delivery_options; - - -- Discounts - OPEN result_discounts FOR - -- RETURN QUERY - SELECT - D.id_discount, - P.id_category, - D.id_product, - D.id_permutation, - DR.id_region, - C.id_currency, - D.code AS code_discount, - D.name AS name_discount, - D.multiplier, - D.subtractor, - D.apply_multiplier_first, - D.quantity_min, - D.quantity_max, - D.date_start, - D.date_end, - STRING_AGG(DR.code, ', ') OVER(PARTITION BY D.id_discount) AS codes_region, - STRING_AGG(DR.name, ', ') OVER(PARTITION BY D.id_discount) AS names_region, - STRING_AGG(C.code, ', ') OVER(PARTITION BY D.id_discount) AS codes_currency, - STRING_AGG(C.name, ', ') OVER(PARTITION BY D.id_discount) AS names_currency, - ROW_NUMBER() OVER(ORDER BY D.display_order) AS display_order - FROM tmp_Discount t_D - INNER JOIN Shop_Discount D ON t_D.id_discount = D.id_discount - INNER JOIN Shop_Product P ON D.id_product = P.id_product - INNER JOIN tmp_Shop_Product t_P - ON D.id_product = t_P.id_product - -- AND D.id_permutation = t_P.id_permutation - INNER JOIN Shop_Discount_Region_Currency_Link DRCL - ON D.id_discount = DRCL.id_discount - INNER JOIN tmp_Delivery_Region t_DR ON DRCL.id_region = t_DR.id_region - INNER JOIN Shop_Region DR ON t_DR.id_region = DR.id_region - INNER JOIN tmp_Currency t_C ON DRCL.id_currency = t_C.id_currency - INNER JOIN Shop_Currency C ON t_C.id_currency = C.id_currency - GROUP BY D.id_discount, DR.id_region, C.id_currency, P.id_category, P.id_product, D.id_permutation - ORDER BY D.display_order, DR.display_order, C.display_order - ; - RETURN NEXT result_discounts; - -- CLOSE result_discounts; - /* - -- Delivery Regions - SELECT - t_DR.id_region, - t_P.id_category, - t_P.id_product, - t_P.id_permutation, - DR.code, - DR.name - FROM tmp_Delivery_Region t_DR - INNER JOIN Shop_Delivery_Region DR ON t_DR.id_region = DR.id_region - INNER JOIN Shop_Product_Region_Currency_Link PDRL - ON DR.id_region = PDRL.id_region - AND ( - v_get_inactive_delivery_region - OR PDRL.active - ) - INNER JOIN tmp_Shop_Product t_P - ON PDRL.id_product = t_P.id_product - AND PDRL.id_permutation = t_P.id_permutation - INNER JOIN tmp_Currency t_C ON PDRL.id_currency = t_C.id_currency - ORDER BY t_DR.display_order - ; - */ - - -- Errors - /* - OPEN result_errors FOR - RETURN QUERY - SELECT - t_ME.display_order, - t_ME.guid, - t_ME.id_type, - t_ME.msg, - MET.code, - MET.name, - MET.description - FROM tmp_Msg_Error t_ME - INNER JOIN Shop_Msg_Error_Type MET - ON t_ME.id_type = MET.id_type - WHERE guid = v_guid - ; - RETURN NEXT result_errors; - */ - - /* - -- Return arguments for test - SELECT - v_ids_category, - v_get_inactive_category, - v_ids_product, - v_get_inactive_product, - v_get_first_product_only, - v_get_all_product, - v_ids_image, - v_get_inactive_image, - v_get_first_image_only, - v_get_all_image - ; - */ - - -- select 'other outputs'; - -- select * from tmp_Shop_Product; - - -- Clean up - /* - DROP TEMPORARY TABLE IF EXISTS tmp_Discount; - DROP TEMPORARY TABLE IF EXISTS tmp_Currency; - DROP TEMPORARY TABLE IF EXISTS tmp_Delivery_Region; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Image; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Variation; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Product; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Product_Category; - DROP TABLE IF EXISTS tmp_Discount; - DROP TABLE IF EXISTS tmp_Currency; - DROP TABLE IF EXISTS tmp_Delivery_Region; - DROP TABLE IF EXISTS tmp_Shop_Image; - DROP TABLE IF EXISTS tmp_Shop_Variation; - DROP TABLE IF EXISTS tmp_Shop_Product; - DROP TABLE IF EXISTS tmp_Shop_Product_Category; - */ -END; -$$ LANGUAGE plpgsql; - - -/* - -DROP FUNCTION IF EXISTS fetch_results; - -CREATE OR REPLACE FUNCTION fetch_results() -RETURNS VOID AS $$ -DECLARE - curs refcursor; - rec record; - curs1 refcursor; - rec1 record; - curs2 refcursor; - rec2 record; -BEGIN - FOR curs IN SELECT p_shop_get_many_product ( - 1, -- a_id_user - TRUE, -- a_get_all_category - FALSE, -- a_get_inactive_category - FALSE, -- a_get_first_category_only - ARRAY[]::INTEGER[], -- a_ids_category - TRUE, -- a_get_all_product - FALSE, -- a_get_inactive_product - FALSE, -- a_get_first_product_only - ARRAY[]::INTEGER[], -- a_ids_product - TRUE, -- a_get_all_product_permutation - FALSE, -- a_get_inactive_permutation - FALSE, -- a_get_first_permutation_only - ARRAY[1, 2, 3, 4, 5]::INTEGER[], -- a_ids_permutation - FALSE, -- a_get_all_image - FALSE, -- a_get_inactive_image - TRUE, -- a_get_first_image_only - ARRAY[]::INTEGER[], -- a_ids_image - FALSE, -- a_get_all_delivery_region - FALSE, -- a_get_inactive_delivery_region - ARRAY[]::INTEGER[], -- a_ids_delivery_region - FALSE, -- a_get_all_currency - FALSE, -- a_get_inactive_currency - ARRAY[]::INTEGER[], -- a_ids_currency - TRUE, -- a_get_all_discount - FALSE, -- a_get_inactive_discount - ARRAY[]::INTEGER[] -- a_ids_discount - ) LOOP - RAISE NOTICE 'Fetching from cursor: %', curs; - LOOP - FETCH curs INTO rec; - EXIT WHEN NOT FOUND; - RAISE NOTICE 'Record: %', rec; - END LOOP; - END LOOP; -END; -$$ LANGUAGE plpgsql; - -SELECT fetch_results(); - -*/ - - -CREATE OR REPLACE FUNCTION p_shop_get_many_currency ( - IN a_get_inactive_currency BOOLEAN -) -RETURNS SETOF REFCURSOR -AS $$ -DECLARE - v_get_inactive_currency BOOLEAN; - result_currency REFCURSOR; -BEGIN - v_get_inactive_currency := COALESCE(a_get_inactive_currency, FALSE); - - OPEN result_currency FOR - SELECT - C.id_currency, - C.code, - C.name, - C.factor_from_GBP, - C.active, - C.display_order - FROM Shop_Currency C - WHERE v_get_inactive_currency - OR C.active - ORDER BY C.display_order - ; - RETURN NEXT result_currency; -END; -$$ LANGUAGE plpgsql; - - -/* - -DROP FUNCTION IF EXISTS fetch_results; - -CREATE OR REPLACE FUNCTION fetch_results() -RETURNS VOID AS $$ -DECLARE - curs refcursor; - rec record; -BEGIN - FOR curs IN SELECT p_shop_get_many_currency ( - FALSE -- a_get_inactive_currency - ) LOOP - RAISE NOTICE 'Fetching from cursor: %', curs; - LOOP - FETCH curs INTO rec; - EXIT WHEN NOT FOUND; - RAISE NOTICE 'Record: %', rec; - END LOOP; - END LOOP; -END; -$$ LANGUAGE plpgsql; - -SELECT fetch_results(); - -*/ - - -CREATE OR REPLACE FUNCTION p_shop_get_many_region ( - IN a_get_inactive_region BOOLEAN -) -RETURNS SETOF REFCURSOR -AS $$ -DECLARE - v_get_inactive_region BOOLEAN; - result_region REFCURSOR; -BEGIN - v_get_inactive_region := COALESCE(a_get_inactive_region, FALSE); - - OPEN result_region FOR - SELECT - R.id_region, - R.code, - R.name, - R.active, - R.display_order - FROM Shop_Region R - WHERE v_get_inactive_region - OR R.active - ORDER BY R.display_order - ; - -- RETURN NEXT result_region; -END; -$$ LANGUAGE plpgsql; - - -/* - -DROP FUNCTION IF EXISTS fetch_results; - -CREATE OR REPLACE FUNCTION fetch_results() -RETURNS VOID AS $$ -DECLARE - curs refcursor; - rec record; - curs1 refcursor; - rec1 record; - curs2 refcursor; - rec2 record; -BEGIN - FOR curs IN SELECT p_shop_get_many_region ( - FALSE -- a_get_inactive_region - ) LOOP - RAISE NOTICE 'Fetching from cursor: %', curs; - LOOP - FETCH curs INTO rec; - EXIT WHEN NOT FOUND; - RAISE NOTICE 'Record: %', rec; - END LOOP; - END LOOP; -END; -$$ LANGUAGE plpgsql; - -SELECT fetch_results(); - -*/ - - -CREATE OR REPLACE FUNCTION p_shop_get_many_user_order ( - IN a_id_user INTEGER, - IN a_ids_order VARCHAR(4000), - IN a_n_order_max INTEGER, - IN a_id_checkout_session VARCHAR(200) -) -RETURNS SETOF REFCURSOR -AS $$ -DECLARE - v_id_user INTEGER; - v_ids_order VARCHAR(4000); - v_n_order_max INTEGER; - v_id_checkout_session VARCHAR(200); - v_has_filter_user BOOLEAN; - v_has_filter_order BOOLEAN; - v_has_filter_session BOOLEAN; - v_code_error_data VARCHAR(200); - v_code_error_permission VARCHAR(200); - v_guid UUID; - result_orders REFCURSOR; - -- result_errors REFCURSOR; -BEGIN - v_id_user := TRIM(COALESCE(a_id_user, '')); - v_ids_order := TRIM(COALESCE(a_ids_order, '')); - v_n_order_max := a_n_order_max; - v_id_checkout_session := TRIM(COALESCE(a_id_checkout_session, '')); - - v_code_error_data := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 1); - v_code_error_permission := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 2); - v_guid = gen_random_uuid(); - - v_has_filter_user = CASE WHEN v_id_user = '' THEN FALSE ELSE TRUE END; - v_ids_order = REPLACE(v_ids_order, '|', ','); - v_has_filter_order = CASE WHEN v_ids_order = '' THEN FALSE ELSE TRUE END; - v_has_filter_session = CASE WHEN v_id_checkout_session = '' THEN FALSE ELSE TRUE END; - - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Shop_User; - DROP TABLE IF EXISTS tmp_Shop_Order; - - /* - CREATE TABLE tmp_Shop_User( - id_user INTEGER PRIMARY KEY, - CONSTRAINT FK_tmp_Shop_User_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user), - active BOOLEAN NOT NULL - ); - */ - - CREATE TEMPORARY TABLE tmp_Shop_Order ( - id_order INTEGER NOT NULL PRIMARY KEY, - CONSTRAINT FK_tmp_Shop_Order_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_User_Order(id_order), - active BOOLEAN NOT NULL - ); - - /* - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - guid UUID NOT NULL, - -- id_type INTEGER NOT NULL, - -- CONSTRAINT FK_tmp_Msg_Error_id_type FOREIGN KEY (id_type) - -- REFERENCES Shop_Msg_Error_Type (id_type), - code VARCHAR(50), - msg VARCHAR(4000) NOT NULL - ); - */ - - -- User - IF v_has_filter_user THEN - INSERT INTO tmp_Shop_User ( - id_user, - active - ) - SELECT id_user, - active - FROM Shop_User - WHERE id_user = v_id_user - AND active - LIMIT 1 - ; - - v_has_filter_user = EXISTS (SELECT id_user FROM tmp_Shop_User LIMIT 1); - v_id_user := (SELECT id_user FROM tmp_Shop_User LIMIT 1); - ELSE - RAISE EXCEPTION 'Valid user ID must be provided.' - USING ERRCODE = '22000' - ; - END IF; - - -- Permissions - CALL p_shop_calc_user ( - v_guid, -- a_guid - a_id_user, -- a_id_user - 0, -- a_get_inactive_users - CONVERT((SELECT id_permission FROM Shop_Permission WHERE 'STORE_USER' = code), CHAR), -- a_ids_permission - (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW' AND active), -- a_ids_access_level - '', -- a_ids_product - '' -- a_ids_permutation - ); - - IF NOT (SELECT can_edit FROM Shop_Calc_User_Temp WHERE guid = v_guid) THEN - RAISE EXCEPTION 'User ID does not have permission to access orders.' - USING ERRCODE = '42501' - ; - END IF; - - DELETE FROM Shop_Calc_User_Temp - WHERE guid = v_guid - ; - - -- Invalid Order IDs - IF v_has_filter_order AND EXISTS ( - SELECT * - FROM Shop_User_Order - WHERE - NOT (id_user = v_id_user) - AND id_order = ANY(v_ids_order) - LIMIT 1 - ) THEN -- id_order LIKE CONCAT('%', v_ids_order, '%') LIMIT 1) THEN - RAISE EXCEPTION 'You do not have access to the following order IDs: %', ( - SELECT STRING_AGG(id_order, ', ') - FROM Shop_User_Order - WHERE - NOT (id_user = v_id_user) - AND id_order = ANY(v_ids_order) - ) - USING ERRCODE = '22000' - ; - END IF; - -- Invalid Checkout Session IDs - IF v_has_filter_session AND EXISTS ( - SELECT * - FROM Shop_User_Order - WHERE - NOT (id_user = v_id_user) - AND id_checkout_session = v_id_checkout_session - ) THEN - RAISE EXCEPTION 'You do not have access to the following checkout session IDs: %', ( - SELECT STRING_AGG(id_order, ', ') - FROM Shop_User_Order - WHERE - NOT (id_user = v_id_user) - AND id_checkout_session = v_id_checkout_session - ) - USING ERRCODE = '22000' - ; - END IF; - - -- Valid Orders - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - - INSERT INTO tmp_Shop_Order ( - id_order, - active - ) - SELECT UO.id_order, - UO.active - FROM Shop_User_Order UO - INNER JOIN tmp_Shop_User t_U - ON UO.id_user = t_U.id_user - AND t_U.active - WHERE ((NOT v_has_filter_order OR FIND_IN_SET(UO.id_order, v_ids_order) > 0) -- UO.id_order LIKE CONCAT('%', v_ids_order, '%')) - OR (NOT v_has_filter_session OR UO.id_checkout_session = v_id_checkout_session)) - AND UO.active - ; - END IF; - - - - -- Returns - /* - SELECT * - FROM tmp_Shop_User - ; - */ - - OPEN result_orders FOR - SELECT t_O.id_order, - UOPL.id_product, - UOPL.id_permutation, - UOPL.quantity - FROM tmp_Shop_Order t_O - INNER JOIN Shop_User_Order UO - ON t_O.id_order = UO.id_order - INNER JOIN Shop_User_Order_Product_Link UOPL - ON UO.id_order = UOPL.id_order - WHERE t_O.active - ; - RETURN NEXT result_orders; - - /* - -- Errors - OPEN result_errors FOR - SELECT * - FROM tmp_Msg_Error - ; - -- RETURN NEXT result_errors; - */ - - - /* - -- Return arguments for test - SELECT - v_id_user, - v_ids_order, - v_n_order_max, - v_id_checkout_session - ; - */ - - -- Clean up - -- DROP TABLE IF EXISTS tmp_Shop_User; - -- DROP TABLE IF EXISTS tmp_Shop_Order; -END; -$$ LANGUAGE plpgsql; - - -/* - -DROP FUNCTION IF EXISTS fetch_results; - -CREATE OR REPLACE FUNCTION fetch_results() -RETURNS VOID AS $$ -DECLARE - curs refcursor; - rec record; - curs1 refcursor; - rec1 record; - curs2 refcursor; - rec2 record; -BEGIN - FOR curs IN SELECT p_shop_get_many_user_order ( - 'auth0|6582b95c895d09a70ba10fef', # a_id_user - '1', # a_ids_order - 0, # a_n_order_max - '' # a_id_checkout_session - ) LOOP - RAISE NOTICE 'Fetching from cursor: %', curs; - LOOP - FETCH curs INTO rec; - EXIT WHEN NOT FOUND; - RAISE NOTICE 'Record: %', rec; - END LOOP; - END LOOP; -END; -$$ LANGUAGE plpgsql; - -SELECT fetch_results(); - -*/ - - -/* - -CALL p_shop_get_many_user_order ( - 'auth0|6582b95c895d09a70ba10fef', # a_id_user - '1', # a_ids_order - 0, # a_n_order_max - '' # a_id_checkout_session -); - -CALL p_shop_get_many_user_order ( - '', # a_id_user - '1', # a_ids_order - 0, # a_n_order_max - '' # a_id_checkout_session -); - -insert into shop_product_change_set (comment) - values ('set product not subscription - test bool output to python'); - update shop_product - set is_subscription = 0, - id_change_set = (select id_change_set from shop_product_change_set order by id_change_set desc limit 1) - where id_product = 1 -select * from shop_User; -select * from shop_User_oRDER; -*/ - - -/* - -CALL p_shop_get_many_stripe_product_new ( - '' -) - -*/ - -CREATE OR REPLACE FUNCTION p_shop_get_many_stripe_product_new ( - IN a_id_user INTEGER -) -RETURNS SETOF REFCURSOR -AS $$ -DECLARE - v_id_user INTEGER; - v_code_error_data VARCHAR(200); - v_code_error_permission VARCHAR(200); - v_guid UUID; - result_products REFCURSOR; - result_product_variation_links REFCURSOR; - -- result_errors REFCURSOR; -BEGIN - v_id_user := a_id_user; - v_code_error_data := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 1); - v_code_error_permission := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 2); - v_guid = gen_random_uuid(); - - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Shop_Product; - DROP TABLE IF EXISTS tmp_Shop_User; - - CREATE TEMPORARY TABLE tmp_Shop_User( - id_user INTEGER PRIMARY KEY, - CONSTRAINT FK_tmp_Shop_User_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user), - active BOOLEAN NOT NULL - ); - - CREATE TEMPORARY TABLE tmp_Shop_Product ( - id_product INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - id_permutation INTEGER NULL, - CONSTRAINT FK_tmp_Shop_Product_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - active BOOLEAN NOT NULL, - display_order_product INTEGER NOT NULL, - display_order_permutation INTEGER NOT NULL, - name VARCHAR(200) NOT NULL, - description VARCHAR(4000) NOT NULL - ); - - /* - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( -- IF NOT EXISTS - display_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - guid UUID NOT NULL, - code VARCHAR(50) NOT NULL, - -- CONSTRAINT chk_tmp_Msg_Error_code CHECK (code IN (SELECT code FROM Shop_Msg_Error_Type)), - /* - id_type INTEGER NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type(id_type), - */ - msg VARCHAR(4000) NOT NULL - ); - */ - - - -- User - IF NOT EXISTS( - SELECT * - FROM Shop_User - WHERE - id_user = v_id_user - AND active - ) THEN - RAISE EXCEPTION 'Valid user ID required.' - USING ERRCODE = '22000' - ; - END IF; - - INSERT INTO tmp_Shop_User ( - id_user, - active - ) - SELECT id_user, - active - FROM Shop_User - WHERE id_user = v_id_user - AND active - LIMIT 1 - ; - - -- Get products - INSERT INTO tmp_Shop_Product ( - id_product, - id_permutation, - active, - display_order_product, - display_order_permutation, - name, - description - ) - SELECT id_product, - id_permutation, - active, - display_order_product, - display_order_permutation, - name, - description - FROM ( - SELECT id_product, - NULL AS id_permutation, - active, - display_order AS display_order_product, - NULL AS display_order_permutation, - name, - description, - id_stripe_product - FROM Shop_Product P - UNION - SELECT t_PPPV.id_product, - id_permutation, - t_PPPV.active, - display_order_product, - display_order_permutation, - P.name, ': ' || names_variation AS name, - P.description || ' With variations: ' || type_name_pairs_variation AS description, - t_PPPV.id_stripe_product - FROM ( - SELECT P.id_product, - PP.id_permutation, - PP.active, - P.display_order AS display_order_product, - PP.display_order AS display_order_permutation, - STRING_AGG(V.name, ' ') AS names_variation, - STRING_AGG(VT.name || ': ' || V.name, ', ') AS type_name_pairs_variation, - PP.id_stripe_product - FROM Shop_Product_Permutation PP - INNER JOIN Shop_Product P - ON PP.id_product = P.id_product - AND P.active - INNER JOIN Shop_Product_Permutation_Variation_Link PPVL - ON PP.id_permutation = PPVL.id_permutation - AND PPVL.active - INNER JOIN Shop_Variation V - ON PPVL.id_variation = V.id_variation - AND V.active - INNER JOIN Shop_Variation_Type VT - ON V.id_type = VT.id_type - AND VT.active - GROUP BY id_product, id_permutation -- , VT.id_type, V.id_variation - ) t_PPPV - INNER JOIN Shop_Product P - ON t_PPPV.id_product = P.id_product - ) t_PPP - WHERE ISNULL(id_stripe_product) - AND active - ; - - -- Permissions - CALL p_shop_calc_user ( - v_guid, -- a_guid - v_id_user, -- a_id_user - 0, -- a_get_inactive_users - CONVERT((SELECT id_permission FROM Shop_Permission WHERE 'STORE_ADMIN' = code), CHAR), -- a_ids_permission - (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'ADMIN' AND active), -- a_ids_access_level - (SELECT STRING_AGG(id_product, ',') From tmp_Shop_Product), -- a_ids_product - (SELECT STRING_AGG(id_permutation, ',') From tmp_Shop_Product) -- a_ids_permutation -- WHERE NOT ISNULL(id_permutation) - ); - - IF EXISTS (SELECT can_admin FROM Shop_Calc_User_Temp WHERE guid = v_guid AND NOT can_admin) THEN - RAISE EXCEPTION 'User ID does not have permission to get all new stripe products.' - USING ERRCODE = '42501' - ; - END IF; - - DELETE FROM Shop_Calc_User_Temp - WHERE guid = v_guid - ; - - - - - -- Returns - /* - SELECT * - FROM tmp_Shop_User - ; - */ - - /* - IF EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - DELETE FROM tmp_Shop_Product; - END IF; - */ - - OPEN result_products FOR - SELECT id_product, - id_permutation, - name, - description - FROM tmp_Shop_Product - ORDER BY display_order_product, display_order_permutation - ; - RETURN NEXT result_products; - - OPEN result_product_variation_links FOR - SELECT PP.id_permutation, - V.id_variation, - V.name AS name_variation, - VT.id_type AS id_type_variation, - VT.name as name_variation_type - FROM tmp_Shop_Product t_P - INNER JOIN Shop_Product_Permutation PP - ON t_P.id_permutation = PP.id_permutation - INNER JOIN Shop_Product_Permutation_Variation_Link PPVL - ON PP.id_permutation = PPVL.id_permutation - AND PPVL.active - INNER JOIN Shop_Variation V - ON PPVL.id_variation = V.id_variation - AND V.active - INNER JOIN Shop_Variation_Type VT - ON V.id_type = VT.id_type - AND VT.active - ; - RETURN NEXT result_product_variation_links; - - -- Errors - /* - OPEN result_errors FOR - SELECT * - FROM tmp_Msg_Error - ; - -- RETURN NEXT result_errors; - */ - - - /* - -- Return arguments for test - SELECT - v_id_user - ; - */ - - -- Clean up - DROP TABLE IF EXISTS tmp_Shop_Product; - DROP TABLE IF EXISTS tmp_Shop_User; -END; -$$ LANGUAGE plpgsql; - - -/* - -DROP FUNCTION IF EXISTS fetch_results; - -CREATE OR REPLACE FUNCTION fetch_results() -RETURNS VOID AS $$ -DECLARE - curs refcursor; - rec record; - curs1 refcursor; - rec1 record; - curs2 refcursor; - rec2 record; -BEGIN - FOR curs IN SELECT p_shop_get_many_stripe_product_new ( - 'auth0|6582b95c895d09a70ba10fef' - ) LOOP - RAISE NOTICE 'Fetching from cursor: %', curs; - LOOP - FETCH curs INTO rec; - EXIT WHEN NOT FOUND; - RAISE NOTICE 'Record: %', rec; - END LOOP; - END LOOP; -END; -$$ LANGUAGE plpgsql; - -SELECT fetch_results(); - -*/ - - -/* -CALL p_shop_get_many_stripe_product_new ( - '' -); - -CALL p_shop_get_many_stripe_product_new ( - 'auth0|6582b95c895d09a70ba10fef' -); - - - -select * from shop_product; -select * from shop_product_permutation_variation_link; - -CALL p_shop_calc_user ( - 'ead789a1-c7ac-11ee-a256-b42e9986184a', -- a_guid - 'auth0|6582b95c895d09a70ba10fef', -- a_id_user - 0, -- a_get_inactive_users - '4', -- a_ids_permission - '3', -- a_ids_access_level - '1', -- a_ids_product - '1' -- a_ids_permutation -- WHERE NOT ISNULL(id_permutation) - ); - -*/ - - - -/* - -CALL p_shop_get_many_stripe_price_new ( - '' -) - -*/ - - - -CREATE OR REPLACE FUNCTION p_shop_get_many_stripe_price_new ( - IN a_id_user INTEGER -) -RETURNS SETOF REFCURSOR -AS $$ -DECLARE - v_id_user INTEGER; - v_has_filter_user BOOLEAN; - v_code_error_data VARCHAR(200); - v_code_error_permission VARCHAR(200); - v_guid UUID; - result_products REFCURSOR; - -- result_errors REFCURSOR; -BEGIN - v_id_user := TRIM(COALESCE(a_id_user, '')); - v_code_error_data := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 1); - v_code_error_permission := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 2); - v_guid = gen_random_uuid(); - - v_has_filter_user = CASE WHEN v_id_user = '' THEN FALSE ELSE TRUE END; - - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Shop_Product_Currency_Link; - DROP TABLE IF EXISTS tmp_Shop_User; - - CREATE TEMPORARY TABLE tmp_Shop_User( - id_user INTEGER PRIMARY KEY, - CONSTRAINT FK_tmp_Shop_User_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user), - active BOOLEAN NOT NULL - ); - - CREATE TEMPORARY TABLE tmp_Shop_Product_Currency_Link ( - id_link INTEGER NOT NULL PRIMARY KEY, - CONSTRAINT FK_tmp_Shop_Product_Currency_Link_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Product_Currency_Region_Link(id_link), - id_product INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_CurrencyLink_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - id_permutation INTEGER NULL, - CONSTRAINT FK_tmp_Shop_Product_Currency_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - id_currency INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_Currency_Link_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency), - active BOOLEAN NOT NULL - ); - - /* - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( -- IF NOT EXISTS - display_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - guid UUID NOT NULL, - code VARCHAR(50) NOT NULL, - -- CONSTRAINT chk_tmp_Msg_Error_code CHECK (code IN (SELECT code FROM Shop_Msg_Error_Type)), - /* - id_type INTEGER NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type(id_type), - */ - msg VARCHAR(4000) NOT NULL - ); - */ - - - -- User permissions - IF NOT EXISTS( - SELECT * - FROM Shop_User - WHERE - id_user = v_id_user - AND active - ) THEN - RAISE EXCEPTION 'Valid user ID required.' - USING ERRCODE = '22000' - ; - END IF; - - INSERT INTO tmp_Shop_User ( - id_user, - active - ) - SELECT id_user, - active - FROM Shop_User - WHERE id_user = v_id_user - AND active - LIMIT 1 - ; - - -- Get products - INSERT INTO tmp_Shop_Product_Currency_Link ( - id_link, - id_product, - id_permutation, - id_currency, - active - ) - SELECT id_link, - id_product, - id_permutation, - id_currency, - active - FROM Shop_Product_Currency_Region_Link - WHERE ISNULL(id_stripe_price) - AND active - ; - - -- Permissions - -- SELECT * FROM tmp_Msg_Error LIMIT 1; - CALL p_shop_calc_user ( - v_guid, -- a_guid - v_id_user, -- a_id_user - 0, -- a_get_inactive_users - CONVERT((SELECT id_permission FROM Shop_Permission WHERE 'STORE_ADMIN' = code), CHAR), -- a_ids_permission - (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'ADMIN' AND active), -- a_ids_access_level - (SELECT STRING_AGG(DISTINCT id_product, ',') FROM tmp_Shop_Product_Currency_Link), -- (SELECT DISTINCT id_product FROM tmp_Shop_Product_Currency_Link) calc_PCL) -- a_ids_product - (SELECT STRING_AGG(DISTINCT id_permutation, ',') FROM tmp_Shop_Product_Currency_Link) -- a_ids_permutation - ); - -- SELECT * FROM tmp_Msg_Error LIMIT 1; - - IF EXISTS (SELECT can_admin FROM Shop_Calc_User_Temp WHERE guid = v_guid AND NOT can_admin LIMIT 1) THEN - RAISE EXCEPTION 'User ID does not have permission to get all new stripe prices.' - USING ERRCODE = '42501' - ; - END IF; - - DELETE FROM Shop_Calc_User_Temp - WHERE guid = v_guid - ; - - - - -- Returns - /* - IF EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - DELETE FROM tmp_Shop_Product_Currency_Link; - END IF; - */ - /* - SELECT * - FROM tmp_Shop_User - ; - */ - - OPEN result_products FOR - SELECT t_PCL.id_product, - t_PCL.id_permutation, - P.price_GBP_full * C.factor_from_GBP AS unit_price, - C.code AS code_currency, - P.id_stripe_product, - P.is_subscription, - LOWER(RI.code) AS name_recurring_interval, - P.count_interval_recurrence - FROM tmp_Shop_Product_Currency_Link t_PCL - INNER JOIN Shop_Product P - ON t_PCL.id_product = P.id_product - AND P.active - INNER JOIN Shop_Interval_Recurrence RI - ON P.id_unit_measurement_interval_recurrence = RI.id_interval - AND RI.active - INNER JOIN Shop_Currency C - ON t_PCL.id_currency = C.id_currency - AND C.active - WHERE t_PCL.active - ; - RETURN NEXT result_products; - - -- Errors - /* - OPEN result_errors FOR - SELECT * - FROM tmp_Msg_Error - ; - -- RETURN NEXT result_errors; - */ - - - /* - -- Return arguments for test - SELECT - v_id_user - ; - */ - - -- Clean up - DROP TABLE IF EXISTS tmp_Shop_User; - DROP TABLE IF EXISTS tmp_Shop_Product_Currency_Link; -END; -$$ LANGUAGE plpgsql; - - -/* - -DROP FUNCTION IF EXISTS fetch_results; - -CREATE OR REPLACE FUNCTION fetch_results() -RETURNS VOID AS $$ -DECLARE - curs refcursor; - rec record; - curs1 refcursor; - rec1 record; - curs2 refcursor; - rec2 record; -BEGIN - FOR curs IN SELECT p_shop_get_many_stripe_price_new ( - 'auth0|6582b95c895d09a70ba10fef' - ) LOOP - RAISE NOTICE 'Fetching from cursor: %', curs; - LOOP - FETCH curs INTO rec; - EXIT WHEN NOT FOUND; - RAISE NOTICE 'Record: %', rec; - END LOOP; - END LOOP; -END; -$$ LANGUAGE plpgsql; - -SELECT fetch_results(); - -*/ - - -/* -CALL p_shop_get_many_stripe_price_new ( - '' -); - -CALL p_shop_get_many_stripe_price_new ( - 'auth0|6582b95c895d09a70ba10fef' -); - -*/ - - -CREATE OR REPLACE FUNCTION p_shop_get_many_supplier ( - IN a_id_user INTEGER, - IN a_get_all_supplier BOOLEAN, - IN a_get_inactive_supplier BOOLEAN, - IN a_get_first_supplier_only BOOLEAN, - IN a_ids_supplier INTEGER[] -) -RETURNS SETOF REFCURSOR -AS $$ -DECLARE - v_id_user INTEGER; - v_get_all_supplier BOOLEAN; - v_get_inactive_supplier BOOLEAN; - v_get_first_supplier_only BOOLEAN; - v_ids_supplier INTEGER[]; - v_has_filter_supplier BOOLEAN; - v_guid UUID; - v_id_permission_supplier INTEGER; - v_id_access_level_view INTEGER; - v_id_minimum INTEGER; - result_suppliers REFCURSOR; - -- result_errors REFCURSOR; -BEGIN - v_id_user := TRIM(COALESCE(a_id_user, '')); - v_get_all_supplier := COALESCE(a_get_all_supplier, TRUE); - v_get_inactive_supplier := COALESCE(a_get_inactive_supplier, FALSE); - v_get_first_supplier_only := COALESCE(a_get_first_supplier_only, FALSE); - v_ids_supplier := TRIM(COALESCE(a_ids_supplier, '')); - - v_guid := gen_random_uuid(); - v_id_access_level_view := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW'); - v_has_filter_supplier = NOT (a_ids_supplier = ''); - - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Shop_Supplier; - - CREATE TABLE tmp_Shop_Supplier ( - id_supplier INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Supplier_id_supplier - FOREIGN KEY (id_supplier) - REFERENCES Shop_Supplier(id_supplier), - active BOOLEAN NOT NULL, - rank_supplier INTEGER NULL, - can_view BOOLEAN, - can_edit BOOLEAN, - can_admin BIT - ); - - /* - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - guid UUID NOT NULL, - id_type INTEGER NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type (id_type), - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - */ - - -- select v_has_filter_product, v_has_filter_permutation; - - IF v_has_filter_supplier THEN - IF EXISTS ( - SELECT * - FROM UNNEST(v_ids_supplier) AS Supplier_Id - LEFT JOIN Shop_Supplier S ON Supplier_Id = S.id_supplier - WHERE ISNULL(S.id_supplier) - ) THEN - RAISE EXCEPTION 'Invalid supplier IDs: %', ( - SELECT STRING_AGG(Supplier_Id, ', ') - FROM UNNEST(v_ids_supplier) AS Supplier_Id - LEFT JOIN Shop_Supplier S ON Supplier_Id = S.id_supplier - WHERE ISNULL(S.id_supplier) - LIMIT 1 - ) - USING ERRCODE = '22000' - ; - ELSE - INSERT INTO tmp_Shop_Supplier ( - id_supplier, - active, - rank_supplier - ) - SELECT - S.id_supplier, - S.active, - RANK() OVER (ORDER BY id_supplier ASC) AS rank_supplier - FROM Shop_Supplier S - WHERE - ( - a_get_inactive_supplier - OR S.active = TRUE - ) - AND ( - a_get_all_supplier - OR S.id_supplier = ANY(v_ids_supplier) - ) - ; - END IF; - - IF a_get_first_supplier_only THEN - DELETE FROM tmp_Shop_Supplier t_S - WHERE t_S.rank_supplier > ( - SELECT MIN(t_S.rank_supplier) - FROM tmp_Shop_Supplier t_S - ) - ; - END IF; - END IF; - - -- Permissions - -- v_id_user := (SELECT id_user FROM Shop_User WHERE name = CURRENT_USER); - v_id_permission_supplier := (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_SUPPLIER' LIMIT 1); - - -- SELECT v_guid, a_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_permutation_permission; - -- select * from Shop_Calc_User_Temp; - - CALL p_shop_calc_user(v_guid, a_id_user, FALSE, v_id_permission_supplier, v_id_access_level_view, ''); - - -- select * from Shop_Calc_User_Temp; - - IF NOT EXISTS (SELECT can_view FROM Shop_Calc_User_Temp UE_T WHERE UE_T.GUID = v_guid) THEN - RAISE EXCEPTION 'You do not have view permissions for %', ( - SELECT name - FROM Shop_Permission - WHERE id_permission = v_id_permission_supplier - LIMIT 1 - ) - USING ERRCODE = '42501' - ; - END IF; - - - -- select * from tmp_Shop_Product; - - -- Returns - - -- Suppliers - OPEN result_suppliers FOR - SELECT - t_S.id_supplier, - S.name_company, - name_contact, - department_contact, - id_address, - phone_number, - fax, - email, - website, - id_currency, - active - FROM tmp_Shop_Supplier t_S - INNER JOIN Shop_Supplier S - ON t_S.id_supplier = S.id_supplier - ; - RETURN NEXT result_suppliers; - - -- Errors - /* - SELECT - /* - t_ME.display_order, - t_ME.guid, - t_ME.id_type, - t_ME.msg, - MET.code, - MET.name, - MET.description - */ - * - FROM tmp_Msg_Error t_ME - INNER JOIN Shop_Msg_Error_Type MET - ON t_ME.id_type = MET.id_type - WHERE guid = v_guid - ; - OPEN result_errors FOR - SELECT * - FROM tmp_Msg_Error - ; - -- RETURN NEXT result_errors; - */ - - /* - -- Return arguments for test - SELECT - a_ids_category, - a_get_inactive_category, - a_ids_product, - a_get_inactive_product, - a_get_first_product_only, - a_get_all_product, - a_ids_image, - a_get_inactive_image, - a_get_first_image_only, - a_get_all_image - ; - */ - - -- select 'other outputs'; - -- select * from tmp_Shop_Product; - - -- Clean up - DROP TABLE IF EXISTS tmp_Supplier; - - DELETE FROM Shop_Calc_User_Temp - WHERE GUID = v_guid - ; -END; -$$ LANGUAGE plpgsql; - - -/* - -DROP FUNCTION IF EXISTS fetch_results; - -CREATE OR REPLACE FUNCTION fetch_results() -RETURNS VOID AS $$ -DECLARE - curs refcursor; - rec record; -BEGIN - FOR curs IN SELECT p_shop_get_many_supplier ( - '', -- a_id_user - TRUE, -- a_get_all_supplier - FALSE, -- a_get_inactive_supplier - FALSE, -- a_get_first_supplier_only - '' -- a_ids_supplier - ) LOOP - RAISE NOTICE 'Fetching from cursor: %', curs; - LOOP - FETCH curs INTO rec; - EXIT WHEN NOT FOUND; - RAISE NOTICE 'Record: %', rec; - END LOOP; - END LOOP; -END; -$$ LANGUAGE plpgsql; - -SELECT fetch_results(); - -*/ - - - -CREATE OR REPLACE FUNCTION p_shop_get_many_supplier_purchase_order ( - IN a_id_user INTEGER, - IN a_get_all_supplier BOOLEAN, - IN a_get_inactive_supplier BOOLEAN, - IN a_get_first_supplier_only BOOLEAN, - IN a_ids_supplier INTEGER[], - IN a_get_all_order BOOLEAN, - IN a_get_inactive_order BOOLEAN, - IN a_get_first_order_only BOOLEAN, - IN a_ids_order INTEGER[], - IN a_get_inactive_category BOOLEAN, - IN a_ids_category INTEGER[], - IN a_get_inactive_product BOOLEAN, - IN a_ids_product INTEGER[], - IN a_get_inactive_permutation BOOLEAN, - IN a_ids_permutation INTEGER[], - IN a_date_from TIMESTAMP, - IN a_date_to TIMESTAMP -) -RETURNS SETOF REFCURSOR -AS $$ -DECLARE - v_id_user INTEGER; - v_get_all_supplier BOOLEAN; - v_get_inactive_supplier BOOLEAN; - v_get_first_supplier_only BOOLEAN; - v_ids_supplier INTEGER[]; - v_get_all_order BOOLEAN; - v_get_inactive_order BOOLEAN; - v_get_first_order_only BOOLEAN; - v_ids_order INTEGER[]; - v_get_inactive_category BOOLEAN; - v_ids_category INTEGER[]; - v_get_inactive_product BOOLEAN; - v_ids_product INTEGER[]; - v_get_inactive_permutation BOOLEAN; - v_ids_permutation INTEGER[]; - v_date_from TIMESTAMP; - v_date_to TIMESTAMP; - v_has_filter_supplier BOOLEAN; - v_has_filter_order BOOLEAN; - v_has_filter_category BOOLEAN; - v_has_filter_product BOOLEAN; - v_has_filter_permutation BOOLEAN; - v_has_filter_date_from BOOLEAN; - v_has_filter_date_to BOOLEAN; - v_guid UUID; - v_ids_permission_supplier_purchase_order INTEGER[]; - v_ids_product_permission INTEGER[]; - v_id_access_level_view INTEGER; - v_code_error_data VARCHAR(50); - v_id_type_error_data INTEGER; - result_suppliers REFCURSOR; - result_orders REFCURSOR; - result_order_product_links REFCURSOR; - -- result_errors REFCURSOR; -BEGIN - v_id_user := TRIM(COALESCE(a_id_user, '')); - v_get_all_supplier := COALESCE(a_get_all_supplier, TRUE); - v_get_inactive_supplier := COALESCE(a_get_inactive_supplier, FALSE); - v_get_first_supplier_only := COALESCE(a_get_first_supplier_only, FALSE); - v_ids_supplier := TRIM(COALESCE(a_ids_supplier, '')); - v_get_all_order := COALESCE(a_get_all_order, TRUE); - v_get_inactive_order := COALESCE(a_get_inactive_order, FALSE); - v_get_first_order_only := COALESCE(a_get_first_order_only, FALSE); - v_ids_order := TRIM(COALESCE(a_ids_order, '')); - v_get_inactive_category := COALESCE(a_get_inactive_category, FALSE); - v_ids_category := TRIM(COALESCE(a_ids_category, '')); - v_get_inactive_product := COALESCE(a_get_inactive_product, FALSE); - v_ids_product := TRIM(COALESCE(a_ids_product, '')); - v_get_inactive_permutation := COALESCE(a_get_inactive_permutation, FALSE); - v_ids_permutation := TRIM(COALESCE(a_ids_permutation, '')); - v_date_from := a_date_from; - v_date_to := a_date_to; - - v_guid := gen_random_uuid(); - v_id_access_level_view := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW' LIMIT 1); - -- v_ids_permission_supplier_purchase_order := (SELECT id_permission FROM Shop_Permission WHERE code = 'SHOP_SUPPLIER_PURCHASE_ORDER' LIMIT 1); - v_code_error_data = 'BAD_DATA'; - v_id_type_error_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_data); - v_has_filter_supplier = (CARDINALITY(v_ids_supplier) > 0); - v_has_filter_order = (CARDINALITY(v_ids_order) > 0); - v_has_filter_category = (CARDINALITY(v_ids_category) > 0); - v_has_filter_product = (CARDINALITY(v_ids_product) > 0); - v_has_filter_permutation = (CARDINALITY(v_ids_permutation) > 0); - v_has_filter_date_from = CASE WHEN ISNULL(v_date_from) THEN FALSE ELSE TRUE END; - v_has_filter_date_to = CASE WHEN ISNULL(v_date_to) THEN FALSE ELSE TRUE END; - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Shop_Supplier_Purchase_Order_Product_Link; - DROP TABLE IF EXISTS tmp_Shop_Supplier_Purchase_Order; - DROP TABLE IF EXISTS tmp_Shop_Supplier; - DROP TABLE IF EXISTS tmp_Shop_Product; - - CREATE TABLE tmp_Shop_Supplier ( - id_supplier INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Supplier_id_supplier - FOREIGN KEY (id_supplier) - REFERENCES Shop_Supplier(id_supplier), - active BOOLEAN NOT NULL, - rank_supplier INTEGER NULL, - can_view BOOLEAN, - can_edit BOOLEAN, - can_admin BIT - ); - - CREATE TABLE tmp_Shop_Supplier_Purchase_Order ( - id_order INTEGER NOT NULL PRIMARY KEY, - id_supplier_ordered INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Supplier_Purchase_Order_id_supplier_ordered - FOREIGN KEY (id_supplier_ordered) - REFERENCES Shop_Supplier(id_supplier), - cost_total_local REAL NOT NULL, - id_currency_cost INTEGER NOT NULL, - active BOOLEAN NOT NULL, - rank_order INTEGER NOT NULL - ); - - /* - CREATE TABLE tmp_Shop_Supplier_Purchase_Order_Product_Link ( - id_link INTEGER NOT NULL PRIMARY KEY, - id_order INTEGER NOT NULL, - CONSTRAINT FK_tmp_Supplier_Purchase_Order_Product_Link_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Supplier_Purchase_Order(id_order), - id_permutation INTEGER NOT NULL, - CONSTRAINT FK_tmp_Supplier_Purchase_Order_Product_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - cost_total_local REAL NOT NULL, - id_currency_cost INTEGER NOT NULL, - quantity_ordered REAL NOT NULL, - id_unit_quantity INTEGER NOT NULL, - CONSTRAINT FK_tmp_Supplier_Purchase_Order_Product_Link_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - quantity_received REAL NULL, - latency_delivery_days INTEGER NOT NULL, - display_order INTEGER NOT NULL - ); - */ - - CREATE TABLE tmp_Shop_Product ( - id_category INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_category - FOREIGN KEY (id_category) - REFERENCES Shop_Product_Category(id_category), - id_product INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - -- product_has_variations BOOLEAN NOT NULL, - id_permutation INTEGER NULL, - CONSTRAINT FK_tmp_Shop_Product_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - active_category BOOLEAN NOT NULL, - active_product BOOLEAN NOT NULL, - active_permutation BOOLEAN NULL, - display_order_category INTEGER NOT NULL, - display_order_product INTEGER NOT NULL, - display_order_permutation INTEGER NULL, - rank_permutation INTEGER NOT NULL, -- _in_category - name VARCHAR(255) NOT NULL, - description VARCHAR(4000) NOT NULL, - /* - price_GBP_full REAL NOT NULL, - price_GBP_min REAL NOT NULL, - */ - latency_manufacture INTEGER NOT NULL, - quantity_min REAL NOT NULL, - quantity_max REAL NOT NULL, - quantity_step REAL NOT NULL, - quantity_stock REAL NOT NULL, - is_subscription BOOLEAN NOT NULL, - id_unit_measurement_interval_recurrence INTEGER, - CONSTRAINT FK_tmp_Shop_Product_id_unit_measurement_interval_recurrence - FOREIGN KEY (id_unit_measurement_interval_recurrence) - REFERENCES Shop_Interval_Recurrence(id_interval), - count_interval_recurrence INTEGER, - id_stripe_product VARCHAR(100), - product_has_variations INTEGER NOT NULL, - can_view BOOLEAN, - can_edit BOOLEAN, - can_admin BIT - ); - - /* - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - guid UUID NOT NULL, - id_type INTEGER NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type (id_type), - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - */ - - -- select v_has_filter_product, v_has_filter_permutation; - - IF v_has_filter_supplier THEN - IF EXISTS ( - SELECT * - FROM UNNEST(v_ids_supplier) AS Supplier_Id - LEFT JOIN Shop_Supplier S ON Supplier_Id = S.id_supplier - WHERE ISNULL(S.id_supplier) - LIMIT 1 - ) THEN - RAISE EXCEPTION 'Invalid supplier IDs: %', ( - SELECT STRING_AGG(Supplier_Id, ', ') - FROM UNNEST(v_ids_supplier) AS Supplier_Id - LEFT JOIN Shop_Supplier S ON Supplier_Id = S.id_supplier - WHERE ISNULL(S.id_supplier) - LIMIT 1 - ) - USING ERRCODE = '22000' - ; - ELSE - INSERT INTO tmp_Shop_Supplier ( - id_supplier, - active, - rank_supplier - ) - SELECT - S.id_supplier, - S.active, - RANK() OVER (ORDER BY id_supplier ASC) AS rank_supplier - FROM Shop_Supplier S - INNER JOIN Split_Temp TS ON S.id_supplier = TS.substring - WHERE - ( - v_get_inactive_supplier - OR S.active = TRUE - ) - ; - END IF; - - IF v_get_first_supplier_only THEN - DELETE FROM tmp_Shop_Supplier t_S - WHERE t_S.rank_supplier > ( - SELECT MIN(t_S.rank_supplier) - FROM tmp_Shop_Supplier t_S - ) - ; - END IF; - END IF; - - IF v_has_filter_category = TRUE THEN - IF EXISTS ( - SELECT * - FROM UNNEST(v_ids_category) AS Category_Id - LEFT JOIN Shop_Product_Category C ON Category_Id = C.id_category - WHERE ISNULL(C.id_category) - ) THEN - RAISE EXCEPTION 'Invalid category IDs: %', ( - SELECT STRING_AGG(Category_Id, ', ') - FROM UNNEST(v_ids_category) AS Category_Id - LEFT JOIN Shop_Product_Category C ON Category_Id = C.id_category - WHERE ISNULL(C.id_category) - ) - USING ERRCODE = '22000' - ; - END IF; - END IF; - - IF v_has_filter_product = TRUE THEN - IF EXISTS ( - SELECT * - FROM UNNEST(v_ids_product) AS Product_Id - LEFT JOIN Shop_Product P ON Product_Id = P.id_product - WHERE ISNULL(P.id_product) - LIMIT 1 - ) THEN - RAISE EXCEPTION 'Invalid product IDs: %', ( - SELECT STRING_AGG(Product_Id, ', ') - FROM UNNEST(v_ids_product) AS Product_Id - LEFT JOIN Shop_Product P ON Product_Id = P.id_product - WHERE ISNULL(P.id_product) - ) - USING ERRCODE = '22000' - ; - END IF; - END IF; - - IF v_has_filter_permutation = TRUE THEN - IF EXISTS ( - SELECT * - FROM UNNEST(v_ids_permutation) AS Permutation_Id - LEFT JOIN Shop_Product_Permutation PP ON Permutation_Id = PP.id_permutation - WHERE ISNULL(PP.id_permutation) - LIMIT 1 - ) THEN - RAISE EXCEPTION 'Invalid permutation IDs: %', ( - SELECT STRING_AGG(Permutation_Id, ', ') - FROM UNNEST(v_ids_permutation) AS Permutation_Id - LEFT JOIN Shop_Product_Permutation PP ON Permutation_Id = PP.id_permutation - WHERE ISNULL(PP.id_permutation) - ) - USING ERRCODE = '22000' - ; - END IF; - END IF; - - IF v_has_filter_category = TRUE OR v_has_filter_product = TRUE OR v_has_filter_permutation = TRUE THEN - INSERT INTO tmp_Shop_Product ( - id_category, - id_product, - id_permutation, - active_category, - active_product, - active_permutation, - display_order_category, - display_order_product, - display_order_permutation - -- rank_permutation, - /* - name, - description, - /* - price_GBP_VAT_incl, - price_GBP_VAT_excl, - price_GBP_min, - */ - latency_manufacture, - quantity_min, - quantity_max, - quantity_step, - quantity_stock, - is_subscription, - id_unit_measurement_interval_recurrence, - count_interval_recurrence, - id_stripe_product, - product_has_variations - */ - ) - SELECT - P.id_category, - P.id_product, - -- P.has_variations AS product_has_variations, - PP.id_permutation, - C.active AS active_category, - P.active AS active_product, - PP.active AS active_permutation, - C.display_order AS display_order_category, - P.display_order AS display_order_product, - PP.display_order AS display_order_permutation - -- RANK() OVER (ORDER BY C.display_order, P.display_order, PP.display_order) AS rank_permutation, #PARTITION BY P.id_category -- _in_category - /* - P.name, - PP.description, - /* - PP.price_GBP_VAT_incl, - PP.price_GBP_VAT_excl, - PP.price_GBP_min, - */ - PP.latency_manufacture, - PP.quantity_min, - PP.quantity_max, - PP.quantity_step, - PP.quantity_stock, - PP.is_subscription, - PP.id_unit_measurement_interval_recurrence, - PP.count_interval_recurrence, - PP.id_stripe_product, - P.has_variations - */ - FROM Shop_Product P - INNER JOIN Shop_Product_Permutation PP - ON P.id_product = PP.id_product - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - WHERE - -- permutations - ( - ( - NOT v_has_filter_permutation - OR FIND_IN_SET(PP.id_permutation, v_ids_permutation) > 0 - ) - AND ( - v_get_inactive_permutation - OR PP.active = TRUE - ) - ) - -- categories - AND ( - ( - NOT v_has_filter_category - OR FIND_IN_SET(P.id_category, v_ids_category) > 0 - ) - AND ( - v_get_inactive_category - OR C.active = TRUE - ) - ) - -- products - AND ( - ( - NOT v_has_filter_product - OR FIND_IN_SET(P.id_product, v_ids_product) > 0 - ) - AND ( - v_get_inactive_product - OR P.active = TRUE - ) - ) - ; - END IF; - - -- Get orders - IF v_has_filter_order AND EXISTS ( - -- SELECT * FROM Split_Temp TS LEFT JOIN Shop_Supplier_Purchase_Order SPO ON TS.substring = SPO.id_order WHERE ISNULL(SPO.id_order) - SELECT * - FROM UNNEST(v_ids_order) Order_Id - - ) THEN - RAISE EXCEPTION 'Invalid order IDs: %', ( - SELECT STRING_AGG(TS.substring, ', ') - FROM UNNEST(v_ids_order) - LEFT JOIN Shop_Supplier_Purchase_Order SPO ON TS.substring = SPO.id_order - WHERE ISNULL(SPO.id_order) - ) - USING ERRCODE = '22000' - ; - END IF; - - INSERT INTO tmp_Shop_Supplier_Purchase_Order ( -- _Product_Link - id_order, - -- active, - rank_order - ) - SELECT - SPO.id_order, - -- SPO.active, - RANK() OVER (ORDER BY SPO.id_order ASC) AS rank_order - FROM Shop_Supplier_Purchase_Order SPO - -- INNER JOIN Split_Temp TS ON SPO.id_order = TS.substring - INNER JOIN Shop_Supplier_Purchase_Order_Product_Link SPOPL ON SPO.id_order = SPOPL.id_order - INNER JOIN Shop_Supplier S ON SPO.id_supplier_ordered = S.id_supplier - INNER JOIN Shop_Product_Permutation PP ON SPOPL.id_permutation = PP.id_permutation - INNER JOIN Shop_Product P ON PP.id_product = P.id_product - INNER JOIN Shop_Product_Category C ON P.id_category = C.id_category - LEFT JOIN tmp_Shop_Product t_P ON SPOPL.id_permutation = t_P.id_permutation - LEFT JOIN tmp_Shop_Supplier t_S ON SPO.id_supplier_ordered = t_S.id_supplier - WHERE - -- supplier - ( - v_has_filter_supplier = FALSE - OR NOT ISNULL(t_S.id_supplier) -- SPO.id_supplier_ordered IN (SELECT DISTINCT id_supplier FROM tmp_Shop_Supplier) - ) - -- order - AND ( - ( - v_has_filter_order = FALSE - OR ( - -- ID - -- FIND_IN_SET(SPO.id_order, v_ids_order) > 0 - SPO.id_order = ANY(v_ids_order) - -- date - AND ( - ( - v_has_filter_date_from = FALSE - OR SPO.created_on > v_date_from - ) - AND ( - v_has_filter_date_to = FALSE - OR SPO.created_on < v_date_to - ) - ) - ) - ) - -- active - /* - AND ( - v_get_inactive_order - OR SPO.active = TRUE - ) - */ - ) - -- permutations - AND ( - ( - v_has_filter_category = FALSE - AND v_has_filter_product = FALSE - AND v_has_filter_permutation = FALSE - ) - OR NOT ISNULL(t_P.id_permutation) -- SPO.id_permutation IN (SELECT DISTINCT id_permutation FROM tmp_Shop_Product) - ) - ; - - IF v_get_first_order_only THEN - DELETE FROM tmp_Shop_Supplier_Purchase_Order t_SPO - WHERE t_SPO.rank_order > ( - SELECT MIN(t_SPO.rank_order) - FROM tmp_Shop_Supplier_Purchase_Order t_SPO - ) - ; - END IF; - - -- Permissions - -- v_id_user := (SELECT id_user FROM Shop_User WHERE name = CURRENT_USER); - v_ids_permission_supplier_purchase_order := (SELECT STRING_AGG(id_permission, ',') FROM Shop_Permission WHERE code IN ('STORE_SUPPLIER', 'STORE_SUPPLIER_PURCHASE_ORDER')); - -- v_ids_permutation_permission := (SELECT STRING_AGG(id_permutation, ',') FROM tmp_Shop_Product WHERE NOT ISNULL(id_permutation)); - v_ids_product_permission := (SELECT STRING_AGG(DISTINCT t_P.id_product, ',') FROM tmp_Shop_Product t_P WHERE NOT ISNULL(t_P.id_product)); - - -- SELECT v_guid, v_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_permutation_permission; - -- select * from Shop_Calc_User_Temp; - - CALL p_shop_calc_user(v_guid, v_id_user, FALSE, v_ids_permission_supplier_purchase_order, v_id_access_level_view, v_ids_product_permission); - - -- select * from Shop_Calc_User_Temp; - - IF NOT EXISTS (SELECT can_view FROM Shop_Calc_User_Temp UE_T WHERE UE_T.GUID = v_guid) THEN - RAISE EXCEPTION 'You do not have view permissions for %', ( - SELECT STRING_AGG(name, ', ') - FROM Shop_Permission - WHERE id_permission = v_ids_permission_supplier_purchase_order - ) - USING ERRCODE = '42501' - ; - END IF; - - - UPDATE tmp_Shop_Product t_P - SET t_P.can_view = UE_T.can_view, - t_P.can_edit = UE_T.can_edit, - t_P.can_admin = UE_T.can_admin - FROM tmp_Shop_Product t_P - INNER JOIN Shop_Calc_User_Temp UE_T - ON t_P.id_product = UE_T.id_product -- t_P.id_permutation = UE_T.id_permutation - AND UE_T.GUID = v_guid - ; - - -- CALL p_shop_clear_calc_user(v_guid); - -- DROP TABLE IF EXISTS Shop_Calc_User_Temp; - DELETE FROM Shop_Calc_User_Temp - WHERE GUID = v_guid - ; - - - -- select * from tmp_Shop_Product; - - -- Returns - -- v_now := CURRENT_TIMESTAMP; - - -- Suppliers - OPEN result_suppliers FOR - SELECT - t_S.id_supplier, - S.name_company, - S.name_contact, - S.department_contact, - S.id_address, - S.phone_number, - S.fax, - S.email, - S.website, - S.id_currency, - t_S.active - FROM tmp_Shop_Supplier t_S - INNER JOIN Shop_Supplier S - ON t_S.id_supplier = S.id_supplier - ; - RETURN NEXT result_suppliers; - - -- Supplier Purchase Order - OPEN result_orders FOR - SELECT -- * - t_SPO.id_order, - SPO.id_supplier_ordered, - SPO.cost_total_local, - SPO.id_currency_cost, - t_SPO.active - FROM Shop_Supplier_Purchase_Order SPO - INNER JOIN tmp_Shop_Supplier_Purchase_Order t_SPO ON SPO.id_order = t_SPO.id_order - ; - RETURN NEXT result_orders; - - -- Supplier Purchase Order Product Link - OPEN result_order_product_links FOR - SELECT - SPOPL.id_link, - SPOPL.id_order, - SPOPL.id_permutation, - P.name as name_product, - SPOPL.cost_total_local, - SPOPL.id_currency_cost, - SPOPL.quantity_ordered, - SPOPL.id_unit_quantity, - SPOPL.quantity_received, - SPOPL.latency_delivery_days, - SPOPL.display_order - FROM Shop_Supplier_Purchase_Order_Product_Link SPOPL - -- INNER JOIN tmp_Shop_Supplier_Purchase_Order_Product_Link t_SPOPL ON SPOPL.id_link = t_SPOPL.id_link - INNER JOIN tmp_Shop_Supplier_Purchase_Order t_SPO ON SPOPL.id_order = t_SPO.id_order - INNER JOIN Shop_Product_Permutation PP ON SPOPL.id_permutation = PP.id_permutation - INNER JOIN Shop_Product P ON PP.id_product = P.id_product - INNER JOIN Shop_Product_Category C ON P.id_category = C.id_category - ORDER BY SPOPL.id_order, C.display_order, P.display_order, PP.display_order - ; - RETURN NEXT result_order_product_links; - - -- Errors - /* - SELECT - /* - t_ME.display_order, - t_ME.guid, - t_ME.id_type, - t_ME.msg, - MET.code, - MET.name, - MET.description - */ - * - FROM tmp_Msg_Error t_ME - INNER JOIN Shop_Msg_Error_Type MET - ON t_ME.id_type = MET.id_type - WHERE guid = v_guid - ; - */ - - /* - OPEN result_errors FOR - SELECT * - FROM tmp_Msg_Error - ; - -- RETURN NEXT result_errors; - */ - - - /* - -- Return arguments for test - SELECT - v_ids_category, - v_get_inactive_category, - v_ids_product, - v_get_inactive_product, - v_get_first_product_only, - v_get_all_product, - v_ids_image, - v_get_inactive_image, - v_get_first_image_only, - v_get_all_image - ; - */ - - -- select 'other outputs'; - -- select * from tmp_Shop_Product; - - -- Clean up - DROP TABLE IF EXISTS tmp_Shop_Supplier_Purchase_Order_Product_Link; - DROP TABLE IF EXISTS tmp_Shop_Supplier_Purchase_Order; - DROP TABLE IF EXISTS tmp_Shop_Supplier; - DROP TABLE IF EXISTS tmp_Shop_Product; - - DELETE FROM Shop_Calc_User_Temp - WHERE GUID = v_guid - ; -END; -$$ LANGUAGE plpgsql; - - -/* - -DROP FUNCTION IF EXISTS fetch_results; - -CREATE OR REPLACE FUNCTION fetch_results() -RETURNS VOID AS $$ -DECLARE - curs refcursor; - rec record; -BEGIN - FOR curs IN SELECT p_shop_get_many_supplier_purchase_order ( - '', -- a_id_user - TRUE, -- a_get_all_supplier - FALSE, -- a_get_inactive_supplier - FALSE, -- a_get_first_supplier_only - '', -- a_ids_supplier - TRUE, -- a_get_all_order - -- FALSE, -- a_get_inactive_order - FALSE, -- a_get_first_order_only - '', -- a_ids_order - FALSE, -- a_get_inactive_category - '', -- a_ids_category - FALSE, -- a_get_inactive_product - '', -- a_ids_product - FALSE, -- a_get_inactive_permutation - '', -- a_ids_permutation - NULL, -- a_date_from - NULL -- a_date_to - ) LOOP - RAISE NOTICE 'Fetching from cursor: %', curs; - LOOP - FETCH curs INTO rec; - EXIT WHEN NOT FOUND; - RAISE NOTICE 'Record: %', rec; - END LOOP; - END LOOP; -END; -$$ LANGUAGE plpgsql; - -SELECT fetch_results(); - -*/ - - - -CREATE OR REPLACE FUNCTION p_shop_get_many_manufacturing_purchase_order ( - IN a_id_user INTEGER, - IN a_get_all_order BOOLEAN, - IN a_get_inactive_order BOOLEAN, - IN a_get_first_order_only BOOLEAN, - IN a_ids_order INTEGER[], - IN a_get_inactive_category BOOLEAN, - IN a_ids_category INTEGER[], - IN a_get_inactive_product BOOLEAN, - IN a_ids_product INTEGER[], - IN a_get_inactive_permutation BOOLEAN, - IN a_ids_permutation INTEGER[], - IN a_date_from TIMESTAMP, - IN a_date_to TIMESTAMP -) -RETURNS SETOF REFCURSOR -AS $$ -DECLARE - v_id_user INTEGER; - v_get_all_order BOOLEAN; - v_get_inactive_order BOOLEAN; - v_get_first_order_only BOOLEAN; - v_ids_order INTEGER[]; - v_get_inactive_category BOOLEAN; - v_ids_category INTEGER[]; - v_get_inactive_product BOOLEAN; - v_ids_product INTEGER[]; - v_get_inactive_permutation BOOLEAN; - v_ids_permutation INTEGER[]; - v_date_from TIMESTAMP; - v_date_to TIMESTAMP; - v_has_filter_order BOOLEAN; - v_has_filter_category BOOLEAN; - v_has_filter_product BOOLEAN; - v_has_filter_permutation BOOLEAN; - v_has_filter_date_from BOOLEAN; - v_has_filter_date_to BOOLEAN; - v_guid UUID; - v_id_access_level_view INTEGER; - v_code_error_data VARCHAR(50); - v_id_type_error_data INTEGER; - v_ids_permission_manufacturing_purchase_order VARCHAR(4000); - v_ids_product_permission INTEGER[]; - result_orders REFCURSOR; - result_order_product_links REFCURSOR; - result_errors REFCURSOR; -BEGIN - v_id_user := TRIM(COALESCE(a_id_user, '')); - v_get_all_order := COALESCE(a_get_all_order, TRUE); - v_get_inactive_order := COALESCE(a_get_inactive_order, FALSE); - v_get_first_order_only := COALESCE(a_get_first_order_only, FALSE); - v_ids_order := TRIM(COALESCE(a_ids_order, '')); - v_get_inactive_category := COALESCE(a_get_inactive_category, FALSE); - v_ids_category := TRIM(COALESCE(a_ids_category, '')); - v_get_inactive_product := COALESCE(a_get_inactive_product, FALSE); - v_ids_product := TRIM(COALESCE(a_ids_product, '')); - v_get_inactive_permutation := COALESCE(a_get_inactive_permutation, FALSE); - v_ids_permutation := TRIM(COALESCE(a_ids_permutation, '')); - v_date_from := a_date_from; - v_date_to := a_date_to; - - v_guid := gen_random_uuid(); - v_id_access_level_view := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW' LIMIT 1); - -- v_ids_permission_manufacturing_purchase_order := (SELECT id_permission FROM Shop_Permission WHERE code = 'SHOP_manufacturing_PURCHASE_ORDER' LIMIT 1); - v_code_error_data = 'BAD_DATA'; - v_id_type_error_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_data); - - v_has_filter_order = CASE WHEN v_ids_order = '' THEN FALSE ELSE TRUE END; - v_has_filter_category = CASE WHEN v_ids_category = '' THEN FALSE ELSE TRUE END; - v_has_filter_product = CASE WHEN v_ids_product = '' THEN FALSE ELSE TRUE END; - v_has_filter_permutation = CASE WHEN v_ids_permutation = '' THEN FALSE ELSE TRUE END; - v_has_filter_date_from = CASE WHEN ISNULL(v_date_from) THEN FALSE ELSE TRUE END; - v_has_filter_date_to = CASE WHEN ISNULL(v_date_to) THEN FALSE ELSE TRUE END; - - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Shop_Manufacturing_Purchase_Order_Product_Link; - DROP TABLE IF EXISTS tmp_Shop_Manufacturing_Purchase_Order; - DROP TABLE IF EXISTS tmp_Shop_Product; - - CREATE TABLE tmp_Shop_Manufacturing_Purchase_Order ( - id_order INTEGER NOT NULL PRIMARY KEY, - /* - id_supplier_ordered INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Manufacturing_Purchase_Order_id_supplier_ordered - FOREIGN KEY (id_supplier_ordered) - REFERENCES Shop_Supplier(id_supplier), - */ - cost_total_local REAL NOT NULL, - id_currency_cost INTEGER NOT NULL, - value_produced_total_local REAL NOT NULL, - active BOOLEAN NOT NULL, - rank_order INTEGER NOT NULL - ); - - /* - CREATE TABLE tmp_Shop_Manufacturing_Purchase_Order_Product_Link ( - id_link INTEGER NOT NULL PRIMARY KEY, - id_order INTEGER NOT NULL, - CONSTRAINT FK_tmp_manufacturing_Purchase_Order_Product_Link_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_manufacturing_Purchase_Order(id_order), - id_permutation INTEGER NOT NULL, - CONSTRAINT FK_tmp_manufacturing_Purchase_Order_Product_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - cost_total_local REAL NOT NULL, - id_currency_cost INTEGER NOT NULL, - quantity_used REAL NOT NULL, - id_unit_quantity INTEGER NOT NULL, - CONSTRAINT FK_tmp_manufacturing_Purchase_Order_Product_Link_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - quantity_produced REAL NULL, - latency_delivery_days INTEGER NOT NULL, - display_order INTEGER NOT NULL - ); - */ - - CREATE TABLE tmp_Shop_Product ( - id_category INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_category - FOREIGN KEY (id_category) - REFERENCES Shop_Product_Category(id_category), - id_product INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - -- product_has_variations BOOLEAN NOT NULL, - id_permutation INTEGER NULL, - CONSTRAINT FK_tmp_Shop_Product_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - active_category BOOLEAN NOT NULL, - active_product BOOLEAN NOT NULL, - active_permutation BOOLEAN NULL, - display_order_category INTEGER NOT NULL, - display_order_product INTEGER NOT NULL, - display_order_permutation INTEGER NULL, - rank_permutation INTEGER NOT NULL, -- _in_category - -- name VARCHAR(255) NOT NULL, - -- description VARCHAR(4000) NOT NULL, - /* - price_GBP_full REAL NOT NULL, - price_GBP_min REAL NOT NULL, - */ - /* - latency_manufacture INTEGER NOT NULL, - quantity_min REAL NOT NULL, - quantity_max REAL NOT NULL, - quantity_step REAL NOT NULL, - quantity_stock REAL NOT NULL, - is_subscription BOOLEAN NOT NULL, - id_unit_measurement_interval_recurrence INTEGER, - CONSTRAINT FK_tmp_Shop_Product_id_unit_measurement_interval_recurrence - FOREIGN KEY (id_unit_measurement_interval_recurrence) - REFERENCES Shop_Interval_Recurrence(id_interval), - count_interval_recurrence INTEGER, - id_stripe_product VARCHAR(100), - product_has_variations INTEGER NOT NULL, - */ - can_view BOOLEAN, - can_edit BOOLEAN, - can_admin BIT - ); - - /* - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - guid UUID NOT NULL, - id_type INTEGER NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type (id_type), - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - */ - - -- select v_has_filter_product, v_has_filter_permutation; - - IF v_has_filter_category = TRUE AND EXISTS ( - SELECT * - FROM UNNEST(v_ids_category) AS Category_Id - LEFT JOIN Shop_Product_Category C ON Category_Id = C.id_category - WHERE ISNULL(C.id_category) - ) THEN - RAISE EXCEPTION 'Invalid category IDs: %', ( - SELECT COALESCE(STRING_AGG(Category_Id, ', ') ,'NULL') - FROM UNNEST(v_ids_category) AS Category_Id - LEFT JOIN Shop_Product_Category C ON Category_Id = C.id_category - WHERE ISNULL(C.id_category) - ) - USING ERRCODE = '22000' - ; - END IF; - - IF v_has_filter_product = TRUE AND EXISTS ( - SELECT * - FROM UNNEST(v_ids_product) AS Product_Id - LEFT JOIN Shop_Product P ON Product_Id = P.id_product - WHERE ISNULL(P.id_product) - LIMIT 1 - ) THEN - RAISE EXCEPTION 'Invalid product IDs: %', ( - SELECT COALESCE(STRING_AGG(Product_Id, ', ') ,'NULL') - FROM UNNEST(v_ids_product) AS Product_Id - LEFT JOIN Shop_Product P ON Product_Id = P.id_product - WHERE ISNULL(P.id_product) - ) - USING ERRCODE = '22000' - ; - END IF; - - IF v_has_filter_permutation = TRUE AND EXISTS ( - SELECT * - FROM UNNEST(v_ids_permutation) AS Permutation_Id - LEFT JOIN Shop_Product_Permutation PP ON Permutation_Id = PP.id_permutation - WHERE ISNULL(PP.id_permutation) - LIMIT 1 - ) THEN - RAISE EXCEPTION 'Invalid permutation IDs: %', ( - SELECT STRING_AGG(Permutation_Id, ', ') - FROM UNNEST(v_ids_permutation) AS Permutation_Id - LEFT JOIN Shop_Product_Permutation PP ON Permutation_Id = PP.id_permutation - WHERE ISNULL(PP.id_permutation) - ) - USING ERRCODE = '22000' - ; - END IF; - - IF v_has_filter_category = TRUE OR v_has_filter_product = TRUE OR v_has_filter_permutation = TRUE THEN - INSERT INTO tmp_Shop_Product ( - id_category, - id_product, - id_permutation, - active_category, - active_product, - active_permutation, - display_order_category, - display_order_product, - display_order_permutation - -- rank_permutation, - /* - name, - description, - /* - price_GBP_VAT_incl, - price_GBP_VAT_excl, - price_GBP_min, - */ - latency_manufacture, - quantity_min, - quantity_max, - quantity_step, - quantity_stock, - is_subscription, - id_unit_measurement_interval_recurrence, - count_interval_recurrence, - id_stripe_product, - product_has_variations - */ - ) - SELECT - P.id_category, - P.id_product, - -- P.has_variations AS product_has_variations, - PP.id_permutation, - C.active AS active_category, - P.active AS active_product, - PP.active AS active_permutation, - C.display_order AS display_order_category, - P.display_order AS display_order_product, - PP.display_order AS display_order_permutation - -- RANK() OVER (ORDER BY C.display_order, P.display_order, PP.display_order) AS rank_permutation, #PARTITION BY P.id_category -- _in_category - /* - P.name, - PP.description, - /* - PP.price_GBP_VAT_incl, - PP.price_GBP_VAT_excl, - PP.price_GBP_min, - */ - PP.latency_manufacture, - PP.quantity_min, - PP.quantity_max, - PP.quantity_step, - PP.quantity_stock, - PP.is_subscription, - PP.id_unit_measurement_interval_recurrence, - PP.count_interval_recurrence, - PP.id_stripe_product, - P.has_variations - */ - FROM Shop_Product P - INNER JOIN Shop_Product_Permutation PP - ON P.id_product = PP.id_product - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - WHERE - -- permutations - ( - ( - NOT v_has_filter_permutation - OR FIND_IN_SET(PP.id_permutation, v_ids_permutation) > 0 - ) - AND ( - v_get_inactive_permutation - OR PP.active = TRUE - ) - ) - -- categories - AND ( - ( - NOT v_has_filter_category - OR FIND_IN_SET(P.id_category, v_ids_category) > 0 - ) - AND ( - v_get_inactive_category - OR C.active = TRUE - ) - ) - -- products - AND ( - ( - NOT v_has_filter_product - OR FIND_IN_SET(P.id_product, v_ids_product) > 0 - ) - AND ( - v_get_inactive_product - OR P.active = TRUE - ) - ) - ; - END IF; - - -- Get orders - IF v_has_filter_order AND EXISTS ( - SELECT * - FROM UNNEST(v_ids_order) AS Order_Id - LEFT JOIN Shop_Manufacturing_Purchase_Order MPO ON Order_Id = MPO.id_order - WHERE ISNULL(MPO.id_order) - LIMIT 1 - ) THEN - RAISE EXCEPTION 'Invalid order IDs: %', ( - SELECT STRING_AGG(Order_Id, ', ') - FROM UNNEST(v_ids_order) AS Order_Id - LEFT JOIN Shop_Manufacturing_Purchase_Order MPO ON Order_Id = MPO.id_order - WHERE ISNULL(MPO.id_order) - ) - USING ERRCODE = '22000' - ; - END IF; - - INSERT INTO tmp_Shop_Manufacturing_Purchase_Order ( -- _Product_Link - id_order, - -- active, - rank_order - ) - SELECT - MPO.id_order, - -- MPO.active, - RANK() OVER (ORDER BY MPO.id_order ASC) AS rank_order - FROM Shop_Manufacturing_Purchase_Order MPO - -- INNER JOIN Split_Temp TS ON MPO.id_order = TS.substring - INNER JOIN Shop_manufacturing_Purchase_Order_Product_Link MPOPL ON MPO.id_order = MPOPL.id_order - INNER JOIN Shop_Product_Permutation PP ON MPOPL.id_permutation = PP.id_permutation - INNER JOIN Shop_Product P ON PP.id_product = P.id_product - INNER JOIN Shop_Product_Category C ON P.id_category = C.id_category - LEFT JOIN tmp_Shop_Product t_P ON MPOPL.id_permutation = t_P.id_permutation - WHERE - -- order - ( - ( - v_has_filter_order = 0 - OR ( - -- ID - -- FIND_IN_SET(MPO.id_order, v_ids_order) > 0 - MPO.id_order = ANY(v_ids_order) - -- date - AND ( - ( - v_has_filter_date_from = 0 - OR MPO.created_on > v_date_from - ) - AND ( - v_has_filter_date_to = 0 - OR MPO.created_on < v_date_to - ) - ) - ) - ) - -- active - /* - AND ( - v_get_inactive_order - OR MPO.active = TRUE - ) - */ - ) - -- permutations - AND ( - ( - v_has_filter_category = FALSE - AND v_has_filter_product = FALSE - AND v_has_filter_permutation = 0 - ) - OR NOT ISNULL(t_P.id_permutation) -- MPO.id_permutation IN (SELECT DISTINCT id_permutation FROM tmp_Shop_Product) - ) - ; - - IF v_get_first_order_only THEN - DELETE FROM tmp_Shop_Manufacturing_Purchase_Order t_MPO - WHERE t_MPO.rank_order > ( - SELECT MIN(t_MPO.rank_order) - FROM tmp_Shop_Manufacturing_Purchase_Order t_MPO - ) - ; - END IF; - - -- Permissions - -- v_id_user := (SELECT id_user FROM Shop_User WHERE name = CURRENT_USER); - v_ids_permission_manufacturing_purchase_order := (SELECT STRING_AGG(id_permission, ',') FROM Shop_Permission WHERE code IN ('STORE_manufacturing', 'STORE_manufacturing_PURCHASE_ORDER')); - -- v_ids_permutation_permission := (SELECT STRING_AGG(id_permutation, ',') FROM tmp_Shop_Product WHERE NOT ISNULL(id_permutation)); - v_ids_product_permission := (SELECT STRING_AGG(P.id_product, ',') FROM (SELECT DISTINCT id_product FROM tmp_Shop_Product WHERE NOT ISNULL(id_product)) P); - - -- SELECT v_guid, v_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_permutation_permission; - -- select * from Shop_Calc_User_Temp; - - CALL p_shop_calc_user(v_guid, v_id_user, FALSE, v_ids_permission_manufacturing_purchase_order, v_id_access_level_view, v_ids_product_permission); - - -- select * from Shop_Calc_User_Temp; - - IF NOT EXISTS (SELECT can_view FROM Shop_Calc_User_Temp UE_T WHERE UE_T.GUID = v_guid) THEN - RAISE EXCEPTION 'You do not have view permissions for %', ( - SELECT STRING_AGG(name, ', ') - FROM Shop_Permission - WHERE id_permission = v_ids_permission_manufacturing_purchase_order - ) - USING ERRCODE = '42501' - ; - END IF; - - - UPDATE tmp_Shop_Product t_P - SET t_P.can_view = UE_T.can_view, - t_P.can_edit = UE_T.can_edit, - t_P.can_admin = UE_T.can_admin - FROM tmp_Shop_Product t_P - INNER JOIN Shop_Calc_User_Temp UE_T - ON t_P.id_product = UE_T.id_product -- t_P.id_permutation = UE_T.id_permutation - AND UE_T.GUID = v_guid - ; - - -- CALL p_shop_clear_calc_user(v_guid); - -- DROP TABLE IF EXISTS Shop_Calc_User_Temp; - DELETE FROM Shop_Calc_User_Temp - WHERE GUID = v_guid - ; - - - -- select * from tmp_Shop_Product; - - -- Returns - - -- manufacturing Purchase Order - OPEN result_orders FOR - SELECT -- * - t_MPO.id_order, - MPO.cost_total_local, - MPO.id_currency_cost, - MPO.value_produced_total_local, - t_MPO.active - FROM Shop_Manufacturing_Purchase_Order MPO - INNER JOIN tmp_Shop_Manufacturing_Purchase_Order t_MPO ON MPO.id_order = t_MPO.id_order - ; - RETURN NEXT result_orders; - - -- manufacturing Purchase Order Product Link - OPEN result_order_product_links FOR - SELECT - MPOPL.id_link, - MPOPL.id_order, - MPOPL.id_permutation, - P.name as name_product, - MPOPL.cost_total_local, - MPOPL.id_currency_cost, - MPOPL.value_produced_total_local, - MPOPL.quantity_used, - MPOPL.id_unit_quantity, - MPOPL.quantity_produced, - MPOPL.latency_manufacture, - MPOPL.display_order - FROM Shop_manufacturing_Purchase_Order_Product_Link MPOPL - -- INNER JOIN tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL ON MPOPL.id_link = t_MPOPL.id_link - INNER JOIN tmp_Shop_Manufacturing_Purchase_Order t_MPO ON MPOPL.id_order = t_MPO.id_order - INNER JOIN Shop_Product_Permutation PP ON MPOPL.id_permutation = PP.id_permutation - INNER JOIN Shop_Product P ON PP.id_product = P.id_product - INNER JOIN Shop_Product_Category C ON P.id_category = C.id_category - ORDER BY MPOPL.id_order, C.display_order, P.display_order, PP.display_order - ; - RETURN NEXT result_order_product_links; - - -- Errors - /* - SELECT - /* - t_ME.display_order, - t_ME.guid, - t_ME.id_type, - t_ME.msg, - MET.code, - MET.name, - MET.description - */ - * - FROM tmp_Msg_Error t_ME - INNER JOIN Shop_Msg_Error_Type MET - ON t_ME.id_type = MET.id_type - WHERE guid = v_guid - ; - OPEN result_errors FOR - SELECT * - FROM tmp_Msg_Error - ; - -- RETURN NEXT result_errors; - */ - - /* - -- Return arguments for test - SELECT - v_ids_category, - v_get_inactive_category, - v_ids_product, - v_get_inactive_product, - v_get_first_product_only, - v_get_all_product, - v_ids_image, - v_get_inactive_image, - v_get_first_image_only, - v_get_all_image - ; - */ - - -- select 'other outputs'; - -- select * from tmp_Shop_Product; - - -- Clean up - DROP TABLE IF EXISTS tmp_Shop_Manufacturing_Purchase_Order_Product_Link; - DROP TABLE IF EXISTS tmp_Shop_Manufacturing_Purchase_Order; - DROP TABLE IF EXISTS tmp_Shop_Product; - - DELETE FROM Shop_Calc_User_Temp - WHERE GUID = v_guid - ; -END; -$$ LANGUAGE plpgsql; - - -/* - - -DROP FUNCTION IF EXISTS fetch_results; - -CREATE OR REPLACE FUNCTION fetch_results() -RETURNS VOID AS $$ -DECLARE - curs refcursor; - rec record; -BEGIN - FOR curs IN SELECT p_shop_get_many_manufacturing_purchase_order ( - '', -- a_id_user - TRUE, -- a_get_all_order - FALSE, -- a_get_inactive_order - FALSE, -- a_get_first_order_only - '', -- a_ids_order - FALSE, -- a_get_inactive_category - '', -- a_ids_category - FALSE, -- a_get_inactive_product - '', -- a_ids_product - FALSE, -- a_get_inactive_permutation - '', -- a_ids_permutation - NULL, -- a_date_from - NULL -- a_date_to - ) LOOP - RAISE NOTICE 'Fetching from cursor: %', curs; - LOOP - FETCH curs INTO rec; - EXIT WHEN NOT FOUND; - RAISE NOTICE 'Record: %', rec; - END LOOP; - END LOOP; -END; -$$ LANGUAGE plpgsql; - -SELECT fetch_results(); - -*/ - - - -CREATE OR REPLACE FUNCTION p_shop_get_many_customer ( - IN a_id_user INTEGER, - IN a_get_all_customer BOOLEAN, - IN a_get_inactive_customer BOOLEAN, - IN a_get_first_customer_only BOOLEAN, - IN a_ids_customer INTEGER[] -) -RETURNS SETOF REFCURSOR -AS $$ -DECLARE - v_id_user INTEGER; - v_get_all_customer BOOLEAN; - v_get_inactive_customer BOOLEAN; - v_get_first_customer_only BOOLEAN; - v_ids_customer INTEGER[]; - v_has_filter_customer BOOLEAN; - v_guid UUID; - v_id_permission_customer INTEGER; - v_id_access_level_view INTEGER; - v_id_error_type_bad_data INTEGER; - v_code_error_type_bad_data VARCHAR(50); - result_customers REFCURSOR; - -- result_errors REFCURSOR; -BEGIN - v_id_user := TRIM(COALESCE(a_id_user, '')); - v_get_inactive_customer := COALESCE(a_get_inactive_customer, FALSE); - v_get_first_customer_only := COALESCE(a_get_first_customer_only, FALSE); - v_ids_customer := TRIM(COALESCE(a_ids_customer, '')); - v_get_all_customer := COALESCE(a_get_all_customer, CASE WHEN v_ids_customer = '' THEN TRUE ELSE FALSE END); - - - v_code_error_type_bad_data = 'BAD_DATA'; - v_id_error_type_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_type_bad_data LIMIT 1); - v_guid := gen_random_uuid(); - v_id_access_level_view := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW'); - - v_has_filter_customer = CASE WHEN a_ids_customer = '' THEN FALSE ELSE TRUE END; - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Shop_Customer; - - CREATE TABLE tmp_Shop_Customer ( - id_customer INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Customer_id_customer - FOREIGN KEY (id_customer) - REFERENCES Shop_Customer(id_customer), - active BOOLEAN NOT NULL, - rank_customer INTEGER NULL, - can_view BOOLEAN, - can_edit BOOLEAN, - can_admin BIT - ); - - /* - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - guid UUID NOT NULL, - id_type INTEGER NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type (id_type), - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - */ - - -- select v_has_filter_product, v_has_filter_permutation; - - IF v_has_filter_customer = TRUE OR a_get_all_customer = TRUE THEN - IF EXISTS ( - SELECT * - FROM UNNEST(v_ids_customer) AS Customer_Id - LEFT JOIN Shop_Customer C ON Customer_Id = C.id_customer - WHERE ISNULL(C.id_customer) - ) THEN - RAISE EXCEPTION 'Invalid customer IDs: %', ( - SELECT STRING_AGG(Customer_Id, ', ') - FROM UNNEST(v_ids_customer) AS Customer_Id - LEFT JOIN Shop_Customer C ON Customer_Id = C.id_customer - WHERE ISNULL(C.id_customer) - LIMIT 1 - ) - USING ERRCODE = '22000' - ; - ELSE - INSERT INTO tmp_Shop_Customer ( - id_customer, - active, - rank_customer - ) - SELECT - C.id_customer, - C.active, - RANK() OVER (ORDER BY C.id_customer ASC) AS rank_customer - FROM Shop_Customer C - LEFT JOIN Split_Temp S_T ON C.id_customer = S_T.substring - WHERE - ( - a_get_all_customer = 1 - OR NOT ISNULL(S_T.substring) - ) - AND ( - a_get_inactive_customer = 1 - OR C.active = TRUE - ) - ; - END IF; - - IF a_get_first_customer_only = TRUE THEN - DELETE FROM tmp_Shop_Customer t_C - WHERE t_C.rank_customer > ( - SELECT MIN(t_C.rank_customer) - FROM tmp_Shop_Customer t_C - ) - ; - END IF; - END IF; - - -- Permissions - -- v_id_user := (SELECT id_user FROM Shop_User WHERE name = CURRENT_USER); - v_id_permission_customer := (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_CUSTOMER' LIMIT 1); - - -- SELECT v_guid, a_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_permutation_permission; - -- select * from Shop_Calc_User_Temp; - - CALL p_shop_calc_user(v_guid, a_id_user, FALSE, v_id_permission_customer, v_id_access_level_view, ''); - - -- select * from Shop_Calc_User_Temp; - - IF NOT EXISTS (SELECT can_view FROM Shop_Calc_User_Temp UE_T WHERE UE_T.GUID = v_guid) THEN - RAISE EXCEPTION 'You do not have view permissions for %', ( - SELECT COALESCE(STRING_AGG(name, ', '), 'NULL') - FROM Shop_Permission - WHERE id_permission = v_id_permission_customer - ) - USING ERRCODE = '42501' - ; - END IF; - - - -- select * from tmp_Shop_Product; - - -- Returns - -- v_now := CURRENT_TIMESTAMP; - - -- customers - OPEN result_customers FOR - SELECT - t_C.id_customer, - C.name_company, - C.name_contact, - C.department_contact, - C.id_address, - C.phone_number, - C.email, - C.id_currency, - C.active - FROM tmp_Shop_Customer t_C - INNER JOIN Shop_Customer C ON t_C.id_customer = C.id_customer - ; - RETURN NEXT result_customers; - - -- Errors - /* - SELECT - /* - t_ME.display_order, - t_ME.guid, - t_ME.id_type, - t_ME.msg, - MET.code, - MET.name, - MET.description - */ - * - FROM tmp_Msg_Error t_ME - INNER JOIN Shop_Msg_Error_Type MET - ON t_ME.id_type = MET.id_type - WHERE guid = v_guid - ; - OPEN result_errors FOR - SELECT * - FROM tmp_Msg_Error - ; - -- RETURN NEXT result_errors; - */ - - /* - -- Return arguments for test - SELECT - a_ids_category, - a_get_inactive_category, - a_ids_product, - a_get_inactive_product, - a_get_first_product_only, - a_get_all_product, - a_ids_image, - a_get_inactive_image, - a_get_first_image_only, - a_get_all_image - ; - */ - - -- select 'other outputs'; - -- select * from tmp_Shop_Product; - - -- Clean up - DROP TABLE IF EXISTS tmp_Shop_Customer; - - DELETE FROM Shop_Calc_User_Temp - WHERE GUID = v_guid - ; -END; -$$ LANGUAGE plpgsql; - - -/* - -DROP FUNCTION IF EXISTS fetch_results; - -CREATE OR REPLACE FUNCTION fetch_results() -RETURNS VOID AS $$ -DECLARE - curs refcursor; - rec record; -BEGIN - FOR curs IN SELECT p_shop_get_many_customer ( - '', -- a_id_user - 1, -- a_get_all_customer - 0, -- a_get_inactive_customer - 0, -- a_get_first_customer_only - '' -- a_ids_customer - ) LOOP - RAISE NOTICE 'Fetching from cursor: %', curs; - LOOP - FETCH curs INTO rec; - EXIT WHEN NOT FOUND; - RAISE NOTICE 'Record: %', rec; - END LOOP; - END LOOP; -END; -$$ LANGUAGE plpgsql; - -SELECT fetch_results(); - -*/ - - - -CREATE OR REPLACE FUNCTION p_shop_get_many_customer_sales_order ( - IN a_id_user INTEGER, - IN a_get_all_customer BOOLEAN, - IN a_get_inactive_customer BOOLEAN, - IN a_get_first_customer_only BOOLEAN, - IN a_ids_customer INTEGER[], - IN a_get_all_order BOOLEAN, - IN a_get_inactive_order BOOLEAN, - IN a_get_first_order_only BOOLEAN, - IN a_ids_order INTEGER[], - IN a_get_inactive_category BOOLEAN, - IN a_ids_category INTEGER[], - IN a_get_inactive_product BOOLEAN, - IN a_ids_product INTEGER[], - IN a_get_inactive_permutation BOOLEAN, - IN a_ids_permutation INTEGER[], - IN a_date_from TIMESTAMP, - IN a_date_to TIMESTAMP -) -RETURNS SETOF REFCURSOR -AS $$ -DECLARE - v_id_user INTEGER; - v_get_all_customer BOOLEAN; - v_get_inactive_customer BOOLEAN; - v_get_first_customer_only BOOLEAN; - v_ids_customer INTEGER[]; - v_get_all_order BOOLEAN; - v_get_inactive_order BOOLEAN; - v_get_first_order_only BOOLEAN; - v_ids_order INTEGER[]; - v_get_inactive_category BOOLEAN; - v_ids_category INTEGER[]; - v_get_inactive_product BOOLEAN; - v_ids_product INTEGER[]; - v_get_inactive_permutation BOOLEAN; - v_ids_permutation INTEGER[]; - v_date_from TIMESTAMP; - v_date_to TIMESTAMP; - -- Argument redeclaration - -- Variable declaration - v_has_filter_customer BOOLEAN; - v_has_filter_order BOOLEAN; - v_has_filter_category BOOLEAN; - v_has_filter_product BOOLEAN; - v_has_filter_permutation BOOLEAN; - v_has_filter_date_from BOOLEAN; - v_has_filter_date_to BOOLEAN; - v_guid UUID; - -- v_id_user VARCHAR(100); - -- v_ids_permutation_unavailable VARCHAR(4000); - v_ids_permission_customer_purchase_order VARCHAR(4000); - v_ids_product_permission VARCHAR(4000); - -- v_ids_permutation_permission VARCHAR(4000); - v_id_access_level_view INTEGER; - -- v_now TIMESTAMP; - -- v_id_minimum INTEGER; - v_code_error_data VARCHAR(50); - v_id_type_error_data INTEGER; - result_customers REFCURSOR; - result_orders REFCURSOR; - result_order_product_links REFCURSOR; - -- result_errors REFCURSOR; -BEGIN - v_id_user := TRIM(COALESCE(a_id_user, '')); - v_get_inactive_customer := COALESCE(a_get_inactive_customer, FALSE); - v_get_first_customer_only := COALESCE(a_get_first_customer_only, FALSE); - v_ids_customer := TRIM(COALESCE(a_ids_customer, '')); - v_get_all_customer := COALESCE(a_get_all_customer, CASE WHEN v_ids_customer = '' THEN TRUE ELSE FALSE END); - v_get_inactive_order := COALESCE(a_get_inactive_order, FALSE); - v_get_first_order_only := COALESCE(a_get_first_order_only, FALSE); - v_ids_order := TRIM(COALESCE(a_ids_order, '')); - v_get_all_order := COALESCE(a_get_all_order, CASE WHEN v_ids_order = '' THEN TRUE ELSE FALSE END); - v_get_inactive_category := COALESCE(a_get_inactive_category, FALSE); - v_ids_category := TRIM(COALESCE(a_ids_category, '')); - v_get_inactive_product := COALESCE(a_get_inactive_product, FALSE); - v_ids_product := TRIM(COALESCE(a_ids_product, '')); - v_get_inactive_permutation := COALESCE(a_get_inactive_permutation, FALSE); - v_ids_permutation := TRIM(COALESCE(a_ids_permutation, '')); - v_date_from := a_date_from; - v_date_to := a_date_to; - - v_guid := gen_random_uuid(); - v_id_access_level_view := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW' LIMIT 1); - -- v_ids_permission_customer_purchase_order := (SELECT id_permission FROM Shop_Permission WHERE code = 'Shop_Customer_Sales_ORDER' LIMIT 1); - v_code_error_data := 'BAD_DATA'; - v_id_type_error_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_data); - - v_has_filter_category := CASE WHEN a_ids_category = '' THEN FALSE ELSE TRUE END; - v_has_filter_product := CASE WHEN a_ids_product = '' THEN FALSE ELSE TRUE END; - v_has_filter_permutation := CASE WHEN a_ids_permutation = '' THEN FALSE ELSE TRUE END; - v_has_filter_date_from := CASE WHEN ISNULL(a_date_from) THEN FALSE ELSE TRUE END; - v_has_filter_date_to := CASE WHEN ISNULL(a_date_to) THEN FALSE ELSE TRUE END; - - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Shop_Customer_Sales_Order_Product_Link; - DROP TABLE IF EXISTS tmp_Shop_Customer_Sales_Order; - DROP TABLE IF EXISTS tmp_Shop_Customer; - DROP TABLE IF EXISTS tmp_Shop_Product; - - CREATE TABLE tmp_Shop_Customer ( - id_customer INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Customer_id_customer - FOREIGN KEY (id_customer) - REFERENCES Shop_Customer(id_customer), - active BOOLEAN NOT NULL, - rank_customer INTEGER NULL, - can_view BOOLEAN, - can_edit BOOLEAN, - can_admin BIT - ); - - CREATE TABLE tmp_Shop_Customer_Sales_Order ( - id_order INTEGER NOT NULL PRIMARY KEY, - /* - id_customer INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Customer_Sales_Order_id_customer - FOREIGN KEY (id_customer) - REFERENCES Shop_Customer(id_customer), - price_total_local REAL NOT NULL, - id_currency_price INTEGER NOT NULL, - */ - active BOOLEAN NOT NULL, - rank_order INTEGER NOT NULL - ); - - /* - CREATE TABLE tmp_Shop_Customer_Sales_Order_Product_Link ( - id_link INTEGER NOT NULL PRIMARY KEY, - id_order INTEGER NOT NULL, - CONSTRAINT FK_tmp_customer_Purchase_Order_Product_Link_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Customer_Sales_Order(id_order), - id_permutation INTEGER NOT NULL, - CONSTRAINT FK_tmp_customer_Purchase_Order_Product_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - price_total_local REAL NOT NULL, - id_currency_price INTEGER NOT NULL, - quantity_ordered REAL NOT NULL, - id_unit_quantity INTEGER NOT NULL, - CONSTRAINT FK_tmp_customer_Purchase_Order_Product_Link_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - quantity_received REAL NULL, - latency_delivery_days INTEGER NOT NULL, - display_order INTEGER NOT NULL - ); - */ - - CREATE TABLE tmp_Shop_Product ( - id_category INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_category - FOREIGN KEY (id_category) - REFERENCES Shop_Product_Category(id_category), - id_product INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - -- product_has_variations BOOLEAN NOT NULL, - id_permutation INTEGER NULL, - CONSTRAINT FK_tmp_Shop_Product_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - active_category BOOLEAN NOT NULL, - active_product BOOLEAN NOT NULL, - active_permutation BOOLEAN NULL, - display_order_category INTEGER NOT NULL, - display_order_product INTEGER NOT NULL, - display_order_permutation INTEGER NULL, - rank_permutation INTEGER NOT NULL, -- _in_category - -- name VARCHAR(255) NOT NULL, - -- description VARCHAR(4000) NOT NULL, - /* - price_GBP_full REAL NOT NULL, - price_GBP_min REAL NOT NULL, - */ - /* - latency_manufacture INTEGER NOT NULL, - quantity_min REAL NOT NULL, - quantity_max REAL NOT NULL, - quantity_step REAL NOT NULL, - quantity_stock REAL NOT NULL, - is_subscription BOOLEAN NOT NULL, - id_unit_measurement_interval_recurrence INTEGER, - CONSTRAINT FK_tmp_Shop_Product_id_unit_measurement_interval_recurrence - FOREIGN KEY (id_unit_measurement_interval_recurrence) - REFERENCES Shop_Interval_Recurrence(id_interval), - count_interval_recurrence INTEGER, - id_stripe_product VARCHAR(100), - product_has_variations INTEGER NOT NULL, - */ - can_view BOOLEAN, - can_edit BOOLEAN, - can_admin BIT - ); - - /* - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - guid UUID NOT NULL, - id_type INTEGER NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type (id_type), - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - */ - - -- select v_has_filter_product, v_has_filter_permutation; - - IF v_has_filter_customer = TRUE OR a_get_all_customer = TRUE THEN - IF EXISTS ( - SELECT * - FROM UNNEST(v_ids_customer) AS Customer_Id - LEFT JOIN Shop_Customer C ON Customer_Id = C.id_customer - WHERE ISNULL(C.id_customer) - LIMIT 1 - ) THEN - RAISE EXCEPTION 'Invalid customer IDs: %', ( - SELECT STRING_AGG(Customer_Id, ', ') - FROM UNNEST(v_ids_customer) AS Customer_Id - LEFT JOIN Shop_Customer C ON Customer_Id = C.id_customer - WHERE ISNULL(C.id_customer) - ) - USING ERRCODE = '22000' - ; - ELSE - INSERT INTO tmp_Shop_Customer ( - id_customer, - active, - rank_customer - ) - SELECT - C.id_customer, - C.active, - RANK() OVER (ORDER BY id_customer ASC) AS rank_customer - FROM Shop_Customer C - -- LEFT JOIN Split_Temp S_T ON C.id_customer = S_T.substring - WHERE - ( - a_get_all_customer = TRUE - -- OR NOT ISNULL(S_T.substring) - OR C.id_customer = ANY(v_ids_customer) - ) - AND ( - a_get_inactive_customer - OR C.active = TRUE - ) - ; - END IF; - - IF a_get_first_customer_only THEN - DELETE FROM tmp_Shop_Customer t_C - WHERE t_C.rank_customer > ( - SELECT MIN(t_C.rank_customer) - FROM tmp_Shop_Customer t_C - ) - ; - END IF; - END IF; - - IF v_has_filter_category = TRUE AND EXISTS ( - SELECT STRING_AGG(Category_Id, ', ') - FROM UNNEST(v_ids_category) AS Category_Id - LEFT JOIN Shop_Product_Category C ON Category_Id = C.id_customer - WHERE ISNULL(C.id_customer) - LIMIT 1 - ) THEN - RAISE EXCEPTION 'Invalid category IDs: %', ( - SELECT STRING_AGG(Category_Id, ', ') - FROM UNNEST(v_ids_category) AS Category_Id - LEFT JOIN Shop_Product_Category C ON Category_Id = C.id_customer - WHERE ISNULL(C.id_customer) - ) - USING ERRCODE = '22000' - ; - END IF; - - IF v_has_filter_product = TRUE AND EXISTS ( - SELECT * - FROM UNNEST(v_ids_product) AS Product_Id - LEFT JOIN Shop_Product P ON Product_Id = P.id_product - WHERE ISNULL(P.id_product) - LIMIT 1 - ) THEN - RAISE EXCEPTION 'Invalid product IDs: %', ( - SELECT COALESCE(STRING_AGG(Product_Id, ', ') ,'NULL') - FROM UNNEST(v_ids_product) AS Product_Id - LEFT JOIN Shop_Product P ON Product_Id = P.id_product - WHERE ISNULL(P.id_product) - ) - USING ERRCODE = '22000' - ; - END IF; - - IF v_has_filter_permutation = TRUE AND EXISTS ( - SELECT * - FROM UNNEST(v_ids_permutation) AS Permutation_Id - LEFT JOIN Shop_Product_Permutation PP ON Permutation_Id = PP.id_permutation - WHERE ISNULL(PP.id_permutation) - LIMIT 1 - ) THEN - RAISE EXCEPTION 'Invalid permutation IDs: %', ( - SELECT STRING_AGG(Permutation_Id, ', ') - FROM UNNEST(v_ids_permutation) AS Permutation_Id - LEFT JOIN Shop_Product_Permutation PP ON Permutation_Id = PP.id_permutation - WHERE ISNULL(PP.id_permutation) - ) - USING ERRCODE = '22000' - ; - END IF; - - IF v_has_filter_category = TRUE OR v_has_filter_product = TRUE OR v_has_filter_permutation = TRUE THEN - INSERT INTO tmp_Shop_Product ( - id_category, - id_product, - id_permutation, - active_category, - active_product, - active_permutation, - display_order_category, - display_order_product, - display_order_permutation - -- rank_permutation, - /* - name, - description, - /* - price_GBP_VAT_incl, - price_GBP_VAT_excl, - price_GBP_min, - */ - latency_manufacture, - quantity_min, - quantity_max, - quantity_step, - quantity_stock, - is_subscription, - id_unit_measurement_interval_recurrence, - count_interval_recurrence, - id_stripe_product, - product_has_variations - */ - ) - SELECT - P.id_category, - P.id_product, - -- P.has_variations AS product_has_variations, - PP.id_permutation, - C.active AS active_category, - P.active AS active_product, - PP.active AS active_permutation, - C.display_order AS display_order_category, - P.display_order AS display_order_product, - PP.display_order AS display_order_permutation - -- RANK() OVER (ORDER BY C.display_order, P.display_order, PP.display_order) AS rank_permutation, #PARTITION BY P.id_category -- _in_category - /* - P.name, - PP.description, - /* - PP.price_GBP_VAT_incl, - PP.price_GBP_VAT_excl, - PP.price_GBP_min, - */ - PP.latency_manufacture, - PP.quantity_min, - PP.quantity_max, - PP.quantity_step, - PP.quantity_stock, - PP.is_subscription, - PP.id_unit_measurement_interval_recurrence, - PP.count_interval_recurrence, - PP.id_stripe_product, - P.has_variations - */ - FROM Shop_Product P - INNER JOIN Shop_Product_Permutation PP - ON P.id_product = PP.id_product - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - WHERE - -- permutations - ( - ( - NOT v_has_filter_permutation - OR FIND_IN_SET(PP.id_permutation, a_ids_permutation) > 0 - ) - AND ( - a_get_inactive_permutation - OR PP.active = TRUE - ) - ) - -- categories - AND ( - ( - NOT v_has_filter_category - OR FIND_IN_SET(P.id_category, a_ids_category) > 0 - ) - AND ( - a_get_inactive_category - OR C.active = TRUE - ) - ) - -- products - AND ( - ( - NOT v_has_filter_product - OR FIND_IN_SET(P.id_product, a_ids_product) > 0 - ) - AND ( - a_get_inactive_product - OR P.active = TRUE - ) - ) - ; - END IF; - - -- Get orders - IF v_has_filter_order AND EXISTS ( - SELECT * - FROM UNNEST(v_ids_order) AS Order_Id - LEFT JOIN Shop_Customer_Sales_Order CSO ON Order_Id = CSO.id_order - WHERE ISNULL(CSO.id_order) - LIMIT 1 - ) THEN - RAISE EXCEPTION 'Invalid order IDs: %', ( - SELECT STRING_AGG(Order_Id, ', ') - FROM UNNEST(v_ids_order) AS Order_Id - LEFT JOIN Shop_Customer_Sales_Order CSO ON Order_Id = CSO.id_order - WHERE ISNULL(CSO.id_order) - ) - USING ERRCODE = '22000' - ; - END IF; - - INSERT INTO tmp_Shop_Customer_Sales_Order ( -- _Product_Link - id_order, - active, - rank_order - ) - SELECT - CSO.id_order, - CSO.active, - RANK() OVER (ORDER BY CSO.id_order ASC) AS rank_order - FROM Shop_Customer_Sales_Order CSO - -- LEFT JOIN Split_Temp S_T ON CSO.id_order = S_T.substring - INNER JOIN Shop_Customer_Sales_Order_Product_Link CSOPL ON CSO.id_order = CSOPL.id_order - INNER JOIN Shop_Customer S ON CSO.id_customer = S.id_customer - INNER JOIN Shop_Product_Permutation PP ON CSOPL.id_permutation = PP.id_permutation - INNER JOIN Shop_Product P ON PP.id_product = P.id_product - INNER JOIN Shop_Product_Category C ON P.id_category = C.id_category - LEFT JOIN tmp_Shop_Product t_P ON CSOPL.id_permutation = t_P.id_permutation - LEFT JOIN tmp_Shop_Customer t_S ON CSO.id_customer = t_S.id_customer - WHERE - -- customer - /* - ( - a_get_all_customer = 1 - OR NOT ISNULL(t_S.id_customer) -- CSO.id_customer IN (SELECT DISTINCT id_customer FROM tmp_Shop_Customer) - ) - */ - NOT ISNULL(t_S.id_customer) - -- order - AND ( - ( - a_get_all_order = 1 - OR ( - -- ID - -- FIND_IN_SET(CSO.id_order, a_ids_order) > 0 - -- NOT ISNULL(S_T.substring) - CSO.id_order = ANY(v_ids_order) - -- date - AND ( - ( - v_has_filter_date_from = 0 - OR CSO.created_on > a_date_from - ) - AND ( - v_has_filter_date_to = 0 - OR CSO.created_on < a_date_to - ) - ) - ) - ) - -- active - AND ( - a_get_inactive_order - OR CSO.active = TRUE - ) - ) - -- permutations - AND ( - ( - v_has_filter_category = FALSE - AND v_has_filter_product = FALSE - AND v_has_filter_permutation = 0 - ) - OR NOT ISNULL(t_P.id_permutation) -- CSO.id_permutation IN (SELECT DISTINCT id_permutation FROM tmp_Shop_Product) - ) - ; - - IF a_get_first_order_only THEN - DELETE FROM tmp_Shop_Customer_Sales_Order t_CSO - WHERE t_CSO.rank_order > ( - SELECT MIN(t_CSO.rank_order) - FROM tmp_Shop_Customer_Sales_Order t_CSO - ) - ; - END IF; - - -- Permissions - -- v_id_user := (SELECT id_user FROM Shop_User WHERE name = CURRENT_USER); - v_ids_permission_customer_purchase_order := (SELECT STRING_AGG(id_permission, ',') FROM Shop_Permission WHERE code IN ('STORE_customer', 'STORE_customer_PURCHASE_ORDER')); - -- v_ids_permutation_permission := (SELECT STRING_AGG(id_permutation, ',') FROM tmp_Shop_Product WHERE NOT ISNULL(id_permutation)); - v_ids_product_permission := (SELECT STRING_AGG(P.id_product, ',') FROM (SELECT DISTINCT id_product FROM tmp_Shop_Product WHERE NOT ISNULL(id_product)) P); - - -- SELECT v_guid, a_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_permutation_permission; - -- select * from Shop_Calc_User_Temp; - - CALL p_shop_calc_user(v_guid, a_id_user, FALSE, v_ids_permission_customer_purchase_order, v_id_access_level_view, v_ids_product_permission); - - -- select * from Shop_Calc_User_Temp; - - IF NOT EXISTS (SELECT can_view FROM Shop_Calc_User_Temp UE_T WHERE UE_T.GUID = v_guid) THEN - RAISE EXCEPTION 'You do not have view permissions for %', ( - SELECT COALESCE(STRING_AGG(name, ', '), 'NULL') - FROM Shop_Permission - WHERE id_permission = v_ids_permission_customer_purchase_order - ) - USING ERRCODE = '42501' - ; - END IF; - - - UPDATE tmp_Shop_Product t_P - SET t_P.can_view = UE_T.can_view, - t_P.can_edit = UE_T.can_edit, - t_P.can_admin = UE_T.can_admin - FROM tmp_Shop_Product t_P - INNER JOIN Shop_Calc_User_Temp UE_T - ON t_P.id_product = UE_T.id_product -- t_P.id_permutation = UE_T.id_permutation - AND UE_T.GUID = v_guid - ; - - -- CALL p_shop_clear_calc_user(v_guid); - -- DROP TABLE IF EXISTS Shop_Calc_User_Temp; - DELETE FROM Shop_Calc_User_Temp - WHERE GUID = v_guid - ; - - - -- select * from tmp_Shop_Customer; - -- select * from tmp_Shop_Product; - - -- Returns - -- v_now := CURRENT_TIMESTAMP; - - -- customers - OPEN result_customers FOR - SELECT - t_S.id_customer, - S.name_company, - S.name_contact, - S.department_contact, - S.id_address, - S.phone_number, - S.email, - S.id_currency, - t_S.active - FROM tmp_Shop_Customer t_S - INNER JOIN Shop_Customer S - ON t_S.id_customer = S.id_customer - ; - RETURN NEXT result_customers; - - -- Customer Sales Order - OPEN result_orders FOR - SELECT -- * - t_CSO.id_order, - CSO.id_customer, - CSO.price_total_local, - CSO.id_currency_price, - t_CSO.active - FROM Shop_Customer_Sales_Order CSO - INNER JOIN tmp_Shop_Customer_Sales_Order t_CSO ON CSO.id_order = t_CSO.id_order - ; - RETURN NEXT result_orders; - - -- Customer Sales Order Product Link - OPEN result_order_product_links FOR - SELECT - CSOPL.id_link, - CSOPL.id_order, - CSOPL.id_permutation, - P.name as name_product, - CSOPL.price_total_local, - CSOPL.id_currency_price, - CSOPL.quantity_ordered, - CSOPL.id_unit_quantity, - CSOPL.quantity_delivered, - CSOPL.latency_delivery_days, - CSOPL.display_order - FROM Shop_Customer_Sales_Order_Product_Link CSOPL - -- INNER JOIN tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL ON CSOPL.id_link = t_CSOPL.id_link - INNER JOIN tmp_Shop_Customer_Sales_Order t_CSO ON CSOPL.id_order = t_CSO.id_order - INNER JOIN Shop_Product_Permutation PP ON CSOPL.id_permutation = PP.id_permutation - INNER JOIN Shop_Product P ON PP.id_product = P.id_product - INNER JOIN Shop_Product_Category C ON P.id_category = C.id_category - ORDER BY CSOPL.id_order, C.display_order, P.display_order, PP.display_order - ; - RETURN NEXT result_order_product_links; - - -- Errors - /* - SELECT - /* - t_ME.display_order, - t_ME.guid, - t_ME.id_type, - t_ME.msg, - MET.code, - MET.name, - MET.description - */ - * - FROM tmp_Msg_Error t_ME - INNER JOIN Shop_Msg_Error_Type MET - ON t_ME.id_type = MET.id_type - WHERE guid = v_guid - ; - OPEN result_errors FOR - SELECT * - FROM tmp_Msg_Error - ; - -- RETURN NEXT result_errors; - */ - - /* - -- Return arguments for test - SELECT - a_ids_category, - a_get_inactive_category, - a_ids_product, - a_get_inactive_product, - a_get_first_product_only, - a_get_all_product, - a_ids_image, - a_get_inactive_image, - a_get_first_image_only, - a_get_all_image - ; - */ - - -- select 'other outputs'; - -- select * from tmp_Shop_Product; - - -- Clean up - DROP TABLE IF EXISTS tmp_Shop_Customer_Sales_Order_Product_Link; - DROP TABLE IF EXISTS tmp_Shop_Customer_Sales_Order; - DROP TABLE IF EXISTS tmp_Shop_Customer; - DROP TABLE IF EXISTS tmp_Shop_Product; - - DELETE FROM Shop_Calc_User_Temp - WHERE GUID = v_guid - ; -END; -$$ LANGUAGE plpgsql; - - -/* - - -DROP FUNCTION IF EXISTS fetch_results; - -CREATE OR REPLACE FUNCTION fetch_results() -RETURNS VOID AS $$ -DECLARE - curs refcursor; - rec record; -BEGIN - FOR curs IN SELECT p_shop_get_many_customer_sales_order ( - '', -- a_id_user - 1, -- a_get_all_customer - 0, -- a_get_inactive_customer - 0, -- a_get_first_customer_only - '', -- a_ids_customer - 1, -- a_get_all_order - 0, -- a_get_inactive_order - 0, -- a_get_first_order_only - '', -- a_ids_order - 0, -- a_get_inactive_category - '', -- a_ids_category - 0, -- a_get_inactive_product - '', -- a_ids_product - 0, -- a_get_inactive_permutation - '', -- a_ids_permutation - NULL, -- a_date_from - NULL -- a_date_to - ) LOOP - RAISE NOTICE 'Fetching from cursor: %', curs; - LOOP - FETCH curs INTO rec; - EXIT WHEN NOT FOUND; - RAISE NOTICE 'Record: %', rec; - END LOOP; - END LOOP; -END; -$$ LANGUAGE plpgsql; - -SELECT fetch_results(); - -*/ - - - -DO $$ -BEGIN - RAISE NOTICE 'PROCEDURE CREATION COMPLETE'; -END $$; - -/* - -CALL p_populate_database () - -*/ - -/* --- Remove previous proc -DROP PROCEDURE IF EXISTS p_populate_database; - - -DELIMITER // -CREATE OR REPLACE PROCEDURE p_populate_database () -BEGIN -*/ - - --- Access Levels -INSERT INTO Shop_Access_Level ( - display_order, code, name, priority -) -VALUES - (1, 'VIEW', 'View', 3), - (2, 'EDIT', 'Edit', 2), - (3, 'ADMIN', 'Admin', 1) -; - --- Error Message Types -INSERT INTO Shop_Msg_Error_Type ( - code, name, description -) -VALUES - ('BAD_DATA', 'Invalid data', 'Rubbish data'), - ('NO_PERMISSION', 'No permission', 'Not authorised'), - ('PRODUCT_AVAILABILITY', 'Product not available', 'Product not available') -; - --- File Types -INSERT INTO File_Type ( - code, name, extension -) -VALUES - ('JPEG', 'Joint Photographic Export Group', 'jpg'), - ('PNG', 'Portable Network Graphic', 'png'), - ('GIF', 'GIF', 'gif'), - ('MPEG-4', 'Multimedia Photographic Export Group 4', 'mp4') -; - --- Generic / shared properties -INSERT INTO Shop_General ( - quantity_max -) -VALUES ( - 10 -); - --- Categories -INSERT INTO Shop_Product_Category ( - display_order, - code, - name, - description -) -VALUES - (1, 'ASS', 'Assistive Devices', 'Braille product line and other assistive devices'), - (99, 'MISC', 'Miscellaneous', 'Not category allocated products'), - (2, 'TECH', 'Technology', 'Technological devices') -; - --- Recurrence Interval -INSERT INTO Shop_Interval_Recurrence ( - code, name, name_plural -) -VALUES - ('WEEK', 'Week', 'Weeks'), - ('MONTH', 'Month', 'Months'), - ('YEAR', 'Year', 'Years') -; - -INSERT INTO Shop_Region ( - display_order, code, name -) -VALUES - (1, 'UK', 'United Kingdom') -; - -/* -INSERT INTO Shop_Region_Branch ( - display_order, id_region_parent, id_region_child -) -VALUES - (1, 1, 2) -; -*/ - --- Currency -INSERT INTO Shop_Currency ( - display_order, code, name, symbol, factor_from_GBP -) -VALUES - (1, 'GBP', 'Great British Pound', '£', 1), - (2, 'EUR', 'Euro', '€', 1.17) -; - --- Taxes and Surcharges -INSERT INTO Shop_Tax_Or_Surcharge ( - display_order, - code, - name, - id_region_buyer, - id_region_seller, - fixed_fee, - multiplier, - apply_fixed_fee_before_multiplier, - quantity_min, - quantity_max -) -VALUES - (1, 'VAT', 'Value Added Tax', 1, 1, 0, 0.2, TRUE, 0, 1) -; - --- Products -INSERT INTO Shop_Product ( - display_order, - id_category, - name, - has_variations, - id_access_level_required -) -VALUES - ( - 1, - 1, - 'Braille Keyboard Translator', - TRUE, - 3 - ), - ( - 2, - 2, - 'Test product 1', - FALSE, - 3 - ), - ( - 3, - 3, - 'Phone', - FALSE, - 1 - ), - ( - 4, - 3, - 'Laptop', - FALSE, - 1 - ), - ( - 5, - 3, - 'Smart Watch', - FALSE, - 1 - ) -; - --- Variation Types -INSERT INTO Shop_Variation_Type ( - display_order, code, name, name_plural -) -VALUES - (1, 'COLOUR', 'Colour', 'Colours') -; - --- Variations -INSERT INTO Shop_Variation ( - display_order, id_type, code, name -) -VALUES - (1, 1, 'RED', 'Red'), - (2, 1, 'BLUE', 'Blue') -; - --- Product Permutations -INSERT INTO Shop_Product_Permutation ( - display_order, - id_product, - description, - cost_local, - id_currency_cost, - profit_local_min, - -- id_currency_profit_min, - latency_manufacture, - quantity_min, - quantity_max, - quantity_step, - quantity_stock, - is_subscription, - id_unit_measurement_interval_recurrence, - count_interval_recurrence, - -- id_access_level_required, - id_stripe_product -) -VALUES - ( - 1, - 1, - 'Good Red', - 5, - 1, - 3, - -- 1, - 14, - 1, - 3, - 1, - 99, - FALSE, - NULL, - NULL, - -- 1, - NULL - ), - ( - 2, - 1, - 'Good Blue', - 6, - 1, - 4, - -- 1, - 14, - 1, - 3, - 1, - 99, - FALSE, - NULL, - NULL, - -- 1, - NULL - ), - ( - 3, - 2, - 'Test product describes good', - 10, - 1, - 5, - -- 1, - 14, - 1, - 2, - 1, - 99, - FALSE, - NULL, - NULL, - -- 1, - NULL - ), - ( - 4, - 3, - 'Phone describes good', - 10, - 1, - 5, - -- 1, - 14, - 1, - 2, - 1, - 99, - FALSE, - NULL, - NULL, - -- 1, - NULL - ), - ( - 5, - 4, - 'Laptop describes good', - 10, - 1, - 5, - -- 1, - 14, - 1, - 2, - 1, - 99, - FALSE, - NULL, - NULL, - -- 1, - NULL - ), - ( - 6, - 5, - 'Smart watch describes good', - 10, - 1, - 5, - -- 1, - 14, - 1, - 2, - 1, - 99, - FALSE, - NULL, - NULL, - -- 1, - NULL - ) -; - --- Product Permutation Variation Links -INSERT INTO Shop_Product_Permutation_Variation_Link ( - display_order, id_permutation, id_variation -) -VALUES - (1, 1, 1), - (2, 2, 2) -; - --- Product Currency Link -INSERT INTO Shop_Product_Currency_Region_Link ( - id_product, id_permutation, id_currency, id_region_purchase, price_local_VAT_incl, price_local_VAT_excl -) -VALUES - (1, 1, 1, 1, 24, 20), - (1, 1, 2, 1, 48, 40), - (1, 2, 1, 1, 96, 80), - (2, 3, 1, 1, 144, 120), - (3, 4, 1, 1, 600, 500), - (4, 5, 1, 1, 1500, 1200), - (5, 6, 1, 1, 180, 150) -; - -INSERT INTO Shop_Image_Type ( - display_order, code, name, name_plural -) -VALUES - (1, 'FULL', 'Full Quality Image', 'Full Quality Images'), - (2, 'LOW', 'Low Quality Image', 'Low Quality Images'), - (3, 'THUMBNAIL', 'Thumbnail Image', 'Thumbnail Images') -; - -INSERT INTO Shop_Image ( - display_order, id_product, id_permutation, id_type_image, id_type_file, url -) -VALUES - (1, 1, 1, 1, 1, '/static/images/prod_PB0NUOSEs06ymG.jpg'), - -- (1, NULL, 1, 1, 1, '/static/images/prod_PB0NUOSEs06ymG.jpg'), - (2, 1, 2, 1, 1, '/static/images/prod_PB0NUOSEs06ymG.jpg'), - -- (1, NULL, 2, 1, 1, '/static/images/prod_PB0NUOSEs06ymG.jpg') - (3, 2, 3, 1, 1, '/static/images/prod_PB0NUOSEs06ymG.jpg'), - (4, 3, 4, 1, 1, '/static/images/prod_.jpg'), - (5, 4, 5, 1, 1, '/static/images/prod_1.jpg'), - (6, 5, 6, 1, 1, '/static/images/prod_2.jpg') -; - -INSERT INTO Shop_Delivery_Option ( - display_order, code, name, latency_delivery_min, latency_delivery_max, quantity_min, quantity_max -) -VALUES - (1, 'COLLECT', 'Collection', 0, 0, 0, 1), - (2, 'SIGNED_1', 'First Class Signed-For', 2, 4, 0, 1) -; - -INSERT INTO Shop_Product_Permutation_Delivery_Option_Link ( - display_order, id_product, id_permutation, id_delivery_option, id_region, id_currency, price_local -) -VALUES - (1, 1, 1, 1, 1, 1, 5), - (2, 1, 2, 1, 1, 1, 9), - (3, 2, NULL, 1, 1, 1, 10), - (4, 3, 4, 1, 1, 1, 10), - (5, 4, 5, 1, 1, 1, 10), - (6, 5, 6, 1, 1, 1, 10) -; - --- Discounts -INSERT INTO Shop_Discount ( - id_product, - id_permutation, - code, - name, - multiplier, - quantity_min, - quantity_max, - date_start, - date_end, - display_order -) -VALUES - (1, 1, 'CRIMBO50', 'Christmas 50% off sale!', 0.5, 3, 9, CURRENT_TIMESTAMP, '2023-12-31 23:59:59', 1), - (1, 2, 'CRIMBO50', 'Christmas 50% off sale!', 0.5, 3, 9, CURRENT_TIMESTAMP, '2023-12-31 23:59:59', 1) -; - --- Discount Delivery Region Links -INSERT INTO Shop_Discount_Region_Currency_Link ( - id_discount, - id_region, - id_currency -) -VALUES - (1, 1, 1), - (2, 1, 1), - (1, 1, 2), - (2, 1, 2) -; - --- Permission Groups -INSERT INTO Shop_Permission_Group ( - display_order, code, name -) -VALUES - (0, 'ADMIN', 'Website Admin'), - (1, 'HOME', 'Home, Contact Us, and other public information'), - (2, 'PRODUCT', 'Store Products'), - (3, 'USER', 'Store User'), - (4, 'SALES_AND_PURCHASING', 'Sales and Purchasing'), - (5, 'MANUFACTURING', 'Manufacturing') -; - --- Permissions -INSERT INTO Shop_Permission ( - display_order, code, name, id_permission_group, id_access_level_required -) -VALUES - (1, 'HOME', 'Home Page', 2, 1), - (2, 'STORE_PRODUCT', 'Store Product Page', 3, 1), - (3, 'STORE_USER', 'Store User Account Page', 4, 2), - (4, 'STORE_ADMIN', 'Store Admin Page', 1, 3), - (5, 'STORE_SUPPLIER', 'Store Supplier Page', 4, 2), - (6, 'STORE_SUPPLIER_PURCHASE_ORDER', 'Store Supplier Purchase Order Page', 4, 2), - (7, 'STORE_MANUFACTURING_PURCHASE_ORDER', 'Store Manufacturing Purchase Order Page', 5, 2), - (8, 'STORE_CUSTOMER', 'Store Customer Page', 4, 2), - (9, 'STORE_CUSTOMER_SALES_ORDER', 'Store Customer Sales Order Page', 4, 2), - (99, 'CONTACT_US', 'Contact Us Page', 2, 1) -; - --- Roles -INSERT INTO Shop_Role ( - display_order, - code, - name -) -VALUES - (1, 'DIRECTOR', 'Director'), - (2, 'USER', 'User') -; - --- Role Permission link -INSERT INTO Shop_Role_Permission_Link ( - id_role, id_permission, id_access_level -) -VALUES - (1, 1, 3), - (1, 2, 3), - (1, 3, 3), - (1, 4, 3), - (1, 5, 3), - (2, 1, 1), - (2, 2, 1), - (2, 3, 1), - (2, 4, 1), - (2, 5, 1) -; - --- Users -INSERT INTO Shop_User ( - id_user_oauth, - name, - email, - -- is_email_verified, - is_super_user -) -VALUES - ('auth0|6582b95c895d09a70ba10fef', 'Teddy', 'edward.middletonsmith@gmail.com', TRUE), - ('parts_guest', 'Guest', '', FALSE) -; - --- User Role link -INSERT INTO Shop_User_Role_Link ( - id_user, id_role -) -VALUES - (1, 1) -; - --- Addresses -INSERT INTO Shop_Address ( - -- id_user, - id_region, name_full, phone_number, postcode, address_line_1, address_line_2, city, county -) -VALUES (1, 'Edward M-S', '07375 571430', 'CV22 6DN', '53 Alfred Green Close', '', 'Rugby', 'Warwickshire') -/* -SELECT U.id_user, 1, U.name, '07375 571430', 'CV22 6DN', '53 Alfred Green Close', '', 'Rugby', 'Warwickshire' - FROM Shop_User U -*/ -; - --- User Basket -INSERT INTO Shop_User_Basket ( - id_user, - id_product, - id_permutation, - quantity -) -VALUES - (1, 1, 1, 69) -; - --- User Order Status -INSERT INTO Shop_User_Order_Status ( - display_order, code, name, name_plural -) -VALUES - (1, 'SUCCESS', 'Success', 'Successes'), - (2, 'FAIL', 'Failure', 'Failures') -; - -/* --- User Order -INSERT INTO Shop_User_Order ( - id_user, value_total, id_order_status, id_checkout_session, id_currency -) -VALUES - (1, 25, 1, 'noods', 1), - (1, 25, 1, 'noods', 1) -; - --- User Order Product Link -INSERT INTO Shop_User_Order_Product_Link ( - id_order, id_product, id_permutation, quantity -) -VALUES - (1, 1, 1, 69), - (1, 2, NULL, 69), - (1, 1, 2, 69) -; -*/ - --- Supplier -INSERT INTO Shop_Supplier ( - name_company, name_contact, department_contact, id_address, phone_number, fax, email, website, id_currency -) -VALUES - ('Precision And Research Technology Systems Limited', 'Teddy Middleton-Smith', 'Executive Management', 1, '07375571430', '', 'teddy@partsltd.co.uk', 'www.partsltd.co.uk', 1) -; - --- Unit of Measurement -INSERT INTO Shop_Unit_Measurement ( - name_singular, name_plural, symbol, is_base_unit -) -VALUES - ('metre', 'metres', 'm', TRUE), - ('kilogram', 'kilograms', 'kg', TRUE), - ('item', 'items', 'x', FALSE) -; - -/* --- Unit of Measurement Conversion -INSERT INTO Shop_Unit_Measurement_Conversion ( - id_unit_derived, id_unit_base, power_unit_base, multiplier_unit_base, increment_unit_base -) -VALUES - -; -*/ - -/* --- Supplier Purchase Order -INSERT INTO Shop_Supplier_Purchase_Order ( - id_supplier, value_total, id_order_status, id_checkout_session, id_currency -) -VALUES -; - --- Supplier Purchase Order Product Link -INSERT INTO Shop_Supplier_Purchase_Order_Product_Link ( - id_order, id_permutation, cost_total_local, id_currency_cost, quantity_ordered, id_unit_quantity, quantity_received, latency_delivery, display_order -) -VALUES -; -*/ - -/* --- Manufacturing Purchase Order -INSERT INTO Shop_Manufacturing_Purchase_Order ( - cost_total_local, id_currency_cost -) -VALUES -; - --- Manufacturing Purchase Order Product Link -INSERT INTO Shop_Manufacturing_Purchase_Order_Product_Link ( - id_order, id_permutation, cost_total_local, id_currency_cost, quantity_used, id_unit_quantity, quantity_produced, latency_manufacturing_days, display_order -) -VALUES -; -*/ - -/* --- Customer -INSERT INTO Shop_Customer ( - name_company, name_contact, department_contact, id_address, phone_number, email, id_currency -) -VALUES - -; -*/ - -/* --- Customer Sales Order -INSERT INTO Shop_Customer_Sales_Order ( - cost_total_local, id_currency_cost -) -VALUES -; - --- Customer Sales Order Product Link -INSERT INTO Shop_Customer_Sales_Order_Product_Link ( - id_order, id_permutation, cost_total_local, id_currency_cost, quantity_ordered, id_unit_quantity, quantity_delivered, latency_delivery_days, display_order -) -VALUES -; -*/ - - -/* - -- Clean up -END // -DELIMITER ;; - - --- Call -CALL p_populate_database(); - --- Remove proc -DROP PROCEDURE IF EXISTS p_populate_database; -*/ - -DO $$ -BEGIN - RAISE NOTICE 'TABLE POPULATION COMPLETE'; -END $$; - --- Product Change Sets -SELECT * FROM Shop_Product_Change_Set; - --- User Change Sets -SELECT * FROM Shop_User_Change_Set; - --- Access Levels -SELECT * FROM Shop_Access_Level; -SELECT * FROM Shop_Access_Level_Audit; - --- Error Message type -SELECT * FROM Shop_Msg_Error_Type; - --- File Types -SELECT * FROM File_Type; -SELECT * FROM File_Type_Audit; - --- Generic / shared properties -SELECT * FROM Shop_General; -SELECT * FROM Shop_General_Audit; - --- Categories -SELECT * FROM Shop_Product_Category; -SELECT * FROM Shop_Product_Category_Audit; - --- Recurrence Interval -SELECT * FROM Shop_Interval_Recurrence; -SELECT * FROM Shop_Interval_Recurrence_Audit; - --- Region -SELECT * FROM Shop_Region; -SELECT * FROM Shop_Region_Audit; - --- Region Branch -SELECT * FROM Shop_Region_Branch; -SELECT * FROM Shop_Region_Branch_Audit; - --- Currency -SELECT * FROM Shop_Currency; -SELECT * FROM Shop_Currency_Audit; - --- Taxes and Surcharges -SELECT * FROM Shop_Tax_Or_Surcharge; -SELECT * FROM Shop_Tax_Or_Surcharge_Audit; - --- Products -SELECT * FROM Shop_Product; -SELECT * FROM Shop_Product_Audit; - --- Variation Types -SELECT * FROM Shop_Variation_Type; -SELECT * FROM Shop_Variation_Type_Audit; - --- Variations -SELECT * FROM Shop_Variation; -SELECT * FROM Shop_Variation_Audit; - --- Permutations -SELECT * FROM Shop_Product_Permutation; -SELECT * FROM Shop_Product_Permutation_Audit; - --- Permutation Variation Links -SELECT * FROM Shop_Product_Permutation_Variation_Link; -SELECT * FROM Shop_Product_Permutation_Variation_Link_Audit; - --- Product Currency Links -SELECT * FROM Shop_Product_Currency_Region_Link; -SELECT * FROM Shop_Product_Currency_Region_Link_Audit; - --- Image Types -SELECT * FROM Shop_Image_Type; -SELECT * FROM Shop_Image_Type_Audit; - --- Images -SELECT * FROM Shop_Image; -SELECT * FROM Shop_Image_Audit; - --- Delivery Option Types -SELECT * FROM Shop_Delivery_Option; -SELECT * FROM Shop_Delivery_Option_Audit; - --- Delivery Options -SELECT * FROM Shop_Product_Permutation_Delivery_Option_Link; -SELECT * FROM Shop_Product_Permutation_Delivery_Option_Link_Audit; - --- Discounts -SELECT * FROM Shop_Discount; -SELECT * FROM Shop_Discount_Audit; - --- Discount Delivery Region Links -SELECT * FROM Shop_Discount_Region_Currency_Link; -SELECT * FROM Shop_Discount_Region_Currency_Link_Audit; - - --- Permission Groups -SELECT * FROM Shop_Permission_Group; -SELECT * FROM Shop_Permission_Group_Audit; - --- Permissions -SELECT * FROM Shop_Permission; -SELECT * FROM Shop_Permission_Audit; - --- Roles -SELECT * FROM Shop_Role; -SELECT * FROM Shop_Role_Audit; - --- Role Permission link -SELECT * FROM Shop_Role_Permission_Link; -SELECT * FROM Shop_Role_Permission_Link_Audit; - --- Users -SELECT * FROM Shop_User; -SELECT * FROM Shop_User_Audit; - --- User Role link -SELECT * FROM Shop_User_Role_Link; -SELECT * FROM Shop_User_Role_Link_Audit; - - --- Addresses -SELECT * FROM Shop_Address; -SELECT * FROM Shop_Address_Audit; - --- Basket -SELECT * FROM Shop_User_Basket; -SELECT * FROM Shop_User_Basket_Audit; - --- Order Statuses -SELECT * FROM Shop_User_Order_Status; -SELECT * FROM Shop_User_Order_Status_Audit; - -/* --- Orders -SELECT * FROM Shop_User_Order; -SELECT * FROM Shop_User_Order_Audit; - --- Order Products -SELECT * FROM Shop_User_Order_Product_Link; -SELECT * FROM Shop_User_Order_Product_Link_Audit; -*/ - --- Supplier -SELECT * FROM Shop_Supplier; -SELECT * FROM Shop_Supplier_Audit; - --- Unit Of Measurement -SELECT * FROM Shop_Unit_Measurement; -SELECT * FROM Shop_Unit_Measurement_Audit; - --- Unit of Measurement Conversion -SELECT * FROM Shop_Unit_Measurement_Conversion; -SELECT * FROM Shop_Unit_Measurement_Conversion_Audit; - --- Supplier Purchase Order -SELECT * FROM Shop_Supplier_Purchase_Order; -SELECT * FROM Shop_Supplier_Purchase_Order_Audit; - --- Supplier Purchase Order Product Link -SELECT * FROM Shop_Supplier_Purchase_Order_Product_Link; -SELECT * FROM Shop_Supplier_Purchase_Order_Product_Link_Audit; - --- Manufacturing Purchase Order -SELECT * FROM Shop_Manufacturing_Purchase_Order; -SELECT * FROM Shop_Manufacturing_Purchase_Order_Audit; - --- Manufacturing Purchase Order Product Link -SELECT * FROM Shop_Manufacturing_Purchase_Order_Product_Link; -SELECT * FROM Shop_Manufacturing_Purchase_Order_Product_Link_Audit; - --- Customers -SELECT * FROM Shop_Customer; -SELECT * FROM Shop_Customer_Audit; - --- Customer Sales Order -SELECT * FROM Shop_Customer_Sales_Order; -SELECT * FROM Shop_Customer_Sales_Order_Audit; - --- Customer Sales Order Product Link -SELECT * FROM Shop_Customer_Sales_Order_Product_Link; -SELECT * FROM Shop_Customer_Sales_Order_Product_Link_Audit; - diff --git a/static/PostgreSQL/001_destroy.sql b/static/PostgreSQL/001_destroy.sql deleted file mode 100644 index da1807be..00000000 --- a/static/PostgreSQL/001_destroy.sql +++ /dev/null @@ -1,293 +0,0 @@ - -/* Clear Store DataBase */ - - - --- Drop dependencies -DROP TABLE IF EXISTS Shop_Calc_User_Temp; -DROP TABLE IF EXISTS tmp_Msg_Error; -DROP TABLE IF EXISTS tmp_Currency; -DROP TABLE IF EXISTS tmp_Delivery_Region; -DROP TABLE IF EXISTS tmp_Region; -DROP TABLE IF EXISTS tmp_Shop_User; -DROP TABLE IF EXISTS tmp_Shop_Order; -DROP TABLE IF EXISTS tmp_Shop_Product; -DROP TABLE IF EXISTS tmp_Shop_Product_p_shop_calc_user; -DROP TABLE IF EXISTS tmp_Shop_Image; -DROP TABLE IF EXISTS tmp_Shop_Variation; -DROP TABLE IF EXISTS tmp_Shop_Discount; -DROP TABLE IF EXISTS tmp_Discount; -DROP TABLE IF EXISTS tmp_Shop_Product_Category; -DROP TABLE IF EXISTS tmp_Shop_Product_Currency_Region_Link; -DROP TABLE IF EXISTS tmp_Shop_Product_Currency_Link; -DROP TABLE IF EXISTS tmp_User_Role_Link; -DROP TABLE IF EXISTS tmp_Shop_Basket; -DROP TABLE IF EXISTS tmp_Shop_Supplier_Purchase_Order_Product_Link; -DROP TABLE IF EXISTS tmp_Shop_Supplier_Purchase_Order; -DROP TABLE IF EXISTS tmp_Shop_Supplier; -DROP TABLE IF EXISTS tmp_Shop_Manufacturing_Purchase_Order_Product_Link; -DROP TABLE IF EXISTS tmp_Shop_Manufacturing_Purchase_Order; -DROP TABLE IF EXISTS tmp_Shop_Customer; - - - --- Delete old tables -DROP TABLE IF EXISTS Shop_Customer_Sales_Order_Product_Link_Temp; -DROP TABLE IF EXISTS Shop_Customer_Sales_Order_Product_Link_Audit; -DROP TABLE IF EXISTS Shop_Customer_Sales_Order_Product_Link; - -DROP TABLE IF EXISTS Shop_Customer_Sales_Order_Audit; -DROP TABLE IF EXISTS Shop_Customer_Sales_Order; - -DROP TABLE IF EXISTS Shop_Customer_Audit; -DROP TABLE IF EXISTS Shop_Customer; - -DROP TABLE IF EXISTS Shop_Manufacturing_Purchase_Order_Product_Link_Temp; -DROP TABLE IF EXISTS Shop_Manufacturing_Purchase_Order_Product_Link_Audit; -DROP TABLE IF EXISTS Shop_Manufacturing_Purchase_Order_Product_Link; - -DROP TABLE IF EXISTS Shop_Manufacturing_Purchase_Order_Audit; -DROP TABLE IF EXISTS Shop_Manufacturing_Purchase_Order; - -DROP TABLE IF EXISTS Shop_Supplier_Purchase_Order_Product_Link_Temp; -DROP TABLE IF EXISTS Shop_Supplier_Purchase_Order_Product_Link_Audit; -DROP TABLE IF EXISTS Shop_Supplier_Purchase_Order_Product_Link; - -DROP TABLE IF EXISTS Shop_Supplier_Purchase_Order_Audit; -DROP TABLE IF EXISTS Shop_Supplier_Purchase_Order; - -DROP TABLE IF EXISTS Shop_Unit_Measurement_Conversion_Audit; -DROP TABLE IF EXISTS Shop_Unit_Measurement_Conversion; - -DROP TABLE IF EXISTS Shop_Unit_Measurement_Audit; -DROP TABLE IF EXISTS Shop_Unit_Measurement; - -DROP TABLE IF EXISTS Shop_Supplier_Audit; -DROP TABLE IF EXISTS Shop_Supplier; - -DROP TABLE IF EXISTS Shop_User_Order_Product_Link_Audit; -DROP TABLE IF EXISTS Shop_User_Order_Product_Link; - -DROP TABLE IF EXISTS Shop_User_Order_Audit; -DROP TABLE IF EXISTS Shop_User_Order; - -DROP TABLE IF EXISTS Shop_User_Order_Status_Audit; -DROP TABLE IF EXISTS Shop_User_Order_Status; - -DROP TABLE IF EXISTS Shop_User_Basket_Audit; -DROP TABLE IF EXISTS Shop_User_Basket; - -DROP TABLE IF EXISTS Shop_Address_Audit; -DROP TABLE IF EXISTS Shop_Address; - -DROP TABLE IF EXISTS Shop_User_Role_Link_Audit; -DROP TABLE IF EXISTS Shop_User_Role_Link; - -DROP TABLE IF EXISTS Shop_User_Audit; -DROP TABLE IF EXISTS Shop_User; - -DROP TABLE IF EXISTS Shop_Role_Permission_Link_Audit; -DROP TABLE IF EXISTS Shop_Role_Permission_Link; - -DROP TABLE IF EXISTS Shop_Role_Audit; -DROP TABLE IF EXISTS Shop_Role; - -DROP TABLE IF EXISTS Shop_Permission_Audit; -DROP TABLE IF EXISTS Shop_Permission; - -DROP TABLE IF EXISTS Shop_Permission_Group_Audit; -DROP TABLE IF EXISTS Shop_Permission_Group; - - -DROP TABLE IF EXISTS Shop_Discount_Region_Currency_Link_Audit; -DROP TABLE IF EXISTS Shop_Discount_Region_Currency_Link; - -DROP TABLE IF EXISTS Shop_Discount_Audit; -DROP TABLE IF EXISTS Shop_Discount; - -DROP TABLE IF EXISTS Shop_Product_Permutation_Delivery_Option_Link_Audit; -DROP TABLE IF EXISTS Shop_Product_Permutation_Delivery_Option_Link; - -DROP TABLE IF EXISTS Shop_Delivery_Option_Audit; -DROP TABLE IF EXISTS Shop_Delivery_Option; - -DROP TABLE IF EXISTS Shop_Image_Audit; -DROP TABLE IF EXISTS Shop_Image; - -DROP TABLE IF EXISTS Shop_Image_Type_Audit; -DROP TABLE IF EXISTS Shop_Image_Type; - -DROP TABLE IF EXISTS Shop_Product_Currency_Region_Link_Audit; -DROP TABLE IF EXISTS Shop_Product_Currency_Region_Link; -DROP TABLE IF EXISTS Shop_Product_Currency_Link_Audit; -DROP TABLE IF EXISTS Shop_Product_Currency_Link; - -DROP TABLE IF EXISTS Shop_Product_Variation_Link_Audit; -DROP TABLE IF EXISTS Shop_Product_Variation_Link; -DROP TABLE IF EXISTS Shop_Product_Permutation_Variation_Link_Audit; -DROP TABLE IF EXISTS Shop_Product_Permutation_Variation_Link; - -DROP TABLE IF EXISTS Shop_Product_Permutation_Audit; -DROP TABLE IF EXISTS Shop_Product_Permutation; - -DROP TABLE IF EXISTS Shop_Variation_Audit; -DROP TABLE IF EXISTS Shop_Variation; -DROP TABLE IF EXISTS Shop_Product_Variation_Type_Link_Audit; -DROP TABLE IF EXISTS Shop_Product_Variation_Type_Link; - -DROP TABLE IF EXISTS Shop_Variation_Type_Audit; -DROP TABLE IF EXISTS Shop_Variation_Type; - -DROP TABLE IF EXISTS Shop_Product_Audit; -DROP TABLE IF EXISTS Shop_Product; - -DROP TABLE IF EXISTS Shop_Tax_Or_Surcharge_Audit; -DROP TABLE IF EXISTS Shop_Tax_Or_Surcharge; - -DROP TABLE IF EXISTS Shop_Currency_Audit; -DROP TABLE IF EXISTS Shop_Currency; - -DROP TABLE IF EXISTS Shop_Delivery_Region_Branch_Audit; -DROP TABLE IF EXISTS Shop_Delivery_Region_Branch; -DROP TABLE IF EXISTS Shop_Region_Branch_Audit; -DROP TABLE IF EXISTS Shop_Region_Branch; - -DROP TABLE IF EXISTS Shop_Delivery_Region_Audit; -DROP TABLE IF EXISTS Shop_Delivery_Region; -DROP TABLE IF EXISTS Shop_Region_Audit; -DROP TABLE IF EXISTS Shop_Region; - -DROP TABLE IF EXISTS Shop_Interval_Recurrence_Audit; -DROP TABLE IF EXISTS Shop_Interval_Recurrence; - -DROP TABLE IF EXISTS Shop_Product_Category_Audit; -DROP TABLE IF EXISTS Shop_Product_Category; - -DROP TABLE IF EXISTS Shop_General_Audit; -DROP TABLE IF EXISTS Shop_General; - -DROP TABLE IF EXISTS File_Type_Audit; -DROP TABLE IF EXISTS File_Type; - -DROP TABLE IF EXISTS Msg_Error_Type; - -DROP TABLE IF EXISTS Shop_Access_Level_Audit; -DROP TABLE IF EXISTS Shop_Access_Level; - -DROP TABLE IF EXISTS Shop_Sales_And_Purchasing_Change_Set; -DROP TABLE IF EXISTS Shop_User_Change_Set; - -DROP TABLE IF EXISTS Shop_Msg_Error_Type; - -DROP TABLE IF EXISTS Shop_Product_Change_Set; - -DO $$ -BEGIN - RAISE NOTICE 'TABLE DELETION COMPLETE'; -END $$; - - -DROP FUNCTION IF EXISTS fn_shop_user_eval; -DROP FUNCTION IF EXISTS p_shop_calc_user; -DROP PROCEDURE IF EXISTS fn_shop_user_eval; -DROP PROCEDURE IF EXISTS p_shop_calc_user; - -DROP FUNCTION IF EXISTS fn_shop_save_product; -DROP FUNCTION IF EXISTS p_shop_save_product; -DROP PROCEDURE IF EXISTS fn_shop_save_product; -DROP PROCEDURE IF EXISTS p_shop_save_product; - -DROP FUNCTION IF EXISTS fn_shop_save_supplier; -DROP FUNCTION IF EXISTS p_shop_save_supplier; -DROP PROCEDURE IF EXISTS fn_shop_save_supplier; -DROP PROCEDURE IF EXISTS p_shop_save_supplier; - -DROP FUNCTION IF EXISTS fn_shop_save_supplier_purchase_order; -DROP FUNCTION IF EXISTS p_shop_save_supplier_purchase_order; -DROP PROCEDURE IF EXISTS fn_shop_save_supplier_purchase_order; -DROP PROCEDURE IF EXISTS p_shop_save_supplier_purchase_order; - -DROP FUNCTION IF EXISTS fn_shop_save_manufacturing_purchase_order; -DROP FUNCTION IF EXISTS p_shop_save_manufacturing_purchase_order; -DROP PROCEDURE IF EXISTS fn_shop_save_manufacturing_purchase_order; -DROP PROCEDURE IF EXISTS p_shop_save_manufacturing_purchase_order; - -DROP FUNCTION IF EXISTS fn_shop_save_customer; -DROP FUNCTION IF EXISTS p_shop_save_customer; -DROP PROCEDURE IF EXISTS fn_shop_save_customer; -DROP PROCEDURE IF EXISTS p_shop_save_customer; - -DROP FUNCTION IF EXISTS fn_shop_save_customer_sales_order; -DROP FUNCTION IF EXISTS p_shop_save_customer_sales_order; -DROP PROCEDURE IF EXISTS fn_shop_save_customer_sales_order; -DROP PROCEDURE IF EXISTS p_shop_save_customer_sales_order; - -DROP FUNCTION IF EXISTS fn_shop_save_user; -DROP FUNCTION IF EXISTS p_shop_save_user; -DROP PROCEDURE IF EXISTS fn_shop_save_user; -DROP PROCEDURE IF EXISTS p_shop_save_user; - -DROP FUNCTION IF EXISTS fn_shop_save_user_basket; -DROP FUNCTION IF EXISTS p_shop_save_user_basket; -DROP PROCEDURE IF EXISTS fn_shop_save_user_basket; -DROP PROCEDURE IF EXISTS p_shop_save_user_basket; - -DROP FUNCTION IF EXISTS fn_shop_get_many_product; -DROP FUNCTION IF EXISTS p_shop_get_many_product; -DROP PROCEDURE IF EXISTS fn_shop_get_many_product; -DROP PROCEDURE IF EXISTS p_shop_get_many_product; - -DROP FUNCTION IF EXISTS fn_shop_get_many_role_permission; -DROP FUNCTION IF EXISTS p_shop_get_many_role_permission; -DROP PROCEDURE IF EXISTS fn_shop_get_many_role_permission; -DROP PROCEDURE IF EXISTS p_shop_get_many_role_permission; - -DROP FUNCTION IF EXISTS fn_shop_get_many_currency; -DROP FUNCTION IF EXISTS p_shop_get_many_currency; -DROP PROCEDURE IF EXISTS fn_shop_get_many_currency; -DROP PROCEDURE IF EXISTS p_shop_get_many_currency; - -DROP FUNCTION IF EXISTS fn_shop_get_many_region; -DROP FUNCTION IF EXISTS p_shop_get_many_region; -DROP PROCEDURE IF EXISTS fn_shop_get_many_region; -DROP PROCEDURE IF EXISTS p_shop_get_many_region; - -DROP FUNCTION IF EXISTS fn_shop_get_many_user_order; -DROP FUNCTION IF EXISTS p_shop_get_many_user_order; -DROP PROCEDURE IF EXISTS fn_shop_get_many_user_order; -DROP PROCEDURE IF EXISTS p_shop_get_many_user_order; - -DROP FUNCTION IF EXISTS fn_shop_get_many_stripe_product_new; -DROP FUNCTION IF EXISTS p_shop_get_many_stripe_product_new; -DROP PROCEDURE IF EXISTS fn_shop_get_many_stripe_product_new; -DROP PROCEDURE IF EXISTS p_shop_get_many_stripe_product_new; - -DROP FUNCTION IF EXISTS fn_shop_get_many_stripe_price_new; -DROP FUNCTION IF EXISTS p_shop_get_many_stripe_price_new; -DROP PROCEDURE IF EXISTS fn_shop_get_many_stripe_price_new; -DROP PROCEDURE IF EXISTS p_shop_get_many_stripe_price_new; - -DROP FUNCTION IF EXISTS fn_shop_get_many_supplier; -DROP FUNCTION IF EXISTS p_shop_get_many_supplier; -DROP PROCEDURE IF EXISTS fn_shop_get_many_supplier; -DROP PROCEDURE IF EXISTS p_shop_get_many_supplier; - -DROP FUNCTION IF EXISTS fn_shop_get_many_supplier_purchase_order; -DROP FUNCTION IF EXISTS p_shop_get_many_supplier_purchase_order; -DROP PROCEDURE IF EXISTS fn_shop_get_many_supplier_purchase_order; -DROP PROCEDURE IF EXISTS p_shop_get_many_supplier_purchase_order; - -DROP FUNCTION IF EXISTS fn_shop_get_many_manufacturing_purchase_order; -DROP FUNCTION IF EXISTS p_shop_get_many_manufacturing_purchase_order; -DROP PROCEDURE IF EXISTS fn_shop_get_many_manufacturing_purchase_order; -DROP PROCEDURE IF EXISTS p_shop_get_many_manufacturing_purchase_order; - -DROP FUNCTION IF EXISTS fn_shop_get_many_customer; -DROP FUNCTION IF EXISTS p_shop_get_many_customer; -DROP PROCEDURE IF EXISTS fn_shop_get_many_customer; -DROP PROCEDURE IF EXISTS p_shop_get_many_customer; - -DROP FUNCTION IF EXISTS fn_shop_get_many_customer_sales_order; -DROP FUNCTION IF EXISTS p_shop_get_many_customer_sales_order; -DROP PROCEDURE IF EXISTS fn_shop_get_many_customer_sales_order; -DROP PROCEDURE IF EXISTS p_shop_get_many_customer_sales_order; \ No newline at end of file diff --git a/static/PostgreSQL/100.0_tbl_Shop_Product_Change_Set.sql b/static/PostgreSQL/100.0_tbl_Shop_Product_Change_Set.sql deleted file mode 100644 index b1dcc507..00000000 --- a/static/PostgreSQL/100.0_tbl_Shop_Product_Change_Set.sql +++ /dev/null @@ -1,13 +0,0 @@ - --- Product Change Sets - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Change_Set'; - -CREATE TABLE Shop_Product_Change_Set ( - id_change_set INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - comment VARCHAR(4000), - updated_last_on TIMESTAMP, - updated_last_by VARCHAR(100) -); \ No newline at end of file diff --git a/static/PostgreSQL/100.1_tbl_Shop_User_Change_Set.sql b/static/PostgreSQL/100.1_tbl_Shop_User_Change_Set.sql deleted file mode 100644 index ed444f86..00000000 --- a/static/PostgreSQL/100.1_tbl_Shop_User_Change_Set.sql +++ /dev/null @@ -1,13 +0,0 @@ - --- User Change Sets - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Change_Set'; - -CREATE TABLE IF NOT EXISTS Shop_User_Change_Set ( - id_change_set INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - comment VARCHAR(4000), - updated_last_on TIMESTAMP, - updated_last_by VARCHAR(100) -); \ No newline at end of file diff --git a/static/PostgreSQL/100.2_tbl_Shop_Access_Level.sql b/static/PostgreSQL/100.2_tbl_Shop_Access_Level.sql deleted file mode 100644 index 4921d6d2..00000000 --- a/static/PostgreSQL/100.2_tbl_Shop_Access_Level.sql +++ /dev/null @@ -1,21 +0,0 @@ - --- Access Levels - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Access_Level'; - -CREATE TABLE IF NOT EXISTS Shop_Access_Level ( - id_access_level INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - code VARCHAR(50), - name VARCHAR(255), - priority INTEGER NOT NULL, - active BOOLEAN NOT NULL DEFAULT TRUE, - display_order INTEGER NOT NULL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Access_Level_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/PostgreSQL/100.2_tbl_Shop_Sales_And_Purchasing_Change_Set.sql b/static/PostgreSQL/100.2_tbl_Shop_Sales_And_Purchasing_Change_Set.sql deleted file mode 100644 index 754d2a92..00000000 --- a/static/PostgreSQL/100.2_tbl_Shop_Sales_And_Purchasing_Change_Set.sql +++ /dev/null @@ -1,13 +0,0 @@ - --- Sales And Purchasing Change Sets - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Sales_And_Purchasing_Change_Set'; - -CREATE TABLE Shop_Sales_And_Purchasing_Change_Set ( - id_change_set INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - comment VARCHAR(4000), - updated_last_on TIMESTAMP, - updated_last_by VARCHAR(100) -); \ No newline at end of file diff --git a/static/PostgreSQL/100.3_tbl_Shop_Access_Level_Audit.sql b/static/PostgreSQL/100.3_tbl_Shop_Access_Level_Audit.sql deleted file mode 100644 index 930b0167..00000000 --- a/static/PostgreSQL/100.3_tbl_Shop_Access_Level_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Access Level Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Access_Level_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Access_Level_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_access_level INTEGER NOT NULL, - CONSTRAINT FK_Shop_Access_Level_Audit_id_access_level - FOREIGN KEY (id_access_level) - REFERENCES Shop_Access_Level(id_access_level) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(255), - value_new VARCHAR(255), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Access_Level_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/PostgreSQL/100_tbl_Msg_Error_Type.sql b/static/PostgreSQL/100_tbl_Msg_Error_Type.sql deleted file mode 100644 index e5268d39..00000000 --- a/static/PostgreSQL/100_tbl_Msg_Error_Type.sql +++ /dev/null @@ -1,13 +0,0 @@ - --- Error Message Type - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Msg_Error_Type'; - -CREATE TABLE IF NOT EXISTS Shop_Msg_Error_Type ( - id_type INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - code VARCHAR(50) NOT NULL, - name VARCHAR(200) NOT NULL, - description VARCHAR(1000) -); diff --git a/static/PostgreSQL/102_tbl_File_Type.sql b/static/PostgreSQL/102_tbl_File_Type.sql deleted file mode 100644 index 24823251..00000000 --- a/static/PostgreSQL/102_tbl_File_Type.sql +++ /dev/null @@ -1,17 +0,0 @@ - --- File Types - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'File_Type'; - -CREATE TABLE IF NOT EXISTS File_Type ( - id_type INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - code VARCHAR(50), - name VARCHAR(100), - extension VARCHAR(50), - created_on TIMESTAMP, - created_by INT, - updated_last_on TIMESTAMP, - updated_last_by VARCHAR(100) -); diff --git a/static/PostgreSQL/103_tbl_File_Type_Audit.sql b/static/PostgreSQL/103_tbl_File_Type_Audit.sql deleted file mode 100644 index 895a3f45..00000000 --- a/static/PostgreSQL/103_tbl_File_Type_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- File Type Audit - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'File_Type_Audit'; - -CREATE TABLE IF NOT EXISTS File_Type_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_type INTEGER NOT NULL, - CONSTRAINT FK_File_Type_Audit_id_type - FOREIGN KEY (id_type) - REFERENCES File_Type(id_type) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(100), - value_new VARCHAR(100), - created_on TIMESTAMP, - created_by INT, - updated_last_on TIMESTAMP, - updated_last_by VARCHAR(100) -); \ No newline at end of file diff --git a/static/PostgreSQL/104_tbl_Shop_General.sql b/static/PostgreSQL/104_tbl_Shop_General.sql deleted file mode 100644 index 087e8209..00000000 --- a/static/PostgreSQL/104_tbl_Shop_General.sql +++ /dev/null @@ -1,17 +0,0 @@ - --- Generic / shared properties - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_General'; - -CREATE TABLE IF NOT EXISTS Shop_General ( - id_general INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - quantity_max REAL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT CHK_Shop_General_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/PostgreSQL/105_tbl_Shop_General_Audit.sql b/static/PostgreSQL/105_tbl_Shop_General_Audit.sql deleted file mode 100644 index 36e5a3a4..00000000 --- a/static/PostgreSQL/105_tbl_Shop_General_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Shop General Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_General_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_General_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_general INTEGER NOT NULL, - CONSTRAINT FK_Shop_General_Audit_id_general - FOREIGN KEY (id_general) - REFERENCES Shop_General(id_general) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(100), - value_new VARCHAR(100), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_General_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/PostgreSQL/106_tbl_Shop_Category.sql b/static/PostgreSQL/106_tbl_Shop_Category.sql deleted file mode 100644 index 28e3e698..00000000 --- a/static/PostgreSQL/106_tbl_Shop_Category.sql +++ /dev/null @@ -1,21 +0,0 @@ - --- Categories - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Category'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Category ( - id_category INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - code VARCHAR(50), - name VARCHAR(255), - description VARCHAR(4000), - active BOOLEAN NOT NULL DEFAULT TRUE, - display_order INTEGER NOT NULL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Product_Category_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/PostgreSQL/107_tbl_Shop_Category_Audit.sql b/static/PostgreSQL/107_tbl_Shop_Category_Audit.sql deleted file mode 100644 index ba0ec8be..00000000 --- a/static/PostgreSQL/107_tbl_Shop_Category_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Category Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Category_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Category_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_category INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Category_Audit_id_category - FOREIGN KEY (id_category) - REFERENCES Shop_Product_Category(id_category) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(4000), - value_new VARCHAR(4000), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Category_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/PostgreSQL/108_tbl_Shop_Recurrence_Interval.sql b/static/PostgreSQL/108_tbl_Shop_Recurrence_Interval.sql deleted file mode 100644 index 4075a57e..00000000 --- a/static/PostgreSQL/108_tbl_Shop_Recurrence_Interval.sql +++ /dev/null @@ -1,20 +0,0 @@ - --- Recurrence Interval - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Interval_Recurrence'; - -CREATE TABLE IF NOT EXISTS Shop_Interval_Recurrence ( - id_interval INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - code VARCHAR(50), - name VARCHAR(255), - name_plural VARCHAR(256), - active BOOLEAN NOT NULL DEFAULT TRUE, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Interval_Recurrence_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/PostgreSQL/109_tbl_Shop_Recurrence_Interval_Audit.sql b/static/PostgreSQL/109_tbl_Shop_Recurrence_Interval_Audit.sql deleted file mode 100644 index 8ca9184b..00000000 --- a/static/PostgreSQL/109_tbl_Shop_Recurrence_Interval_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Recurrence Interval Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Interval_Recurrence_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Interval_Recurrence_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_interval INTEGER NOT NULL, - CONSTRAINT FK_Shop_Interval_Recurrence_Audit_id_interval - FOREIGN KEY (id_interval) - REFERENCES Shop_Interval_Recurrence(id_interval) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(256), - value_new VARCHAR(256), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Interval_Recurrence_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/PostgreSQL/110.0_tbl_Shop_Region.sql b/static/PostgreSQL/110.0_tbl_Shop_Region.sql deleted file mode 100644 index c5246629..00000000 --- a/static/PostgreSQL/110.0_tbl_Shop_Region.sql +++ /dev/null @@ -1,20 +0,0 @@ - --- Regions - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Region'; - -CREATE TABLE IF NOT EXISTS Shop_Region ( - id_region INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - code VARCHAR(50) NOT NULL, - name VARCHAR(200) NOT NULL, - active BOOLEAN NOT NULL DEFAULT TRUE, - display_order INTEGER NOT NULL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Region_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/PostgreSQL/110.1_tbl_Shop_Region_Audit.sql b/static/PostgreSQL/110.1_tbl_Shop_Region_Audit.sql deleted file mode 100644 index 07a36839..00000000 --- a/static/PostgreSQL/110.1_tbl_Shop_Region_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Region Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Region_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Region_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_region INTEGER NOT NULL, - CONSTRAINT FK_Shop_Region_Audit_id_region - FOREIGN KEY (id_region) - REFERENCES Shop_Region(id_region) - ON UPDATE RESTRICT, - name_field VARCHAR(64) NOT NULL, - value_prev VARCHAR(200), - value_new VARCHAR(200), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Region_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/PostgreSQL/110.2_tbl_Shop_Region_Branch.sql b/static/PostgreSQL/110.2_tbl_Shop_Region_Branch.sql deleted file mode 100644 index 42e1ae32..00000000 --- a/static/PostgreSQL/110.2_tbl_Shop_Region_Branch.sql +++ /dev/null @@ -1,29 +0,0 @@ - --- Region Branchs - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Region_Branch'; - -CREATE TABLE IF NOT EXISTS Shop_Region_Branch ( - id_branch INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_region_parent INTEGER NOT NULL, - CONSTRAINT FK_Shop_Region_Branch_id_region_parent - FOREIGN KEY (id_region_parent) - REFERENCES Shop_Region(id_region) - ON UPDATE RESTRICT, - id_region_child INTEGER NOT NULL, - CONSTRAINT FK_Shop_Region_Branch_id_region_child - FOREIGN KEY (id_region_child) - REFERENCES Shop_Region(id_region) - ON UPDATE RESTRICT, - -- depth INTEGER NOT NULL, - active BOOLEAN NOT NULL DEFAULT TRUE, - display_order INTEGER NOT NULL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Region_Branch_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/PostgreSQL/110.3_tbl_Shop_Region_Branch_Audit.sql b/static/PostgreSQL/110.3_tbl_Shop_Region_Branch_Audit.sql deleted file mode 100644 index fed4446a..00000000 --- a/static/PostgreSQL/110.3_tbl_Shop_Region_Branch_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Region Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Region_Branch_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Region_Branch_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_branch INTEGER NOT NULL, - CONSTRAINT FK_Shop_Region_Branch_Audit_id_branch - FOREIGN KEY (id_branch) - REFERENCES Shop_Region_Branch(id_branch) - ON UPDATE RESTRICT, - name_field VARCHAR(64) NOT NULL, - value_prev VARCHAR(10), - value_new VARCHAR(10), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Region_Branch_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/PostgreSQL/110.4_tbl_Shop_Currency.sql b/static/PostgreSQL/110.4_tbl_Shop_Currency.sql deleted file mode 100644 index 5e3b6530..00000000 --- a/static/PostgreSQL/110.4_tbl_Shop_Currency.sql +++ /dev/null @@ -1,23 +0,0 @@ - --- Currencies - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Currency'; - -CREATE TABLE IF NOT EXISTS Shop_Currency ( - id_currency INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - code VARCHAR(50) NOT NULL, - name VARCHAR(255) NOT NULL, - symbol VARCHAR(1) NOT NULL, - factor_from_GBP REAL NOT NULL, - active BOOLEAN NOT NULL DEFAULT TRUE, - display_order INTEGER NOT NULL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Currency_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) - ON UPDATE RESTRICT -); \ No newline at end of file diff --git a/static/PostgreSQL/110.5_tbl_Shop_Currency_Audit.sql b/static/PostgreSQL/110.5_tbl_Shop_Currency_Audit.sql deleted file mode 100644 index cb68b4ae..00000000 --- a/static/PostgreSQL/110.5_tbl_Shop_Currency_Audit.sql +++ /dev/null @@ -1,23 +0,0 @@ - --- Currency Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Currency_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Currency_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_currency INTEGER NOT NULL, - CONSTRAINT FK_Shop_Currency_Audit_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(255), - value_new VARCHAR(255), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Currency_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - ON UPDATE RESTRICT -); \ No newline at end of file diff --git a/static/PostgreSQL/110.6_tbl_Shop_Tax_Or_Surcharge.sql b/static/PostgreSQL/110.6_tbl_Shop_Tax_Or_Surcharge.sql deleted file mode 100644 index 77ba8f90..00000000 --- a/static/PostgreSQL/110.6_tbl_Shop_Tax_Or_Surcharge.sql +++ /dev/null @@ -1,38 +0,0 @@ - --- Taxes and Surcharges - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Tax_Or_Surcharge'; - -CREATE TABLE Shop_Tax_Or_Surcharge ( - id_tax INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - code VARCHAR(50) NOT NULL, - name VARCHAR(200) NOT NULL, - id_region_buyer INTEGER NOT NULL, - CONSTRAINT FK_Shop_Tax_Or_Surcharge_id_region_buyer - FOREIGN KEY (id_region_buyer) - REFERENCES Shop_Region(id_region), - id_region_seller INTEGER NOT NULL, - CONSTRAINT FK_Shop_Tax_Or_Surcharge_id_region_seller - FOREIGN KEY (id_region_seller) - REFERENCES Shop_Region(id_region), - id_currency INTEGER, - CONSTRAINT FK_Shop_Tax_Or_Surcharge_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency) - ON UPDATE RESTRICT, - fixed_fee REAL NOT NULL DEFAULT 0, - multiplier REAL NOT NULL DEFAULT 1 CHECK (multiplier > 0), - apply_fixed_fee_before_multiplier BOOLEAN NOT NULL DEFAULT TRUE, - quantity_min REAL NOT NULL DEFAULT 0, - quantity_max REAL NOT NULL, - active BOOLEAN NOT NULL DEFAULT TRUE, - display_order INTEGER NOT NULL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Tax_Or_Surcharge_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/PostgreSQL/110.7_tbl_Shop_Tax_Or_Surcharge_Audit.sql b/static/PostgreSQL/110.7_tbl_Shop_Tax_Or_Surcharge_Audit.sql deleted file mode 100644 index c753c207..00000000 --- a/static/PostgreSQL/110.7_tbl_Shop_Tax_Or_Surcharge_Audit.sql +++ /dev/null @@ -1,23 +0,0 @@ - --- Tax Or Surcharge Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Tax_Or_Surcharge_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Tax_Or_Surcharge_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_tax INTEGER NOT NULL, - CONSTRAINT FK_Shop_Tax_Or_Surcharge_Audit_id_discount - FOREIGN KEY (id_tax) - REFERENCES Shop_Tax_Or_Surcharge(id_tax) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(200), - value_new VARCHAR(200), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Tax_Or_Surcharge_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) - ON UPDATE RESTRICT -); \ No newline at end of file diff --git a/static/PostgreSQL/110.8_tbl_Shop_Product.sql b/static/PostgreSQL/110.8_tbl_Shop_Product.sql deleted file mode 100644 index ed44d554..00000000 --- a/static/PostgreSQL/110.8_tbl_Shop_Product.sql +++ /dev/null @@ -1,48 +0,0 @@ - --- Products - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product'; - -CREATE TABLE IF NOT EXISTS Shop_Product ( - id_product INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - name VARCHAR(255) NOT NULL, - -- description VARCHAR(4000), - id_category INTEGER NOT NULL, - has_variations BOOLEAN NOT NULL, - /* - price_GBP_full REAL, - price_GBP_min REAL, - -- ratio_discount_overall REAL NOT NULL DEFAULT 0, - CONSTRAINT FK_Shop_Product_id_category - FOREIGN KEY (id_category) - REFERENCES Shop_Product_Category(id_category) - ON UPDATE RESTRICT, - latency_manuf INTEGER, - quantity_min REAL, - quantity_max REAL, - quantity_step REAL, - quantity_stock REAL, - is_subscription BOOLEAN, - id_unit_measurement_interval_recurrence INTEGER, - CONSTRAINT FK_Shop_Product_id_unit_measurement_interval_recurrence - FOREIGN KEY (id_unit_measurement_interval_recurrence) - REFERENCES Shop_Interval_Recurrence(id_interval), - count_interval_recurrence INTEGER, - */ - id_access_level_required INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_id_access_level_required - FOREIGN KEY (id_access_level_required) - REFERENCES Shop_Access_Level(id_access_level), - -- id_stripe_product VARCHAR(100), - -- id_stripe_price VARCHAR(100) NOT NULL, - active BOOLEAN NOT NULL DEFAULT TRUE, - display_order INTEGER NOT NULL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Product_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/PostgreSQL/110.9_tbl_Shop_Product_Audit.sql b/static/PostgreSQL/110.9_tbl_Shop_Product_Audit.sql deleted file mode 100644 index 932c2b0d..00000000 --- a/static/PostgreSQL/110.9_tbl_Shop_Product_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Products - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_product INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Audit_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(255), - value_new VARCHAR(255), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/PostgreSQL/112_tbl_Shop_Variation_Type.sql b/static/PostgreSQL/112_tbl_Shop_Variation_Type.sql deleted file mode 100644 index 8a77d963..00000000 --- a/static/PostgreSQL/112_tbl_Shop_Variation_Type.sql +++ /dev/null @@ -1,21 +0,0 @@ - --- Variation Types - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Variation_Type'; - -CREATE TABLE IF NOT EXISTS Shop_Variation_Type ( - id_type INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - code VARCHAR(50), - name VARCHAR(255), - name_plural VARCHAR(256), - active BOOLEAN NOT NULL DEFAULT TRUE, - display_order INTEGER NOT NULL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Variation_Type_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/PostgreSQL/113.0_tbl_Shop_Variation_Type_Audit.sql b/static/PostgreSQL/113.0_tbl_Shop_Variation_Type_Audit.sql deleted file mode 100644 index 1ae8c678..00000000 --- a/static/PostgreSQL/113.0_tbl_Shop_Variation_Type_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Variation Type Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Variation_Type_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Variation_Type_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_type INTEGER NOT NULL, - CONSTRAINT FK_Shop_Variation_Type_Audit_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Variation_Type(id_type) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(256), - value_new VARCHAR(256), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Variation_Type_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/PostgreSQL/114_tbl_Shop_Variation.sql b/static/PostgreSQL/114_tbl_Shop_Variation.sql deleted file mode 100644 index 8f0ae1ae..00000000 --- a/static/PostgreSQL/114_tbl_Shop_Variation.sql +++ /dev/null @@ -1,25 +0,0 @@ - --- Variations - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Variation'; - -CREATE TABLE Shop_Variation ( - id_variation INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_type INTEGER NOT NULL, - CONSTRAINT FK_Shop_Variation_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Variation_Type(id_type) - ON UPDATE RESTRICT, - code VARCHAR(50), - name VARCHAR(255), - active BOOLEAN NOT NULL DEFAULT TRUE, - display_order INTEGER NOT NULL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Variation_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/PostgreSQL/115_tbl_Shop_Variation_Audit.sql b/static/PostgreSQL/115_tbl_Shop_Variation_Audit.sql deleted file mode 100644 index f439d2b8..00000000 --- a/static/PostgreSQL/115_tbl_Shop_Variation_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Variation Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Variation_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Variation_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_variation INTEGER NOT NULL, - CONSTRAINT FK_Shop_Variation_Audit_id_variation - FOREIGN KEY (id_variation) - REFERENCES Shop_Variation(id_variation) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(255), - value_new VARCHAR(255), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Variation_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/PostgreSQL/117.1_tbl_Shop_Product_Permutation.sql b/static/PostgreSQL/117.1_tbl_Shop_Product_Permutation.sql deleted file mode 100644 index b7a0ebd8..00000000 --- a/static/PostgreSQL/117.1_tbl_Shop_Product_Permutation.sql +++ /dev/null @@ -1,47 +0,0 @@ - --- Product Permutation - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Permutation'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Permutation ( - id_permutation INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_product INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Variation_Link_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product) - ON UPDATE RESTRICT, - -- name VARCHAR(255) NOT NULL, - description VARCHAR(4000) NOT NULL, - cost_local REAL NOT NULL, - id_currency_cost INTEGER NOT NULL, - profit_local_min REAL NOT NULL, - -- id_currency_profit_min INTEGER NOT NULL, - latency_manufacture INTEGER NOT NULL, - quantity_min REAL NOT NULL, - quantity_max REAL NOT NULL, - quantity_step REAL NOT NULL, - quantity_stock REAL NOT NULL, - is_subscription BOOLEAN NOT NULL, - id_unit_measurement_interval_recurrence INTEGER, - CONSTRAINT FK_Shop_Product_Permutation_id_unit_measurement_interval_recurrence - FOREIGN KEY (id_unit_measurement_interval_recurrence) - REFERENCES Shop_Interval_Recurrence(id_interval), - count_interval_recurrence INTEGER, - /* - id_access_level_required INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_id_access_level_required - FOREIGN KEY (id_access_level_required) - REFERENCES Shop_Access_Level(id_access_level), - */ - id_stripe_product VARCHAR(100) NULL, - active BOOLEAN NOT NULL DEFAULT TRUE, - display_order INTEGER NOT NULL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Product_Variation_Link_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/PostgreSQL/117.2_tbl_Shop_Product_Permutation_Audit.sql b/static/PostgreSQL/117.2_tbl_Shop_Product_Permutation_Audit.sql deleted file mode 100644 index d4d4c443..00000000 --- a/static/PostgreSQL/117.2_tbl_Shop_Product_Permutation_Audit.sql +++ /dev/null @@ -1,23 +0,0 @@ - --- Product Permutation Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Permutation_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Permutation_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_permutation INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_Audit_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(4000), - value_new VARCHAR(4000), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) - ON UPDATE RESTRICT -); diff --git a/static/PostgreSQL/117.3_tbl_Shop_Product_Permutation_Variation_Link.sql b/static/PostgreSQL/117.3_tbl_Shop_Product_Permutation_Variation_Link.sql deleted file mode 100644 index 50b0e03c..00000000 --- a/static/PostgreSQL/117.3_tbl_Shop_Product_Permutation_Variation_Link.sql +++ /dev/null @@ -1,28 +0,0 @@ - --- Product Permutation Variation Link - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Permutation_Variation_Link'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Permutation_Variation_Link ( - id_link INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_permutation INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_Variation_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation) - ON UPDATE RESTRICT, - id_variation INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_Variation_Link_id_variation - FOREIGN KEY (id_variation) - REFERENCES Shop_Variation(id_variation) - ON UPDATE RESTRICT, - active BOOLEAN NOT NULL DEFAULT TRUE, - display_order INTEGER NOT NULL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Product_Permutation_Variation_Link_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/PostgreSQL/117.4_tbl_Shop_Product_Permutation_Variation_Link_Audit.sql b/static/PostgreSQL/117.4_tbl_Shop_Product_Permutation_Variation_Link_Audit.sql deleted file mode 100644 index 3cce2d5c..00000000 --- a/static/PostgreSQL/117.4_tbl_Shop_Product_Permutation_Variation_Link_Audit.sql +++ /dev/null @@ -1,23 +0,0 @@ - --- Product Permutation Variation Link Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Permutation_Variation_Link_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Permutation_Variation_Link_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_link INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_Variation_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Product_Permutation_Variation_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(10), - value_new VARCHAR(10), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_Variation_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) - ON UPDATE RESTRICT -); \ No newline at end of file diff --git a/static/PostgreSQL/117.5_tbl_Shop_Product_Currency_Region_Link.sql b/static/PostgreSQL/117.5_tbl_Shop_Product_Currency_Region_Link.sql deleted file mode 100644 index 0055dc9d..00000000 --- a/static/PostgreSQL/117.5_tbl_Shop_Product_Currency_Region_Link.sql +++ /dev/null @@ -1,40 +0,0 @@ - --- Product Currency Region link - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Currency_Region_Link'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Currency_Region_Link ( - id_link INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_product INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Currency_Region_Link_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product) - ON UPDATE RESTRICT, - id_permutation INTEGER NULL, - CONSTRAINT FK_Shop_Product_Currency_Region_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation) - ON UPDATE RESTRICT, - id_currency INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Currency_Region_Link_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency) - ON UPDATE RESTRICT, - id_region_purchase INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Currency_Region_Link_id_region_purchase - FOREIGN KEY (id_region_purchase) - REFERENCES Shop_Region(id_region) - ON UPDATE RESTRICT, - price_local_VAT_incl REAL NULL, - price_local_VAT_excl REAL NULL, - id_stripe_price VARCHAR(200), - active BOOLEAN NOT NULL DEFAULT TRUE, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Product_Currency_Region_Link_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/PostgreSQL/117.6_tbl_Shop_Product_Currency_Region_Link_Audit.sql b/static/PostgreSQL/117.6_tbl_Shop_Product_Currency_Region_Link_Audit.sql deleted file mode 100644 index 2aa7d47b..00000000 --- a/static/PostgreSQL/117.6_tbl_Shop_Product_Currency_Region_Link_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Product Currency Region Link Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Currency_Region_Link_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Currency_Region_Link_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_link INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Currency_Region_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Product_Currency_Region_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(10), - value_new VARCHAR(10), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Currency_Region_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/PostgreSQL/118_tbl_Shop_Image_Type.sql b/static/PostgreSQL/118_tbl_Shop_Image_Type.sql deleted file mode 100644 index 4a8a8d71..00000000 --- a/static/PostgreSQL/118_tbl_Shop_Image_Type.sql +++ /dev/null @@ -1,21 +0,0 @@ - --- Image Types - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Image_Type'; - -CREATE TABLE IF NOT EXISTS Shop_Image_Type ( - id_type INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - code VARCHAR(50), - name VARCHAR(255), - name_plural VARCHAR(256), - active BOOLEAN NOT NULL DEFAULT TRUE, - display_order INTEGER NOT NULL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Image_Type_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/PostgreSQL/119_tbl_Shop_Image_Type_Audit.sql b/static/PostgreSQL/119_tbl_Shop_Image_Type_Audit.sql deleted file mode 100644 index bebb9ccd..00000000 --- a/static/PostgreSQL/119_tbl_Shop_Image_Type_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Image Type Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Image_Type_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Image_Type_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_type INTEGER NOT NULL, - CONSTRAINT FK_Shop_Image_Type_Audit_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Image_Type(id_type) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(256), - value_new VARCHAR(256), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Image_Type_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/PostgreSQL/120_tbl_Shop_Image.sql b/static/PostgreSQL/120_tbl_Shop_Image.sql deleted file mode 100644 index acf18eba..00000000 --- a/static/PostgreSQL/120_tbl_Shop_Image.sql +++ /dev/null @@ -1,35 +0,0 @@ - --- Images - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Image'; - -CREATE TABLE IF NOT EXISTS Shop_Image ( - id_image INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_type_image INTEGER NOT NULL, - CONSTRAINT FK_Shop_Image_id_type_image - FOREIGN KEY (id_type_image) - REFERENCES Shop_Image_Type(id_type), - id_type_file INTEGER NOT NULL, - CONSTRAINT FK_Shop_Image_id_type_file - FOREIGN KEY (id_type_file) - REFERENCES File_Type(id_type), - id_product INTEGER NULL, - CONSTRAINT FK_Shop_Image_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - id_permutation INTEGER NULL, - CONSTRAINT FK_Shop_Image_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - url VARCHAR(255), - active BOOLEAN NOT NULL DEFAULT TRUE, - display_order INTEGER NOT NULL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Image_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/PostgreSQL/121_tbl_Shop_Image_Audit.sql b/static/PostgreSQL/121_tbl_Shop_Image_Audit.sql deleted file mode 100644 index 23060b27..00000000 --- a/static/PostgreSQL/121_tbl_Shop_Image_Audit.sql +++ /dev/null @@ -1,21 +0,0 @@ - --- Image Type Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Image_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Image_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_image INTEGER NOT NULL, - CONSTRAINT FK_Shop_Image_Audit_id_image - FOREIGN KEY (id_image) - REFERENCES Shop_Image(id_image), - name_field VARCHAR(50), - value_prev VARCHAR(10), - value_new VARCHAR(10), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Image_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/PostgreSQL/122_tbl_Shop_Delivery_Option.sql b/static/PostgreSQL/122_tbl_Shop_Delivery_Option.sql deleted file mode 100644 index d4241ff4..00000000 --- a/static/PostgreSQL/122_tbl_Shop_Delivery_Option.sql +++ /dev/null @@ -1,25 +0,0 @@ - --- Delivery Options - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Delivery_Option'; - -CREATE TABLE IF NOT EXISTS Shop_Delivery_Option ( - id_option INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - code VARCHAR(50) NOT NULL, - name VARCHAR(100) NOT NULL, - description VARCHAR(4000), - latency_delivery_min INTEGER NOT NULL, - latency_delivery_max INTEGER NOT NULL, - quantity_min INTEGER NOT NULL, - quantity_max INTEGER NOT NULL, - active BOOLEAN NOT NULL DEFAULT TRUE, - display_order INTEGER NOT NULL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Delivery_Option_Type_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/PostgreSQL/123_tbl_Shop_Delivery_Option_Audit.sql b/static/PostgreSQL/123_tbl_Shop_Delivery_Option_Audit.sql deleted file mode 100644 index 5c0a8e06..00000000 --- a/static/PostgreSQL/123_tbl_Shop_Delivery_Option_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Delivery Option Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Delivery_Option_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Delivery_Option_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_option INTEGER NOT NULL, - CONSTRAINT FK_Shop_Delivery_Option_Audit_id_option - FOREIGN KEY (id_option) - REFERENCES Shop_Delivery_Option(id_option) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(4000), - value_new VARCHAR(4000), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Delivery_Option_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/PostgreSQL/124_tbl_Shop_Product_Delivery_Option_Link.sql b/static/PostgreSQL/124_tbl_Shop_Product_Delivery_Option_Link.sql deleted file mode 100644 index 3f5b9952..00000000 --- a/static/PostgreSQL/124_tbl_Shop_Product_Delivery_Option_Link.sql +++ /dev/null @@ -1,44 +0,0 @@ - --- Delivery Option - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Permutation_Delivery_Option_Link'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Permutation_Delivery_Option_Link ( - id_link INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_product INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_Delivery_Option_Link_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product) - ON UPDATE RESTRICT, - id_permutation INTEGER, - CONSTRAINT FK_Shop_Product_Permutation_Delivery_Option_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation) - ON UPDATE RESTRICT, - id_delivery_option INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_Delivery_Option_Link_id_delivery_option - FOREIGN KEY (id_delivery_option) - REFERENCES Shop_Delivery_Option(id_option) - ON UPDATE RESTRICT, - id_region INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_Delivery_Option_Link_id_region - FOREIGN KEY (id_region) - REFERENCES Shop_Region(id_region) - ON UPDATE RESTRICT, - id_currency INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_Delivery_Option_Link_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency) - ON UPDATE RESTRICT, - price_local REAL NOT NULL, - active BOOLEAN NOT NULL DEFAULT TRUE, - display_order INTEGER NOT NULL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Product_Permutation_Delivery_Option_Link_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/PostgreSQL/125_tbl_Shop_Product_Delivery_Option_Link_Audit.sql b/static/PostgreSQL/125_tbl_Shop_Product_Delivery_Option_Link_Audit.sql deleted file mode 100644 index 1101429d..00000000 --- a/static/PostgreSQL/125_tbl_Shop_Product_Delivery_Option_Link_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Delivery Option Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Product_Permutation_Delivery_Option_Link_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Product_Permutation_Delivery_Option_Link_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_link INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_Delivery_Option_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Product_Permutation_Delivery_Option_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(64) NOT NULL, - value_prev VARCHAR(10), - value_new VARCHAR(10), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Product_Permutation_Delivery_Option_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/PostgreSQL/130.4_tbl_Shop_Discount.sql b/static/PostgreSQL/130.4_tbl_Shop_Discount.sql deleted file mode 100644 index c7641a47..00000000 --- a/static/PostgreSQL/130.4_tbl_Shop_Discount.sql +++ /dev/null @@ -1,48 +0,0 @@ - --- Discounts - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Discount'; - -CREATE TABLE Shop_Discount ( - id_discount INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - code VARCHAR(50) NOT NULL, - name VARCHAR(200) NOT NULL, - id_product INTEGER NOT NULL, - CONSTRAINT FK_Shop_Discount_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - id_permutation INTEGER, - CONSTRAINT FK_Shop_Discount_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation) - ON UPDATE RESTRICT, - /* - id_delivery_region INTEGER, - CONSTRAINT FK_Shop_Discount_id_delivery_region - FOREIGN KEY (id_delivery_region) - REFERENCES Shop_Delivery_Region(id_region) - ON UPDATE RESTRICT, - id_currency INTEGER, - CONSTRAINT FK_Shop_Discount_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency) - ON UPDATE RESTRICT, - */ - multiplier REAL NOT NULL DEFAULT 1 CHECK (multiplier > 0), - subtractor REAL NOT NULL DEFAULT 0, - apply_multiplier_first BOOLEAN NOT NULL DEFAULT TRUE, - quantity_min REAL NOT NULL DEFAULT 0, - quantity_max REAL NOT NULL, - date_start TIMESTAMP NOT NULL, - date_end TIMESTAMP NOT NULL, - active BOOLEAN NOT NULL DEFAULT TRUE, - display_order INTEGER NOT NULL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Discount_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/PostgreSQL/131_tbl_Shop_Discount_Audit.sql b/static/PostgreSQL/131_tbl_Shop_Discount_Audit.sql deleted file mode 100644 index 71a27cb5..00000000 --- a/static/PostgreSQL/131_tbl_Shop_Discount_Audit.sql +++ /dev/null @@ -1,23 +0,0 @@ - --- Discount Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Discount_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Discount_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_discount INTEGER NOT NULL, - CONSTRAINT FK_Shop_Discount_Audit_id_discount - FOREIGN KEY (id_discount) - REFERENCES Shop_Discount(id_discount) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(200), - value_new VARCHAR(200), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Discount_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) - ON UPDATE RESTRICT -); \ No newline at end of file diff --git a/static/PostgreSQL/132_tbl_Shop_Discount_Region_Currency_Link.sql b/static/PostgreSQL/132_tbl_Shop_Discount_Region_Currency_Link.sql deleted file mode 100644 index a03740e2..00000000 --- a/static/PostgreSQL/132_tbl_Shop_Discount_Region_Currency_Link.sql +++ /dev/null @@ -1,32 +0,0 @@ - --- Discount Region Currency Link - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Discount_Region_Currency_Link'; - -CREATE TABLE IF NOT EXISTS Shop_Discount_Region_Currency_Link ( - id_link INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_discount INTEGER NOT NULL, - CONSTRAINT FK_Shop_Discount_Region_Currency_Link_id_discount - FOREIGN KEY (id_discount) - REFERENCES Shop_Discount(id_discount) - ON UPDATE RESTRICT, - id_region INTEGER NOT NULL, - CONSTRAINT FK_Shop_Discount_Region_Currency_Link_id_region - FOREIGN KEY (id_region) - REFERENCES Shop_Region(id_region) - ON UPDATE RESTRICT, - id_currency INTEGER NOT NULL, - CONSTRAINT FK_Shop_Discount_Region_Currency_Link_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency) - ON UPDATE RESTRICT, - active BOOLEAN NOT NULL DEFAULT TRUE, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Discount_Region_Currency_Link_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/PostgreSQL/133_tbl_Shop_Discount_Region_Currency_Link_Audit.sql b/static/PostgreSQL/133_tbl_Shop_Discount_Region_Currency_Link_Audit.sql deleted file mode 100644 index 5640d207..00000000 --- a/static/PostgreSQL/133_tbl_Shop_Discount_Region_Currency_Link_Audit.sql +++ /dev/null @@ -1,23 +0,0 @@ - --- Discount Region Currency Link Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Discount_Region_Currency_Link_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Discount_Region_Currency_Link_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_link INTEGER NOT NULL, - CONSTRAINT FK_Shop_Discount_Region_Currency_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Discount_Region_Currency_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(10), - value_new VARCHAR(10), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Discount_Region_Currency_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) - ON UPDATE RESTRICT -); \ No newline at end of file diff --git a/static/PostgreSQL/153_tbl_Shop_Permission_Group.sql b/static/PostgreSQL/153_tbl_Shop_Permission_Group.sql deleted file mode 100644 index 38fd7f44..00000000 --- a/static/PostgreSQL/153_tbl_Shop_Permission_Group.sql +++ /dev/null @@ -1,21 +0,0 @@ - --- Permission Groups - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Permission_Group'; - -CREATE TABLE IF NOT EXISTS Shop_Permission_Group ( - id_group INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - code VARCHAR(50), - name VARCHAR(255), - active BOOLEAN NOT NULL DEFAULT TRUE, - display_order INTEGER NOT NULL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Permission_Group_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - ON UPDATE RESTRICT -); \ No newline at end of file diff --git a/static/PostgreSQL/154_tbl_Shop_Permission_Group_Audit.sql b/static/PostgreSQL/154_tbl_Shop_Permission_Group_Audit.sql deleted file mode 100644 index 9fa6120f..00000000 --- a/static/PostgreSQL/154_tbl_Shop_Permission_Group_Audit.sql +++ /dev/null @@ -1,23 +0,0 @@ - --- Permission Group Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Permission_Group_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Permission_Group_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_group INTEGER NOT NULL, - CONSTRAINT FK_Shop_Permission_Group_Audit_id_group - FOREIGN KEY (id_group) - REFERENCES Shop_Permission_Group(id_group) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(255), - value_new VARCHAR(255), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Permission_Group_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - ON UPDATE RESTRICT -); \ No newline at end of file diff --git a/static/PostgreSQL/155_tbl_Shop_Permission.sql b/static/PostgreSQL/155_tbl_Shop_Permission.sql deleted file mode 100644 index bf9cb136..00000000 --- a/static/PostgreSQL/155_tbl_Shop_Permission.sql +++ /dev/null @@ -1,29 +0,0 @@ - --- Permissions - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Permission'; - -CREATE TABLE IF NOT EXISTS Shop_Permission ( - id_permission INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - code VARCHAR(50), - name VARCHAR(255), - id_permission_group INTEGER NOT NULL, - CONSTRAINT FK_Shop_Permission_id_permission_group - FOREIGN KEY (id_permission_group) - REFERENCES Shop_Permission_Group(id_group) - ON UPDATE RESTRICT, - id_access_level_required INTEGER NOT NULL, - CONSTRAINT FK_Shop_Permission_id_access_level_required - FOREIGN KEY (id_access_level_required) - REFERENCES Shop_Access_Level(id_access_level), - active BOOLEAN NOT NULL DEFAULT TRUE, - display_order INTEGER NOT NULL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Permission_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/PostgreSQL/156_tbl_Shop_Permission_Audit.sql b/static/PostgreSQL/156_tbl_Shop_Permission_Audit.sql deleted file mode 100644 index ad7ce0bc..00000000 --- a/static/PostgreSQL/156_tbl_Shop_Permission_Audit.sql +++ /dev/null @@ -1,23 +0,0 @@ - --- Permission Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Permission_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Permission_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_permission INTEGER NOT NULL, - CONSTRAINT FK_Shop_Permission_Audit_id_permission - FOREIGN KEY (id_permission) - REFERENCES Shop_Permission(id_permission) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(255), - value_new VARCHAR(255), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Permission_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - ON UPDATE RESTRICT -); \ No newline at end of file diff --git a/static/PostgreSQL/157_tbl_Shop_Role.sql b/static/PostgreSQL/157_tbl_Shop_Role.sql deleted file mode 100644 index b2a1bdfb..00000000 --- a/static/PostgreSQL/157_tbl_Shop_Role.sql +++ /dev/null @@ -1,20 +0,0 @@ - --- Roles - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Role'; - -CREATE TABLE IF NOT EXISTS Shop_Role ( - id_role INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - code VARCHAR(50), - name VARCHAR(255), - active BOOLEAN NOT NULL DEFAULT TRUE, - display_order INTEGER NOT NULL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Role_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/PostgreSQL/158_tbl_Shop_Role_Audit.sql b/static/PostgreSQL/158_tbl_Shop_Role_Audit.sql deleted file mode 100644 index f8385f8c..00000000 --- a/static/PostgreSQL/158_tbl_Shop_Role_Audit.sql +++ /dev/null @@ -1,23 +0,0 @@ - --- Role Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Role_Audit'; - -CREATE TABLE Shop_Role_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_role INTEGER NOT NULL, - CONSTRAINT FK_Shop_Role_Audit_id_role - FOREIGN KEY (id_role) - REFERENCES Shop_Role(id_role) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(255), - value_new VARCHAR(255), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Role_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - ON UPDATE RESTRICT -); \ No newline at end of file diff --git a/static/PostgreSQL/159_tbl_Shop_Role_Permission_Link.sql b/static/PostgreSQL/159_tbl_Shop_Role_Permission_Link.sql deleted file mode 100644 index 2fa67c58..00000000 --- a/static/PostgreSQL/159_tbl_Shop_Role_Permission_Link.sql +++ /dev/null @@ -1,31 +0,0 @@ - --- Role Permission link - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Role_Permission_Link'; - -CREATE TABLE IF NOT EXISTS Shop_Role_Permission_Link ( - id_link INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_role INTEGER, - CONSTRAINT FK_Shop_Role_Permission_Link_id_role - FOREIGN KEY (id_role) - REFERENCES Shop_Role(id_role) - ON UPDATE RESTRICT, - id_permission INTEGER, - CONSTRAINT FK_Shop_Role_Permission_Link_id_permission - FOREIGN KEY (id_permission) - REFERENCES Shop_Permission(id_permission) - ON UPDATE RESTRICT, - id_access_level INTEGER, - CONSTRAINT FK_Shop_Role_Permission_Link_id_access_level - FOREIGN KEY (id_access_level) - REFERENCES Shop_Access_Level(id_access_level), - active BOOLEAN NOT NULL DEFAULT TRUE, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Role_Permission_Link_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/PostgreSQL/160_tbl_Shop_Role_Permission_Link_Audit.sql b/static/PostgreSQL/160_tbl_Shop_Role_Permission_Link_Audit.sql deleted file mode 100644 index 8793c4e8..00000000 --- a/static/PostgreSQL/160_tbl_Shop_Role_Permission_Link_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Role Permission link Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Role_Permission_Link_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Role_Permission_Link_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_link INTEGER NOT NULL, - CONSTRAINT FK_Shop_Role_Permission_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Role_Permission_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(10), - value_new VARCHAR(10), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Role_Permission_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/PostgreSQL/161_tbl_Shop_User.sql b/static/PostgreSQL/161_tbl_Shop_User.sql deleted file mode 100644 index 197a472e..00000000 --- a/static/PostgreSQL/161_tbl_Shop_User.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Users - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User'; - -CREATE TABLE IF NOT EXISTS Shop_User ( - id_user INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_user_oauth VARCHAR(200) NOT NULL, - name VARCHAR(255) NOT NULL, - email VARCHAR(254) NOT NULL, - is_email_verified BOOLEAN NOT NULL DEFAULT FALSE, - is_super_user BOOLEAN NOT NULL DEFAULT FALSE, - active BOOLEAN NOT NULL DEFAULT TRUE, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_User_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); diff --git a/static/PostgreSQL/162_tbl_Shop_User_Audit.sql b/static/PostgreSQL/162_tbl_Shop_User_Audit.sql deleted file mode 100644 index d7544cf7..00000000 --- a/static/PostgreSQL/162_tbl_Shop_User_Audit.sql +++ /dev/null @@ -1,23 +0,0 @@ - --- User Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_User_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_user INTEGER, - CONSTRAINT FK_Shop_User_Audit_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(255), - value_new VARCHAR(255), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_User_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - ON UPDATE RESTRICT -); \ No newline at end of file diff --git a/static/PostgreSQL/163_tbl_Shop_User_Role_Link.sql b/static/PostgreSQL/163_tbl_Shop_User_Role_Link.sql deleted file mode 100644 index 55b92c30..00000000 --- a/static/PostgreSQL/163_tbl_Shop_User_Role_Link.sql +++ /dev/null @@ -1,26 +0,0 @@ - --- User Role link - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Role_Link'; - -CREATE TABLE IF NOT EXISTS Shop_User_Role_Link ( - id_link INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_user INTEGER, - CONSTRAINT FK_Shop_User_Role_Link_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user) - ON UPDATE RESTRICT, - id_role INTEGER NOT NULL, - CONSTRAINT FK_Shop_User_Role_Link_id_role - FOREIGN KEY (id_role) - REFERENCES Shop_Role(id_role), - active BOOLEAN NOT NULL DEFAULT TRUE, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_User_Role_Link_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/PostgreSQL/164_tbl_Shop_User_Role_Link_Audit.sql b/static/PostgreSQL/164_tbl_Shop_User_Role_Link_Audit.sql deleted file mode 100644 index 3d5a4d38..00000000 --- a/static/PostgreSQL/164_tbl_Shop_User_Role_Link_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- User Role Link Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Role_Link_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_User_Role_Link_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_link INTEGER NOT NULL, - CONSTRAINT FK_Shop_User_Role_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_User_Role_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(200), - value_new VARCHAR(200), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_User_Role_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); diff --git a/static/PostgreSQL/165_tbl_Shop_Address.sql b/static/PostgreSQL/165_tbl_Shop_Address.sql deleted file mode 100644 index 01024659..00000000 --- a/static/PostgreSQL/165_tbl_Shop_Address.sql +++ /dev/null @@ -1,33 +0,0 @@ - --- Addresses - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Address'; - -CREATE TABLE Shop_Address ( - id_address INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - /* - a_id_user INTEGER, - CONSTRAINT FK_Shop_Address_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user) - ON UPDATE RESTRICT, - */ - -- region VARCHAR(100) NOT NULL, - id_region INTEGER NOT NULL, - name_full VARCHAR(255) NOT NULL, - phone_number VARCHAR(20) NOT NULL, - postcode VARCHAR(20) NOT NULL, - address_line_1 VARCHAR(100) NOT NULL, - address_line_2 VARCHAR(100) NOT NULL, - city VARCHAR(50) NOT NULL, - county VARCHAR(100) NOT NULL, - active BOOLEAN NOT NULL DEFAULT TRUE, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Address_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/PostgreSQL/166_tbl_Shop_Address_Audit.sql b/static/PostgreSQL/166_tbl_Shop_Address_Audit.sql deleted file mode 100644 index 948a70c3..00000000 --- a/static/PostgreSQL/166_tbl_Shop_Address_Audit.sql +++ /dev/null @@ -1,23 +0,0 @@ - --- Address Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Address_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Address_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_address INTEGER NOT NULL, - CONSTRAINT FK_Shop_Address_Audit_id_address - FOREIGN KEY (id_address) - REFERENCES Shop_Address(id_address) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(255), - value_new VARCHAR(255), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Address_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) - ON UPDATE RESTRICT -); \ No newline at end of file diff --git a/static/PostgreSQL/167_tbl_Shop_User_Basket.sql b/static/PostgreSQL/167_tbl_Shop_User_Basket.sql deleted file mode 100644 index 4dcbf836..00000000 --- a/static/PostgreSQL/167_tbl_Shop_User_Basket.sql +++ /dev/null @@ -1,39 +0,0 @@ - --- User Basket (Product Link) - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Basket'; - -CREATE TABLE IF NOT EXISTS Shop_User_Basket ( - id_item INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_user INTEGER, - CONSTRAINT FK_Shop_User_Basket_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user) - ON UPDATE RESTRICT, - id_product INTEGER NOT NULL, - CONSTRAINT FK_Shop_User_Basket_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product) - ON UPDATE RESTRICT, - id_permutation INTEGER, - CONSTRAINT FK_Shop_User_Basket_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation) - ON UPDATE RESTRICT, - quantity INTEGER NOT NULL, - active BOOLEAN NOT NULL DEFAULT TRUE, - created_on TIMESTAMP, - created_by INT, - id_change_set_user INTEGER, - CONSTRAINT FK_Shop_User_Basket_id_change_set_user - FOREIGN KEY (id_change_set_user) - REFERENCES Shop_User_Change_Set(id_change_set) - /* - id_change_set_product INTEGER, - CONSTRAINT FK_Shop_User_Basket_id_change_set_product - FOREIGN KEY (id_change_set_product) - REFERENCES Shop_Product_Change_Set(id_change_set) - */ -); diff --git a/static/PostgreSQL/168_tbl_Shop_User_Basket_Audit.sql b/static/PostgreSQL/168_tbl_Shop_User_Basket_Audit.sql deleted file mode 100644 index 7c512907..00000000 --- a/static/PostgreSQL/168_tbl_Shop_User_Basket_Audit.sql +++ /dev/null @@ -1,27 +0,0 @@ - --- Product Basket Audits - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Basket_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_User_Basket_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_item INTEGER NOT NULL, - CONSTRAINT FK_Shop_User_Basket_Audit_id_link - FOREIGN KEY (id_item) - REFERENCES Shop_User_Basket(id_item) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(200), - value_new VARCHAR(200), - id_change_set_user INTEGER, - CONSTRAINT FK_Shop_User_Basket_Audit_id_change_set_user - FOREIGN KEY (id_change_set_user) - REFERENCES Shop_User_Change_Set(id_change_set) - /* - id_change_set_product INTEGER, - CONSTRAINT FK_Shop_User_Basket_Audit_id_change_set_product - FOREIGN KEY (id_change_set_product) - REFERENCES Shop_Product_Change_Set(id_change_set) - */ -); diff --git a/static/PostgreSQL/169_tbl_Shop_User_Order_Status.sql b/static/PostgreSQL/169_tbl_Shop_User_Order_Status.sql deleted file mode 100644 index 0a51f5b9..00000000 --- a/static/PostgreSQL/169_tbl_Shop_User_Order_Status.sql +++ /dev/null @@ -1,21 +0,0 @@ - --- User Order Types - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Order_Status'; - -CREATE TABLE IF NOT EXISTS Shop_User_Order_Status ( - id_status INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - code VARCHAR(50), - name VARCHAR(255), - name_plural VARCHAR(256), - active BOOLEAN NOT NULL DEFAULT TRUE, - display_order INTEGER NOT NULL, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_User_Order_Status_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); diff --git a/static/PostgreSQL/170_tbl_Shop_User_Order_Status_Audit.sql b/static/PostgreSQL/170_tbl_Shop_User_Order_Status_Audit.sql deleted file mode 100644 index 25dbb368..00000000 --- a/static/PostgreSQL/170_tbl_Shop_User_Order_Status_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Order Type Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_User_Order_Status_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_User_Order_Status_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_status INTEGER NOT NULL, - CONSTRAINT FK_Shop_User_Order_Status_Audit_id_status - FOREIGN KEY (id_status) - REFERENCES Shop_User_Order_Status(id_status) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(256), - value_new VARCHAR(256), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_User_Order_Status_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); \ No newline at end of file diff --git a/static/PostgreSQL/181.0_tbl_Shop_Supplier.sql b/static/PostgreSQL/181.0_tbl_Shop_Supplier.sql deleted file mode 100644 index 6f45d42f..00000000 --- a/static/PostgreSQL/181.0_tbl_Shop_Supplier.sql +++ /dev/null @@ -1,32 +0,0 @@ - --- Supplier - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Supplier'; - -CREATE TABLE IF NOT EXISTS Shop_Supplier ( - id_supplier INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - name_company VARCHAR(255) NOT NULL, - name_contact VARCHAR(255) NULL, - department_contact VARCHAR(255) NULL, - id_address INTEGER NOT NULL, - CONSTRAINT FK_Shop_Supplier_id_address - FOREIGN KEY (id_address) - REFERENCES Shop_Address(id_address), - phone_number VARCHAR(50) NULL, - fax VARCHAR(50) NULL, - email VARCHAR(255) NOT NULL, - website VARCHAR(255) NULL, - id_currency INTEGER NOT NULL, - CONSTRAINT FK_Shop_Supplier_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency), - active BOOLEAN NOT NULL DEFAULT TRUE, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Supplier_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); diff --git a/static/PostgreSQL/181.1_tbl_Shop_Supplier_Audit.sql b/static/PostgreSQL/181.1_tbl_Shop_Supplier_Audit.sql deleted file mode 100644 index ca866eea..00000000 --- a/static/PostgreSQL/181.1_tbl_Shop_Supplier_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Supplier Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Supplier_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Supplier_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_supplier INTEGER NOT NULL, - CONSTRAINT FK_Shop_Supplier_Audit_id_supplier - FOREIGN KEY (id_supplier) - REFERENCES Shop_Supplier(id_supplier) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(255), - value_new VARCHAR(255), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Supplier_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_User_Change_Set(id_change_set) -); diff --git a/static/PostgreSQL/181.2_tbl_Shop_Unit_Measurement.sql b/static/PostgreSQL/181.2_tbl_Shop_Unit_Measurement.sql deleted file mode 100644 index f26169fc..00000000 --- a/static/PostgreSQL/181.2_tbl_Shop_Unit_Measurement.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Unit of Measurement - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Unit_Measurement'; - -CREATE TABLE IF NOT EXISTS Shop_Unit_Measurement ( - id_unit_measurement INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - name_singular VARCHAR(255) NOT NULL, - name_plural VARCHAR(256) NOT NULL, - symbol VARCHAR(50) NOT NULL, - is_base_unit BOOLEAN NOT NULL DEFAULT FALSE, - - active BOOLEAN NOT NULL DEFAULT TRUE, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Unit_Measurement_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/PostgreSQL/181.3_tbl_Shop_Unit_Measurement_Audit.sql b/static/PostgreSQL/181.3_tbl_Shop_Unit_Measurement_Audit.sql deleted file mode 100644 index 9ee19084..00000000 --- a/static/PostgreSQL/181.3_tbl_Shop_Unit_Measurement_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Unit of Measurement Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Unit_Measurement_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Unit_Measurement_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_unit_measurement INTEGER NOT NULL, - CONSTRAINT FK_Shop_Unit_Measurement_Audit_id_unit_measurement - FOREIGN KEY (id_unit_measurement) - REFERENCES Shop_Unit_Measurement(id_unit_measurement) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(256), - value_new VARCHAR(256), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Unit_Measurement_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/PostgreSQL/181.4_tbl_Shop_Unit_Measurement_Conversion.sql b/static/PostgreSQL/181.4_tbl_Shop_Unit_Measurement_Conversion.sql deleted file mode 100644 index fafb6fd3..00000000 --- a/static/PostgreSQL/181.4_tbl_Shop_Unit_Measurement_Conversion.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Unit of Measurement Conversion - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Unit_Measurement_Conversion'; - -CREATE TABLE IF NOT EXISTS Shop_Unit_Measurement_Conversion ( - id_conversion INTEGER NOT NULL PRIMARY KEY, - id_unit_derived INTEGER NOT NULL, - id_unit_base INTEGER NOT NULL, - power_unit_base REAL NOT NULL, - multiplier_unit_base REAL NOT NULL, - increment_unit_base REAL NOT NULL, - active BOOLEAN NOT NULL DEFAULT TRUE, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Unit_Measurement_Conversion_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/PostgreSQL/181.5_tbl_Shop_Unit_Measurement_Conversion_Audit.sql b/static/PostgreSQL/181.5_tbl_Shop_Unit_Measurement_Conversion_Audit.sql deleted file mode 100644 index 6ec246ff..00000000 --- a/static/PostgreSQL/181.5_tbl_Shop_Unit_Measurement_Conversion_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Unit of Measurement Conversion Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Unit_Measurement_Conversion_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Unit_Measurement_Conversion_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_conversion INTEGER NOT NULL, - CONSTRAINT FK_Shop_Unit_Measurement_Conversion_Audit_id_conversion - FOREIGN KEY (id_conversion) - REFERENCES Shop_Unit_Measurement_Conversion(id_conversion) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(100), - value_new VARCHAR(100), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Unit_Measurement_Conversion_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Product_Change_Set(id_change_set) -); diff --git a/static/PostgreSQL/181.6_tbl_Shop_Supplier_Purchase_Order.sql b/static/PostgreSQL/181.6_tbl_Shop_Supplier_Purchase_Order.sql deleted file mode 100644 index a36cfa4c..00000000 --- a/static/PostgreSQL/181.6_tbl_Shop_Supplier_Purchase_Order.sql +++ /dev/null @@ -1,41 +0,0 @@ - --- Supplier Purchase Order - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Supplier_Purchase_Order'; - -CREATE TABLE IF NOT EXISTS Shop_Supplier_Purchase_Order ( - id_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_supplier_ordered INTEGER NOT NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_id_supplier_ordered - FOREIGN KEY (id_supplier_ordered) - REFERENCES Shop_Supplier(id_supplier), - /* - id_supplier_fulfilled INTEGER NOT NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_id_supplier_fulfilled - FOREIGN KEY (id_supplier_fulfilled) - REFERENCES Shop_Supplier(id_supplier), - */ - cost_total_local REAL NOT NULL, - id_currency_cost INTEGER NOT NULL, - /* - latency_delivery INTEGER NOT NULL, - quantity_ordered REAL NOT NULL, - id_unit_quantity INTEGER NOT NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit), - -- quantity_received INTEGER NULL, - display_order INTEGER NOT NULL, - */ - active BOOLEAN NOT NULL DEFAULT TRUE, - created_on TIMESTAMP, - created_by INT, - updated_last_on TIMESTAMP NULL, - created_last_by VARCHAR(100) NULL, - id_change_set INTEGER NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); diff --git a/static/PostgreSQL/181.7_tbl_Shop_Supplier_Purchase_Order_Audit.sql b/static/PostgreSQL/181.7_tbl_Shop_Supplier_Purchase_Order_Audit.sql deleted file mode 100644 index 2b303dce..00000000 --- a/static/PostgreSQL/181.7_tbl_Shop_Supplier_Purchase_Order_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Supplier Purchase Order Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Supplier_Purchase_Order_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Supplier_Purchase_Order_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_order INTEGER NOT NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_Audit_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Supplier_Purchase_Order(id_order) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(10), - value_new VARCHAR(10), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); diff --git a/static/PostgreSQL/181.8_tbl_Shop_Supplier_Purchase_Order_Product_Link.sql b/static/PostgreSQL/181.8_tbl_Shop_Supplier_Purchase_Order_Product_Link.sql deleted file mode 100644 index 0dbd93eb..00000000 --- a/static/PostgreSQL/181.8_tbl_Shop_Supplier_Purchase_Order_Product_Link.sql +++ /dev/null @@ -1,37 +0,0 @@ - --- Supplier Purchase Order Product Link - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Supplier_Purchase_Order_Product_Link'; - -CREATE TABLE IF NOT EXISTS Shop_Supplier_Purchase_Order_Product_Link ( - id_link INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_order INTEGER NOT NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_Product_Link_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Supplier_Purchase_Order(id_order), - id_permutation INTEGER NOT NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_Product_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - cost_total_local REAL NOT NULL, - id_currency_cost INTEGER NOT NULL, - quantity_ordered REAL NOT NULL, - id_unit_quantity INTEGER NOT NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_Product_Link_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - quantity_received REAL NULL, - latency_delivery_days INTEGER NOT NULL, - display_order INTEGER NOT NULL, - active BOOLEAN NOT NULL, - created_on TIMESTAMP, - created_by INT, - updated_last_on TIMESTAMP NULL, - created_last_by VARCHAR(100) NULL, - id_change_set INTEGER NULL, - CONSTRAINT FK_Shop_Supplier_Purchase_Order_Product_Link_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); diff --git a/static/PostgreSQL/181.9_tbl_Shop_Supplier_Purchase_Order_Product_Link_Audit.sql b/static/PostgreSQL/181.9_tbl_Shop_Supplier_Purchase_Order_Product_Link_Audit.sql deleted file mode 100644 index 66520dfa..00000000 --- a/static/PostgreSQL/181.9_tbl_Shop_Supplier_Purchase_Order_Product_Link_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Supplier Purchase Order Product Link Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Supplier_Purchase_Order_Product_Link_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Supplier_Purchase_Order_Product_Link_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_link INTEGER NOT NULL, - CONSTRAINT FK_Supplier_Purch_Order_Product_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Supplier_Purchase_Order_Product_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(10), - value_new VARCHAR(10), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Supplier_Purch_Order_Product_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); diff --git a/static/PostgreSQL/182.0_tbl_Shop_Supplier_Purchase_Order_Product_Link_Temp.sql b/static/PostgreSQL/182.0_tbl_Shop_Supplier_Purchase_Order_Product_Link_Temp.sql deleted file mode 100644 index d088fbb0..00000000 --- a/static/PostgreSQL/182.0_tbl_Shop_Supplier_Purchase_Order_Product_Link_Temp.sql +++ /dev/null @@ -1,34 +0,0 @@ - --- Supplier Purchase Order Product Link Temp - - - --- drop table Shop_Supplier_Purchase_Order_Product_Link_Temp; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Supplier_Purchase_Order_Product_Link_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Supplier_Purchase_Order_Product_Link_Temp ( - id_link INTEGER NOT NULL PRIMARY KEY, - GUID UUID NOT NULL, - id_order INTEGER NOT NULL, - /* - CONSTRAINT FK_Supplier_Purchase_Order_Product_Link_Temp_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Supplier_Purchase_Order(id_order), - */ - id_permutation INTEGER NOT NULL, - CONSTRAINT FK_Supplier_Purchase_Order_Product_Link_Temp_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - cost_total_local REAL NOT NULL, - id_currency_cost INTEGER NOT NULL, - quantity_ordered REAL NOT NULL, - id_unit_quantity INTEGER NOT NULL, - CONSTRAINT FK_Supplier_Purchase_Order_Product_Link_Temp_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - quantity_received REAL NULL, - latency_delivery_days INTEGER NOT NULL, - display_order INTEGER NOT NULL, - active BOOLEAN NOT NULL -); diff --git a/static/PostgreSQL/183_tbl_Shop_Manufacturing_Purchase_Order.sql b/static/PostgreSQL/183_tbl_Shop_Manufacturing_Purchase_Order.sql deleted file mode 100644 index 0870e058..00000000 --- a/static/PostgreSQL/183_tbl_Shop_Manufacturing_Purchase_Order.sql +++ /dev/null @@ -1,33 +0,0 @@ - - --- Manufacturing Purchase Order - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Manufacturing_Purchase_Order'; - -CREATE TABLE IF NOT EXISTS Shop_Manufacturing_Purchase_Order ( - id_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - cost_total_local REAL NOT NULL, - id_currency_cost INTEGER NOT NULL, - value_produced_total_local REAL NOT NULL, - /* - latency_delivery INTEGER NOT NULL, - quantity_ordered REAL NOT NULL, - id_unit_quantity INTEGER NOT NULL, - CONSTRAINT FK_Shop_Manufacturing_Purchase_Order_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit), - quantity_received INTEGER NULL, - display_order INTEGER NOT NULL, - */ - active BOOLEAN NOT NULL DEFAULT TRUE, - created_on TIMESTAMP, - created_by INT, - updated_last_on TIMESTAMP NULL, - created_last_by VARCHAR(100) NULL, - id_change_set INTEGER NULL, - CONSTRAINT FK_Shop_Manufacturing_Purchase_Order_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); diff --git a/static/PostgreSQL/184_tbl_Shop_Manufacturing_Purchase_Order_Audit.sql b/static/PostgreSQL/184_tbl_Shop_Manufacturing_Purchase_Order_Audit.sql deleted file mode 100644 index d50b5156..00000000 --- a/static/PostgreSQL/184_tbl_Shop_Manufacturing_Purchase_Order_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Manufacturing Purchase Order Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Manufacturing_Purchase_Order_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Manufacturing_Purchase_Order_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_order INTEGER NOT NULL, - CONSTRAINT FK_Shop_Manufacturing_Purchase_Order_Audit_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Manufacturing_Purchase_Order(id_order) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(10), - value_new VARCHAR(10), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Manufacturing_Purchase_Order_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); diff --git a/static/PostgreSQL/185_tbl_Shop_Manufacturing_Purchase_Order_Product_Link.sql b/static/PostgreSQL/185_tbl_Shop_Manufacturing_Purchase_Order_Product_Link.sql deleted file mode 100644 index 6ff6f469..00000000 --- a/static/PostgreSQL/185_tbl_Shop_Manufacturing_Purchase_Order_Product_Link.sql +++ /dev/null @@ -1,38 +0,0 @@ - --- Manufacturing Purchase Order Product Link - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Manufacturing_Purchase_Order_Product_Link'; - -CREATE TABLE IF NOT EXISTS Shop_Manufacturing_Purchase_Order_Product_Link ( - id_link INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_order INTEGER NOT NULL, - CONSTRAINT FK_Manufacturing_Purchase_Order_Product_Link_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Manufacturing_Purchase_Order(id_order), - id_permutation INTEGER NOT NULL, - CONSTRAINT FK_Manufacturing_Purchase_Order_Product_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - cost_total_local REAL NOT NULL, - id_currency_cost INTEGER NOT NULL, - value_produced_total_local REAL NOT NULL, - quantity_used REAL NOT NULL, - id_unit_quantity INTEGER NOT NULL, - CONSTRAINT FK_Manufacturing_Purchase_Order_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - latency_manufacture INTEGER NOT NULL, - quantity_produced REAL NOT NULL, - display_order INTEGER NOT NULL, - active BOOLEAN NOT NULL, - created_on TIMESTAMP, - created_by INT, - updated_last_on TIMESTAMP NULL, - created_last_by VARCHAR(100) NULL, - id_change_set INTEGER NULL, - CONSTRAINT FK_Manufacturing_Purchase_Order_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); diff --git a/static/PostgreSQL/186.1_tbl_Shop_Manufacturing_Purchase_Order_Product_Link_Temp.sql b/static/PostgreSQL/186.1_tbl_Shop_Manufacturing_Purchase_Order_Product_Link_Temp.sql deleted file mode 100644 index 7237a1aa..00000000 --- a/static/PostgreSQL/186.1_tbl_Shop_Manufacturing_Purchase_Order_Product_Link_Temp.sql +++ /dev/null @@ -1,35 +0,0 @@ - --- Manufacturing Purchase Order Product Link Temp - - - --- DROP TABLE Shop_Manufacturing_Purchase_Order_Product_Link_Temp; --- SELECT * FROM Shop_Manufacturing_Purchase_Order_Product_Link_Temp; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Manufacturing_Purchase_Order_Product_Link_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Manufacturing_Purchase_Order_Product_Link_Temp ( - id_link INTEGER NOT NULL PRIMARY KEY, - GUID UUID NOT NULL, - id_order INTEGER NOT NULL, - /* - CONSTRAINT FK_Manuf_Purch_Order_Product_Link_Temp_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Manufacturing_Purchase_Order(id_order), - */ - id_permutation INTEGER NOT NULL, - CONSTRAINT FK_Manuf_Purch_Order_Product_Link_Temp_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - cost_total_local REAL NOT NULL, - id_currency_cost INTEGER NOT NULL, - quantity_used REAL NOT NULL, - id_unit_quantity INTEGER NOT NULL, - CONSTRAINT FK_Manuf_Purch_Order_Product_Link_Temp_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - quantity_produced REAL NULL, - latency_manufacture INTEGER NOT NULL, - display_order INTEGER NOT NULL, - active BOOLEAN NOT NULL -); diff --git a/static/PostgreSQL/186_tbl_Shop_Manufacturing_Purchase_Order_Product_Link_Audit.sql b/static/PostgreSQL/186_tbl_Shop_Manufacturing_Purchase_Order_Product_Link_Audit.sql deleted file mode 100644 index f6507628..00000000 --- a/static/PostgreSQL/186_tbl_Shop_Manufacturing_Purchase_Order_Product_Link_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Manufacturing Purchase Order Product Link Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Manufacturing_Purchase_Order_Product_Link_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Manufacturing_Purchase_Order_Product_Link_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_link INTEGER NOT NULL, - CONSTRAINT FK_Manufacturing_Purch_Order_Product_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Manufacturing_Purchase_Order_Product_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(10), - value_new VARCHAR(10), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Manufacturing_Purch_Order_Product_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); diff --git a/static/PostgreSQL/187.0_tbl_Shop_Customer.sql b/static/PostgreSQL/187.0_tbl_Shop_Customer.sql deleted file mode 100644 index 39ecf58d..00000000 --- a/static/PostgreSQL/187.0_tbl_Shop_Customer.sql +++ /dev/null @@ -1,29 +0,0 @@ --- Customer - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Customer'; - -CREATE TABLE IF NOT EXISTS Shop_Customer ( - id_customer INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - name_company VARCHAR(255) NOT NULL, - name_contact VARCHAR(255) NULL, - department_contact VARCHAR(255) NULL, - id_address INTEGER NOT NULL, - CONSTRAINT FK_Shop_Customer_id_address - FOREIGN KEY (id_address) - REFERENCES Shop_Address(id_address), - phone_number VARCHAR(50) NULL, - email VARCHAR(255) NOT NULL, - id_currency INTEGER NOT NULL, - CONSTRAINT FK_Shop_Customer_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency), - active BOOLEAN NOT NULL DEFAULT TRUE, - created_on TIMESTAMP, - created_by INT, - id_change_set INTEGER, - CONSTRAINT FK_Shop_Customer_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); diff --git a/static/PostgreSQL/187.1_tbl_Shop_Customer_Audit.sql b/static/PostgreSQL/187.1_tbl_Shop_Customer_Audit.sql deleted file mode 100644 index 5ed1e9ca..00000000 --- a/static/PostgreSQL/187.1_tbl_Shop_Customer_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Customer Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Customer_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Customer_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_customer INTEGER NOT NULL, - CONSTRAINT FK_Shop_Customer_Audit_id_customer - FOREIGN KEY (id_customer) - REFERENCES Shop_Customer(id_customer) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(255), - value_new VARCHAR(255), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Customer_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); diff --git a/static/PostgreSQL/187.2_tbl_Shop_Customer_Sales_Order.sql b/static/PostgreSQL/187.2_tbl_Shop_Customer_Sales_Order.sql deleted file mode 100644 index ab831c86..00000000 --- a/static/PostgreSQL/187.2_tbl_Shop_Customer_Sales_Order.sql +++ /dev/null @@ -1,35 +0,0 @@ - --- Customer Sales Purchase Order - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Customer_Sales_Order'; - -CREATE TABLE IF NOT EXISTS Shop_Customer_Sales_Order ( - id_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_customer INTEGER NOT NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_id_customer - FOREIGN KEY (id_customer) - REFERENCES Shop_Customer(id_customer), - price_total_local REAL NOT NULL, - id_currency_price INTEGER NOT NULL, - /* - latency_delivery INTEGER NOT NULL, - quantity_ordered REAL NOT NULL, - id_unit_quantity INTEGER NOT NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit), - quantity_received INTEGER NULL, - display_order INTEGER NOT NULL, - */ - active BOOLEAN NOT NULL DEFAULT TRUE, - created_on TIMESTAMP, - created_by INT, - updated_last_on TIMESTAMP NULL, - created_last_by VARCHAR(100) NULL, - id_change_set INTEGER NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); diff --git a/static/PostgreSQL/188_tbl_Shop_Customer_Sales_Order_Audit.sql b/static/PostgreSQL/188_tbl_Shop_Customer_Sales_Order_Audit.sql deleted file mode 100644 index ff12450c..00000000 --- a/static/PostgreSQL/188_tbl_Shop_Customer_Sales_Order_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Customer Sales Order Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Customer_Sales_Order_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Customer_Sales_Order_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_order INTEGER NOT NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_Audit_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Customer_Sales_Order(id_order) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(10), - value_new VARCHAR(10), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); diff --git a/static/PostgreSQL/189_tbl_Shop_Customer_Sales_Order_Product_Link.sql b/static/PostgreSQL/189_tbl_Shop_Customer_Sales_Order_Product_Link.sql deleted file mode 100644 index 058f16b7..00000000 --- a/static/PostgreSQL/189_tbl_Shop_Customer_Sales_Order_Product_Link.sql +++ /dev/null @@ -1,38 +0,0 @@ - --- Customer Sales Order Product Link - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Customer_Sales_Order_Product_Link'; - -CREATE TABLE IF NOT EXISTS Shop_Customer_Sales_Order_Product_Link ( - id_link INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_order INTEGER NOT NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_Product_Link_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Customer_Sales_Order(id_order), - id_permutation INTEGER NOT NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_Product_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - price_total_local REAL NOT NULL, - id_currency_price INTEGER NOT NULL, - quantity_ordered REAL NOT NULL, - id_unit_quantity INTEGER NOT NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_Product_Link_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - quantity_delivered REAL NOT NULL, - latency_delivery_days INTEGER NOT NULL, - display_order INTEGER NOT NULL, - - active BOOLEAN NOT NULL, - created_on TIMESTAMP, - created_by INT, - updated_last_on TIMESTAMP NULL, - created_last_by VARCHAR(100) NULL, - id_change_set INTEGER NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_Product_Link_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); diff --git a/static/PostgreSQL/190_tbl_Shop_Customer_Sales_Order_Product_Link_Audit.sql b/static/PostgreSQL/190_tbl_Shop_Customer_Sales_Order_Product_Link_Audit.sql deleted file mode 100644 index a2da163b..00000000 --- a/static/PostgreSQL/190_tbl_Shop_Customer_Sales_Order_Product_Link_Audit.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Customer Sales Order Product Link Audits - - - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Customer_Sales_Order_Product_Link_Audit'; - -CREATE TABLE IF NOT EXISTS Shop_Customer_Sales_Order_Product_Link_Audit ( - id_audit INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_link INTEGER NOT NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_Product_Link_Audit_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Customer_Sales_Order_Product_Link(id_link) - ON UPDATE RESTRICT, - name_field VARCHAR(50), - value_prev VARCHAR(10), - value_new VARCHAR(10), - id_change_set INTEGER NOT NULL, - CONSTRAINT FK_Shop_Customer_Sales_Order_Product_Link_Audit_id_change_set - FOREIGN KEY (id_change_set) - REFERENCES Shop_Sales_And_Purchasing_Change_Set(id_change_set) -); diff --git a/static/PostgreSQL/191_tbl_Shop_Customer_Sales_Order_Product_Link_Temp.sql b/static/PostgreSQL/191_tbl_Shop_Customer_Sales_Order_Product_Link_Temp.sql deleted file mode 100644 index 3a6e352c..00000000 --- a/static/PostgreSQL/191_tbl_Shop_Customer_Sales_Order_Product_Link_Temp.sql +++ /dev/null @@ -1,34 +0,0 @@ - --- Customer Sales Order Product Link Temp - - - --- DROP TABLE Shop_Customer_Sales_Order_Product_Link_Temp; - -SELECT CONCAT('WARNING: Table ', TABLE_NAME, ' already exists.') AS msg_warning FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Shop_Customer_Sales_Order_Product_Link_Temp'; - -CREATE TABLE IF NOT EXISTS Shop_Customer_Sales_Order_Product_Link_Temp ( - id_link INTEGER NOT NULL PRIMARY KEY, - GUID UUID NOT NULL, - id_order INTEGER NOT NULL, - /* - CONSTRAINT FK_Customer_Sales_Order_Product_Link_Temp_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Customer_Sales_Order(id_order), - */ - id_permutation INTEGER NOT NULL, - CONSTRAINT FK_Customer_Sales_Order_Product_Link_Temp_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - price_total_local REAL NOT NULL, - id_currency_price INTEGER NOT NULL, - quantity_ordered REAL NOT NULL, - id_unit_quantity INTEGER NOT NULL, - CONSTRAINT FK_Customer_Sales_Order_Product_Link_Temp_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - quantity_delivered REAL NULL, - latency_delivery_days INTEGER NOT NULL, - display_order INTEGER NOT NULL, - active BOOLEAN NOT NULL -); diff --git a/static/PostgreSQL/300.2_tri_Shop_Sales_And_Purchasing_Change_Set.sql b/static/PostgreSQL/300.2_tri_Shop_Sales_And_Purchasing_Change_Set.sql deleted file mode 100644 index 044661bf..00000000 --- a/static/PostgreSQL/300.2_tri_Shop_Sales_And_Purchasing_Change_Set.sql +++ /dev/null @@ -1,26 +0,0 @@ - -DO $$ -BEGIN - RAISE NOTICE 'TABLE CREATION COMPLETE'; -END $$; - --- Product Change Set - -CREATE OR REPLACE FUNCTION before_insert_Shop_Sales_And_Purchasing_Change_Set() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.updated_last_on IS NULL THEN - NEW.updated_last_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.updated_last_by IS NULL THEN - NEW.updated_last_by = CURRENT_USER; - END IF; - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Sales_And_Purchasing_Change_Set -BEFORE INSERT ON Shop_Sales_And_Purchasing_Change_Set -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Sales_And_Purchasing_Change_Set(); - diff --git a/static/PostgreSQL/301.1_tri_Shop_User_Change_Set.sql b/static/PostgreSQL/301.1_tri_Shop_User_Change_Set.sql deleted file mode 100644 index 0e5fdb16..00000000 --- a/static/PostgreSQL/301.1_tri_Shop_User_Change_Set.sql +++ /dev/null @@ -1,20 +0,0 @@ - --- Shop User Change Set - -CREATE OR REPLACE FUNCTION before_insert_Shop_User_Change_Set() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.updated_last_on IS NULL THEN - NEW.updated_last_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.updated_last_by IS NULL THEN - NEW.updated_last_by = CURRENT_USER; - END IF; - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_User_Change_Set -BEFORE INSERT ON Shop_User_Change_Set -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_User_Change_Set(); diff --git a/static/PostgreSQL/301.2_tri_Shop_Access_Level.sql b/static/PostgreSQL/301.2_tri_Shop_Access_Level.sql deleted file mode 100644 index d4175132..00000000 --- a/static/PostgreSQL/301.2_tri_Shop_Access_Level.sql +++ /dev/null @@ -1,66 +0,0 @@ - --- Shop Access Level - -CREATE OR REPLACE FUNCTION before_insert_Shop_Access_Level() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Access_Level -BEFORE INSERT ON Shop_Access_Level -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Access_Level(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Access_Level() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Access_Level_Audit ( - id_access_level, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_access_level, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT (OLD.code <=> NEW.code) - UNION - -- Changed name - SELECT NEW.id_access_level, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT (OLD.name <=> NEW.name) - UNION - -- Changed priority - SELECT NEW.id_access_level, 'priority', CONVERT(OLD.priority, CHAR), CONVERT(NEW.priority, CHAR), NEW.id_change_set - WHERE NOT (OLD.priority <=> NEW.priority) - UNION - -- Changed active - SELECT NEW.id_access_level, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_access_level, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Access_Level -BEFORE UPDATE ON Shop_Access_Level -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Access_Level(); diff --git a/static/PostgreSQL/301_tri_Shop_Product_Change_Set.sql b/static/PostgreSQL/301_tri_Shop_Product_Change_Set.sql deleted file mode 100644 index d2a67f54..00000000 --- a/static/PostgreSQL/301_tri_Shop_Product_Change_Set.sql +++ /dev/null @@ -1,22 +0,0 @@ - --- Product Change Set - - - -CREATE OR REPLACE FUNCTION before_insert_Shop_Product_Change_Set() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.updated_last_on IS NULL THEN - NEW.updated_last_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.updated_last_by IS NULL THEN - NEW.updated_last_by = CURRENT_USER; - END IF; - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Product_Change_Set -BEFORE INSERT ON Shop_Product_Change_Set -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Product_Change_Set(); diff --git a/static/PostgreSQL/302_tri_File_Type.sql b/static/PostgreSQL/302_tri_File_Type.sql deleted file mode 100644 index 4eacb9a8..00000000 --- a/static/PostgreSQL/302_tri_File_Type.sql +++ /dev/null @@ -1,48 +0,0 @@ - --- File Type - -CREATE OR REPLACE FUNCTION before_insert_File_Type() -RETURNS TRIGGER AS $$ -BEGIN - NEW.created_on = CURRENT_TIMESTAMP; - NEW.created_by = CURRENT_USER; - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_File_Type -BEFORE INSERT ON File_Type -FOR EACH ROW -EXECUTE FUNCTION before_insert_File_Type(); - - -CREATE OR REPLACE FUNCTION before_update_File_Type() -RETURNS TRIGGER AS $$ -BEGIN - INSERT INTO File_Type_Audit ( - id_type, - name_field, - value_prev, - value_new - ) - -- Changed code - SELECT NEW.id_type, 'code', OLD.code, NEW.code - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_type, 'name', OLD.name, NEW.name - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed extension - SELECT NEW.id_type, 'extension', CONVERT(OLD.extension, CHAR), CONVERT(NEW.extension, CHAR) - WHERE NOT OLD.extension <=> NEW.extension - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_File_Type -BEFORE UPDATE ON File_Type -FOR EACH ROW -EXECUTE FUNCTION before_update_File_Type(); diff --git a/static/PostgreSQL/303_tri_File_Type_Audit.sql b/static/PostgreSQL/303_tri_File_Type_Audit.sql deleted file mode 100644 index 7c8ba354..00000000 --- a/static/PostgreSQL/303_tri_File_Type_Audit.sql +++ /dev/null @@ -1,33 +0,0 @@ - --- File Type Audits - -CREATE OR REPLACE FUNCTION before_insert_File_Type_Audit() -RETURNS TRIGGER AS $$ -BEGIN - NEW.created_on = CURRENT_TIMESTAMP; - NEW.created_by = CURRENT_USER; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_File_Type_Audit -BEFORE INSERT ON File_Type_Audit -FOR EACH ROW -EXECUTE FUNCTION before_insert_File_Type_Audit(); - - -CREATE OR REPLACE FUNCTION before_update_File_Type_Audit() -RETURNS TRIGGER AS $$ -BEGIN - NEW.updated_last_on = CURRENT_TIMESTAMP; - NEW.updated_last_by = CURRENT_USER; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_File_Type_Audit -BEFORE UPDATE ON File_Type_Audit -FOR EACH ROW -EXECUTE FUNCTION before_update_File_Type_Audit(); \ No newline at end of file diff --git a/static/PostgreSQL/304_tri_Shop_General.sql b/static/PostgreSQL/304_tri_Shop_General.sql deleted file mode 100644 index 3628912b..00000000 --- a/static/PostgreSQL/304_tri_Shop_General.sql +++ /dev/null @@ -1,47 +0,0 @@ - --- Shop General - -CREATE OR REPLACE FUNCTION before_insert_Shop_General() -RETURNS TRIGGER AS $$ -BEGIN - NEW.created_on = CURRENT_TIMESTAMP; - NEW.created_by = CURRENT_USER; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_General -BEFORE INSERT ON Shop_General -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_General(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_General() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_General_Audit ( - id_general, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed quantity max - SELECT NEW.id_general, 'quantity_max', CONVERT(OLD.quantity_max, CHAR), CONVERT(NEW.quantity_max, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_General -BEFORE UPDATE ON Shop_General -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_General(); \ No newline at end of file diff --git a/static/PostgreSQL/306_tri_Shop_Category.sql b/static/PostgreSQL/306_tri_Shop_Category.sql deleted file mode 100644 index 727212ba..00000000 --- a/static/PostgreSQL/306_tri_Shop_Category.sql +++ /dev/null @@ -1,63 +0,0 @@ - --- Shop Category - -CREATE OR REPLACE FUNCTION before_insert_Shop_Product_Category() -RETURNS TRIGGER AS $$ -BEGIN - NEW.created_on = CURRENT_TIMESTAMP; - NEW.created_by = CURRENT_USER; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Product_Category -BEFORE INSERT ON Shop_Product_Category -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Product_Category(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Product_Category() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Product_Category_Audit ( - id_category, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_category, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_category, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed description - SELECT NEW.id_category, 'description', OLD.description, NEW.description, NEW.id_change_set - WHERE NOT OLD.description <=> NEW.description - UNION - -- Changed active - SELECT NEW.id_category, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_category, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Product_Category -BEFORE UPDATE ON Shop_Product_Category -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Product_Category(); diff --git a/static/PostgreSQL/308_tri_Shop_Recurrence_Interval.sql b/static/PostgreSQL/308_tri_Shop_Recurrence_Interval.sql deleted file mode 100644 index 0a82210f..00000000 --- a/static/PostgreSQL/308_tri_Shop_Recurrence_Interval.sql +++ /dev/null @@ -1,59 +0,0 @@ - --- Shop Recurrence Interval - -CREATE OR REPLACE FUNCTION before_insert_Shop_Interval_Recurrence() -RETURNS TRIGGER AS $$ -BEGIN - NEW.created_on = CURRENT_TIMESTAMP; - NEW.created_by = CURRENT_USER; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Interval_Recurrence -BEFORE INSERT ON Shop_Interval_Recurrence -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Interval_Recurrence(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Interval_Recurrence() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Interval_Recurrence_Audit ( - id_interval, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_interval, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_interval, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed name_plural - SELECT NEW.id_interval, 'name_plural', OLD.name_plural, NEW.name_plural, NEW.id_change_set - WHERE NOT OLD.name_plural <=> NEW.name_plural - UNION - -- Changed name - SELECT NEW.id_interval, 'active', OLD.active, NEW.active, NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Interval_Recurrence -BEFORE UPDATE ON Shop_Interval_Recurrence -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Interval_Recurrence(); diff --git a/static/PostgreSQL/310.0_tri_Shop_Region.sql b/static/PostgreSQL/310.0_tri_Shop_Region.sql deleted file mode 100644 index cb76b90c..00000000 --- a/static/PostgreSQL/310.0_tri_Shop_Region.sql +++ /dev/null @@ -1,59 +0,0 @@ - --- Shop Delivery Region - -CREATE OR REPLACE FUNCTION before_insert_Shop_Region() -RETURNS TRIGGER AS $$ -BEGIN - NEW.created_on = CURRENT_TIMESTAMP; - NEW.created_by = CURRENT_USER; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Region -BEFORE INSERT ON Shop_Region -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Region(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Region() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Region_Audit ( - id_region, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_region, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_region, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed active - SELECT NEW.id_region, 'active', CONVERT(OLD.active, CHAR), CONVERT(NEW.active, CHAR), NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - UNION - -- Changed display_order - SELECT NEW.id_region, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Region -BEFORE UPDATE ON Shop_Region -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Region(); diff --git a/static/PostgreSQL/310.2_tri_Shop_Region_Branch.sql b/static/PostgreSQL/310.2_tri_Shop_Region_Branch.sql deleted file mode 100644 index 8192c4c7..00000000 --- a/static/PostgreSQL/310.2_tri_Shop_Region_Branch.sql +++ /dev/null @@ -1,57 +0,0 @@ - --- Shop Region Branch - -CREATE OR REPLACE FUNCTION before_insert_Shop_Region_Branch() -RETURNS TRIGGER AS $$ -BEGIN - NEW.created_on = CURRENT_TIMESTAMP; - NEW.created_by = CURRENT_USER; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Region_Branch -BEFORE INSERT ON Shop_Region_Branch -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Region_Branch(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Region_Branch() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Region_Branch_Audit ( - id_branch, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed depth - SELECT NEW.id_branch, 'depth', CONVERT(OLD.depth, CHAR), CONVERT(NEW.depth, CHAR), NEW.id_change_set - WHERE NOT OLD.depth <=> NEW.depth - UNION - */ - -- Changed active - SELECT NEW.id_branch, 'active', CONVERT(OLD.active, CHAR), CONVERT(NEW.active, CHAR), NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - UNION - -- Changed display_order - SELECT NEW.id_branch, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Region_Branch -BEFORE UPDATE ON Shop_Region_Branch -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Region_Branch(); diff --git a/static/PostgreSQL/310.4_tri_Shop_Currency.sql b/static/PostgreSQL/310.4_tri_Shop_Currency.sql deleted file mode 100644 index 325344e6..00000000 --- a/static/PostgreSQL/310.4_tri_Shop_Currency.sql +++ /dev/null @@ -1,71 +0,0 @@ - --- Shop Currency - -CREATE OR REPLACE FUNCTION before_insert_Shop_Currency() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Currency -BEFORE INSERT ON Shop_Currency -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Currency(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Currency() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Currency_Audit ( - id_currency, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_currency, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_currency, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed symbol - SELECT NEW.id_currency, 'symbol', OLD.symbol, NEW.symbol, NEW.id_change_set - WHERE NOT OLD.symbol <=> NEW.symbol - UNION - -- Changed ratio_2_GBP - SELECT NEW.id_currency, 'factor_from_GBP', OLD.factor_from_GBP, NEW.factor_from_GBP, NEW.id_change_set - WHERE NOT OLD.factor_from_GBP <=> NEW.factor_from_GBP - UNION - -- Changed active - SELECT NEW.id_currency, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_currency, 'display_order', CONVERT(display_order, CHAR), CONVERT(display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Currency -BEFORE UPDATE ON Shop_Currency -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Currency(); diff --git a/static/PostgreSQL/310.6_tri_Shop_Tax_Or_Surcharge.sql b/static/PostgreSQL/310.6_tri_Shop_Tax_Or_Surcharge.sql deleted file mode 100644 index bb1a86ca..00000000 --- a/static/PostgreSQL/310.6_tri_Shop_Tax_Or_Surcharge.sql +++ /dev/null @@ -1,80 +0,0 @@ - --- Shop Tax_Or_Surcharge - -CREATE OR REPLACE FUNCTION before_insert_Shop_Tax_Or_Surcharge() -RETURNS TRIGGER AS $$ -BEGIN - NEW.created_on = CURRENT_TIMESTAMP; - NEW.created_by = CURRENT_USER; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Tax_Or_Surcharge -BEFORE INSERT ON Shop_Tax_Or_Surcharge -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Tax_Or_Surcharge(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Tax_Or_Surcharge() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Tax_Or_Surcharge_Audit ( - id_tax, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_tax, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_tax, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed fixed_fee - SELECT NEW.id_tax, 'fixed_fee', OLD.fixed_fee, NEW.fixed_fee, NEW.id_change_set - WHERE NOT OLD.fixed_fee <=> NEW.fixed_fee - UNION - -- Changed multiplier - SELECT NEW.id_tax, 'multiplier', OLD.multiplier, NEW.multiplier, NEW.id_change_set - WHERE NOT OLD.multiplier <=> NEW.multiplier - UNION - -- Changed apply_fixed_fee_before_multiplier - SELECT NEW.id_tax, 'apply_fixed_fee_before_multiplier', CONVERT(CONVERT(OLD.apply_fixed_fee_before_multiplier, SIGNED), CHAR), CONVERT(CONVERT(NEW.apply_fixed_fee_before_multiplier, SIGNED), CHAR), NEW.id_change_set - WHERE NOT OLD.apply_fixed_fee_before_multiplier <=> NEW.apply_fixed_fee_before_multiplier - UNION - -- Changed quantity_min - SELECT NEW.id_tax, 'quantity_min', OLD.quantity_min, NEW.quantity_min, NEW.id_change_set - WHERE NOT OLD.quantity_min <=> NEW.quantity_min - UNION - -- Changed quantity_max - SELECT NEW.id_tax, 'quantity_max', OLD.quantity_max, NEW.quantity_max, NEW.id_change_set - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - UNION - -- Changed display_order - SELECT NEW.id_tax, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - UNION - -- Changed active - SELECT NEW.id_tax, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Tax_Or_Surcharge -BEFORE UPDATE ON Shop_Tax_Or_Surcharge -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Tax_Or_Surcharge(); - diff --git a/static/PostgreSQL/310.8_tri_Shop_Product.sql b/static/PostgreSQL/310.8_tri_Shop_Product.sql deleted file mode 100644 index 4f25d19a..00000000 --- a/static/PostgreSQL/310.8_tri_Shop_Product.sql +++ /dev/null @@ -1,173 +0,0 @@ - --- Shop Product - -CREATE OR REPLACE FUNCTION before_insert_Shop_Product() -RETURNS TRIGGER AS $$ -BEGIN - NEW.created_on = CURRENT_TIMESTAMP; - NEW.created_by = CURRENT_USER; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Product -BEFORE INSERT ON Shop_Product -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Product(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Product() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - /* - IF NOT NEW.has_variations THEN - IF ISNULL(NEW.price_GBP_full) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have price or variations (with prices).'; - END IF; - IF ISNULL(NEW.price_GBP_min) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have minimum price or variations (with prices).'; - END IF; - IF ISNULL(NEW.latency_manuf) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have manufacturing latency or variations (with manufacturing latencies).'; - END IF; - IF ISNULL(NEW.quantity_min) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have minimum quantity or variations (with minimum quantities).'; - END IF; - IF ISNULL(NEW.quantity_max) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have maximum quantity or variations (with maximum quantities).'; - END IF; - IF ISNULL(NEW.quantity_step) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have increment of quantity or variations (with increments of quantities).'; - END IF; - IF ISNULL(NEW.quantity_stock) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have stock quantity or variations (with stock quantities).'; - END IF; - IF ISNULL(NEW.is_subscription) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have subscription status or variations (with subscription statuses).'; - END IF; - IF ISNULL(NEW.id_unit_measurement_interval_recurrence) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have recurrence interval or variations (with recurrence intervals).'; - END IF; - IF ISNULL(NEW.count_interval_recurrence) THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Product must have recurrence interval count or variations (with recurrence interval counts).'; - END IF; - END IF; - */ - - INSERT INTO Shop_Product_Audit ( - id_product, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed name - SELECT NEW.id_product, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - /* - UNION - -- Changed description - SELECT NEW.id_product, 'description', OLD.description, NEW.description, NEW.id_change_set - WHERE NOT OLD.description <=> NEW.description - UNION - -- Changed price_GBP_full - SELECT NEW.id_product, 'price_GBP_full', CONVERT(OLD.price_GBP_full, CHAR), CONVERT(NEW.price_GBP_full, CHAR), NEW.id_change_set - WHERE NOT OLD.price_GBP_full <=> NEW.price_GBP_full - UNION - -- Changed price_GBP_min - SELECT NEW.id_product, 'price_GBP_min', CONVERT(OLD.price_GBP_min, CHAR), CONVERT(NEW.price_GBP_min, CHAR), NEW.id_change_set - WHERE NOT OLD.price_GBP_min <=> NEW.price_GBP_min - UNION - / - -- Changed discount - SELECT NEW.id_product, 'discount', CONVERT(OLD.discount, CHAR), CONVERT(NEW.discount, CHAR), NEW.id_change_set - WHERE NOT OLD.discount <=> NEW.discount - */ - UNION - -- Changed id_category - SELECT NEW.id_product, 'id_category', CONVERT(OLD.id_category, CHAR), CONVERT(NEW.id_category, CHAR), NEW.id_change_set - WHERE NOT OLD.id_category <=> NEW.id_category - UNION - -- Changed has_variations - SELECT NEW.id_product, 'has_variations', CONVERT(CONVERT(NEW.has_variations, SIGNED), CHAR), CONVERT(CONVERT(NEW.has_variations, SIGNED), CHAR), NEW.id_change_set - WHERE NOT OLD.has_variations <=> NEW.has_variations - /* - UNION - -- Changed latency_manuf - SELECT NEW.id_product, 'latency_manuf', CONVERT(OLD.latency_manuf, CHAR), CONVERT(NEW.latency_manuf, CHAR), NEW.id_change_set - WHERE NOT OLD.latency_manuf <=> NEW.latency_manuf - UNION - -- Changed quantity_min - SELECT NEW.id_product, 'quantity_min', CONVERT(OLD.quantity_min, CHAR), CONVERT(NEW.quantity_min, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_min <=> NEW.quantity_min - UNION - -- Changed quantity_max - SELECT NEW.id_product, 'quantity_max', CONVERT(OLD.quantity_max, CHAR), CONVERT(NEW.quantity_max, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - UNION - -- Changed quantity_step - SELECT NEW.id_product, 'quantity_step', CONVERT(OLD.quantity_step, CHAR), CONVERT(NEW.quantity_step, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_step <=> NEW.quantity_step - UNION - -- Changed quantity_stock - SELECT NEW.id_product, 'quantity_stock', CONVERT(OLD.quantity_stock, CHAR), CONVERT(NEW.quantity_stock, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_stock <=> NEW.quantity_stock - UNION - -- Changed is_subscription - SELECT NEW.id_product, 'is_subscription', CONVERT(CONVERT(OLD.is_subscription, SIGNED), CHAR), CONVERT(CONVERT(NEW.is_subscription, SIGNED), CHAR), NEW.id_change_set - WHERE NOT OLD.is_subscription <=> NEW.is_subscription - UNION - -- Changed id_unit_measurement_interval_recurrence - SELECT NEW.id_product, 'id_unit_measurement_interval_recurrence', CONVERT(OLD.id_unit_measurement_interval_recurrence, CHAR), CONVERT(NEW.id_unit_measurement_interval_recurrence, CHAR), NEW.id_change_set - WHERE NOT OLD.id_unit_measurement_interval_recurrence <=> NEW.id_unit_measurement_interval_recurrence - UNION - -- Changed count_interval_recurrence - SELECT NEW.id_product, 'count_interval_recurrence', CONVERT(OLD.count_interval_recurrence, CHAR), CONVERT(NEW.count_interval_recurrence, CHAR), NEW.id_change_set - WHERE NOT OLD.count_interval_recurrence <=> NEW.count_interval_recurrence - UNION - -- Changed id_stripe_product - SELECT NEW.id_product, 'id_stripe_product', OLD.id_stripe_product, NEW.id_stripe_product, NEW.id_change_set - WHERE NOT OLD.id_stripe_product <=> NEW.id_stripe_product - / - UNION - -- Changed id_stripe_price - SELECT NEW.id_product, 'id_stripe_price', OLD.id_stripe_price, NEW.id_stripe_price, NEW.id_change_set - WHERE NOT OLD.id_stripe_price <=> NEW.id_stripe_price - */ - UNION - -- Changed id_access_level_required - SELECT NEW.id_product, 'id_access_level_required', CONVERT(OLD.id_access_level_required, CHAR), CONVERT(NEW.id_access_level_required, CHAR), NEW.id_change_set - WHERE NOT OLD.id_access_level_required <=> NEW.id_access_level_required - UNION - -- Changed active - SELECT NEW.id_product, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_product, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Product -BEFORE UPDATE ON Shop_Product -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Product(); diff --git a/static/PostgreSQL/312_tri_Shop_Variation_Type.sql b/static/PostgreSQL/312_tri_Shop_Variation_Type.sql deleted file mode 100644 index fa23aed3..00000000 --- a/static/PostgreSQL/312_tri_Shop_Variation_Type.sql +++ /dev/null @@ -1,63 +0,0 @@ - --- Shop Variation Type - -CREATE OR REPLACE FUNCTION before_insert_Shop_Variation_Type() -RETURNS TRIGGER AS $$ -BEGIN - NEW.created_on = CURRENT_TIMESTAMP; - NEW.created_by = CURRENT_USER; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Variation_Type -BEFORE INSERT ON Shop_Variation_Type -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Variation_Type(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Variation_Type() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Variation_Type_Audit ( - id_type, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_type, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_type, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed name_plural - SELECT NEW.id_type, 'name_plural', OLD.name_plural, NEW.name_plural, NEW.id_change_set - WHERE NOT OLD.name_plural <=> NEW.name_plural - UNION - -- Changed active - SELECT NEW.id_type, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_type, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Variation_Type -BEFORE UPDATE ON Shop_Variation_Type -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Variation_Type(); diff --git a/static/PostgreSQL/314_tri_Shop_Variation.sql b/static/PostgreSQL/314_tri_Shop_Variation.sql deleted file mode 100644 index ee5b384f..00000000 --- a/static/PostgreSQL/314_tri_Shop_Variation.sql +++ /dev/null @@ -1,59 +0,0 @@ - --- Shop Variation - -CREATE OR REPLACE FUNCTION before_insert_Shop_Variation() -RETURNS TRIGGER AS $$ -BEGIN - NEW.created_on = CURRENT_TIMESTAMP; - NEW.created_by = CURRENT_USER; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Variation -BEFORE INSERT ON Shop_Variation -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Variation(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Variation() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Variation_Audit ( - id_variation, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_variation, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_variation, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed active - SELECT NEW.id_variation, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_variation, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Variation -BEFORE UPDATE ON Shop_Variation -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Variation(); diff --git a/static/PostgreSQL/317.1_tri_Shop_Product_Permutation.sql b/static/PostgreSQL/317.1_tri_Shop_Product_Permutation.sql deleted file mode 100644 index 7a43d1e7..00000000 --- a/static/PostgreSQL/317.1_tri_Shop_Product_Permutation.sql +++ /dev/null @@ -1,133 +0,0 @@ - --- Shop Product Permutation - -CREATE OR REPLACE FUNCTION before_insert_Shop_Product_Permutation() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Product_Permutation -BEFORE INSERT ON Shop_Product_Permutation -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Product_Permutation(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Product_Permutation() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Product_Permutation_Audit ( - id_permutation, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_product - SELECT NEW.id_permutation, 'id_product', OLD.id_product, NEW.id_product, NEW.id_change_set - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed id_variation - SELECT NEW.id_permutation, 'id_variation', OLD.id_variation, NEW.id_variation, NEW.id_change_set - WHERE NOT OLD.id_variation <=> NEW.id_variation - UNION - -- Changed name - SELECT NEW.id_permutation, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT (OLD.name <=> NEW.name) - UNION - */ - -- Changed description - SELECT NEW.id_permutation, 'description', OLD.description, NEW.description, NEW.id_change_set - WHERE NOT (OLD.description <=> NEW.description) - UNION - -- Changed cost_local - SELECT NEW.id_permutation, 'cost_local', CONVERT(OLD.cost_local, CHAR), CONVERT(NEW.cost_local, CHAR), NEW.id_change_set - WHERE NOT (OLD.cost_local <=> NEW.cost_local) - UNION - -- Changed id_currency_cost - SELECT NEW.id_permutation, 'id_currency_cost', CONVERT(OLD.id_currency_cost, CHAR), CONVERT(NEW.id_currency_cost, CHAR), NEW.id_change_set - WHERE NOT (OLD.id_currency_cost <=> NEW.id_currency_cost) - UNION - -- Changed profit_local_min - SELECT NEW.id_permutation, 'profit_local_min', CONVERT(OLD.profit_local_min, CHAR), CONVERT(NEW.profit_local_min, CHAR), NEW.id_change_set - WHERE NOT (OLD.profit_local_min <=> NEW.profit_local_min) - UNION - /* - -- Changed id_currency_profit_min - SELECT NEW.id_permutation, 'id_currency_profit_min', CONVERT(OLD.id_currency_profit_min, CHAR), CONVERT(NEW.id_currency_profit_min, CHAR), NEW.id_change_set - WHERE NOT (OLD.id_currency_profit_min <=> NEW.id_currency_profit_min) - UNION - */ - /* - -- Changed price_GBP_min - SELECT NEW.id_permutation, 'price_GBP_min', CONVERT(OLD.price_GBP_min, CHAR), CONVERT(NEW.price_GBP_min, CHAR), NEW.id_change_set - WHERE NOT (OLD.price_GBP_min <=> NEW.price_GBP_min) - UNION - */ - -- Changed latency_manufacture - SELECT NEW.id_product, 'latency_manufacture', CONVERT(OLD.latency_manufacture, CHAR), CONVERT(NEW.latency_manufacture, CHAR), NEW.id_change_set - WHERE NOT OLD.latency_manufacture <=> NEW.latency_manufacture - UNION - -- Changed quantity_min - SELECT NEW.id_product, 'quantity_min', CONVERT(OLD.quantity_min, CHAR), CONVERT(NEW.quantity_min, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_min <=> NEW.quantity_min - UNION - -- Changed quantity_max - SELECT NEW.id_product, 'quantity_max', CONVERT(OLD.quantity_max, CHAR), CONVERT(NEW.quantity_max, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - UNION - -- Changed quantity_step - SELECT NEW.id_product, 'quantity_step', CONVERT(OLD.quantity_step, CHAR), CONVERT(NEW.quantity_step, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_step <=> NEW.quantity_step - UNION - -- Changed quantity_stock - SELECT NEW.id_product, 'quantity_stock', CONVERT(OLD.quantity_stock, CHAR), CONVERT(NEW.quantity_stock, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_stock <=> NEW.quantity_stock - UNION - -- Changed is_subscription - SELECT NEW.id_product, 'is_subscription', CONVERT(CONVERT(OLD.is_subscription, SIGNED), CHAR), CONVERT(CONVERT(NEW.is_subscription, SIGNED), CHAR), NEW.id_change_set - WHERE NOT OLD.is_subscription <=> NEW.is_subscription - UNION - -- Changed id_unit_measurement_interval_recurrence - SELECT NEW.id_product, 'id_unit_measurement_interval_recurrence', CONVERT(OLD.id_unit_measurement_interval_recurrence, CHAR), CONVERT(NEW.id_unit_measurement_interval_recurrence, CHAR), NEW.id_change_set - WHERE NOT OLD.id_unit_measurement_interval_recurrence <=> NEW.id_unit_measurement_interval_recurrence - UNION - -- Changed count_interval_recurrence - SELECT NEW.id_product, 'count_interval_recurrence', CONVERT(OLD.count_interval_recurrence, CHAR), CONVERT(NEW.count_interval_recurrence, CHAR), NEW.id_change_set - WHERE NOT OLD.count_interval_recurrence <=> NEW.count_interval_recurrence - UNION - -- Changed id_stripe_product - SELECT NEW.id_permutation, 'id_stripe_product', OLD.id_stripe_product, NEW.id_stripe_product, NEW.id_change_set - WHERE NOT (OLD.id_stripe_product <=> NEW.id_stripe_product) - UNION - -- Changed active - SELECT NEW.id_permutation, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_permutation, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Product_Permutation -BEFORE UPDATE ON Shop_Product_Permutation -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Product_Permutation(); diff --git a/static/PostgreSQL/317.3_tri_Shop_Product_Permutation_Variation_Link.sql b/static/PostgreSQL/317.3_tri_Shop_Product_Permutation_Variation_Link.sql deleted file mode 100644 index ef28a99b..00000000 --- a/static/PostgreSQL/317.3_tri_Shop_Product_Permutation_Variation_Link.sql +++ /dev/null @@ -1,65 +0,0 @@ - --- Shop Product Permutation Variation Link - -CREATE OR REPLACE FUNCTION before_insert_Shop_Product_Permutation_Variation_Link() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Product_Permutation_Variation_Link -BEFORE INSERT ON Shop_Product_Permutation_Variation_Link -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Product_Permutation_Variation_Link(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Product_Permutation_Variation_Link() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Product_Permutation_Variation_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_product - SELECT NEW.id_link, 'id_product', OLD.id_product, NEW.id_product, NEW.id_change_set - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed id_variation - SELECT NEW.id_link, 'id_variation', OLD.id_variation, NEW.id_variation, NEW.id_change_set - WHERE NOT OLD.id_variation <=> NEW.id_variation - UNION - */ - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_link, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Product_Permutation_Variation_Link -BEFORE UPDATE ON Shop_Product_Permutation_Variation_Link -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Product_Permutation_Variation_Link(); diff --git a/static/PostgreSQL/317.5_tri_Shop_Product_Currency_Region_Link.sql b/static/PostgreSQL/317.5_tri_Shop_Product_Currency_Region_Link.sql deleted file mode 100644 index 6542497a..00000000 --- a/static/PostgreSQL/317.5_tri_Shop_Product_Currency_Region_Link.sql +++ /dev/null @@ -1,97 +0,0 @@ - --- Shop Product Currency Region Link - -CREATE OR REPLACE FUNCTION before_insert_Shop_Product_Currency_Region_Link() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - /* - NEW.price_local = ( - SELECT PP.price_GBP_full * C.factor_from_GBP - FROM Shop_Product_Permutation PP - INNER JOIN Shop_Product P ON PP.id_product = P.id_product - INNER JOIN Shop_Currency C ON NEW.id_currency = C.id_currency - WHERE NEW.id_product = P.id_product - LIMIT 1 - ); - */ - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Product_Currency_Region_Link -BEFORE INSERT ON Shop_Product_Currency_Region_Link -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Product_Currency_Region_Link(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Product_Currency_Region_Link() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - /* - NEW.price_local = ( - SELECT P.price_GBP_full * C.factor_from_GBP - FROM Shop_Product P - INNER JOIN Shop_Currency C ON NEW.id_currency = C.id_currency - WHERE NEW.id_product = P.id_product - LIMIT 1 - ); - */ - - INSERT INTO Shop_Product_Currency_Region_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_product - SELECT NEW.id_link, 'id_product', CONVERT(OLD.id_product, CHAR), CONVERT(NEW.id_product, CHAR), NEW.id_change_set - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed id_currency - SELECT NEW.id_link, 'id_currency', CONVERT(OLD.id_currency, CHAR), CONVERT(NEW.id_currency, CHAR), NEW.id_change_set - WHERE NOT OLD.id_currency <=> NEW.id_currency - UNION - -- Changed price_local - SELECT NEW.id_link, 'price_local', OLD.price_local, NEW.price_local, NEW.id_change_set - WHERE NOT OLD.price_local <=> NEW.price_local - UNION - */ - -- Changed price_local_VAT_incl - SELECT NEW.id_link, 'price_local_VAT_incl', OLD.price_local_VAT_incl, NEW.price_local_VAT_incl, NEW.id_change_set - WHERE NOT OLD.price_local_VAT_incl <=> NEW.price_local_VAT_incl - UNION - -- Changed price_local_VAT_excl - SELECT NEW.id_link, 'price_local_VAT_excl', OLD.price_local_VAT_excl, NEW.price_local_VAT_excl, NEW.id_change_set - WHERE NOT OLD.price_local_VAT_excl <=> NEW.price_local_VAT_excl - UNION - -- Changed id_stripe_price - SELECT NEW.id_link, 'id_stripe_price', OLD.id_stripe_price, NEW.id_stripe_price, NEW.id_change_set - WHERE NOT OLD.id_stripe_price <=> NEW.id_stripe_price - UNION - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Product_Currency_Region_Link -BEFORE UPDATE ON Shop_Product_Currency_Region_Link -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Product_Currency_Region_Link(); diff --git a/static/PostgreSQL/318_tri_Shop_Image_Type.sql b/static/PostgreSQL/318_tri_Shop_Image_Type.sql deleted file mode 100644 index 038f9c34..00000000 --- a/static/PostgreSQL/318_tri_Shop_Image_Type.sql +++ /dev/null @@ -1,63 +0,0 @@ - --- Shop Image Type - -CREATE OR REPLACE FUNCTION before_insert_Shop_Image_Type() -RETURNS TRIGGER AS $$ -BEGIN - NEW.created_on = CURRENT_TIMESTAMP; - NEW.created_by = CURRENT_USER; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Image_Type -BEFORE INSERT ON Shop_Image_Type -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Image_Type(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Image_Type() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Image_Type_Audit ( - id_type, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_type, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_type, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed name_plural - SELECT NEW.id_type, 'name_plural', OLD.name_plural, NEW.name_plural, NEW.id_change_set - WHERE NOT OLD.name_plural <=> NEW.name_plural - UNION - -- Changed active - SELECT NEW.id_type, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_type, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Image_Type -BEFORE UPDATE ON Shop_Image_Type -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Image_Type(); diff --git a/static/PostgreSQL/320_tri_Shop_Image.sql b/static/PostgreSQL/320_tri_Shop_Image.sql deleted file mode 100644 index 1bb31cbe..00000000 --- a/static/PostgreSQL/320_tri_Shop_Image.sql +++ /dev/null @@ -1,75 +0,0 @@ - --- Shop Image - -CREATE OR REPLACE FUNCTION before_insert_Shop_Image() -RETURNS TRIGGER AS $$ -BEGIN - NEW.created_on = CURRENT_TIMESTAMP; - NEW.created_by = CURRENT_USER; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Image -BEFORE INSERT ON Shop_Image -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Image(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Image() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - IF ISNULL(NEW.id_product) AND ISNULL(NEW.id_permutation) THEN - RAISE EXCEPTION 'Image must NOT have ID for product AND product permutation.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Image_Audit ( - id_image, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_type_image - SELECT NEW.id_image, 'id_type_image', CONVERT(OLD.id_type_image, CHAR), CONVERT(NEW.id_type_image, CHAR), NEW.id_change_set - WHERE NOT OLD.id_type_image <=> NEW.id_type_image - UNION - -- Changed id_type_file - SELECT NEW.id_image, 'id_type_file', CONVERT(OLD.id_type_file, CHAR), CONVERT(NEW.id_type_file, CHAR), NEW.id_change_set - WHERE NOT OLD.id_type_file <=> NEW.id_type_file - UNION - -- Changed id_product - SELECT NEW.id_image, 'id_product', CONVERT(OLD.id_product, CHAR), CONVERT(NEW.id_product, CHAR), NEW.id_change_set - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed id_permutation - SELECT NEW.id_image, 'id_permutation', CONVERT(OLD.id_permutation, CHAR), CONVERT(NEW.id_permutation, CHAR), NEW.id_change_set - WHERE NOT OLD.id_permutation <=> NEW.id_permutation - UNION - -- Changed url - SELECT NEW.id_image, 'url', OLD.url, NEW.url, NEW.id_change_set - WHERE NOT OLD.url <=> NEW.url - UNION - -- Changed active - SELECT NEW.id_image, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_image, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Image -BEFORE UPDATE ON Shop_Image -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Image(); diff --git a/static/PostgreSQL/322_tri_Shop_Delivery_Option.sql b/static/PostgreSQL/322_tri_Shop_Delivery_Option.sql deleted file mode 100644 index 7d3a1fb7..00000000 --- a/static/PostgreSQL/322_tri_Shop_Delivery_Option.sql +++ /dev/null @@ -1,75 +0,0 @@ - --- Shop Delivery Option Type - -CREATE OR REPLACE FUNCTION before_insert_Shop_Delivery_Option() -RETURNS TRIGGER AS $$ -BEGIN - NEW.created_on = CURRENT_TIMESTAMP; - NEW.created_by = CURRENT_USER; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Delivery_Option -BEFORE INSERT ON Shop_Delivery_Option -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Delivery_Option(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Delivery_Option() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Delivery_Option_Audit ( - id_option, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_option, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_option, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed latency_delivery_min - SELECT NEW.id_option, 'latency_delivery_min', CONVERT(OLD.latency_delivery_min, CHAR), CONVERT(NEW.latency_delivery_min, CHAR), NEW.id_change_set - WHERE NOT OLD.latency_delivery_min <=> NEW.latency_delivery_min - UNION - -- Changed latency_delivery_max - SELECT NEW.id_option, 'latency_delivery_max', CONVERT(OLD.latency_delivery_max, CHAR), CONVERT(NEW.latency_delivery_max, CHAR), NEW.id_change_set - WHERE NOT OLD.latency_delivery_max <=> NEW.latency_delivery_max - UNION - -- Changed quantity_min - SELECT NEW.id_option, 'quantity_min', CONVERT(OLD.quantity_min, CHAR), CONVERT(NEW.quantity_min, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_min <=> NEW.quantity_min - UNION - -- Changed quantity_max - SELECT NEW.id_option, 'quantity_max', CONVERT(OLD.quantity_max, CHAR), CONVERT(NEW.quantity_max, CHAR), NEW.id_change_set - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - UNION - -- Changed active - SELECT NEW.id_option, 'active', CONVERT(OLD.active, CHAR), CONVERT(NEW.active, CHAR), NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - UNION - -- Changed display_order - SELECT NEW.id_option, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Delivery_Option -BEFORE UPDATE ON Shop_Delivery_Option -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Delivery_Option(); diff --git a/static/PostgreSQL/324_tri_Shop_Product_Delivery_Option_Link.sql b/static/PostgreSQL/324_tri_Shop_Product_Delivery_Option_Link.sql deleted file mode 100644 index 1a021d03..00000000 --- a/static/PostgreSQL/324_tri_Shop_Product_Delivery_Option_Link.sql +++ /dev/null @@ -1,77 +0,0 @@ - --- Shop Product Delivery Option Link - -CREATE OR REPLACE FUNCTION before_insert_Shop_Product_Permutation_Delivery_Option_Link() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Product_Permutation_Delivery_Option_Link -BEFORE INSERT ON Shop_Product_Permutation_Delivery_Option_Link -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Product_Permutation_Delivery_Option_Link(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Product_Permutation_Delivery_Option_Link() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Product_Permutation_Delivery_Option_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_product - SELECT NEW.id_link, 'id_product', CONVERT(OLD.id_product, CHAR), CONVERT(NEW.id_product, CHAR), NEW.id_change_set - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed id_permutation - SELECT NEW.id_link, 'id_permutation', CONVERT(OLD.id_permutation, CHAR), CONVERT(NEW.id_permutation, CHAR), NEW.id_change_set - WHERE NOT OLD.id_permutation <=> NEW.id_permutation - UNION - -- Changed id_option - SELECT NEW.id_link, 'id_option', CONVERT(OLD.id_option, CHAR), CONVERT(NEW.id_option, CHAR), NEW.id_change_set - WHERE NOT OLD.id_option <=> NEW.id_option - UNION - -- Changed id_region - SELECT NEW.id_link, 'id_region', CONVERT(OLD.id_region, CHAR), CONVERT(NEW.id_region, CHAR), NEW.id_change_set - WHERE NOT OLD.id_region <=> NEW.id_region - UNION - */ - -- Changed price_local - SELECT NEW.id_link, 'price_local', CONVERT(OLD.price_local, CHAR), CONVERT(NEW.price_local, CHAR), NEW.id_change_set - WHERE NOT OLD.price_local <=> NEW.price_local - UNION - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_link, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Product_Permutation_Delivery_Option_Link -BEFORE UPDATE ON Shop_Product_Permutation_Delivery_Option_Link -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Product_Permutation_Delivery_Option_Link(); diff --git a/static/PostgreSQL/330_tri_Shop_Discount.sql b/static/PostgreSQL/330_tri_Shop_Discount.sql deleted file mode 100644 index 9ab188a1..00000000 --- a/static/PostgreSQL/330_tri_Shop_Discount.sql +++ /dev/null @@ -1,87 +0,0 @@ - --- Shop Discount - -CREATE OR REPLACE FUNCTION before_insert_Shop_Discount() -RETURNS TRIGGER AS $$ -BEGIN - NEW.created_on = CURRENT_TIMESTAMP; - NEW.created_by = CURRENT_USER; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Discount -BEFORE INSERT ON Shop_Discount -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Discount(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Discount() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Discount_Audit ( - id_discount, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_discount, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_discount, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed multiplier - SELECT NEW.id_discount, 'multiplier', OLD.multiplier, NEW.multiplier, NEW.id_change_set - WHERE NOT OLD.multiplier <=> NEW.multiplier - UNION - -- Changed subtractor - SELECT NEW.id_discount, 'subtractor', OLD.subtractor, NEW.subtractor, NEW.id_change_set - WHERE NOT OLD.subtractor <=> NEW.subtractor - UNION - -- Changed apply_multiplier_first - SELECT NEW.id_discount, 'apply_multiplier_first', CONVERT(CONVERT(OLD.apply_multiplier_first, SIGNED), CHAR), CONVERT(CONVERT(NEW.apply_multiplier_first, SIGNED), CHAR), NEW.id_change_set - WHERE NOT OLD.apply_multiplier_first <=> NEW.apply_multiplier_first - UNION - -- Changed quantity_min - SELECT NEW.id_discount, 'quantity_min', OLD.quantity_min, NEW.quantity_min, NEW.id_change_set - WHERE NOT OLD.quantity_min <=> NEW.quantity_min - UNION - -- Changed quantity_max - SELECT NEW.id_discount, 'quantity_max', OLD.quantity_max, NEW.quantity_max, NEW.id_change_set - WHERE NOT OLD.quantity_max <=> NEW.quantity_max - UNION - -- Changed date_start - SELECT NEW.id_discount, 'date_start', OLD.date_start, NEW.date_start, NEW.id_change_set - WHERE NOT OLD.date_start <=> NEW.date_start - UNION - -- Changed date_end - SELECT NEW.id_discount, 'date_end', OLD.date_end, NEW.date_end, NEW.id_change_set - WHERE NOT OLD.date_end <=> NEW.date_end - UNION - -- Changed display_order - SELECT NEW.id_discount, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - UNION - -- Changed active - SELECT NEW.id_discount, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Discount -BEFORE UPDATE ON Shop_Discount -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Discount(); diff --git a/static/PostgreSQL/332_tri_Shop_Discount_Region_Currency_Link.sql b/static/PostgreSQL/332_tri_Shop_Discount_Region_Currency_Link.sql deleted file mode 100644 index 9176681b..00000000 --- a/static/PostgreSQL/332_tri_Shop_Discount_Region_Currency_Link.sql +++ /dev/null @@ -1,61 +0,0 @@ - --- Shop Discount Region Currency Link - -CREATE OR REPLACE FUNCTION before_insert_Shop_Discount_Region_Currency_Link() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Discount_Region_Currency_Link -BEFORE INSERT ON Shop_Discount_Region_Currency_Link -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Discount_Region_Currency_Link(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Discount_Region_Currency_Link() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Discount_Region_Currency_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_discount - SELECT NEW.id_link, 'id_discount', CONVERT(OLD.id_discount, CHAR), CONVERT(NEW.id_discount, CHAR), NEW.id_change_set - WHERE NOT OLD.id_discount <=> NEW.id_discount - UNION - -- Changed id_region - SELECT NEW.id_link, 'id_region', CONVERT(OLD.id_region, CHAR), CONVERT(NEW.id_region, CHAR), NEW.id_change_set - WHERE NOT OLD.id_region <=> NEW.id_region - UNION - */ - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Discount_Region_Currency_Link -BEFORE UPDATE ON Shop_Discount_Region_Currency_Link -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Discount_Region_Currency_Link(); diff --git a/static/PostgreSQL/353_tri_Shop_Permission_Group.sql b/static/PostgreSQL/353_tri_Shop_Permission_Group.sql deleted file mode 100644 index aaec1645..00000000 --- a/static/PostgreSQL/353_tri_Shop_Permission_Group.sql +++ /dev/null @@ -1,63 +0,0 @@ - --- Shop Permission Group - -CREATE OR REPLACE FUNCTION before_insert_Shop_Permission_Group() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Permission_Group -BEFORE INSERT ON Shop_Permission_Group -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Permission_Group(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Permission_Group() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Permission_Group_Audit ( - id_group, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_group, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_group, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed active - SELECT NEW.id_group, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_group, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Permission_Group -BEFORE UPDATE ON Shop_Permission_Group -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Permission_Group(); diff --git a/static/PostgreSQL/355_tri_Shop_Permission.sql b/static/PostgreSQL/355_tri_Shop_Permission.sql deleted file mode 100644 index 65d22c36..00000000 --- a/static/PostgreSQL/355_tri_Shop_Permission.sql +++ /dev/null @@ -1,71 +0,0 @@ - --- Shop Permission - -CREATE OR REPLACE FUNCTION before_insert_Shop_Permission() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Permission -BEFORE INSERT ON Shop_Permission -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Permission(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Permission() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Permission_Audit ( - id_permission, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_permission, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_permission, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed id_permission_group - SELECT NEW.id_permission, 'id_permission_group', CONVERT(OLD.id_permission_group, CHAR), CONVERT(NEW.id_permission_group, CHAR), NEW.id_change_set - WHERE NOT OLD.id_permission_group <=> NEW.id_permission_group - UNION - -- Changed Id_access_level_required - SELECT NEW.id_permission, 'Id_access_level_required', CONVERT(OLD.Id_access_level_required, CHAR), CONVERT(NEW.Id_access_level_required, CHAR), NEW.id_change_set - WHERE NOT OLD.Id_access_level_required <=> NEW.Id_access_level_required - UNION - -- Changed active - SELECT NEW.id_permission, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_permission, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Permission -BEFORE UPDATE ON Shop_Permission -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Permission(); diff --git a/static/PostgreSQL/357_tri_Shop_Role.sql b/static/PostgreSQL/357_tri_Shop_Role.sql deleted file mode 100644 index 89979d74..00000000 --- a/static/PostgreSQL/357_tri_Shop_Role.sql +++ /dev/null @@ -1,63 +0,0 @@ - --- Shop Role - -CREATE OR REPLACE FUNCTION before_insert_Shop_Role() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Role -BEFORE INSERT ON Shop_Role -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Role(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Role() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Role_Audit ( - id_role, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_role, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_role, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed active - SELECT NEW.id_role, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_role, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Role -BEFORE UPDATE ON Shop_Role -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Role(); diff --git a/static/PostgreSQL/359_tri_Shop_Role_Permission_Link.sql b/static/PostgreSQL/359_tri_Shop_Role_Permission_Link.sql deleted file mode 100644 index cefe3ce1..00000000 --- a/static/PostgreSQL/359_tri_Shop_Role_Permission_Link.sql +++ /dev/null @@ -1,65 +0,0 @@ - --- Shop Role Permission Link - -CREATE OR REPLACE FUNCTION before_insert_Shop_Role_Permission_Link() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Role_Permission_Link -BEFORE INSERT ON Shop_Role_Permission_Link -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Role_Permission_Link(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Role_Permission_Link() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Role_Permission_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - /* - -- Changed id_role - SELECT NEW.id_link, 'id_role', CONVERT(OLD.id_role, CHAR), CONVERT(NEW.id_role, CHAR), NEW.id_change_set - WHERE NOT OLD.id_role <=> NEW.id_role - UNION - -- Changed id_permission - SELECT NEW.id_link, 'id_permission', CONVERT(OLD.id_permission, CHAR), CONVERT(NEW.id_permission, CHAR), NEW.id_change_set - WHERE NOT OLD.id_permission <=> NEW.id_permission - UNION - */ - -- Changed id_access_level - SELECT NEW.id_link, 'id_access_level', CONVERT(OLD.id_access_level, CHAR), CONVERT(NEW.id_access_level, CHAR), NEW.id_change_set - WHERE NOT OLD.id_access_level <=> NEW.id_access_level - UNION - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Role_Permission_Link -BEFORE UPDATE ON Shop_Role_Permission_Link -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Role_Permission_Link(); diff --git a/static/PostgreSQL/361_tri_Shop_User.sql b/static/PostgreSQL/361_tri_Shop_User.sql deleted file mode 100644 index 55ca4803..00000000 --- a/static/PostgreSQL/361_tri_Shop_User.sql +++ /dev/null @@ -1,71 +0,0 @@ - --- Shop User - -CREATE OR REPLACE FUNCTION before_insert_Shop_User() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_User -BEFORE INSERT ON Shop_User -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_User(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_User() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_User_Audit ( - id_user, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_user_oauth - SELECT NEW.id_user, 'id_user_oauth', OLD.id_user_oauth, NEW.id_user_oauth, NEW.id_change_set - WHERE NOT (OLD.id_user_oauth <=> NEW.id_user_oauth) - UNION - -- Changed name - SELECT NEW.id_user, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT (OLD.name <=> NEW.name) - UNION - -- Changed email - SELECT NEW.id_user, 'email', OLD.email, NEW.email, NEW.id_change_set - WHERE NOT (OLD.email <=> NEW.email) - UNION - -- Changed is_email_verified - SELECT NEW.id_user, 'is_email_verified', OLD.is_email_verified, NEW.is_email_verified, NEW.id_change_set - WHERE NOT (OLD.is_email_verified <=> NEW.is_email_verified) - UNION - -- Changed is_super_user - SELECT NEW.id_user, 'is_super_user', CONVERT(CONVERT(OLD.is_super_user, SIGNED), CHAR), CONVERT(CONVERT(NEW.is_super_user, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.is_super_user <=> NEW.is_super_user) - UNION - -- Changed active - SELECT NEW.id_user, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_User -BEFORE UPDATE ON Shop_User -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_User(); diff --git a/static/PostgreSQL/363_tri_Shop_User_Role_Link.sql b/static/PostgreSQL/363_tri_Shop_User_Role_Link.sql deleted file mode 100644 index 6ac8b839..00000000 --- a/static/PostgreSQL/363_tri_Shop_User_Role_Link.sql +++ /dev/null @@ -1,51 +0,0 @@ - --- Shop User Role Link - -CREATE OR REPLACE FUNCTION before_insert_Shop_User_Role_Link() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_User_Role_Link -BEFORE INSERT ON Shop_User_Role_Link -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_User_Role_Link(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_User_Role_Link() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_User_Role_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed active - SELECT NEW.id_link, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_User_Role_Link -BEFORE UPDATE ON Shop_User_Role_Link -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_User_Role_Link(); diff --git a/static/PostgreSQL/365_tri_Shop_Address.sql b/static/PostgreSQL/365_tri_Shop_Address.sql deleted file mode 100644 index 037d5e49..00000000 --- a/static/PostgreSQL/365_tri_Shop_Address.sql +++ /dev/null @@ -1,83 +0,0 @@ - --- Shop Address - -CREATE OR REPLACE FUNCTION before_insert_Shop_Address() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Address -BEFORE INSERT ON Shop_Address -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Address(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Address() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Address_Audit ( - id_address, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed region - SELECT NEW.id_address, 'id_region', OLD.id_region, NEW.id_region, NEW.id_change_set - WHERE NOT OLD.id_region <=> NEW.id_region - UNION - -- Changed name_full - SELECT NEW.id_address, 'name_full', OLD.name_full, NEW.name_full, NEW.id_change_set - WHERE NOT OLD.name_full <=> NEW.name_full - UNION - -- Changed phone_number - SELECT NEW.id_address, 'phone_number', OLD.phone_number, NEW.phone_number, NEW.id_change_set - WHERE NOT OLD.phone_number <=> NEW.phone_number - UNION - -- Changed postcode - SELECT NEW.id_address, 'postcode', OLD.postcode, NEW.postcode, NEW.id_change_set - WHERE NOT OLD.postcode <=> NEW.postcode - UNION - -- Changed address_line_1 - SELECT NEW.id_address, 'address_line_1', OLD.address_line_1, NEW.address_line_1, NEW.id_change_set - WHERE NOT OLD.address_line_1 <=> NEW.address_line_1 - UNION - -- Changed address_line_2 - SELECT NEW.id_address, 'address_line_2', OLD.address_line_2, NEW.address_line_2, NEW.id_change_set - WHERE NOT OLD.address_line_2 <=> NEW.address_line_2 - UNION - -- Changed city - SELECT NEW.id_address, 'city', OLD.city, NEW.city, NEW.id_change_set - WHERE NOT OLD.city <=> NEW.city - UNION - -- Changed county - SELECT NEW.id_address, 'county', OLD.county, NEW.county, NEW.id_change_set - WHERE NOT OLD.county <=> NEW.county - UNION - -- Changed active - SELECT NEW.id_address, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Address -BEFORE UPDATE ON Shop_Address -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Address(); \ No newline at end of file diff --git a/static/PostgreSQL/367_tri_Shop_User_Basket.sql b/static/PostgreSQL/367_tri_Shop_User_Basket.sql deleted file mode 100644 index 0884a259..00000000 --- a/static/PostgreSQL/367_tri_Shop_User_Basket.sql +++ /dev/null @@ -1,63 +0,0 @@ - --- Shop Product Variation Link - -CREATE OR REPLACE FUNCTION before_insert_Shop_User_Basket() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_User_Basket -BEFORE INSERT ON Shop_User_Basket -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_User_Basket(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_User_Basket() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.id_change_set_user <=> OLD.id_change_set_user THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_User_Basket_Audit ( - id_item, - name_field, - value_prev, - value_new, - id_change_set_user - ) - -- Changed id_user - SELECT NEW.id_item, 'id_user', OLD.id_user, NEW.id_user, NEW.id_change_set_user - WHERE NOT OLD.id_user <=> NEW.id_user - UNION - -- Changed id_product - SELECT NEW.id_item, 'id_product', OLD.id_product, NEW.id_product, NEW.id_change_set_user - WHERE NOT OLD.id_product <=> NEW.id_product - UNION - -- Changed quantity - SELECT NEW.id_item, 'quantity', CONVERT(OLD.quantity, CHAR), CONVERT(NEW.quantity, CHAR), NEW.id_change_set_user - WHERE NOT (OLD.quantity <=> NEW.quantity) - UNION - -- Changed active - SELECT NEW.id_item, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set_user - WHERE NOT (OLD.active <=> NEW.active) - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_User_Basket -BEFORE UPDATE ON Shop_User_Basket -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_User_Basket(); diff --git a/static/PostgreSQL/369_tri_Shop_User_Order_Status.sql b/static/PostgreSQL/369_tri_Shop_User_Order_Status.sql deleted file mode 100644 index 74560390..00000000 --- a/static/PostgreSQL/369_tri_Shop_User_Order_Status.sql +++ /dev/null @@ -1,63 +0,0 @@ - --- Shop User Order Type - -CREATE OR REPLACE FUNCTION before_insert_Shop_User_Order_Status() -RETURNS TRIGGER AS $$ -BEGIN - NEW.created_on = CURRENT_TIMESTAMP; - NEW.created_by = CURRENT_USER; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_User_Order_Status -BEFORE INSERT ON Shop_User_Order_Status -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_User_Order_Status(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_User_Order_Status() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_User_Order_Status_Audit ( - id_Status, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed code - SELECT NEW.id_Status, 'code', OLD.code, NEW.code, NEW.id_change_set - WHERE NOT OLD.code <=> NEW.code - UNION - -- Changed name - SELECT NEW.id_Status, 'name', OLD.name, NEW.name, NEW.id_change_set - WHERE NOT OLD.name <=> NEW.name - UNION - -- Changed name_plural - SELECT NEW.id_Status, 'name_plural', OLD.name_plural, NEW.name_plural, NEW.id_change_set - WHERE NOT OLD.name_plural <=> NEW.name_plural - UNION - -- Changed active - SELECT NEW.id_Status, 'active', CONVERT(CONVERT(OLD.active, SIGNED), CHAR), CONVERT(CONVERT(NEW.active, SIGNED), CHAR), NEW.id_change_set - WHERE NOT (OLD.active <=> NEW.active) - UNION - -- Changed display_order - SELECT NEW.id_Status, 'display_order', CONVERT(OLD.display_order, CHAR), CONVERT(NEW.display_order, CHAR), NEW.id_change_set - WHERE NOT (OLD.display_order <=> NEW.display_order) - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_User_Order_Status -BEFORE UPDATE ON Shop_User_Order_Status -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_User_Order_Status(); diff --git a/static/PostgreSQL/381.0_tri_Shop_Supplier.sql b/static/PostgreSQL/381.0_tri_Shop_Supplier.sql deleted file mode 100644 index 307b0688..00000000 --- a/static/PostgreSQL/381.0_tri_Shop_Supplier.sql +++ /dev/null @@ -1,83 +0,0 @@ - --- Shop Supplier - -CREATE OR REPLACE FUNCTION before_insert_Shop_Supplier() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Supplier -BEFORE INSERT ON Shop_Supplier -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Supplier(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Supplier() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Supplier_Audit ( - id_supplier, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed name_company - SELECT NEW.id_supplier, 'name_company', OLD.name_company, NEW.name_company, NEW.id_change_set - WHERE NOT OLD.name_company <=> NEW.name_company - UNION - -- Changed name_contact - SELECT NEW.id_supplier, 'name_contact', OLD.name_contact, NEW.name_contact, NEW.id_change_set - WHERE NOT OLD.name_contact <=> NEW.name_contact - UNION - -- Changed department_contact - SELECT NEW.id_supplier, 'department_contact', OLD.department_contact, NEW.department_contact, NEW.id_change_set - WHERE NOT OLD.department_contact <=> NEW.department_contact - UNION - -- Changed id_address - SELECT NEW.id_supplier, 'id_address', OLD.id_address, NEW.id_address, NEW.id_change_set - WHERE NOT OLD.id_address <=> NEW.id_address - UNION - -- Changed phone_number - SELECT NEW.id_supplier, 'phone_number', OLD.phone_number, NEW.phone_number, NEW.id_change_set - WHERE NOT OLD.phone_number <=> NEW.phone_number - UNION - -- Changed fax - SELECT NEW.id_supplier, 'fax', OLD.fax, NEW.fax, NEW.id_change_set - WHERE NOT OLD.fax <=> NEW.fax - UNION - -- Changed email - SELECT NEW.id_supplier, 'email', OLD.email, NEW.email, NEW.id_change_set - WHERE NOT OLD.email <=> NEW.email - UNION - -- Changed website - SELECT NEW.id_supplier, 'website', OLD.website, NEW.website, NEW.id_change_set - WHERE NOT OLD.website <=> NEW.website - UNION - -- Changed id_currency - SELECT NEW.id_supplier, 'id_currency', OLD.id_currency, NEW.id_currency, NEW.id_change_set - WHERE NOT OLD.id_currency <=> NEW.id_currency - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Supplier -BEFORE UPDATE ON Shop_Supplier -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Supplier(); diff --git a/static/PostgreSQL/381.2_tri_Shop_Unit_Measurement.sql b/static/PostgreSQL/381.2_tri_Shop_Unit_Measurement.sql deleted file mode 100644 index 87aa9ebc..00000000 --- a/static/PostgreSQL/381.2_tri_Shop_Unit_Measurement.sql +++ /dev/null @@ -1,67 +0,0 @@ - --- Shop Unit of Measurement - -CREATE OR REPLACE FUNCTION before_insert_Shop_Unit_Measurement() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Unit_Measurement -BEFORE INSERT ON Shop_Unit_Measurement -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Unit_Measurement(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Unit_Measurement() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Unit_Measurement_Audit ( - id_unit_measurement, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed name_singular - SELECT NEW.id_unit_measurement, 'name_singular', OLD.name_singular, NEW.name_singular, NEW.id_change_set - WHERE NOT OLD.name_singular <=> NEW.name_singular - UNION - -- Changed name_plural - SELECT NEW.id_unit_measurement, 'name_plural', OLD.name_plural, NEW.name_plural, NEW.id_change_set - WHERE NOT OLD.name_plural <=> NEW.name_plural - UNION - -- Changed symbol - SELECT NEW.id_unit_measurement, 'symbol', OLD.symbol, NEW.symbol, NEW.id_change_set - WHERE NOT OLD.symbol <=> NEW.symbol - UNION - -- Changed is_base_unit - SELECT NEW.id_unit_measurement, 'is_base_unit', OLD.is_base_unit, NEW.is_base_unit, NEW.id_change_set - WHERE NOT OLD.is_base_unit <=> NEW.is_base_unit - UNION - -- Changed active - SELECT NEW.id_unit_measurement, 'active', OLD.active, NEW.active, NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Unit_Measurement -BEFORE UPDATE ON Shop_Unit_Measurement -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Unit_Measurement(); diff --git a/static/PostgreSQL/381.4_tri_Shop_Unit_Of_Measurement_Conversion.sql b/static/PostgreSQL/381.4_tri_Shop_Unit_Of_Measurement_Conversion.sql deleted file mode 100644 index bbc78792..00000000 --- a/static/PostgreSQL/381.4_tri_Shop_Unit_Of_Measurement_Conversion.sql +++ /dev/null @@ -1,71 +0,0 @@ - --- Shop Unit of Measurement Conversion - -CREATE OR REPLACE FUNCTION before_insert_Shop_Unit_Measurement_Conversion() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Unit_Measurement_Conversion -BEFORE INSERT ON Shop_Unit_Measurement_Conversion -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Unit_Measurement_Conversion(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Unit_Measurement_Conversion() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Unit_Measurement_Conversion_Audit ( - id_conversion, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_unit_derived - SELECT NEW.id_conversion, 'id_unit_derived', OLD.id_unit_derived, NEW.id_unit_derived, NEW.id_change_set - WHERE NOT OLD.id_unit_derived <=> NEW.id_unit_derived - UNION - -- Changed id_unit_base - SELECT NEW.id_conversion, 'id_unit_base', OLD.id_unit_base, NEW.id_unit_base, NEW.id_change_set - WHERE NOT OLD.id_unit_base <=> NEW.id_unit_base - UNION - -- Changed power_unit_base - SELECT NEW.id_conversion, 'power_unit_base', OLD.power_unit_base, NEW.power_unit_base, NEW.id_change_set - WHERE NOT OLD.power_unit_base <=> NEW.power_unit_base - UNION - -- Changed multiplier_unit_base - SELECT NEW.id_conversion, 'multiplier_unit_base', OLD.multiplier_unit_base, NEW.multiplier_unit_base, NEW.id_change_set - WHERE NOT OLD.multiplier_unit_base <=> NEW.multiplier_unit_base - UNION - -- Changed increment_unit_base - SELECT NEW.id_conversion, 'active', OLD.increment_unit_base, NEW.increment_unit_base, NEW.id_change_set - WHERE NOT OLD.increment_unit_base <=> NEW.increment_unit_base - UNION - -- Changed active - SELECT NEW.id_conversion, 'active', OLD.active, NEW.active, NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Unit_Measurement_Conversion -BEFORE UPDATE ON Shop_Unit_Measurement_Conversion -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Unit_Measurement_Conversion(); diff --git a/static/PostgreSQL/381.6_tri_Shop_Supplier_Purchase_Order.sql b/static/PostgreSQL/381.6_tri_Shop_Supplier_Purchase_Order.sql deleted file mode 100644 index 4c2cc08c..00000000 --- a/static/PostgreSQL/381.6_tri_Shop_Supplier_Purchase_Order.sql +++ /dev/null @@ -1,78 +0,0 @@ - --- Shop Supplier Purchase Order - -CREATE OR REPLACE FUNCTION before_insert_Shop_Supplier_Purchase_Order() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Supplier_Purchase_Order -BEFORE INSERT ON Shop_Supplier_Purchase_Order -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Supplier_Purchase_Order(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Supplier_Purchase_Order() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Supplier_Purchase_Order_Audit ( - id_order, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_supplier_ordered - SELECT NEW.id_order, 'id_supplier_ordered', OLD.id_supplier_ordered, NEW.id_supplier_ordered, NEW.id_change_set - WHERE NOT OLD.id_supplier_ordered <=> NEW.id_supplier_ordered - UNION - -- Changed cost_total_local - SELECT NEW.id_order, 'cost_total_local', OLD.cost_total_local, NEW.cost_total_local, NEW.id_change_set - WHERE NOT OLD.cost_total_local <=> NEW.cost_total_local - UNION - -- Changed id_currency_cost - SELECT NEW.id_order, 'id_currency_cost', OLD.id_currency_cost, NEW.id_currency_cost, NEW.id_change_set - WHERE NOT OLD.id_currency_cost <=> NEW.id_currency_cost - /* - UNION - -- Changed latency_delivery - SELECT NEW.id_order, 'latency_delivery', OLD.latency_delivery, NEW.latency_delivery, NEW.id_change_set - WHERE NOT OLD.latency_delivery <=> NEW.latency_delivery - UNION - -- Changed quantity_ordered - SELECT NEW.id_order, 'quantity_ordered', OLD.quantity_ordered, NEW.quantity_ordered, NEW.id_change_set - WHERE NOT OLD.quantity_ordered <=> NEW.quantity_ordered - UNION - -- Changed id_unit_quantity - SELECT NEW.id_order, 'id_unit_quantity', OLD.id_unit_quantity, NEW.id_unit_quantity, NEW.id_change_set - WHERE NOT OLD.id_unit_quantity <=> NEW.id_unit_quantity - UNION - -- Changed quantity_received - SELECT NEW.id_order, 'quantity_received', OLD.quantity_received, NEW.quantity_received, NEW.id_change_set - WHERE NOT OLD.quantity_received <=> NEW.quantity_received - */ - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Supplier_Purchase_Order -BEFORE UPDATE ON Shop_Supplier_Purchase_Order -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Supplier_Purchase_Order(); - diff --git a/static/PostgreSQL/381.8_tri_Shop_Supplier_Purchase_Order_Product_Link.sql b/static/PostgreSQL/381.8_tri_Shop_Supplier_Purchase_Order_Product_Link.sql deleted file mode 100644 index 12c95581..00000000 --- a/static/PostgreSQL/381.8_tri_Shop_Supplier_Purchase_Order_Product_Link.sql +++ /dev/null @@ -1,87 +0,0 @@ - --- Shop Supplier Purchase Order Product Link - -CREATE OR REPLACE FUNCTION before_insert_Shop_Supplier_Purchase_Order_Product_Link() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Supplier_Purchase_Order_Product_Link -BEFORE INSERT ON Shop_Supplier_Purchase_Order_Product_Link -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Supplier_Purchase_Order_Product_Link(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Supplier_Purchase_Order_Product_Link() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Supplier_Purchase_Order_Product_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_order - SELECT NEW.id_link, 'id_order', OLD.id_order, NEW.id_order, NEW.id_change_set - WHERE NOT OLD.id_order <=> NEW.id_order - UNION - -- Changed id_permutation - SELECT NEW.id_link, 'id_permutation', OLD.id_permutation, NEW.id_permutation, NEW.id_change_set - WHERE NOT OLD.id_permutation <=> NEW.id_permutation - UNION - -- Changed cost_total_local - SELECT NEW.id_link, 'cost_total_local', OLD.cost_total_local, NEW.cost_total_local, NEW.id_change_set - WHERE NOT OLD.cost_total_local <=> NEW.cost_total_local - UNION - -- Changed id_currency_cost - SELECT NEW.id_link, 'id_currency_cost', OLD.id_currency_cost, NEW.id_currency_cost, NEW.id_change_set - WHERE NOT OLD.id_currency_cost <=> NEW.id_currency_cost - UNION - -- Changed quantity_ordered - SELECT NEW.id_link, 'quantity_ordered', OLD.quantity_ordered, NEW.quantity_ordered, NEW.id_change_set - WHERE NOT OLD.quantity_ordered <=> NEW.quantity_ordered - UNION - -- Changed id_unit_quantity - SELECT NEW.id_link, 'id_unit_quantity', OLD.id_unit_quantity, NEW.id_unit_quantity, NEW.id_change_set - WHERE NOT OLD.id_unit_quantity <=> NEW.id_unit_quantity - UNION - -- Changed quantity_received - SELECT NEW.id_link, 'quantity_received', OLD.quantity_received, NEW.quantity_received, NEW.id_change_set - WHERE NOT OLD.quantity_received <=> NEW.quantity_received - UNION - -- Changed latency_delivery_days - SELECT NEW.id_link, 'latency_delivery_days', OLD.latency_delivery_days, NEW.latency_delivery_days, NEW.id_change_set - WHERE NOT OLD.latency_delivery_days <=> NEW.latency_delivery_days - UNION - -- Changed display_order - SELECT NEW.id_link, 'display_order', OLD.display_order, NEW.display_order, NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - UNION - -- Changed active - SELECT NEW.id_link, 'active', OLD.active, NEW.active, NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Supplier_Purchase_Order_Product_Link -BEFORE UPDATE ON Shop_Supplier_Purchase_Order_Product_Link -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Supplier_Purchase_Order_Product_Link(); diff --git a/static/PostgreSQL/383_tri_Shop_Manufacturing_Purchase_Order.sql b/static/PostgreSQL/383_tri_Shop_Manufacturing_Purchase_Order.sql deleted file mode 100644 index ab23291e..00000000 --- a/static/PostgreSQL/383_tri_Shop_Manufacturing_Purchase_Order.sql +++ /dev/null @@ -1,63 +0,0 @@ - --- Shop Manufacturing Purchase Order - -CREATE OR REPLACE FUNCTION before_insert_Shop_Manufacturing_Purchase_Order() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Manufacturing_Purchase_Order -BEFORE INSERT ON Shop_Manufacturing_Purchase_Order -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Manufacturing_Purchase_Order(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Manufacturing_Purchase_Order() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Manufacturing_Purchase_Order_Audit ( - id_order, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed cost_total_local - SELECT NEW.id_order, 'cost_total_local', OLD.cost_total_local, NEW.cost_total_local, NEW.id_change_set - WHERE NOT OLD.cost_total_local <=> NEW.cost_total_local - UNION - -- Changed value_produced_total_local - SELECT NEW.id_order, 'value_produced_total_local', OLD.value_produced_total_local, NEW.value_produced_total_local, NEW.id_change_set - WHERE NOT OLD.value_produced_total_local <=> NEW.value_produced_total_local - UNION - -- Changed id_currency_cost - SELECT NEW.id_order, 'id_currency_cost', OLD.id_currency_cost, NEW.id_currency_cost, NEW.id_change_set - WHERE NOT OLD.id_currency_cost <=> NEW.id_currency_cost - UNION - -- Changed active - SELECT NEW.id_order, 'active', OLD.active, NEW.active, NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Manufacturing_Purchase_Order -BEFORE UPDATE ON Shop_Manufacturing_Purchase_Order -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Manufacturing_Purchase_Order(); diff --git a/static/PostgreSQL/385_tri_Shop_Manufacturing_Purchase_Order_Product_Link.sql b/static/PostgreSQL/385_tri_Shop_Manufacturing_Purchase_Order_Product_Link.sql deleted file mode 100644 index ed7062e0..00000000 --- a/static/PostgreSQL/385_tri_Shop_Manufacturing_Purchase_Order_Product_Link.sql +++ /dev/null @@ -1,87 +0,0 @@ - --- Shop Manufacturing Purchase Order Product Link - -CREATE OR REPLACE FUNCTION before_insert_Shop_Manufacturing_Purchase_Order_Product_Link() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Manufacturing_Purch_Order_Product_Link -BEFORE INSERT ON Shop_Manufacturing_Purchase_Order_Product_Link -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Manufacturing_Purchase_Order_Product_Link(); - - -CREATE OR REPLACE FUNCTION before_update_Manufacturing_Purch_Order_Product_Link() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Manufacturing_Purchase_Order_Product_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_order - SELECT NEW.id_link, 'id_order', OLD.id_order, NEW.id_order, NEW.id_change_set - WHERE NOT OLD.id_order <=> NEW.id_order - UNION - -- Changed id_permutation - SELECT NEW.id_link, 'id_permutation', OLD.id_permutation, NEW.id_permutation, NEW.id_change_set - WHERE NOT OLD.id_permutation <=> NEW.id_permutation - UNION - -- Changed cost_total_local - SELECT NEW.id_link, 'cost_total_local', OLD.cost_total_local, NEW.cost_total_local, NEW.id_change_set - WHERE NOT OLD.cost_total_local <=> NEW.cost_total_local - UNION - -- Changed id_currency_cost - SELECT NEW.id_link, 'id_currency_cost', OLD.id_currency_cost, NEW.id_currency_cost, NEW.id_change_set - WHERE NOT OLD.id_currency_cost <=> NEW.id_currency_cost - UNION - -- Changed quantity_used - SELECT NEW.id_link, 'quantity_used', OLD.quantity_used, NEW.quantity_used, NEW.id_change_set - WHERE NOT OLD.quantity_used <=> NEW.quantity_used - UNION - -- Changed id_unit_quantity - SELECT NEW.id_link, 'id_unit_quantity', OLD.id_unit_quantity, NEW.id_unit_quantity, NEW.id_change_set - WHERE NOT OLD.id_unit_quantity <=> NEW.id_unit_quantity - UNION - -- Changed quantity_produced - SELECT NEW.id_link, 'quantity_produced', OLD.quantity_produced, NEW.quantity_produced, NEW.id_change_set - WHERE NOT OLD.quantity_produced <=> NEW.quantity_produced - UNION - -- Changed latency_manufacture - SELECT NEW.id_link, 'latency_manufacture', OLD.latency_manufacture, NEW.latency_manufacture, NEW.id_change_set - WHERE NOT OLD.latency_manufacture <=> NEW.latency_manufacture - UNION - -- Changed display_order - SELECT NEW.id_link, 'display_order', OLD.display_order, NEW.display_order, NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - UNION - -- Changed active - SELECT NEW.id_link, 'active', OLD.active, NEW.active, NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Manufacturing_Purch_Order_Product_Link -BEFORE UPDATE ON Shop_Manufacturing_Purchase_Order_Product_Link -FOR EACH ROW -EXECUTE FUNCTION before_update_Manufacturing_Purch_Order_Product_Link(); - diff --git a/static/PostgreSQL/387.0_tri_Shop_Customer.sql b/static/PostgreSQL/387.0_tri_Shop_Customer.sql deleted file mode 100644 index 4c318e17..00000000 --- a/static/PostgreSQL/387.0_tri_Shop_Customer.sql +++ /dev/null @@ -1,79 +0,0 @@ - --- Shop Customer - -CREATE OR REPLACE FUNCTION before_insert_Shop_Customer() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Customer -BEFORE INSERT ON Shop_Customer -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Customer(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Customer() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Customer_Audit ( - id_customer, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed name_company - SELECT NEW.id_customer, 'name_company', OLD.name_company, NEW.name_company, NEW.id_change_set - WHERE NOT OLD.name_company <=> NEW.name_company - UNION - -- Changed name_contact - SELECT NEW.id_customer, 'name_contact', OLD.name_contact, NEW.name_contact, NEW.id_change_set - WHERE NOT OLD.name_contact <=> NEW.name_contact - UNION - -- Changed department_contact - SELECT NEW.id_customer, 'department_contact', OLD.department_contact, NEW.department_contact, NEW.id_change_set - WHERE NOT OLD.department_contact <=> NEW.department_contact - UNION - -- Changed id_address - SELECT NEW.id_customer, 'id_address', OLD.id_address, NEW.id_address, NEW.id_change_set - WHERE NOT OLD.id_address <=> NEW.id_address - UNION - -- Changed phone_number - SELECT NEW.id_customer, 'phone_number', OLD.phone_number, NEW.phone_number, NEW.id_change_set - WHERE NOT OLD.phone_number <=> NEW.phone_number - UNION - -- Changed email - SELECT NEW.id_customer, 'email', OLD.email, NEW.email, NEW.id_change_set - WHERE NOT OLD.email <=> NEW.email - UNION - -- Changed id_currency - SELECT NEW.id_customer, 'id_currency', OLD.id_currency, NEW.id_currency, NEW.id_change_set - WHERE NOT OLD.id_currency <=> NEW.id_currency - UNION - -- Changed active - SELECT NEW.id_customer, 'active', OLD.active, NEW.active, NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Customer -BEFORE UPDATE ON Shop_Customer -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Customer(); - diff --git a/static/PostgreSQL/387.2_tri_Shop_Customer_Sales_Order.sql b/static/PostgreSQL/387.2_tri_Shop_Customer_Sales_Order.sql deleted file mode 100644 index f752f5e7..00000000 --- a/static/PostgreSQL/387.2_tri_Shop_Customer_Sales_Order.sql +++ /dev/null @@ -1,62 +0,0 @@ - --- Shop Customer Sales Order - -CREATE OR REPLACE FUNCTION before_insert_Shop_Customer_Sales_Order() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Customer_Sales_Order -BEFORE INSERT ON Shop_Customer_Sales_Order -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Customer_Sales_Order(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Customer_Sales_Order() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Customer_Sales_Order_Audit ( - id_order, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_customer - SELECT NEW.id_order, 'id_customer', OLD.id_customer, NEW.id_customer, NEW.id_change_set - WHERE NOT OLD.id_customer <=> NEW.id_customer - UNION - -- Changed price_total_local - SELECT NEW.id_order, 'price_total_local', OLD.price_total_local, NEW.price_total_local, NEW.id_change_set - WHERE NOT OLD.price_total_local <=> NEW.price_total_local - UNION - -- Changed id_currency_price - SELECT NEW.id_order, 'id_currency_price', OLD.id_currency_price, NEW.id_currency_price, NEW.id_change_set - WHERE NOT OLD.id_currency_price <=> NEW.id_currency_price - UNION - -- Changed active - SELECT NEW.id_order, 'active', OLD.active, NEW.active, NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Customer_Sales_Order -BEFORE UPDATE ON Shop_Customer_Sales_Order -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Customer_Sales_Order(); diff --git a/static/PostgreSQL/389_tri_Shop_Customer_Sales_Order_Product_Link.sql b/static/PostgreSQL/389_tri_Shop_Customer_Sales_Order_Product_Link.sql deleted file mode 100644 index 80a03098..00000000 --- a/static/PostgreSQL/389_tri_Shop_Customer_Sales_Order_Product_Link.sql +++ /dev/null @@ -1,86 +0,0 @@ - --- Shop Customer Sales Order Product Link - -CREATE OR REPLACE FUNCTION before_insert_Shop_Customer_Sales_Order_Product_Link() -RETURNS TRIGGER AS $$ -BEGIN - IF NEW.created_on IS NULL THEN - NEW.created_on = CURRENT_TIMESTAMP; - END IF; - IF NEW.created_by IS NULL THEN - NEW.created_by = CURRENT_USER; - END IF; - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_insert_Shop_Customer_Sales_Order_Product_Link -BEFORE INSERT ON Shop_Customer_Sales_Order_Product_Link -FOR EACH ROW -EXECUTE FUNCTION before_insert_Shop_Customer_Sales_Order_Product_Link(); - - -CREATE OR REPLACE FUNCTION before_update_Shop_Customer_Sales_Order_Product_Link() -RETURNS TRIGGER AS $$ -BEGIN - IF OLD.id_change_set IS NOT DISTINCT FROM NEW.id_change_set THEN - RAISE EXCEPTION 'New change Set ID must be provided.' - USING ERRCODE = '45000'; - END IF; - - INSERT INTO Shop_Customer_Sales_Order_Product_Link_Audit ( - id_link, - name_field, - value_prev, - value_new, - id_change_set - ) - -- Changed id_order - SELECT NEW.id_link, 'id_order', OLD.id_order, NEW.id_order, NEW.id_change_set - WHERE NOT OLD.id_order <=> NEW.id_order - UNION - -- Changed id_permutation - SELECT NEW.id_link, 'id_permutation', OLD.id_permutation, NEW.id_permutation, NEW.id_change_set - WHERE NOT OLD.id_permutation <=> NEW.id_permutation - UNION - -- Changed price_total_local - SELECT NEW.id_link, 'price_total_local', OLD.price_total_local, NEW.price_total_local, NEW.id_change_set - WHERE NOT OLD.price_total_local <=> NEW.price_total_local - UNION - -- Changed id_currency_price - SELECT NEW.id_link, 'id_currency_price', OLD.id_currency_price, NEW.id_currency_price, NEW.id_change_set - WHERE NOT OLD.id_currency_price <=> NEW.id_currency_price - UNION - -- Changed quantity_ordered - SELECT NEW.id_link, 'quantity_ordered', OLD.quantity_ordered, NEW.quantity_ordered, NEW.id_change_set - WHERE NOT OLD.quantity_ordered <=> NEW.quantity_ordered - UNION - -- Changed id_unit_quantity - SELECT NEW.id_link, 'id_unit_quantity', OLD.id_unit_quantity, NEW.id_unit_quantity, NEW.id_change_set - WHERE NOT OLD.id_unit_quantity <=> NEW.id_unit_quantity - UNION - -- Changed quantity_delivered - SELECT NEW.id_link, 'quantity_delivered', OLD.quantity_delivered, NEW.quantity_delivered, NEW.id_change_set - WHERE NOT OLD.quantity_delivered <=> NEW.quantity_delivered - UNION - -- Changed latency_delivery_days - SELECT NEW.id_link, 'latency_delivery_days', OLD.latency_delivery_days, NEW.latency_delivery_days, NEW.id_change_set - WHERE NOT OLD.latency_delivery_days <=> NEW.latency_delivery_days - UNION - -- Changed display_order - SELECT NEW.id_link, 'display_order', OLD.display_order, NEW.display_order, NEW.id_change_set - WHERE NOT OLD.display_order <=> NEW.display_order - UNION - -- Changed active - SELECT NEW.id_link, 'active', OLD.active, NEW.active, NEW.id_change_set - WHERE NOT OLD.active <=> NEW.active - ; - - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE TRIGGER tri_before_update_Shop_Customer_Sales_Order_Product_Link -BEFORE UPDATE ON Shop_Customer_Sales_Order_Product_Link -FOR EACH ROW -EXECUTE FUNCTION before_update_Shop_Customer_Sales_Order_Product_Link(); diff --git a/static/PostgreSQL/600_p_shop_save_product.sql b/static/PostgreSQL/600_p_shop_save_product.sql deleted file mode 100644 index d29a1d12..00000000 --- a/static/PostgreSQL/600_p_shop_save_product.sql +++ /dev/null @@ -1,257 +0,0 @@ - - -DO $$ -BEGIN - RAISE NOTICE 'TRIGGER CREATION COMPLETE'; -END $$; - -/* -CREATE OR REPLACE PROCEDURE p_save_product ( - IN a_guid UUID, - -) -AS $$ -BEGIN - - -- Argument default values - IF a_ids_category IS NULL THEN - SET a_ids_category = ''; - END IF; - IF a_get_inactive_categories IS NULL THEN - SET a_get_inactive_categories = FALSE; - END IF; - /* - IF a_get_all_categories IS NULL THEN - SET a_get_all_categories = FALSE; - END IF; - */ - IF a_ids_product IS NULL THEN - SET a_ids_product = ''; - END IF; - IF a_get_inactive_products IS NULL THEN - SET a_get_inactive_products = FALSE; - END IF; - IF a_get_first_product_only IS NULL THEN - SET a_get_first_product_only = TRUE; - END IF; - IF a_get_all_products IS NULL THEN - SET a_get_all_products = FALSE; - END IF; - IF a_ids_image IS NULL THEN - SET a_ids_image = ''; - END IF; - IF a_get_inactive_images IS NULL THEN - SET a_get_inactive_images = FALSE; - END IF; - IF a_get_first_image_only IS NULL THEN - SET a_get_first_image_only = TRUE; - END IF; - IF a_get_all_images IS NULL THEN - SET a_get_all_images = FALSE; - END IF; - - - -- Temporary tables - CREATE TABLE tmp_Shop_Product_Category ( - id_category INTEGER NOT NULL, - active BOOLEAN NOT NULL, - display_order INTEGER NOT NULL, - can_view BOOLEAN NOT NULL, - can_edit BOOLEAN NOT NULL, - can_admin BOOLEAN NOT NULL - ); - - CREATE TABLE tmp_Shop_Product ( - id_category INTEGER NOT NULL, - id_product INTEGER NOT NULL, - active BOOLEAN NOT NULL, - display_order INTEGER NOT NULL, - can_view BOOLEAN NOT NULL, - can_edit BOOLEAN NOT NULL, - can_admin BOOLEAN NOT NULL - ); - - CREATE TABLE tmp_Shop_Variation ( - id_variation INTEGER NOT NULL, - id_product INTEGER NOT NULL, - display_order INTEGER NOT NULL - ); - - CREATE TABLE tmp_Shop_Image ( - id_product INTEGER NOT NULL, - id_image INTEGER NOT NULL, - active BOOLEAN NOT NULL, - display_order INTEGER NOT NULL - ); - - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - guid UUID NOT NULL, - id_type INTEGER NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type (id_type), - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - - - -- Parse filters - SET a_ids_category = REPLACE(a_ids_category, ',', '|'); - SET a_ids_product = REPLACE(a_ids_product, ',', '|'); - SET v_has_filter_category = CASE WHEN a_ids_category = '' THEN FALSE ELSE TRUE END; - SET v_has_filter_product = CASE WHEN a_ids_product = '' THEN FALSE ELSE TRUE END; - - INSERT INTO tmp_Shop_Product_Category ( - id_category, active, display_order - ) - SELECT C.id_category, C.active, C.display_order - FROM Shop_Product_Category C - WHERE (NOT v_has_filter_category OR C.id_category LIKE '%' || a_ids_category || '%') - AND (a_get_inactive_categories OR C.active); - - INSERT INTO tmp_Shop_Product ( - id_category, id_product, active, display_order - ) - SELECT P.id_category, P.id_product, P.active, P.display_order - FROM Shop_Product P - INNER JOIN tmp_Shop_Product_Category tC - ON P.id_category = tC.id_category - WHERE (a_get_all_products OR P.id_product LIKE '%' || a_ids_product || '%') - AND (a_get_inactive_products OR P.active); - - IF a_get_first_product_only THEN - DELETE FROM tmp_Shop_Product - WHERE display_order > (SELECT display_order FROM tmp_Shop_Product ORDER BY display_order ASC LIMIT 1); - END IF; - - IF v_has_filter_product THEN - DELETE FROM tmp_Shop_Product_Category - WHERE id_category NOT IN (SELECT DISTINCT id_category FROM tmp_Shop_Product); - END IF; - - INSERT INTO tmp_Shop_Variation ( - id_variation, id_product -- , display_order - ) - SELECT P.id_variation, P.id_product -- , P.display_order - FROM Shop_Variation V - INNER JOIN tmp_Shop_Product tP - ON V.id_product = tP.id_product - WHERE V.active; - - INSERT INTO tmp_Shop_Image ( - id_product, id_image, active, display_order - ) - SELECT I.id_product, I.id_image, I.active, I.display_order - FROM Shop_Image I - INNER JOIN tmp_Shop_Product tP - ON I.id_image = tP.id_image - WHERE (a_get_all_images OR I.id_image LIKE '%' || a_ids_image || '%') - AND (a_get_inactive_images OR I.active); - - IF a_get_first_image_only THEN - DELETE FROM tmp_Shop_Image - WHERE display_order > (SELECT display_order FROM tmp_Shop_Image ORDER BY display_order ASC LIMIT 1); - END IF; - - IF v_has_filter_image THEN - DELETE FROM tmp_Shop_Product - WHERE id_product NOT IN (SELECT DISTINCT id_product FROM tmp_Shop_Image); - DELETE FROM tmp_Shop_Product_Category - WHERE id_category NOT IN (SELECT DISTINCT id_category FROM tmp_Shop_Product); - END IF; - - - -- Permissions - IF EXISTS (SELECT * FROM tmp_Shop_Product_Category LIMIT 1) THEN - SET v_guid_permission = gen_random_uuid(); - SET v_id_user = CURRENT_USER; - SET v_id_permission_product = (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_PRODUCT' LIMIT 1); - SET v_ids_product_permission = (SELECT STRING_AGG(item, '|') FROM tmp_Shop_Product); - - CALL p_shop_calc_user(v_guid_permission, v_id_user, v_id_permission_product, v_ids_product_permission); - - UPDATE tmp_Shop_Product tP - INNER JOIN Shop_Calc_User_Temp TP - ON tP.id_product = TP.id_product - AND TP.GUID = v_guid_permission - SET tP.can_view = TP.can_view, - tP.can_edit = TP.can_edit, - tP.can_admin = TP.can_admin; - - CALL p_shop_clear_calc_user(v_guid_permission); - END IF; - - - -- Returns - SET v_now = CURRENT_TIMESTAMP; - - -- Categories - SELECT ( - tC.id_category, - C.name, - C.description, - tC.can_view, - tC.can_edit, - tC.can_admin - ) - FROM tmp_Shop_Product_Category tC - INNER JOIN Shop_Product_Category C - ON tC.id_category = C.id_category - ; - - -- Products - SELECT - tP.id_product, - P.name, - P.price, - P.description, - C.id_category, - P.lead_time, - P.id_stripe_product, - P.id_stripe_price, - P.is_subscription, - RI.name AS name_interval_recurrence, - RI.name_plural AS name_plural_interval_recurrence, - P.count_interval_recurrence, - tP.can_view, - tP.can_edit, - tP.can_admin - FROM tmp_Shop_Product tP - INNER JOIN Shop_Product P - ON tP.id_product = P.id_product - INNER JOIN Shop_Interval_Recurrence RI - ON P.id_unit_measurement_interval_recurrence = RI.id_interval - ; - - -- Variations - SELECT - PVL.id_variation, - tV.id_product, - V.code, - V.name, - PVL.display_order - FROM tmp_Shop_Product tV - INNER JOIN Shop_Product_Variation_Link PVL - ON tV.id_product = PVL.id_product - INNER JOIN Shop_Variation V - ON PVL.id_variation = V.id_variation - WHERE V.active - AND PVL.active - ; - - -- Images - SELECT - tI.id_image, - tI.id_product, - I.url, - PIL.display_order - FROM tmp_Shop_Image tI - INNER JOIN Shop_Product_Image_Link PIL - ON tI.id_product = PIL.id_product - WHERE I.active - AND PIL.active - ; -END; -$$ LANGUAGE plpgsql; -*/ diff --git a/static/PostgreSQL/600_p_shop_user_eval.sql b/static/PostgreSQL/600_p_shop_user_eval.sql deleted file mode 100644 index f50b45c0..00000000 --- a/static/PostgreSQL/600_p_shop_user_eval.sql +++ /dev/null @@ -1,730 +0,0 @@ - -/* - -CALL p_shop_calc_user ( - gen_random_uuid(), -- a_guid - '', -- a_id_user - 0, -- a_get_inactive_users - '1', -- a_ids_permission - '', -- a_ids_access_level - '1' -- a_ids_product -) - -*/ - -CREATE OR REPLACE PROCEDURE p_shop_calc_user ( - IN a_guid UUID, - IN a_id_user INTEGER, - IN a_get_inactive_users BOOLEAN, - IN a_ids_permission INTEGER[], - IN a_ids_access_level INTEGER[], - IN a_ids_product INTEGER[] -- VARCHAR(4000) -- IN a_ids_permutation VARCHAR(4000) - /* - OUT result_errors TABLE ( - guid UUID, - id_type INTEGER, - code VARCHAR(50), - msg VARCHAR(4000) - ) - */ - -- INOUT a_error_msg TEXT -) -AS $$ -DECLARE - v_guid UUID; - v_id_user INTEGER; - v_get_inactive_users BOOLEAN; - v_ids_permission INTEGER[]; - v_ids_access_level INTEGER[]; - v_ids_product INTEGER[]; -- TEXT; -- VARCHAR(4000); -- IN a_ids_permutation VARCHAR(4000) - v_has_filter_user BOOLEAN; - v_has_filter_permission BOOLEAN; - v_has_filter_access_level BOOLEAN; - -- v_has_filter_permutation BOOLEAN; - v_has_filter_product BOOLEAN; - v_id_permission_product INTEGER; - v_id_permission INTEGER; - -- v_ids_product UUID; - v_id_access_level_view INTEGER; - -- v_id_access_level_product_required INTEGER; - v_priority_access_level_view INTEGER; - v_priority_access_level_edit INTEGER; - v_priority_access_level_admin INTEGER; - v_id_access_level INTEGER; - v_priority_access_level INTEGER; - v_now TIMESTAMP; - v_ids_row_delete UUID; - v_code_error_data VARCHAR(200); - v_id_error_data INTEGER; - v_code_error_permission VARCHAR(200); - -- result_errors REFCURSOR; - -- v_error_msg TEXT := NULL; -BEGIN - -- Parse arguments + get default values - v_guid := COALESCE(a_guid, gen_random_uuid()); - v_id_user := CASE WHEN a_id_user IS NULL THEN '' ELSE TRIM(a_id_user) END; - v_get_inactive_users := COALESCE(a_get_inactive_users, FALSE); - v_ids_permission := COALESCE(a_ids_permission, ARRAY[]::INTEGER[]); - v_ids_access_level := COALESCE(a_ids_access_level, ARRAY[]::INTEGER[]); - -- v_ids_permutation := CASE WHEN a_ids_permutation IS NULL THEN '' ELSE TRIM(a_ids_permutation) END; - v_ids_product := COALESCE(a_ids_product, ARRAY[]::INTEGER[]); - - v_id_error_data := 1; - v_code_error_data := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = v_id_error_data); - - v_code_error_permission := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 2); - - v_has_filter_user := (v_id_user <= 0); - v_has_filter_permission := (CARDINALITY(v_ids_permission) > 0); - v_has_filter_access_level := (CARDINALITY(v_ids_access_level) > 0); - /* - v_has_filter_permutation := CASE WHEN v_ids_permutation = '' THEN FALSE ELSE TRUE END; - */ - v_has_filter_product := (CARDINALITY(v_ids_product) = 0); - v_id_access_level_view := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW' LIMIT 1); - v_priority_access_level_view := (SELECT priority FROM Shop_Access_Level WHERE id_access_level = v_id_access_level_view); - v_priority_access_level_edit := (SELECT priority FROM Shop_Access_Level WHERE code = 'EDIT' LIMIT 1); - v_priority_access_level_admin := (SELECT priority FROM Shop_Access_Level WHERE code = 'ADMIN' LIMIT 1); - - v_id_permission_product := (SELECT v_id_permission FROM Shop_Permission WHERE code = 'SHOP_PRODUCT' LIMIT 1); - - -- Clear previous proc results - -- DROP TABLE IF EXISTS tmp_User_Role_Link; - -- DROP TEMPORARY TABLE IF EXISTS tmp_User_Role_Link; - DROP TABLE IF EXISTS tmp_Shop_Product_p_shop_calc_user; - -- DROP TABLE IF EXISTS Shop_Calc_User_Temp; - - - -- Permanent Table - CREATE TABLE IF NOT EXISTS Shop_Calc_User_Temp ( - id_row INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - guid UUID NOT NULL, - id_user INTEGER, - CONSTRAINT FK_Shop_Calc_User_Temp_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User (id_user), - id_permission_required INTEGER NOT NULL, - CONSTRAINT FK_Shop_Calc_User_Temp_id_permission_required - FOREIGN KEY (id_permission_required) - REFERENCES Shop_Permission (id_permission), - /* - id_access_level_required INTEGER NOT NULL, - CONSTRAINT FK_Shop_Calc_User_Temp_id_access_level_required - FOREIGN KEY (id_access_level_required) - REFERENCES Shop_Access_Level (id_access_level), - */ - priority_access_level_required INTEGER NOT NULL, - /* - CONSTRAINT FK_Shop_Calc_User_Temp_priority_access_level_required - FOREIGN KEY (priority_access_level_required) - REFERENCES Shop_Access_Level (priority), - */ - id_product INTEGER NULL, - CONSTRAINT FK_Shop_Calc_User_Temp_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product (id_product), - /* - id_permutation INTEGER NULL, - CONSTRAINT FK_Shop_Calc_User_Temp_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES parts.Shop_Product_Permutation (id_permutation), - */ - is_super_user BOOLEAN NULL, - priority_access_level_user INTEGER NULL, - /* - CONSTRAINT FK_Shop_Calc_User_Temp_priority_access_level_minimum - FOREIGN KEY (priority_access_level_minimum) - REFERENCES Shop_Access_Level (priority) - */ - can_view BOOLEAN, - can_edit BOOLEAN, - can_admin BOOLEAN, -- DEFAULT 0 - name_error VARCHAR(200) NULL - ); - - -- Temporary tables - CREATE TEMPORARY TABLE tmp_Shop_Product_p_shop_calc_user ( - id_row INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_product INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_p_shop_calc_user_id_product FOREIGN KEY (id_product) - REFERENCES Shop_Product (id_product), - /* - id_permutation INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_p_shop_calc_user_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES parts.Shop_Product_Permutation (id_permutation), - */ - id_access_level_required INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_p_shop_calc_user_id_access_level_required - FOREIGN KEY (id_access_level_required) - REFERENCES Shop_Access_Level (id_access_level), - guid UUID NOT NULL, - rank_product INTEGER NOT NULL - ); - - /* - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - guid UUID NOT NULL, - id_type INTEGER NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type (id_type), - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - */ - - - -- Permission IDs - IF v_has_filter_permission THEN - -- CALL p_split(a_guid, v_ids_permission, ','); - - -- Invalid - IF EXISTS ( - SELECT UNNEST(v_ids_permission) AS id_permission - EXCEPT - SELECT id_permission FROM Shop_Permission - ) THEN -- (SELECT PERM.id_permission FROM Split_Temp ST LEFT JOIN Shop_Permission PERM ON ST.substring = PERM.id_permission WHERE ISNULL(PERM.id_permission)) THEN - /* - INSERT INTO tmp_Msg_Error ( - guid, - id_type, - code, - msg - ) - SELECT - v_guid, - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_data LIMIT 1), - v_code_error_data, - 'Invalid permission IDs: ' || COALESCE(STRING_AGG(ST.substring, ', '), 'NULL') - FROM Split_Temp ST - LEFT JOIN Shop_Permission PERM ON ST.substring = PERM.id_permission - WHERE ISNULL(PERM.id_permission) - ; - */ - RAISE EXCEPTION 'Invalid permission IDs: %', ( - SELECT STRING_AGG(id_permission, ', ') - FROM ( - SELECT UNNEST(v_ids_permission) AS id_permission - EXCEPT - SELECT id_permission FROM Shop_Permission - ) Permission - ) - USING ERRCODE = '22000' - ; - END IF; - - -- Inactive - IF EXISTS ( - SELECT UNNEST(v_ids_permission) AS id_permission - EXCEPT - SELECT id_permission FROM Shop_Permission - WHERE active - ) THEN -- (SELECT PERM.id_permission FROM Split_Temp ST INNER JOIN Shop_Permission PERM ON ST.substring = PERM.id_permission WHERE PERM.active = FALSE) THEN - /* - INSERT INTO tmp_Msg_Error ( - guid, - id_type, - code, - msg - ) - SELECT - v_guid, - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_data LIMIT 1), - v_code_error_data, - 'The following permissions are not active: ' || COALESCE(STRING_AGG(ST.substring, ', '), 'NULL') - FROM Split_Temp ST - INNER JOIN Shop_Permission PERM ON ST.substring = PERM.id_permission - WHERE PERM.active = FALSE - ; - */ - RAISE EXCEPTION 'Inactive permission IDs: %', ( - SELECT STRING_AGG(id_permission, ', ') - FROM ( - SELECT UNNEST(v_ids_permission) AS id_permission - EXCEPT - SELECT id_permission FROM Shop_Permission - WHERE active - ) Permission - ) - USING ERRCODE = '22000' - ; - END IF; - - -- Get the permission with the highest priority access level required - v_id_permission := ( - SELECT PERMS.id_permission - FROM ( - SELECT PERM2.id_permission - FROM Split_Temp ST - INNER JOIN Shop_Permission PERM2 ON ST.substring = PERM2.id_permission - WHERE PERM.active - UNION - SELECT v_id_permission_product - ) PERMS - INNER JOIN Shop_Permission PERM1 ON PERMS.id_permission = PERM1.id_permission - INNER JOIN Shop_Access_Level AL ON PERM1.id_access_level_required = AL.id_access_level - ORDER BY AL.priority ASC - LIMIT 1 - ); - - -- DROP TABLE Split_Temp; - ELSIF v_has_filter_product THEN - v_id_permission := v_id_permission_product; - ELSE - /* - INSERT INTO tmp_Msg_Error ( - guid, - id_type, - code, - msg - ) - VALUES ( - v_guid, - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_data LIMIT 1), - v_code_error_data, - 'Permission ID required' - ) - ; - */ - RAISE EXCEPTION 'Permission ID required.' - USING ERRCODE = '22000' - ; - END IF; - - -- access level - IF v_has_filter_access_level THEN - IF EXISTS ( - /* - SELECT ST.substring - FROM Split_Temp ST - LEFT JOIN Shop_Access_Level AL - ON ST.substring = AL.id_access_level - WHERE - ISNULL(AL.id_access_level) - OR AL.active = FALSE - */ - SELECT UNNEST(v_ids_access_level) AS id_access_level - EXCEPT - SELECT id_access_level FROM Shop_Access_Level - ) THEN - /* - INSERT INTO tmp_Msg_Error ( - guid, - id_type, - code, - msg - ) - SELECT - v_guid, - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_data LIMIT 1), - v_code_error_data, - 'Invalid access level IDs: ' || STRING_AGG(ST.substring, ', ') - FROM Split_Temp ST - LEFT JOIN Shop_Access_Level AL ON ST.substring = AL.id_access_level - WHERE ISNULL(AL.id_access_level) - ; - */ - RAISE EXCEPTION 'Invalid access level IDs: %', ( - SELECT STRING_AGG(id_access_level, ', ') - FROM ( - SELECT UNNEST(v_ids_access_level) AS id_access_level - EXCEPT - SELECT id_access_level FROM Shop_Access_Level - ) AL - ) - USING ERRCODE = '22000' - ; - END IF; - - IF EXISTS ( - SELECT UNNEST(v_ids_access_level) AS id_access_level - EXCEPT - SELECT id_access_level FROM Shop_Access_Level - WHERE active - ) THEN - RAISE EXCEPTION 'Inactive access level IDs: %', ( - SELECT STRING_AGG(id_access_level, ', ') - FROM ( - SELECT UNNEST(v_ids_access_level) AS id_access_level - EXCEPT - SELECT id_access_level FROM Shop_Access_Level - ) AL - ) - USING ERRCODE = '22000' - ; - END IF; - - v_id_access_level := ( - SELECT AL.id_access_level - FROM Shop_Access_Level AL - WHERE - AL.active - AND AL.id_access_level = ANY(v_ids_access_level) - ORDER BY AL.priority ASC - LIMIT 1 - ); - ELSE - v_id_access_level := ( - SELECT id_access_level_required AS id_access_level - FROM ( - SELECT id_access_level - FROM Shop_Permission PERM - WHERE - PERM.id_permission = v_id_permission - UNION - SELECT v_id_access_level_view AS id_access_level - ) PERMS - INNER JOIN Shop_Access_Level AL ON PERMS.id_access_level = AL.id_access_level - ORDER BY AL.priority ASC - LIMIT 1 - ); -- v_id_access_level_view; - END IF; - - v_priority_access_level := (SELECT priority FROM Shop_Access_Level WHERE id_access_level = v_id_access_level); - - -- Invalid user ID - IF v_has_filter_user THEN - IF ISNULL((SELECT id_user FROM Shop_User WHERE id_user = v_id_user)) THEN -- NOT v_has_filter_user THEN - /* - INSERT INTO tmp_Msg_Error ( - guid, - id_type, - code, - msg - ) - VALUES ( - v_guid, - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_data LIMIT 1), - v_code_error_data, - 'Invalid user ID: ' || COALESCE(v_id_user, 'NULL') - ) - ; - */ - RAISE EXCEPTION 'Invalid user ID: %', v_id_user - USING ERRCODE = '22000' - ; - END IF; - - IF ISNULL((SELECT id_user FROM Shop_User WHERE id_user = v_id_user AND active)) THEN - RAISE EXCEPTION 'Inactive user ID: %', v_id_user - USING ERRCODE = '22000' - ; - END IF; - END IF; - - - -- Invalid products - IF v_has_filter_product THEN - -- Invalid product IDs - IF EXISTS ( - SELECT UNNEST(v_ids_product) AS id_product - EXCEPT - SELECT id_product FROM Shop_Product - ) THEN -- (SELECT * FROM Split_Temp ST LEFT JOIN Shop_Product P ON ST.substring = P.id_product WHERE ISNULL(P.id_product)) THEN - /* - INSERT INTO tmp_Msg_Error ( - guid, - id_type, - code, - msg - ) - SELECT - v_guid, - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_data LIMIT 1), - v_code_error_data, - 'Invalid product IDs: ' || COALESCE(STRING_AGG(ST.substring, ', '), 'NULL') - FROM Split_Temp ST - LEFT JOIN Shop_Product P ON ST.substring = P.id_product - WHERE ISNULL(P.id_product) - ; - */ - RAISE EXCEPTION 'Invalid product IDs: %', ( - SELECT STRING_AGG(id_product, ', ') - FROM ( - SELECT UNNEST(v_ids_product) AS id_product - EXCEPT - SELECT id_product FROM Shop_Product - ) Product - ) - USING ERRCODE = '22000' - ; - END IF; - - INSERT INTO tmp_Shop_Product_p_shop_calc_user ( - id_product, - -- id_permutation, - id_access_level_required, - guid, - rank_product -- rank_permutation - ) - SELECT - DISTINCT P.id_product, - -- PP.id_permutation, - P.id_access_level_required, - v_guid, - RANK() OVER (ORDER BY C.display_order, P.display_order) AS rank_product - FROM Shop_Product P -- ON ST.substring = P.id_product -- Shop_Product_Permutation PP - INNER JOIN Shop_Product_Category C ON P.id_category = C.id_category - INNER JOIN Shop_Access_Level AL - ON P.id_access_level_required = AL.id_access_level - AND AL.active - WHERE -- FIND_IN_SET(P.id_product, v_ids_product) > 0 -- FIND_IN_SET(PP.id_permutation, v_ids_permutation) > 0 - P.id_product = ANY(v_ids_product) - -- AND P.active -- not worried as we want users to be able to see their order history - ; - /* - DELETE FROM tmp_Shop_Product_p_shop_calc_user - WHERE rank_permutation > 1 - ; - */ - -- v_has_filter_product := EXISTS (SELECT * FROM tmp_Shop_Product_p_shop_calc_user WHERE v_guid = guid); - END IF; - - -- User permissions - /* - IF v_has_filter_product THEN - INSERT INTO Shop_Calc_User_Temp ( - guid, - id_user, - id_permission_required, - id_product, - -- id_permutation, - priority_access_level_required, - priority_access_level_user, - is_super_user, - can_view, - can_edit, - can_admin - ) - SELECT - v_guid, - v_id_user, - v_id_permission AS id_permission_required, - P.id_product, - -- t_P.id_permutation, - CASE WHEN v_priority_access_level <= AL_P.priority THEN v_priority_access_level ELSE AL_P.priority END AS priority_access_level_required, - AL_U.priority AS priority_access_level_user, - U.is_super_user, - CASE WHEN U.is_super_user THEN TRUE ELSE CASE WHEN NOT ISNULL(AL_U.priority) AND AL_U.priority <= v_priority_access_level_view AND AL_U.priority <= priority_access_level_required THEN TRUE ELSE FALSE END END AS can_view, - CASE WHEN U.is_super_user THEN TRUE ELSE CASE WHEN NOT ISNULL(AL_U.priority) AND AL_U.priority <= v_priority_access_level_edit AND AL_U.priority <= priority_access_level_required THEN TRUE ELSE FALSE END END AS can_edit, - CASE WHEN U.is_super_user THEN TRUE ELSE CASE WHEN NOT ISNULL(AL_U.priority) AND AL_U.priority <= v_priority_access_level_admin AND AL_U.priority <= priority_access_level_required THEN TRUE ELSE FALSE END END AS can_admin - FROM Shop_User U - /* - ON U.id_user = v_id_user - AND U.active - */ - LEFT JOIN Shop_User_Role_Link URL - ON U.id_user = URL.id_user - AND URL.active - LEFT JOIN Shop_Role_Permission_Link RPL - ON URL.id_role = RPL.id_role - AND RPL.active - INNER JOIN Shop_Access_Level AL_U - ON RPL.id_access_leveL = AL_U.id_access_level - AND AL_U.active - INNER JOIN tmp_Shop_Product_p_shop_calc_user t_P - ON t_P.guid = v_guid - AND AL.id_access_level = t_P.id_access_leveL_required - INNER JOIN Shop_Access_Level AL_P - ON t_P.id_access_leveL_required = AL_P.id_access_level - AND AL_P.active - WHERE - v_guid = t_P.guid - AND U.active - AND U.id_user = v_id_user - ; - ELSE - INSERT INTO Shop_Calc_User_Temp (--UE_T - guid, - id_user, - id_permission_required, - priority_access_level_required, - priority_access_level_user, - is_super_user, - can_view, - can_edit, - can_admin - ) - SELECT - v_guid, - v_id_user, - v_id_permission AS id_permission_required, - v_priority_access_level AS priority_access_level_required, - AL.priority AS priority_access_level_user, - U.is_super_user, - CASE WHEN U.is_super_user THEN TRUE ELSE CASE WHEN NOT ISNULL(AL.priority) AND AL.priority <= v_priority_access_level_view AND AL.priority <= v_priority_access_level THEN TRUE ELSE FALSE END END AS can_view, - CASE WHEN U.is_super_user THEN TRUE ELSE CASE WHEN NOT ISNULL(AL.priority) AND AL.priority <= v_priority_access_level_edit AND AL.priority <= v_priority_access_level THEN TRUE ELSE FALSE END END AS can_edit, - CASE WHEN U.is_super_user THEN TRUE ELSE CASE WHEN NOT ISNULL(AL.priority) AND AL.priority <= v_priority_access_level_admin AND AL.priority <= v_priority_access_level THEN TRUE ELSE FALSE END END AS can_admin - FROM Shop_User U - INNER JOIN Shop_User_Role_Link URL - ON U.id_user = URL.id_user - AND URL.active - INNER JOIN Shop_Role_Permission_Link RPL - ON URL.id_role = RPL.id_role - AND RPL.active - INNER JOIN Shop_Access_Level AL - ON RPL.id_access_level = AL.id_access_level - AND AL.active - WHERE - U.id_user = v_id_user - AND U.active - AND RPL.id_permission = v_id_permission - ORDER BY AL.priority ASC - ; - END IF; - */ - INSERT INTO Shop_Calc_User_Temp (--UE_T - guid, - id_user, - id_permission_required, - id_product, - priority_access_level_required, - priority_access_level_user, - is_super_user, - can_view, - can_edit, - can_admin, - name_error - ) - SELECT - v_guid, - v_id_user, - v_id_permission AS id_permission_required, - t_P.id_product, - MIN(v_priority_access_level, AL_P.priority) AS priority_access_level_required, - AL_U.priority AS priority_access_level_user, - U.is_super_user, - (U.is_super_user AND NOT ISNULL(priority_access_level_user) AND priority_access_level_user <= v_priority_access_level_view AND priority_access_level_user <= priority_access_level_required) AS can_view, - (U.is_super_user AND NOT ISNULL(priority_access_level_user) AND priority_access_level_user <= v_priority_access_level_edit AND priority_access_level_user <= priority_access_level_required) AS can_edit, - (U.is_super_user AND NOT ISNULL(priority_access_level_user) AND priority_access_level_user <= v_priority_access_level_admin AND priority_access_level_user <= priority_access_level_required) AS can_admin, - Permission.name || ' ' || (SELECT name FROM Shop_Access_Level WHERE priority = priority_access_level_required ORDER BY id_access_level ASC LIMIT 1) || ' permissions' || CASE WHEN ISNULL(t_P.id_product) THEN '' ELSE ' for product ' || P.name END AS name_error - FROM Shop_User U - INNER JOIN Shop_User_Role_Link URL - ON U.id_user = URL.id_user - AND URL.active - INNER JOIN Shop_Role_Permission_Link RPL - ON URL.id_role = RPL.id_role - AND RPL.active - INNER JOIN Shop_Access_Level AL_U - ON RPL.id_access_level = AL_U.id_access_level - AND AL_U.active - INNER JOIN Shop_Permission Permission - ON RPL.id_permission = Permission.id_permission - AND Permission.active - CROSS JOIN tmp_Shop_Product_p_shop_calc_user t_P -- ON t_P.guid = v_guid - INNER JOIN Shop_Product P ON t_P.id_product = P.id_product - INNER JOIN Shop_Access_Level AL_P - ON t_P.id_access_level_required = AL_P.id_access_level - -- AND AL_P.active - WHERE - U.id_user = v_id_user - AND U.active - AND RPL.id_permission = v_id_permission - AND t_P.guid = v_guid - ORDER BY AL_P.priority ASC, t_P.rank_product ASC - ; - - -- IF EXISTS (SELECT * FROM tmp_Msg_Error WHERE GUID = v_guid) THEN - /* - OPEN result_errors FOR - SELECT * - FROM tmp_Msg_Error - WHERE GUID = v_guid - ; - -- RETURN NEXT result_errors; - -- result_errors - a_error_msg := ( - SELECT - -- GUID, id_type, code, - msg - FROM tmp_Msg_Error - WHERE GUID = v_guid - LIMIT 1 - ); - */ - - -- select * from tmp_Shop_Product_p_shop_calc_user; - -- Clean up - DROP TABLE IF EXISTS tmp_Shop_Product_p_shop_calc_user; - -- DROP TEMPORARY TABLE IF EXISTS tmp_User_Role_Link; - -- DROP TABLE IF EXISTS tmp_Msg_Error; -END; -$$ LANGUAGE plpgsql; - - -/* - -CALL p_shop_calc_user ( - '56c9dfc1-e22f-11ee-aab4-b42e9986184a', -- v_guid - '', -- v_id_user -- 'auth0|6582b95c895d09a70ba10fef', - false, -- v_get_inactive_users - '4,5', -- v_ids_permission - '1', -- v_ids_access_level - -- null, -- v_ids_product - '1,2,3' -- v_ids_permutation -); - -SELECT * -FROM Shop_Calc_User_Temp -; - -DROP TABLE Shop_Calc_User_Temp; - -SELECT * -FROM Shop_Permission -; - -SELECT * -FROM Shop_Access_Level -; - -SELECT * -FROM Shop_Product -; - -SELECT * -FROM Shop_Product_Permutation -; - - -*/ - -/* -SELECT 'NOODS' AS guid, - U.id_user AS id_user, - P.id_permission AS id_permission_required, - AL.id_access_level AS id_access_level_required, - /* - v_id_permission, - v_id_access_level, - */ - AL.priority, -- MIN(AL.priority), - U.is_super_user - /* - CASE WHEN U.is_super_user THEN TRUE ELSE CASE WHEN priority_access_level_minimum <= v_priority_access_level_view THEN TRUE ELSE FALSE END END, - CASE WHEN U.is_super_user THEN TRUE ELSE CASE WHEN priority_access_level_minimum <= v_priority_access_level_edit THEN TRUE ELSE FALSE END END, - CASE WHEN U.is_super_user THEN TRUE ELSE CASE WHEN priority_access_level_minimum <= v_priority_access_level_admin THEN TRUE ELSE FALSE END END - */ -FROM parts.Shop_User U -INNER JOIN Shop_User_Role_Link URL - ON U.id_user = URL.id_user - AND URL.active -INNER JOIN Shop_Role_Permission_Link RPL - ON URL.id_role = RPL.id_role - AND RPL.active -INNER JOIN Shop_Permission P - ON RPL.id_permission = P.id_permission - AND P.active -inner JOIN Shop_Access_Level AL - -- ON P.id_access_level_required = AL.id_access_level - ON RPL.id_access_level = AL.id_access_level - AND AL.active -WHERE U.id_user = 'auth0|6582b95c895d09a70ba10fef' - AND U.active - AND FIND_IN_SET(P.id_permission, '1,2') > 0 - -- AND v_id_access_level = AL.id_access_leveld --- GROUP BY U.id_user, P.id_permission, AL.id_access_level -- , is_super_user - -*/ diff --git a/static/PostgreSQL/602_p_save_supplier_purchase_order.sql b/static/PostgreSQL/602_p_save_supplier_purchase_order.sql deleted file mode 100644 index 3913ecfb..00000000 --- a/static/PostgreSQL/602_p_save_supplier_purchase_order.sql +++ /dev/null @@ -1,515 +0,0 @@ - - - --- DROP TABLE IF EXISTS tmp_Shop_Supplier_Purchase_Order_Product_Link; --- DROP TABLE IF EXISTS tmp_Msg_Error; - -CREATE OR REPLACE PROCEDURE p_shop_save_supplier_purchase_order ( - IN a_guid UUID, - IN a_id_user INTEGER, - IN a_comment UUID, - IN a_id_order INTEGER, - IN a_id_supplier_ordered INTEGER, - IN a_id_currency_cost INTEGER, - IN a_active BOOLEAN -) -AS $$ -DECLARE - v_guid UUID; - v_id_user INTEGER; - v_comment VARCHAR(4000); - v_id_order INTEGER; - v_id_supplier_ordered INTEGER; - v_id_currency_cost INTEGER; - v_active BOOLEAN; - v_id_error_type_bad_data INTEGER; - v_code_error_type_bad_data VARCHAR(50); - v_id_error_type_no_permission INTEGER; - v_code_error_type_no_permission VARCHAR(50); - v_guid_permission UUID; - -- v_id_user VARCHAR(100); - v_id_permission_supplier_purchase_order INTEGER; - v_id_access_level_EDIT INTEGER; - v_ids_product VARCHAR(4000); - v_ids_product_no_permission VARCHAR(4000); - -- v_id_order_new INTEGER; - v_id_change_set INTEGER; - v_is_new_supplier_purchase_order BOOLEAN; - -- result_orders REFCURSOR; - -- result_order_product_links REFCURSOR; - -- result_errors REFCURSOR; -BEGIN - -- SET SESSION sql_mode = sys.list_drop(@@session.sql_mode, 'ONLY_FULL_GROUP_BY'); - - v_guid := COALESCE(a_guid, gen_random_uuid()); - v_id_user := TRIM(COALESCE(a_id_user, '')); - v_comment := TRIM(COALESCE(a_comment, '')); - v_id_order := COALESCE(a_id_order, -1); - v_id_supplier_ordered := a_id_supplier_ordered; - v_id_currency_cost := a_id_currency_cost; - v_active := COALESCE(a_active, FALSE); - - v_code_error_type_bad_data = 'BAD_DATA'; - v_id_error_type_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_type_bad_data LIMIT 1); - v_code_error_type_no_permission = 'NO_PERMISSION'; - v_id_error_type_no_permission := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_type_no_permission LIMIT 1); - v_guid_permission = gen_random_uuid(); - -- v_id_user = CURRENT_USER; - v_id_permission_supplier_purchase_order := (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_SUPPLIER_PURCHASE_ORDER' LIMIT 1); - v_id_access_level_EDIT := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'EDIT'); - - v_is_new_supplier_purchase_order := CASE WHEN v_id_order <= 0 THEN TRUE ELSE FALSE END; - - -- Temporary tables - /* - CREATE TABLE tmp_Shop_Supplier_Purchase_Order ( - id_order INTEGER NOT NULL PRIMARY KEY, - id_supplier_ordered INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Supplier_Purchase_Order_id_supplier_ordered - FOREIGN KEY (id_supplier_ordered) - REFERENCES Shop_Supplier(id_supplier), - cost_total_local REAL NOT NULL, - id_currency_cost INTEGER NOT NULL - ); - */ - - CREATE TABLE tmp_Shop_Supplier_Purchase_Order_Product_Link ( - id_link INTEGER NOT NULL PRIMARY KEY, - id_order INTEGER NOT NULL, - /* - CONSTRAINT FK_tmp_Supplier_Purchase_Order_Product_Link_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Supplier_Purchase_Order(id_order), - */ - id_permutation INTEGER NOT NULL, - CONSTRAINT FK_tmp_Supplier_Purchase_Order_Product_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - cost_total_local REAL NOT NULL, - id_currency_cost INTEGER NOT NULL, - quantity_ordered REAL NOT NULL, - id_unit_quantity INTEGER NOT NULL, - CONSTRAINT FK_tmp_Supplier_Purchase_Order_Product_Link_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - quantity_received REAL NULL, - latency_delivery_days INTEGER NOT NULL, - display_order INTEGER NOT NULL, - active BOOLEAN NOT NULL, - name_error VARCHAR(200) NOT NULL - ); - - /* - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - guid UUID NOT NULL, - id_type INTEGER NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type (id_type), - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - */ - - - -- Argument validation - -- User ID - IF NOT EXISTS (SELECT * FROM Shop_User WHERE id_user = v_id_user) THEN - RAISE EXCEPTION 'Invalid User ID: %', COALESCE(v_id_user, 'NULL') - USING ERRCODE = '22000' - ; - END IF; - - -- Order ID - IF ((v_id_order > 0) AND NOT EXISTS (SELECT * FROM Shop_Supplier_Purchase_Order WHERE id_order = v_id_order)) THEN - RAISE EXCEPTION 'Invalid Supplier Purchase Order ID: %', COALESCE(v_id_order, 'NULL') - USING ERRCODE = '22000' - ; - END IF; - - -- Supplier ID - IF ISNULL(v_id_supplier_ordered) OR NOT EXISTS (SELECT * FROM Shop_Supplier WHERE id_supplier = v_id_supplier_ordered) THEN - RAISE EXCEPTION 'Invalid Supplier ID: %', COALESCE(v_id_supplier_ordered, 'NULL') - USING ERRCODE = '22000' - ; - END IF; - - -- Currency ID - IF ISNULL(v_id_currency_cost) OR NOT EXISTS (SELECT * FROM Shop_Currency WHERE id_currency = v_id_currency_cost) THEN - RAISE EXCEPTION 'Invalid currency ID: %', COALESCE(v_id_currency, 'NULL') - USING ERRCODE = '22000' - ; - END IF; - - -- Comment - IF v_comment = '' THEN - RAISE EXCEPTION 'A comment must be provided.' - USING ERRCODE = '22000' - ; - END IF; - - - -- Get data from Temp table - INSERT INTO tmp_Shop_Supplier_Purchase_Order_Product_Link ( - id_link, - id_order, - id_permutation, - cost_total_local, - id_currency_cost, - quantity_ordered, - id_unit_quantity, - quantity_received, - latency_delivery_days, - display_order, - active, - name_error - ) - SELECT - SPOPL_T.id_link, - SPOPL_T.id_order, - SPOPL_T.id_permutation, - PP.cost_local * quantity_ordered AS cost_total_local, - SPOPL_T.id_currency_cost, - SPOPL_T.quantity_ordered, - SPOPL_T.id_unit_quantity, - SPOPL_T.quantity_received, - SPOPL_T.latency_delivery_days, - SPOPL_T.display_order, - SPOPL_T.active, - CAST(PP.id_permutation AS VARCHAR(10)) || ' - ' || COALESCE(PP.name ,'') AS name_error - FROM Shop_Supplier_Purchase_Order_Product_Link_Temp SPOPL_T - INNER JOIN Shop_Product_Permutation PP ON SPOPL_T.id_permutation = PP.id_permutation - WHERE SPOPL_T.GUID = v_guid - ; - DELETE FROM Shop_Supplier_Purchase_Order_Product_Link_Temp SPOPL_T - WHERE SPOPL_T.GUID = v_guid - ; - - /* - UPDATE tmp_Shop_Supplier_Purchase_Order_Product_Link t_SPOPL - - cost_total_local - */ - - -- Invalid quantity ordered - IF EXISTS ( - SELECT * - FROM tmp_Shop_Supplier_Purchase_Order_Product_Link - WHERE - NOT ISNULL(quantity_ordered) - AND quantity_ordered < 0 - ) THEN - RAISE EXCEPTION 'Invalid quantity ordered property for the following permutations: %', ( - SELECT STRING_AGG(t_SPOPL.name_error, ', ') - FROM tmp_Shop_Supplier_Purchase_Order_Product_Link t_SPOPL - -- INNER JOIN Shop_Product_Permutation PP ON t_SPOPL.id_permutation = PP.id_permutation - WHERE t_SPOPL.quantity_ordered < 0 - ) - USING ERRCODE = '22000' - ; - END IF; - - -- Duplicates - IF EXISTS (SELECT id_permutation, name_error, COUNT(*) FROM tmp_Shop_Supplier_Purchase_Order_Product_Link t_SPOPL GROUP BY id_permutation HAVING COUNT(*) > 1) THEN - RAISE EXCEPTION 'Duplicate records: %', || ( - SELECT STRING_AGG(t_SPOPLC.name_error, ', ') - FROM (SELECT id_permutation, name_error, COUNT(*) FROM tmp_Shop_Supplier_Purchase_Order_Product_Link t_SPOPL GROUP BY id_permutation HAVING COUNT(*) > 1) t_SPOPLC - ) - USING ERRCODE = '22000' - ; - END IF; - - - - -- Permissions - v_ids_product := ( - SELECT STRING_AGG(DISTINCT PP.id_product, ',') - FROM tmp_Shop_Supplier_Purchase_Order_Product_Link t_SPO - INNER JOIN Shop_Product_Permutation PP ON t_SPO.id_permutation = PP.id_permutation - ); - - CALL p_shop_calc_user(v_guid_permission, v_id_user, 0, v_id_permission_supplier_purchase_order, v_id_access_level_edit, v_ids_product); - - /* - UPDATE tmp_Shop_Supplier t_S - INNER JOIN Shop_Calc_User_Temp TP - ON TP.GUID = v_guid_permission - SET tP.can_view = TP.can_view, - tP.can_edit = TP.can_edit, - tP.can_admin = TP.can_admin; - */ - /* - v_has_permission := ( - SELECT can_edit - FROM Shop_Calc_User_Temp - WHERE - GUID = v_guid_permission - AND can_edit = 0 - ); - - IF v_has_permission = FALSE THEN - v_id_error_type_no_permission := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'NO_PERMISSION'); - INSERT INTO tmp_Msg_Error ( - guid, id_type, msg - ) - SELECT - v_guid, - v_id_error_type_no_permission, - CONCAT('You do not have ', name, ' permissions.') - FROM Shop_Permission - WHERE id_permission = v_id_permission_supplier_purchase_order - ; - END IF; - */ - v_ids_product_no_permission := ( - SELECT STRING_AGG(PT.id_product, ',') - FROM Shop_Calc_User_Temp PT - WHERE - PT.can_edit = 0 - AND NOT ISNULL(PT.id_product) - ); - IF NOT ISNULL(v_ids_product_no_permission) THEN - RAISE EXCEPTION 'You do not have permission to edit the following product IDs: %', v_ids_product_no_permission - USING ERRCODE = '42501' - ; - END IF; - - DELETE FROM Shop_Calc_User_Temp - WHERE GUID = v_guid; - - -- Transaction - START TRANSACTION; - INSERT INTO Shop_Sales_And_Purchasing_Change_Set ( - comment, - updated_last_by, - updated_last_on - ) - VALUES ( - 'Save ' - || CASE WHEN v_is_new_supplier_purchase_order = TRUE THEN 'new ' ELSE '' END - || 'Supplier Purchase Order - ' - || v_comment, - v_id_user, - CURRENT_TIMESTAMP - ); - - v_id_change_set := (SELECT id_change_set FROM Shop_Sales_And_Purchasing_Change_Set ORDER BY id_change_set DESC LIMIT 1); - - IF (v_is_new_supplier_purchase_order = 1) THEN - INSERT INTO Shop_Supplier_Purchase_Order ( - id_supplier_ordered, - cost_total_local, - id_currency_cost, - created_by, - id_change_set, - active - ) - SELECT - v_id_supplier_ordered, - SUM(t_SPOPL.cost_total_local), - v_id_currency_cost, - v_id_user, - v_id_change_set, - v_active - FROM tmp_Shop_Supplier_Purchase_Order_Product_Link t_SPOPL - ; - -- v_id_order_new - v_id_order := (SELECT id_order FROM Shop_Supplier_Purchase_Order ORDER BY id_order DESC LIMIT 1); - INSERT INTO Shop_Supplier_Purchase_Order_Product_Link ( - id_order, - id_permutation, - cost_total_local, - id_currency_cost, - quantity_ordered, - id_unit_quantity, - quantity_received, - latency_delivery_days, - display_order, - active, - created_by, - id_change_set - ) - SELECT - v_id_order, -- v_id_order_new, - id_permutation, - cost_total_local, - id_currency_cost, - quantity_ordered, - id_unit_quantity, - quantity_received, - latency_delivery_days, - display_order, - active, - v_id_user, - v_id_change_set - FROM tmp_Shop_Supplier_Purchase_Order_Product_Link t_SPOPL - ; - ELSE - UPDATE Shop_Supplier_Purchase_Order SPO - SET - SPO.id_supplier_ordered = v_id_supplier_ordered, - SPO.cost_total_local = SUM(t_SPOPL.cost_total_local), - SPO.id_currency = v_id_currency_cost, - SPO.id_change_set = v_id_change_set, - SPO.active = v_active - FROM Shop_Supplier_Purchase_Order SPO - INNER JOIN tmp_Shop_Supplier_Purchase_Order_Product_Link t_SPOPL ON SPO.id_order = t_SPOPL.id_order - WHERE SPO.id_order = v_id_order - ; - IF EXISTS (SELECT * FROM tmp_Shop_Supplier_Purchase_Order_Product_Link t_SPOPL INNER JOIN Shop_Supplier_Purchase_Order_Product_Link SPOPL ON t_SPOPL.id_link = SPOPL.id_link) THEN - UPDATE Shop_Supplier_Purchase_Order_Product_Link SPOPL - SET - SPOPL.id_order = t_SPOPL.id_order, - SPOPL.id_permutation = t_SPOPL.id_permutation, - SPOPL.cost_total_local = t_SPOPL.cost_total_local, - SPOPL.id_currency_cost = t_SPOPL.id_currency_cost, - SPOPL.quantity_ordered = t_SPOPL.quantity_ordered, - SPOPL.id_unit_quantity = t_SPOPL.id_unit_quantity, - SPOPL.quantity_received = t_SPOPL.quantity_received, - SPOPL.latency_delivery_days = t_SPOPL.latency_delivery_days, - SPOPL.display_order = t_SPOPL.display_order, - SPOPL.active = t_SPOPL.active, - SPOPL.id_change_set = v_id_change_set - FROM Shop_Supplier_Purchase_Order_Product_Link SPOPL - INNER JOIN tmp_Shop_Supplier_Purchase_Order_Product_Link t_SPOPL - ON SPOPL.id_link = t_SPOPL.id_link - ; - ELSE - INSERT INTO Shop_Supplier_Purchase_Order_Product_Link ( - id_order, - id_permutation, - cost_total_local, - id_currency_cost, - quantity_ordered, - id_unit_quantity, - quantity_received, - latency_delivery_days, - display_order, - active, - created_by, - id_change_set - ) - SELECT - id_order, - id_permutation, - cost_total_local, - id_currency_cost, - quantity_ordered, - id_unit_quantity, - quantity_received, - latency_delivery_days, - display_order, - active, - v_id_user, - v_id_change_set - FROM tmp_Shop_Supplier_Purchase_Order_Product_Link t_SPOPL - WHERE t_SPOPL.id_link < 0 - ; - END IF; - END IF; - - COMMIT; - /* - IF EXISTS (SELECT * FROM tmp_Msg_Error) THEN - ROLLBACK; - ELSE - COMMIT; - END IF; - */ - - -- Returns - -- v_now = CURRENT_TIMESTAMP; - /* - -- Supplier Purchase Orders - OPEN result_orders FOR - SELECT * - FROM Shop_Supplier_Purchase_Order - WHERE id_order = v_id_order - ; - -- RETURN NEXT result_orders; - - -- Supplier Purchase Order Product Links - OPEN result_order_product_links FOR - SELECT * - FROM Shop_Supplier_Purchase_Order_Product_Link - WHERE id_order = v_id_order - ; - -- RETURN NEXT result_order_product_links; - */ - -- Errors - /* - OPEN result_errors FOR - SELECT * - FROM tmp_Msg_Error - ; - -- RETURN NEXT result_errors; - */ - - -- DROP TABLE tmp_Shop_Supplier_Purchase_Order; - DROP TABLE tmp_Shop_Supplier_Purchase_Order_Product_Link; - DROP TABLE tmp_Msg_Error; -END; -$$ LANGUAGE plpgsql; - - -/* - -DELETE FROM Shop_Supplier_Purchase_Order_Product_Link_Audit; -DELETE FROM Shop_Supplier_Purchase_Order_Product_Link; -DELETE FROM Shop_Supplier_Purchase_Order_Product_Link_Temp; -DELETE FROM Shop_Supplier_Purchase_Order_Audit; -DELETE FROM Shop_Supplier_Purchase_Order; - -INSERT INTO Shop_Supplier_Purchase_Order_Product_Link_Temp ( - guid, - id_link, - id_order, - id_permutation, - cost_total_local, - id_currency_cost, - quantity_ordered, - id_unit_quantity, - quantity_received, - latency_delivery_days, - display_order, - active -) -VALUES - ( - 'NIPS', -- guid - -1, -- id_link, - -1, -- id_order, - 1, -- id_permutation, - 100, -- cost_total_local, - 1, -- id_currency_cost, - 1, -- quantity_ordered, - 1, -- id_unit_quantity, - 1, -- quantity_received, - 14, -- latency_delivery_days , - 1, -- display_order - 1 -- active - ) -; - -SELECT * FROM Shop_Supplier_Purchase_Order_Product_Link_Temp; - -CALL p_shop_save_supplier_purchase_order ( - 'NIPS', -- a_guid - 'auth0|6582b95c895d09a70ba10fef', -- a_id_user - -1, -- a_id_order - 1, -- a_id_supplier_ordered - 1 -- a_id_currency_cost -); - -SELECT * FROM Shop_Supplier_Purchase_Order_Product_Link_Temp; - -DELETE FROM Shop_Supplier_Purchase_Order_Product_Link_Audit; -DELETE FROM Shop_Supplier_Purchase_Order_Product_Link; -DELETE FROM Shop_Supplier_Purchase_Order_Product_Link_Temp; -DELETE FROM Shop_Supplier_Purchase_Order_Audit; -DELETE FROM Shop_Supplier_Purchase_Order; - - -*/ - diff --git a/static/PostgreSQL/602_p_shop_save_supplier.sql b/static/PostgreSQL/602_p_shop_save_supplier.sql deleted file mode 100644 index 1534a0bf..00000000 --- a/static/PostgreSQL/602_p_shop_save_supplier.sql +++ /dev/null @@ -1,306 +0,0 @@ - - - - -CREATE OR REPLACE PROCEDURE p_shop_save_supplier ( - IN a_guid UUID, - IN a_id_user INTEGER, - IN a_comment UUID, - IN a_id_supplier INTEGER, - IN a_name_company VARCHAR(256), - IN a_name_contact VARCHAR(256), - IN a_department_contact VARCHAR(256), - IN a_id_address INTEGER, - IN a_phone_number VARCHAR(20), - IN a_fax VARCHAR(20), - IN a_email VARCHAR(515), - IN a_website VARCHAR(300), - IN a_id_currency INTEGER, - IN a_active BOOLEAN -) -AS $$ -DECLARE - v_guid UUID; - v_id_user INTEGER; - v_comment VARCHAR(4000); - v_id_supplier INTEGER; - v_name_company VARCHAR(256); - v_name_contact VARCHAR(256); - v_department_contact VARCHAR(256); - v_id_address INTEGER; - v_phone_number VARCHAR(256); - v_fax VARCHAR(256); - v_email VARCHAR(256); - v_website VARCHAR(256); - v_id_currency INTEGER; - v_active BOOLEAN; - v_id_error_type_bad_data INTEGER; - v_id_error_type_no_permission INTEGER; - v_guid_permission UUID; - v_id_permission_supplier INTEGER; - -- v_id_access_level_EDIT INTEGER; - v_has_permission BOOLEAN; - v_id_change_set INTEGER; - v_is_new_supplier BOOLEAN; - -- result_errors REFCURSOR; -BEGIN - -- SET SESSION sql_mode = sys.list_drop(@@session.sql_mode, 'ONLY_FULL_GROUP_BY'); - - v_guid := COALESCE(a_guid, gen_random_uuid()); - v_id_user := TRIM(COALESCE(a_id_user, '')); - v_comment := TRIM(COALESCE(a_comment, '')); - v_id_supplier := COALESCE(a_id_supplier, -1); - v_name_company := TRIM(COALESCE(a_name_company, '')); - v_name_contact := TRIM(COALESCE(a_name_contact, '')); - v_department_contact := TRIM(COALESCE(a_department_contact, '')); - v_id_address := a_id_address; - v_phone_number := TRIM(COALESCE(a_phone_number, '')); - v_fax := TRIM(COALESCE(a_fax, '')); - v_email := TRIM(COALESCE(a_email, '')); - v_website := TRIM(COALESCE(a_website, '')); - v_id_currency := a_id_currency; - v_active := COALESCE(a_active, FALSE); - - v_id_error_type_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA'); - v_guid_permission = gen_random_uuid(); - v_id_user = CURRENT_USER; - v_id_permission_supplier = (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_SUPPLIER' LIMIT 1); - -- v_id_access_level_EDIT = (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'EDIT'); - v_is_new_supplier := CASE WHEN v_id_supplier <= 0 THEN TRUE ELSE FALSE END; - - - -- Temporary tables - /* - CREATE TABLE tmp_Shop_Supplier ( - id_supplier INTEGER NOT NULL, - name_company VARCHAR(255) NOT NULL, - name_contact VARCHAR(255) NULL, - department_contact VARCHAR(255) NULL, - id_address INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Supplier_id_address - FOREIGN KEY (id_address) - REFERENCES Shop_Address(id_address), - phone_number VARCHAR(50) NULL, - fax VARCHAR(50) NULL, - email VARCHAR(255) NOT NULL, - website VARCHAR(255) NULL, - id_currency INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Supplier_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency), - active BOOLEAN NOT NULL, - can_view BOOLEAN NOT NULL, - can_edit BOOLEAN NOT NULL, - can_admin BOOLEAN NOT NULL - ); - */ - - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - guid UUID NOT NULL, - id_type INTEGER NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type (id_type), - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - - - -- Argument validation - IF v_name_company = '' THEN - /* - INSERT INTO tmp_Msg_Error ( - guid, id_type, msg - ) - VALUES - (v_guid, v_id_error_type_bad_data, 'Supplier company name must be provided') - ; - */ - RAISE EXCEPTION 'Supplier company name must be provided' - USING ERRCODE = '22000' - ; - END IF; - - IF v_id_address IS NULL THEN - /* - INSERT INTO tmp_Msg_Error ( - guid, id_type, msg - ) - VALUES - (v_guid, v_id_error_type_bad_data, 'Address ID must be provided') - ; - */ - RAISE EXCEPTION 'Address ID must be provided' - USING ERRCODE = '22000' - ; - END IF; - - IF v_email = '' THEN - /* - INSERT INTO tmp_Msg_Error ( - guid, id_type, msg - ) - VALUES - (v_guid, v_id_error_type_bad_data, 'Email must be provided') - ; - */ - RAISE EXCEPTION 'Email must be provided.' - USING ERRCODE = '22000' - ; - END IF; - - IF v_comment = '' THEN - RAISE EXCEPTION 'A comment must be provided.' - USING ERRCODE = '22000' - ; - END IF; - - - IF (v_is_new_supplier = FALSE AND NOT EXISTS (SELECT * FROM Shop_Supplier S WHERE S.id_supplier = v_id_supplier)) THEN - RAISE EXCEPTION 'Invalid supplier ID: %', v_id_supplier - USING ERRCODE = '22000' - ; - END IF; - - /* - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - INSERT INTO tmp_Shop_Supplier ( - id_supplier, name_company, name_contact, department_contact, id_address, phone_number, fax, email, website, id_currency, active - ) - VALUES - (v_id_supplier, v_name_company, v_name_contact, v_department_contact, v_id_address, v_phone_number, v_fax, v_email, v_website, v_id_currency, v_active) - /* - FROM Shop_Supplier S - WHERE (NOT v_has_filter_category OR C.id_category LIKE '%' || v_ids_category || '%') - AND (v_get_inactive_categories OR C.active) - */ - ; - END IF; - */ - - -- Permissions - CALL p_shop_calc_user(v_guid_permission, v_id_user, v_id_permission_supplier, ''); - - /* - UPDATE tmp_Shop_Supplier t_S - INNER JOIN Shop_Calc_User_Temp TP - ON TP.GUID = v_guid_permission - SET tP.can_view = TP.can_view, - tP.can_edit = TP.can_edit, - tP.can_admin = TP.can_admin; - */ - v_has_permission := (SELECT can_edit FROM Shop_Calc_User_Temp WHERE GUID = v_guid_permission); - - IF v_has_permission = FALSE THEN - v_id_error_type_no_permission := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'NO_PERMISSION'); - /* - INSERT INTO tmp_Msg_Error ( - guid, id_type, msg - ) - SELECT - v_guid, - v_id_error_type_no_permission, - 'You do not have %' || name || ' permissions.' - FROM Shop_Permission - WHERE id_permission = v_id_permission_supplier - ; - */ - RAISE EXCEPTION 'No permission: %', ( - SELECT name_error - FROM Shop_Calc_User_Temp - WHERE GUID = v_guid_permission - ) - USING ERRCODE = '42501' - ; - END IF; - - -- CALL p_shop_clear_calc_user(v_guid_permission); - - DELETE FROM Shop_Calc_User_Temp - WHERE GUID = v_guid; - - - -- Transaction - INSERT INTO Shop_Sales_And_Purchasing_Change_Set ( - comment, - updated_last_by, - updated_last_on - ) - VALUES ( - 'Save ' - || CASE WHEN v_is_new_supplier = TRUE THEN 'new ' ELSE '' END - || 'Supplier - ' - || v_comment, - v_id_user, - CURRENT_TIMESTAMP - ); - - v_id_change_set := (SELECT id_change_set FROM Shop_Sales_And_Purchasing_Change_Set ORDER BY id_change_set DESC LIMIT 1); - - START TRANSACTION; - IF (v_is_new_supplier = TRUE) THEN - INSERT INTO Shop_Supplier ( - -- id_supplier, - name_company, name_contact, department_contact, id_address, phone_number, fax, email, website, id_currency, active, id_change_set - ) - VALUES - ( - -- v_id_supplier, - v_name_company, v_name_contact, v_department_contact, v_id_address, v_phone_number, v_fax, v_email, v_website, v_id_currency, v_active, v_id_change_set - ) - /* - FROM Shop_Supplier S - WHERE (NOT v_has_filter_category OR C.id_category LIKE '%' || v_ids_category || '%') - AND (v_get_inactive_categories OR C.active) - */ - ; - ELSE - UPDATE Shop_Supplier S - -- INNER JOIN tmp_Shop_Supplier t_S ON S.id_supplier = t_S.id_supplier - SET - /* - S.name_company = t_S.name_company, - S.name_contact = t_S.name_contact, - S.department_contact = t_S.department_contact, - S.id_address = t_S.id_address, - S.phone_number = t_S.phone_number, - S.fax = t_S.fax, - S.email = t_S.email, - S.website = t_S.website, - S.id_currency = t_S.id_currency, - S.active = t_S.active - */ - S.name_company = v_name_company, - S.name_contact = v_name_contact, - S.department_contact = v_department_contact, - S.id_address = v_id_address, - S.phone_number = v_phone_number, - S.fax = v_fax, - S.email = v_email, - S.website = v_website, - S.id_currency = v_id_currency, - S.active = v_active, - S.id_change_set = v_id_change_set - ; - END IF; - COMMIT; - - -- Returns - -- v_now = CURRENT_TIMESTAMP; - - -- Errors - /* - OPEN result_errors FOR - SELECT * - FROM tmp_Msg_Error - ; - -- RETURN NEXT result_errors; - */ - - DROP TABLE tmp_Shop_Supplier; - -- DROP TABLE tmp_Msg_Error; -END; -$$ LANGUAGE plpgsql; - - diff --git a/static/PostgreSQL/604_p_shop_save_manufacturing_purchase_order.sql b/static/PostgreSQL/604_p_shop_save_manufacturing_purchase_order.sql deleted file mode 100644 index 5b12fecb..00000000 --- a/static/PostgreSQL/604_p_shop_save_manufacturing_purchase_order.sql +++ /dev/null @@ -1,606 +0,0 @@ - - - - --- DROP TABLE IF EXISTS tmp_Shop_Manufacturing_Purchase_Order_Product_Link; --- DROP TABLE IF EXISTS tmp_Msg_Error; - -CREATE OR REPLACE PROCEDURE p_shop_save_manufacturing_purchase_order ( - IN a_guid UUID, - IN a_id_user INTEGER, - IN a_id_order INTEGER, - -- IN a_id_supplier_ordered INTEGER, - IN a_id_currency_cost INTEGER, - IN a_active BOOLEAN, - IN a_comment UUID -) -AS $$ -DECLARE - v_guid UUID; - v_id_user INTEGER; - v_comment VARCHAR(4000); - v_id_order INTEGER; - v_id_currency_cost INTEGER; - v_active BOOLEAN; - v_id_error_type_bad_data INTEGER; - v_code_error_type_bad_data VARCHAR(50); - v_id_error_type_no_permission INTEGER; - v_code_error_type_no_permission VARCHAR(50); - v_guid_permission UUID; - -- v_id_user VARCHAR(100); - v_id_permission_manufacturing_purchase_order INTEGER; - v_id_access_level_EDIT INTEGER; - v_ids_product VARCHAR(4000); - v_ids_product_no_permission VARCHAR(4000); - -- v_id_order_new INTEGER; - v_id_change_set INTEGER; - v_is_new_manufacturing_purchase_order BOOLEAN; - result_errors REFCURSOR; -BEGIN - -- SET SESSION sql_mode = sys.list_drop(@@session.sql_mode, 'ONLY_FULL_GROUP_BY'); - - v_guid := COALESCE(a_guid, gen_random_uuid()); - v_id_user := TRIM(COALESCE(a_id_user, '')); - v_comment := TRIM(COALESCE(a_comment, '')); - v_id_order := COALESCE(a_id_order, -1); - v_id_currency_cost := a_id_currency_cost; - v_active := COALESCE(a_active, FALSE); - - v_code_error_type_bad_data = 'BAD_DATA'; - v_id_error_type_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_type_bad_data LIMIT 1); - v_code_error_type_no_permission = 'NO_PERMISSION'; - v_id_error_type_no_permission := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_type_no_permission LIMIT 1); - v_guid_permission = gen_random_uuid(); - -- v_id_user = CURRENT_USER; - v_id_permission_manufacturing_purchase_order := (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_MANUFACTURING_PURCHASE_ORDER' LIMIT 1); - v_id_access_level_EDIT := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'EDIT'); - v_is_new_manufacturing_purchase_order := CASE WHEN v_id_order <= 0 THEN TRUE ELSE FALSE END; - - -- Temporary tables - /* - CREATE TABLE tmp_Shop_Supplier_Purchase_Order ( - id_order INTEGER NOT NULL PRIMARY KEY, - id_supplier_ordered INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Supplier_Purchase_Order_id_supplier_ordered - FOREIGN KEY (id_supplier_ordered) - REFERENCES Shop_Supplier(id_supplier), - cost_total_local REAL NOT NULL, - id_currency_cost INTEGER NOT NULL - ); - */ - - CREATE TABLE tmp_Shop_Manufacturing_Purchase_Order_Product_Link ( - id_link INTEGER NOT NULL PRIMARY KEY, - id_order INTEGER NOT NULL, - /* - CONSTRAINT FK_tmp_Supplier_Purchase_Order_Product_Link_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Manufacturing_Purchase_Order(id_order), - */ - id_permutation INTEGER NOT NULL, - CONSTRAINT FK_tmp_Manuf_Purch_Order_Product_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - cost_total_local REAL NOT NULL, - id_currency_cost INTEGER NOT NULL, - value_produced_total_local REAL NOT NULL, - quantity_used REAL NOT NULL, - id_unit_quantity INTEGER NOT NULL, - CONSTRAINT FK_tmp_Manuf_Purch_Order_Product_Link_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - quantity_produced REAL NULL, - latency_manufacture INTEGER NOT NULL, - display_order INTEGER NOT NULL, - active BOOLEAN NOT NULL, - name_error VARCHAR(200) NOT NULL - ); - - /* - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - guid UUID NOT NULL, - id_type INTEGER NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type (id_type), - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - */ - - - -- Argument validation - -- User ID - IF NOT EXISTS (SELECT * FROM Shop_User WHERE id_user = v_id_user) THEN - RAISE EXCEPTION 'Invalid User ID: %', COALESCE(v_id_user, 'NULL') - USING ERRCODE = '22000' - ; - END IF; - - -- Order ID - IF ((v_id_order > 0) AND NOT EXISTS (SELECT * FROM Shop_Manufacturing_Purchase_Order WHERE id_order = v_id_order)) THEN - RAISE EXCEPTION 'Invalid Manufacturing Purchase Order ID: %', COALESCE(v_id_order, 'NULL') - USING ERRCODE = '22000' - ; - END IF; - - /* - -- Supplier ID - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF ISNULL(v_id_supplier_ordered) OR NOT EXISTS (SELECT * FROM Shop_Supplier WHERE id_supplier = v_id_supplier_ordered) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES - (v_guid, v_id_error_type_bad_data, v_code_error_type_bad_data, CONCAT('Invalid supplier ID: ', COALESCE(v_id_supplier_ordered, 'NULL'))) - ; - END IF; - END IF; - */ - - -- Currency ID - IF ISNULL(v_id_currency_cost) OR NOT EXISTS (SELECT * FROM Shop_Currency WHERE id_currency = v_id_currency_cost) THEN - RAISE EXCEPTION 'Invalid currency ID: %', COALESCE(v_id_currency, 'NULL') - USING ERRCODE = '22000' - ; - END IF; - - -- Comment - IF v_comment = '' THEN - /* - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES - (v_guid, v_id_error_type_bad_data, v_code_error_type_bad_data, 'A comment must be provided.') - ; - */ - RAISE EXCEPTION 'A comment must be provided.' - USING ERRCODE = '22000' - ; - END IF; - - - -- Get data from Temp table - INSERT INTO tmp_Shop_Manufacturing_Purchase_Order_Product_Link ( - id_link, - id_order, - id_permutation, - cost_total_local, - id_currency_cost, - quantity_used, - id_unit_quantity, - quantity_produced, - value_produced_total_local, - latency_manufacture, - display_order, - active, - name_error - ) - SELECT - MPOPL_T.id_link, - MPOPL_T.id_order, - MPOPL_T.id_permutation, - PP.cost_local * MPOPL_T.quantity_used AS cost_total_local, - MPOPL_T.id_currency_cost, - MPOPL_T.quantity_used, - MPOPL_T.id_unit_quantity, - MPOPL_T.quantity_produced, - (PP.cost_local + PP.profit_local_min) * MPOPL_T.quantity_produced AS value_produced_total_local, - MPOPL_T.latency_manufacture, - MPOPL_T.display_order, - MPOPL_T.active, - PP.id_permutation, ' - ' || COALESCE(P.name ,'') AS name_error - FROM Shop_Manufacturing_Purchase_Order_Product_Link_Temp MPOPL_T - INNER JOIN Shop_Product_Permutation PP ON MPOPL_T.id_permutation = PP.id_permutation - INNER JOIN Shop_Product P ON PP.id_product = P.id_product - WHERE MPOPL_T.GUID = v_guid - -- GROUP BY MPOPL_T.id_order, name_error, MPOPL_T.id_link - /* - group by - MPOPL_T.id_link, - MPOPL_T.id_order, - MPOPL_T.id_permutation, - cost_total_local, - MPOPL_T.id_currency_cost, - MPOPL_T.quantity_used, - MPOPL_T.id_unit_quantity, - MPOPL_T.quantity_produced, - value_produced_total_local, - MPOPL_T.latency_manufacture, - MPOPL_T.display_order, - MPOPL_T.active, - name_error - */ - -- GROUP BY id_link, P.id_product, PP.id_permutation - -- GROUP BY name_error, ID_LINK, cost_total_local, value_produced_total_local - ; - DELETE FROM Shop_Manufacturing_Purchase_Order_Product_Link_Temp MPOPL_T - WHERE MPOPL_T.GUID = v_guid - ; - - -- Invalid quantity used - IF EXISTS ( - SELECT * - FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link - WHERE - NOT ISNULL(quantity_used) - AND quantity_used < 0 - ) THEN - /* - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - SELECT - v_guid, - v_id_error_type_bad_data, - v_code_error_type_bad_data, - 'Invalid quantity used property for the following permutations: ' || STRING_AGG(t_MPOPL.name_error, ', ') - FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE t_MPOPL.quantity_used < 0 - ; - */ - RAISE EXCEPTION 'Invalid quantity used property for the following permutations: %', ( - SELECT STRING_AGG(t_MPOPL.name_error, ', ') - FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE t_MPOPL.quantity_used < 0 - ) - USING ERRCODE = '22000' - ; - END IF; - - -- Invalid quantity produced - IF EXISTS ( - SELECT * - FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link - WHERE - NOT ISNULL(quantity_produced) - AND quantity_produced < 0 - ) THEN - /* - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - SELECT - v_guid, - v_id_error_type_bad_data, - v_code_error_type_bad_data, - 'Invalid quantity produced property for the following permutations: ' || STRING_AGG(t_MPOPL.name_error, ', ') - FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE t_MPOPL.quantity_produced < 0 - ; - */ - RAISE EXCEPTION 'Invalid quantity produced property for the following permutations: %', ( - SELECT STRING_AGG(t_MPOPL.name_error, ', ') - FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE t_MPOPL.quantity_produced < 0 - ) - USING ERRCODE = '22000' - ; - END IF; - - -- Duplicates - IF EXISTS (SELECT id_permutation, name_error, COUNT(*) FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL GROUP BY id_permutation HAVING COUNT(*) > 1) THEN - /* - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - SELECT - v_guid, - v_id_error_type_bad_data, - v_code_error_type_bad_data, - 'Duplicate records: ' || STRING_AGG(t_MPOPLC.name_error, ', ') - FROM (SELECT id_permutation, name_error, COUNT(*) FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL GROUP BY id_permutation HAVING COUNT(*) > 1) t_MPOPLC - ; - */ - RAISE EXCEPTION 'Duplicate records: %', ( - SELECT STRING_AGG(t_MPOPLC.name_error, ', ') - FROM (SELECT id_permutation, name_error, COUNT(*) FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL GROUP BY id_permutation HAVING COUNT(*) > 1) t_MPOPLC - ) - USING ERRCODE = '22000' - ; - END IF; - - - -- Permissions - v_ids_product := ( - SELECT STRING_AGG(DISTINCT PP.id_product, ',') - FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPO - INNER JOIN Shop_Product_Permutation PP ON t_MPO.id_permutation = PP.id_permutation - ); - - CALL p_shop_calc_user(v_guid_permission, v_id_user, 0, v_id_permission_manufacturing_purchase_order, v_id_access_level_edit, v_ids_product); - - /* - UPDATE tmp_Shop_Supplier t_S - INNER JOIN Shop_Calc_User_Temp TP - ON TP.GUID = v_guid_permission - SET tP.can_view = TP.can_view, - tP.can_edit = TP.can_edit, - tP.can_admin = TP.can_admin; - */ - /* - v_has_permission := ( - SELECT can_edit - FROM Shop_Calc_User_Temp - WHERE - GUID = v_guid_permission - AND can_edit = 0 - ); - - IF v_has_permission = FALSE THEN - v_id_error_type_no_permission := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'NO_PERMISSION'); - INSERT INTO tmp_Msg_Error ( - guid, id_type, msg - ) - SELECT - v_guid, - v_id_error_type_no_permission, - CONCAT('You do not have ', name, ' permissions.') - FROM Shop_Permission - WHERE id_permission = v_id_permission_manufacturing_purchase_order - ; - END IF; - */ - v_ids_product_no_permission := ( - SELECT STRING_AGG(PT.id_product, ',') - FROM Shop_Calc_User_Temp PT - WHERE - PT.can_edit = 0 - AND NOT ISNULL(PT.id_product) - ); - IF NOT ISNULL(v_ids_product_no_permission) THEN - /* - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES ( - v_guid, - v_id_error_type_no_permission, - v_code_error_type_no_permission, - */ - RAISE EXCEPTION 'You do not have permission to edit the following product IDs: %', v_ids_product_no_permission - USING ERRCODE = '42501' - ; - END IF; - - -- Transaction - START TRANSACTION; - INSERT INTO Shop_Sales_And_Purchasing_Change_Set ( - comment, - updated_last_by, - updated_last_on - ) - VALUES ( - 'Save ' - || CASE WHEN v_is_new_manufacturing_purchase_order = TRUE THEN 'new ' ELSE '' END - || 'Manufacturing Purchase Order - ' - || v_comment, - v_id_user, - CURRENT_TIMESTAMP - ); - - v_id_change_set := (SELECT id_change_set FROM Shop_Sales_And_Purchasing_Change_Set ORDER BY id_change_set DESC LIMIT 1); - - IF (v_is_new_manufacturing_purchase_order = 1) THEN - INSERT INTO Shop_Manufacturing_Purchase_Order ( - -- id_supplier_ordered, - cost_total_local, - id_currency_cost, - value_produced_total_local, - created_by, - id_change_set, - active - ) - SELECT - -- v_id_supplier_ordered, - SUM(t_MPOPL.cost_total_local), - v_id_currency_cost, - SUM(t_MPOPL.value_produced_total_local), - v_id_user, - v_id_change_set, - v_active - FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL - ; - -- v_id_order_new - v_id_order := (SELECT id_order FROM Shop_Manufacturing_Purchase_Order ORDER BY id_order DESC LIMIT 1); - - INSERT INTO Shop_Manufacturing_Purchase_Order_Product_Link ( - id_order, - id_permutation, - cost_total_local, - value_produced_total_local, - id_currency_cost, - quantity_used, - id_unit_quantity, - quantity_produced, - latency_manufacture, - display_order, - active, - created_by, - id_change_set - ) - SELECT - v_id_order, -- v_id_order_new, - id_permutation, - cost_total_local, - value_produced_total_local, - id_currency_cost, - quantity_used, - id_unit_quantity, - quantity_produced, - latency_manufacture, - display_order, - active, - v_id_user, - v_id_change_set - FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL - ; - ELSE - UPDATE Shop_Manufacturing_Purchase_Order MPO - SET - -- MPO.id_supplier_ordered = v_id_supplier_ordered, - MPO.cost_total_local = SUM(t_MPOPL.cost_total_local), - MPO.value_produced_total_local = SUM(t_MPOPL.value_produced_total_local), - MPO.id_currency = v_id_currency_cost, - MPO.id_change_set = v_id_change_set, - MPO.active = v_active - FROM Shop_Manufacturing_Purchase_Order MPO - INNER JOIN tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL ON MPO.id_order = t_MPOPL.id_order - WHERE MPO.id_order = v_id_order - ; - IF EXISTS (SELECT * FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL INNER JOIN Shop_Manufacturing_Purchase_Order_Product_Link MPOPL ON t_MPOPL.id_link = MPOPL.id_link) THEN - UPDATE Shop_Manufacturing_Purchase_Order_Product_Link MPOPL - SET - MPOPL.id_order = t_MPOPL.id_order, - MPOPL.id_permutation = t_MPOPL.id_permutation, - MPOPL.cost_total_local = t_MPOPL.cost_total_local, - MPOPL.value_produced_total_local = t_MPOPL.value_produced_total_local, - MPOPL.id_currency_cost = t_MPOPL.id_currency_cost, - MPOPL.quantity_used = t_MPOPL.quantity_used, - MPOPL.id_unit_quantity = t_MPOPL.id_unit_quantity, - MPOPL.quantity_produced = t_MPOPL.quantity_produced, - MPOPL.latency_manufacture = t_MPOPL.latency_manufacture, - MPOPL.display_order = t_MPOPL.display_order, - MPOPL.active = t_MPOPL.active, - MPOPL.id_change_set = v_id_change_set - FROM Shop_Manufacturing_Purchase_Order_Product_Link MPOPL - INNER JOIN tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL - ON MPOPL.id_link = t_MPOPL.id_link - ; - ELSE - INSERT INTO Shop_Manufacturing_Purchase_Order_Product_Link ( - id_order, - id_permutation, - cost_total_local, - value_produced_total_local, - id_currency_cost, - quantity_used, - id_unit_quantity, - quantity_produced, - latency_manufacture, - display_order, - active, - created_by, - id_change_set - ) - SELECT - id_order, - id_permutation, - cost_total_local, - value_produced_total_local, - id_currency_cost, - quantity_used, - id_unit_quantity, - quantity_produced, - latency_manufacture, - display_order, - active, - v_id_user, - v_id_change_set - FROM tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL - WHERE t_MPOPL.id_link < 0 - ; - END IF; - END IF; - - COMMIT; - - -- Returns - -- v_now = CURRENT_TIMESTAMP; - /* - -- Manufacturing Purchase Orders - SELECT * - FROM Shop_Manufacturing_Purchase_Order - WHERE - id_order = v_id_order - -- GUID = v_guid - ; - - -- Manufacturing Purchase Order Product Links - SELECT * - FROM Shop_Manufacturing_Purchase_Order_Product_Link - WHERE - id_order = v_id_order - -- GUID = v_guid - ; - */ - - -- Errors - /* - OPEN result_errors FOR - SELECT * - FROM tmp_Msg_Error - ; - -- RETURN NEXT result_errors; - */ - - -- DROP TABLE tmp_Shop_Manufacturing_Purchase_Order; - DROP TABLE tmp_Shop_Manufacturing_Purchase_Order_Product_Link; - -- DROP TABLE tmp_Msg_Error; -END; -$$ LANGUAGE plpgsql; - - -/* - -DELETE FROM Shop_Manufacturing_Purchase_Order_Product_Link_Audit; -DELETE FROM Shop_Manufacturing_Purchase_Order_Product_Link; -DELETE FROM Shop_Manufacturing_Purchase_Order_Product_Link_Temp; -DELETE FROM Shop_Manufacturing_Purchase_Order_Audit; -DELETE FROM Shop_Manufacturing_Purchase_Order; - -INSERT INTO Shop_Manufacturing_Purchase_Order_Product_Link_Temp ( - guid, - id_link, - id_order, - id_permutation, - cost_total_local, - id_currency_cost, - quantity_used, - id_unit_quantity, - quantity_produced, - latency_manufacture, - display_order, - active -) -VALUES - ( - 'NIPS', -- guid - -1, -- id_link, - -1, -- id_order, - 1, -- id_permutation, - 100, -- cost_total_local, - 1, -- id_currency_cost, - 1, -- quantity_used, - 1, -- id_unit_quantity, - 1, -- quantity_produced, - 14, -- latency_manufacture , - 1, -- display_order - 1 -- active - ) -; - -SELECT * FROM Shop_Manufacturing_Purchase_Order_Product_Link_Temp; - -CALL p_shop_save_manufacturing_purchase_order ( - 'NIPS', -- a_guid - 'auth0|6582b95c895d09a70ba10fef', -- a_id_user - -1, -- a_id_order - 1, -- a_id_currency_cost - 1, -- a_active - 'Initial data' -- a_comment -); - -SELECT * FROM Shop_Manufacturing_Purchase_Order_Product_Link_Temp; - -DELETE FROM Shop_Manufacturing_Purchase_Order_Product_Link_Audit; -DELETE FROM Shop_Manufacturing_Purchase_Order_Product_Link; -DELETE FROM Shop_Manufacturing_Purchase_Order_Product_Link_Temp; -DELETE FROM Shop_Manufacturing_Purchase_Order_Audit; -DELETE FROM Shop_Manufacturing_Purchase_Order; - - -*/ - diff --git a/static/PostgreSQL/605_p_shop_save_customer.sql b/static/PostgreSQL/605_p_shop_save_customer.sql deleted file mode 100644 index 79ec88d7..00000000 --- a/static/PostgreSQL/605_p_shop_save_customer.sql +++ /dev/null @@ -1,313 +0,0 @@ - - - - -CREATE OR REPLACE PROCEDURE p_shop_save_customer ( - IN a_guid UUID, - IN a_id_user INTEGER, - IN a_comment UUID, - IN a_id_customer INTEGER, - IN a_name_company VARCHAR(256), - IN a_name_contact VARCHAR(256), - IN a_department_contact VARCHAR(256), - IN a_id_address INTEGER, - IN a_phone_number VARCHAR(20), - IN a_email VARCHAR(515), - IN a_id_currency INTEGER, - IN a_active BOOLEAN -) -AS $$ -DECLARE - v_guid UUID; - v_id_user INTEGER; - v_comment VARCHAR(4000); - v_id_customer INTEGER; - v_name_company VARCHAR(256); - v_name_contact VARCHAR(256); - v_department_contact VARCHAR(256); - v_id_address INTEGER; - v_phone_number VARCHAR(256); - v_email VARCHAR(256); - v_id_currency INTEGER; - v_active BOOLEAN; - v_id_error_type_bad_data INTEGER; - v_id_error_type_no_permission INTEGER; - v_guid_permission UUID; - v_id_permission_customer INTEGER; - v_id_access_level_EDIT INTEGER; - v_has_permission BOOLEAN; - v_id_change_set INTEGER; - v_is_new_customer BOOLEAN; - -- result_errors REFCURSOR; -BEGIN - -- SET SESSION sql_mode = sys.list_drop(@@session.sql_mode, 'ONLY_FULL_GROUP_BY'); - - v_guid := COALESCE(a_guid, gen_random_uuid()); - v_id_user := TRIM(COALESCE(a_id_user, '')); - v_comment := TRIM(COALESCE(a_comment, '')); - v_id_customer := COALESCE(a_id_customer, -1); - v_name_company := TRIM(COALESCE(a_name_company, '')); - v_name_contact := TRIM(COALESCE(a_name_contact, '')); - v_department_contact := TRIM(COALESCE(a_department_contact, '')); - v_id_address := a_id_address; - v_phone_number := TRIM(COALESCE(a_phone_number, '')); - v_email := TRIM(COALESCE(a_email, '')); - v_id_currency := a_id_currency; - v_active := COALESCE(a_active, FALSE); - - v_id_error_type_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA'); - v_guid_permission = gen_random_uuid(); - v_id_permission_customer = (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_CUSTOMER' LIMIT 1); - v_id_access_level_EDIT = (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'EDIT'); - v_is_new_customer := CASE WHEN v_id_customer <= 0 THEN TRUE ELSE FALSE END; - - -- Temporary tables - /* - CREATE TABLE tmp_Shop_Customer ( - id_customer INTEGER NOT NULL, - name_company VARCHAR(255) NOT NULL, - name_contact VARCHAR(255) NULL, - department_contact VARCHAR(255) NULL, - id_address INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Customer_id_address - FOREIGN KEY (id_address) - REFERENCES Shop_Address(id_address), - phone_number VARCHAR(50) NULL, - fax VARCHAR(50) NULL, - email VARCHAR(255) NOT NULL, - website VARCHAR(255) NULL, - id_currency INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Customer_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency), - active BOOLEAN NOT NULL, - can_view BOOLEAN NOT NULL, - can_edit BOOLEAN NOT NULL, - can_admin BOOLEAN NOT NULL - ); - */ - /* - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - guid UUID NOT NULL, - id_type INTEGER NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type (id_type), - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - */ - - -- Argument validation - IF v_name_company = '' THEN - RAISE EXCEPTION 'Customer company name must be provided' - USING ERRCODE = '22000' - ; - END IF; - IF v_id_address IS NULL THEN - /* - INSERT INTO tmp_Msg_Error ( - guid, id_type, msg - ) - VALUES - (v_guid, v_id_error_type_bad_data, 'Customer address ID must be provided') - ; - */ - RAISE EXCEPTION 'Customer address ID must be provided' - USING ERRCODE = '22000' - ; - END IF; - IF v_email = '' THEN - /* - INSERT INTO tmp_Msg_Error ( - guid, id_type, msg - ) - VALUES - (v_guid, v_id_error_type_bad_data, 'Customer email must be provided') - ; - */ - RAISE EXCEPTION 'Customer email must be provided' - USING ERRCODE = '22000' - ; - END IF; - - - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - /* - IF (v_is_new_customer = FALSE AND NOT EXISTS (SELECT * FROM Shop_Customer C WHERE C.id_customer = v_id_customer)) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, msg - ) - VALUES - (v_guid, v_id_error_type_bad_data, 'Invalid customer ID: ' || v_id_customer) - ; - END IF; - */ - RAISE EXCEPTION 'Invalid customer ID: %', v_id_customer - USING ERRCODE = '22000' - ; - END IF; - - /* - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - INSERT INTO tmp_Shop_Customer ( - id_customer, name_company, name_contact, department_contact, id_address, phone_number, fax, email, website, id_currency, active - ) - VALUES - (v_id_customer, v_name_company, v_name_contact, v_department_contact, v_id_address, v_phone_number, v_fax, v_email, v_website, v_id_currency, v_active) - /* - FROM Shop_Customer S - WHERE (NOT v_has_filter_category OR C.id_category LIKE '%' || v_ids_category || '%') - AND (v_get_inactive_categories OR C.active) - */ - ; - END IF; - */ - - -- Permissions - CALL p_shop_calc_user(v_guid_permission, v_id_user, 0, v_id_permission_customer, v_id_access_level_edit, ''); - - /* - UPDATE tmp_Shop_Customer t_S - INNER JOIN Shop_Calc_User_Temp TP - ON TP.GUID = v_guid_permission - SET tP.can_view = TP.can_view, - tP.can_edit = TP.can_edit, - tP.can_admin = TP.can_admin; - */ - v_has_permission := (SELECT can_edit FROM Shop_Calc_User_Temp WHERE GUID = v_guid_permission); - - IF v_has_permission = FALSE THEN - v_id_error_type_no_permission := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'NO_PERMISSION'); - /* - INSERT INTO tmp_Msg_Error ( - guid, id_type, msg - ) - SELECT - v_guid, - v_id_error_type_no_permission, - 'You do not have ' || name || ' permissions.' - FROM Shop_Permission - WHERE id_permission = v_id_permission_customer - ; - RAISE EXCEPTION 'You do not have ' || name || ' permissions.' - FROM Shop_Permission - WHERE id_permission = v_id_permission_customer - USING ERRCODE = '22000' - ; - */ - END IF; - - -- CALL p_shop_clear_calc_user(v_guid_permission); - - DELETE FROM Shop_Calc_User_Temp - WHERE GUID = v_guid; - - - -- Transaction - INSERT INTO Shop_Sales_And_Purchasing_Change_Set ( - comment, - updated_last_by, - updated_last_on - ) - VALUES ( - 'Save ' - || CASE WHEN v_is_new_customer = TRUE THEN 'new ' ELSE '' END - || 'Customer - ' - || v_comment, - v_id_user, - CURRENT_TIMESTAMP - ); - - v_id_change_set := (SELECT id_change_set FROM Shop_Sales_And_Purchasing_Change_Set ORDER BY id_change_set DESC LIMIT 1); - - START TRANSACTION; - IF (v_is_new_customer = TRUE) THEN - INSERT INTO Shop_Customer ( - -- id_customer, - name_company, name_contact, department_contact, id_address, phone_number, email, id_currency, active, id_change_set - ) - VALUES - ( - -- v_id_customer, - v_name_company, v_name_contact, v_department_contact, v_id_address, v_phone_number, v_email, v_id_currency, v_active, v_id_change_set - ) - /* - FROM Shop_Customer S - WHERE (NOT v_has_filter_category OR C.id_category LIKE '%' || v_ids_category || '%') - AND (v_get_inactive_categories OR C.active) - */ - ; - ELSE - UPDATE Shop_Customer C - -- INNER JOIN tmp_Shop_Customer t_S ON S.id_customer = t_S.id_customer - SET - /* - S.name_company = t_S.name_company, - S.name_contact = t_S.name_contact, - S.department_contact = t_S.department_contact, - S.id_address = t_S.id_address, - S.phone_number = t_S.phone_number, - S.fax = t_S.fax, - S.email = t_S.email, - S.website = t_S.website, - S.id_currency = t_S.id_currency, - S.active = t_S.active - */ - C.name_company = v_name_company, - C.name_contact = v_name_contact, - C.department_contact = v_department_contact, - C.id_address = v_id_address, - C.phone_number = v_phone_number, - C.email = v_email, - C.id_currency = v_id_currency, - C.active = v_active, - C.id_change_set = v_id_change_set - ; - END IF; - - COMMIT; - - -- Returns - -- v_now = CURRENT_TIMESTAMP; - - -- Errors - /* - OPEN result_errors FOR - SELECT * - FROM tmp_Msg_Error - ; - -- RETURN NEXT result_errors; - */ - - -- DROP TABLE tmp_Shop_Customer; - -- DROP TABLE tmp_Msg_Error; -END; -$$ LANGUAGE plpgsql; - - -/* - -CALL p_shop_save_customer ( - 'NIPS', -- a_guid - 'auth0|6582b95c895d09a70ba10fef', -- a_id_user - 'Initial Customer', -- a_comment - '-1', -- a_id_customer - 'good co', -- a_name_company - 'teddy', -- a_name_contact - 'manufacturing', -- a_department_contact - 1, -- a_id_address - 'BRING BRING', -- a_phone_number - 'e@mail.com', -- a_email - 1, -- a_id_currency_cost - 1 -- a_active -); - -SELECT * FROM Shop_Customer -; - -DELETE FROM Shop_Customer -; - -*/ diff --git a/static/PostgreSQL/606_p_shop_save_customer_sales_order.sql b/static/PostgreSQL/606_p_shop_save_customer_sales_order.sql deleted file mode 100644 index 3c445bfb..00000000 --- a/static/PostgreSQL/606_p_shop_save_customer_sales_order.sql +++ /dev/null @@ -1,555 +0,0 @@ - --- DROP TABLE IF EXISTS tmp_Shop_Customer_Sales_Order_Product_Link; --- DROP TABLE IF EXISTS tmp_Msg_Error; - -CREATE OR REPLACE PROCEDURE p_shop_save_customer_sales_order ( - IN a_guid UUID, - IN a_id_user INTEGER, - IN a_comment VARCHAR(4000), - IN a_id_order INTEGER, - IN a_id_customer INTEGER, - IN a_id_currency_price INTEGER, - IN a_active BOOLEAN -) -AS $$ -DECLARE - v_guid UUID; - v_id_user INTEGER; - v_comment VARCHAR(4000); - v_id_order INTEGER; - v_id_customer INTEGER; - v_id_currency_price INTEGER; - v_active BOOLEAN; - v_id_error_type_bad_data INTEGER; - v_code_error_type_bad_data VARCHAR(50); - v_id_error_type_no_permission INTEGER; - v_code_error_type_no_permission VARCHAR(50); - -- v_guid_permission UUID; - v_id_permission_Customer_Sales_order INTEGER; - v_id_access_level_EDIT INTEGER; - v_ids_product VARCHAR(4000); - v_ids_product_no_permission VARCHAR(4000); - -- v_id_order_new INTEGER; - v_id_change_set INTEGER; - v_is_new_Customer_Sales_order BOOLEAN; - result_errors REFCURSOR; -BEGIN - -- SET SESSION sql_mode = sys.list_drop(@@session.sql_mode, 'ONLY_FULL_GROUP_BY'); - - v_guid := COALESCE(a_guid, gen_random_uuid()); - v_id_user := TRIM(COALESCE(a_id_user, '')); - v_comment := TRIM(COALESCE(a_comment, '')); - v_id_order := COALESCE(a_id_order, -1); - v_id_customer := a_id_customer; - v_id_currency_price := a_id_currency_price; - v_active := COALESCE(a_active, FALSE); - - v_code_error_type_bad_data := 'BAD_DATA'; - v_id_error_type_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_type_bad_data LIMIT 1); - v_code_error_type_no_permission := 'NO_PERMISSION'; - v_id_error_type_no_permission := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_type_no_permission LIMIT 1); - -- v_guid_permission := gen_random_uuid(); - v_id_permission_Customer_Sales_order := (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_CUSTOMER_SALES_ORDER' LIMIT 1); - v_id_access_level_EDIT := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'EDIT'); - - v_is_new_Customer_Sales_order := CASE WHEN v_id_order <= 0 THEN TRUE ELSE FALSE END; - - -- Temporary tables - /* - CREATE TABLE tmp_Shop_Customer_Sales_Order ( - id_order INTEGER NOT NULL PRIMARY KEY, - id_supplier_ordered INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Customer_Sales_Order_id_supplier_ordered - FOREIGN KEY (id_supplier_ordered) - REFERENCES Shop_Supplier(id_supplier), - price_total_local REAL NOT NULL, - id_currency_price INTEGER NOT NULL - ); - */ - - CREATE TABLE tmp_Shop_Customer_Sales_Order_Product_Link ( - id_link INTEGER NOT NULL PRIMARY KEY, - id_order INTEGER NOT NULL, - /* - CONSTRAINT FK_tmp_Supplier_Purchase_Order_Product_Link_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Customer_Sales_Order(id_order), - */ - id_permutation INTEGER NOT NULL, - CONSTRAINT FK_tmp_Supplier_Purchase_Order_Product_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - price_total_local REAL NOT NULL, - id_currency_price INTEGER NOT NULL, - quantity_ordered REAL NOT NULL, - id_unit_quantity INTEGER NOT NULL, - CONSTRAINT FK_tmp_Supplier_Purchase_Order_Product_Link_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - quantity_delivered REAL NULL, - latency_delivery_days INTEGER NOT NULL, - display_order INTEGER NOT NULL, - active BOOLEAN NOT NULL, - name_error VARCHAR(200) NOT NULL - ); - - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - guid UUID NOT NULL, - id_type INTEGER NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type (id_type), - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - - - -- Argument validation - -- User ID - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF NOT EXISTS (SELECT * FROM Shop_User WHERE id_user = v_id_user) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES - (v_guid, v_id_error_type_bad_data, v_code_error_type_bad_data, CONCAT('Invalid User ID: ', COALESCE(v_id_user, 'NULL'))) - ; - END IF; - END IF; - - -- Order ID - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF (v_id_order > 0) AND NOT EXISTS (SELECT * FROM Shop_Customer_Sales_Order WHERE id_order = v_id_order) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES - (v_guid, v_id_error_type_bad_data, v_code_error_type_bad_data, CONCAT('Invalid Customer Sales Order ID: ', COALESCE(v_id_order, 'NULL'))) - ; - END IF; - END IF; - - -- Customer ID - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF ISNULL(v_id_customer) OR NOT EXISTS (SELECT * FROM Shop_Customer WHERE id_customer = v_id_customer) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES - (v_guid, v_id_error_type_bad_data, v_code_error_type_bad_data, CONCAT('Invalid Customer ID: ', COALESCE(v_id_customer, 'NULL'))) - ; - END IF; - END IF; - - -- Currency ID - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF ISNULL(v_id_currency_price) OR NOT EXISTS (SELECT * FROM Shop_Currency WHERE id_currency = v_id_currency_price) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES - (v_guid, v_id_error_type_bad_data, v_code_error_type_bad_data, CONCAT('Invalid currency ID: ', COALESCE(v_id_currency, 'NULL'))) - ; - END IF; - END IF; - - -- Comment - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF v_comment = '' THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES - (v_guid, v_id_error_type_bad_data, v_code_error_type_bad_data, 'A comment must be provided.') - ; - END IF; - END IF; - - - -- Get data from Temp table - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - INSERT INTO tmp_Shop_Customer_Sales_Order_Product_Link ( - id_link, - id_order, - id_permutation, - price_total_local, - id_currency_price, - quantity_ordered, - id_unit_quantity, - quantity_delivered, - latency_delivery_days, - display_order, - active, - name_error - ) - SELECT - CSOPL_T.id_link, - CSOPL_T.id_order, - CSOPL_T.id_permutation, - (PP.cost_local + PP.profit_local_min) * quantity_ordered AS price_total_local, - CSOPL_T.id_currency_price, - CSOPL_T.quantity_ordered, - CSOPL_T.id_unit_quantity, - CSOPL_T.quantity_delivered, - CSOPL_T.latency_delivery_days, - CSOPL_T.display_order, - CSOPL_T.active, - PP.id_permutation || ' - ' || COALESCE(P.name ,'') AS name_error - FROM Shop_Customer_Sales_Order_Product_Link_Temp CSOPL_T - INNER JOIN Shop_Product_Permutation PP ON CSOPL_T.id_permutation = PP.id_permutation - INNER JOIN Shop_Product P ON PP.id_product = P.id_product - WHERE CSOPL_T.GUID = v_guid - ; - DELETE FROM Shop_Customer_Sales_Order_Product_Link_Temp CSOPL_T - WHERE CSOPL_T.GUID = v_guid - ; - - /* - UPDATE tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL - SET - price_total_local - */ - END IF; - - -- Invalid quantity ordered - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF EXISTS ( - SELECT * - FROM tmp_Shop_Customer_Sales_Order_Product_Link - WHERE - NOT ISNULL(quantity_ordered) - AND quantity_ordered < 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - SELECT - v_guid, - v_id_error_type_bad_data, - v_code_error_type_bad_data, - 'Invalid quantity ordered property for the following permutations: ' || STRING_AGG(t_CSOPL.name_error, ', ') - FROM tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL - -- INNER JOIN Shop_Product_Permutation PP ON t_CSOPL.id_permutation = PP.id_permutation - WHERE t_CSOPL.quantity_ordered < 0 - ; - END IF; - END IF; - - -- Duplicates - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - IF EXISTS (SELECT id_permutation, name_error, COUNT(*) FROM tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL GROUP BY id_permutation HAVING COUNT(*) > 1) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - SELECT - v_guid, - v_id_error_type_bad_data, - v_code_error_type_bad_data, - 'Duplicate records: ' || STRING_AGG(t_CSOPLC.name_error, ', ') - FROM (SELECT id_permutation, name_error, COUNT(*) FROM tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL GROUP BY id_permutation HAVING COUNT(*) > 1) t_CSOPLC - ; - END IF; - END IF; - - - - -- Permissions - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - v_ids_product := ( - SELECT STRING_AGG(DISTINCT PP.id_product, ',') - FROM tmp_Shop_Customer_Sales_Order_Product_Link t_SPO - INNER JOIN Shop_Product_Permutation PP ON t_SPO.id_permutation = PP.id_permutation - ); - - CALL p_shop_calc_user(v_guid_permission, v_id_user, 0, v_id_permission_Customer_Sales_order, v_id_access_level_edit, v_ids_product); - - /* - UPDATE tmp_Shop_Supplier t_S - INNER JOIN Shop_Calc_User_Temp TP - ON TP.GUID = v_guid_permission - SET tP.can_view = TP.can_view, - tP.can_edit = TP.can_edit, - tP.can_admin = TP.can_admin; - */ - /* - SET v_has_permission := ( - SELECT can_edit - FROM Shop_Calc_User_Temp - WHERE - GUID = v_guid_permission - AND can_edit = 0 - ); - - IF v_has_permission = FALSE THEN - v_id_error_type_no_permission := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'NO_PERMISSION'); - INSERT INTO tmp_Msg_Error ( - guid, id_type, msg - ) - SELECT - v_guid, - v_id_error_type_no_permission, - CONCAT('You do not have ', name, ' permissions.') - FROM Shop_Permission - WHERE id_permission = v_id_permission_Customer_Sales_order - ; - END IF; - */ - v_ids_product_no_permission := ( - SELECT STRING_AGG(PT.id_product, ',') - FROM Shop_Calc_User_Temp PT - WHERE - PT.can_edit = 0 - AND NOT ISNULL(PT.id_product) - ); - IF NOT ISNULL(v_ids_product_no_permission) THEN - INSERT INTO tmp_Msg_Error ( - guid, id_type, code, msg - ) - VALUES ( - v_guid, - v_id_error_type_no_permission, - v_code_error_type_no_permission, - 'You do not have permission to edit the following product IDs: ' || v_ids_product_no_permission - ) - ; - END IF; - - DELETE FROM Shop_Calc_User_Temp - WHERE GUID = v_guid; - END IF; - - -- Transaction - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - START TRANSACTION; - INSERT INTO Shop_Sales_And_Purchasing_Change_Set ( - comment, - updated_last_by, - updated_last_on - ) - VALUES ( - 'Save ' - || CASE WHEN v_is_new_Customer_Sales_order = TRUE THEN 'new ' ELSE '' END - || 'Customer Sales Order - ' - || v_comment, - v_id_user, - CURRENT_TIMESTAMP - ); - - v_id_change_set := (SELECT id_change_set FROM Shop_Sales_And_Purchasing_Change_Set ORDER BY id_change_set DESC LIMIT 1); - - IF (v_is_new_Customer_Sales_order = 1) THEN - INSERT INTO Shop_Customer_Sales_Order ( - id_customer, - price_total_local, - id_currency_price, - created_by, - id_change_set, - active - ) - SELECT - v_id_customer, - SUM(t_CSOPL.price_total_local), - v_id_currency_price, - v_id_user, - v_id_change_set, - v_active - FROM tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL - ; - -- v_id_order_new - v_id_order := (SELECT id_order FROM Shop_Customer_Sales_Order ORDER BY id_order DESC LIMIT 1); - INSERT INTO Shop_Customer_Sales_Order_Product_Link ( - id_order, - id_permutation, - price_total_local, - id_currency_price, - quantity_ordered, - id_unit_quantity, - quantity_delivered, - latency_delivery_days, - display_order, - active, - created_by, - id_change_set - ) - SELECT - v_id_order, -- v_id_order_new, - id_permutation, - price_total_local, - id_currency_price, - quantity_ordered, - id_unit_quantity, - quantity_delivered, - latency_delivery_days, - display_order, - active, - v_id_user, - v_id_change_set - FROM tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL - ; - ELSE - UPDATE Shop_Customer_Sales_Order CSO - SET - CSO.id_customer = v_id_customer, - CSO.price_total_local = SUM(t_CSOPL.price_total_local), - CSO.id_currency = v_id_currency_price, - CSO.id_change_set = v_id_change_set, - CSO.active = v_active - FROM Shop_Customer_Sales_Order CSO - INNER JOIN tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL ON CSO.id_order = t_CSOPL.id_order - WHERE SPO.id_order = v_id_order - ; - IF EXISTS (SELECT * FROM tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL INNER JOIN Shop_Customer_Sales_Order_Product_Link CSOPL ON t_CSOPL.id_link = CSOPL.id_link) THEN - UPDATE Shop_Customer_Sales_Order_Product_Link CSOPL - SET - CSOPL.id_order = t_CSOPL.id_order, - CSOPL.id_permutation = t_CSOPL.id_permutation, - CSOPL.price_total_local = t_CSOPL.price_total_local, - CSOPL.id_currency_price = t_CSOPL.id_currency_price, - CSOPL.quantity_ordered = t_CSOPL.quantity_ordered, - CSOPL.id_unit_quantity = t_CSOPL.id_unit_quantity, - CSOPL.quantity_delivered = t_CSOPL.quantity_delivered, - CSOPL.latency_delivery_days = t_CSOPL.latency_delivery_days, - CSOPL.display_order = t_CSOPL.display_order, - CSOPL.active = t_CSOPL.active, - CSOPL.id_change_set = v_id_change_set - FROM Shop_Customer_Sales_Order_Product_Link CSOPL - INNER JOIN tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL - ON CSOPL.id_link = t_CSOPL.id_link - ; - ELSE - INSERT INTO Shop_Customer_Sales_Order_Product_Link ( - id_order, - id_permutation, - price_total_local, - id_currency_price, - quantity_ordered, - id_unit_quantity, - quantity_delivered, - latency_delivery_days, - display_order, - active, - created_by, - id_change_set - ) - SELECT - id_order, - id_permutation, - price_total_local, - id_currency_price, - quantity_ordered, - id_unit_quantity, - quantity_delivered, - latency_delivery_days, - display_order, - active, - v_id_user, - v_id_change_set - FROM tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL - WHERE t_CSOPL.id_link < 0 - ; - END IF; - END IF; - - COMMIT; - /* - IF EXISTS (SELECT * FROM tmp_Msg_Error) THEN - ROLLBACK; - ELSE - COMMIT; - END IF; - */ - END IF; - - -- Returns - -- v_now := CURRENT_TIMESTAMP; - /* - -- Supplier Purchase Orders - SELECT * - FROM Shop_Customer_Sales_Order - WHERE id_order = v_id_order - ; - - -- Supplier Purchase Order Product Links - SELECT * - FROM Shop_Customer_Sales_Order_Product_Link - WHERE id_order = v_id_order - ; - */ - - -- Errors - OPEN result_errors FOR - SELECT * - FROM tmp_Msg_Error - ; - -- RETURN NEXT result_errors; - - -- DROP TABLE tmp_Shop_Customer_Sales_Order; - DROP TABLE tmp_Shop_Customer_Sales_Order_Product_Link; - DROP TABLE tmp_Msg_Error; -END; -$$ LANGUAGE plpgsql; - - -/* - -DELETE FROM Shop_Customer_Sales_Order_Product_Link_Audit; -DELETE FROM Shop_Customer_Sales_Order_Product_Link; -DELETE FROM Shop_Customer_Sales_Order_Product_Link_Temp; -DELETE FROM Shop_Customer_Sales_Order_Audit; -DELETE FROM Shop_Customer_Sales_Order; - -INSERT INTO Shop_Customer_Sales_Order_Product_Link_Temp ( - guid, - id_link, - id_order, - id_permutation, - price_total_local, - id_currency_price, - quantity_ordered, - id_unit_quantity, - quantity_delivered, - latency_delivery_days, - display_order, - active -) -VALUES - ( - 'NIPS', -- guid - -1, -- id_link, - -1, -- id_order, - 1, -- id_permutation, - 100, -- price_total_local, - 1, -- id_currency_price, - 1, -- quantity_ordered, - 1, -- id_unit_quantity, - 1, -- quantity_delivered, - 14, -- latency_delivery_days , - 1, -- display_order - 1 -- active - ) -; - -SELECT * FROM Shop_Customer_Sales_Order_Product_Link_Temp; - -CALL p_shop_save_customer_sales_order ( - 'NIPS', -- a_guid - 'auth0|6582b95c895d09a70ba10fef', -- a_id_user - 'Initial customer', -- a_comment - -1, -- a_id_order - 4, -- a_id_customer - 1, -- a_id_currency_price - 1 -- a_active -); - -SELECT * FROM Shop_Customer_Sales_Order_Product_Link_Temp; - -DELETE FROM Shop_Customer_Sales_Order_Product_Link_Audit; -DELETE FROM Shop_Customer_Sales_Order_Product_Link; -DELETE FROM Shop_Customer_Sales_Order_Product_Link_Temp; -DELETE FROM Shop_Customer_Sales_Order_Audit; -DELETE FROM Shop_Customer_Sales_Order; - - -*/ - diff --git a/static/PostgreSQL/610_p_shop_save_user.sql b/static/PostgreSQL/610_p_shop_save_user.sql deleted file mode 100644 index 2fcfb3f2..00000000 --- a/static/PostgreSQL/610_p_shop_save_user.sql +++ /dev/null @@ -1,166 +0,0 @@ - - - -/* - -CALL p_shop_save_user ( - 'auth0|6582b95c895d09a70ba10fef', -- a_id_user - '', -- a_name - '', -- a_email - 0 -- a_email_verified -) - -*/ - - -CREATE OR REPLACE PROCEDURE p_shop_save_user ( - IN a_id_user INTEGER, - IN a_name VARCHAR(255), - IN a_email VARCHAR(254), - IN a_email_verified BIT -) -AS $$ -DECLARE - v_id_user INTEGER; - v_name VARCHAR(255); - v_email VARCHAR(254); - v_email_verified BIT; - v_has_filter_user BOOLEAN; - result_errors REFCURSOR; -BEGIN - v_id_user := TRIM(COALESCE(a_id_user, '')); - v_name := TRIM(COALESCE(a_name, '')); - v_email := TRIM(COALESCE(a_email, '')); - v_email_verified := COALESCE(a_email_verified, FALSE); - - v_has_filter_user = CASE WHEN v_id_user = '' THEN FALSE ELSE TRUE END; - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Msg_Error; - DROP TABLE IF EXISTS tmp_Shop_User; - - CREATE TABLE tmp_Shop_User ( - id_user INTEGER, - CONSTRAINT FK_tmp_Shop_User_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user), - active BOOLEAN NOT NULL - ); - - CREATE TABLE tmp_Msg_Error ( - display_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - id_type INTEGER NOT NULL, - -- code VARCHAR(50) NOT NULL, - -- CONSTRAINT chk_tmp_Msg_Error_code CHECK (code IN (SELECT code FROM Shop_Msg_Error_Type)), - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type(id_type), - msg VARCHAR(4000) NOT NULL - ); - - - -- Parse filters - - - -- User - IF v_has_filter_user THEN - INSERT INTO tmp_Shop_User ( - id_user, - active - ) - SELECT id_user, - active - FROM Shop_User - WHERE id_user = v_id_user - AND active - LIMIT 1 - ; - - IF NOT EXISTS (SELECT id_user FROM tmp_Shop_User LIMIT 1) THEN - INSERT INTO Shop_User ( - id_user, - name, - email, - email_verified - ) - VALUES ( - v_id_user, - v_name, - v_email, - v_email_verified - ); - - INSERT INTO tmp_Shop_User ( - id_user, - active - ) - SELECT id_user, - active - FROM Shop_User - WHERE id_user = v_id_user - AND active - LIMIT 1 - ; - END IF; - - v_id_user := (SELECT id_user FROM tmp_Shop_User LIMIT 1); - ELSE - INSERT INTO tmp_Msg_Error ( - id_type, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - 'No user ID provided.' - ) - ; - END IF; - - - /* - IF NOT EXISTS (SELECT msg FROM tmp_Msg_Error LIMIT 1) THEN - END IF; - */ - - - -- Returns - /* - -- User - SELECT * - FROM tmp_Shop_User - ; - */ - - -- Errors - OPEN result_errors FOR - SELECT * - FROM tmp_Msg_Error - ; - -- RETURN NEXT result_errors; - - /* - -- Return arguments for test - SELECT a_id_user, - a_name, - a_email, - a_email_verified - ; - */ - - -- Clean up - DROP TABLE IF EXISTS tmp_Msg_Error; - DROP TABLE IF EXISTS tmp_Shop_User; -END; -$$ LANGUAGE plpgsql; - - -/* - -CALL p_shop_save_user ( - '', - '', - '', - 0 -) - -*/ diff --git a/static/PostgreSQL/611_p_shop_save_user_basket.sql b/static/PostgreSQL/611_p_shop_save_user_basket.sql deleted file mode 100644 index 6952dada..00000000 --- a/static/PostgreSQL/611_p_shop_save_user_basket.sql +++ /dev/null @@ -1,833 +0,0 @@ - - - -/* - -CALL p_shop_edit_user_basket ( - '', -- a_id_user - '', -- a_ids_permutation_basket - '', -- a_quantities_permutation_basket - 1, -- a_id_permutation_edit - NULL, -- a_quantity_permutation_edit - 1, -- a_sum_not_edit - 1, -- a_id_currency_edit - 1 -- a_id_region_purchase -) - -* - - -CREATE OR REPLACE PROCEDURE p_shop_edit_user_basket ( - IN a_id_user INTEGER, - IN a_ids_permutation_basket VARCHAR(4000), - IN a_quantities_permutation_basket VARCHAR(4000), - IN a_id_permutation_edit INTEGER, - IN a_quantity_permutation_edit INTEGER, - IN a_sum_not_edit BOOLEAN, - IN a_id_currency INTEGER, - IN a_id_region_purchase INT -) -AS $$ -DECLARE - v_guid UUID; - v_id_user INTEGER; - v_ids_permutation_basket BOOLEAN; - v_quantities_permutation_basket VARCHAR -- REMAKE WITH TEMP TABLE -BEGIN - -- Argument redeclaration - -- Variable declaration - DECLARE v_has_filter_user BOOLEAN; - DECLARE v_has_filter_permutation_basket BOOLEAN; - DECLARE v_has_filter_permutation_edit BOOLEAN; - DECLARE v_has_filter_region BOOLEAN; - DECLARE v_has_filter_currency BOOLEAN; - DECLARE v_n_id_permutation_basket INTEGER; - DECLARE v_n_quantity_permutation_basket INTEGER; - DECLARE v_row_number INTEGER; - DECLARE v_guid UUID; - -- DECLARE v_id_user VARCHAR(100); - DECLARE v_id_permission_product INTEGER; - DECLARE v_ids_permutation_permission VARCHAR(4000); - DECLARE v_now TIMESTAMP; - -- DECLARE v_quantity_new INTEGER; - DECLARE v_change_set_used BOOLEAN; - DECLARE v_id_change_set INTEGER; - - SET v_guid = gen_random_uuid(); - - -- Argument validation + default values - IF a_id_user IS NULL THEN - SET a_id_user = ''; - ELSE - SET a_id_user = TRIM(a_id_user); - END IF; - IF a_ids_permutation_basket IS NULL THEN - SET a_ids_permutation_basket = ''; - ELSE - SET a_ids_permutation_basket = TRIM(a_ids_permutation_basket); - END IF; - IF a_quantities_permutation_basket IS NULL THEN - SET a_quantities_permutation_basket = ''; - ELSE - SET a_quantities_permutation_basket = TRIM(a_quantities_permutation_basket); - END IF; - IF a_sum_not_edit IS NULL THEN - SET a_sum_not_edit = TRUE; - END IF; - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Msg_Error; - DROP TABLE IF EXISTS tmp_Shop_Basket; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Quantity; - DROP TABLE IF EXISTS tmp_Shop_Product; - DROP TABLE IF EXISTS tmp_Shop_User; - - CREATE TABLE tmp_Shop_User ( - id_user INTEGER, - CONSTRAINT FK_tmp_Shop_User_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user), - active BOOLEAN NOT NULL - ); - - CREATE TABLE tmp_Shop_Product ( - id_product INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - id_permutation INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - display_order INTEGER NOT NULL, - active INTEGER NOT NULL DEFAULT 1 - ); - - CREATE TEMPORARY TABLE tmp_Shop_Quantity( - quantity INTEGER NOT NULL, - display_order INTEGER NOT NULL, - active INTEGER NOT NULL DEFAULT 1 - ); - - CREATE TABLE tmp_Shop_Basket ( - id_category INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Basket_id_category - FOREIGN KEY (id_category) - REFERENCES Shop_Product_Category(id_category), - id_product INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Basket_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - id_permutation INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Basket_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - id_region_purchase INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Basket_id_region_purchase - FOREIGN KEY (id_region_purchase) - REFERENCES Shop_Region(id_region), - id_currency INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Basket_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency), - quantity INTEGER NOT NULL, - active BOOLEAN NOT NULL DEFAULT TRUE - /* - display_order_category INTEGER NOT NULL, - display_order_product INTEGER NOT NULL - */ - ); - - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - guid UUID NOT NULL, - id_type INTEGER NOT NULL, - -- code VARCHAR(50) NOT NULL, - -- CONSTRAINT chk_tmp_Msg_Error_code CHECK (code IN (SELECT code FROM Shop_Msg_Error_Type)), - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type(id_type), - msg VARCHAR(4000) NOT NULL - ); - - - -- Parse filters - SET v_has_filter_user = NOT (a_id_user = ''); - SET v_has_filter_permutation_basket = NOT (a_ids_permutation_basket = ''); - SET v_has_filter_permutation_edit = NOT ISNULL(a_id_permutation_edit); - SET v_has_filter_currency = NOT ISNULL(a_id_currency); - SET v_has_filter_region = NOT ISNULL(a_id_region_purchase); - -- SET v_quantity_new = CASE WHEN a_sum_not_edit THEN quantity + a_quantity_product_edit ELSE a_quantity_product_edit END; - /* - SELECT v_has_filter_user, v_has_filter_basket - ; - - */ - - -- Currency - IF NOT v_has_filter_currency THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - 'Currency ID not provided.' - ) - ; - END IF; - IF v_has_filter_currency AND NOT EXISTS ( SELECT * FROM Shop_Currency WHERE id_currency = a_id_currency) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('Currency ID not found: ', a_id_currency, '.') - ) - ; - END IF; - - -- Region - IF NOT v_has_filter_region THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - 'Region ID not provided.' - ) - ; - END IF; - IF v_has_filter_region AND NOT EXISTS ( SELECT * FROM Shop_Region WHERE id_region = a_id_region_purchase) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('Region ID not found: ', a_id_region_purchase, '.') - ) - ; - END IF; - - -- User - IF v_has_filter_user THEN - INSERT INTO tmp_Shop_User ( - id_user, - active - ) - SELECT id_user, - active - FROM Shop_User - WHERE id_user LIKE CONCAT('%', a_id_user, '%') - AND active - LIMIT 1 - ; - - IF NOT EXISTS (SELECT id_user FROM tmp_Shop_User LIMIT 1) THEN - SET v_has_filter_user = FALSE; - - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('User ID not found: ', a_id_user, '.') - ) - ; - END IF; - - SET a_id_user := (SELECT id_user FROM tmp_Shop_User LIMIT 1); - END IF; - - IF v_has_filter_user AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - SET v_change_set_used = FALSE; - INSERT INTO Shop_User_Change_Set ( - comment - ) - VALUES ( - 'edit basket' - ); - SET v_id_change_set := (SELECT id_change_set FROM Shop_User_Change_Set ORDER BY id_change_set DESC LIMIT 1); - END IF; - - -- Get basket - -- User - IF v_has_filter_user AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - INSERT INTO tmp_Shop_Basket ( - id_category, - id_product, - id_permutation, - id_region_purchase, - id_currency, - quantity, - active - /* - display_order_category, - display_order_product - */ - ) - SELECT - C.id_category, - UB.id_product, - UB.id_permutation, - UB.id_region_purchase, - UB.id_currency, - UB.quantity, - UB.active - /* - C.display_order, - P.display_order - */ - FROM Shop_User_Basket UB - /* - INNER JOIN tmp_Shop_User t_U - ON UB.id_user = t_U.id_user - */ - INNER JOIN Shop_Product_Permutation PP - ON UB.id_product = PP.id_product - AND PP.active - INNER JOIN Shop_Product P - ON PP.id_product = P.id_product - AND P.active - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - AND C.active - WHERE UB.id_user = a_id_user - ; - END IF; - - -- Currency - IF EXISTS (SELECT * FROM tmp_Shop_Basket WHERE active LIMIT 1) - AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - IF EXISTS (SELECT * FROM tmp_Shop_Basket WHERE active AND id_currency != a_id_currency) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT( - 'Currency ID does not match currency of other items in basket. Basket currency: ', - (SELECT code FROM Shop_Currency WHERE id_currency = ( - SELECT - id_currency - FROM tmp_Shop_Basket - WHERE active - AND id_currency != a_id_currency - LIMIT 1 - )), - ', new currency: ', - (SELECT code FROM Shop_Currency WHERE id_currency = a_id_currency), - '.' - ) - ) - ; - END IF; - END IF; - - -- Region - IF EXISTS (SELECT * FROM tmp_Shop_Basket WHERE active LIMIT 1) - AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Shop_Basket - WHERE - active - AND id_region_purchase != a_id_region_purchase - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('Purchase region ID does not match region of other items in basket. Basket currency: ', - (SELECT code FROM Shop_Region WHERE id_region = ( - SELECT - id_region_purchase - FROM tmp_Shop_Basket - WHERE active - AND id_region != a_id_region_purchase - LIMIT 1 - )), - ', new currency: ', - (SELECT code FROM Shop_Region WHERE id_region = a_id_region_purchase), - '.' - ) - ) - ; - END IF; - END IF; - - -- String product id, permutation id, quantity list - IF NOT EXISTS (SELECT * FROM tmp_Shop_Basket WHERE active LIMIT 1) AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN -- NOT v_has_filter_user AND - -- Get product ids - CALL p_split(a_guid, a_ids_permutation_basket, ','); - INSERT INTO tmp_Shop_Product ( - id_product, id_permutation, display_order - ) - SELECT PP.id_product, ST.substring, ST.display_order - FROM Split_Temp ST - INNER JOIN Shop_Product_Permutation PP - ON ST.substring = PP.id_permutation - -- AND PP.active - ; - /* - SELECT substring as id_product, display_order - FROM Split_Temp - ; - */ - DROP TABLE Split_Temp; - - -- Get product quantities - CALL p_split(a_guid, a_quantities_permutation_basket, ','); - INSERT INTO tmp_Shop_Quantity ( - quantity, display_order - ) - SELECT substring, display_order - FROM Split_Temp - ; - /* - SELECT substring AS quantity_product, display_order - FROM Split_Temp - ; - */ - DROP TABLE Split_Temp; - - -- Compare number of product ids to number of quantities - SET v_n_id_permutation_basket := (SELECT display_order FROM tmp_Shop_Product ORDER BY display_order DESC LIMIT 1); - SET v_n_quantity_permutation_basket := (SELECT display_order FROM tmp_Shop_Quantity ORDER BY display_order DESC LIMIT 1); - IF NOT v_n_id_permutation_basket = v_n_quantity_permutation_basket THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('Number of permutations (', v_n_id_permutation_basket, ') does not equal number of quantities (', v_n_quantity_permutation_basket, ') for basket.') - ) - ; - ELSE - INSERT INTO tmp_Shop_Basket ( - id_category, - id_product, - id_permutation, - id_region_purchase, - id_currency, - quantity - ) - SELECT - C.id_category, - P.id_product, - t_P.id_permutation, - a_id_region_purchase, - a_id_currency, - t_Q.quantity - FROM tmp_Shop_Product t_P - INNER JOIN tmp_Shop_Quantity t_Q - ON t_P.display_order = t_Q.display_order - INNER JOIN Shop_Product_Permutation PP - ON t_P.id_permutation = PP.id_permutation - AND PP.active - INNER JOIN Shop_Product P - ON PP.id_product = P.id_product - AND P.active - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - AND C.active - -- RIGHT JOIN tmp_Shop_Basket t_UB ON ISNULL(t_UB.id_product) - -- WHERE t_P.id_product NOT IN (SELECT id_product FROM tmp_Shop_Basket) - ; - - /* - IF EXISTS( - SELECT * - FROM Shop_Product P - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - INNER JOIN tmp_Shop_Basket t_B - ON P.id_product = t_B.id_product - WHERE C.active = FALSE OR P.active = FALSE LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('No valid product IDs in list: ', a_ids_permutation_basket, '.') - ) - ; - END IF; - */ - END IF; - END IF; - - /* - select v_has_filter_edit; - select * from tmp_Shop_Basket; - select * from tmp_Msg_Error; - */ - - - -- Edit basket product - IF v_has_filter_permutation_edit AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM Shop_Product_Permutation PP - INNER JOIN Shop_Product P - ON PP.id_product = P.id_product - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - WHERE - ( - C.active = FALSE - OR P.active = FALSE - OR PP.active = FALSE - ) - AND PP.id_permutation = a_id_permutation_edit - LIMIT 1 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - CONCAT('Invalid product ID to edit: ', a_id_product_edit, '.') - ) - ; - END IF; - END IF; - IF v_has_filter_permutation_edit AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - IF EXISTS ( - SELECT * - FROM tmp_Shop_Basket - WHERE - id_permutation = a_id_permutation_edit - ) THEN - UPDATE tmp_Shop_Basket - SET quantity = CASE WHEN a_sum_not_edit = TRUE THEN COALESCE(quantity, 0) + a_quantity_permutation_edit ELSE a_quantity_permutation_edit END, - active = CASE WHEN CASE WHEN a_sum_not_edit = TRUE THEN COALESCE(quantity, 0) + a_quantity_permutation_edit ELSE a_quantity_permutation_edit END = FALSE THEN FALSE ELSE TRUE END - WHERE id_permutation = a_id_permutation_edit - ; - - IF EXISTS ( - SELECT * - FROM tmp_Shop_Basket t_B - WHERE t_B.quantity < 0 - ) THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - 'Invalid basket quantity.' - ) - ; - END IF; - - IF v_has_filter_user AND NOT EXISTS (SELECT msg FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - SET v_change_set_used = TRUE; - - UPDATE Shop_User_Basket UB - INNER JOIN tmp_Shop_Basket t_UB - ON UB.id_permutation = a_id_permutation_edit - SET UB.quantity = t_UB.quantity, - UB.active = t_UB.active, - UB.id_change_set_user = v_id_change_set - WHERE UB.id_permutation = a_id_permutation_edit - AND id_user = a_id_user - ; - END IF; - ELSE - IF a_quantity_permutation_edit < 0 THEN - INSERT INTO tmp_Msg_Error ( - id_type, - guid, - msg - ) - VALUES ( - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'BAD_DATA' LIMIT 1), - v_guid, - 'Invalid basket quantity.' - ) - ; - ELSE - INSERT INTO tmp_Shop_Basket ( - id_category, - id_product, - id_permutation, - id_region_purchase, - id_currency, - quantity, - active - ) - SELECT - P.id_category, - P.id_product, - PP.id_permutation, - a_id_region_purchase, - a_id_currency, - a_quantity_permutation_edit, - CASE WHEN a_quantity_permutation_edit > 0 THEN TRUE ELSE FALSE END - FROM Shop_Product_Permutation PP - INNER JOIN Shop_Product P - ON PP.id_product = P.id_product - WHERE id_permutation = a_id_permutation_edit - ; - IF v_has_filter_user THEN - IF EXISTS ( - SELECT * - FROM Shop_User_Basket UB - WHERE - UB.id_permutation = a_id_permutation_edit - ) THEN - SET v_change_set_used = TRUE; - - UPDATE Shop_User_Basket - INNER JOIN tmp_Shop_Basket t_UB ON UB.id_permutation = t_UB.id_permutation - SET UB.quantity = t_UB.quantity, - UB.active = t_UB.active, - UB.id_change_set_user = v_id_change_set - WHERE UB.id_permutation = a_id_permutation_edit - AND id_user = a_id_user - ; - ELSE - INSERT INTO Shop_User_Basket ( - id_user, - id_product, - id_permutation, - id_region_purchase, - id_currency, - quantity, - active - ) - SELECT a_id_user, - t_UB.id_product, - t_UB.id_permutation, - t_UB.id_region_purchase, - t_UB.id_currency, - t_UB.quantity, - t_UB.active - FROM tmp_Shop_Basket t_UB - WHERE id_permutation = a_id_permutation_edit - ; - END IF; - END IF; - END IF; - END IF; - END IF; - - - -- Checks - /* - SELECT * FROM tmp_Shop_Basket; - SELECT - STRING_AGG(t_UB.id_product, ',') AS basket_product_ids - FROM tmp_Shop_Basket t_UB - -- WHERE ISNULL(t_UB.id_permutation) - ; - SELECT - STRING_AGG(t_UB.id_permutation, ',') AS basket_permutation_ids - FROM tmp_Shop_Basket t_UB - WHERE NOT ISNULL(t_UB.id_permutation) - ; - */ - -- Returns - CALL p_shop_get_many_product ( - a_id_user, -- a_id_user - 1, -- a_get_all_categories - '', -- a_ids_category - 0, -- a_get_inactive_categories - 0, -- a_get_all_products - ( - SELECT - STRING_AGG(t_B.id_product, ',') - FROM tmp_Shop_Basket t_B - WHERE active = TRUE - ), -- a_ids_product - 0, -- a_get_inactive_products - 0, -- a_get_first_product_only - 0, -- a_get_all_product_permutations - ( - SELECT - STRING_AGG(t_B.id_permutation, ',') - FROM tmp_Shop_Basket t_B - WHERE NOT ISNULL(t_B.id_permutation) - AND active = TRUE - ), -- a_ids_permutation - 0, -- a_get_inactive_permutations - 0, -- a_get_all_images - '', -- a_ids_image - 0, -- a_get_inactive_images - 1, -- a_get_first_image_only - 0, -- a_get_all_delivery_region - a_id_region_purchase, -- a_ids_delivery_region - 0, -- a_get_inactive_delivery_region - 0, -- a_get_all_currency - a_id_currency, -- a_ids_currency - 0, -- a_get_inactive_currency - 1, -- a_get_all_discount - '', -- a_ids_discount - 0 -- a_get_inactive_discount - ); - - -- Basket - SELECT t_UB.id_category, - t_UB.id_product, - t_UB.id_permutation, - P.name, - PCL.price_local_VAT_incl, - PCL.price_local_VAT_excl, - PCL.id_currency, - t_UB.quantity - FROM tmp_Shop_Basket t_UB - INNER JOIN Shop_Product_Permutation PP - ON t_UB.id_permutation = PP.id_permutation - INNER JOIN Shop_Product P - ON PP.id_product = P.id_product - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - INNER JOIN Shop_Product_Currency_Link PCL - ON PP.id_permutation = PCL.id_permutation - AND PCL.id_region_purchase = a_id_region_purchase - AND PCL.id_currency = a_id_currency - WHERE t_UB.active = TRUE - ORDER BY C.display_order, P.display_order - ; - - -- Errors - /* Completed by product get many */ - SELECT - t_ME.display_order, - t_ME.guid, - t_ME.id_type, - t_ME.msg, - MET.code, - MET.name, - MET.description - FROM tmp_Msg_Error t_ME - INNER JOIN Shop_Msg_Error_Type MET - ON t_ME.id_type = MET.id_type - WHERE GUID = v_guid - ; - - /* - -- Return arguments for test - SELECT - a_ids_category, - a_get_inactive_categories, - a_ids_product, - a_get_inactive_products, - a_get_first_product_only, - a_get_all_products, - a_ids_image, - a_get_inactive_images, - a_get_first_image_only, - a_get_all_images - ; - */ - - -- Clean up - IF NOT v_change_set_used THEN - DELETE FROM Shop_User_Change_Set - WHERE id_change_set = v_id_change_set - ; - END IF; - - -- DROP TABLE IF EXISTS tmp_Msg_Error; - DELETE FROM tmp_Msg_Error WHERE guid = v_guid; - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN - DROP TABLE tmp_Msg_Error; - END IF; - DROP TABLE IF EXISTS tmp_Shop_Basket; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Quantity; - DROP TABLE IF EXISTS tmp_Shop_Product; - DROP TABLE IF EXISTS tmp_Shop_User; -END; -$$ LANGUAGE plpgsql; - -*/ - - -/* - -CALL p_shop_edit_user_basket ( - '', -- a_id_user - '', -- a_ids_permutation_basket - '', -- a_quantities_permutation_basket - 2, -- a_id_permutation_edit - 1, -- a_quantity_permutation_edit - 1, -- a_sum_not_edit - 2, -- a_id_currency_edit - 1 -- a_id_region_purchase -); - -CALL p_shop_edit_user_basket ( - '', -- a_id_user - '1', -- a_ids_permutation_basket - '9', -- a_quantities_permutation_basket - 1, -- a_id_permutation_edit - 69, -- a_quantity_permutation_edit - 1, -- a_sum_not_edit - 1, -- a_id_currency_edit - 1 -- a_id_region_purchase -); -CALL p_shop_edit_user_basket ( - 'auth0|6582b95c895d09a70ba10feF', -- a_id_user - '2', -- a_ids_permutation_basket - '7', -- a_quantities_permutation_basket - 2, -- a_id_permutation_edit - NULL, -- a_quantity_permutation_edit - 1, -- a_sum_not_edit - 1, -- a_id_currency_edit - 1 -- a_id_region_purchase -); - - - {'a_id_user': 'auth0|6582b95c895d09a70ba10fef', - 'a_ids_permutation_basket': '1', - '7', -- a_quantities_permutation_basket - 'a_id_permutation_edit': 1, - 'a_quantity_permutation_edit': 1, - 'a_sum_not_edit': 1} - - select * from shop_user_basket; - insert into shop_user_change_set (comment) - values( 'deactivate duplicates'); - update SHOP_USER_BASKET - set active = FALSE, - id_change_set_user = (select id_change_set from shop_user_change_set order by id_change_set desc limit 1) - where id_user = 'auth0|6582b95c895d09a70ba10fef' - and id_product = 1 - ; - select * from shop_user_basket; -*/ diff --git a/static/PostgreSQL/700_p_shop_get_many_product.sql b/static/PostgreSQL/700_p_shop_get_many_product.sql deleted file mode 100644 index 0e879542..00000000 --- a/static/PostgreSQL/700_p_shop_get_many_product.sql +++ /dev/null @@ -1,1231 +0,0 @@ - - -CREATE OR REPLACE FUNCTION p_shop_get_many_product ( - IN a_id_user INTEGER, - IN a_get_all_category BOOLEAN, - IN a_get_inactive_category BOOLEAN, - IN a_get_first_category_only BOOLEAN, - IN a_ids_category INTEGER[], - IN a_get_all_product BOOLEAN, - IN a_get_inactive_product BOOLEAN, - IN a_get_first_product_only BOOLEAN, - IN a_ids_product INTEGER[], - IN a_get_all_product_permutation BOOLEAN, - IN a_get_inactive_permutation BOOLEAN, - IN a_get_first_permutation_only BOOLEAN, - IN a_ids_permutation INTEGER[], - IN a_get_all_image BOOLEAN, - IN a_get_inactive_image BOOLEAN, - IN a_get_first_image_only BOOLEAN, - IN a_ids_image INTEGER[], - IN a_get_all_delivery_region BOOLEAN, - IN a_get_inactive_delivery_region BOOLEAN, - IN a_ids_delivery_region INTEGER[], - IN a_get_all_currency BOOLEAN, - IN a_get_inactive_currency BOOLEAN, - IN a_ids_currency INTEGER[], - IN a_get_all_discount BOOLEAN, - IN a_get_inactive_discount BOOLEAN, - IN a_ids_discount INTEGER[] -) -RETURNS SETOF REFCURSOR -- categories, SETOF products, SETOF variations, SETOF prices, SETOF images, SETOF delivery_options, SETOF discounts -AS $$ -DECLARE - v_id_user INTEGER; - v_get_all_category BOOLEAN; - v_get_inactive_category BOOLEAN; - v_get_first_category_only BOOLEAN; - v_ids_category INTEGER[]; - v_get_all_product BOOLEAN; - v_get_inactive_product BOOLEAN; - v_get_first_product_only BOOLEAN; - v_ids_product INTEGER[]; - v_get_all_product_permutation BOOLEAN; - v_get_inactive_permutation BOOLEAN; - v_get_first_permutation_only BOOLEAN; - v_ids_permutation INTEGER[]; - v_get_all_image BOOLEAN; - v_get_inactive_image BOOLEAN; - v_get_first_image_only BOOLEAN; - v_ids_image INTEGER[]; - v_get_all_delivery_region BOOLEAN; - v_get_inactive_delivery_region BOOLEAN; - v_ids_delivery_region INTEGER[]; - v_get_all_currency BOOLEAN; - v_get_inactive_currency BOOLEAN; - v_ids_currency INTEGER[]; - v_get_all_discount BOOLEAN; - v_get_inactive_discount BOOLEAN; - v_ids_discount INTEGER[]; - - v_has_filter_category BOOLEAN; - v_has_filter_product BOOLEAN; - v_has_filter_permutation BOOLEAN; - v_has_filter_image BOOLEAN; - v_has_filter_delivery_region BOOLEAN; - v_has_filter_currency BOOLEAN; - v_has_filter_discount BOOLEAN; - v_guid UUID; - -- v_id_user VARCHAR(100); - v_ids_permutation_unavailable VARCHAR(4000); - v_id_permission_product INTEGER; - v_ids_product_permission VARCHAR(4000); - -- v_ids_permutation_permission VARCHAR(4000); - v_id_access_level_view INTEGER; - -- v_now TIMESTAMP; - v_id_minimum INTEGER; - - result_categories REFCURSOR; - result_products REFCURSOR; - result_variations REFCURSOR; - result_prices REFCURSOR; - result_images REFCURSOR; - result_delivery_options REFCURSOR; - result_discounts REFCURSOR; - /* - -- result_errors REFCURSOR; - */ -BEGIN - v_id_user := a_id_user; - v_get_all_category := COALESCE(a_get_all_category, FALSE); - v_get_inactive_category := COALESCE(a_get_inactive_category, FALSE); - v_get_first_category_only := COALESCE(a_get_first_category_only, TRUE); - v_ids_category := COALESCE(a_ids_category, ARRAY[]::INTEGER[]); - v_get_all_product := COALESCE(a_get_all_product, FALSE); - v_get_inactive_product := COALESCE(a_get_inactive_product, FALSE); - v_get_first_product_only := COALESCE(a_get_first_product_only, TRUE); - v_ids_product := COALESCE(a_ids_product, ARRAY[]::INTEGER[]); - v_get_all_product_permutation := COALESCE(a_get_all_product_permutation, FALSE); - v_get_inactive_permutation := COALESCE(a_get_inactive_permutation, FALSE); - v_get_first_permutation_only := COALESCE(a_get_first_permutation_only, TRUE); - v_ids_permutation := COALESCE(a_ids_permutation, ARRAY[]::INTEGER[]); - v_get_all_image := COALESCE(a_get_all_image, TRUE); - v_get_inactive_image := COALESCE(a_get_inactive_image, FALSE); - v_get_first_image_only := COALESCE(a_get_first_image_only, FALSE); - v_ids_image := COALESCE(a_ids_image, ARRAY[]::INTEGER[]); - v_get_all_delivery_region := COALESCE(a_get_all_delivery_region, TRUE); - v_get_inactive_delivery_region := COALESCE(a_get_inactive_delivery_region, FALSE); - v_ids_delivery_region := COALESCE(a_ids_delivery_region, ARRAY[]::INTEGER[]); - v_get_all_currency := COALESCE(a_get_all_currency, TRUE); - v_get_inactive_currency := COALESCE(a_get_inactive_currency, FALSE); - v_ids_currency := COALESCE(a_ids_currency, ARRAY[]::INTEGER[]); - v_get_all_discount := COALESCE(a_get_all_discount, TRUE); - v_get_inactive_discount := COALESCE(a_get_inactive_discount, FALSE); - v_ids_discount := COALESCE(a_ids_discount, ARRAY[]::INTEGER[]); - /* - ROLLBACK; - */ - v_guid := gen_random_uuid(); - v_id_access_level_view := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW'); - - v_has_filter_category = (CARDINALITY(v_ids_category) > 0); - v_has_filter_product = (CARDINALITY(v_ids_product) > 0); - v_has_filter_permutation = (CARDINALITY(v_ids_permutation) > 0); - v_has_filter_image = (CARDINALITY(v_ids_image) > 0); - v_has_filter_delivery_region = (CARDINALITY(v_ids_delivery_region) > 0); - v_has_filter_currency = (CARDINALITY(v_ids_currency) > 0); - v_has_filter_discount = (CARDINALITY(v_ids_discount) > 0); - - /* - SELECT v_id_user, v_get_all_category, v_ids_category, v_get_inactive_category, v_get_all_product, - v_ids_product, v_get_inactive_product, v_get_first_product_only, v_get_all_product_permutation, v_ids_permutation, - v_get_inactive_permutation, v_get_all_image, v_ids_image, v_get_inactive_image, v_get_first_image_only, - v_get_all_delivery_region, v_ids_delivery_region, v_get_inactive_delivery_region, v_get_all_currency, v_ids_currency, - v_get_inactive_currency, v_get_all_discount, v_ids_discount, v_get_inactive_discount - ; - */ - - -- Temporary tables - /* - DROP TEMPORARY TABLE IF EXISTS tmp_Discount; - DROP TEMPORARY TABLE IF EXISTS tmp_Currency; - DROP TEMPORARY TABLE IF EXISTS tmp_Delivery_Region; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Image; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Variation; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Product; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Product_Category; - */ - DROP TABLE IF EXISTS tmp_Discount; - DROP TABLE IF EXISTS tmp_Currency; - DROP TABLE IF EXISTS tmp_Delivery_Region; - DROP TABLE IF EXISTS tmp_Shop_Image; - DROP TABLE IF EXISTS tmp_Shop_Variation; - DROP TABLE IF EXISTS tmp_Shop_Product; - DROP TABLE IF EXISTS tmp_Shop_Product_Category; - - CREATE TEMPORARY TABLE tmp_Shop_Product_Category ( - id_category INTEGER NOT NULL, - /* - CONSTRAINT FK_tmp_Shop_Product_Category_id_category - FOREIGN KEY (id_category) - REFERENCES Shop_Product_Category(id_category), - */ - active BOOLEAN NOT NULL, - display_order INTEGER NOT NULL, - can_view BOOLEAN, - can_edit BOOLEAN, - can_admin BIT - ); - - CREATE TEMPORARY TABLE tmp_Shop_Product ( - id_category INTEGER NOT NULL, - /* - CONSTRAINT FK_tmp_Shop_Product_id_category - FOREIGN KEY (id_category) - REFERENCES Shop_Product_Category(id_category), - */ - id_product INTEGER NOT NULL, - /* - CONSTRAINT FK_tmp_Shop_Product_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - */ - -- product_has_variations BOOLEAN NOT NULL, - id_permutation INTEGER NULL, - /* - CONSTRAINT FK_tmp_Shop_Product_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - */ - active_category BOOLEAN NOT NULL, - active_product BOOLEAN NOT NULL, - active_permutation BOOLEAN NULL, - display_order_category INTEGER NOT NULL, - display_order_product INTEGER NOT NULL, - display_order_permutation INTEGER NULL, - -- rank_permutation INTEGER NOT NULL, -- _in_category - rank_category INTEGER NOT NULL, - rank_product INTEGER NOT NULL, - rank_permutation INTEGER NOT NULL, - name VARCHAR(255) NOT NULL, - description VARCHAR(4000) NOT NULL, - /* - price_GBP_full REAL NOT NULL, - price_GBP_min REAL NOT NULL, - */ - latency_manufacture INTEGER NOT NULL, - quantity_min REAL NOT NULL, - quantity_max REAL NOT NULL, - quantity_step REAL NOT NULL, - quantity_stock REAL NOT NULL, - is_subscription BOOLEAN NOT NULL, - id_unit_measurement_interval_recurrence INTEGER, - /* - CONSTRAINT FK_tmp_Shop_Product_id_unit_measurement_interval_recurrence - FOREIGN KEY (id_unit_measurement_interval_recurrence) - REFERENCES Shop_Interval_Recurrence(id_interval), - */ - count_interval_recurrence INTEGER, - id_stripe_product VARCHAR(100), - product_has_variations BOOLEAN NOT NULL, - can_view BOOLEAN, - can_edit BOOLEAN, - can_admin BOOLEAN - ); - - /* - CREATE TEMPORARY TABLE tmp_Shop_Variation ( - id_variation INTEGER NOT NULL, - id_product INTEGER NOT NULL, - display_order INTEGER NOT NULL - ); - */ - - CREATE TEMPORARY TABLE tmp_Shop_Image ( - id_image INTEGER NOT NULL, - /* - CONSTRAINT FK_tmp_Shop_Image_id_image - FOREIGN KEY (id_image) - REFERENCES Shop_Image(id_image), - */ - id_product INTEGER NOT NULL, - /* - CONSTRAINT FK_tmp_Shop_Image_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - */ - id_permutation INTEGER NULL, - /* - CONSTRAINT FK_tmp_Shop_Image_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - */ - active BOOLEAN NOT NULL, - display_order INTEGER NOT NULL, - rank_in_product_permutation INTEGER NOT NULL - ); - - CREATE TEMPORARY TABLE tmp_Delivery_Region ( - id_region INTEGER NOT NULL, - /* - CONSTRAINT FK_tmp_Delivery_Region_id_region - FOREIGN KEY (id_region) - REFERENCES Shop_Region(id_region), - */ - active BOOLEAN NOT NULL, - display_order INTEGER NOT NULL, - requires_delivery_option BOOLEAN NOT NULL DEFAULT FALSE - ); - - CREATE TEMPORARY TABLE tmp_Currency ( - id_currency INTEGER NOT NULL, - /* - CONSTRAINT FK_tmp_Shop_Currency_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency), - */ - active BOOLEAN NOT NULL, - display_order INTEGER NOT NULL - ); - - CREATE TEMPORARY TABLE tmp_Discount ( - id_discount INTEGER NOT NULL, - /* - CONSTRAINT FK_tmp_Discount_id_discount - FOREIGN KEY (id_discount) - REFERENCES Shop_Discount(id_discount), - */ - active BOOLEAN NOT NULL, - display_order INTEGER NOT NULL - ); - - /* - CREATE TEMPORARY TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - guid UUID NOT NULL, - id_type INTEGER NOT NULL, - /* - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type (id_type), - */ - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - */ - - - INSERT INTO tmp_Shop_Product ( - id_category, - id_product, - id_permutation, - active_category, - active_product, - active_permutation, - display_order_category, - display_order_product, - display_order_permutation, - -- rank_permutation, - rank_category, - rank_product, - rank_permutation, - name, - description, - /* - price_GBP_VAT_incl, - price_GBP_VAT_excl, - price_GBP_min, - */ - latency_manufacture, - quantity_min, - quantity_max, - quantity_step, - quantity_stock, - is_subscription, - id_unit_measurement_interval_recurrence, - count_interval_recurrence, - id_stripe_product, - product_has_variations - ) - SELECT - P.id_category, - P.id_product, - -- P.has_variations AS product_has_variations, - PP.id_permutation, - C.active AS active_category, - P.active AS active_product, - PP.active AS active_permutation, - C.display_order AS display_order_category, - P.display_order AS display_order_product, - PP.display_order AS display_order_permutation, - -- RANK() OVER (ORDER BY C.display_order, P.display_order, PP.display_order) AS rank_permutation, -- PARTITION BY P.id_category -- _in_category - RANK() OVER (ORDER BY C.display_order) AS rank_category, - RANK() OVER (PARTITION BY P.id_category ORDER BY P.display_order) AS rank_product, - RANK() OVER (PARTITION BY P.id_category, P.id_product ORDER BY PP.display_order) AS rank_permutation, - P.name, - PP.description, - /* - PP.price_GBP_VAT_incl, - PP.price_GBP_VAT_excl, - PP.price_GBP_min, - */ - PP.latency_manufacture, - PP.quantity_min, - PP.quantity_max, - PP.quantity_step, - PP.quantity_stock, - PP.is_subscription, - PP.id_unit_measurement_interval_recurrence, - PP.count_interval_recurrence, - PP.id_stripe_product, - P.has_variations - FROM Shop_Product P - INNER JOIN Shop_Product_Permutation PP - ON P.id_product = PP.id_product - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - WHERE - -- permutations - ( - ( - v_get_all_product_permutation - OR ( - v_has_filter_permutation - -- AND FIND_IN_SET(PP.id_permutation, v_ids_permutation) > 0 - AND PP.id_permutation = ANY(v_ids_permutation) - ) - ) - AND (v_get_inactive_permutation OR PP.active) - ) - -- categories - AND ( - ( - v_get_all_category - OR ( - v_has_filter_category - -- AND FIND_IN_SET(P.id_category, v_ids_category) > 0 - AND C.id_category = ANY(v_ids_category) - ) - ) - AND (v_get_inactive_category OR C.active) - ) - -- products - AND ( - ( - v_get_all_product - OR ( - v_has_filter_product - -- AND FIND_IN_SET(P.id_product, v_ids_product) > 0 - AND P.id_product = ANY(v_ids_product) - ) - ) - AND (v_get_inactive_product OR P.active) - ) - ; - - -- select * from tmp_Shop_Product; - - IF v_get_first_category_only THEN - DELETE FROM tmp_Shop_Product t_P - WHERE t_P.rank_category > 1 - ; - END IF; - - IF v_get_first_product_only THEN - DELETE FROM tmp_Shop_Product t_P - WHERE t_P.rank_product > 1 - ; - END IF; - - IF v_get_first_permutation_only THEN - DELETE FROM tmp_Shop_Product t_P - WHERE t_P.rank_permutation > 1 - ; - END IF; - - - INSERT INTO tmp_Shop_Product_Category ( - id_category, - active, - display_order - ) - SELECT DISTINCT C.id_category, - C.active, - C.display_order - FROM tmp_Shop_Product t_P - INNER JOIN Shop_Product_Category C - ON t_P.id_category = C.id_category - ORDER BY C.display_order - ; - - /* - INSERT INTO tmp_Shop_Variation ( - id_variation, id_product -- , display_order - ) - SELECT P.id_variation, P.id_product -- , P.display_order - FROM Shop_Variation V - INNER JOIN tmp_Shop_Product t_P - ON V.id_product = t_P.id_product - WHERE V.active; - */ - - -- Product Images - INSERT INTO tmp_Shop_Image ( - id_product, - id_permutation, - id_image, - active, - display_order, - rank_in_product_permutation - ) - SELECT id_product, - id_permutation, - id_image, - active, - ROW_NUMBER() OVER (ORDER BY display_order_product_temp, display_order_image), - RANK() OVER (PARTITION BY id_product, id_permutation ORDER BY display_order_product_temp, display_order_image) - FROM ( - SELECT t_P.id_product, - I.id_permutation, - I.id_image, - I.active, - I.display_order AS display_order_image, - t_P.rank_permutation AS display_order_product_temp - FROM Shop_Image I - INNER JOIN tmp_Shop_Product t_P - ON I.id_product = t_P.id_product - AND NOT t_P.product_has_variations - UNION - SELECT t_P.id_product, - I.id_permutation, - I.id_image, - I.active, - I.display_order AS display_order_image, - t_P.rank_permutation AS display_order_product_temp - FROM Shop_Image I - INNER JOIN tmp_Shop_Product t_P - ON I.id_permutation = t_P.id_permutation - AND t_P.product_has_variations - ) IPP - WHERE - ( - v_get_all_image - OR v_get_first_image_only - -- OR FIND_IN_SET(id_image, v_ids_image) > 0 - OR IPP.id_image = ANY(v_ids_image) - ) - AND (v_get_inactive_image OR IPP.active) - ; - - IF v_get_first_image_only THEN - DELETE FROM tmp_Shop_Image - WHERE rank_in_product_permutation > 1 - ; - END IF; - - /* - IF v_has_filter_image THEN - DELETE FROM tmp_Shop_Product - WHERE id_product NOT IN (SELECT DISTINCT id_product FROM tmp_Shop_Image); - DELETE FROM tmp_Shop_Product_Category - WHERE id_category NOT IN (SELECT DISTINCT id_category FROM tmp_Shop_Product); - END IF; - */ - - -- Delivery Regions - INSERT INTO tmp_Delivery_Region ( - id_region, - active, - display_order, - requires_delivery_option - ) - WITH RECURSIVE Recursive_CTE_Delivery_Region AS ( - SELECT - CAST(NULL AS INTEGER) AS id_region_parent, - DR.id_region AS id_region_child, - -- CASE WHEN FIND_IN_SET(DR.id_region, v_ids_delivery_region) > 0 THEN TRUE ELSE FALSE END AS requires_delivery_option - (DR.id_region = ANY(v_ids_delivery_region)) AS requires_delivery_option - FROM Shop_Product_Currency_Region_Link PCRL - INNER JOIN Shop_Currency C ON PCRL.id_currency = C.id_currency - INNER JOIN tmp_Shop_Product t_P - ON PCRL.id_product = t_P.id_product - AND PCRL.id_permutation = t_P.id_permutation - INNER JOIN Shop_Region DR ON PCRL.id_region_purchase = DR.id_region - WHERE - ( - v_get_all_delivery_region - -- OR FIND_IN_SET(DR.id_region, v_ids_delivery_region) > 0 - OR DR.id_region = ANY(v_ids_delivery_region) - ) - AND ( - v_get_inactive_delivery_region - OR DR.active = TRUE - ) - UNION - SELECT - DRB.id_region_parent, - DRB.id_region_child, - FALSE AS requires_delivery_option - FROM Shop_Region_Branch DRB - INNER JOIN Recursive_CTE_Delivery_Region r_DR - ON DRB.id_region_parent = r_DR.id_region_child - WHERE ( - v_get_inactive_delivery_region - OR DRB.active = TRUE - ) - ) - SELECT - DR.id_region, - DR.active, - DR.display_order, - requires_delivery_option - FROM Shop_Region DR - INNER JOIN Recursive_CTE_Delivery_Region r_DR - ON DR.id_region = r_DR.id_region_parent - OR DR.id_region = r_DR.id_region_child - ; - /* - select * from tmp_delivery_region; - SELECT * - FROM tmp_Shop_Product t_P - WHERE - /*( - v_get_all_category - OR v_get_all_product - OR v_get_all_product_permutation - ) */ - FIND_IN_SET(t_P.id_category, v_ids_category) > 0 - OR FIND_IN_SET(t_P.id_product, v_ids_product) > 0 - OR FIND_IN_SET(t_P.id_permutation, v_ids_permutation) > 0 - ; - */ - - IF v_has_filter_delivery_region THEN - v_ids_permutation_unavailable = ( - SELECT STRING_AGG(t_P.id_permutation, ', ') - FROM ( - SELECT * - FROM tmp_Shop_Product t_P - WHERE - /*( - v_get_all_category - OR v_get_all_produc - OR v_get_all_product_permutation - ) - FIND_IN_SET(t_P.id_category, v_ids_category) > 0 - OR FIND_IN_SET(t_P.id_product, v_ids_product) > 0 - OR FIND_IN_SET(t_P.id_permutation, v_ids_permutation) > 0 - */ - t_P.id_category = ANY(v_ids_category) - OR t_P.id_product = ANY(v_ids_product) - OR t_P.id_permutation = ANY(v_ids_permutation) - ) t_P - LEFT JOIN ( - SELECT * - FROM Shop_Product_Currency_Region_Link PCRL - WHERE - v_get_all_delivery_region - -- OR FIND_IN_SET(PCRL.id_region_purchase, v_ids_delivery_region) > 0 - OR PCRL.id_region_purchase = ANY(v_ids_delivery_region) - ) PCRL - ON t_P.id_product = PCRL.id_product - AND t_P.id_permutation = PCRL.id_permutation - LEFT JOIN tmp_Delivery_Region t_DR - ON PCRL.id_region_purchase = t_DR.id_region - AND t_DR.requires_delivery_option - WHERE - ISNULL(t_DR.id_region) - ); - IF NOT ISNULL(v_ids_permutation_unavailable) THEN - /* - INSERT INTO tmp_Msg_Error ( - guid, - id_type, - code, - msg - ) - VALUES ( - v_guid, - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'PRODUCT_AVAILABILITY' LIMIT 1), - 'PRODUCT_AVAILABILITY', - 'Error: The following permutation IDs are not available in this region: ' || COALESCE(v_ids_permutation_unavailable, 'NULL') - ); - */ - RAISE EXCEPTION 'The following permutation IDs are not available in this region: %', COALESCE(v_ids_permutation_unavailable, 'NULL') - USING ERRCODE = '22000'; - END IF; - /* - DELETE FROM tmp_Shop_Product t_P - WHERE t_P.id_permutation NOT IN ( - SELECT - id_permutation - FROM Shop_Product_Currency_Region_Link PCL - INNER JOIN tmp_Delivery_Region t_DR - ON PCRL.id_region_purchase = t_DR.id_region - ); - */ - END IF; - - -- select * from tmp_Shop_Product; - - -- Currencies - INSERT INTO tmp_Currency ( - id_currency, - active, - display_order - ) - SELECT - C.id_currency, - C.active, - C.display_order - FROM Shop_Product_Currency_Region_Link PCRL - INNER JOIN Shop_Currency C ON PCRL.id_currency = C.id_currency - INNER JOIN tmp_Shop_Product t_P - ON PCRL.id_product = t_P.id_product - AND PCRL.id_permutation = t_P.id_permutation - INNER JOIN tmp_Delivery_Region t_DR ON PCRL.id_region_purchase = t_DR.id_region - WHERE - ( - v_get_all_currency - -- R FIND_IN_SET(C.id_currency, v_ids_currency) > 0 - OR C.id_currency = ANY(v_ids_currency) - ) - AND ( - v_get_inactive_currency - OR ( - C.active - AND PCRL.active - ) - ) - ; - - -- select * from tmp_Currency; - - IF v_has_filter_currency THEN - v_ids_permutation_unavailable = ( - SELECT STRING_AGG(t_P.id_permutation, ', ') - FROM ( - SELECT * - FROM tmp_Shop_Product t_P - WHERE - /*( - v_get_all_category - OR v_get_all_product - OR v_get_all_product_permutation - ) - FIND_IN_SET(t_P.id_category, v_ids_category) > 0 - OR FIND_IN_SET(t_P.id_product, v_ids_product) > 0 - OR FIND_IN_SET(t_P.id_permutation, v_ids_permutation) > 0 - */ - t_P.id_category = ANY(v_ids_category) - OR t_P.id_product = ANY(v_ids_product) - OR t_P.id_permutation = ANY(v_ids_permutation) - ) t_P - INNER JOIN ( - SELECT * - FROM Shop_Product_Currency_Region_Link PCRL - WHERE - ( - v_get_all_currency - -- OR FIND_IN_SET(PCRL.id_currency, v_ids_currency) > 0 - OR PCRL.id_currency = ANY(v_ids_currency) - ) - ) PCRL - ON t_P.id_permutation = PCRL.id_permutation - LEFT JOIN tmp_Currency t_C - ON PCRL.id_currency = t_C.id_currency - WHERE ISNULL(t_C.id_currency) - ); - IF NOT ISNULL(v_ids_permutation_unavailable) THEN - /* - INSERT INTO tmp_Msg_Error ( - guid, - id_type, - code, - msg - ) - VALUES ( - v_guid, - (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = 'PRODUCT_AVAILABILITY' LIMIT 1), - 'PRODUCT_AVAILABILITY', - 'Error: The following permutation IDs are not available in this currency: ' || COALESCE(v_ids_permutation_unavailable, 'NULL') - ); - */ - RAISE EXCEPTION 'The following permutation IDs are not available in this currency: %', COALESCE(v_ids_permutation_unavailable, 'NULL') - USING ERRCODE = '22000'; - END IF; - /* - DELETE FROM tmp_Shop_Product t_P - WHERE t_P.id_permutation NOT IN ( - SELECT - id_permutation - FROM Shop_Product_Currency_Region_Link PCL - INNER JOIN tmp_Currency t_C - ON PCRL.id_currency = t_C.id_currency - ); - */ - END IF; - - -- Discounts - INSERT INTO tmp_Discount ( - id_discount, - active, - display_order - ) - SELECT - D.id_discount, - D.active, - D.display_order - FROM Shop_Discount D - INNER JOIN tmp_Shop_Product t_P - ON D.id_product = t_P.id_product - AND D.id_permutation = t_P.id_permutation - WHERE - ( - v_get_all_discount - -- OR FIND_IN_SET(D.id_discount, v_ids_discount) > 0 - OR D.id_discount = ANY(v_ids_discount) - ) - AND ( - v_get_inactive_discount - OR D.active - ) - ; - -- select 'pre-permission results'; - -- select * from tmp_Shop_Product; - - -- Permissions - IF EXISTS (SELECT * FROM tmp_Shop_Product_Category LIMIT 1) THEN - -- v_id_user := (SELECT id_user FROM Shop_User WHERE name = CURRENT_USER); - v_id_permission_product := (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_PRODUCT' LIMIT 1); - v_ids_product_permission := (SELECT STRING_AGG(id_product, ',') FROM tmp_Shop_Product WHERE NOT ISNULL(id_product)); - -- v_ids_permutation_permission := (SELECT STRING_AGG(id_permutation, ',') FROM tmp_Shop_Product WHERE NOT ISNULL(id_permutation)); - - -- SELECT v_guid, v_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_product_permission; - -- select * from Shop_Calc_User_Temp; - - CALL p_shop_calc_user(v_guid, v_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_product_permission); - - -- select * from Shop_Calc_User_Temp; - - UPDATE tmp_Shop_Product t_P - SET t_P.can_view = UE_T.can_view, - t_P.can_edit = UE_T.can_edit, - t_P.can_admin = UE_T.can_admin - FROM tmp_Shop_Product t_P - INNER JOIN Shop_Calc_User_Temp UE_T - ON t_P.id_product = UE_T.id_product - AND UE_T.GUID = v_guid - ; - -- select * from Shop_Calc_User_Temp; - -- select * from tmp_Shop_Product; - - DELETE FROM tmp_Shop_Product t_P - WHERE - -- FIND_IN_SET(t_P.id_product, (SELECT STRING_AGG(UET.id_product, ',') FROM Shop_Calc_User_Temp UET)) = FALSE -- id_product NOT LIKE CONCAT('%', (SELECT STRING_AGG(id_product, '|') FROM Shop_Calc_User_Temp), '%'); - t_P.id_product NOT IN ( - SELECT id_product - FROM Shop_Calc_User_Temp UET - WHERE UET.GUID = v_guid - ) - OR ISNULL(t_P.can_view) - OR t_P.can_view = FALSE - ; - - -- CALL p_shop_clear_calc_user(v_guid); - -- DROP TABLE IF EXISTS Shop_Calc_User_Temp; - DELETE FROM Shop_Calc_User_Temp - WHERE GUID = v_guid - ; - END IF; - - - -- select * from tmp_Shop_Product; - - -- Returns - -- v_now := CURRENT_TIMESTAMP; - - -- Categories - OPEN result_categories FOR - -- RETURN QUERY - SELECT - DISTINCT t_C.id_category, - C.name, - C.description, - C.display_order - FROM tmp_Shop_Product_Category t_C - INNER JOIN Shop_Product_Category C - ON t_C.id_category = C.id_category - INNER JOIN tmp_Shop_Product t_P - ON t_C.id_category = t_P.id_category - ORDER BY C.display_order - ; - RETURN NEXT result_categories; - -- CLOSE result_categories; - - -- Products - OPEN result_products FOR - -- RETURN QUERY - SELECT - t_P.id_product, - t_P.id_permutation, - t_P.name, - t_P.description, - P.has_variations, - P.id_category, - PP.cost_local, - PP.id_currency_cost, - PP.profit_local_min, - t_P.latency_manufacture, - t_P.quantity_min, - t_P.quantity_max, - t_P.quantity_step, - t_P.quantity_stock, - t_P.id_stripe_product, - t_P.is_subscription, - RI.name AS name_interval_recurrence, - RI.name_plural AS name_plural_interval_recurrence, - t_P.count_interval_recurrence, - t_P.display_order_category, - t_P.display_order_product, - t_P.display_order_permutation, - COALESCE(t_P.can_view, FALSE), - COALESCE(t_P.can_edit, FALSE), - COALESCE(t_P.can_admin, FALSE) - FROM tmp_Shop_Product t_P - INNER JOIN Shop_Product P ON t_P.id_product = P.id_product - INNER JOIN Shop_Product_Permutation PP ON t_P.id_permutation = PP.id_permutation - LEFT JOIN Shop_Interval_Recurrence RI ON t_P.id_unit_measurement_interval_recurrence = RI.id_interval - ORDER BY t_P.rank_permutation - ; - RETURN NEXT result_products; - -- CLOSE result_products; - - -- Variations - OPEN result_variations FOR - -- RETURN QUERY - SELECT - V.id_variation, - t_P.id_product, - t_P.id_permutation, - t_P.id_category, - VT.code AS code_variation_type, - VT.name AS name_variation_type, - V.code AS code_variation, - V.name AS name_variation, - RANK() OVER (ORDER BY t_P.rank_permutation, PPVL.display_order) AS display_order - FROM Shop_Variation V - INNER JOIN Shop_Variation_Type VT - ON V.id_type = VT.id_type - INNER JOIN Shop_Product_Permutation_Variation_Link PPVL ON V.id_variation = PPVL.id_variation - INNER JOIN tmp_Shop_Product t_P ON PPVL.id_permutation = t_P.id_permutation - WHERE V.active - AND PPVL.active - ; - RETURN NEXT result_variations; - -- CLOSE result_variations; - - /* - -- Permutation variations output - SELECT t_P.id_permutation, - t_P.id_product, - t_P.id_category, - id_variation - FROM Shop_Product_Permutation_Variation_Link PPVL - INNER JOIN tmp_Shop_Product t_P - ON t_P.id_permutation = PPVL.id_permutation - ORDER BY t_P.display_order - ; - */ - -- select * from Shop_Product_Currency_Region_Link; - -- select * from shop_currency; - /* - select * from tmp_Currency; - select * from tmp_delivery_region; - select * from tmp_shop_product; - */ - - -- Product Price - OPEN result_prices FOR - -- RETURN QUERY - SELECT - PCRL.id_link AS id_price, - t_P.id_permutation, - t_P.id_product, - t_P.id_category, - t_C.id_currency, - C.code AS code_currency, - C.name AS name_currency, - C.symbol AS symbol_currency, - t_DR.id_region, - PCRL.price_local_VAT_incl, - PCRL.price_local_VAT_excl, - ROW_NUMBER() OVER(ORDER BY t_P.rank_permutation, C.display_order) AS display_order - FROM Shop_Product_Currency_Region_Link PCRL - INNER JOIN tmp_Shop_Product t_P - ON PCRL.id_product = t_P.id_product - AND PCRL.id_permutation = t_P.id_permutation - -- INNER JOIN Shop_Product P ON PCRL.id_product = P.id_product - INNER JOIN tmp_Currency t_C ON PCRL.id_currency = t_C.id_currency - INNER JOIN Shop_Currency C ON t_C.id_currency = C.id_currency - INNER JOIN tmp_Delivery_Region t_DR ON PCRL.id_region_purchase = t_DR.id_region - WHERE ( - v_get_inactive_product - AND v_get_inactive_permutation - AND v_get_inactive_currency - AND v_get_inactive_delivery_region - OR PCRL.active - ) - ORDER BY t_P.rank_permutation - ; - RETURN NEXT result_prices; - -- CLOSE result_prices; - - /* - -- Currency - SELECT - DISTINCT C.id_currency, - C.code, - C.name, - C.factor_from_GBP, - t_C.display_order - FROM Shop_Currency C - INNER JOIN tmp_Currency t_C ON C.id_currency = t_C.id_currency - GROUP BY C.id_currency, t_C.display_order - ORDER BY t_C.display_order - ; - */ - - -- Images - OPEN result_images FOR - -- RETURN QUERY - SELECT - t_I.id_image, - t_I.id_product, - t_I.id_permutation, - t_P.id_category, - I.url, - I.active, - I.display_order - FROM tmp_Shop_Image t_I - INNER JOIN Shop_Image I - ON t_I.id_image = I.id_image - INNER JOIN tmp_Shop_Product t_P - ON t_I.id_product = t_P.id_product - AND t_I.id_permutation = t_P.id_permutation - ORDER BY t_P.rank_permutation, I.display_order - ; - RETURN NEXT result_images; - -- CLOSE result_images; - - -- Delivery options - OPEN result_delivery_options FOR - -- RETURN QUERY - SELECT - _DO.id_option, - PDOL.id_product, - PDOL.id_permutation, - t_P.id_category, - _DO.code, - _DO.name, - _DO.latency_delivery_min, - _DO.latency_delivery_max, - _DO.quantity_min, - _DO.quantity_max, - STRING_AGG(DR.code, ',') AS codes_region, - STRING_AGG(DR.name, ',') AS names_region, - PDOL.price_local, - PDOL.display_order - FROM Shop_Delivery_Option _DO - INNER JOIN Shop_Product_Permutation_Delivery_Option_Link PDOL - ON _DO.id_option = PDOL.id_delivery_option - AND ( - v_get_inactive_delivery_region - OR PDOL.active - ) - INNER JOIN tmp_Shop_Product t_P - ON PDOL.id_product = t_P.id_product - AND PDOL.id_permutation = t_P.id_permutation - INNER JOIN tmp_Delivery_Region t_DR ON PDOL.id_region = t_DR.id_region - INNER JOIN Shop_Region DR ON t_DR.id_region = DR.id_region - WHERE ( - v_get_inactive_delivery_region - OR _DO.active - ) - GROUP BY t_P.id_category, t_P.id_product, PDOL.id_permutation, t_P.rank_permutation, DR.id_region, _DO.id_option, PDOL.id_link - ORDER BY t_P.rank_permutation, PDOL.display_order - ; - RETURN NEXT result_delivery_options; - -- CLOSE result_delivery_options; - - -- Discounts - OPEN result_discounts FOR - -- RETURN QUERY - SELECT - D.id_discount, - P.id_category, - D.id_product, - D.id_permutation, - DR.id_region, - C.id_currency, - D.code AS code_discount, - D.name AS name_discount, - D.multiplier, - D.subtractor, - D.apply_multiplier_first, - D.quantity_min, - D.quantity_max, - D.date_start, - D.date_end, - STRING_AGG(DR.code, ', ') OVER(PARTITION BY D.id_discount) AS codes_region, - STRING_AGG(DR.name, ', ') OVER(PARTITION BY D.id_discount) AS names_region, - STRING_AGG(C.code, ', ') OVER(PARTITION BY D.id_discount) AS codes_currency, - STRING_AGG(C.name, ', ') OVER(PARTITION BY D.id_discount) AS names_currency, - ROW_NUMBER() OVER(ORDER BY D.display_order) AS display_order - FROM tmp_Discount t_D - INNER JOIN Shop_Discount D ON t_D.id_discount = D.id_discount - INNER JOIN Shop_Product P ON D.id_product = P.id_product - INNER JOIN tmp_Shop_Product t_P - ON D.id_product = t_P.id_product - -- AND D.id_permutation = t_P.id_permutation - INNER JOIN Shop_Discount_Region_Currency_Link DRCL - ON D.id_discount = DRCL.id_discount - INNER JOIN tmp_Delivery_Region t_DR ON DRCL.id_region = t_DR.id_region - INNER JOIN Shop_Region DR ON t_DR.id_region = DR.id_region - INNER JOIN tmp_Currency t_C ON DRCL.id_currency = t_C.id_currency - INNER JOIN Shop_Currency C ON t_C.id_currency = C.id_currency - GROUP BY D.id_discount, DR.id_region, C.id_currency, P.id_category, P.id_product, D.id_permutation - ORDER BY D.display_order, DR.display_order, C.display_order - ; - RETURN NEXT result_discounts; - -- CLOSE result_discounts; - /* - -- Delivery Regions - SELECT - t_DR.id_region, - t_P.id_category, - t_P.id_product, - t_P.id_permutation, - DR.code, - DR.name - FROM tmp_Delivery_Region t_DR - INNER JOIN Shop_Delivery_Region DR ON t_DR.id_region = DR.id_region - INNER JOIN Shop_Product_Region_Currency_Link PDRL - ON DR.id_region = PDRL.id_region - AND ( - v_get_inactive_delivery_region - OR PDRL.active - ) - INNER JOIN tmp_Shop_Product t_P - ON PDRL.id_product = t_P.id_product - AND PDRL.id_permutation = t_P.id_permutation - INNER JOIN tmp_Currency t_C ON PDRL.id_currency = t_C.id_currency - ORDER BY t_DR.display_order - ; - */ - - -- Errors - /* - OPEN result_errors FOR - RETURN QUERY - SELECT - t_ME.display_order, - t_ME.guid, - t_ME.id_type, - t_ME.msg, - MET.code, - MET.name, - MET.description - FROM tmp_Msg_Error t_ME - INNER JOIN Shop_Msg_Error_Type MET - ON t_ME.id_type = MET.id_type - WHERE guid = v_guid - ; - RETURN NEXT result_errors; - */ - - /* - -- Return arguments for test - SELECT - v_ids_category, - v_get_inactive_category, - v_ids_product, - v_get_inactive_product, - v_get_first_product_only, - v_get_all_product, - v_ids_image, - v_get_inactive_image, - v_get_first_image_only, - v_get_all_image - ; - */ - - -- select 'other outputs'; - -- select * from tmp_Shop_Product; - - -- Clean up - /* - DROP TEMPORARY TABLE IF EXISTS tmp_Discount; - DROP TEMPORARY TABLE IF EXISTS tmp_Currency; - DROP TEMPORARY TABLE IF EXISTS tmp_Delivery_Region; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Image; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Variation; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Product; - DROP TEMPORARY TABLE IF EXISTS tmp_Shop_Product_Category; - DROP TABLE IF EXISTS tmp_Discount; - DROP TABLE IF EXISTS tmp_Currency; - DROP TABLE IF EXISTS tmp_Delivery_Region; - DROP TABLE IF EXISTS tmp_Shop_Image; - DROP TABLE IF EXISTS tmp_Shop_Variation; - DROP TABLE IF EXISTS tmp_Shop_Product; - DROP TABLE IF EXISTS tmp_Shop_Product_Category; - */ -END; -$$ LANGUAGE plpgsql; - - -/* - -DROP FUNCTION IF EXISTS fetch_results; - -CREATE OR REPLACE FUNCTION fetch_results() -RETURNS VOID AS $$ -DECLARE - curs refcursor; - rec record; - curs1 refcursor; - rec1 record; - curs2 refcursor; - rec2 record; -BEGIN - FOR curs IN SELECT p_shop_get_many_product ( - 1, -- a_id_user - TRUE, -- a_get_all_category - FALSE, -- a_get_inactive_category - FALSE, -- a_get_first_category_only - ARRAY[]::INTEGER[], -- a_ids_category - TRUE, -- a_get_all_product - FALSE, -- a_get_inactive_product - FALSE, -- a_get_first_product_only - ARRAY[]::INTEGER[], -- a_ids_product - TRUE, -- a_get_all_product_permutation - FALSE, -- a_get_inactive_permutation - FALSE, -- a_get_first_permutation_only - ARRAY[1, 2, 3, 4, 5]::INTEGER[], -- a_ids_permutation - FALSE, -- a_get_all_image - FALSE, -- a_get_inactive_image - TRUE, -- a_get_first_image_only - ARRAY[]::INTEGER[], -- a_ids_image - FALSE, -- a_get_all_delivery_region - FALSE, -- a_get_inactive_delivery_region - ARRAY[]::INTEGER[], -- a_ids_delivery_region - FALSE, -- a_get_all_currency - FALSE, -- a_get_inactive_currency - ARRAY[]::INTEGER[], -- a_ids_currency - TRUE, -- a_get_all_discount - FALSE, -- a_get_inactive_discount - ARRAY[]::INTEGER[] -- a_ids_discount - ) LOOP - RAISE NOTICE 'Fetching from cursor: %', curs; - LOOP - FETCH curs INTO rec; - EXIT WHEN NOT FOUND; - RAISE NOTICE 'Record: %', rec; - END LOOP; - END LOOP; -END; -$$ LANGUAGE plpgsql; - -SELECT fetch_results(); - -*/ diff --git a/static/PostgreSQL/701_p_shop_get_many_role_permission.sql b/static/PostgreSQL/701_p_shop_get_many_role_permission.sql deleted file mode 100644 index 27141e79..00000000 --- a/static/PostgreSQL/701_p_shop_get_many_role_permission.sql +++ /dev/null @@ -1,152 +0,0 @@ - -/* -DROP TABLE IF EXISTS tmp_Shop_Image; -DROP TABLE IF EXISTS tmp_Shop_Product; -DROP TABLE IF EXISTS tmp_Shop_Variation; -DROP TABLE IF EXISTS tmp_Shop_Product_Category; - -CREATE OR REPLACE PROCEDURE p_shop_get_many_role_permission ( - a_ids_role VARCHAR(4000), - a_get_inactive_roles BOOLEAN -) -AS $$ -DECLARE - v_ids_role VARCHAR(4000); - v_get_inactive_roles BOOLEAN; - v_has_filter_role BOOLEAN; - v_priority_view INTEGER; - v_priority_edit INTEGER; - v_priority_admin INTEGER; -BEGIN - v_ids_role := TRIM(COALESCE(a_ids_role, '')); - v_get_inactive_roles := COALESCE(a_get_inactive_roles, FALSE); - - -- v_ids_role = REPLACE(v_ids_role, '|', ',`'); - v_has_filter_role = CASE WHEN v_ids_role = '' THEN FALSE ELSE TRUE END; - - - -- Temporary tables - CREATE TABLE tmp_Permission ( - id_role INTEGER NOT NULL, - CONSTRAINT FK_tmp_User_Permission_id_role - FOREIGN KEY (id_role) - REFERENCES Shop_Role(id_role), - id_permission INTEGER, - CONSTRAINT FK_tmp_User_Permission_id_permission - FOREIGN KEY (id_permission) - REFERENCES Shop_Permission(id_permission), - id_access_level INTEGER, - CONSTRAINT FK_tmp_User_Permission_id_access_level - FOREIGN KEY (id_user) - REFERENCES Shop_Access_Level(id_user), - can_view BOOLEAN, - can_edit BOOLEAN, - can_admin BIT - ); - - - INSERT INTO tmp_User_Permission ( - id_role, - id_permission, - id_access_level, - can_view, - can_edit, - can_admin - ) - SELECT U.id_user, - U.is_super_user, - U.is_super_user, - U.is_super_user, - U.is_super_user - FROM Shop_Role R - INNER JOIN Shop_Role_Permission_Link RPL - ON R.id_role = RPL.id_role - AND RPL.active - INNER JOIN Shop_Permission PERM - ON RPL.id_permission = PERM.id_permission - AND PERM.active - INNER JOIN Shop_Permission_Group PG - ON PERM.id_permission_group = PG.id_group - AND PG.active - LEFT JOIN Shop_Access_Level AL - ON RPL.id_access_level = AL.id_access_level - AND AL.active - WHERE FIND_IN_SET(R.id_role, v_ids_role) > 0 - AND PERM.required_access_level = FALSE OR AL. - ; - - UPDATE tmp_User_Permission t_UP - INNER JOIN Shop_Access_Level AL - ON AL.code = 'ADMIN' - SET t_UP.id_access_level = AL.id_access_level - WHERE t_UP.is_super_user - ; - - - -- Clean up - DROP TABLE IF EXISTS tmp_Shop_Product_Category; - DROP TABLE IF EXISTS tmp_Shop_Product; - DROP TABLE IF EXISTS tmp_Shop_Image; -END; -$$ LANGUAGE plpgsql; -*/ - - -/* - -DROP FUNCTION IF EXISTS fetch_results; - -CREATE OR REPLACE FUNCTION fetch_results() -RETURNS VOID AS $$ -DECLARE - curs refcursor; - rec record; - curs1 refcursor; - rec1 record; - curs2 refcursor; - rec2 record; -BEGIN - FOR curs IN SELECT p_shop_get_many_product ( - 1, -- a_id_user - TRUE, -- a_get_all_category - FALSE, -- a_get_inactive_category - FALSE, -- a_get_first_category_only - ARRAY[]::INTEGER[], -- a_ids_category - TRUE, -- a_get_all_product - FALSE, -- a_get_inactive_product - FALSE, -- a_get_first_product_only - ARRAY[]::INTEGER[], -- a_ids_product - TRUE, -- a_get_all_product_permutation - FALSE, -- a_get_inactive_permutation - FALSE, -- a_get_first_permutation_only - ARRAY[1, 2, 3, 4, 5]::INTEGER[], -- a_ids_permutation - FALSE, -- a_get_all_image - FALSE, -- a_get_inactive_image - TRUE, -- a_get_first_image_only - ARRAY[]::INTEGER[], -- a_ids_image - FALSE, -- a_get_all_delivery_region - FALSE, -- a_get_inactive_delivery_region - ARRAY[]::INTEGER[], -- a_ids_delivery_region - FALSE, -- a_get_all_currency - FALSE, -- a_get_inactive_currency - ARRAY[]::INTEGER[], -- a_ids_currency - TRUE, -- a_get_all_discount - FALSE, -- a_get_inactive_discount - ARRAY[]::INTEGER[] -- a_ids_discount - CURS1, - CURS2 - ) LOOP - RAISE NOTICE 'Fetching from cursor: %', curs; - LOOP - FETCH curs INTO rec; - EXIT WHEN NOT FOUND; - RAISE NOTICE 'Record: %', rec; - END LOOP; - END LOOP; -END; -$$ LANGUAGE plpgsql; - -SELECT fetch_results(); - -*/ - diff --git a/static/PostgreSQL/702.1_p_shop_get_many_currency.sql b/static/PostgreSQL/702.1_p_shop_get_many_currency.sql deleted file mode 100644 index ba8a9a43..00000000 --- a/static/PostgreSQL/702.1_p_shop_get_many_currency.sql +++ /dev/null @@ -1,57 +0,0 @@ - - -CREATE OR REPLACE FUNCTION p_shop_get_many_currency ( - IN a_get_inactive_currency BOOLEAN -) -RETURNS SETOF REFCURSOR -AS $$ -DECLARE - v_get_inactive_currency BOOLEAN; - result_currency REFCURSOR; -BEGIN - v_get_inactive_currency := COALESCE(a_get_inactive_currency, FALSE); - - OPEN result_currency FOR - SELECT - C.id_currency, - C.code, - C.name, - C.factor_from_GBP, - C.active, - C.display_order - FROM Shop_Currency C - WHERE v_get_inactive_currency - OR C.active - ORDER BY C.display_order - ; - RETURN NEXT result_currency; -END; -$$ LANGUAGE plpgsql; - - -/* - -DROP FUNCTION IF EXISTS fetch_results; - -CREATE OR REPLACE FUNCTION fetch_results() -RETURNS VOID AS $$ -DECLARE - curs refcursor; - rec record; -BEGIN - FOR curs IN SELECT p_shop_get_many_currency ( - FALSE -- a_get_inactive_currency - ) LOOP - RAISE NOTICE 'Fetching from cursor: %', curs; - LOOP - FETCH curs INTO rec; - EXIT WHEN NOT FOUND; - RAISE NOTICE 'Record: %', rec; - END LOOP; - END LOOP; -END; -$$ LANGUAGE plpgsql; - -SELECT fetch_results(); - -*/ diff --git a/static/PostgreSQL/702.2_p_shop_get_many_region.sql b/static/PostgreSQL/702.2_p_shop_get_many_region.sql deleted file mode 100644 index 62202b1a..00000000 --- a/static/PostgreSQL/702.2_p_shop_get_many_region.sql +++ /dev/null @@ -1,60 +0,0 @@ - - -CREATE OR REPLACE FUNCTION p_shop_get_many_region ( - IN a_get_inactive_region BOOLEAN -) -RETURNS SETOF REFCURSOR -AS $$ -DECLARE - v_get_inactive_region BOOLEAN; - result_region REFCURSOR; -BEGIN - v_get_inactive_region := COALESCE(a_get_inactive_region, FALSE); - - OPEN result_region FOR - SELECT - R.id_region, - R.code, - R.name, - R.active, - R.display_order - FROM Shop_Region R - WHERE v_get_inactive_region - OR R.active - ORDER BY R.display_order - ; - -- RETURN NEXT result_region; -END; -$$ LANGUAGE plpgsql; - - -/* - -DROP FUNCTION IF EXISTS fetch_results; - -CREATE OR REPLACE FUNCTION fetch_results() -RETURNS VOID AS $$ -DECLARE - curs refcursor; - rec record; - curs1 refcursor; - rec1 record; - curs2 refcursor; - rec2 record; -BEGIN - FOR curs IN SELECT p_shop_get_many_region ( - FALSE -- a_get_inactive_region - ) LOOP - RAISE NOTICE 'Fetching from cursor: %', curs; - LOOP - FETCH curs INTO rec; - EXIT WHEN NOT FOUND; - RAISE NOTICE 'Record: %', rec; - END LOOP; - END LOOP; -END; -$$ LANGUAGE plpgsql; - -SELECT fetch_results(); - -*/ diff --git a/static/PostgreSQL/703_p_shop_get_many_user_order.sql b/static/PostgreSQL/703_p_shop_get_many_user_order.sql deleted file mode 100644 index 8604c138..00000000 --- a/static/PostgreSQL/703_p_shop_get_many_user_order.sql +++ /dev/null @@ -1,283 +0,0 @@ - - -CREATE OR REPLACE FUNCTION p_shop_get_many_user_order ( - IN a_id_user INTEGER, - IN a_ids_order VARCHAR(4000), - IN a_n_order_max INTEGER, - IN a_id_checkout_session VARCHAR(200) -) -RETURNS SETOF REFCURSOR -AS $$ -DECLARE - v_id_user INTEGER; - v_ids_order VARCHAR(4000); - v_n_order_max INTEGER; - v_id_checkout_session VARCHAR(200); - v_has_filter_user BOOLEAN; - v_has_filter_order BOOLEAN; - v_has_filter_session BOOLEAN; - v_code_error_data VARCHAR(200); - v_code_error_permission VARCHAR(200); - v_guid UUID; - result_orders REFCURSOR; - -- result_errors REFCURSOR; -BEGIN - v_id_user := TRIM(COALESCE(a_id_user, '')); - v_ids_order := TRIM(COALESCE(a_ids_order, '')); - v_n_order_max := a_n_order_max; - v_id_checkout_session := TRIM(COALESCE(a_id_checkout_session, '')); - - v_code_error_data := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 1); - v_code_error_permission := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 2); - v_guid = gen_random_uuid(); - - v_has_filter_user = CASE WHEN v_id_user = '' THEN FALSE ELSE TRUE END; - v_ids_order = REPLACE(v_ids_order, '|', ','); - v_has_filter_order = CASE WHEN v_ids_order = '' THEN FALSE ELSE TRUE END; - v_has_filter_session = CASE WHEN v_id_checkout_session = '' THEN FALSE ELSE TRUE END; - - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Shop_User; - DROP TABLE IF EXISTS tmp_Shop_Order; - - /* - CREATE TABLE tmp_Shop_User( - id_user INTEGER PRIMARY KEY, - CONSTRAINT FK_tmp_Shop_User_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user), - active BOOLEAN NOT NULL - ); - */ - - CREATE TEMPORARY TABLE tmp_Shop_Order ( - id_order INTEGER NOT NULL PRIMARY KEY, - CONSTRAINT FK_tmp_Shop_Order_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_User_Order(id_order), - active BOOLEAN NOT NULL - ); - - /* - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - guid UUID NOT NULL, - -- id_type INTEGER NOT NULL, - -- CONSTRAINT FK_tmp_Msg_Error_id_type FOREIGN KEY (id_type) - -- REFERENCES Shop_Msg_Error_Type (id_type), - code VARCHAR(50), - msg VARCHAR(4000) NOT NULL - ); - */ - - -- User - IF v_has_filter_user THEN - INSERT INTO tmp_Shop_User ( - id_user, - active - ) - SELECT id_user, - active - FROM Shop_User - WHERE id_user = v_id_user - AND active - LIMIT 1 - ; - - v_has_filter_user = EXISTS (SELECT id_user FROM tmp_Shop_User LIMIT 1); - v_id_user := (SELECT id_user FROM tmp_Shop_User LIMIT 1); - ELSE - RAISE EXCEPTION 'Valid user ID must be provided.' - USING ERRCODE = '22000' - ; - END IF; - - -- Permissions - CALL p_shop_calc_user ( - v_guid, -- a_guid - a_id_user, -- a_id_user - 0, -- a_get_inactive_users - CONVERT((SELECT id_permission FROM Shop_Permission WHERE 'STORE_USER' = code), CHAR), -- a_ids_permission - (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW' AND active), -- a_ids_access_level - '', -- a_ids_product - '' -- a_ids_permutation - ); - - IF NOT (SELECT can_edit FROM Shop_Calc_User_Temp WHERE guid = v_guid) THEN - RAISE EXCEPTION 'User ID does not have permission to access orders.' - USING ERRCODE = '42501' - ; - END IF; - - DELETE FROM Shop_Calc_User_Temp - WHERE guid = v_guid - ; - - -- Invalid Order IDs - IF v_has_filter_order AND EXISTS ( - SELECT * - FROM Shop_User_Order - WHERE - NOT (id_user = v_id_user) - AND id_order = ANY(v_ids_order) - LIMIT 1 - ) THEN -- id_order LIKE CONCAT('%', v_ids_order, '%') LIMIT 1) THEN - RAISE EXCEPTION 'You do not have access to the following order IDs: %', ( - SELECT STRING_AGG(id_order, ', ') - FROM Shop_User_Order - WHERE - NOT (id_user = v_id_user) - AND id_order = ANY(v_ids_order) - ) - USING ERRCODE = '22000' - ; - END IF; - -- Invalid Checkout Session IDs - IF v_has_filter_session AND EXISTS ( - SELECT * - FROM Shop_User_Order - WHERE - NOT (id_user = v_id_user) - AND id_checkout_session = v_id_checkout_session - ) THEN - RAISE EXCEPTION 'You do not have access to the following checkout session IDs: %', ( - SELECT STRING_AGG(id_order, ', ') - FROM Shop_User_Order - WHERE - NOT (id_user = v_id_user) - AND id_checkout_session = v_id_checkout_session - ) - USING ERRCODE = '22000' - ; - END IF; - - -- Valid Orders - IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - - INSERT INTO tmp_Shop_Order ( - id_order, - active - ) - SELECT UO.id_order, - UO.active - FROM Shop_User_Order UO - INNER JOIN tmp_Shop_User t_U - ON UO.id_user = t_U.id_user - AND t_U.active - WHERE ((NOT v_has_filter_order OR FIND_IN_SET(UO.id_order, v_ids_order) > 0) -- UO.id_order LIKE CONCAT('%', v_ids_order, '%')) - OR (NOT v_has_filter_session OR UO.id_checkout_session = v_id_checkout_session)) - AND UO.active - ; - END IF; - - - - -- Returns - /* - SELECT * - FROM tmp_Shop_User - ; - */ - - OPEN result_orders FOR - SELECT t_O.id_order, - UOPL.id_product, - UOPL.id_permutation, - UOPL.quantity - FROM tmp_Shop_Order t_O - INNER JOIN Shop_User_Order UO - ON t_O.id_order = UO.id_order - INNER JOIN Shop_User_Order_Product_Link UOPL - ON UO.id_order = UOPL.id_order - WHERE t_O.active - ; - RETURN NEXT result_orders; - - /* - -- Errors - OPEN result_errors FOR - SELECT * - FROM tmp_Msg_Error - ; - -- RETURN NEXT result_errors; - */ - - - /* - -- Return arguments for test - SELECT - v_id_user, - v_ids_order, - v_n_order_max, - v_id_checkout_session - ; - */ - - -- Clean up - -- DROP TABLE IF EXISTS tmp_Shop_User; - -- DROP TABLE IF EXISTS tmp_Shop_Order; -END; -$$ LANGUAGE plpgsql; - - -/* - -DROP FUNCTION IF EXISTS fetch_results; - -CREATE OR REPLACE FUNCTION fetch_results() -RETURNS VOID AS $$ -DECLARE - curs refcursor; - rec record; - curs1 refcursor; - rec1 record; - curs2 refcursor; - rec2 record; -BEGIN - FOR curs IN SELECT p_shop_get_many_user_order ( - 'auth0|6582b95c895d09a70ba10fef', # a_id_user - '1', # a_ids_order - 0, # a_n_order_max - '' # a_id_checkout_session - ) LOOP - RAISE NOTICE 'Fetching from cursor: %', curs; - LOOP - FETCH curs INTO rec; - EXIT WHEN NOT FOUND; - RAISE NOTICE 'Record: %', rec; - END LOOP; - END LOOP; -END; -$$ LANGUAGE plpgsql; - -SELECT fetch_results(); - -*/ - - -/* - -CALL p_shop_get_many_user_order ( - 'auth0|6582b95c895d09a70ba10fef', # a_id_user - '1', # a_ids_order - 0, # a_n_order_max - '' # a_id_checkout_session -); - -CALL p_shop_get_many_user_order ( - '', # a_id_user - '1', # a_ids_order - 0, # a_n_order_max - '' # a_id_checkout_session -); - -insert into shop_product_change_set (comment) - values ('set product not subscription - test bool output to python'); - update shop_product - set is_subscription = 0, - id_change_set = (select id_change_set from shop_product_change_set order by id_change_set desc limit 1) - where id_product = 1 -select * from shop_User; -select * from shop_User_oRDER; -*/ diff --git a/static/PostgreSQL/704_p_shop_get_many_stripe_product_new.sql b/static/PostgreSQL/704_p_shop_get_many_stripe_product_new.sql deleted file mode 100644 index 2b7330ea..00000000 --- a/static/PostgreSQL/704_p_shop_get_many_stripe_product_new.sql +++ /dev/null @@ -1,316 +0,0 @@ - - -/* - -CALL p_shop_get_many_stripe_product_new ( - '' -) - -*/ - -CREATE OR REPLACE FUNCTION p_shop_get_many_stripe_product_new ( - IN a_id_user INTEGER -) -RETURNS SETOF REFCURSOR -AS $$ -DECLARE - v_id_user INTEGER; - v_code_error_data VARCHAR(200); - v_code_error_permission VARCHAR(200); - v_guid UUID; - result_products REFCURSOR; - result_product_variation_links REFCURSOR; - -- result_errors REFCURSOR; -BEGIN - v_id_user := a_id_user; - v_code_error_data := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 1); - v_code_error_permission := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 2); - v_guid = gen_random_uuid(); - - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Shop_Product; - DROP TABLE IF EXISTS tmp_Shop_User; - - CREATE TEMPORARY TABLE tmp_Shop_User( - id_user INTEGER PRIMARY KEY, - CONSTRAINT FK_tmp_Shop_User_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user), - active BOOLEAN NOT NULL - ); - - CREATE TEMPORARY TABLE tmp_Shop_Product ( - id_product INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - id_permutation INTEGER NULL, - CONSTRAINT FK_tmp_Shop_Product_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - active BOOLEAN NOT NULL, - display_order_product INTEGER NOT NULL, - display_order_permutation INTEGER NOT NULL, - name VARCHAR(200) NOT NULL, - description VARCHAR(4000) NOT NULL - ); - - /* - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( -- IF NOT EXISTS - display_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - guid UUID NOT NULL, - code VARCHAR(50) NOT NULL, - -- CONSTRAINT chk_tmp_Msg_Error_code CHECK (code IN (SELECT code FROM Shop_Msg_Error_Type)), - /* - id_type INTEGER NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type(id_type), - */ - msg VARCHAR(4000) NOT NULL - ); - */ - - - -- User - IF NOT EXISTS( - SELECT * - FROM Shop_User - WHERE - id_user = v_id_user - AND active - ) THEN - RAISE EXCEPTION 'Valid user ID required.' - USING ERRCODE = '22000' - ; - END IF; - - INSERT INTO tmp_Shop_User ( - id_user, - active - ) - SELECT id_user, - active - FROM Shop_User - WHERE id_user = v_id_user - AND active - LIMIT 1 - ; - - -- Get products - INSERT INTO tmp_Shop_Product ( - id_product, - id_permutation, - active, - display_order_product, - display_order_permutation, - name, - description - ) - SELECT id_product, - id_permutation, - active, - display_order_product, - display_order_permutation, - name, - description - FROM ( - SELECT id_product, - NULL AS id_permutation, - active, - display_order AS display_order_product, - NULL AS display_order_permutation, - name, - description, - id_stripe_product - FROM Shop_Product P - UNION - SELECT t_PPPV.id_product, - id_permutation, - t_PPPV.active, - display_order_product, - display_order_permutation, - P.name, ': ' || names_variation AS name, - P.description || ' With variations: ' || type_name_pairs_variation AS description, - t_PPPV.id_stripe_product - FROM ( - SELECT P.id_product, - PP.id_permutation, - PP.active, - P.display_order AS display_order_product, - PP.display_order AS display_order_permutation, - STRING_AGG(V.name, ' ') AS names_variation, - STRING_AGG(VT.name || ': ' || V.name, ', ') AS type_name_pairs_variation, - PP.id_stripe_product - FROM Shop_Product_Permutation PP - INNER JOIN Shop_Product P - ON PP.id_product = P.id_product - AND P.active - INNER JOIN Shop_Product_Permutation_Variation_Link PPVL - ON PP.id_permutation = PPVL.id_permutation - AND PPVL.active - INNER JOIN Shop_Variation V - ON PPVL.id_variation = V.id_variation - AND V.active - INNER JOIN Shop_Variation_Type VT - ON V.id_type = VT.id_type - AND VT.active - GROUP BY id_product, id_permutation -- , VT.id_type, V.id_variation - ) t_PPPV - INNER JOIN Shop_Product P - ON t_PPPV.id_product = P.id_product - ) t_PPP - WHERE ISNULL(id_stripe_product) - AND active - ; - - -- Permissions - CALL p_shop_calc_user ( - v_guid, -- a_guid - v_id_user, -- a_id_user - 0, -- a_get_inactive_users - CONVERT((SELECT id_permission FROM Shop_Permission WHERE 'STORE_ADMIN' = code), CHAR), -- a_ids_permission - (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'ADMIN' AND active), -- a_ids_access_level - (SELECT STRING_AGG(id_product, ',') From tmp_Shop_Product), -- a_ids_product - (SELECT STRING_AGG(id_permutation, ',') From tmp_Shop_Product) -- a_ids_permutation -- WHERE NOT ISNULL(id_permutation) - ); - - IF EXISTS (SELECT can_admin FROM Shop_Calc_User_Temp WHERE guid = v_guid AND NOT can_admin) THEN - RAISE EXCEPTION 'User ID does not have permission to get all new stripe products.' - USING ERRCODE = '42501' - ; - END IF; - - DELETE FROM Shop_Calc_User_Temp - WHERE guid = v_guid - ; - - - - - -- Returns - /* - SELECT * - FROM tmp_Shop_User - ; - */ - - /* - IF EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - DELETE FROM tmp_Shop_Product; - END IF; - */ - - OPEN result_products FOR - SELECT id_product, - id_permutation, - name, - description - FROM tmp_Shop_Product - ORDER BY display_order_product, display_order_permutation - ; - RETURN NEXT result_products; - - OPEN result_product_variation_links FOR - SELECT PP.id_permutation, - V.id_variation, - V.name AS name_variation, - VT.id_type AS id_type_variation, - VT.name as name_variation_type - FROM tmp_Shop_Product t_P - INNER JOIN Shop_Product_Permutation PP - ON t_P.id_permutation = PP.id_permutation - INNER JOIN Shop_Product_Permutation_Variation_Link PPVL - ON PP.id_permutation = PPVL.id_permutation - AND PPVL.active - INNER JOIN Shop_Variation V - ON PPVL.id_variation = V.id_variation - AND V.active - INNER JOIN Shop_Variation_Type VT - ON V.id_type = VT.id_type - AND VT.active - ; - RETURN NEXT result_product_variation_links; - - -- Errors - /* - OPEN result_errors FOR - SELECT * - FROM tmp_Msg_Error - ; - -- RETURN NEXT result_errors; - */ - - - /* - -- Return arguments for test - SELECT - v_id_user - ; - */ - - -- Clean up - DROP TABLE IF EXISTS tmp_Shop_Product; - DROP TABLE IF EXISTS tmp_Shop_User; -END; -$$ LANGUAGE plpgsql; - - -/* - -DROP FUNCTION IF EXISTS fetch_results; - -CREATE OR REPLACE FUNCTION fetch_results() -RETURNS VOID AS $$ -DECLARE - curs refcursor; - rec record; - curs1 refcursor; - rec1 record; - curs2 refcursor; - rec2 record; -BEGIN - FOR curs IN SELECT p_shop_get_many_stripe_product_new ( - 'auth0|6582b95c895d09a70ba10fef' - ) LOOP - RAISE NOTICE 'Fetching from cursor: %', curs; - LOOP - FETCH curs INTO rec; - EXIT WHEN NOT FOUND; - RAISE NOTICE 'Record: %', rec; - END LOOP; - END LOOP; -END; -$$ LANGUAGE plpgsql; - -SELECT fetch_results(); - -*/ - - -/* -CALL p_shop_get_many_stripe_product_new ( - '' -); - -CALL p_shop_get_many_stripe_product_new ( - 'auth0|6582b95c895d09a70ba10fef' -); - - - -select * from shop_product; -select * from shop_product_permutation_variation_link; - -CALL p_shop_calc_user ( - 'ead789a1-c7ac-11ee-a256-b42e9986184a', -- a_guid - 'auth0|6582b95c895d09a70ba10fef', -- a_id_user - 0, -- a_get_inactive_users - '4', -- a_ids_permission - '3', -- a_ids_access_level - '1', -- a_ids_product - '1' -- a_ids_permutation -- WHERE NOT ISNULL(id_permutation) - ); - -*/ diff --git a/static/PostgreSQL/705_p_shop_get_many_stripe_price_new.sql b/static/PostgreSQL/705_p_shop_get_many_stripe_price_new.sql deleted file mode 100644 index a85fafd3..00000000 --- a/static/PostgreSQL/705_p_shop_get_many_stripe_price_new.sql +++ /dev/null @@ -1,253 +0,0 @@ - - - -/* - -CALL p_shop_get_many_stripe_price_new ( - '' -) - -*/ - - - -CREATE OR REPLACE FUNCTION p_shop_get_many_stripe_price_new ( - IN a_id_user INTEGER -) -RETURNS SETOF REFCURSOR -AS $$ -DECLARE - v_id_user INTEGER; - v_has_filter_user BOOLEAN; - v_code_error_data VARCHAR(200); - v_code_error_permission VARCHAR(200); - v_guid UUID; - result_products REFCURSOR; - -- result_errors REFCURSOR; -BEGIN - v_id_user := TRIM(COALESCE(a_id_user, '')); - v_code_error_data := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 1); - v_code_error_permission := (SELECT code FROM Shop_Msg_Error_Type WHERE id_type = 2); - v_guid = gen_random_uuid(); - - v_has_filter_user = CASE WHEN v_id_user = '' THEN FALSE ELSE TRUE END; - - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Shop_Product_Currency_Link; - DROP TABLE IF EXISTS tmp_Shop_User; - - CREATE TEMPORARY TABLE tmp_Shop_User( - id_user INTEGER PRIMARY KEY, - CONSTRAINT FK_tmp_Shop_User_id_user - FOREIGN KEY (id_user) - REFERENCES Shop_User(id_user), - active BOOLEAN NOT NULL - ); - - CREATE TEMPORARY TABLE tmp_Shop_Product_Currency_Link ( - id_link INTEGER NOT NULL PRIMARY KEY, - CONSTRAINT FK_tmp_Shop_Product_Currency_Link_id_link - FOREIGN KEY (id_link) - REFERENCES Shop_Product_Currency_Region_Link(id_link), - id_product INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_CurrencyLink_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - id_permutation INTEGER NULL, - CONSTRAINT FK_tmp_Shop_Product_Currency_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - id_currency INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_Currency_Link_id_currency - FOREIGN KEY (id_currency) - REFERENCES Shop_Currency(id_currency), - active BOOLEAN NOT NULL - ); - - /* - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( -- IF NOT EXISTS - display_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - guid UUID NOT NULL, - code VARCHAR(50) NOT NULL, - -- CONSTRAINT chk_tmp_Msg_Error_code CHECK (code IN (SELECT code FROM Shop_Msg_Error_Type)), - /* - id_type INTEGER NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type(id_type), - */ - msg VARCHAR(4000) NOT NULL - ); - */ - - - -- User permissions - IF NOT EXISTS( - SELECT * - FROM Shop_User - WHERE - id_user = v_id_user - AND active - ) THEN - RAISE EXCEPTION 'Valid user ID required.' - USING ERRCODE = '22000' - ; - END IF; - - INSERT INTO tmp_Shop_User ( - id_user, - active - ) - SELECT id_user, - active - FROM Shop_User - WHERE id_user = v_id_user - AND active - LIMIT 1 - ; - - -- Get products - INSERT INTO tmp_Shop_Product_Currency_Link ( - id_link, - id_product, - id_permutation, - id_currency, - active - ) - SELECT id_link, - id_product, - id_permutation, - id_currency, - active - FROM Shop_Product_Currency_Region_Link - WHERE ISNULL(id_stripe_price) - AND active - ; - - -- Permissions - -- SELECT * FROM tmp_Msg_Error LIMIT 1; - CALL p_shop_calc_user ( - v_guid, -- a_guid - v_id_user, -- a_id_user - 0, -- a_get_inactive_users - CONVERT((SELECT id_permission FROM Shop_Permission WHERE 'STORE_ADMIN' = code), CHAR), -- a_ids_permission - (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'ADMIN' AND active), -- a_ids_access_level - (SELECT STRING_AGG(DISTINCT id_product, ',') FROM tmp_Shop_Product_Currency_Link), -- (SELECT DISTINCT id_product FROM tmp_Shop_Product_Currency_Link) calc_PCL) -- a_ids_product - (SELECT STRING_AGG(DISTINCT id_permutation, ',') FROM tmp_Shop_Product_Currency_Link) -- a_ids_permutation - ); - -- SELECT * FROM tmp_Msg_Error LIMIT 1; - - IF EXISTS (SELECT can_admin FROM Shop_Calc_User_Temp WHERE guid = v_guid AND NOT can_admin LIMIT 1) THEN - RAISE EXCEPTION 'User ID does not have permission to get all new stripe prices.' - USING ERRCODE = '42501' - ; - END IF; - - DELETE FROM Shop_Calc_User_Temp - WHERE guid = v_guid - ; - - - - -- Returns - /* - IF EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid LIMIT 1) THEN - DELETE FROM tmp_Shop_Product_Currency_Link; - END IF; - */ - /* - SELECT * - FROM tmp_Shop_User - ; - */ - - OPEN result_products FOR - SELECT t_PCL.id_product, - t_PCL.id_permutation, - P.price_GBP_full * C.factor_from_GBP AS unit_price, - C.code AS code_currency, - P.id_stripe_product, - P.is_subscription, - LOWER(RI.code) AS name_recurring_interval, - P.count_interval_recurrence - FROM tmp_Shop_Product_Currency_Link t_PCL - INNER JOIN Shop_Product P - ON t_PCL.id_product = P.id_product - AND P.active - INNER JOIN Shop_Interval_Recurrence RI - ON P.id_unit_measurement_interval_recurrence = RI.id_interval - AND RI.active - INNER JOIN Shop_Currency C - ON t_PCL.id_currency = C.id_currency - AND C.active - WHERE t_PCL.active - ; - RETURN NEXT result_products; - - -- Errors - /* - OPEN result_errors FOR - SELECT * - FROM tmp_Msg_Error - ; - -- RETURN NEXT result_errors; - */ - - - /* - -- Return arguments for test - SELECT - v_id_user - ; - */ - - -- Clean up - DROP TABLE IF EXISTS tmp_Shop_User; - DROP TABLE IF EXISTS tmp_Shop_Product_Currency_Link; -END; -$$ LANGUAGE plpgsql; - - -/* - -DROP FUNCTION IF EXISTS fetch_results; - -CREATE OR REPLACE FUNCTION fetch_results() -RETURNS VOID AS $$ -DECLARE - curs refcursor; - rec record; - curs1 refcursor; - rec1 record; - curs2 refcursor; - rec2 record; -BEGIN - FOR curs IN SELECT p_shop_get_many_stripe_price_new ( - 'auth0|6582b95c895d09a70ba10fef' - ) LOOP - RAISE NOTICE 'Fetching from cursor: %', curs; - LOOP - FETCH curs INTO rec; - EXIT WHEN NOT FOUND; - RAISE NOTICE 'Record: %', rec; - END LOOP; - END LOOP; -END; -$$ LANGUAGE plpgsql; - -SELECT fetch_results(); - -*/ - - -/* -CALL p_shop_get_many_stripe_price_new ( - '' -); - -CALL p_shop_get_many_stripe_price_new ( - 'auth0|6582b95c895d09a70ba10fef' -); - -*/ diff --git a/static/PostgreSQL/706_p_shop_get_many_supplier.sql b/static/PostgreSQL/706_p_shop_get_many_supplier.sql deleted file mode 100644 index 92efce78..00000000 --- a/static/PostgreSQL/706_p_shop_get_many_supplier.sql +++ /dev/null @@ -1,247 +0,0 @@ - - -CREATE OR REPLACE FUNCTION p_shop_get_many_supplier ( - IN a_id_user INTEGER, - IN a_get_all_supplier BOOLEAN, - IN a_get_inactive_supplier BOOLEAN, - IN a_get_first_supplier_only BOOLEAN, - IN a_ids_supplier INTEGER[] -) -RETURNS SETOF REFCURSOR -AS $$ -DECLARE - v_id_user INTEGER; - v_get_all_supplier BOOLEAN; - v_get_inactive_supplier BOOLEAN; - v_get_first_supplier_only BOOLEAN; - v_ids_supplier INTEGER[]; - v_has_filter_supplier BOOLEAN; - v_guid UUID; - v_id_permission_supplier INTEGER; - v_id_access_level_view INTEGER; - v_id_minimum INTEGER; - result_suppliers REFCURSOR; - -- result_errors REFCURSOR; -BEGIN - v_id_user := TRIM(COALESCE(a_id_user, '')); - v_get_all_supplier := COALESCE(a_get_all_supplier, TRUE); - v_get_inactive_supplier := COALESCE(a_get_inactive_supplier, FALSE); - v_get_first_supplier_only := COALESCE(a_get_first_supplier_only, FALSE); - v_ids_supplier := TRIM(COALESCE(a_ids_supplier, '')); - - v_guid := gen_random_uuid(); - v_id_access_level_view := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW'); - v_has_filter_supplier = NOT (a_ids_supplier = ''); - - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Shop_Supplier; - - CREATE TABLE tmp_Shop_Supplier ( - id_supplier INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Supplier_id_supplier - FOREIGN KEY (id_supplier) - REFERENCES Shop_Supplier(id_supplier), - active BOOLEAN NOT NULL, - rank_supplier INTEGER NULL, - can_view BOOLEAN, - can_edit BOOLEAN, - can_admin BIT - ); - - /* - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - guid UUID NOT NULL, - id_type INTEGER NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type (id_type), - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - */ - - -- select v_has_filter_product, v_has_filter_permutation; - - IF v_has_filter_supplier THEN - IF EXISTS ( - SELECT * - FROM UNNEST(v_ids_supplier) AS Supplier_Id - LEFT JOIN Shop_Supplier S ON Supplier_Id = S.id_supplier - WHERE ISNULL(S.id_supplier) - ) THEN - RAISE EXCEPTION 'Invalid supplier IDs: %', ( - SELECT STRING_AGG(Supplier_Id, ', ') - FROM UNNEST(v_ids_supplier) AS Supplier_Id - LEFT JOIN Shop_Supplier S ON Supplier_Id = S.id_supplier - WHERE ISNULL(S.id_supplier) - LIMIT 1 - ) - USING ERRCODE = '22000' - ; - ELSE - INSERT INTO tmp_Shop_Supplier ( - id_supplier, - active, - rank_supplier - ) - SELECT - S.id_supplier, - S.active, - RANK() OVER (ORDER BY id_supplier ASC) AS rank_supplier - FROM Shop_Supplier S - WHERE - ( - a_get_inactive_supplier - OR S.active = TRUE - ) - AND ( - a_get_all_supplier - OR S.id_supplier = ANY(v_ids_supplier) - ) - ; - END IF; - - IF a_get_first_supplier_only THEN - DELETE FROM tmp_Shop_Supplier t_S - WHERE t_S.rank_supplier > ( - SELECT MIN(t_S.rank_supplier) - FROM tmp_Shop_Supplier t_S - ) - ; - END IF; - END IF; - - -- Permissions - -- v_id_user := (SELECT id_user FROM Shop_User WHERE name = CURRENT_USER); - v_id_permission_supplier := (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_SUPPLIER' LIMIT 1); - - -- SELECT v_guid, a_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_permutation_permission; - -- select * from Shop_Calc_User_Temp; - - CALL p_shop_calc_user(v_guid, a_id_user, FALSE, v_id_permission_supplier, v_id_access_level_view, ''); - - -- select * from Shop_Calc_User_Temp; - - IF NOT EXISTS (SELECT can_view FROM Shop_Calc_User_Temp UE_T WHERE UE_T.GUID = v_guid) THEN - RAISE EXCEPTION 'You do not have view permissions for %', ( - SELECT name - FROM Shop_Permission - WHERE id_permission = v_id_permission_supplier - LIMIT 1 - ) - USING ERRCODE = '42501' - ; - END IF; - - - -- select * from tmp_Shop_Product; - - -- Returns - - -- Suppliers - OPEN result_suppliers FOR - SELECT - t_S.id_supplier, - S.name_company, - name_contact, - department_contact, - id_address, - phone_number, - fax, - email, - website, - id_currency, - active - FROM tmp_Shop_Supplier t_S - INNER JOIN Shop_Supplier S - ON t_S.id_supplier = S.id_supplier - ; - RETURN NEXT result_suppliers; - - -- Errors - /* - SELECT - /* - t_ME.display_order, - t_ME.guid, - t_ME.id_type, - t_ME.msg, - MET.code, - MET.name, - MET.description - */ - * - FROM tmp_Msg_Error t_ME - INNER JOIN Shop_Msg_Error_Type MET - ON t_ME.id_type = MET.id_type - WHERE guid = v_guid - ; - OPEN result_errors FOR - SELECT * - FROM tmp_Msg_Error - ; - -- RETURN NEXT result_errors; - */ - - /* - -- Return arguments for test - SELECT - a_ids_category, - a_get_inactive_category, - a_ids_product, - a_get_inactive_product, - a_get_first_product_only, - a_get_all_product, - a_ids_image, - a_get_inactive_image, - a_get_first_image_only, - a_get_all_image - ; - */ - - -- select 'other outputs'; - -- select * from tmp_Shop_Product; - - -- Clean up - DROP TABLE IF EXISTS tmp_Supplier; - - DELETE FROM Shop_Calc_User_Temp - WHERE GUID = v_guid - ; -END; -$$ LANGUAGE plpgsql; - - -/* - -DROP FUNCTION IF EXISTS fetch_results; - -CREATE OR REPLACE FUNCTION fetch_results() -RETURNS VOID AS $$ -DECLARE - curs refcursor; - rec record; -BEGIN - FOR curs IN SELECT p_shop_get_many_supplier ( - '', -- a_id_user - TRUE, -- a_get_all_supplier - FALSE, -- a_get_inactive_supplier - FALSE, -- a_get_first_supplier_only - '' -- a_ids_supplier - ) LOOP - RAISE NOTICE 'Fetching from cursor: %', curs; - LOOP - FETCH curs INTO rec; - EXIT WHEN NOT FOUND; - RAISE NOTICE 'Record: %', rec; - END LOOP; - END LOOP; -END; -$$ LANGUAGE plpgsql; - -SELECT fetch_results(); - -*/ - diff --git a/static/PostgreSQL/706_p_shop_get_many_supplier_purchase_order.sql b/static/PostgreSQL/706_p_shop_get_many_supplier_purchase_order.sql deleted file mode 100644 index 8ff67675..00000000 --- a/static/PostgreSQL/706_p_shop_get_many_supplier_purchase_order.sql +++ /dev/null @@ -1,709 +0,0 @@ - - -CREATE OR REPLACE FUNCTION p_shop_get_many_supplier_purchase_order ( - IN a_id_user INTEGER, - IN a_get_all_supplier BOOLEAN, - IN a_get_inactive_supplier BOOLEAN, - IN a_get_first_supplier_only BOOLEAN, - IN a_ids_supplier INTEGER[], - IN a_get_all_order BOOLEAN, - IN a_get_inactive_order BOOLEAN, - IN a_get_first_order_only BOOLEAN, - IN a_ids_order INTEGER[], - IN a_get_inactive_category BOOLEAN, - IN a_ids_category INTEGER[], - IN a_get_inactive_product BOOLEAN, - IN a_ids_product INTEGER[], - IN a_get_inactive_permutation BOOLEAN, - IN a_ids_permutation INTEGER[], - IN a_date_from TIMESTAMP, - IN a_date_to TIMESTAMP -) -RETURNS SETOF REFCURSOR -AS $$ -DECLARE - v_id_user INTEGER; - v_get_all_supplier BOOLEAN; - v_get_inactive_supplier BOOLEAN; - v_get_first_supplier_only BOOLEAN; - v_ids_supplier INTEGER[]; - v_get_all_order BOOLEAN; - v_get_inactive_order BOOLEAN; - v_get_first_order_only BOOLEAN; - v_ids_order INTEGER[]; - v_get_inactive_category BOOLEAN; - v_ids_category INTEGER[]; - v_get_inactive_product BOOLEAN; - v_ids_product INTEGER[]; - v_get_inactive_permutation BOOLEAN; - v_ids_permutation INTEGER[]; - v_date_from TIMESTAMP; - v_date_to TIMESTAMP; - v_has_filter_supplier BOOLEAN; - v_has_filter_order BOOLEAN; - v_has_filter_category BOOLEAN; - v_has_filter_product BOOLEAN; - v_has_filter_permutation BOOLEAN; - v_has_filter_date_from BOOLEAN; - v_has_filter_date_to BOOLEAN; - v_guid UUID; - v_ids_permission_supplier_purchase_order INTEGER[]; - v_ids_product_permission INTEGER[]; - v_id_access_level_view INTEGER; - v_code_error_data VARCHAR(50); - v_id_type_error_data INTEGER; - result_suppliers REFCURSOR; - result_orders REFCURSOR; - result_order_product_links REFCURSOR; - -- result_errors REFCURSOR; -BEGIN - v_id_user := TRIM(COALESCE(a_id_user, '')); - v_get_all_supplier := COALESCE(a_get_all_supplier, TRUE); - v_get_inactive_supplier := COALESCE(a_get_inactive_supplier, FALSE); - v_get_first_supplier_only := COALESCE(a_get_first_supplier_only, FALSE); - v_ids_supplier := TRIM(COALESCE(a_ids_supplier, '')); - v_get_all_order := COALESCE(a_get_all_order, TRUE); - v_get_inactive_order := COALESCE(a_get_inactive_order, FALSE); - v_get_first_order_only := COALESCE(a_get_first_order_only, FALSE); - v_ids_order := TRIM(COALESCE(a_ids_order, '')); - v_get_inactive_category := COALESCE(a_get_inactive_category, FALSE); - v_ids_category := TRIM(COALESCE(a_ids_category, '')); - v_get_inactive_product := COALESCE(a_get_inactive_product, FALSE); - v_ids_product := TRIM(COALESCE(a_ids_product, '')); - v_get_inactive_permutation := COALESCE(a_get_inactive_permutation, FALSE); - v_ids_permutation := TRIM(COALESCE(a_ids_permutation, '')); - v_date_from := a_date_from; - v_date_to := a_date_to; - - v_guid := gen_random_uuid(); - v_id_access_level_view := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW' LIMIT 1); - -- v_ids_permission_supplier_purchase_order := (SELECT id_permission FROM Shop_Permission WHERE code = 'SHOP_SUPPLIER_PURCHASE_ORDER' LIMIT 1); - v_code_error_data = 'BAD_DATA'; - v_id_type_error_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_data); - v_has_filter_supplier = (CARDINALITY(v_ids_supplier) > 0); - v_has_filter_order = (CARDINALITY(v_ids_order) > 0); - v_has_filter_category = (CARDINALITY(v_ids_category) > 0); - v_has_filter_product = (CARDINALITY(v_ids_product) > 0); - v_has_filter_permutation = (CARDINALITY(v_ids_permutation) > 0); - v_has_filter_date_from = CASE WHEN ISNULL(v_date_from) THEN FALSE ELSE TRUE END; - v_has_filter_date_to = CASE WHEN ISNULL(v_date_to) THEN FALSE ELSE TRUE END; - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Shop_Supplier_Purchase_Order_Product_Link; - DROP TABLE IF EXISTS tmp_Shop_Supplier_Purchase_Order; - DROP TABLE IF EXISTS tmp_Shop_Supplier; - DROP TABLE IF EXISTS tmp_Shop_Product; - - CREATE TABLE tmp_Shop_Supplier ( - id_supplier INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Supplier_id_supplier - FOREIGN KEY (id_supplier) - REFERENCES Shop_Supplier(id_supplier), - active BOOLEAN NOT NULL, - rank_supplier INTEGER NULL, - can_view BOOLEAN, - can_edit BOOLEAN, - can_admin BIT - ); - - CREATE TABLE tmp_Shop_Supplier_Purchase_Order ( - id_order INTEGER NOT NULL PRIMARY KEY, - id_supplier_ordered INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Supplier_Purchase_Order_id_supplier_ordered - FOREIGN KEY (id_supplier_ordered) - REFERENCES Shop_Supplier(id_supplier), - cost_total_local REAL NOT NULL, - id_currency_cost INTEGER NOT NULL, - active BOOLEAN NOT NULL, - rank_order INTEGER NOT NULL - ); - - /* - CREATE TABLE tmp_Shop_Supplier_Purchase_Order_Product_Link ( - id_link INTEGER NOT NULL PRIMARY KEY, - id_order INTEGER NOT NULL, - CONSTRAINT FK_tmp_Supplier_Purchase_Order_Product_Link_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Supplier_Purchase_Order(id_order), - id_permutation INTEGER NOT NULL, - CONSTRAINT FK_tmp_Supplier_Purchase_Order_Product_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - cost_total_local REAL NOT NULL, - id_currency_cost INTEGER NOT NULL, - quantity_ordered REAL NOT NULL, - id_unit_quantity INTEGER NOT NULL, - CONSTRAINT FK_tmp_Supplier_Purchase_Order_Product_Link_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - quantity_received REAL NULL, - latency_delivery_days INTEGER NOT NULL, - display_order INTEGER NOT NULL - ); - */ - - CREATE TABLE tmp_Shop_Product ( - id_category INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_category - FOREIGN KEY (id_category) - REFERENCES Shop_Product_Category(id_category), - id_product INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - -- product_has_variations BOOLEAN NOT NULL, - id_permutation INTEGER NULL, - CONSTRAINT FK_tmp_Shop_Product_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - active_category BOOLEAN NOT NULL, - active_product BOOLEAN NOT NULL, - active_permutation BOOLEAN NULL, - display_order_category INTEGER NOT NULL, - display_order_product INTEGER NOT NULL, - display_order_permutation INTEGER NULL, - rank_permutation INTEGER NOT NULL, -- _in_category - name VARCHAR(255) NOT NULL, - description VARCHAR(4000) NOT NULL, - /* - price_GBP_full REAL NOT NULL, - price_GBP_min REAL NOT NULL, - */ - latency_manufacture INTEGER NOT NULL, - quantity_min REAL NOT NULL, - quantity_max REAL NOT NULL, - quantity_step REAL NOT NULL, - quantity_stock REAL NOT NULL, - is_subscription BOOLEAN NOT NULL, - id_unit_measurement_interval_recurrence INTEGER, - CONSTRAINT FK_tmp_Shop_Product_id_unit_measurement_interval_recurrence - FOREIGN KEY (id_unit_measurement_interval_recurrence) - REFERENCES Shop_Interval_Recurrence(id_interval), - count_interval_recurrence INTEGER, - id_stripe_product VARCHAR(100), - product_has_variations INTEGER NOT NULL, - can_view BOOLEAN, - can_edit BOOLEAN, - can_admin BIT - ); - - /* - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - guid UUID NOT NULL, - id_type INTEGER NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type (id_type), - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - */ - - -- select v_has_filter_product, v_has_filter_permutation; - - IF v_has_filter_supplier THEN - IF EXISTS ( - SELECT * - FROM UNNEST(v_ids_supplier) AS Supplier_Id - LEFT JOIN Shop_Supplier S ON Supplier_Id = S.id_supplier - WHERE ISNULL(S.id_supplier) - LIMIT 1 - ) THEN - RAISE EXCEPTION 'Invalid supplier IDs: %', ( - SELECT STRING_AGG(Supplier_Id, ', ') - FROM UNNEST(v_ids_supplier) AS Supplier_Id - LEFT JOIN Shop_Supplier S ON Supplier_Id = S.id_supplier - WHERE ISNULL(S.id_supplier) - LIMIT 1 - ) - USING ERRCODE = '22000' - ; - ELSE - INSERT INTO tmp_Shop_Supplier ( - id_supplier, - active, - rank_supplier - ) - SELECT - S.id_supplier, - S.active, - RANK() OVER (ORDER BY id_supplier ASC) AS rank_supplier - FROM Shop_Supplier S - INNER JOIN Split_Temp TS ON S.id_supplier = TS.substring - WHERE - ( - v_get_inactive_supplier - OR S.active = TRUE - ) - ; - END IF; - - IF v_get_first_supplier_only THEN - DELETE FROM tmp_Shop_Supplier t_S - WHERE t_S.rank_supplier > ( - SELECT MIN(t_S.rank_supplier) - FROM tmp_Shop_Supplier t_S - ) - ; - END IF; - END IF; - - IF v_has_filter_category = TRUE THEN - IF EXISTS ( - SELECT * - FROM UNNEST(v_ids_category) AS Category_Id - LEFT JOIN Shop_Product_Category C ON Category_Id = C.id_category - WHERE ISNULL(C.id_category) - ) THEN - RAISE EXCEPTION 'Invalid category IDs: %', ( - SELECT STRING_AGG(Category_Id, ', ') - FROM UNNEST(v_ids_category) AS Category_Id - LEFT JOIN Shop_Product_Category C ON Category_Id = C.id_category - WHERE ISNULL(C.id_category) - ) - USING ERRCODE = '22000' - ; - END IF; - END IF; - - IF v_has_filter_product = TRUE THEN - IF EXISTS ( - SELECT * - FROM UNNEST(v_ids_product) AS Product_Id - LEFT JOIN Shop_Product P ON Product_Id = P.id_product - WHERE ISNULL(P.id_product) - LIMIT 1 - ) THEN - RAISE EXCEPTION 'Invalid product IDs: %', ( - SELECT STRING_AGG(Product_Id, ', ') - FROM UNNEST(v_ids_product) AS Product_Id - LEFT JOIN Shop_Product P ON Product_Id = P.id_product - WHERE ISNULL(P.id_product) - ) - USING ERRCODE = '22000' - ; - END IF; - END IF; - - IF v_has_filter_permutation = TRUE THEN - IF EXISTS ( - SELECT * - FROM UNNEST(v_ids_permutation) AS Permutation_Id - LEFT JOIN Shop_Product_Permutation PP ON Permutation_Id = PP.id_permutation - WHERE ISNULL(PP.id_permutation) - LIMIT 1 - ) THEN - RAISE EXCEPTION 'Invalid permutation IDs: %', ( - SELECT STRING_AGG(Permutation_Id, ', ') - FROM UNNEST(v_ids_permutation) AS Permutation_Id - LEFT JOIN Shop_Product_Permutation PP ON Permutation_Id = PP.id_permutation - WHERE ISNULL(PP.id_permutation) - ) - USING ERRCODE = '22000' - ; - END IF; - END IF; - - IF v_has_filter_category = TRUE OR v_has_filter_product = TRUE OR v_has_filter_permutation = TRUE THEN - INSERT INTO tmp_Shop_Product ( - id_category, - id_product, - id_permutation, - active_category, - active_product, - active_permutation, - display_order_category, - display_order_product, - display_order_permutation - -- rank_permutation, - /* - name, - description, - /* - price_GBP_VAT_incl, - price_GBP_VAT_excl, - price_GBP_min, - */ - latency_manufacture, - quantity_min, - quantity_max, - quantity_step, - quantity_stock, - is_subscription, - id_unit_measurement_interval_recurrence, - count_interval_recurrence, - id_stripe_product, - product_has_variations - */ - ) - SELECT - P.id_category, - P.id_product, - -- P.has_variations AS product_has_variations, - PP.id_permutation, - C.active AS active_category, - P.active AS active_product, - PP.active AS active_permutation, - C.display_order AS display_order_category, - P.display_order AS display_order_product, - PP.display_order AS display_order_permutation - -- RANK() OVER (ORDER BY C.display_order, P.display_order, PP.display_order) AS rank_permutation, #PARTITION BY P.id_category -- _in_category - /* - P.name, - PP.description, - /* - PP.price_GBP_VAT_incl, - PP.price_GBP_VAT_excl, - PP.price_GBP_min, - */ - PP.latency_manufacture, - PP.quantity_min, - PP.quantity_max, - PP.quantity_step, - PP.quantity_stock, - PP.is_subscription, - PP.id_unit_measurement_interval_recurrence, - PP.count_interval_recurrence, - PP.id_stripe_product, - P.has_variations - */ - FROM Shop_Product P - INNER JOIN Shop_Product_Permutation PP - ON P.id_product = PP.id_product - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - WHERE - -- permutations - ( - ( - NOT v_has_filter_permutation - OR FIND_IN_SET(PP.id_permutation, v_ids_permutation) > 0 - ) - AND ( - v_get_inactive_permutation - OR PP.active = TRUE - ) - ) - -- categories - AND ( - ( - NOT v_has_filter_category - OR FIND_IN_SET(P.id_category, v_ids_category) > 0 - ) - AND ( - v_get_inactive_category - OR C.active = TRUE - ) - ) - -- products - AND ( - ( - NOT v_has_filter_product - OR FIND_IN_SET(P.id_product, v_ids_product) > 0 - ) - AND ( - v_get_inactive_product - OR P.active = TRUE - ) - ) - ; - END IF; - - -- Get orders - IF v_has_filter_order AND EXISTS ( - -- SELECT * FROM Split_Temp TS LEFT JOIN Shop_Supplier_Purchase_Order SPO ON TS.substring = SPO.id_order WHERE ISNULL(SPO.id_order) - SELECT * - FROM UNNEST(v_ids_order) Order_Id - - ) THEN - RAISE EXCEPTION 'Invalid order IDs: %', ( - SELECT STRING_AGG(TS.substring, ', ') - FROM UNNEST(v_ids_order) - LEFT JOIN Shop_Supplier_Purchase_Order SPO ON TS.substring = SPO.id_order - WHERE ISNULL(SPO.id_order) - ) - USING ERRCODE = '22000' - ; - END IF; - - INSERT INTO tmp_Shop_Supplier_Purchase_Order ( -- _Product_Link - id_order, - -- active, - rank_order - ) - SELECT - SPO.id_order, - -- SPO.active, - RANK() OVER (ORDER BY SPO.id_order ASC) AS rank_order - FROM Shop_Supplier_Purchase_Order SPO - -- INNER JOIN Split_Temp TS ON SPO.id_order = TS.substring - INNER JOIN Shop_Supplier_Purchase_Order_Product_Link SPOPL ON SPO.id_order = SPOPL.id_order - INNER JOIN Shop_Supplier S ON SPO.id_supplier_ordered = S.id_supplier - INNER JOIN Shop_Product_Permutation PP ON SPOPL.id_permutation = PP.id_permutation - INNER JOIN Shop_Product P ON PP.id_product = P.id_product - INNER JOIN Shop_Product_Category C ON P.id_category = C.id_category - LEFT JOIN tmp_Shop_Product t_P ON SPOPL.id_permutation = t_P.id_permutation - LEFT JOIN tmp_Shop_Supplier t_S ON SPO.id_supplier_ordered = t_S.id_supplier - WHERE - -- supplier - ( - v_has_filter_supplier = FALSE - OR NOT ISNULL(t_S.id_supplier) -- SPO.id_supplier_ordered IN (SELECT DISTINCT id_supplier FROM tmp_Shop_Supplier) - ) - -- order - AND ( - ( - v_has_filter_order = FALSE - OR ( - -- ID - -- FIND_IN_SET(SPO.id_order, v_ids_order) > 0 - SPO.id_order = ANY(v_ids_order) - -- date - AND ( - ( - v_has_filter_date_from = FALSE - OR SPO.created_on > v_date_from - ) - AND ( - v_has_filter_date_to = FALSE - OR SPO.created_on < v_date_to - ) - ) - ) - ) - -- active - /* - AND ( - v_get_inactive_order - OR SPO.active = TRUE - ) - */ - ) - -- permutations - AND ( - ( - v_has_filter_category = FALSE - AND v_has_filter_product = FALSE - AND v_has_filter_permutation = FALSE - ) - OR NOT ISNULL(t_P.id_permutation) -- SPO.id_permutation IN (SELECT DISTINCT id_permutation FROM tmp_Shop_Product) - ) - ; - - IF v_get_first_order_only THEN - DELETE FROM tmp_Shop_Supplier_Purchase_Order t_SPO - WHERE t_SPO.rank_order > ( - SELECT MIN(t_SPO.rank_order) - FROM tmp_Shop_Supplier_Purchase_Order t_SPO - ) - ; - END IF; - - -- Permissions - -- v_id_user := (SELECT id_user FROM Shop_User WHERE name = CURRENT_USER); - v_ids_permission_supplier_purchase_order := (SELECT STRING_AGG(id_permission, ',') FROM Shop_Permission WHERE code IN ('STORE_SUPPLIER', 'STORE_SUPPLIER_PURCHASE_ORDER')); - -- v_ids_permutation_permission := (SELECT STRING_AGG(id_permutation, ',') FROM tmp_Shop_Product WHERE NOT ISNULL(id_permutation)); - v_ids_product_permission := (SELECT STRING_AGG(DISTINCT t_P.id_product, ',') FROM tmp_Shop_Product t_P WHERE NOT ISNULL(t_P.id_product)); - - -- SELECT v_guid, v_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_permutation_permission; - -- select * from Shop_Calc_User_Temp; - - CALL p_shop_calc_user(v_guid, v_id_user, FALSE, v_ids_permission_supplier_purchase_order, v_id_access_level_view, v_ids_product_permission); - - -- select * from Shop_Calc_User_Temp; - - IF NOT EXISTS (SELECT can_view FROM Shop_Calc_User_Temp UE_T WHERE UE_T.GUID = v_guid) THEN - RAISE EXCEPTION 'You do not have view permissions for %', ( - SELECT STRING_AGG(name, ', ') - FROM Shop_Permission - WHERE id_permission = v_ids_permission_supplier_purchase_order - ) - USING ERRCODE = '42501' - ; - END IF; - - - UPDATE tmp_Shop_Product t_P - SET t_P.can_view = UE_T.can_view, - t_P.can_edit = UE_T.can_edit, - t_P.can_admin = UE_T.can_admin - FROM tmp_Shop_Product t_P - INNER JOIN Shop_Calc_User_Temp UE_T - ON t_P.id_product = UE_T.id_product -- t_P.id_permutation = UE_T.id_permutation - AND UE_T.GUID = v_guid - ; - - -- CALL p_shop_clear_calc_user(v_guid); - -- DROP TABLE IF EXISTS Shop_Calc_User_Temp; - DELETE FROM Shop_Calc_User_Temp - WHERE GUID = v_guid - ; - - - -- select * from tmp_Shop_Product; - - -- Returns - -- v_now := CURRENT_TIMESTAMP; - - -- Suppliers - OPEN result_suppliers FOR - SELECT - t_S.id_supplier, - S.name_company, - S.name_contact, - S.department_contact, - S.id_address, - S.phone_number, - S.fax, - S.email, - S.website, - S.id_currency, - t_S.active - FROM tmp_Shop_Supplier t_S - INNER JOIN Shop_Supplier S - ON t_S.id_supplier = S.id_supplier - ; - RETURN NEXT result_suppliers; - - -- Supplier Purchase Order - OPEN result_orders FOR - SELECT -- * - t_SPO.id_order, - SPO.id_supplier_ordered, - SPO.cost_total_local, - SPO.id_currency_cost, - t_SPO.active - FROM Shop_Supplier_Purchase_Order SPO - INNER JOIN tmp_Shop_Supplier_Purchase_Order t_SPO ON SPO.id_order = t_SPO.id_order - ; - RETURN NEXT result_orders; - - -- Supplier Purchase Order Product Link - OPEN result_order_product_links FOR - SELECT - SPOPL.id_link, - SPOPL.id_order, - SPOPL.id_permutation, - P.name as name_product, - SPOPL.cost_total_local, - SPOPL.id_currency_cost, - SPOPL.quantity_ordered, - SPOPL.id_unit_quantity, - SPOPL.quantity_received, - SPOPL.latency_delivery_days, - SPOPL.display_order - FROM Shop_Supplier_Purchase_Order_Product_Link SPOPL - -- INNER JOIN tmp_Shop_Supplier_Purchase_Order_Product_Link t_SPOPL ON SPOPL.id_link = t_SPOPL.id_link - INNER JOIN tmp_Shop_Supplier_Purchase_Order t_SPO ON SPOPL.id_order = t_SPO.id_order - INNER JOIN Shop_Product_Permutation PP ON SPOPL.id_permutation = PP.id_permutation - INNER JOIN Shop_Product P ON PP.id_product = P.id_product - INNER JOIN Shop_Product_Category C ON P.id_category = C.id_category - ORDER BY SPOPL.id_order, C.display_order, P.display_order, PP.display_order - ; - RETURN NEXT result_order_product_links; - - -- Errors - /* - SELECT - /* - t_ME.display_order, - t_ME.guid, - t_ME.id_type, - t_ME.msg, - MET.code, - MET.name, - MET.description - */ - * - FROM tmp_Msg_Error t_ME - INNER JOIN Shop_Msg_Error_Type MET - ON t_ME.id_type = MET.id_type - WHERE guid = v_guid - ; - */ - - /* - OPEN result_errors FOR - SELECT * - FROM tmp_Msg_Error - ; - -- RETURN NEXT result_errors; - */ - - - /* - -- Return arguments for test - SELECT - v_ids_category, - v_get_inactive_category, - v_ids_product, - v_get_inactive_product, - v_get_first_product_only, - v_get_all_product, - v_ids_image, - v_get_inactive_image, - v_get_first_image_only, - v_get_all_image - ; - */ - - -- select 'other outputs'; - -- select * from tmp_Shop_Product; - - -- Clean up - DROP TABLE IF EXISTS tmp_Shop_Supplier_Purchase_Order_Product_Link; - DROP TABLE IF EXISTS tmp_Shop_Supplier_Purchase_Order; - DROP TABLE IF EXISTS tmp_Shop_Supplier; - DROP TABLE IF EXISTS tmp_Shop_Product; - - DELETE FROM Shop_Calc_User_Temp - WHERE GUID = v_guid - ; -END; -$$ LANGUAGE plpgsql; - - -/* - -DROP FUNCTION IF EXISTS fetch_results; - -CREATE OR REPLACE FUNCTION fetch_results() -RETURNS VOID AS $$ -DECLARE - curs refcursor; - rec record; -BEGIN - FOR curs IN SELECT p_shop_get_many_supplier_purchase_order ( - '', -- a_id_user - TRUE, -- a_get_all_supplier - FALSE, -- a_get_inactive_supplier - FALSE, -- a_get_first_supplier_only - '', -- a_ids_supplier - TRUE, -- a_get_all_order - -- FALSE, -- a_get_inactive_order - FALSE, -- a_get_first_order_only - '', -- a_ids_order - FALSE, -- a_get_inactive_category - '', -- a_ids_category - FALSE, -- a_get_inactive_product - '', -- a_ids_product - FALSE, -- a_get_inactive_permutation - '', -- a_ids_permutation - NULL, -- a_date_from - NULL -- a_date_to - ) LOOP - RAISE NOTICE 'Fetching from cursor: %', curs; - LOOP - FETCH curs INTO rec; - EXIT WHEN NOT FOUND; - RAISE NOTICE 'Record: %', rec; - END LOOP; - END LOOP; -END; -$$ LANGUAGE plpgsql; - -SELECT fetch_results(); - -*/ - diff --git a/static/PostgreSQL/708_p_shop_get_many_manufacturing_purchase_order.sql b/static/PostgreSQL/708_p_shop_get_many_manufacturing_purchase_order.sql deleted file mode 100644 index adad5f6c..00000000 --- a/static/PostgreSQL/708_p_shop_get_many_manufacturing_purchase_order.sql +++ /dev/null @@ -1,601 +0,0 @@ - - -CREATE OR REPLACE FUNCTION p_shop_get_many_manufacturing_purchase_order ( - IN a_id_user INTEGER, - IN a_get_all_order BOOLEAN, - IN a_get_inactive_order BOOLEAN, - IN a_get_first_order_only BOOLEAN, - IN a_ids_order INTEGER[], - IN a_get_inactive_category BOOLEAN, - IN a_ids_category INTEGER[], - IN a_get_inactive_product BOOLEAN, - IN a_ids_product INTEGER[], - IN a_get_inactive_permutation BOOLEAN, - IN a_ids_permutation INTEGER[], - IN a_date_from TIMESTAMP, - IN a_date_to TIMESTAMP -) -RETURNS SETOF REFCURSOR -AS $$ -DECLARE - v_id_user INTEGER; - v_get_all_order BOOLEAN; - v_get_inactive_order BOOLEAN; - v_get_first_order_only BOOLEAN; - v_ids_order INTEGER[]; - v_get_inactive_category BOOLEAN; - v_ids_category INTEGER[]; - v_get_inactive_product BOOLEAN; - v_ids_product INTEGER[]; - v_get_inactive_permutation BOOLEAN; - v_ids_permutation INTEGER[]; - v_date_from TIMESTAMP; - v_date_to TIMESTAMP; - v_has_filter_order BOOLEAN; - v_has_filter_category BOOLEAN; - v_has_filter_product BOOLEAN; - v_has_filter_permutation BOOLEAN; - v_has_filter_date_from BOOLEAN; - v_has_filter_date_to BOOLEAN; - v_guid UUID; - v_id_access_level_view INTEGER; - v_code_error_data VARCHAR(50); - v_id_type_error_data INTEGER; - v_ids_permission_manufacturing_purchase_order VARCHAR(4000); - v_ids_product_permission INTEGER[]; - result_orders REFCURSOR; - result_order_product_links REFCURSOR; - result_errors REFCURSOR; -BEGIN - v_id_user := TRIM(COALESCE(a_id_user, '')); - v_get_all_order := COALESCE(a_get_all_order, TRUE); - v_get_inactive_order := COALESCE(a_get_inactive_order, FALSE); - v_get_first_order_only := COALESCE(a_get_first_order_only, FALSE); - v_ids_order := TRIM(COALESCE(a_ids_order, '')); - v_get_inactive_category := COALESCE(a_get_inactive_category, FALSE); - v_ids_category := TRIM(COALESCE(a_ids_category, '')); - v_get_inactive_product := COALESCE(a_get_inactive_product, FALSE); - v_ids_product := TRIM(COALESCE(a_ids_product, '')); - v_get_inactive_permutation := COALESCE(a_get_inactive_permutation, FALSE); - v_ids_permutation := TRIM(COALESCE(a_ids_permutation, '')); - v_date_from := a_date_from; - v_date_to := a_date_to; - - v_guid := gen_random_uuid(); - v_id_access_level_view := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW' LIMIT 1); - -- v_ids_permission_manufacturing_purchase_order := (SELECT id_permission FROM Shop_Permission WHERE code = 'SHOP_manufacturing_PURCHASE_ORDER' LIMIT 1); - v_code_error_data = 'BAD_DATA'; - v_id_type_error_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_data); - - v_has_filter_order = CASE WHEN v_ids_order = '' THEN FALSE ELSE TRUE END; - v_has_filter_category = CASE WHEN v_ids_category = '' THEN FALSE ELSE TRUE END; - v_has_filter_product = CASE WHEN v_ids_product = '' THEN FALSE ELSE TRUE END; - v_has_filter_permutation = CASE WHEN v_ids_permutation = '' THEN FALSE ELSE TRUE END; - v_has_filter_date_from = CASE WHEN ISNULL(v_date_from) THEN FALSE ELSE TRUE END; - v_has_filter_date_to = CASE WHEN ISNULL(v_date_to) THEN FALSE ELSE TRUE END; - - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Shop_Manufacturing_Purchase_Order_Product_Link; - DROP TABLE IF EXISTS tmp_Shop_Manufacturing_Purchase_Order; - DROP TABLE IF EXISTS tmp_Shop_Product; - - CREATE TABLE tmp_Shop_Manufacturing_Purchase_Order ( - id_order INTEGER NOT NULL PRIMARY KEY, - /* - id_supplier_ordered INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Manufacturing_Purchase_Order_id_supplier_ordered - FOREIGN KEY (id_supplier_ordered) - REFERENCES Shop_Supplier(id_supplier), - */ - cost_total_local REAL NOT NULL, - id_currency_cost INTEGER NOT NULL, - value_produced_total_local REAL NOT NULL, - active BOOLEAN NOT NULL, - rank_order INTEGER NOT NULL - ); - - /* - CREATE TABLE tmp_Shop_Manufacturing_Purchase_Order_Product_Link ( - id_link INTEGER NOT NULL PRIMARY KEY, - id_order INTEGER NOT NULL, - CONSTRAINT FK_tmp_manufacturing_Purchase_Order_Product_Link_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_manufacturing_Purchase_Order(id_order), - id_permutation INTEGER NOT NULL, - CONSTRAINT FK_tmp_manufacturing_Purchase_Order_Product_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - cost_total_local REAL NOT NULL, - id_currency_cost INTEGER NOT NULL, - quantity_used REAL NOT NULL, - id_unit_quantity INTEGER NOT NULL, - CONSTRAINT FK_tmp_manufacturing_Purchase_Order_Product_Link_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - quantity_produced REAL NULL, - latency_delivery_days INTEGER NOT NULL, - display_order INTEGER NOT NULL - ); - */ - - CREATE TABLE tmp_Shop_Product ( - id_category INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_category - FOREIGN KEY (id_category) - REFERENCES Shop_Product_Category(id_category), - id_product INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - -- product_has_variations BOOLEAN NOT NULL, - id_permutation INTEGER NULL, - CONSTRAINT FK_tmp_Shop_Product_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - active_category BOOLEAN NOT NULL, - active_product BOOLEAN NOT NULL, - active_permutation BOOLEAN NULL, - display_order_category INTEGER NOT NULL, - display_order_product INTEGER NOT NULL, - display_order_permutation INTEGER NULL, - rank_permutation INTEGER NOT NULL, -- _in_category - -- name VARCHAR(255) NOT NULL, - -- description VARCHAR(4000) NOT NULL, - /* - price_GBP_full REAL NOT NULL, - price_GBP_min REAL NOT NULL, - */ - /* - latency_manufacture INTEGER NOT NULL, - quantity_min REAL NOT NULL, - quantity_max REAL NOT NULL, - quantity_step REAL NOT NULL, - quantity_stock REAL NOT NULL, - is_subscription BOOLEAN NOT NULL, - id_unit_measurement_interval_recurrence INTEGER, - CONSTRAINT FK_tmp_Shop_Product_id_unit_measurement_interval_recurrence - FOREIGN KEY (id_unit_measurement_interval_recurrence) - REFERENCES Shop_Interval_Recurrence(id_interval), - count_interval_recurrence INTEGER, - id_stripe_product VARCHAR(100), - product_has_variations INTEGER NOT NULL, - */ - can_view BOOLEAN, - can_edit BOOLEAN, - can_admin BIT - ); - - /* - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - guid UUID NOT NULL, - id_type INTEGER NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type (id_type), - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - */ - - -- select v_has_filter_product, v_has_filter_permutation; - - IF v_has_filter_category = TRUE AND EXISTS ( - SELECT * - FROM UNNEST(v_ids_category) AS Category_Id - LEFT JOIN Shop_Product_Category C ON Category_Id = C.id_category - WHERE ISNULL(C.id_category) - ) THEN - RAISE EXCEPTION 'Invalid category IDs: %', ( - SELECT COALESCE(STRING_AGG(Category_Id, ', ') ,'NULL') - FROM UNNEST(v_ids_category) AS Category_Id - LEFT JOIN Shop_Product_Category C ON Category_Id = C.id_category - WHERE ISNULL(C.id_category) - ) - USING ERRCODE = '22000' - ; - END IF; - - IF v_has_filter_product = TRUE AND EXISTS ( - SELECT * - FROM UNNEST(v_ids_product) AS Product_Id - LEFT JOIN Shop_Product P ON Product_Id = P.id_product - WHERE ISNULL(P.id_product) - LIMIT 1 - ) THEN - RAISE EXCEPTION 'Invalid product IDs: %', ( - SELECT COALESCE(STRING_AGG(Product_Id, ', ') ,'NULL') - FROM UNNEST(v_ids_product) AS Product_Id - LEFT JOIN Shop_Product P ON Product_Id = P.id_product - WHERE ISNULL(P.id_product) - ) - USING ERRCODE = '22000' - ; - END IF; - - IF v_has_filter_permutation = TRUE AND EXISTS ( - SELECT * - FROM UNNEST(v_ids_permutation) AS Permutation_Id - LEFT JOIN Shop_Product_Permutation PP ON Permutation_Id = PP.id_permutation - WHERE ISNULL(PP.id_permutation) - LIMIT 1 - ) THEN - RAISE EXCEPTION 'Invalid permutation IDs: %', ( - SELECT STRING_AGG(Permutation_Id, ', ') - FROM UNNEST(v_ids_permutation) AS Permutation_Id - LEFT JOIN Shop_Product_Permutation PP ON Permutation_Id = PP.id_permutation - WHERE ISNULL(PP.id_permutation) - ) - USING ERRCODE = '22000' - ; - END IF; - - IF v_has_filter_category = TRUE OR v_has_filter_product = TRUE OR v_has_filter_permutation = TRUE THEN - INSERT INTO tmp_Shop_Product ( - id_category, - id_product, - id_permutation, - active_category, - active_product, - active_permutation, - display_order_category, - display_order_product, - display_order_permutation - -- rank_permutation, - /* - name, - description, - /* - price_GBP_VAT_incl, - price_GBP_VAT_excl, - price_GBP_min, - */ - latency_manufacture, - quantity_min, - quantity_max, - quantity_step, - quantity_stock, - is_subscription, - id_unit_measurement_interval_recurrence, - count_interval_recurrence, - id_stripe_product, - product_has_variations - */ - ) - SELECT - P.id_category, - P.id_product, - -- P.has_variations AS product_has_variations, - PP.id_permutation, - C.active AS active_category, - P.active AS active_product, - PP.active AS active_permutation, - C.display_order AS display_order_category, - P.display_order AS display_order_product, - PP.display_order AS display_order_permutation - -- RANK() OVER (ORDER BY C.display_order, P.display_order, PP.display_order) AS rank_permutation, #PARTITION BY P.id_category -- _in_category - /* - P.name, - PP.description, - /* - PP.price_GBP_VAT_incl, - PP.price_GBP_VAT_excl, - PP.price_GBP_min, - */ - PP.latency_manufacture, - PP.quantity_min, - PP.quantity_max, - PP.quantity_step, - PP.quantity_stock, - PP.is_subscription, - PP.id_unit_measurement_interval_recurrence, - PP.count_interval_recurrence, - PP.id_stripe_product, - P.has_variations - */ - FROM Shop_Product P - INNER JOIN Shop_Product_Permutation PP - ON P.id_product = PP.id_product - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - WHERE - -- permutations - ( - ( - NOT v_has_filter_permutation - OR FIND_IN_SET(PP.id_permutation, v_ids_permutation) > 0 - ) - AND ( - v_get_inactive_permutation - OR PP.active = TRUE - ) - ) - -- categories - AND ( - ( - NOT v_has_filter_category - OR FIND_IN_SET(P.id_category, v_ids_category) > 0 - ) - AND ( - v_get_inactive_category - OR C.active = TRUE - ) - ) - -- products - AND ( - ( - NOT v_has_filter_product - OR FIND_IN_SET(P.id_product, v_ids_product) > 0 - ) - AND ( - v_get_inactive_product - OR P.active = TRUE - ) - ) - ; - END IF; - - -- Get orders - IF v_has_filter_order AND EXISTS ( - SELECT * - FROM UNNEST(v_ids_order) AS Order_Id - LEFT JOIN Shop_Manufacturing_Purchase_Order MPO ON Order_Id = MPO.id_order - WHERE ISNULL(MPO.id_order) - LIMIT 1 - ) THEN - RAISE EXCEPTION 'Invalid order IDs: %', ( - SELECT STRING_AGG(Order_Id, ', ') - FROM UNNEST(v_ids_order) AS Order_Id - LEFT JOIN Shop_Manufacturing_Purchase_Order MPO ON Order_Id = MPO.id_order - WHERE ISNULL(MPO.id_order) - ) - USING ERRCODE = '22000' - ; - END IF; - - INSERT INTO tmp_Shop_Manufacturing_Purchase_Order ( -- _Product_Link - id_order, - -- active, - rank_order - ) - SELECT - MPO.id_order, - -- MPO.active, - RANK() OVER (ORDER BY MPO.id_order ASC) AS rank_order - FROM Shop_Manufacturing_Purchase_Order MPO - -- INNER JOIN Split_Temp TS ON MPO.id_order = TS.substring - INNER JOIN Shop_manufacturing_Purchase_Order_Product_Link MPOPL ON MPO.id_order = MPOPL.id_order - INNER JOIN Shop_Product_Permutation PP ON MPOPL.id_permutation = PP.id_permutation - INNER JOIN Shop_Product P ON PP.id_product = P.id_product - INNER JOIN Shop_Product_Category C ON P.id_category = C.id_category - LEFT JOIN tmp_Shop_Product t_P ON MPOPL.id_permutation = t_P.id_permutation - WHERE - -- order - ( - ( - v_has_filter_order = 0 - OR ( - -- ID - -- FIND_IN_SET(MPO.id_order, v_ids_order) > 0 - MPO.id_order = ANY(v_ids_order) - -- date - AND ( - ( - v_has_filter_date_from = 0 - OR MPO.created_on > v_date_from - ) - AND ( - v_has_filter_date_to = 0 - OR MPO.created_on < v_date_to - ) - ) - ) - ) - -- active - /* - AND ( - v_get_inactive_order - OR MPO.active = TRUE - ) - */ - ) - -- permutations - AND ( - ( - v_has_filter_category = FALSE - AND v_has_filter_product = FALSE - AND v_has_filter_permutation = 0 - ) - OR NOT ISNULL(t_P.id_permutation) -- MPO.id_permutation IN (SELECT DISTINCT id_permutation FROM tmp_Shop_Product) - ) - ; - - IF v_get_first_order_only THEN - DELETE FROM tmp_Shop_Manufacturing_Purchase_Order t_MPO - WHERE t_MPO.rank_order > ( - SELECT MIN(t_MPO.rank_order) - FROM tmp_Shop_Manufacturing_Purchase_Order t_MPO - ) - ; - END IF; - - -- Permissions - -- v_id_user := (SELECT id_user FROM Shop_User WHERE name = CURRENT_USER); - v_ids_permission_manufacturing_purchase_order := (SELECT STRING_AGG(id_permission, ',') FROM Shop_Permission WHERE code IN ('STORE_manufacturing', 'STORE_manufacturing_PURCHASE_ORDER')); - -- v_ids_permutation_permission := (SELECT STRING_AGG(id_permutation, ',') FROM tmp_Shop_Product WHERE NOT ISNULL(id_permutation)); - v_ids_product_permission := (SELECT STRING_AGG(P.id_product, ',') FROM (SELECT DISTINCT id_product FROM tmp_Shop_Product WHERE NOT ISNULL(id_product)) P); - - -- SELECT v_guid, v_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_permutation_permission; - -- select * from Shop_Calc_User_Temp; - - CALL p_shop_calc_user(v_guid, v_id_user, FALSE, v_ids_permission_manufacturing_purchase_order, v_id_access_level_view, v_ids_product_permission); - - -- select * from Shop_Calc_User_Temp; - - IF NOT EXISTS (SELECT can_view FROM Shop_Calc_User_Temp UE_T WHERE UE_T.GUID = v_guid) THEN - RAISE EXCEPTION 'You do not have view permissions for %', ( - SELECT STRING_AGG(name, ', ') - FROM Shop_Permission - WHERE id_permission = v_ids_permission_manufacturing_purchase_order - ) - USING ERRCODE = '42501' - ; - END IF; - - - UPDATE tmp_Shop_Product t_P - SET t_P.can_view = UE_T.can_view, - t_P.can_edit = UE_T.can_edit, - t_P.can_admin = UE_T.can_admin - FROM tmp_Shop_Product t_P - INNER JOIN Shop_Calc_User_Temp UE_T - ON t_P.id_product = UE_T.id_product -- t_P.id_permutation = UE_T.id_permutation - AND UE_T.GUID = v_guid - ; - - -- CALL p_shop_clear_calc_user(v_guid); - -- DROP TABLE IF EXISTS Shop_Calc_User_Temp; - DELETE FROM Shop_Calc_User_Temp - WHERE GUID = v_guid - ; - - - -- select * from tmp_Shop_Product; - - -- Returns - - -- manufacturing Purchase Order - OPEN result_orders FOR - SELECT -- * - t_MPO.id_order, - MPO.cost_total_local, - MPO.id_currency_cost, - MPO.value_produced_total_local, - t_MPO.active - FROM Shop_Manufacturing_Purchase_Order MPO - INNER JOIN tmp_Shop_Manufacturing_Purchase_Order t_MPO ON MPO.id_order = t_MPO.id_order - ; - RETURN NEXT result_orders; - - -- manufacturing Purchase Order Product Link - OPEN result_order_product_links FOR - SELECT - MPOPL.id_link, - MPOPL.id_order, - MPOPL.id_permutation, - P.name as name_product, - MPOPL.cost_total_local, - MPOPL.id_currency_cost, - MPOPL.value_produced_total_local, - MPOPL.quantity_used, - MPOPL.id_unit_quantity, - MPOPL.quantity_produced, - MPOPL.latency_manufacture, - MPOPL.display_order - FROM Shop_manufacturing_Purchase_Order_Product_Link MPOPL - -- INNER JOIN tmp_Shop_Manufacturing_Purchase_Order_Product_Link t_MPOPL ON MPOPL.id_link = t_MPOPL.id_link - INNER JOIN tmp_Shop_Manufacturing_Purchase_Order t_MPO ON MPOPL.id_order = t_MPO.id_order - INNER JOIN Shop_Product_Permutation PP ON MPOPL.id_permutation = PP.id_permutation - INNER JOIN Shop_Product P ON PP.id_product = P.id_product - INNER JOIN Shop_Product_Category C ON P.id_category = C.id_category - ORDER BY MPOPL.id_order, C.display_order, P.display_order, PP.display_order - ; - RETURN NEXT result_order_product_links; - - -- Errors - /* - SELECT - /* - t_ME.display_order, - t_ME.guid, - t_ME.id_type, - t_ME.msg, - MET.code, - MET.name, - MET.description - */ - * - FROM tmp_Msg_Error t_ME - INNER JOIN Shop_Msg_Error_Type MET - ON t_ME.id_type = MET.id_type - WHERE guid = v_guid - ; - OPEN result_errors FOR - SELECT * - FROM tmp_Msg_Error - ; - -- RETURN NEXT result_errors; - */ - - /* - -- Return arguments for test - SELECT - v_ids_category, - v_get_inactive_category, - v_ids_product, - v_get_inactive_product, - v_get_first_product_only, - v_get_all_product, - v_ids_image, - v_get_inactive_image, - v_get_first_image_only, - v_get_all_image - ; - */ - - -- select 'other outputs'; - -- select * from tmp_Shop_Product; - - -- Clean up - DROP TABLE IF EXISTS tmp_Shop_Manufacturing_Purchase_Order_Product_Link; - DROP TABLE IF EXISTS tmp_Shop_Manufacturing_Purchase_Order; - DROP TABLE IF EXISTS tmp_Shop_Product; - - DELETE FROM Shop_Calc_User_Temp - WHERE GUID = v_guid - ; -END; -$$ LANGUAGE plpgsql; - - -/* - - -DROP FUNCTION IF EXISTS fetch_results; - -CREATE OR REPLACE FUNCTION fetch_results() -RETURNS VOID AS $$ -DECLARE - curs refcursor; - rec record; -BEGIN - FOR curs IN SELECT p_shop_get_many_manufacturing_purchase_order ( - '', -- a_id_user - TRUE, -- a_get_all_order - FALSE, -- a_get_inactive_order - FALSE, -- a_get_first_order_only - '', -- a_ids_order - FALSE, -- a_get_inactive_category - '', -- a_ids_category - FALSE, -- a_get_inactive_product - '', -- a_ids_product - FALSE, -- a_get_inactive_permutation - '', -- a_ids_permutation - NULL, -- a_date_from - NULL -- a_date_to - ) LOOP - RAISE NOTICE 'Fetching from cursor: %', curs; - LOOP - FETCH curs INTO rec; - EXIT WHEN NOT FOUND; - RAISE NOTICE 'Record: %', rec; - END LOOP; - END LOOP; -END; -$$ LANGUAGE plpgsql; - -SELECT fetch_results(); - -*/ - diff --git a/static/PostgreSQL/709_p_shop_get_many_customer.sql b/static/PostgreSQL/709_p_shop_get_many_customer.sql deleted file mode 100644 index d75d1f02..00000000 --- a/static/PostgreSQL/709_p_shop_get_many_customer.sql +++ /dev/null @@ -1,249 +0,0 @@ - - -CREATE OR REPLACE FUNCTION p_shop_get_many_customer ( - IN a_id_user INTEGER, - IN a_get_all_customer BOOLEAN, - IN a_get_inactive_customer BOOLEAN, - IN a_get_first_customer_only BOOLEAN, - IN a_ids_customer INTEGER[] -) -RETURNS SETOF REFCURSOR -AS $$ -DECLARE - v_id_user INTEGER; - v_get_all_customer BOOLEAN; - v_get_inactive_customer BOOLEAN; - v_get_first_customer_only BOOLEAN; - v_ids_customer INTEGER[]; - v_has_filter_customer BOOLEAN; - v_guid UUID; - v_id_permission_customer INTEGER; - v_id_access_level_view INTEGER; - v_id_error_type_bad_data INTEGER; - v_code_error_type_bad_data VARCHAR(50); - result_customers REFCURSOR; - -- result_errors REFCURSOR; -BEGIN - v_id_user := TRIM(COALESCE(a_id_user, '')); - v_get_inactive_customer := COALESCE(a_get_inactive_customer, FALSE); - v_get_first_customer_only := COALESCE(a_get_first_customer_only, FALSE); - v_ids_customer := TRIM(COALESCE(a_ids_customer, '')); - v_get_all_customer := COALESCE(a_get_all_customer, CASE WHEN v_ids_customer = '' THEN TRUE ELSE FALSE END); - - - v_code_error_type_bad_data = 'BAD_DATA'; - v_id_error_type_bad_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_type_bad_data LIMIT 1); - v_guid := gen_random_uuid(); - v_id_access_level_view := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW'); - - v_has_filter_customer = CASE WHEN a_ids_customer = '' THEN FALSE ELSE TRUE END; - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Shop_Customer; - - CREATE TABLE tmp_Shop_Customer ( - id_customer INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Customer_id_customer - FOREIGN KEY (id_customer) - REFERENCES Shop_Customer(id_customer), - active BOOLEAN NOT NULL, - rank_customer INTEGER NULL, - can_view BOOLEAN, - can_edit BOOLEAN, - can_admin BIT - ); - - /* - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - guid UUID NOT NULL, - id_type INTEGER NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type (id_type), - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - */ - - -- select v_has_filter_product, v_has_filter_permutation; - - IF v_has_filter_customer = TRUE OR a_get_all_customer = TRUE THEN - IF EXISTS ( - SELECT * - FROM UNNEST(v_ids_customer) AS Customer_Id - LEFT JOIN Shop_Customer C ON Customer_Id = C.id_customer - WHERE ISNULL(C.id_customer) - ) THEN - RAISE EXCEPTION 'Invalid customer IDs: %', ( - SELECT STRING_AGG(Customer_Id, ', ') - FROM UNNEST(v_ids_customer) AS Customer_Id - LEFT JOIN Shop_Customer C ON Customer_Id = C.id_customer - WHERE ISNULL(C.id_customer) - LIMIT 1 - ) - USING ERRCODE = '22000' - ; - ELSE - INSERT INTO tmp_Shop_Customer ( - id_customer, - active, - rank_customer - ) - SELECT - C.id_customer, - C.active, - RANK() OVER (ORDER BY C.id_customer ASC) AS rank_customer - FROM Shop_Customer C - LEFT JOIN Split_Temp S_T ON C.id_customer = S_T.substring - WHERE - ( - a_get_all_customer = 1 - OR NOT ISNULL(S_T.substring) - ) - AND ( - a_get_inactive_customer = 1 - OR C.active = TRUE - ) - ; - END IF; - - IF a_get_first_customer_only = TRUE THEN - DELETE FROM tmp_Shop_Customer t_C - WHERE t_C.rank_customer > ( - SELECT MIN(t_C.rank_customer) - FROM tmp_Shop_Customer t_C - ) - ; - END IF; - END IF; - - -- Permissions - -- v_id_user := (SELECT id_user FROM Shop_User WHERE name = CURRENT_USER); - v_id_permission_customer := (SELECT id_permission FROM Shop_Permission WHERE code = 'STORE_CUSTOMER' LIMIT 1); - - -- SELECT v_guid, a_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_permutation_permission; - -- select * from Shop_Calc_User_Temp; - - CALL p_shop_calc_user(v_guid, a_id_user, FALSE, v_id_permission_customer, v_id_access_level_view, ''); - - -- select * from Shop_Calc_User_Temp; - - IF NOT EXISTS (SELECT can_view FROM Shop_Calc_User_Temp UE_T WHERE UE_T.GUID = v_guid) THEN - RAISE EXCEPTION 'You do not have view permissions for %', ( - SELECT COALESCE(STRING_AGG(name, ', '), 'NULL') - FROM Shop_Permission - WHERE id_permission = v_id_permission_customer - ) - USING ERRCODE = '42501' - ; - END IF; - - - -- select * from tmp_Shop_Product; - - -- Returns - -- v_now := CURRENT_TIMESTAMP; - - -- customers - OPEN result_customers FOR - SELECT - t_C.id_customer, - C.name_company, - C.name_contact, - C.department_contact, - C.id_address, - C.phone_number, - C.email, - C.id_currency, - C.active - FROM tmp_Shop_Customer t_C - INNER JOIN Shop_Customer C ON t_C.id_customer = C.id_customer - ; - RETURN NEXT result_customers; - - -- Errors - /* - SELECT - /* - t_ME.display_order, - t_ME.guid, - t_ME.id_type, - t_ME.msg, - MET.code, - MET.name, - MET.description - */ - * - FROM tmp_Msg_Error t_ME - INNER JOIN Shop_Msg_Error_Type MET - ON t_ME.id_type = MET.id_type - WHERE guid = v_guid - ; - OPEN result_errors FOR - SELECT * - FROM tmp_Msg_Error - ; - -- RETURN NEXT result_errors; - */ - - /* - -- Return arguments for test - SELECT - a_ids_category, - a_get_inactive_category, - a_ids_product, - a_get_inactive_product, - a_get_first_product_only, - a_get_all_product, - a_ids_image, - a_get_inactive_image, - a_get_first_image_only, - a_get_all_image - ; - */ - - -- select 'other outputs'; - -- select * from tmp_Shop_Product; - - -- Clean up - DROP TABLE IF EXISTS tmp_Shop_Customer; - - DELETE FROM Shop_Calc_User_Temp - WHERE GUID = v_guid - ; -END; -$$ LANGUAGE plpgsql; - - -/* - -DROP FUNCTION IF EXISTS fetch_results; - -CREATE OR REPLACE FUNCTION fetch_results() -RETURNS VOID AS $$ -DECLARE - curs refcursor; - rec record; -BEGIN - FOR curs IN SELECT p_shop_get_many_customer ( - '', -- a_id_user - 1, -- a_get_all_customer - 0, -- a_get_inactive_customer - 0, -- a_get_first_customer_only - '' -- a_ids_customer - ) LOOP - RAISE NOTICE 'Fetching from cursor: %', curs; - LOOP - FETCH curs INTO rec; - EXIT WHEN NOT FOUND; - RAISE NOTICE 'Record: %', rec; - END LOOP; - END LOOP; -END; -$$ LANGUAGE plpgsql; - -SELECT fetch_results(); - -*/ - diff --git a/static/PostgreSQL/710_p_shop_get_many_customer_sales_order.sql b/static/PostgreSQL/710_p_shop_get_many_customer_sales_order.sql deleted file mode 100644 index e880a2a0..00000000 --- a/static/PostgreSQL/710_p_shop_get_many_customer_sales_order.sql +++ /dev/null @@ -1,718 +0,0 @@ - - -CREATE OR REPLACE FUNCTION p_shop_get_many_customer_sales_order ( - IN a_id_user INTEGER, - IN a_get_all_customer BOOLEAN, - IN a_get_inactive_customer BOOLEAN, - IN a_get_first_customer_only BOOLEAN, - IN a_ids_customer INTEGER[], - IN a_get_all_order BOOLEAN, - IN a_get_inactive_order BOOLEAN, - IN a_get_first_order_only BOOLEAN, - IN a_ids_order INTEGER[], - IN a_get_inactive_category BOOLEAN, - IN a_ids_category INTEGER[], - IN a_get_inactive_product BOOLEAN, - IN a_ids_product INTEGER[], - IN a_get_inactive_permutation BOOLEAN, - IN a_ids_permutation INTEGER[], - IN a_date_from TIMESTAMP, - IN a_date_to TIMESTAMP -) -RETURNS SETOF REFCURSOR -AS $$ -DECLARE - v_id_user INTEGER; - v_get_all_customer BOOLEAN; - v_get_inactive_customer BOOLEAN; - v_get_first_customer_only BOOLEAN; - v_ids_customer INTEGER[]; - v_get_all_order BOOLEAN; - v_get_inactive_order BOOLEAN; - v_get_first_order_only BOOLEAN; - v_ids_order INTEGER[]; - v_get_inactive_category BOOLEAN; - v_ids_category INTEGER[]; - v_get_inactive_product BOOLEAN; - v_ids_product INTEGER[]; - v_get_inactive_permutation BOOLEAN; - v_ids_permutation INTEGER[]; - v_date_from TIMESTAMP; - v_date_to TIMESTAMP; - -- Argument redeclaration - -- Variable declaration - v_has_filter_customer BOOLEAN; - v_has_filter_order BOOLEAN; - v_has_filter_category BOOLEAN; - v_has_filter_product BOOLEAN; - v_has_filter_permutation BOOLEAN; - v_has_filter_date_from BOOLEAN; - v_has_filter_date_to BOOLEAN; - v_guid UUID; - -- v_id_user VARCHAR(100); - -- v_ids_permutation_unavailable VARCHAR(4000); - v_ids_permission_customer_purchase_order VARCHAR(4000); - v_ids_product_permission VARCHAR(4000); - -- v_ids_permutation_permission VARCHAR(4000); - v_id_access_level_view INTEGER; - -- v_now TIMESTAMP; - -- v_id_minimum INTEGER; - v_code_error_data VARCHAR(50); - v_id_type_error_data INTEGER; - result_customers REFCURSOR; - result_orders REFCURSOR; - result_order_product_links REFCURSOR; - -- result_errors REFCURSOR; -BEGIN - v_id_user := TRIM(COALESCE(a_id_user, '')); - v_get_inactive_customer := COALESCE(a_get_inactive_customer, FALSE); - v_get_first_customer_only := COALESCE(a_get_first_customer_only, FALSE); - v_ids_customer := TRIM(COALESCE(a_ids_customer, '')); - v_get_all_customer := COALESCE(a_get_all_customer, CASE WHEN v_ids_customer = '' THEN TRUE ELSE FALSE END); - v_get_inactive_order := COALESCE(a_get_inactive_order, FALSE); - v_get_first_order_only := COALESCE(a_get_first_order_only, FALSE); - v_ids_order := TRIM(COALESCE(a_ids_order, '')); - v_get_all_order := COALESCE(a_get_all_order, CASE WHEN v_ids_order = '' THEN TRUE ELSE FALSE END); - v_get_inactive_category := COALESCE(a_get_inactive_category, FALSE); - v_ids_category := TRIM(COALESCE(a_ids_category, '')); - v_get_inactive_product := COALESCE(a_get_inactive_product, FALSE); - v_ids_product := TRIM(COALESCE(a_ids_product, '')); - v_get_inactive_permutation := COALESCE(a_get_inactive_permutation, FALSE); - v_ids_permutation := TRIM(COALESCE(a_ids_permutation, '')); - v_date_from := a_date_from; - v_date_to := a_date_to; - - v_guid := gen_random_uuid(); - v_id_access_level_view := (SELECT id_access_level FROM Shop_Access_Level WHERE code = 'VIEW' LIMIT 1); - -- v_ids_permission_customer_purchase_order := (SELECT id_permission FROM Shop_Permission WHERE code = 'Shop_Customer_Sales_ORDER' LIMIT 1); - v_code_error_data := 'BAD_DATA'; - v_id_type_error_data := (SELECT id_type FROM Shop_Msg_Error_Type WHERE code = v_code_error_data); - - v_has_filter_category := CASE WHEN a_ids_category = '' THEN FALSE ELSE TRUE END; - v_has_filter_product := CASE WHEN a_ids_product = '' THEN FALSE ELSE TRUE END; - v_has_filter_permutation := CASE WHEN a_ids_permutation = '' THEN FALSE ELSE TRUE END; - v_has_filter_date_from := CASE WHEN ISNULL(a_date_from) THEN FALSE ELSE TRUE END; - v_has_filter_date_to := CASE WHEN ISNULL(a_date_to) THEN FALSE ELSE TRUE END; - - - -- Temporary tables - DROP TABLE IF EXISTS tmp_Shop_Customer_Sales_Order_Product_Link; - DROP TABLE IF EXISTS tmp_Shop_Customer_Sales_Order; - DROP TABLE IF EXISTS tmp_Shop_Customer; - DROP TABLE IF EXISTS tmp_Shop_Product; - - CREATE TABLE tmp_Shop_Customer ( - id_customer INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Customer_id_customer - FOREIGN KEY (id_customer) - REFERENCES Shop_Customer(id_customer), - active BOOLEAN NOT NULL, - rank_customer INTEGER NULL, - can_view BOOLEAN, - can_edit BOOLEAN, - can_admin BIT - ); - - CREATE TABLE tmp_Shop_Customer_Sales_Order ( - id_order INTEGER NOT NULL PRIMARY KEY, - /* - id_customer INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Customer_Sales_Order_id_customer - FOREIGN KEY (id_customer) - REFERENCES Shop_Customer(id_customer), - price_total_local REAL NOT NULL, - id_currency_price INTEGER NOT NULL, - */ - active BOOLEAN NOT NULL, - rank_order INTEGER NOT NULL - ); - - /* - CREATE TABLE tmp_Shop_Customer_Sales_Order_Product_Link ( - id_link INTEGER NOT NULL PRIMARY KEY, - id_order INTEGER NOT NULL, - CONSTRAINT FK_tmp_customer_Purchase_Order_Product_Link_id_order - FOREIGN KEY (id_order) - REFERENCES Shop_Customer_Sales_Order(id_order), - id_permutation INTEGER NOT NULL, - CONSTRAINT FK_tmp_customer_Purchase_Order_Product_Link_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - price_total_local REAL NOT NULL, - id_currency_price INTEGER NOT NULL, - quantity_ordered REAL NOT NULL, - id_unit_quantity INTEGER NOT NULL, - CONSTRAINT FK_tmp_customer_Purchase_Order_Product_Link_id_unit_quantity - FOREIGN KEY (id_unit_quantity) - REFERENCES Shop_Unit_Measurement(id_unit_measurement), - quantity_received REAL NULL, - latency_delivery_days INTEGER NOT NULL, - display_order INTEGER NOT NULL - ); - */ - - CREATE TABLE tmp_Shop_Product ( - id_category INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_category - FOREIGN KEY (id_category) - REFERENCES Shop_Product_Category(id_category), - id_product INTEGER NOT NULL, - CONSTRAINT FK_tmp_Shop_Product_id_product - FOREIGN KEY (id_product) - REFERENCES Shop_Product(id_product), - -- product_has_variations BOOLEAN NOT NULL, - id_permutation INTEGER NULL, - CONSTRAINT FK_tmp_Shop_Product_id_permutation - FOREIGN KEY (id_permutation) - REFERENCES Shop_Product_Permutation(id_permutation), - active_category BOOLEAN NOT NULL, - active_product BOOLEAN NOT NULL, - active_permutation BOOLEAN NULL, - display_order_category INTEGER NOT NULL, - display_order_product INTEGER NOT NULL, - display_order_permutation INTEGER NULL, - rank_permutation INTEGER NOT NULL, -- _in_category - -- name VARCHAR(255) NOT NULL, - -- description VARCHAR(4000) NOT NULL, - /* - price_GBP_full REAL NOT NULL, - price_GBP_min REAL NOT NULL, - */ - /* - latency_manufacture INTEGER NOT NULL, - quantity_min REAL NOT NULL, - quantity_max REAL NOT NULL, - quantity_step REAL NOT NULL, - quantity_stock REAL NOT NULL, - is_subscription BOOLEAN NOT NULL, - id_unit_measurement_interval_recurrence INTEGER, - CONSTRAINT FK_tmp_Shop_Product_id_unit_measurement_interval_recurrence - FOREIGN KEY (id_unit_measurement_interval_recurrence) - REFERENCES Shop_Interval_Recurrence(id_interval), - count_interval_recurrence INTEGER, - id_stripe_product VARCHAR(100), - product_has_variations INTEGER NOT NULL, - */ - can_view BOOLEAN, - can_edit BOOLEAN, - can_admin BIT - ); - - /* - CREATE TABLE IF NOT EXISTS tmp_Msg_Error ( - display_order INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, - guid UUID NOT NULL, - id_type INTEGER NOT NULL, - CONSTRAINT FK_tmp_Msg_Error_id_type - FOREIGN KEY (id_type) - REFERENCES Shop_Msg_Error_Type (id_type), - code VARCHAR(50) NOT NULL, - msg VARCHAR(4000) NOT NULL - ); - */ - - -- select v_has_filter_product, v_has_filter_permutation; - - IF v_has_filter_customer = TRUE OR a_get_all_customer = TRUE THEN - IF EXISTS ( - SELECT * - FROM UNNEST(v_ids_customer) AS Customer_Id - LEFT JOIN Shop_Customer C ON Customer_Id = C.id_customer - WHERE ISNULL(C.id_customer) - LIMIT 1 - ) THEN - RAISE EXCEPTION 'Invalid customer IDs: %', ( - SELECT STRING_AGG(Customer_Id, ', ') - FROM UNNEST(v_ids_customer) AS Customer_Id - LEFT JOIN Shop_Customer C ON Customer_Id = C.id_customer - WHERE ISNULL(C.id_customer) - ) - USING ERRCODE = '22000' - ; - ELSE - INSERT INTO tmp_Shop_Customer ( - id_customer, - active, - rank_customer - ) - SELECT - C.id_customer, - C.active, - RANK() OVER (ORDER BY id_customer ASC) AS rank_customer - FROM Shop_Customer C - -- LEFT JOIN Split_Temp S_T ON C.id_customer = S_T.substring - WHERE - ( - a_get_all_customer = TRUE - -- OR NOT ISNULL(S_T.substring) - OR C.id_customer = ANY(v_ids_customer) - ) - AND ( - a_get_inactive_customer - OR C.active = TRUE - ) - ; - END IF; - - IF a_get_first_customer_only THEN - DELETE FROM tmp_Shop_Customer t_C - WHERE t_C.rank_customer > ( - SELECT MIN(t_C.rank_customer) - FROM tmp_Shop_Customer t_C - ) - ; - END IF; - END IF; - - IF v_has_filter_category = TRUE AND EXISTS ( - SELECT STRING_AGG(Category_Id, ', ') - FROM UNNEST(v_ids_category) AS Category_Id - LEFT JOIN Shop_Product_Category C ON Category_Id = C.id_customer - WHERE ISNULL(C.id_customer) - LIMIT 1 - ) THEN - RAISE EXCEPTION 'Invalid category IDs: %', ( - SELECT STRING_AGG(Category_Id, ', ') - FROM UNNEST(v_ids_category) AS Category_Id - LEFT JOIN Shop_Product_Category C ON Category_Id = C.id_customer - WHERE ISNULL(C.id_customer) - ) - USING ERRCODE = '22000' - ; - END IF; - - IF v_has_filter_product = TRUE AND EXISTS ( - SELECT * - FROM UNNEST(v_ids_product) AS Product_Id - LEFT JOIN Shop_Product P ON Product_Id = P.id_product - WHERE ISNULL(P.id_product) - LIMIT 1 - ) THEN - RAISE EXCEPTION 'Invalid product IDs: %', ( - SELECT COALESCE(STRING_AGG(Product_Id, ', ') ,'NULL') - FROM UNNEST(v_ids_product) AS Product_Id - LEFT JOIN Shop_Product P ON Product_Id = P.id_product - WHERE ISNULL(P.id_product) - ) - USING ERRCODE = '22000' - ; - END IF; - - IF v_has_filter_permutation = TRUE AND EXISTS ( - SELECT * - FROM UNNEST(v_ids_permutation) AS Permutation_Id - LEFT JOIN Shop_Product_Permutation PP ON Permutation_Id = PP.id_permutation - WHERE ISNULL(PP.id_permutation) - LIMIT 1 - ) THEN - RAISE EXCEPTION 'Invalid permutation IDs: %', ( - SELECT STRING_AGG(Permutation_Id, ', ') - FROM UNNEST(v_ids_permutation) AS Permutation_Id - LEFT JOIN Shop_Product_Permutation PP ON Permutation_Id = PP.id_permutation - WHERE ISNULL(PP.id_permutation) - ) - USING ERRCODE = '22000' - ; - END IF; - - IF v_has_filter_category = TRUE OR v_has_filter_product = TRUE OR v_has_filter_permutation = TRUE THEN - INSERT INTO tmp_Shop_Product ( - id_category, - id_product, - id_permutation, - active_category, - active_product, - active_permutation, - display_order_category, - display_order_product, - display_order_permutation - -- rank_permutation, - /* - name, - description, - /* - price_GBP_VAT_incl, - price_GBP_VAT_excl, - price_GBP_min, - */ - latency_manufacture, - quantity_min, - quantity_max, - quantity_step, - quantity_stock, - is_subscription, - id_unit_measurement_interval_recurrence, - count_interval_recurrence, - id_stripe_product, - product_has_variations - */ - ) - SELECT - P.id_category, - P.id_product, - -- P.has_variations AS product_has_variations, - PP.id_permutation, - C.active AS active_category, - P.active AS active_product, - PP.active AS active_permutation, - C.display_order AS display_order_category, - P.display_order AS display_order_product, - PP.display_order AS display_order_permutation - -- RANK() OVER (ORDER BY C.display_order, P.display_order, PP.display_order) AS rank_permutation, #PARTITION BY P.id_category -- _in_category - /* - P.name, - PP.description, - /* - PP.price_GBP_VAT_incl, - PP.price_GBP_VAT_excl, - PP.price_GBP_min, - */ - PP.latency_manufacture, - PP.quantity_min, - PP.quantity_max, - PP.quantity_step, - PP.quantity_stock, - PP.is_subscription, - PP.id_unit_measurement_interval_recurrence, - PP.count_interval_recurrence, - PP.id_stripe_product, - P.has_variations - */ - FROM Shop_Product P - INNER JOIN Shop_Product_Permutation PP - ON P.id_product = PP.id_product - INNER JOIN Shop_Product_Category C - ON P.id_category = C.id_category - WHERE - -- permutations - ( - ( - NOT v_has_filter_permutation - OR FIND_IN_SET(PP.id_permutation, a_ids_permutation) > 0 - ) - AND ( - a_get_inactive_permutation - OR PP.active = TRUE - ) - ) - -- categories - AND ( - ( - NOT v_has_filter_category - OR FIND_IN_SET(P.id_category, a_ids_category) > 0 - ) - AND ( - a_get_inactive_category - OR C.active = TRUE - ) - ) - -- products - AND ( - ( - NOT v_has_filter_product - OR FIND_IN_SET(P.id_product, a_ids_product) > 0 - ) - AND ( - a_get_inactive_product - OR P.active = TRUE - ) - ) - ; - END IF; - - -- Get orders - IF v_has_filter_order AND EXISTS ( - SELECT * - FROM UNNEST(v_ids_order) AS Order_Id - LEFT JOIN Shop_Customer_Sales_Order CSO ON Order_Id = CSO.id_order - WHERE ISNULL(CSO.id_order) - LIMIT 1 - ) THEN - RAISE EXCEPTION 'Invalid order IDs: %', ( - SELECT STRING_AGG(Order_Id, ', ') - FROM UNNEST(v_ids_order) AS Order_Id - LEFT JOIN Shop_Customer_Sales_Order CSO ON Order_Id = CSO.id_order - WHERE ISNULL(CSO.id_order) - ) - USING ERRCODE = '22000' - ; - END IF; - - INSERT INTO tmp_Shop_Customer_Sales_Order ( -- _Product_Link - id_order, - active, - rank_order - ) - SELECT - CSO.id_order, - CSO.active, - RANK() OVER (ORDER BY CSO.id_order ASC) AS rank_order - FROM Shop_Customer_Sales_Order CSO - -- LEFT JOIN Split_Temp S_T ON CSO.id_order = S_T.substring - INNER JOIN Shop_Customer_Sales_Order_Product_Link CSOPL ON CSO.id_order = CSOPL.id_order - INNER JOIN Shop_Customer S ON CSO.id_customer = S.id_customer - INNER JOIN Shop_Product_Permutation PP ON CSOPL.id_permutation = PP.id_permutation - INNER JOIN Shop_Product P ON PP.id_product = P.id_product - INNER JOIN Shop_Product_Category C ON P.id_category = C.id_category - LEFT JOIN tmp_Shop_Product t_P ON CSOPL.id_permutation = t_P.id_permutation - LEFT JOIN tmp_Shop_Customer t_S ON CSO.id_customer = t_S.id_customer - WHERE - -- customer - /* - ( - a_get_all_customer = 1 - OR NOT ISNULL(t_S.id_customer) -- CSO.id_customer IN (SELECT DISTINCT id_customer FROM tmp_Shop_Customer) - ) - */ - NOT ISNULL(t_S.id_customer) - -- order - AND ( - ( - a_get_all_order = 1 - OR ( - -- ID - -- FIND_IN_SET(CSO.id_order, a_ids_order) > 0 - -- NOT ISNULL(S_T.substring) - CSO.id_order = ANY(v_ids_order) - -- date - AND ( - ( - v_has_filter_date_from = 0 - OR CSO.created_on > a_date_from - ) - AND ( - v_has_filter_date_to = 0 - OR CSO.created_on < a_date_to - ) - ) - ) - ) - -- active - AND ( - a_get_inactive_order - OR CSO.active = TRUE - ) - ) - -- permutations - AND ( - ( - v_has_filter_category = FALSE - AND v_has_filter_product = FALSE - AND v_has_filter_permutation = 0 - ) - OR NOT ISNULL(t_P.id_permutation) -- CSO.id_permutation IN (SELECT DISTINCT id_permutation FROM tmp_Shop_Product) - ) - ; - - IF a_get_first_order_only THEN - DELETE FROM tmp_Shop_Customer_Sales_Order t_CSO - WHERE t_CSO.rank_order > ( - SELECT MIN(t_CSO.rank_order) - FROM tmp_Shop_Customer_Sales_Order t_CSO - ) - ; - END IF; - - -- Permissions - -- v_id_user := (SELECT id_user FROM Shop_User WHERE name = CURRENT_USER); - v_ids_permission_customer_purchase_order := (SELECT STRING_AGG(id_permission, ',') FROM Shop_Permission WHERE code IN ('STORE_customer', 'STORE_customer_PURCHASE_ORDER')); - -- v_ids_permutation_permission := (SELECT STRING_AGG(id_permutation, ',') FROM tmp_Shop_Product WHERE NOT ISNULL(id_permutation)); - v_ids_product_permission := (SELECT STRING_AGG(P.id_product, ',') FROM (SELECT DISTINCT id_product FROM tmp_Shop_Product WHERE NOT ISNULL(id_product)) P); - - -- SELECT v_guid, a_id_user, false, v_id_permission_product, v_id_access_level_view, v_ids_permutation_permission; - -- select * from Shop_Calc_User_Temp; - - CALL p_shop_calc_user(v_guid, a_id_user, FALSE, v_ids_permission_customer_purchase_order, v_id_access_level_view, v_ids_product_permission); - - -- select * from Shop_Calc_User_Temp; - - IF NOT EXISTS (SELECT can_view FROM Shop_Calc_User_Temp UE_T WHERE UE_T.GUID = v_guid) THEN - RAISE EXCEPTION 'You do not have view permissions for %', ( - SELECT COALESCE(STRING_AGG(name, ', '), 'NULL') - FROM Shop_Permission - WHERE id_permission = v_ids_permission_customer_purchase_order - ) - USING ERRCODE = '42501' - ; - END IF; - - - UPDATE tmp_Shop_Product t_P - SET t_P.can_view = UE_T.can_view, - t_P.can_edit = UE_T.can_edit, - t_P.can_admin = UE_T.can_admin - FROM tmp_Shop_Product t_P - INNER JOIN Shop_Calc_User_Temp UE_T - ON t_P.id_product = UE_T.id_product -- t_P.id_permutation = UE_T.id_permutation - AND UE_T.GUID = v_guid - ; - - -- CALL p_shop_clear_calc_user(v_guid); - -- DROP TABLE IF EXISTS Shop_Calc_User_Temp; - DELETE FROM Shop_Calc_User_Temp - WHERE GUID = v_guid - ; - - - -- select * from tmp_Shop_Customer; - -- select * from tmp_Shop_Product; - - -- Returns - -- v_now := CURRENT_TIMESTAMP; - - -- customers - OPEN result_customers FOR - SELECT - t_S.id_customer, - S.name_company, - S.name_contact, - S.department_contact, - S.id_address, - S.phone_number, - S.email, - S.id_currency, - t_S.active - FROM tmp_Shop_Customer t_S - INNER JOIN Shop_Customer S - ON t_S.id_customer = S.id_customer - ; - RETURN NEXT result_customers; - - -- Customer Sales Order - OPEN result_orders FOR - SELECT -- * - t_CSO.id_order, - CSO.id_customer, - CSO.price_total_local, - CSO.id_currency_price, - t_CSO.active - FROM Shop_Customer_Sales_Order CSO - INNER JOIN tmp_Shop_Customer_Sales_Order t_CSO ON CSO.id_order = t_CSO.id_order - ; - RETURN NEXT result_orders; - - -- Customer Sales Order Product Link - OPEN result_order_product_links FOR - SELECT - CSOPL.id_link, - CSOPL.id_order, - CSOPL.id_permutation, - P.name as name_product, - CSOPL.price_total_local, - CSOPL.id_currency_price, - CSOPL.quantity_ordered, - CSOPL.id_unit_quantity, - CSOPL.quantity_delivered, - CSOPL.latency_delivery_days, - CSOPL.display_order - FROM Shop_Customer_Sales_Order_Product_Link CSOPL - -- INNER JOIN tmp_Shop_Customer_Sales_Order_Product_Link t_CSOPL ON CSOPL.id_link = t_CSOPL.id_link - INNER JOIN tmp_Shop_Customer_Sales_Order t_CSO ON CSOPL.id_order = t_CSO.id_order - INNER JOIN Shop_Product_Permutation PP ON CSOPL.id_permutation = PP.id_permutation - INNER JOIN Shop_Product P ON PP.id_product = P.id_product - INNER JOIN Shop_Product_Category C ON P.id_category = C.id_category - ORDER BY CSOPL.id_order, C.display_order, P.display_order, PP.display_order - ; - RETURN NEXT result_order_product_links; - - -- Errors - /* - SELECT - /* - t_ME.display_order, - t_ME.guid, - t_ME.id_type, - t_ME.msg, - MET.code, - MET.name, - MET.description - */ - * - FROM tmp_Msg_Error t_ME - INNER JOIN Shop_Msg_Error_Type MET - ON t_ME.id_type = MET.id_type - WHERE guid = v_guid - ; - OPEN result_errors FOR - SELECT * - FROM tmp_Msg_Error - ; - -- RETURN NEXT result_errors; - */ - - /* - -- Return arguments for test - SELECT - a_ids_category, - a_get_inactive_category, - a_ids_product, - a_get_inactive_product, - a_get_first_product_only, - a_get_all_product, - a_ids_image, - a_get_inactive_image, - a_get_first_image_only, - a_get_all_image - ; - */ - - -- select 'other outputs'; - -- select * from tmp_Shop_Product; - - -- Clean up - DROP TABLE IF EXISTS tmp_Shop_Customer_Sales_Order_Product_Link; - DROP TABLE IF EXISTS tmp_Shop_Customer_Sales_Order; - DROP TABLE IF EXISTS tmp_Shop_Customer; - DROP TABLE IF EXISTS tmp_Shop_Product; - - DELETE FROM Shop_Calc_User_Temp - WHERE GUID = v_guid - ; -END; -$$ LANGUAGE plpgsql; - - -/* - - -DROP FUNCTION IF EXISTS fetch_results; - -CREATE OR REPLACE FUNCTION fetch_results() -RETURNS VOID AS $$ -DECLARE - curs refcursor; - rec record; -BEGIN - FOR curs IN SELECT p_shop_get_many_customer_sales_order ( - '', -- a_id_user - 1, -- a_get_all_customer - 0, -- a_get_inactive_customer - 0, -- a_get_first_customer_only - '', -- a_ids_customer - 1, -- a_get_all_order - 0, -- a_get_inactive_order - 0, -- a_get_first_order_only - '', -- a_ids_order - 0, -- a_get_inactive_category - '', -- a_ids_category - 0, -- a_get_inactive_product - '', -- a_ids_product - 0, -- a_get_inactive_permutation - '', -- a_ids_permutation - NULL, -- a_date_from - NULL -- a_date_to - ) LOOP - RAISE NOTICE 'Fetching from cursor: %', curs; - LOOP - FETCH curs INTO rec; - EXIT WHEN NOT FOUND; - RAISE NOTICE 'Record: %', rec; - END LOOP; - END LOOP; -END; -$$ LANGUAGE plpgsql; - -SELECT fetch_results(); - -*/ - diff --git a/static/PostgreSQL/900_populate.sql b/static/PostgreSQL/900_populate.sql deleted file mode 100644 index 4122763b..00000000 --- a/static/PostgreSQL/900_populate.sql +++ /dev/null @@ -1,656 +0,0 @@ - - -DO $$ -BEGIN - RAISE NOTICE 'PROCEDURE CREATION COMPLETE'; -END $$; - -/* - -CALL p_populate_database () - -*/ - -/* --- Remove previous proc -DROP PROCEDURE IF EXISTS p_populate_database; - - -DELIMITER // -CREATE OR REPLACE PROCEDURE p_populate_database () -BEGIN -*/ - - --- Access Levels -INSERT INTO Shop_Access_Level ( - display_order, code, name, priority -) -VALUES - (1, 'VIEW', 'View', 3), - (2, 'EDIT', 'Edit', 2), - (3, 'ADMIN', 'Admin', 1) -; - --- Error Message Types -INSERT INTO Shop_Msg_Error_Type ( - code, name, description -) -VALUES - ('BAD_DATA', 'Invalid data', 'Rubbish data'), - ('NO_PERMISSION', 'No permission', 'Not authorised'), - ('PRODUCT_AVAILABILITY', 'Product not available', 'Product not available') -; - --- File Types -INSERT INTO File_Type ( - code, name, extension -) -VALUES - ('JPEG', 'Joint Photographic Export Group', 'jpg'), - ('PNG', 'Portable Network Graphic', 'png'), - ('GIF', 'GIF', 'gif'), - ('MPEG-4', 'Multimedia Photographic Export Group 4', 'mp4') -; - --- Generic / shared properties -INSERT INTO Shop_General ( - quantity_max -) -VALUES ( - 10 -); - --- Categories -INSERT INTO Shop_Product_Category ( - display_order, - code, - name, - description -) -VALUES - (1, 'ASS', 'Assistive Devices', 'Braille product line and other assistive devices'), - (99, 'MISC', 'Miscellaneous', 'Not category allocated products'), - (2, 'TECH', 'Technology', 'Technological devices') -; - --- Recurrence Interval -INSERT INTO Shop_Interval_Recurrence ( - code, name, name_plural -) -VALUES - ('WEEK', 'Week', 'Weeks'), - ('MONTH', 'Month', 'Months'), - ('YEAR', 'Year', 'Years') -; - -INSERT INTO Shop_Region ( - display_order, code, name -) -VALUES - (1, 'UK', 'United Kingdom') -; - -/* -INSERT INTO Shop_Region_Branch ( - display_order, id_region_parent, id_region_child -) -VALUES - (1, 1, 2) -; -*/ - --- Currency -INSERT INTO Shop_Currency ( - display_order, code, name, symbol, factor_from_GBP -) -VALUES - (1, 'GBP', 'Great British Pound', '£', 1), - (2, 'EUR', 'Euro', '€', 1.17) -; - --- Taxes and Surcharges -INSERT INTO Shop_Tax_Or_Surcharge ( - display_order, - code, - name, - id_region_buyer, - id_region_seller, - fixed_fee, - multiplier, - apply_fixed_fee_before_multiplier, - quantity_min, - quantity_max -) -VALUES - (1, 'VAT', 'Value Added Tax', 1, 1, 0, 0.2, TRUE, 0, 1) -; - --- Products -INSERT INTO Shop_Product ( - display_order, - id_category, - name, - has_variations, - id_access_level_required -) -VALUES - ( - 1, - 1, - 'Braille Keyboard Translator', - TRUE, - 3 - ), - ( - 2, - 2, - 'Test product 1', - FALSE, - 3 - ), - ( - 3, - 3, - 'Phone', - FALSE, - 1 - ), - ( - 4, - 3, - 'Laptop', - FALSE, - 1 - ), - ( - 5, - 3, - 'Smart Watch', - FALSE, - 1 - ) -; - --- Variation Types -INSERT INTO Shop_Variation_Type ( - display_order, code, name, name_plural -) -VALUES - (1, 'COLOUR', 'Colour', 'Colours') -; - --- Variations -INSERT INTO Shop_Variation ( - display_order, id_type, code, name -) -VALUES - (1, 1, 'RED', 'Red'), - (2, 1, 'BLUE', 'Blue') -; - --- Product Permutations -INSERT INTO Shop_Product_Permutation ( - display_order, - id_product, - description, - cost_local, - id_currency_cost, - profit_local_min, - -- id_currency_profit_min, - latency_manufacture, - quantity_min, - quantity_max, - quantity_step, - quantity_stock, - is_subscription, - id_unit_measurement_interval_recurrence, - count_interval_recurrence, - -- id_access_level_required, - id_stripe_product -) -VALUES - ( - 1, - 1, - 'Good Red', - 5, - 1, - 3, - -- 1, - 14, - 1, - 3, - 1, - 99, - FALSE, - NULL, - NULL, - -- 1, - NULL - ), - ( - 2, - 1, - 'Good Blue', - 6, - 1, - 4, - -- 1, - 14, - 1, - 3, - 1, - 99, - FALSE, - NULL, - NULL, - -- 1, - NULL - ), - ( - 3, - 2, - 'Test product describes good', - 10, - 1, - 5, - -- 1, - 14, - 1, - 2, - 1, - 99, - FALSE, - NULL, - NULL, - -- 1, - NULL - ), - ( - 4, - 3, - 'Phone describes good', - 10, - 1, - 5, - -- 1, - 14, - 1, - 2, - 1, - 99, - FALSE, - NULL, - NULL, - -- 1, - NULL - ), - ( - 5, - 4, - 'Laptop describes good', - 10, - 1, - 5, - -- 1, - 14, - 1, - 2, - 1, - 99, - FALSE, - NULL, - NULL, - -- 1, - NULL - ), - ( - 6, - 5, - 'Smart watch describes good', - 10, - 1, - 5, - -- 1, - 14, - 1, - 2, - 1, - 99, - FALSE, - NULL, - NULL, - -- 1, - NULL - ) -; - --- Product Permutation Variation Links -INSERT INTO Shop_Product_Permutation_Variation_Link ( - display_order, id_permutation, id_variation -) -VALUES - (1, 1, 1), - (2, 2, 2) -; - --- Product Currency Link -INSERT INTO Shop_Product_Currency_Region_Link ( - id_product, id_permutation, id_currency, id_region_purchase, price_local_VAT_incl, price_local_VAT_excl -) -VALUES - (1, 1, 1, 1, 24, 20), - (1, 1, 2, 1, 48, 40), - (1, 2, 1, 1, 96, 80), - (2, 3, 1, 1, 144, 120), - (3, 4, 1, 1, 600, 500), - (4, 5, 1, 1, 1500, 1200), - (5, 6, 1, 1, 180, 150) -; - -INSERT INTO Shop_Image_Type ( - display_order, code, name, name_plural -) -VALUES - (1, 'FULL', 'Full Quality Image', 'Full Quality Images'), - (2, 'LOW', 'Low Quality Image', 'Low Quality Images'), - (3, 'THUMBNAIL', 'Thumbnail Image', 'Thumbnail Images') -; - -INSERT INTO Shop_Image ( - display_order, id_product, id_permutation, id_type_image, id_type_file, url -) -VALUES - (1, 1, 1, 1, 1, '/static/images/prod_PB0NUOSEs06ymG.jpg'), - -- (1, NULL, 1, 1, 1, '/static/images/prod_PB0NUOSEs06ymG.jpg'), - (2, 1, 2, 1, 1, '/static/images/prod_PB0NUOSEs06ymG.jpg'), - -- (1, NULL, 2, 1, 1, '/static/images/prod_PB0NUOSEs06ymG.jpg') - (3, 2, 3, 1, 1, '/static/images/prod_PB0NUOSEs06ymG.jpg'), - (4, 3, 4, 1, 1, '/static/images/prod_.jpg'), - (5, 4, 5, 1, 1, '/static/images/prod_1.jpg'), - (6, 5, 6, 1, 1, '/static/images/prod_2.jpg') -; - -INSERT INTO Shop_Delivery_Option ( - display_order, code, name, latency_delivery_min, latency_delivery_max, quantity_min, quantity_max -) -VALUES - (1, 'COLLECT', 'Collection', 0, 0, 0, 1), - (2, 'SIGNED_1', 'First Class Signed-For', 2, 4, 0, 1) -; - -INSERT INTO Shop_Product_Permutation_Delivery_Option_Link ( - display_order, id_product, id_permutation, id_delivery_option, id_region, id_currency, price_local -) -VALUES - (1, 1, 1, 1, 1, 1, 5), - (2, 1, 2, 1, 1, 1, 9), - (3, 2, NULL, 1, 1, 1, 10), - (4, 3, 4, 1, 1, 1, 10), - (5, 4, 5, 1, 1, 1, 10), - (6, 5, 6, 1, 1, 1, 10) -; - --- Discounts -INSERT INTO Shop_Discount ( - id_product, - id_permutation, - code, - name, - multiplier, - quantity_min, - quantity_max, - date_start, - date_end, - display_order -) -VALUES - (1, 1, 'CRIMBO50', 'Christmas 50% off sale!', 0.5, 3, 9, CURRENT_TIMESTAMP, '2023-12-31 23:59:59', 1), - (1, 2, 'CRIMBO50', 'Christmas 50% off sale!', 0.5, 3, 9, CURRENT_TIMESTAMP, '2023-12-31 23:59:59', 1) -; - --- Discount Delivery Region Links -INSERT INTO Shop_Discount_Region_Currency_Link ( - id_discount, - id_region, - id_currency -) -VALUES - (1, 1, 1), - (2, 1, 1), - (1, 1, 2), - (2, 1, 2) -; - --- Permission Groups -INSERT INTO Shop_Permission_Group ( - display_order, code, name -) -VALUES - (0, 'ADMIN', 'Website Admin'), - (1, 'HOME', 'Home, Contact Us, and other public information'), - (2, 'PRODUCT', 'Store Products'), - (3, 'USER', 'Store User'), - (4, 'SALES_AND_PURCHASING', 'Sales and Purchasing'), - (5, 'MANUFACTURING', 'Manufacturing') -; - --- Permissions -INSERT INTO Shop_Permission ( - display_order, code, name, id_permission_group, id_access_level_required -) -VALUES - (1, 'HOME', 'Home Page', 2, 1), - (2, 'STORE_PRODUCT', 'Store Product Page', 3, 1), - (3, 'STORE_USER', 'Store User Account Page', 4, 2), - (4, 'STORE_ADMIN', 'Store Admin Page', 1, 3), - (5, 'STORE_SUPPLIER', 'Store Supplier Page', 4, 2), - (6, 'STORE_SUPPLIER_PURCHASE_ORDER', 'Store Supplier Purchase Order Page', 4, 2), - (7, 'STORE_MANUFACTURING_PURCHASE_ORDER', 'Store Manufacturing Purchase Order Page', 5, 2), - (8, 'STORE_CUSTOMER', 'Store Customer Page', 4, 2), - (9, 'STORE_CUSTOMER_SALES_ORDER', 'Store Customer Sales Order Page', 4, 2), - (99, 'CONTACT_US', 'Contact Us Page', 2, 1) -; - --- Roles -INSERT INTO Shop_Role ( - display_order, - code, - name -) -VALUES - (1, 'DIRECTOR', 'Director'), - (2, 'USER', 'User') -; - --- Role Permission link -INSERT INTO Shop_Role_Permission_Link ( - id_role, id_permission, id_access_level -) -VALUES - (1, 1, 3), - (1, 2, 3), - (1, 3, 3), - (1, 4, 3), - (1, 5, 3), - (2, 1, 1), - (2, 2, 1), - (2, 3, 1), - (2, 4, 1), - (2, 5, 1) -; - --- Users -INSERT INTO Shop_User ( - id_user_oauth, - name, - email, - -- is_email_verified, - is_super_user -) -VALUES - ('auth0|6582b95c895d09a70ba10fef', 'Teddy', 'edward.middletonsmith@gmail.com', TRUE), - ('parts_guest', 'Guest', '', FALSE) -; - --- User Role link -INSERT INTO Shop_User_Role_Link ( - id_user, id_role -) -VALUES - (1, 1) -; - --- Addresses -INSERT INTO Shop_Address ( - -- id_user, - id_region, name_full, phone_number, postcode, address_line_1, address_line_2, city, county -) -VALUES (1, 'Edward M-S', '07375 571430', 'CV22 6DN', '53 Alfred Green Close', '', 'Rugby', 'Warwickshire') -/* -SELECT U.id_user, 1, U.name, '07375 571430', 'CV22 6DN', '53 Alfred Green Close', '', 'Rugby', 'Warwickshire' - FROM Shop_User U -*/ -; - --- User Basket -INSERT INTO Shop_User_Basket ( - id_user, - id_product, - id_permutation, - quantity -) -VALUES - (1, 1, 1, 69) -; - --- User Order Status -INSERT INTO Shop_User_Order_Status ( - display_order, code, name, name_plural -) -VALUES - (1, 'SUCCESS', 'Success', 'Successes'), - (2, 'FAIL', 'Failure', 'Failures') -; - -/* --- User Order -INSERT INTO Shop_User_Order ( - id_user, value_total, id_order_status, id_checkout_session, id_currency -) -VALUES - (1, 25, 1, 'noods', 1), - (1, 25, 1, 'noods', 1) -; - --- User Order Product Link -INSERT INTO Shop_User_Order_Product_Link ( - id_order, id_product, id_permutation, quantity -) -VALUES - (1, 1, 1, 69), - (1, 2, NULL, 69), - (1, 1, 2, 69) -; -*/ - --- Supplier -INSERT INTO Shop_Supplier ( - name_company, name_contact, department_contact, id_address, phone_number, fax, email, website, id_currency -) -VALUES - ('Precision And Research Technology Systems Limited', 'Teddy Middleton-Smith', 'Executive Management', 1, '07375571430', '', 'teddy@partsltd.co.uk', 'www.partsltd.co.uk', 1) -; - --- Unit of Measurement -INSERT INTO Shop_Unit_Measurement ( - name_singular, name_plural, symbol, is_base_unit -) -VALUES - ('metre', 'metres', 'm', TRUE), - ('kilogram', 'kilograms', 'kg', TRUE), - ('item', 'items', 'x', FALSE) -; - -/* --- Unit of Measurement Conversion -INSERT INTO Shop_Unit_Measurement_Conversion ( - id_unit_derived, id_unit_base, power_unit_base, multiplier_unit_base, increment_unit_base -) -VALUES - -; -*/ - -/* --- Supplier Purchase Order -INSERT INTO Shop_Supplier_Purchase_Order ( - id_supplier, value_total, id_order_status, id_checkout_session, id_currency -) -VALUES -; - --- Supplier Purchase Order Product Link -INSERT INTO Shop_Supplier_Purchase_Order_Product_Link ( - id_order, id_permutation, cost_total_local, id_currency_cost, quantity_ordered, id_unit_quantity, quantity_received, latency_delivery, display_order -) -VALUES -; -*/ - -/* --- Manufacturing Purchase Order -INSERT INTO Shop_Manufacturing_Purchase_Order ( - cost_total_local, id_currency_cost -) -VALUES -; - --- Manufacturing Purchase Order Product Link -INSERT INTO Shop_Manufacturing_Purchase_Order_Product_Link ( - id_order, id_permutation, cost_total_local, id_currency_cost, quantity_used, id_unit_quantity, quantity_produced, latency_manufacturing_days, display_order -) -VALUES -; -*/ - -/* --- Customer -INSERT INTO Shop_Customer ( - name_company, name_contact, department_contact, id_address, phone_number, email, id_currency -) -VALUES - -; -*/ - -/* --- Customer Sales Order -INSERT INTO Shop_Customer_Sales_Order ( - cost_total_local, id_currency_cost -) -VALUES -; - --- Customer Sales Order Product Link -INSERT INTO Shop_Customer_Sales_Order_Product_Link ( - id_order, id_permutation, cost_total_local, id_currency_cost, quantity_ordered, id_unit_quantity, quantity_delivered, latency_delivery_days, display_order -) -VALUES -; -*/ - - -/* - -- Clean up -END // -DELIMITER ;; - - --- Call -CALL p_populate_database(); - --- Remove proc -DROP PROCEDURE IF EXISTS p_populate_database; -*/ \ No newline at end of file diff --git a/static/PostgreSQL/901_view.sql b/static/PostgreSQL/901_view.sql deleted file mode 100644 index 9e139d9a..00000000 --- a/static/PostgreSQL/901_view.sql +++ /dev/null @@ -1,188 +0,0 @@ - - -DO $$ -BEGIN - RAISE NOTICE 'TABLE POPULATION COMPLETE'; -END $$; - --- Product Change Sets -SELECT * FROM Shop_Product_Change_Set; - --- User Change Sets -SELECT * FROM Shop_User_Change_Set; - --- Access Levels -SELECT * FROM Shop_Access_Level; -SELECT * FROM Shop_Access_Level_Audit; - --- Error Message type -SELECT * FROM Shop_Msg_Error_Type; - --- File Types -SELECT * FROM File_Type; -SELECT * FROM File_Type_Audit; - --- Generic / shared properties -SELECT * FROM Shop_General; -SELECT * FROM Shop_General_Audit; - --- Categories -SELECT * FROM Shop_Product_Category; -SELECT * FROM Shop_Product_Category_Audit; - --- Recurrence Interval -SELECT * FROM Shop_Interval_Recurrence; -SELECT * FROM Shop_Interval_Recurrence_Audit; - --- Region -SELECT * FROM Shop_Region; -SELECT * FROM Shop_Region_Audit; - --- Region Branch -SELECT * FROM Shop_Region_Branch; -SELECT * FROM Shop_Region_Branch_Audit; - --- Currency -SELECT * FROM Shop_Currency; -SELECT * FROM Shop_Currency_Audit; - --- Taxes and Surcharges -SELECT * FROM Shop_Tax_Or_Surcharge; -SELECT * FROM Shop_Tax_Or_Surcharge_Audit; - --- Products -SELECT * FROM Shop_Product; -SELECT * FROM Shop_Product_Audit; - --- Variation Types -SELECT * FROM Shop_Variation_Type; -SELECT * FROM Shop_Variation_Type_Audit; - --- Variations -SELECT * FROM Shop_Variation; -SELECT * FROM Shop_Variation_Audit; - --- Permutations -SELECT * FROM Shop_Product_Permutation; -SELECT * FROM Shop_Product_Permutation_Audit; - --- Permutation Variation Links -SELECT * FROM Shop_Product_Permutation_Variation_Link; -SELECT * FROM Shop_Product_Permutation_Variation_Link_Audit; - --- Product Currency Links -SELECT * FROM Shop_Product_Currency_Region_Link; -SELECT * FROM Shop_Product_Currency_Region_Link_Audit; - --- Image Types -SELECT * FROM Shop_Image_Type; -SELECT * FROM Shop_Image_Type_Audit; - --- Images -SELECT * FROM Shop_Image; -SELECT * FROM Shop_Image_Audit; - --- Delivery Option Types -SELECT * FROM Shop_Delivery_Option; -SELECT * FROM Shop_Delivery_Option_Audit; - --- Delivery Options -SELECT * FROM Shop_Product_Permutation_Delivery_Option_Link; -SELECT * FROM Shop_Product_Permutation_Delivery_Option_Link_Audit; - --- Discounts -SELECT * FROM Shop_Discount; -SELECT * FROM Shop_Discount_Audit; - --- Discount Delivery Region Links -SELECT * FROM Shop_Discount_Region_Currency_Link; -SELECT * FROM Shop_Discount_Region_Currency_Link_Audit; - - --- Permission Groups -SELECT * FROM Shop_Permission_Group; -SELECT * FROM Shop_Permission_Group_Audit; - --- Permissions -SELECT * FROM Shop_Permission; -SELECT * FROM Shop_Permission_Audit; - --- Roles -SELECT * FROM Shop_Role; -SELECT * FROM Shop_Role_Audit; - --- Role Permission link -SELECT * FROM Shop_Role_Permission_Link; -SELECT * FROM Shop_Role_Permission_Link_Audit; - --- Users -SELECT * FROM Shop_User; -SELECT * FROM Shop_User_Audit; - --- User Role link -SELECT * FROM Shop_User_Role_Link; -SELECT * FROM Shop_User_Role_Link_Audit; - - --- Addresses -SELECT * FROM Shop_Address; -SELECT * FROM Shop_Address_Audit; - --- Basket -SELECT * FROM Shop_User_Basket; -SELECT * FROM Shop_User_Basket_Audit; - --- Order Statuses -SELECT * FROM Shop_User_Order_Status; -SELECT * FROM Shop_User_Order_Status_Audit; - -/* --- Orders -SELECT * FROM Shop_User_Order; -SELECT * FROM Shop_User_Order_Audit; - --- Order Products -SELECT * FROM Shop_User_Order_Product_Link; -SELECT * FROM Shop_User_Order_Product_Link_Audit; -*/ - --- Supplier -SELECT * FROM Shop_Supplier; -SELECT * FROM Shop_Supplier_Audit; - --- Unit Of Measurement -SELECT * FROM Shop_Unit_Measurement; -SELECT * FROM Shop_Unit_Measurement_Audit; - --- Unit of Measurement Conversion -SELECT * FROM Shop_Unit_Measurement_Conversion; -SELECT * FROM Shop_Unit_Measurement_Conversion_Audit; - --- Supplier Purchase Order -SELECT * FROM Shop_Supplier_Purchase_Order; -SELECT * FROM Shop_Supplier_Purchase_Order_Audit; - --- Supplier Purchase Order Product Link -SELECT * FROM Shop_Supplier_Purchase_Order_Product_Link; -SELECT * FROM Shop_Supplier_Purchase_Order_Product_Link_Audit; - --- Manufacturing Purchase Order -SELECT * FROM Shop_Manufacturing_Purchase_Order; -SELECT * FROM Shop_Manufacturing_Purchase_Order_Audit; - --- Manufacturing Purchase Order Product Link -SELECT * FROM Shop_Manufacturing_Purchase_Order_Product_Link; -SELECT * FROM Shop_Manufacturing_Purchase_Order_Product_Link_Audit; - --- Customers -SELECT * FROM Shop_Customer; -SELECT * FROM Shop_Customer_Audit; - --- Customer Sales Order -SELECT * FROM Shop_Customer_Sales_Order; -SELECT * FROM Shop_Customer_Sales_Order_Audit; - --- Customer Sales Order Product Link -SELECT * FROM Shop_Customer_Sales_Order_Product_Link; -SELECT * FROM Shop_Customer_Sales_Order_Product_Link_Audit; - diff --git a/static/PostgreSQL/910_anal.sql b/static/PostgreSQL/910_anal.sql deleted file mode 100644 index d83f6962..00000000 --- a/static/PostgreSQL/910_anal.sql +++ /dev/null @@ -1,26 +0,0 @@ - - - - -SELECT TABLE_NAME -FROM INFORMATION_SCHEMA.TABLES -WHERE TABLE_NAME LIKE '%SHOP%' - OR TABLE_NAME LIKE '%FILE_TYPE%'; - - -SELECT FOUND_ROWS(); - - - -SELECT - CONSTRAINT_NAME, - CONSTRAINT_TYPE, - TABLE_NAME, - COLUMN_NAME, - REFERENCED_TABLE_NAME, - REFERENCED_COLUMN_NAME -FROM - INFORMATION_SCHEMA.TABLES -WHERE - TABLE_SCHEMA = 'PARTS' - -- AND TABLE_NAME = 'your_table_name'; diff --git a/static/PostgreSQL/920_edit_permissions.sql b/static/PostgreSQL/920_edit_permissions.sql deleted file mode 100644 index 93a911d9..00000000 --- a/static/PostgreSQL/920_edit_permissions.sql +++ /dev/null @@ -1,83 +0,0 @@ -SELECT URL.id_link, - URL.id_user, - U.name AS name, - URL.id_role, - R.name AS role -FROM Shop_User_Role_Link URL -INNER JOIN Shop_User U - ON URL.id_user = U.id_user -INNER JOIN Shop_Role R - ON URL.id_role = R.id_role -; -SELECT * -FROM Shop_Role_Permission_Link -; -SELECT * -FROM Shop_Access_Level -; -SELECT * -FROM Shop_Permission -; -SELECT * -FROM Shop_Access_Level -; - - -select * from shop_user; -select * from shop_user_audit; -select * from Shop_User_Change_Set; -/* -INSERT INTO Shop_User_Change_Set ( comment ) -VALUES ('Demotion'); -*/ -UPDATE Shop_User -SET is_super_user = 0, - id_change_set = (SELECT id_change_set FROM Shop_User_Change_Set LIMIT 1) -WHERE id_user = 1 -; -select * from shop_user; -select * from shop_user_audit; - - -drop procedure if exists p_test; -delimiter // -create procedure p_test () -begin - declare b0 int; - declare b1 int; - SET b0 = FALSE; - SET b1 = TRUE; - select b0, b1; - select cast(b0 as char), cast(b1 as char); - select cast(b0 as char character set utf8), cast(b1 as char character set utf8); - select convert(b0, char), convert(b1, char); - select convert(b0, char character set utf8), convert(b1, char character set utf8); - select convert(convert(b0, signed), char), convert(convert(b1, signed), char); - select convert(convert(b0, signed), char character set utf8), convert(convert(b1, signed), char character set utf8); -end // -delimiter ; -call p_test(); -drop procedure if exists p_test; - -INSERT INTO Shop_User_Audit ( - id_user, - name_field, - value_prev, - value_new, - id_change_set -) -SELECT id_user, name_field, value_prev, value_new, id_change_set -FROM Shop_User_Audit -WHERE id_audit = 1 -UNION -SELECT id_user, name_field, value_prev, value_new, id_change_set -FROM Shop_User_Audit -WHERE id_audit = 1 -; - -select * from shop_user_audit; - - -SELECT * FROM Shop_Access_Level; - -SELECT * FROM Shop_Product; \ No newline at end of file diff --git a/static/PostgreSQL/temp.txt b/static/PostgreSQL/temp.txt deleted file mode 100644 index b87bbca4..00000000 --- a/static/PostgreSQL/temp.txt +++ /dev/null @@ -1,153 +0,0 @@ -001_destroy.sql -100.0_tbl_Shop_Product_Change_Set.sql -100.1_tbl_Shop_User_Change_Set.sql -100.2_tbl_Shop_Access_Level.sql -100.2_tbl_Shop_Sales_And_Purchasing_Change_Set.sql -100.3_tbl_Shop_Access_Level_Audit.sql -100_tbl_Msg_Error_Type.sql -102_tbl_File_Type.sql -103_tbl_File_Type_Audit.sql -104_tbl_Shop_General.sql -105_tbl_Shop_General_Audit.sql -106_tbl_Shop_Product_Category.sql -107_tbl_Shop_Product_Category_Audit.sql -108_tbl_Shop_Interval_Recurrence.sql -109_tbl_Shop_Interval_Recurrence_Audit.sql -110.0_tbl_Shop_Region.sql -110.1_tbl_Shop_Region_Audit.sql -110.2_tbl_Shop_Region_Branch.sql -110.3_tbl_Shop_Region_Branch_Audit.sql -110.4_tbl_Shop_Currency.sql -110.5_tbl_Shop_Currency_Audit.sql -110.6_tbl_Shop_Tax_Or_Surcharge.sql -110.7_tbl_Shop_Tax_Or_Surcharge_Audit.sql -110.8_tbl_Shop_Product.sql -110.9_tbl_Shop_Product_Audit.sql -112_tbl_Shop_Variation_Type.sql -113.0_tbl_Shop_Variation_Type_Audit.sql -114_tbl_Shop_Variation.sql -115_tbl_Shop_Variation_Audit.sql -117.1_tbl_Shop_Product_Permutation.sql -117.2_tbl_Shop_Product_Permutation_Audit.sql -117.3_tbl_Shop_Product_Permutation_Variation_Link.sql -117.4_tbl_Shop_Product_Permutation_Variation_Link_Audit.sql -117.5_tbl_Shop_Product_Currency_Region_Link.sql -117.6_tbl_Shop_Product_Currency_Region_Link_Audit.sql -118_tbl_Shop_Image_Type.sql -119_tbl_Shop_Image_Type_Audit.sql -120_tbl_Shop_Image.sql -121_tbl_Shop_Image_Audit.sql -122_tbl_Shop_Delivery_Option.sql -123_tbl_Shop_Delivery_Option_Audit.sql -124_tbl_Shop_Product_Permutation_Delivery_Option_Link.sql -125_tbl_Shop_Product_Permutation_Delivery_Option_Link_Audit.sql -130.4_tbl_Shop_Discount.sql -131_tbl_Shop_Discount_Audit.sql -132_tbl_Shop_Discount_Region_Currency_Link.sql -133_tbl_Shop_Discount_Region_Currency_Link_Audit.sql -153_tbl_Shop_Permission_Group.sql -154_tbl_Shop_Permission_Group_Audit.sql -155_tbl_Shop_Permission.sql -156_tbl_Shop_Permission_Audit.sql -157_tbl_Shop_Role.sql -158_tbl_Shop_Role_Audit.sql -159_tbl_Shop_Role_Permission_Link.sql -160_tbl_Shop_Role_Permission_Link_Audit.sql -161_tbl_Shop_User.sql -162_tbl_Shop_User_Audit.sql -163_tbl_Shop_User_Role_Link.sql -164_tbl_Shop_User_Role_Link_Audit.sql -165_tbl_Shop_Address.sql -166_tbl_Shop_Address_Audit.sql -167_tbl_Shop_User_Basket.sql -168_tbl_Shop_User_Basket_Audit.sql -169_tbl_Shop_User_Order_Status.sql -170_tbl_Shop_User_Order_Status_Audit.sql -181.0_tbl_Shop_Supplier.sql -181.1_tbl_Shop_Supplier_Audit.sql -181.2_tbl_Shop_Unit_Measurement.sql -181.3_tbl_Shop_Unit_Measurement_Audit.sql -181.4_tbl_Shop_Unit_Measurement_Conversion.sql -181.5_tbl_Shop_Unit_Measurement_Conversion_Audit.sql -181.6_tbl_Shop_Supplier_Purchase_Order.sql -181.7_tbl_Shop_Supplier_Purchase_Order_Audit.sql -181.8_tbl_Shop_Supplier_Purchase_Order_Product_Link.sql -181.9_tbl_Shop_Supplier_Purchase_Order_Product_Link_Audit.sql -182.0_tbl_Shop_Supplier_Purchase_Order_Product_Link_Temp.sql -183_tbl_Shop_Manufacturing_Purchase_Order.sql -184_tbl_Shop_Manufacturing_Purchase_Order_Audit.sql -185_tbl_Shop_Manufacturing_Purchase_Order_Product_Link.sql -186.1_tbl_Shop_Manufacturing_Purchase_Order_Product_Link_Temp.sql -186_tbl_Shop_Manufacturing_Purchase_Order_Product_Link_Audit.sql -187.0_tbl_Shop_Customer.sql -187.1_tbl_Shop_Customer_Audit.sql -187.2_tbl_Shop_Customer_Sales_Order.sql -188_tbl_Shop_Customer_Sales_Order_Audit.sql -189_tbl_Shop_Customer_Sales_Order_Product_Link.sql -190_tbl_Shop_Customer_Sales_Order_Product_Link_Audit.sql -191_tbl_Shop_Customer_Sales_Order_Product_Link_Temp.sql -300.2_tri_Shop_Sales_And_Purchasing_Change_Set.sql -301.1_tri_Shop_User_Change_Set.sql -301.2_tri_Shop_Access_Level.sql -301_tri_Shop_Product_Change_Set.sql -302_tri_File_Type.sql -303_tri_File_Type_Audit.sql -304_tri_Shop_General.sql -306_tri_Shop_Product_Category.sql -308_tri_Shop_Interval_Recurrence.sql -310.0_tri_Shop_Region.sql -310.2_tri_Shop_Region_Branch.sql -310.4_tri_Shop_Currency.sql -310.6_tri_Shop_Tax_Or_Surcharge.sql -310.8_tri_Shop_Product.sql -312_tri_Shop_Variation_Type.sql -314_tri_Shop_Variation.sql -317.1_tri_Shop_Product_Permutation.sql -317.3_tri_Shop_Product_Permutation_Variation_Link.sql -317.5_tri_Shop_Product_Currency_Region_Link.sql -318_tri_Shop_Image_Type.sql -320_tri_Shop_Image.sql -322_tri_Shop_Delivery_Option.sql -324_tri_Shop_Product_Permutation_Delivery_Option_Link.sql -330_tri_Shop_Discount.sql -332_tri_Shop_Discount_Region_Currency_Link.sql -353_tri_Shop_Permission_Group.sql -355_tri_Shop_Permission.sql -357_tri_Shop_Role.sql -359_tri_Shop_Role_Permission_Link.sql -361_tri_Shop_User.sql -363_tri_Shop_User_Role_Link.sql -365_tri_Shop_Address.sql -367_tri_Shop_User_Basket.sql -369_tri_Shop_User_Order_Status.sql -381.0_tri_Shop_Supplier.sql -381.2_tri_Shop_Unit_Measurement.sql -381.4_tri_Shop_Unit_Of_Measurement_Conversion.sql -381.6_tri_Shop_Supplier_Purchase_Order.sql -381.8_tri_Shop_Supplier_Purchase_Order_Product_Link.sql -383_tri_Shop_Manufacturing_Purchase_Order.sql -385_tri_Shop_Manufacturing_Purchase_Order_Product_Link.sql -387.0_tri_Shop_Customer.sql -387.2_tri_Shop_Customer_Sales_Order.sql -389_tri_Shop_Customer_Sales_Order_Product_Link.sql -600_p_shop_calc_user.sql -602_p_save_supplier_purchase_order.sql -602_p_shop_save_supplier.sql -604_p_shop_save_manufacturing_purchase_order.sql -605_p_shop_save_customer.sql -606_p_shop_save_customer_sales_order.sql -610_p_shop_save_user.sql -611_p_shop_save_user_basket.sql -700_p_shop_get_many_product.sql -702.1_p_shop_get_many_currency.sql -702.2_p_shop_get_many_region.sql -703_p_shop_get_many_user_order.sql -704_p_shop_get_many_stripe_product_new.sql -705_p_shop_get_many_stripe_price_new.sql -706_p_shop_get_many_supplier.sql -706_p_shop_get_many_supplier_purchase_order.sql -708_p_shop_get_many_manufacturing_purchase_order.sql -709_p_shop_get_many_customer.sql -710_p_shop_get_many_customer_sales_order.sql -900_populate.sql -901_view.sql diff --git a/static/batch/sql_combine.ps1 b/static/batch/sql_combine.ps1 index 5b8e77a4..5595a021 100644 --- a/static/batch/sql_combine.ps1 +++ b/static/batch/sql_combine.ps1 @@ -4,7 +4,7 @@ param( [string]$sourceFolder = "C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\static\MySQL\", [string]$outputFileName = "0000_combined.sql", [string]$filePattern = "*.sql", - [string[]]$excludeFiles = @("920_edit_permissions.sql", "910_anal.sql", "701_p_shop_get_many_role_permission.sql", "600_p_shop_save_product.sql", "dump.sql") # Array of filenames to exclude + [string[]]$excludeFiles = @("dump.sql") # Array of filenames to exclude ) $outputFile = Join-Path $sourceFolder $outputFileName diff --git a/static/dist/js/main.bundle.js b/static/dist/js/main.bundle.js index 9aabd22f..52f17fe9 100644 --- a/static/dist/js/main.bundle.js +++ b/static/dist/js/main.bundle.js @@ -4334,52 +4334,8 @@ var PageContact = /*#__PURE__*/function (_BasePage) { key: "initialize", value: function initialize() { this.sharedInitialize(); - // this.hookupALTCHAByLocalServer(); this.hookupButtonSubmitFormContactUs(); } - - /* - hookupALTCHAByAPI() { - const form = document.querySelector(idContactForm); - const altchaWidget = form.querySelector('altcha-widget'); - - // Listen for verification events from the ALTCHA widget - if (altchaWidget) { - altchaWidget.addEventListener('serververification', function(event) { - // Create or update the hidden input for ALTCHA - let altchaInput = form.querySelector('input[name="altcha"]'); - if (!altchaInput) { - altchaInput = document.createElement('input'); - altchaInput.type = 'hidden'; - altchaInput.name = 'altcha'; - form.appendChild(altchaInput); - } - - // Set the verification payload - altchaInput.value = event.detail.payload; - }); - } - } - */ - }, { - key: "hookupALTCHAByLocalServer", - value: function hookupALTCHAByLocalServer() { - window.ALTCHA = { - init: function init(config) { - document.querySelectorAll(config.selector).forEach(function (el) { - new la({ - target: el, - props: { - challengeurl: config.challenge.url, - auto: 'onload' - } - }).$on('verified', function (e) { - config.challenge.onSuccess(e.detail.payload, el); - }); - }); - } - }; - } }, { key: "hookupButtonSubmitFormContactUs", value: function hookupButtonSubmitFormContactUs() { diff --git a/static/js/pages/core/contact.js b/static/js/pages/core/contact.js index 9736e71a..39e4653c 100644 --- a/static/js/pages/core/contact.js +++ b/static/js/pages/core/contact.js @@ -12,49 +12,9 @@ export default class PageContact extends BasePage { initialize() { this.sharedInitialize(); - // this.hookupALTCHAByLocalServer(); this.hookupButtonSubmitFormContactUs(); } - /* - hookupALTCHAByAPI() { - const form = document.querySelector(idContactForm); - const altchaWidget = form.querySelector('altcha-widget'); - - // Listen for verification events from the ALTCHA widget - if (altchaWidget) { - altchaWidget.addEventListener('serververification', function(event) { - // Create or update the hidden input for ALTCHA - let altchaInput = form.querySelector('input[name="altcha"]'); - if (!altchaInput) { - altchaInput = document.createElement('input'); - altchaInput.type = 'hidden'; - altchaInput.name = 'altcha'; - form.appendChild(altchaInput); - } - - // Set the verification payload - altchaInput.value = event.detail.payload; - }); - } - } - */ - hookupALTCHAByLocalServer() { - window.ALTCHA = { init: (config) => { - document.querySelectorAll(config.selector).forEach(el => { - new Altcha({ - target: el, - props: { - challengeurl: config.challenge.url, - auto: 'onload' - } - }).$on('verified', (e) => { - config.challenge.onSuccess(e.detail.payload, el); - }); - }); - }}; - } - hookupButtonSubmitFormContactUs() { const button = document.querySelector('form input[type="submit"]'); button.classList.add(flagButton); diff --git a/templates/pages/core/_contact.html b/templates/pages/core/_contact.html index e3fc5990..5d8a70a4 100644 --- a/templates/pages/core/_contact.html +++ b/templates/pages/core/_contact.html @@ -74,14 +74,4 @@ - - {% endblock %} \ No newline at end of file