Customers

Models

Overview of WHAM Customer Models

These PHP models collectively manage various aspects of account and customer data. Accounts.php and AccountsAttributes.php deal with core account information and additional attributes, while Application.php handles submitted applications. Customer-related models, including Customer.php, CustomerAddress.php, and CustomerCard.php, cover comprehensive details like addresses and payment methods. CustomerIssue.php and Recommendation.php focus on managing support issues and providing recommendations. Additionally, models such as CustomerAudit.php and CustomerUpdates.php ensure effective tracking of changes and interactions, supporting robust data management and customer relationship handling.


The customer module fires the following models.

Class NameModels
Toolstation\Customers\CustomerAuditModels\AccountsThe model uses dynamic attribute access and mutation methods based on a table field prefix.
Toolstation\Customers\Models\AccountsAttributesThe model uses constants to define application types and statuses for easier reference.
Toolstation\Customers\Models\ApplicationThe model uses constants to define application types and statuses for easier reference.
Toolstation\Customers\Models\CatalogueRequestThe model uses custom attributes to map database fields to model properties and includes a scope for filtering incomplete requests.
Toolstation\Customers\Models\CreditSpendThe model includes methods for generating time-based keys for month and year from a DateTime instance.
Toolstation\Customers\Models\CustomerThe Customer model leverages dynamic attribute accessors and mutators, which follow the convention of using the ucu_ prefix for fields in the database.
Toolstation\Customers\Models\CustomerAddressThis Markdown file will help document the CustomerAddress model and ensure that all relevant details are clearly specified..
Toolstation\Customers\Models\CustomerAssociatedThe CustomerAssociatedBranch model represents branch records linked to customers and interacts with the user_customer_associated_branches table in Toolstation.
Toolstation\Customers\Models\CustomerAttributeThe CustomerAttribute model represents customer attributes or notes and interacts with the user_customer_notes table in Toolstation.
Toolstation\Customers\Models\CustomerAuditThe CustomerAudit model tracks audit records and interfaces with the user_customers_updates table.
Toolstation\Customers\Models\CustomerCardThe CustomerCard model represents customer card records and interacts with the user_customer_cards table.
Toolstation\Customers\Models\CustomerCardRequest The CustomerCardRequest model handles customer card requests, interacting with the user_customer_card_requests table.
Toolstation\Customers\Models\CustomerIdentityTokenThe CustomerIdentityToken model represents identity tokens for customers, interacting with the user_customer_identity_tokens table.
Toolstation\Customers\Models\CustomerIssueThe CustomerIssue model represents customer-reported issues and interacts with the user_customer_issues table.
Toolstation\Customers\Models\CustomerIssueNoteThe CustomerIssueNote model extends SystemNote for notes on customer issues.
Toolstation\Customers\Models\CustomerNoteThe CustomerNote model extends SystemNote for customer-specific notes in Eloquent.
Toolstation\Customers\Models\CustomerSpendThe CustomerSpend model handles customer spending data in Eloquent.
Toolstation\Customers\Models\CustomerStatsThe CustomerStats class, in the Toolstation\Customers\Models namespace, represents customer-related statistics and interacts with the user_customer_stats table
Toolstation\Customers\Models\CustomerUpdatesThe CustomerUpdates model requires manual management of createdAt and updatedAt timestamps and uses a non-incrementing string primary key, ucup_ucu_uid
Toolstation\Customers\Models\RecommendationThe Recommendation class, located in the Toolstation\Customers\Models namespace, represents customer recommendations and interacts with the recommendations table.
Toolstation\Customers\Models\RecommendationUnsubscribeThe email maps to run_email and must be validated. This model tracks unsubscribes for recommendation system integrity.
Toolstation\Customers\Models\SavedAccountApplicationThe state and pin attributes are encrypted for security, the STATUS constant enumerates application states for clarity, and email addresses are validated before saving to ensure data integrity.

Account Model

The Account class is an Eloquent model in the Toolstation\Customers\Models namespace, representing user accounts in the Toolstation application. It interacts with the user_accounts table in the database.

Data

  • Namespace: Toolstation\Customers\Models
  • Table: user_accounts
  • Primary Key: uac_id
  • Connection: main
  • Timestamps:
    • Created At: uac_created
    • Updated At: uac_updated
  • Field Prefix: uac
  • Fillable Attributes:
    • name
    • number
    • who
    • created
    • updated
  • Date Attributes:
    • uac_created
    • uac_updated
  • Accessors:
    • getIdAttribute: Returns the primary key value.
    • getNameAttribute: Returns the account name.
    • getNumberAttribute: Returns the account number.
    • getWhoCreatedAttribute: Returns the ID of the creator.
    • getCreatedAttribute: Returns the creation date.
    • getUpdatedAttribute: Returns the last update date.
  • Mutators:
    • setIdAttribute: Sets the primary key attribute.
    • setNameAttribute: Sets the account name.
    • setNumberAttribute: Sets the account number.
    • setWhoAttribute: Sets the creator's ID.
    • setCreatedAttribute: Sets the creation date.
    • setUpdatedAttribute: Sets the update date.
  • Relationships:
    • who(): BelongsTo - The customer who created the account.
    • attributes(): HasMany - Related AccountAttribute models.
    • customers(): BelongsToMany - Associated customers via lnk_account_customers.
    • adminCustomers(): BelongsToMany - Customers with admin roles.
    • employeeCustomers(): BelongsToMany - Customers with employee roles.
    • orders(): BelongsToMany - Orders associated with the account.
    • parentOrders(): BelongsToMany - Parent orders associated with the account.
  • Attributes Accessors:
    • getAllOrdersAttribute: Returns all associated orders, including parent orders, sorted by order date.
    • getAccountOrdersAttribute: Returns orders paid with account credit, sorted by order date.
    • getDirectDebitMandateAttribute: Retrieves the direct debit mandate from account attributes.

Note: The model uses dynamic attribute access and mutation methods based on a table field prefix.


AccountAttribute Model

The AccountAttribute class is an Eloquent model in the Toolstation\Customers\Models namespace, representing attributes related to user accounts. It interacts with the user_account_notes table in the database.

