diff --git a/app/Models/ProfitCenter.php b/app/Models/ProfitCenter.php index 169a518..b035f3e 100644 --- a/app/Models/ProfitCenter.php +++ b/app/Models/ProfitCenter.php @@ -3,6 +3,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Relations\BelongsToMany; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\MorphMany; use Illuminate\Database\Eloquent\SoftDeletes; @@ -33,6 +34,11 @@ public function suppliers(): BelongsToMany return $this->belongsToMany(Supplier::class)->withTimestamps(); } + public function supplierCustomerCodes(): HasMany + { + return $this->hasMany(ProfitCenterSupplierCode::class); + } + public function contact(): MorphMany { return $this->morphMany(Contact::class, 'contactable'); diff --git a/app/Models/ProfitCenterSupplierCode.php b/app/Models/ProfitCenterSupplierCode.php new file mode 100644 index 0000000..826c314 --- /dev/null +++ b/app/Models/ProfitCenterSupplierCode.php @@ -0,0 +1,23 @@ +belongsTo(ProfitCenter::class); + } + + public function supplier(): BelongsTo + { + return $this->belongsTo(Supplier::class); + } +} diff --git a/app/Models/Supplier.php b/app/Models/Supplier.php index 404da01..94cba64 100644 --- a/app/Models/Supplier.php +++ b/app/Models/Supplier.php @@ -44,6 +44,11 @@ public function profitCenter(): BelongsToMany return $this->belongsToMany(ProfitCenter::class)->withTimestamps(); } + public function customerCodes(): HasMany + { + return $this->hasMany(ProfitCenterSupplierCode::class); + } + public function users(): HasMany { return $this->hasMany(User::class); diff --git a/database/migrations/2026_08_09_090000_add_customer_code_to_suppliers_table.php b/database/migrations/2026_08_09_090000_add_customer_code_to_suppliers_table.php new file mode 100644 index 0000000..410466a --- /dev/null +++ b/database/migrations/2026_08_09_090000_add_customer_code_to_suppliers_table.php @@ -0,0 +1,28 @@ +boolean('hasCustomerCode')->default(false)->after('deliveryLeadTime'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('suppliers', function (Blueprint $table) { + $table->dropColumn('hasCustomerCode'); + }); + } +}; diff --git a/database/migrations/2026_08_09_091500_create_profit_center_supplier_codes_table.php b/database/migrations/2026_08_09_091500_create_profit_center_supplier_codes_table.php new file mode 100644 index 0000000..6d7f538 --- /dev/null +++ b/database/migrations/2026_08_09_091500_create_profit_center_supplier_codes_table.php @@ -0,0 +1,34 @@ +id(); + $table->foreignId('profit_center_id')->constrained()->onDelete('cascade'); + $table->foreignId('supplier_id')->constrained()->onDelete('cascade'); + $table->string('customerCode')->nullable(); + $table->userIdFields(); + $table->timestamps(); + $table->softDeletes(); + + $table->unique(['profit_center_id', 'supplier_id']); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('profit_center_supplier_codes'); + } +};