From 75ba62b1e181ba3df60aae86205d969a20f7dda4 Mon Sep 17 00:00:00 2001 From: E98Developer Date: Sun, 9 Aug 2026 09:41:07 +0200 Subject: [PATCH] =?UTF-8?q?ADD=20EV3-431=20Profitcenter=20-=20bet=C5=B1k?= =?UTF-8?q?=C3=B3d=20phase2/1=20add=20ProfitCenterSupplierCode=20data=20mo?= =?UTF-8?q?del?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/ProfitCenter.php | 6 ++++ app/Models/ProfitCenterSupplierCode.php | 23 +++++++++++++ app/Models/Supplier.php | 5 +++ ...0_add_customer_code_to_suppliers_table.php | 28 +++++++++++++++ ...ate_profit_center_supplier_codes_table.php | 34 +++++++++++++++++++ 5 files changed, 96 insertions(+) create mode 100644 app/Models/ProfitCenterSupplierCode.php create mode 100644 database/migrations/2026_08_09_090000_add_customer_code_to_suppliers_table.php create mode 100644 database/migrations/2026_08_09_091500_create_profit_center_supplier_codes_table.php 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'); + } +};