Data

  • Namespace: Toolstation\Customers\Models
  • Table: user_account_notes
  • Primary Key: uan_id
  • Connection: main
  • Timestamps: false
  • Field Prefix: uan
  • Fillable Attributes:
    • accountId
    • attributeId
    • value
    • created
  • Accessors:
    • getIdAttribute: Returns the primary key value.
    • getAccountIdAttribute: Returns the account ID.
    • getAttributeIdAttribute: Returns the attribute ID.
    • getValueAttribute: Returns the attribute value.
    • getCreatedAttribute: Returns the creation date.
  • Mutators:
    • setIdAttribute: Sets the primary key attribute.
    • setAccountIdAttribute: Sets the account ID.
    • setAttributeIdAttribute: Sets the attribute ID.
    • setValueAttribute: Sets the attribute value.
    • setCreatedAttribute: Sets the creation date.
  • Custom Collection:
    • newCollection: Returns an instance of AccountAttributeCollection for managing collections of AccountAttribute models.

Note: The model uses a table field prefix for dynamic attribute access and mutation.


Application Model

The Application class is an Eloquent model in the Toolstation\Customers\Models namespace, representing applications within the Toolstation application. It interacts with the applications table in the database.

Data

  • Namespace: Toolstation\Customers\Models
  • Table: applications
  • Primary Key: id
  • Connection: main
  • Timestamps: true
  • Fillable Attributes:
    • customer_id
    • type
    • status
    • application_data
    • notes
  • Constants:
    • APPLICATION_TYPES:
      • PROCARD: 1
      • PROCARD_ZERO: 2
    • STATUSES:
      • PENDING: 1
      • APPROVED: 2
      • DECLINED: 3
      • DRAFT: 4
  • Accessors:
    • getCustomerIdAttribute: Returns the customer ID.
    • getTypeAttribute: Returns the application type.
    • getApplicationDataAttribute: Returns the application data.
    • getDecodedApplicationDataAttribute: Returns the decoded application data as an array.
    • getStatusAttribute: Returns the application status.
    • getNotesAttribute: Returns the notes, or an empty string if not set.
    • getCreatedAtAttribute: Returns the creation date.
    • getUpdatedAtAttribute: Returns the last update date.
    • getDeletedAtAttribute: Returns the deletion date (if soft deletes are used).
  • Relationships:
    • customer(): BelongsTo - The customer associated with the application.
  • Methods:
    • approve(): Sets the status to APPROVED and saves the model.
    • decline(): Sets the status to DECLINED and saves the model.

Note: The model uses constants to define application types and statuses for easier reference.


CatalogueRequest Model

The CatalogueRequest class is an Eloquent model in the Toolstation\Customers\Models namespace, representing catalogue requests in the Toolstation application. It interacts with the user_requests table in the database.

Data

  • Namespace: Toolstation\Customers\Models
  • Table: user_requests
  • Primary Key: Composite key (not auto-incrementing)
  • Incrementing: false
  • Key Type: string
  • Timestamps: false
  • Dates:
    • ucr_ts
  • Fillable Attributes:
    • addressId
    • customerId
    • date
    • completed
  • Accessors:
    • getCustomerIdAttribute: Converts ucr_ucu_uid to customerId.
    • getAddressIdAttribute: Converts ucr_dad_uid to addressId.
    • getDateAttribute: Converts ucr_ts to date.
    • getCompletedAttribute: Converts ucr_completed to completed.
  • Mutators:
    • setCustomerIdAttribute: Sets ucr_ucu_uid when customerId is mutated.
    • setAddressIdAttribute: Sets ucr_dad_uid when addressId is mutated.
    • setDateAttribute: Sets ucr_ts when date is mutated.
    • setCompletedAttribute: Sets ucr_completed when completed is mutated.
  • Scopes:
    • scopeIncomplete: Filters requests to include only those that are incomplete (ucr_completed = 0 and ucr_sst_uid = 0).

Note: The model uses custom attributes to map database fields to model properties and includes a scope for filtering incomplete requests.


CreditSpend Model

The CreditSpend class is an Eloquent model in the Toolstation\Customers\Models namespace, representing credit spend records in the Toolstation application. It interacts with the credit_spend table in the database.

Data

  • Namespace: Toolstation\Customers\Models
  • Table: credit_spend
  • Connection: history
  • Timestamps: true
  • Fillable Attributes:
    • account_id
    • customer_id
    • key
    • value
  • Methods:
    • getMonthKey(\DateTime $date): string: Generates a month key in the format Y-m based on the given DateTime.
    • getYearKey(\DateTime $date): string: Generates a year key in the format Y based on the given DateTime.

Note: The model includes methods for generating time-based keys for month and year from a DateTime instance.


Customer Model

The Customer class is an Eloquent model within the Toolstation\Customers\Models namespace. This model represents customers in the Toolstation application and interfaces with the user_customers table in the database. It encapsulates all the necessary business logic for managing customer-related data.

Configuration

Namespace

  • Namespace: Toolstation\Customers\Models
  • The model is located within the Toolstation\Customers\Models namespace, ensuring it is organized within the domain of customer-related entities.

Table

  • Table: user_customers
  • The Customer model interacts with the user_customers table in the database. This table stores all the customer-related information.

Primary Key

  • Primary Key: ucu_uid
  • The primary key for this model is ucu_uid, a unique identifier for each customer.

Database Connection

  • Database Connection: main
  • The model uses the main database connection, which is likely configured in the application's database configuration file.

Timestamps

  • Timestamps: Disabled
  • The model does not automatically manage created_at and updated_at timestamps. Instead, it uses custom fields (ucu_created_when and ucu_updated_when) for tracking creation and update times.

Field Prefix

  • Field Prefix: ucu
  • The model follows a naming convention where all table fields related to this model are prefixed with ucu_. This helps in differentiating customer-related fields from other entities.

Relationships Loaded by Default

  • Default Relationships: primaryAddress
  • The primaryAddress relationship is loaded by default whenever a Customer instance is retrieved. This ensures that the primary address data is always available without requiring an additional query.

Attributes

