Version 2.0

This commit is contained in:
2026-05-12 09:23:05 +00:00
parent f2bc048219
commit f1b68e5e78
34 changed files with 564 additions and 283 deletions

View File

@@ -132,7 +132,8 @@ app/
│ ├── ImportCskh.php # app:import-cskh command
│ └── ExportBackup.php # app:export-backup command (JSON backup)
├── Enums/
│ ├── ContractType.php # SALE/LEASE/BCC
│ ├── ContractCategory.php # V2: ownership/business
│ ├── ContractType.php # V2: deposit/purchase/transfer/rental/self_business/bcc
│ ├── ContractStatus.php # ACTIVE/EXPIRED/LIQUIDATED
│ ├── HandoverStatus.php # NOT_READY/READY/SCHEDULED/HANDED_OVER
│ └── ServiceType.php # MANAGEMENT_FEE/GRATITUDE/SELF_BUSINESS
@@ -143,9 +144,8 @@ app/
│ └── HandleUploadErrors.php
├── Models/
│ ├── ActivityLog.php # NEW: Audit trail (user_id, action, description, metadata)
│ ├── Contract.php
│ ├── Customer.php
│ ├── CustomerProduct.php # pivot model (customer_product table)
│ ├── Contract.php # V2: +category, +representative_*
│ ├── Customer.php # V2: ownedProducts() qua contracts
│ ├── Department.php
│ ├── Feedback.php
│ ├── FeedbackAttachment.php
@@ -224,7 +224,7 @@ Relationships: `user()` BelongsTo
| description | text nullable |
| status | string (active/inactive/sold_out) |
Relationships: `customers()` BelongsToMany (pivot: customer_product, withPivot: purchase_date), `contracts()` HasMany, `handovers()` HasMany, `productServices()` HasMany
Relationships: `contracts()` HasMany, `handovers()` HasMany, `productServices()` HasMany
### ProductService (`product_services`)
| Cột | Kiểu |
@@ -250,22 +250,28 @@ Relationships: `product()` BelongsTo
Relationships: `product()` BelongsTo, `customer()` BelongsTo
### Contract (`contracts`)
### Contract (`contracts`) — V2
| Cột | Kiểu |
|-----|------|
| id | bigint PK |
| product_id | FK->products cascadeOnDelete |
| customer_id | FK->customers cascadeOnDelete |
| type | string (sale/lease/bcc → ContractType enum) |
| category | string (ownership/business → ContractCategory enum) |
| type | string (deposit/purchase/transfer/rental/self_business/bcc → ContractType enum) |
| start_date | date nullable |
| end_date | date nullable |
| status | string (active/expired/liquidated → ContractStatus enum) |
| printed_at | date nullable |
| signed_status | string nullable |
| representative_name | string nullable |
| representative_phone | string nullable |
| representative_email | string nullable |
Relationships: `product()` BelongsTo, `customer()` BelongsTo, `feedbacks()` HasMany
### Customer (`customers`)
> **Constraint:** Mỗi product tối đa 1 active contract mỗi category. Validation ở Model `booted::saving`.
### Customer (`customers`) — V2
| Cột | Kiểu |
|-----|------|
| id | bigint PK |
@@ -275,18 +281,7 @@ Relationships: `product()` BelongsTo, `customer()` BelongsTo, `feedbacks()` HasM
| address | text nullable |
| status | string (active) |
Relationships: `products()` BelongsToMany, `feedbacks()` HasMany
### CustomerProduct (`customer_product` — pivot model)
| Cột | Kiểu |
|-----|------|
| id | bigint PK |
| customer_id | FK->customers cascadeOnDelete |
| product_id | FK->products cascadeOnDelete |
| purchase_date | date nullable |
UNIQUE(customer_id, product_id)
Relationships: `customer()` BelongsTo, `product()` BelongsTo, `feedbacks()` HasMany
Relationships: `ownedProducts()` BelongsToMany qua contracts (ownership + active), `feedbacks()` HasMany
### Department (`departments`)
| Cột | Kiểu |
@@ -308,12 +303,11 @@ Relationships: `manager()` BelongsTo User, `feedbacks()` HasMany, `transferLogsF
Uses Spatie `HasRoles`. Relationships: `assignedFeedbacks()` HasMany Feedback, `activityLogs()` HasMany.
### Feedback (`feedback`)
### Feedback (`feedback`) — V2
| Cột | Kiểu |
|-----|------|
| id | bigint PK |
| customer_id | FK->customers cascadeOnDelete |
| customer_product_id | FK->customer_product nullable nullOnDelete |
| contract_id | FK->contracts nullable nullOnDelete |
| feedback_channel_id | FK->feedback_channels |
| assigned_to | FK->users nullable nullOnDelete |
@@ -323,9 +317,9 @@ Uses Spatie `HasRoles`. Relationships: `assignedFeedbacks()` HasMany Feedback, `
| content | text |
| status | string (pending/processing/resolved/closed) |
Fillable: `['customer_id', 'customer_product_id', 'contract_id', 'feedback_channel_id', 'assigned_to', 'title', 'content', 'status', 'current_department_id', 'is_escalated']`
Fillable: `['customer_id', 'contract_id', 'feedback_channel_id', 'assigned_to', 'title', 'content', 'status', 'current_department_id', 'is_escalated']`
Relationships (10): `customer()`, `customerProduct()`, `contract()`, `feedbackChannel()`, `assignedTo()`, `currentDepartment()`, `transferLogs()`, `interactions()` ordered latest, `attachments()`, `tags()` BelongsToMany
Relationships: `customer()`, `contract()`, `feedbackChannel()`, `assignedTo()`, `currentDepartment()`, `transferLogs()`, `interactions()` ordered latest, `attachments()`, `tags()` BelongsToMany
### FeedbackInteraction (`feedback_interactions`)
| Cột | Kiểu |
@@ -498,6 +492,7 @@ Dashboard (3 custom widgets)
| 23 | `2026_05_01_000003_create_product_services_table` | product_services |
| 24 | `2026_05_01_000004_add_color_to_feedback_channels_table` | (modify feedback_channels) add color |
| 25 | `2026_05_09_104519_create_activity_logs_table` | activity_logs |
| 26 | `2026_05_12_075014_v2_restructure_contracts` | **(V2)** contracts +category, +representative; drop customer_product; drop feedback.customer_product_id |
---