From 15b18dfc8fe5fbac98a92b78602cd311021390b6 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 6 Apr 2022 10:38:01 +1000 Subject: [PATCH] Entity translations --- app/Jobs/Document/ZipDocuments.php | 9 +- app/Models/Client.php | 4 + app/Models/Company.php | 5 + app/Models/Credit.php | 5 + app/Models/Expense.php | 5 + app/Models/Invoice.php | 5 + app/Models/Payment.php | 4 + app/Models/Product.php | 7 +- app/Models/Project.php | 4 + app/Models/Quote.php | 5 + app/Models/RecurringExpense.php | 5 +- app/Models/RecurringInvoice.php | 5 + app/Models/RecurringQuote.php | 4 + app/Models/Task.php | 7 +- app/Models/User.php | 5 + app/Models/Vendor.php | 5 + tests/Unit/EntityTranslationTest.php | 157 +++++++++++++++++++++++++++ 17 files changed, 236 insertions(+), 5 deletions(-) create mode 100644 tests/Unit/EntityTranslationTest.php diff --git a/app/Jobs/Document/ZipDocuments.php b/app/Jobs/Document/ZipDocuments.php index 12312acb207e..4ff689e97173 100644 --- a/app/Jobs/Document/ZipDocuments.php +++ b/app/Jobs/Document/ZipDocuments.php @@ -88,7 +88,7 @@ class ZipDocuments implements ShouldQueue foreach ($documents as $document) { - $zipFile->addFromString($document->name, $document->getFile()); + $zipFile->addFromString($this->buildFileName($document), $document->getFile()); } @@ -112,7 +112,12 @@ class ZipDocuments implements ShouldQueue $zipFile->close(); } - } + + private function buildFileName($document) :string + { + $filename = $document->name; + + } } diff --git a/app/Models/Client.php b/app/Models/Client.php index 2d6a0d915d4e..19133814d622 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -712,4 +712,8 @@ class Client extends BaseModel implements HasLocalePreference ]; } + public function translate_entity() + { + return ctrans('texts.client'); + } } diff --git a/app/Models/Company.php b/app/Models/Company.php index 24e1ff98f288..35739589ae56 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -549,4 +549,9 @@ class Company extends BaseModel return $data; } + + public function translate_entity() + { + return ctrans('texts.company'); + } } diff --git a/app/Models/Credit.php b/app/Models/Credit.php index 310041dbefd4..191b4dbcbbf4 100644 --- a/app/Models/Credit.php +++ b/app/Models/Credit.php @@ -314,4 +314,9 @@ class Credit extends BaseModel 'credit_status' => $credit->status_id ?: 1, ]; } + + public function translate_entity() + { + return ctrans('texts.credit'); + } } diff --git a/app/Models/Expense.php b/app/Models/Expense.php index d9a09f6c2c54..27f1273113d1 100644 --- a/app/Models/Expense.php +++ b/app/Models/Expense.php @@ -101,4 +101,9 @@ class Expense extends BaseModel { return $this->belongsTo(Client::class); } + + public function translate_entity() + { + return ctrans('texts.expense'); + } } diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 30d4128cd318..5a028981c5f7 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -560,4 +560,9 @@ class Invoice extends BaseModel 'invoice_status' => $invoice->status_id ?: 1, ]; } + + public function translate_entity() + { + return ctrans('texts.invoice'); + } } diff --git a/app/Models/Payment.php b/app/Models/Payment.php index 584fef37652e..47094396944b 100644 --- a/app/Models/Payment.php +++ b/app/Models/Payment.php @@ -337,4 +337,8 @@ class Payment extends BaseModel ]; } + public function translate_entity() + { + return ctrans('texts.payment'); + } } diff --git a/app/Models/Product.php b/app/Models/Product.php index 01b185263387..19f3d2be7e4f 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -64,4 +64,9 @@ class Product extends BaseModel { return $this->morphMany(Document::class, 'documentable'); } -} + + public function translate_entity() + { + return ctrans('texts.product'); + } +} \ No newline at end of file diff --git a/app/Models/Project.php b/app/Models/Project.php index daf67ad2d1e8..694a44c8dc89 100644 --- a/app/Models/Project.php +++ b/app/Models/Project.php @@ -78,4 +78,8 @@ class Project extends BaseModel return $this->hasMany(Task::class); } + public function translate_entity() + { + return ctrans('texts.project'); + } } diff --git a/app/Models/Quote.php b/app/Models/Quote.php index 7dd4af6e1693..a0a9c8b09925 100644 --- a/app/Models/Quote.php +++ b/app/Models/Quote.php @@ -311,4 +311,9 @@ class Quote extends BaseModel { return $this->calc()->getTotal(); } + + public function translate_entity() + { + return ctrans('texts.quote'); + } } diff --git a/app/Models/RecurringExpense.php b/app/Models/RecurringExpense.php index b886fac71349..aca56970e451 100644 --- a/app/Models/RecurringExpense.php +++ b/app/Models/RecurringExpense.php @@ -239,5 +239,8 @@ class RecurringExpense extends BaseModel } } - + public function translate_entity() + { + return ctrans('texts.recurring_expense'); + } } diff --git a/app/Models/RecurringInvoice.php b/app/Models/RecurringInvoice.php index b600c8c65b4f..7b83d1c22a46 100644 --- a/app/Models/RecurringInvoice.php +++ b/app/Models/RecurringInvoice.php @@ -505,4 +505,9 @@ class RecurringInvoice extends BaseModel { return $this->belongsTo(Subscription::class); } + + public function translate_entity() + { + return ctrans('texts.recurring_invoice'); + } } diff --git a/app/Models/RecurringQuote.php b/app/Models/RecurringQuote.php index b6a685a3a2cd..a35b911453b4 100644 --- a/app/Models/RecurringQuote.php +++ b/app/Models/RecurringQuote.php @@ -488,5 +488,9 @@ class RecurringQuote extends BaseModel return new RecurringService($this); } + public function translate_entity() + { + return ctrans('texts.recurring_quote'); + } } diff --git a/app/Models/Task.php b/app/Models/Task.php index 96d169d965e3..b4e10732200d 100644 --- a/app/Models/Task.php +++ b/app/Models/Task.php @@ -147,4 +147,9 @@ class Task extends BaseModel return round($duration); } -} + + public function translate_entity() + { + return ctrans('texts.task'); + } +} \ No newline at end of file diff --git a/app/Models/User.php b/app/Models/User.php index 7288f94a7e67..16a809109040 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -449,4 +449,9 @@ class User extends Authenticatable implements MustVerifyEmail { return new UserService($this); } + + public function translate_entity() + { + return ctrans('texts.user'); + } } diff --git a/app/Models/Vendor.php b/app/Models/Vendor.php index b7505d680a25..7cc03366a364 100644 --- a/app/Models/Vendor.php +++ b/app/Models/Vendor.php @@ -104,4 +104,9 @@ class Vendor extends BaseModel { return $this->belongsTo(User::class)->withTrashed(); } + + public function translate_entity() + { + return ctrans('texts.vendor'); + } } diff --git a/tests/Unit/EntityTranslationTest.php b/tests/Unit/EntityTranslationTest.php new file mode 100644 index 000000000000..9eaec378a5ea --- /dev/null +++ b/tests/Unit/EntityTranslationTest.php @@ -0,0 +1,157 @@ +faker = \Faker\Factory::create(); + } + + public function testTranslations() + { + $account = Account::factory()->create([ + 'hosted_client_count' => 1000, + 'hosted_company_count' => 1000 + ]); + + + $company = Company::factory()->create([ + 'account_id' => $account->id, + ]); + + $u = User::factory()->create([ + 'email' => $this->faker->email, + 'account_id' => $account->id + ]); + + $client = Client::factory()->create([ + 'company_id' => $company->id, + 'user_id' => $u->id + ]); + + $credit = Credit::factory()->create([ + 'company_id' => $company->id, + 'user_id' => $u->id, + 'client_id' => $client->id, + ]); + + $expense = Expense::factory()->create([ + 'company_id' => $company->id, + 'user_id' => $u->id, + 'client_id' => $client->id, + ]); + + $invoice = Invoice::factory()->create([ + 'company_id' => $company->id, + 'user_id' => $u->id, + 'client_id' => $client->id, + ]); + + $payment = Payment::factory()->create([ + 'company_id' => $company->id, + 'user_id' => $u->id, + 'client_id' => $client->id, + ]); + + $product = Product::factory()->create([ + 'company_id' => $company->id, + 'user_id' => $u->id, + ]); + + $project = Project::factory()->create([ + 'company_id' => $company->id, + 'user_id' => $u->id, + 'client_id' => $client->id, + ]); + + $quote = Quote::factory()->create([ + 'company_id' => $company->id, + 'user_id' => $u->id, + 'client_id' => $client->id, + ]); + + $recurring_expense = RecurringExpense::factory()->create([ + 'company_id' => $company->id, + 'user_id' => $u->id, + 'client_id' => $client->id, + ]); + + $recurring_invoice = RecurringInvoice::factory()->create([ + 'company_id' => $company->id, + 'user_id' => $u->id, + 'client_id' => $client->id, + ]); + + $recurring_quote = RecurringQuote::factory()->create([ + 'company_id' => $company->id, + 'user_id' => $u->id, + 'client_id' => $client->id, + ]); + + $task = Task::factory()->create([ + 'company_id' => $company->id, + 'user_id' => $u->id, + 'client_id' => $client->id, + ]); + + $vendor = Vendor::factory()->create([ + 'company_id' => $company->id, + 'user_id' => $u->id, + ]); + + $this->assertEquals(ctrans('texts.user'), $u->translate_entity()); + $this->assertEquals(ctrans('texts.company'), $company->translate_entity()); + $this->assertEquals(ctrans('texts.client'), $client->translate_entity()); + $this->assertEquals(ctrans('texts.credit'), $credit->translate_entity()); + $this->assertEquals(ctrans('texts.expense'), $expense->translate_entity()); + $this->assertEquals(ctrans('texts.invoice'), $invoice->translate_entity()); + $this->assertEquals(ctrans('texts.payment'), $payment->translate_entity()); + $this->assertEquals(ctrans('texts.product'), $product->translate_entity()); + $this->assertEquals(ctrans('texts.project'), $project->translate_entity()); + $this->assertEquals(ctrans('texts.quote'), $quote->translate_entity()); + $this->assertEquals(ctrans('texts.recurring_expense'), $recurring_expense->translate_entity()); + $this->assertEquals(ctrans('texts.recurring_invoice'), $recurring_invoice->translate_entity()); + $this->assertEquals(ctrans('texts.recurring_quote'), $recurring_quote->translate_entity()); + $this->assertEquals(ctrans('texts.task'), $task->translate_entity()); + $this->assertEquals(ctrans('texts.vendor'), $vendor->translate_entity()); + } + +}