Fillable Fields

  • Fillable: The following attributes can be mass-assigned.
    • id: The customer's unique identifier.
    • username: The username associated with the customer.
    • title: The title (e.g., Mr., Mrs.) of the customer.
    • firstName: The customer's first name.
    • lastName: The customer's last name.
    • telephone: The customer's primary contact number.
    • mobile: The customer's mobile number.
    • fax: The customer's fax number, if applicable.
    • email: The customer's email address.
    • cookie: Stores any relevant cookie information for the customer.
    • company: The name of the company the customer is associated with.
    • jobTitle: The customer's job title within the company.
    • contactPreferences: Stores the customer's preferences for how they wish to be contacted.
    • createdAt: The date and time when the customer record was created.
    • createdBy: The ID of the user or system that created the customer record.
    • updatedAt: The date and time when the customer record was last updated.
    • updatedBy: The ID of the user or system that last updated the customer record.
    • active: A boolean indicating whether the customer is active or inactive.

Date Fields

  • Dates:
    • ucu_created_when: Custom field for storing the creation timestamp.
    • ucu_updated_when: Custom field for storing the last update timestamp.

Attribute Casting

  • Casts:
    • ucu_epos: Casts the EPOS (Electronic Point of Sale) status as a boolean.
    • ucu_active: Casts the active status as a boolean, indicating whether the customer is currently active.

Accessors

getIdAttribute

  • Purpose: Retrieves the customer's unique identifier (ucu_uid).
  • Usage: Accessed via $customer->id.

getFullNameAttribute

  • Purpose: Combines the title, first name, and last name to create the customer's full name.
  • Usage: Accessed via $customer->full_name.

getContactPreferencesAttribute

  • Purpose: Converts the contactPreferences stored as a serialized string into an array for easier access.
  • Usage: Accessed via $customer->contact_preferences.

getDefaultBranchAttribute

  • Purpose: Retrieves the ID of the branch the customer has set as their default.
  • Usage: Accessed via $customer->default_branch.

getFormattedEmailAddress

  • Purpose: Formats the customer's email address as Name <email@example.com>.
  • Usage: Accessed via $customer->formatted_email_address.

Mutators

setIdAttribute

  • Purpose: Sets the customer's unique identifier.
  • Usage: Set via $customer->id = $value.

setContactPreferencesAttribute

  • Purpose: Converts the contact preferences array back into a serialized string for storage in the database.
  • Usage: Set via $customer->contact_preferences = $array.

setVatNumberAttribute

  • Purpose: Sets the VAT (Value-Added Tax) number for the customer, considering the regional rules.
  • Usage: Set via $customer->vat_number = $value.

Relationships

addresses()

  • Type: HasMany
  • Description: Returns a collection of all addresses associated with the customer.
  • Usage: Accessed via $customer->addresses.

defaultAddress()

  • Type: HasMany
  • Description: Returns the address marked as the default for the customer.
  • Usage: Accessed via $customer->defaultAddress.

primaryAddress()

  • Type: HasOne
  • Description: Retrieves the primary address associated with the customer.
  • Usage: Accessed via $customer->primaryAddress.

orders()

  • Type: HasMany
  • Description: Returns a collection of all orders placed by the customer.
  • Usage: Accessed via $customer->orders.

parentOrders()

  • Type: HasMany
  • Description: Retrieves all parent orders associated with the customer.
  • Usage: Accessed via $customer->parentOrders.

customerCardUsage()

  • Type: HasMany
  • Description: Returns the history of the customer's card usage.
  • Usage: Accessed via $customer->customerCardUsage.

Scopes

scopeEpos

  • Purpose: Filters customers by their EPOS status (e.g., whether they use EPOS systems).
  • Usage: Used in queries via Customer::epos().

scopeGuest

  • Purpose: Filters customers who are marked as guests.
  • Usage: Used in queries via Customer::guest().

scopeActive

  • Purpose: Filters customers that are currently active.
  • Usage: Used in queries via Customer::active().

Methods

getOrderIdByProduct

  • Purpose: Retrieves the ID of the order that contains a specific product purchased by the customer.
  • Parameters:
    • productId (int): The ID of the product.
  • Returns: Order ID.
  • Usage: Called via $customer->getOrderIdByProduct($productId).

getOrderByProduct

  • Purpose: Finds and returns the first order containing a specified product.
  • Parameters:
    • productId (int): The ID of the product.
  • Returns: Order model instance.
  • Usage: Called via $customer->getOrderByProduct($productId).

transform

  • Purpose: Converts a Customer instance into an array format suitable for API responses or other transformations.
  • Returns: An array representation of the customer.
  • Usage: Called via $customer->transform().

Note: The Customer model leverages dynamic attribute accessors and mutators, which follow the convention of using the ucu_ prefix for fields in the database.


CustomerAddress Model

The CustomerAddress class is an Eloquent model in the Toolstation\Customers\Models namespace, representing customer addresses in the Toolstation application. It interacts with the addresses table (inherited from the Address model).

Data

  • Namespace: Toolstation\Customers\Models
  • Table: Inherits from Address model; CustomerAddress model uses the addresses table.
  • Connection: Inherits from Address model (assumed to be main if not explicitly set).
  • Timestamps: Inherited from Address model (assumed to be true if Address uses timestamps).

Field Prefix: Inherited from the Address model (not explicitly specified).

Fillable Attributes

The following attributes are mass assignable:

  • Attributes inherited from the Address model, if applicable.

Relationships

  • customer(): BelongsToMany - Defines a many-to-many relationship with the Customer model through the lnk_addresses pivot table.
    • Pivot Table: lnk_addresses
    • Foreign Key (Address): lna_address
    • Foreign Key (Customer): lna_linkto

Methods

  • getCustomer(): Retrieves the first customer associated with the address. This method is necessary due to the many-to-many relationship setup, which may result in multiple customers being associated with a single address.
    Returns:
    • \Toolstation\Customers\Models\Customer: The first customer associated with the address.

    Example:
    $customerAddress = CustomerAddress::find(1);
    $customer = $customerAddress->getCustomer();
    

Note: This Markdown file will help document the CustomerAddress model and ensure that all relevant details are clearly specified..


CustomerAssociatedBranch Model

