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 Name | Models |
|---|---|
Toolstation\Customers\CustomerAuditModels\Accounts | The model uses dynamic attribute access and mutation methods based on a table field prefix. |
Toolstation\Customers\Models\AccountsAttributes | The model uses constants to define application types and statuses for easier reference. |
Toolstation\Customers\Models\Application | The model uses constants to define application types and statuses for easier reference. |
Toolstation\Customers\Models\CatalogueRequest | The model uses custom attributes to map database fields to model properties and includes a scope for filtering incomplete requests. |
Toolstation\Customers\Models\CreditSpend | The model includes methods for generating time-based keys for month and year from a DateTime instance. |
Toolstation\Customers\Models\Customer | The 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\CustomerAddress | This Markdown file will help document the CustomerAddress model and ensure that all relevant details are clearly specified.. |
Toolstation\Customers\Models\CustomerAssociated | The CustomerAssociatedBranch model represents branch records linked to customers and interacts with the user_customer_associated_branches table in Toolstation. |
Toolstation\Customers\Models\CustomerAttribute | The CustomerAttribute model represents customer attributes or notes and interacts with the user_customer_notes table in Toolstation. |
Toolstation\Customers\Models\CustomerAudit | The CustomerAudit model tracks audit records and interfaces with the user_customers_updates table. |
Toolstation\Customers\Models\CustomerCard | The 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\CustomerIdentityToken | The CustomerIdentityToken model represents identity tokens for customers, interacting with the user_customer_identity_tokens table. |
Toolstation\Customers\Models\CustomerIssue | The CustomerIssue model represents customer-reported issues and interacts with the user_customer_issues table. |
Toolstation\Customers\Models\CustomerIssueNote | The CustomerIssueNote model extends SystemNote for notes on customer issues. |
Toolstation\Customers\Models\CustomerNote | The CustomerNote model extends SystemNote for customer-specific notes in Eloquent. |
Toolstation\Customers\Models\CustomerSpend | The CustomerSpend model handles customer spending data in Eloquent. |
Toolstation\Customers\Models\CustomerStats | The CustomerStats class, in the Toolstation\Customers\Models namespace, represents customer-related statistics and interacts with the user_customer_stats table |
Toolstation\Customers\Models\CustomerUpdates | The CustomerUpdates model requires manual management of createdAt and updatedAt timestamps and uses a non-incrementing string primary key, ucup_ucu_uid |
Toolstation\Customers\Models\Recommendation | The Recommendation class, located in the Toolstation\Customers\Models namespace, represents customer recommendations and interacts with the recommendations table. |
Toolstation\Customers\Models\RecommendationUnsubscribe | The email maps to run_email and must be validated. This model tracks unsubscribes for recommendation system integrity. |
Toolstation\Customers\Models\SavedAccountApplication | The 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
- Created At:
- Field Prefix:
uac - Fillable Attributes:
namenumberwhocreatedupdated
- Date Attributes:
uac_createduac_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- RelatedAccountAttributemodels.customers():BelongsToMany- Associated customers vialnk_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:
accountIdattributeIdvaluecreated
- 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 ofAccountAttributeCollectionfor managing collections ofAccountAttributemodels.
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_idtypestatusapplication_datanotes
- Constants:
APPLICATION_TYPES:PROCARD: 1PROCARD_ZERO: 2
STATUSES:PENDING: 1APPROVED: 2DECLINED: 3DRAFT: 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 toAPPROVEDand saves the model.decline(): Sets the status toDECLINEDand 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:
addressIdcustomerIddatecompleted
- Accessors:
getCustomerIdAttribute: Convertsucr_ucu_uidtocustomerId.getAddressIdAttribute: Convertsucr_dad_uidtoaddressId.getDateAttribute: Convertsucr_tstodate.getCompletedAttribute: Convertsucr_completedtocompleted.
- Mutators:
setCustomerIdAttribute: Setsucr_ucu_uidwhencustomerIdis mutated.setAddressIdAttribute: Setsucr_dad_uidwhenaddressIdis mutated.setDateAttribute: Setsucr_tswhendateis mutated.setCompletedAttribute: Setsucr_completedwhencompletedis mutated.
- Scopes:
scopeIncomplete: Filters requests to include only those that are incomplete (ucr_completed = 0anducr_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_idcustomer_idkeyvalue
- Methods:
getMonthKey(\DateTime $date): string: Generates a month key in the formatY-mbased on the givenDateTime.getYearKey(\DateTime $date): string: Generates a year key in the formatYbased on the givenDateTime.
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\Modelsnamespace, ensuring it is organized within the domain of customer-related entities.
Table
- Table:
user_customers - The
Customermodel interacts with theuser_customerstable 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
maindatabase connection, which is likely configured in the application's database configuration file.
Timestamps
- Timestamps: Disabled
- The model does not automatically manage
created_atandupdated_attimestamps. Instead, it uses custom fields (ucu_created_whenanducu_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
primaryAddressrelationship is loaded by default whenever aCustomerinstance 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 theactivestatus 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
contactPreferencesstored 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:
Ordermodel instance. - Usage: Called via
$customer->getOrderByProduct($productId).
transform
- Purpose: Converts a
Customerinstance 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
Addressmodel;CustomerAddressmodel uses theaddressestable. - Connection: Inherits from
Addressmodel (assumed to bemainif not explicitly set). - Timestamps: Inherited from
Addressmodel (assumed to betrueifAddressuses timestamps).
Field Prefix: Inherited from the Address model (not explicitly specified).
Fillable Attributes
The following attributes are mass assignable:
- Attributes inherited from the
Addressmodel, if applicable.
Relationships
customer():BelongsToMany- Defines a many-to-many relationship with theCustomermodel through thelnk_addressespivot table.- Pivot Table:
lnk_addresses - Foreign Key (Address):
lna_address - Foreign Key (Customer):
lna_linkto
- Pivot Table:
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(Usesucab_created_atanducab_updated_atfor timestamps)
Fillable Attributes
The following attributes are mass assignable:
customerIdsiteIdtype
Constants
TYPES: An associative array mapping type names to their values:default=> 1favourite=> 2ordered_from=> 3collected_from=> 4
TYPE_DESCRIPTIONS: An associative array mapping type values to their descriptions:- 1 =>
DEFAULT - 2 =>
FAVOURITE - 3 =>
ORDERED_FROM - 4 =>
COLLECTED_FROM
- 1 =>
Accessors
getIdAttribute(): Returns the value of the primary keyucab_uid.getCustomerIdAttribute(): Returns the value of theucab_ucu_uidattribute.getSiteIdAttribute(): Returns the value of theucab_ssi_uidattribute.getTypeAttribute(): Returns the value of theucab_typeattribute.getCreatedAtAttribute(): Returns the value of theucab_created_atattribute.getUpdatedAtAttribute(): Returns the value of theucab_updated_atattribute.
Mutators
setCustomerIdAttribute($value): Sets the value for theucab_ucu_uidattribute.setSiteIdAttribute($value): Sets the value for theucab_ssi_uidattribute.setTypeAttribute($value): Sets the value for theucab_typeattribute.
Relationships
customer(): Defines abelongsTorelationship with theCustomermodel usingucab_ucu_uidas the foreign key.site(): Defines abelongsTorelationship with theSystemSitemodel usingucab_ssi_uidas 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
customerIdkeyvaluedateTimeupdatedWho
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 newCustomerAttributeCollectioninstance.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
CustomerAttributeCollectionfor handling collections of attributes. - The
getNameAttribute()method relies on cached data for attribute names to improve performance. - Ensure that the
sys_statustable contains the necessary attribute statuses for proper functioning of thegetCustomerAttributeStatuses()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
idactionTimestampactioncustomerIdusernametitlefirstNamelastNametelephonemobilefaxemailcookiecompanyjobTitlecontactPreferencescreatedAtcreatedByupdatedAtupdatedByactive
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(): Returnsnullas remember tokens are not used for this model.
Notes
- The model extends
Authenticatableand usesNotifiabletraits but does not handle authentication or remember tokens. - Date attributes
ucu_created_whenanducu_updated_whenare 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
idcardNumbercustomerIdtypeactiveupdatedAtcreatedAtexpiryAt
Date Attributes
updatedAtcreatedAtexpiryAt
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
bootmethod automatically assigns a new card number and timestamps (updatedAtandcreatedAt) when a new record is being created. - The
newCardNumbermethod 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
addressIdcustomerIdtypedatecompleted
Date Attributes
date(maps touccr_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_completedis 0).scopeType($query, $type): Filters card requests by type (uccr_sst_uid).
Notes
- The
CustomerCardRequestmodel does not handle timestamps automatically;createdAtandupdatedAtshould be managed manually if needed. - The
scopeIncompleteandscopeTypemethods 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_atandupdated_atfields) - Field Prefix:
ucit_(fields are prefixed withucit_)
Fillable Attributes
customerIduserAgenttokenHashexpiresAt
Date Attributes
expiresAt(maps toucit_expires_at)createdAt(maps toucit_created_at)updatedAt(maps toucit_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
CustomerIdentityTokenmodel handles its timestamps automatically via Laravel'screated_atandupdated_atfields. - The
getCreatedAtAttributemethod maps theucit_created_atfield to thecreated_atattribute of the model. - The
expiresAtattribute 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 withuci_)
Fillable Attributes
idtypecategorycreatedcompletedlastAcknowledgeduserCreateduserCompletedorderIdcommentCreatedcommentCompletedproductCodeadditionalNotesresolutionType
Date Attributes
created(maps touci_ts_created)completed(maps touci_ts_completed)lastAcknowledged(maps touci_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
CustomerIssuemodel does not handle timestamps automatically;created_atandupdated_atshould be managed manually if needed. - The
getTypeTextAttributemethod fetches issue statuses from cache or the database, providing a textual description of the issue type. - The
redactableattribute 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
CustomerIssueNotemodel extends theSystemNotemodel and does not have additional timestamps or table definitions; it inherits these from the parent model. - The
getIssueIdAttributemethod 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 toboolean)
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 bySystemStatus::COMMENT_GROUP(dcm_group).
Scopes
scopeNormal($query): Filters notes that are categorized as normal comments (dcm_groupisNORMAL_COMMENT).scopeInternal($query): Filters notes that are categorized as internal comments (dcm_groupisINTERNAL_COMMENT).
Notes
- The
CustomerNotemodel extends theSystemNotemodel and inherits its table and primary key configurations. - The
getCustomerIdAttributemethod provides a convenient accessor for the customer ID. - The
group()relationship fetches the system status group for the note, constrained by theCOMMENT_GROUPtype. - The
scopeNormalandscopeInternalmethods 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_idkeyvalue
Notes
- The
CustomerSpendmodel does not handle timestamps automatically;createdAtandupdatedAtshould be managed manually if needed. - The
fillablearray 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
CustomerStatsmodel does not handle timestamps automatically;createdAtandupdatedAtshould be managed manually if needed. - The
fillablearray 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
CustomerUpdatesmodel does not handle timestamps automatically;createdAtandupdatedAtshould 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_atandrec_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_atandrun_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
emailattribute is mapped to therun_emailfield 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
stateandpinattributes are encrypted before saving and decrypted when accessed to ensure sensitive information is stored securely. - Application States: The
STATUSconstant 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.