From 375ce81df9a219948a6d53a5208edde8f3f82320 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 7 Jul 2022 16:13:37 +1000 Subject: [PATCH] Fixes for language seeder --- app/Models/Expense.php | 2 +- app/Models/PurchaseOrder.php | 2 +- app/Transformers/ExpenseTransformer.php | 1 - app/Transformers/PurchaseOrderTransformer.php | 12 ++++++++++++ ...22_07_06_080127_add_purchase_order_to_expense.php | 10 +++------- database/seeders/LanguageSeeder.php | 1 - 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/app/Models/Expense.php b/app/Models/Expense.php index c36a8f67cb..e79c0fb4c0 100644 --- a/app/Models/Expense.php +++ b/app/Models/Expense.php @@ -105,7 +105,7 @@ class Expense extends BaseModel public function purchase_order() { - return $this->belongsTo(PurchaseOrder::class); + return $this->hasOne(PurchaseOrder::class); } public function translate_entity() diff --git a/app/Models/PurchaseOrder.php b/app/Models/PurchaseOrder.php index ee25e0cc7a..d34062b513 100644 --- a/app/Models/PurchaseOrder.php +++ b/app/Models/PurchaseOrder.php @@ -169,7 +169,7 @@ class PurchaseOrder extends BaseModel public function expense() { - return $this->hasOne(Expense::class); + return $this->belongsTo(Expense::class); } public function user() diff --git a/app/Transformers/ExpenseTransformer.php b/app/Transformers/ExpenseTransformer.php index 17143e29ef..aa191ab73a 100644 --- a/app/Transformers/ExpenseTransformer.php +++ b/app/Transformers/ExpenseTransformer.php @@ -94,7 +94,6 @@ class ExpenseTransformer extends EntityTransformer 'uses_inclusive_taxes' => (bool) $expense->uses_inclusive_taxes, 'calculate_tax_by_amount' => (bool) $expense->calculate_tax_by_amount, 'entity_type' => 'expense', - 'purchase_order_id' => (string) $this->encodePrimaryKey($expense->purchase_order_id), ]; } } diff --git a/app/Transformers/PurchaseOrderTransformer.php b/app/Transformers/PurchaseOrderTransformer.php index 5364a534c2..0e21a84148 100644 --- a/app/Transformers/PurchaseOrderTransformer.php +++ b/app/Transformers/PurchaseOrderTransformer.php @@ -26,6 +26,10 @@ class PurchaseOrderTransformer extends EntityTransformer 'documents' ]; + protected $availableIncludes = [ + 'expense' + ]; + public function includeInvitations(PurchaseOrder $purchase_order) { $transformer = new PurchaseOrderInvitationTransformer($this->serializer); @@ -41,6 +45,13 @@ class PurchaseOrderTransformer extends EntityTransformer return $this->includeCollection($purchase_order->documents, $transformer, Document::class); } + public function includeExpense(PurchaseOrder $purchase_order) + { + $transformer = new ExpenseTransformer($this->serializer); + + return $this->includeItem($purchase_order->expense, $transformer, Document::class); + } + public function transform(PurchaseOrder $purchase_order) { return [ @@ -103,6 +114,7 @@ class PurchaseOrderTransformer extends EntityTransformer 'exchange_rate' => (float)$purchase_order->exchange_rate, 'paid_to_date' => (float)$purchase_order->paid_to_date, 'subscription_id' => $this->encodePrimaryKey($purchase_order->subscription_id), + 'expense_id' => $this->encodePrimaryKey($purchase_order->expense_id), ]; } diff --git a/database/migrations/2022_07_06_080127_add_purchase_order_to_expense.php b/database/migrations/2022_07_06_080127_add_purchase_order_to_expense.php index bd7b44e514..571d77b9c8 100644 --- a/database/migrations/2022_07_06_080127_add_purchase_order_to_expense.php +++ b/database/migrations/2022_07_06_080127_add_purchase_order_to_expense.php @@ -25,26 +25,22 @@ class AddPurchaseOrderToExpense extends Migration */ public function up() { - Schema::table('expenses', function (Blueprint $table) { - $table->unsignedInteger('purchase_order_id')->nullable()->index(); + Schema::table('purchase_orders', function (Blueprint $table) { + $table->unsignedInteger('expense_id')->nullable()->index(); }); PurchaseOrder::withTrashed()->where('status_id', 4)->update(['status_id' => 5]); - $language = Language::find(33); + $language = Language::where('locale', 'bg')->first(); if(!$language) { - Language::unguard(); $l = new Language(); - $l->id = 33; $l->name = "Bulgarian"; $l->locale = "bg"; $l->save(); - - Language::reguard(); $this->buildCache(true); } diff --git a/database/seeders/LanguageSeeder.php b/database/seeders/LanguageSeeder.php index f871f4a572..6e2541ffbf 100644 --- a/database/seeders/LanguageSeeder.php +++ b/database/seeders/LanguageSeeder.php @@ -56,7 +56,6 @@ class LanguageSeeder extends Seeder ['id' => 30, 'name' => 'Arabic', 'locale' => 'ar'], ['id' => 31, 'name' => 'Persian', 'locale' => 'fa'], ['id' => 32, 'name' => 'Latvian', 'locale' => 'lv_LV'], - ['id' => 33, 'name' => 'Bulgarian', 'locale' => 'bg'], ]; foreach ($languages as $language) {