The CustomerAssociatedBranch class is an Eloquent model in the Toolstation\Customers\Models namespace. It represents customer-associated branch records in the Toolstation application and interacts with the user_customer_associated_branches table in the database.

Data

  • Namespace: Toolstation\Customers\Models
  • Table: user_customer_associated_branches
  • Connection: main
  • Primary Key: ucab_uid
  • Incrementing: true
  • Timestamps: true (Uses ucab_created_at and ucab_updated_at for timestamps)

Fillable Attributes

The following attributes are mass assignable:

  • customerId
  • siteId
  • type

Constants

  • TYPES: An associative array mapping type names to their values:
    • default => 1
    • favourite => 2
    • ordered_from => 3
    • collected_from => 4
  • TYPE_DESCRIPTIONS: An associative array mapping type values to their descriptions:
    • 1 => DEFAULT
    • 2 => FAVOURITE
    • 3 => ORDERED_FROM
    • 4 => COLLECTED_FROM

Accessors

  • getIdAttribute(): Returns the value of the primary key ucab_uid.
  • getCustomerIdAttribute(): Returns the value of the ucab_ucu_uid attribute.
  • getSiteIdAttribute(): Returns the value of the ucab_ssi_uid attribute.
  • getTypeAttribute(): Returns the value of the ucab_type attribute.
  • getCreatedAtAttribute(): Returns the value of the ucab_created_at attribute.
  • getUpdatedAtAttribute(): Returns the value of the ucab_updated_at attribute.

Mutators

  • setCustomerIdAttribute($value): Sets the value for the ucab_ucu_uid attribute.
  • setSiteIdAttribute($value): Sets the value for the ucab_ssi_uid attribute.
  • setTypeAttribute($value): Sets the value for the ucab_type attribute.

Relationships

  • customer(): Defines a belongsTo relationship with the Customer model using ucab_ucu_uid as the foreign key.
  • site(): Defines a belongsTo relationship with the SystemSite model using ucab_ssi_uid as the foreign key.

CustomerAttribute Model

The CustomerAttribute class is an Eloquent model in the Toolstation\Customers\Models namespace, representing customer attributes or notes in the Toolstation application. It interacts with the user_customer_notes table in the database.

Data

  • Namespace: Toolstation\Customers\Models
  • Table: user_customer_notes
  • Primary Key: ucn_uid
  • Connection: main
  • Timestamps: false (Timestamps are not used by default)
  • Field Prefix: ucn

Fillable Attributes

  • customerId
  • key
  • value
  • dateTime
  • updatedWho

Date Attributes

  • ucn_ts: The timestamp when the attribute was created or updated.

Accessors

  • getIdAttribute: Returns the primary key value (ucn_uid).
  • getKeyAttribute: Returns the attribute key (ucn_sst_uid).
  • getNameAttribute: Returns the name of the attribute based on the key. Uses cached data for performance.
  • getValueAttribute: Returns the value of the attribute (ucn_val).
  • getDateTimeAttribute: Returns the date and time of the attribute (ucn_ts).
  • getUpdatedWhoAttribute: Returns the ID of the user who last updated the attribute (ucn_who).

Mutators

  • setCustomerIdAttribute: Sets the customer ID (ucn_ucu_uid).
  • setKeyAttribute: Sets the attribute key (ucn_sst_uid).
  • setValueAttribute: Sets the attribute value (ucn_val).
  • setDateTimeAttribute: Sets the timestamp (ucn_ts).
  • setUpdatedWhoAttribute: Sets the ID of the user who last updated the attribute (ucn_who).

Relationships

  • (No explicit relationships defined in the provided code.)

Methods

  • newCollection(array $models = []): Returns a new CustomerAttributeCollection instance.
  • getAttributeNames(): Retrieves attribute names from the cache or the database if the cache is missing.
    Returns:
    • CustomerAttributeCollection: A collection of customer attribute statuses.
  • getCustomerAttributeStatuses(): Retrieves all customer attribute statuses from the database.
    Returns:
    • Collection: A collection of customer attribute statuses formatted as an associative array with IDs and descriptions.

Notes

  • The model uses a custom CustomerAttributeCollection for handling collections of attributes.
  • The getNameAttribute() method relies on cached data for attribute names to improve performance.
  • Ensure that the sys_status table contains the necessary attribute statuses for proper functioning of the getCustomerAttributeStatuses() method.

CustomerAudit Model

The CustomerAudit class is an Eloquent model in the Toolstation\Customers\Models namespace, representing customer audit records in the Toolstation application. It interacts with the user_customers_updates table in the database.

Data

  • Namespace: Toolstation\Customers\Models
  • Table: user_customers_updates
  • Primary Key: uid
  • Connection: audit
  • Timestamps: false (Timestamps are not used by default)
  • Field Prefix: ucu

Fillable Attributes

  • id
  • actionTimestamp
  • action
  • customerId
  • username
  • title
  • firstName
  • lastName
  • telephone
  • mobile
  • fax
  • email
  • cookie
  • company
  • jobTitle
  • contactPreferences
  • createdAt
  • createdBy
  • updatedAt
  • updatedBy
  • active

Date Attributes

  • ucu_created_when: The creation date of the audit record.
  • ucu_updated_when: The last update date of the audit record.

Accessors

  • getIdAttribute: Returns the primary key value (uid).
  • getActionTimestampAttribute: Returns the action timestamp (ucu_ts).
  • getActionAttribute: Returns the action (ucu_action).
  • getCustomerIdAttribute: Returns the customer ID (ucu_uid).
  • getTitleAttribute: Returns the title (ucu_title).
  • getFirstNameAttribute: Returns the first name (ucu_firstname).
  • getLastNameAttribute: Returns the last name (ucu_lastname).
  • getFullNameAttribute: Returns the full name concatenated from title, first name, and last name.
  • getUsernameAttribute: Returns the username (ucu_username).
  • getPasswordAttribute: Returns the password (ucu_password).
  • getTelephoneAttribute: Returns the telephone number (ucu_tel).
  • getMobileAttribute: Returns the mobile number (ucu_mob).
  • getFaxAttribute: Returns the fax number (ucu_fax).
  • getEmailAttribute: Returns the email address (ucu_email).
  • getCookieAttribute: Returns the cookie data (ucu_cookie).
  • getCompanyAttribute: Returns the company name (ucu_company).
  • getJobTitleAttribute: Returns the job title (ucu_jobtitle).
  • getVatNumberAttribute: Returns the VAT number (ucu_company_num).
  • getActiveAttribute: Returns the active status (ucu_active).
  • getCreatedAttribute: Returns the creation date (ucu_created_when).
  • getUpdatedAtAttribute: Returns the last update date (ucu_updated_when).
  • getCreatedWhoAttribute: Returns the ID of the user who created the record (ucu_created_who).
  • getUpdatedWhoAttribute: Returns the ID of the user who last updated the record (ucu_updated_who).
  • getContactPreferencesAttribute: Converts contact/marketing preferences into an array of options.
    Returns:
    • mail_catalogues: Boolean indicating if mailing catalogues are allowed.
    • order_query: An array of boolean values for different order query preferences (email, telephone, mobile, SMS, push).
    • order_progress: An array of boolean values for different order progress notifications (email, SMS, push).
    • offers_info: An array of boolean values for different offers and promotional preferences (post, email, mobile, SMS, push, promo centre).

Methods

  • getRememberTokenName(): Returns null as remember tokens are not used for this model.

Notes

  • The model extends Authenticatable and uses Notifiable traits but does not handle authentication or remember tokens.
  • Date attributes ucu_created_when and ucu_updated_when are treated as Carbon instances for date manipulation.
  • The getContactPreferencesAttribute() method provides a detailed array of the customer’s contact and marketing preferences based on specific codes.

CustomerCard Model

The CustomerCard class is an Eloquent model in the Toolstation\Customers\Models namespace, representing customer card records in the Toolstation application. It interacts with the user_customer_cards table in the database.

Data

  • Namespace: Toolstation\Customers\Models
  • Table: user_customer_cards
  • Primary Key: id
  • Connection: main
  • Timestamps: Not managed by Laravel (manual handling)
  • Field Prefix: None (fields are used as defined)

Fillable Attributes

  • id
  • cardNumber
  • customerId
  • type
  • active
  • updatedAt
  • createdAt
  • expiryAt

Date Attributes

  • updatedAt
  • createdAt
  • expiryAt

Accessors

  • getIdAttribute: Returns the primary key value (id).
  • getCardNumberAttribute: Returns the card number (card_number).
  • getCustomerIdAttribute: Returns the customer ID (customer_id).
  • getTypeAttribute: Returns the card type (type).
  • getActiveAttribute: Returns the active status (active), cast to boolean.
  • getUpdatedAtAttribute: Returns the last updated timestamp (updated_at).
  • getCreatedAtAttribute: Returns the creation timestamp (created_at).
  • getExpiryAtAttribute: Returns the expiry timestamp (expiry_at).

Mutators

  • setIdAttribute: Sets the primary key value (id).
  • setCardNumberAttribute: Sets the card number (card_number).
  • setCustomerIdAttribute: Sets the customer ID (customer_id).
  • setTypeAttribute: Sets the card type (type).
  • setActiveAttribute: Sets the active status (active).
  • setUpdatedAtAttribute: Sets the last updated timestamp (updated_at).
  • setCreatedAtAttribute: Sets the creation timestamp (created_at).
  • setExpiryAtAttribute: Sets the expiry timestamp (expiry_at).

Relationships

  • customer(): BelongsTo - The associated customer for the card (customer_id).

Scopes

  • scopeActive(Builder $query): Filters cards that are active and have not expired.
  • scopeTradeCreditCard(Builder $query): Filters cards of type 'trade credit'.

Business Logic

  • getFormattedCardNumber(): Formats the card number by adding spaces every 4 digits.
  • newCardNumber(): Generates a new unique card number using a prefix, current time, and a random number. Ensures uniqueness by checking existing records.

Note

  • The boot method automatically assigns a new card number and timestamps (updatedAt and createdAt) when a new record is being created.
  • The newCardNumber method ensures that card numbers are unique by checking against existing entries in the database.

CustomerCardRequest Model

The CustomerCardRequest class is an Eloquent model in the Toolstation\Customers\Models namespace, representing requests for customer cards. It interacts with the user_customer_card_requests table in the database.

Data

  • Namespace: Toolstation\Customers\Models
  • Table: user_customer_card_requests
  • Primary Key: uccr_uid
  • Connection: main
  • Timestamps: Not managed by Laravel (manual handling)
  • Field Prefix: None (fields are used as defined)

Fillable Attributes

  • addressId
  • customerId
  • type
  • date
  • completed

Date Attributes

  • date (maps to uccr_ts)

Accessors

  • getIdAttribute: Returns the primary key value (uccr_uid).
  • getCustomerIdAttribute: Returns the customer ID (uccr_ucu_uid).
  • getAddressIdAttribute: Returns the address ID (uccr_dad_uid).
  • getTypeAttribute: Returns the type (uccr_sst_uid).
  • getDateAttribute: Returns the date (uccr_ts).
  • getCompletedAttribute: Returns the completion status (uccr_completed).

Mutators

  • setCustomerIdAttribute: Sets the customer ID (uccr_ucu_uid).
  • setAddressIdAttribute: Sets the address ID (uccr_dad_uid).
  • setTypeAttribute: Sets the type (uccr_sst_uid).
  • setDateAttribute: Sets the date (uccr_ts).
  • setCompletedAttribute: Sets the completion status (uccr_completed).

Relationships

  • customer(): BelongsTo - The associated customer for the card request (uccr_ucu_uid).
  • address(): BelongsTo - The associated address for the card request (uccr_dad_uid).

Scopes

  • scopeIncomplete($query): Filters card requests that are not completed (uccr_completed is 0).
  • scopeType($query, $type): Filters card requests by type (uccr_sst_uid).

Notes

  • The CustomerCardRequest model does not handle timestamps automatically; createdAt and updatedAt should be managed manually if needed.
  • The scopeIncomplete and scopeType methods help filter the requests based on their completion status and type.

CustomerIdentityToken Model

The CustomerIdentityToken class is an Eloquent model in the Toolstation\Customers\Models namespace, representing identity tokens associated with customers. It interacts with the user_customer_identity_tokens table in the database.

Data

  • Namespace: Toolstation\Customers\Models
  • Table: user_customer_identity_tokens
  • Primary Key: ucit_uid
  • Connection: main
  • Timestamps: Managed by Laravel (created_at and updated_at fields)
  • Field Prefix: ucit_ (fields are prefixed with ucit_)

Fillable Attributes

  • customerId
  • userAgent
  • tokenHash
  • expiresAt

Date Attributes

  • expiresAt (maps to ucit_expires_at)
  • createdAt (maps to ucit_created_at)
  • updatedAt (maps to ucit_updated_at)

Accessors

  • getIdAttribute: Returns the primary key value (ucit_uid).
  • getCustomerIdAttribute: Returns the customer ID (ucit_ucu_uid).
  • getUserAgentAttribute: Returns the user agent string (ucit_user_agent).
  • getTokenHashAttribute: Returns the identity token hash (ucit_identity_token_hash).
  • getExpiresAtAttribute: Returns the expiration date (ucit_expires_at).

Mutators

  • setCustomerIdAttribute: Sets the customer ID (ucit_ucu_uid).
  • setUserAgentAttribute: Sets the user agent string (ucit_user_agent).
  • setTokenHashAttribute: Sets the identity token hash (ucit_identity_token_hash).
  • setExpiresAtAttribute: Sets the expiration date (ucit_expires_at).

Relationships

  • customer(): BelongsTo - The associated customer for the identity token (ucit_ucu_uid).

Notes

  • The CustomerIdentityToken model handles its timestamps automatically via Laravel's created_at and updated_at fields.
  • The getCreatedAtAttribute method maps the ucit_created_at field to the created_at attribute of the model.
  • The expiresAt attribute manages expiration dates and is converted to a Carbon instance.

CustomerIssue Model

The CustomerIssue class is an Eloquent model in the Toolstation\Customers\Models namespace, representing issues reported by customers. It interacts with the user_customer_issues table in the database.

Data

  • Namespace: Toolstation\Customers\Models
  • Table: user_customer_issues
  • Primary Key: uci_ruid
  • Connection: main
  • Timestamps: Not managed by Laravel (manual handling)
  • Field Prefix: uci_ (fields are prefixed with uci_)

Fillable Attributes

  • id
  • type
  • category
  • created
  • completed
  • lastAcknowledged
  • userCreated
  • userCompleted
  • orderId
  • commentCreated
  • commentCompleted
  • productCode
  • additionalNotes
  • resolutionType

Date Attributes

  • created (maps to uci_ts_created)
  • completed (maps to uci_ts_completed)
  • lastAcknowledged (maps to uci_last_acknowledged)

Accessors

  • getIdAttribute: Returns the primary key value (uci_ruid).
  • getTypeAttribute: Returns the issue type (uci_sst_uid).
  • getTypeTextAttribute: Returns the issue type description from cache or database.
  • getCreatedAttribute: Returns the creation timestamp (uci_ts_created).
  • getCompletedAttribute: Returns the completion timestamp (uci_ts_completed).
  • getLastAcknowledgedAttribute: Returns the last acknowledged timestamp (uci_last_acknowledged).
  • getUserCreatedAttribute: Returns the user who created the issue (uci_who_created).
  • getUserCompletedAttribute: Returns the user who completed the issue (uci_who_completed).
  • getOrderIdAttribute: Returns the associated order ID (uci_uor_uid).
  • getCustomerIdAttribute: Returns the associated customer ID (uci_ucu_uid).
  • getCommentCreatedAttribute: Returns the opening comment (uci_comment_created).
  • getCommentCompletedAttribute: Returns the closing comment (uci_comment_completed).
  • getResolutionTypeAttribute: Returns the resolution type (uci_action_sst_uid).
  • getProductCodeAttribute: Returns the product code (uci_spa_code).
  • getRedactableFieldsAttribute: Returns an array of fields that may be redacted and their descriptions.

Mutators

  • setIdAttribute: Sets the primary key value (uci_ruid).
  • setTypeAttribute: Sets the issue type (uci_sst_uid).
  • setCreatedAttribute: Sets the creation timestamp (uci_ts_created).
  • setCompletedAttribute: Sets the completion timestamp (uci_ts_completed).
  • setLastAcknowledgedAttribute: Sets the last acknowledged timestamp (uci_last_acknowledged).
  • setUserCreatedAttribute: Sets the user who created the issue (uci_who_created).
  • setUserCompletedAttribute: Sets the user who completed the issue (uci_who_completed).
  • setOrderIdAttribute: Sets the associated order ID (uci_uor_uid).
  • setCommentCreatedAttribute: Sets the opening comment (uci_comment_created).
  • setCommentCompletedAttribute: Sets the closing comment (uci_comment_completed).
  • setCategoryAttribute: Sets the issue category (uci_category_sst_uid).
  • setResolutionTypeAttribute: Sets the resolution type (uci_action_sst_uid).
  • setProductCodeAttribute: Sets the product code (uci_spa_code).
  • setAdditionalNotesAttribute: Sets additional notes (uci_additional_notes).

Relationships

  • customer(): BelongsTo - The associated customer for the issue (uci_ucu_uid).
  • notes(): HasMany - The related notes for the issue (dcm_linkto).

Business Logic

  • getCustomerIssueStatuses(): Retrieves and formats all customer issue statuses from the database.

Notes

  • The CustomerIssue model does not handle timestamps automatically; created_at and updated_at should be managed manually if needed.
  • The getTypeTextAttribute method fetches issue statuses from cache or the database, providing a textual description of the issue type.
  • The redactable attribute defines fields that may be redacted and provides human-readable descriptions for each.

CustomerIssueNote Model

The CustomerIssueNote class is an Eloquent model in the Toolstation\Customers\Models namespace, representing notes associated with customer issues. It extends the SystemNote model and interacts with the relevant table.

Data

  • Namespace: Toolstation\Customers\Models
  • Table: Inherits from SystemNote
  • Primary Key: Inherited from SystemNote
  • Connection: Inherits from SystemNote
  • Timestamps: Inherited from SystemNote

Accessors

  • getIssueIdAttribute: Returns the issue ID (dcm_linkto).

Relationships

  • issue(): BelongsTo - The associated customer issue for the note (dcm_linkto).

Notes

  • The CustomerIssueNote model extends the SystemNote model and does not have additional timestamps or table definitions; it inherits these from the parent model.
  • The getIssueIdAttribute method provides a convenient way to access the issue ID associated with the note.

CustomerNote Model

The CustomerNote class is an Eloquent model in the Toolstation\Customers\Models namespace, representing notes associated with customers. It extends the SystemNote model and provides additional functionality specific to customer notes.

Data

  • Namespace: Toolstation\Customers\Models
  • Table: Inherits from SystemNote
  • Primary Key: Inherited from SystemNote
  • Connection: Inherits from SystemNote
  • Timestamps: Inherited from SystemNote

Constants

  • NORMAL_COMMENT: Represents a normal customer comment (0).
  • INTERNAL_COMMENT: Represents an internal customer comment (1).

Attributes

  • Casts:
    • dcm_active (casts to boolean)

Accessors

  • getCustomerIdAttribute: Returns the customer ID (dcm_linkto).

Relationships

  • customer(): BelongsTo - The associated customer for the note (dcm_linkto).
  • group(): HasOne - The associated group status for the note, filtered by SystemStatus::COMMENT_GROUP (dcm_group).

Scopes

  • scopeNormal($query): Filters notes that are categorized as normal comments (dcm_group is NORMAL_COMMENT).
  • scopeInternal($query): Filters notes that are categorized as internal comments (dcm_group is INTERNAL_COMMENT).

Notes

  • The CustomerNote model extends the SystemNote model and inherits its table and primary key configurations.
  • The getCustomerIdAttribute method provides a convenient accessor for the customer ID.
  • The group() relationship fetches the system status group for the note, constrained by the COMMENT_GROUP type.
  • The scopeNormal and scopeInternal methods are used to filter notes based on their group type.

CustomerSpend Model

The CustomerSpend class is an Eloquent model in the Toolstation\Customers\Models namespace, representing customer spending data. It interacts with the user_customer_spend table in the database.

Data

  • Namespace: Toolstation\Customers\Models
  • Table: user_customer_spend
  • Primary Key: Not specified (assumed to be auto-incrementing or not explicitly set)
  • Connection: history
  • Timestamps: Not managed by Laravel (manual handling)

Fillable Attributes

  • customer_id
  • key
  • value

Notes

  • The CustomerSpend model does not handle timestamps automatically; createdAt and updatedAt should be managed manually if needed.
  • The fillable array defines the attributes that are mass assignable.

CustomerStats Model

The CustomerStats class is an Eloquent model in the Toolstation\Customers\Models namespace, representing statistics related to customers. It interacts with the user_customer_stats table in the database.

Data

  • Namespace: Toolstation\Customers\Models
  • Table: user_customer_stats
  • Primary Key: ucs_ucu_uid
  • Connection: main
  • Timestamps: Not managed by Laravel (manual handling)

Fillable Attributes

  • None (no attributes are mass assignable)

Accessors

  • getCustomerIdAttribute: Returns the customer ID (ucs_ucu_uid).
  • getWorldPositionCurrentIdAttribute: Returns the current world position ID (ucs_worldposition_current_id).
  • getWorldPositionCurrentValueAttribute: Returns the current world position value (ucs_worldposition_current_val).
  • getWorldPositionPreviousIdAttribute: Returns the previous world position ID (ucs_worldposition_previous_id).
  • getWorldPositionPreviousValueAttribute: Returns the previous world position value (ucs_worldposition_previous_val).
  • getOrderCountAttribute: Returns the order count (ucs_orders_count).
  • getOrdersSumAttribute: Returns the total sum of orders (ucs_orders_sum).

Relationships

  • customer(): HasOne - The associated customer for the stats (ucs_ucu_uid).

Notes

  • The CustomerStats model does not handle timestamps automatically; createdAt and updatedAt should be managed manually if needed.
  • The fillable array is empty, indicating that mass assignment is not used or handled differently.

CustomerUpdates Model

The CustomerUpdates class is an Eloquent model in the Toolstation\Customers\Models namespace, representing updates related to customers. It interacts with the user_customer_updates table in the database.

Data

  • Namespace: Toolstation\Customers\Models
  • Table: user_customer_updates
  • Primary Key: ucup_ucu_uid
  • Connection: main
  • Timestamps: Not managed by Laravel (manual handling)

Fillable Attributes

  • ucup_ucu_uid (Customer ID)
  • ucup_ts (Timestamp)
  • ucup_type (Update Type)

Accessors

  • getCustomerIdAttribute: Returns the customer ID (ucup_ucu_uid).
  • getTimestampAttribute: Returns the timestamp (ucup_ts).
  • getTypeAttribute: Returns the update type (ucup_type).

Mutators

  • setCustomerIdAttribute: Sets the customer ID (ucup_ucu_uid).
  • setTimestampAttribute: Sets the timestamp (ucup_ts).
  • setTypeAttribute: Sets the update type (ucup_type).

Relationships

  • customer(): BelongsTo - The associated customer for the update (ucup_ucu_uid).

Notes

  • The CustomerUpdates model does not handle timestamps automatically; createdAt and updatedAt should be managed manually if needed.
  • The model is designed to work with a non-incrementing string primary key, specified by ucup_ucu_uid.

Recommendation Model

The Recommendation class is an Eloquent model in the Toolstation\Customers\Models namespace. It represents recommendations made by customers and interacts with the recommendations table in the database.

Data

  • Namespace: Toolstation\Customers\Models
  • Table: recommendations
  • Primary Key: rec_id
  • Connection: main
  • Timestamps: Managed manually with rec_created_at and rec_updated_at

Fillable Attributes

  • rec_id (Recommendation ID)
  • rec_invite_code (Invite Code)
  • rec_friend_email (Friend's Email)
  • rec_friend_uid (Friend's Customer ID)
  • rec_friend_uor_uid (Friend's Order ID)
  • rec_recommender_uid (Recommender's Customer ID)
  • rec_recommender_uor_uid (Recommender's Order ID)
  • rec_cancelled (Cancelled Status)
  • rec_expires_at (Expiry Date)
  • rec_created_at (Creation Date)
  • rec_updated_at (Last Updated Date)

Constants

  • CREATED_AT: 'rec_created_at' - Column name for the creation timestamp.
  • UPDATED_AT: 'rec_updated_at' - Column name for the last update timestamp.

Accessors

  • getIdAttribute: Returns the recommendation ID (rec_id).
  • getInviteCodeAttribute: Returns the invite code (rec_invite_code).
  • getFriendEmailAttribute: Returns the friend's email (rec_friend_email).
  • getFriendIdAttribute: Returns the friend's customer ID (rec_friend_uid).
  • getFriendOrderIdAttribute: Returns the friend's order ID (rec_friend_uor_uid).
  • getRecommenderIdAttribute: Returns the recommender's customer ID (rec_recommender_uid).
  • getRecommenderOrderIdAttribute: Returns the recommender's order ID (rec_recommender_uor_uid).
  • getCancelledAttribute: Returns the cancelled status (rec_cancelled).
  • getExpiresAtAttribute: Returns the expiry date (rec_expires_at).
  • getCreatedAtAttribute: Returns the creation date (rec_created_at).
  • getUpdatedAtAttribute: Returns the last updated date (rec_updated_at).

Mutators

  • setInviteCodeAttribute: Sets the invite code (rec_invite_code).
  • setFriendEmailAttribute: Sets the friend's email (rec_friend_email).
  • setFriendIdAttribute: Sets the friend's customer ID (rec_friend_uid).
  • setFriendOrderIdAttribute: Sets the friend's order ID (rec_friend_uor_uid).
  • setRecommenderIdAttribute: Sets the recommender's customer ID (rec_recommender_uid).
  • setRecommenderOrderIdAttribute: Sets the recommender's order ID (rec_recommender_uor_uid).
  • setCancelledAttribute: Sets the cancelled status (rec_cancelled).
  • setExpiresAtAttribute: Sets the expiry date (rec_expires_at).
  • setCreatedAtAttribute: Sets the creation date (rec_created_at).
  • setUpdatedAtAttribute: Sets the last updated date (rec_updated_at).

Relationships

  • recommender(): BelongsTo - The customer who made the recommendation.
  • recommenderOrder(): BelongsTo - The order associated with the recommender.
  • friend(): BelongsTo - The customer who was recommended.
  • friendOrder(): BelongsTo - The order associated with the friend.

Helpers

  • isActive(): Determines if the recommendation is active. A recommendation is considered active if it has not expired and is not cancelled.

RecommendationUnsubscribe Model

The RecommendationUnsubscribe class is an Eloquent model in the Toolstation\Customers\Models namespace. It represents records of customers who have unsubscribed from recommendations and interacts with the recommendation_unsubscribes table in the database.

Data

  • Namespace: Toolstation\Customers\Models
  • Table: recommendation_unsubscribes
  • Primary Key: run_id
  • Connection: main
  • Timestamps: Managed manually with run_created_at and run_updated_at

Constants

  • CREATED_AT: 'run_created_at' - Column name for the creation timestamp.
  • UPDATED_AT: 'run_updated_at' - Column name for the last update timestamp.

Accessors

  • getIdAttribute: Returns the unsubscribe ID (run_id).
  • getEmailAttribute: Returns the email address of the customer who unsubscribed (run_email).

Model Relationships

  • This model does not define any relationships.

Helpers

  • This model does not define any helper methods.

Notes

  • Email Field: The email attribute is mapped to the run_email field in the database. Ensure the email format is validated before saving to avoid inconsistencies.
  • Unsubscribe Records: This model is specifically used for tracking unsubscribes from recommendations, which may be crucial for maintaining the integrity of recommendation systems and customer preferences.

SavedAccountApplication Model

The SavedAccountApplication class is an Eloquent model in the Toolstation\Customers\Models namespace. It represents a saved account application and interacts with the user_account_applications table in the database.

Data

  • Namespace: Toolstation\Customers\Models
  • Table: user_account_applications
  • Primary Key: uaa_id
  • Connection: main
  • Timestamps: Managed manually with uaa_ts

Constants

  • STATUS: Array of possible statuses for an application:
    • 'SAVED' => 0
    • 'SUCCESS' => 1
    • 'FAILED' => 2
  • CREATED_AT: 'uaa_ts' - Column name for the creation timestamp.

Attributes

  • state: The state of the application, decrypted for use.
  • token: The token associated with the application.
  • email: The email address used in the application.
  • pin: The PIN for the application, decrypted for use.
  • status: The current status of the application.
  • applicationReference: The reference ID for the application.

Accessors

  • getIdAttribute: Returns the ID of the application (uaa_id).
  • getStateAttribute: Decrypts and returns the state of the application (uaa_state).
  • getTokenAttribute: Returns the token associated with the application (uaa_token).
  • getEmailAttribute: Returns the email address used in the application (uaa_email).
  • getPinAttribute: Decrypts and returns the PIN for the application (uaa_pin).
  • getStatusAttribute: Returns the status of the application (uaa_status).
  • getApplicationReferenceAttribute: Returns the application reference ID (uaa_application_reference_id).

Mutations

  • setStateAttribute: Encrypts and sets the state of the application (uaa_state).
  • setTokenAttribute: Sets the token associated with the application (uaa_token).
  • setEmailAttribute: Sets the email address used in the application (uaa_email).
  • setPinAttribute: Encrypts and sets the PIN for the application (uaa_pin).
  • setDateTimeAttribute: Sets the timestamp (uaa_ts).
  • setStatusAttribute: Sets the status of the application (uaa_status).
  • setApplicationReferenceAttribute: Sets the application reference ID (uaa_application_reference_id).

Notes

  • Encryption: The state and pin attributes are encrypted before saving and decrypted when accessed to ensure sensitive information is stored securely.
  • Application States: The STATUS constant provides a clear enumeration of possible application statuses, making it easier to manage and interpret application states.
  • Email Validation: Ensure that the email addresses are validated properly before saving to maintain data integrity.

Copyright © 2026