2019-03-27 05:50:13 +01:00
|
|
|
<?php
|
2019-05-11 05:32:07 +02:00
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2020-01-07 01:13:47 +01:00
|
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
2019-03-27 05:50:13 +01:00
|
|
|
|
2019-03-28 03:36:36 +01:00
|
|
|
namespace App\Transformers;
|
2019-03-27 05:50:13 +01:00
|
|
|
|
2019-03-28 03:36:36 +01:00
|
|
|
use App\Models\Account;
|
2019-11-27 10:47:59 +01:00
|
|
|
use App\Models\Activity;
|
2019-03-28 03:36:36 +01:00
|
|
|
use App\Models\Client;
|
2019-04-03 03:17:21 +02:00
|
|
|
use App\Models\Company;
|
2019-10-17 13:49:09 +02:00
|
|
|
use App\Models\CompanyGateway;
|
2020-04-11 13:19:05 +02:00
|
|
|
use App\Models\CompanyLedger;
|
2020-07-07 00:35:28 +02:00
|
|
|
use App\Models\CompanyToken;
|
2019-06-24 02:13:53 +02:00
|
|
|
use App\Models\CompanyUser;
|
2020-05-14 11:08:49 +02:00
|
|
|
use App\Models\Credit;
|
2020-02-15 10:06:30 +01:00
|
|
|
use App\Models\Design;
|
2020-08-06 05:04:09 +02:00
|
|
|
use App\Models\Document;
|
2020-01-20 02:31:58 +01:00
|
|
|
use App\Models\Expense;
|
2019-09-22 12:41:43 +02:00
|
|
|
use App\Models\GroupSetting;
|
2019-12-25 13:22:10 +01:00
|
|
|
use App\Models\Payment;
|
2020-05-23 05:33:44 +02:00
|
|
|
use App\Models\PaymentTerm;
|
2019-12-25 13:22:10 +01:00
|
|
|
use App\Models\Product;
|
2020-01-21 01:32:34 +01:00
|
|
|
use App\Models\Project;
|
2019-12-26 23:49:47 +01:00
|
|
|
use App\Models\Quote;
|
2020-08-24 04:45:53 +02:00
|
|
|
use App\Models\SystemLog;
|
2020-01-21 01:32:34 +01:00
|
|
|
use App\Models\Task;
|
2020-09-06 11:38:10 +02:00
|
|
|
use App\Models\TaxRate;
|
2019-03-28 03:36:36 +01:00
|
|
|
use App\Models\User;
|
2020-07-07 00:35:28 +02:00
|
|
|
use App\Models\Webhook;
|
2020-04-11 13:19:05 +02:00
|
|
|
use App\Transformers\CompanyLedgerTransformer;
|
2020-07-13 04:54:56 +02:00
|
|
|
use App\Transformers\CompanyTokenHashedTransformer;
|
2020-07-07 00:35:28 +02:00
|
|
|
use App\Transformers\CompanyTokenTransformer;
|
2020-05-14 11:08:49 +02:00
|
|
|
use App\Transformers\CreditTransformer;
|
2020-08-06 05:04:09 +02:00
|
|
|
use App\Transformers\DocumentTransformer;
|
2020-05-23 05:33:44 +02:00
|
|
|
use App\Transformers\PaymentTermTransformer;
|
2020-08-24 04:45:53 +02:00
|
|
|
use App\Transformers\SystemLogTransformer;
|
2020-01-21 10:13:16 +01:00
|
|
|
use App\Transformers\TaskTransformer;
|
2020-07-07 00:35:28 +02:00
|
|
|
use App\Transformers\WebhookTransformer;
|
2019-03-27 05:50:13 +01:00
|
|
|
use App\Utils\Traits\MakesHash;
|
|
|
|
|
|
|
|
/**
|
2019-12-26 23:49:47 +01:00
|
|
|
* Class CompanyTransformer.
|
2019-03-27 05:50:13 +01:00
|
|
|
*/
|
|
|
|
class CompanyTransformer extends EntityTransformer
|
|
|
|
{
|
2019-04-03 03:17:21 +02:00
|
|
|
use MakesHash;
|
2019-03-27 05:50:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $defaultIncludes = [
|
2020-08-06 05:04:09 +02:00
|
|
|
'documents',
|
2019-03-27 05:50:13 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $availableIncludes = [
|
2020-08-06 05:04:09 +02:00
|
|
|
'documents',
|
2019-03-27 05:50:13 +01:00
|
|
|
'users',
|
2020-02-15 10:06:30 +01:00
|
|
|
'designs',
|
2019-03-27 05:50:13 +01:00
|
|
|
'account',
|
|
|
|
'clients',
|
|
|
|
'contacts',
|
|
|
|
'invoices',
|
|
|
|
'tax_rates',
|
|
|
|
'products',
|
|
|
|
'country',
|
|
|
|
'timezone',
|
|
|
|
'language',
|
|
|
|
'expenses',
|
2020-01-20 02:31:58 +01:00
|
|
|
'vendors',
|
2019-03-27 05:50:13 +01:00
|
|
|
'payments',
|
2020-05-23 05:33:44 +02:00
|
|
|
'payment_terms',
|
2019-09-11 01:31:55 +02:00
|
|
|
'company_user',
|
2019-10-17 13:49:09 +02:00
|
|
|
'groups',
|
|
|
|
'company_gateways',
|
2019-12-26 23:49:47 +01:00
|
|
|
'activities',
|
|
|
|
'quotes',
|
2020-05-14 11:08:49 +02:00
|
|
|
'credits',
|
2020-01-21 01:32:34 +01:00
|
|
|
'projects',
|
|
|
|
'tasks',
|
2020-04-11 13:19:05 +02:00
|
|
|
'ledger',
|
2020-07-07 00:35:28 +02:00
|
|
|
'webhooks',
|
2020-07-13 04:54:56 +02:00
|
|
|
'tokens',
|
2020-08-24 04:45:53 +02:00
|
|
|
'tokens_hashed',
|
|
|
|
'system_logs',
|
2019-03-27 05:50:13 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Company $company
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function transform(Company $company)
|
|
|
|
{
|
2019-11-21 09:38:57 +01:00
|
|
|
$std = new \stdClass;
|
|
|
|
|
2019-03-27 05:50:13 +01:00
|
|
|
return [
|
2020-09-06 11:38:10 +02:00
|
|
|
'id' => (string) $this->encodePrimaryKey($company->id),
|
|
|
|
'company_key' => (string) $company->company_key ?: '',
|
|
|
|
'update_products' => (bool) $company->update_products,
|
|
|
|
'fill_products' => (bool) $company->fill_products,
|
|
|
|
'convert_products' => (bool) $company->convert_products,
|
|
|
|
'custom_surcharge_taxes1' => (bool) $company->custom_surcharge_taxes1,
|
|
|
|
'custom_surcharge_taxes2' => (bool) $company->custom_surcharge_taxes2,
|
|
|
|
'custom_surcharge_taxes3' => (bool) $company->custom_surcharge_taxes3,
|
|
|
|
'custom_surcharge_taxes4' => (bool) $company->custom_surcharge_taxes4,
|
|
|
|
'show_product_cost' => (bool) $company->show_product_cost,
|
|
|
|
'enable_product_cost' => (bool) $company->enable_product_cost,
|
|
|
|
'show_product_details' => (bool) $company->show_product_details,
|
|
|
|
'enable_product_quantity' => (bool) $company->enable_product_quantity,
|
|
|
|
'default_quantity' => (bool) $company->default_quantity,
|
2019-11-21 09:38:57 +01:00
|
|
|
'custom_fields' => $company->custom_fields ?: $std,
|
2019-09-27 00:14:02 +02:00
|
|
|
'size_id' => (string) $company->size_id ?: '',
|
|
|
|
'industry_id' => (string) $company->industry_id ?: '',
|
2019-10-29 03:55:26 +01:00
|
|
|
'first_month_of_year' => (string) $company->first_month_of_year ?: '',
|
|
|
|
'first_day_of_week' => (string) $company->first_day_of_week ?: '',
|
2019-12-10 21:53:41 +01:00
|
|
|
'subdomain' => (string) $company->subdomain ?: '',
|
2019-11-22 22:10:53 +01:00
|
|
|
'portal_mode' => (string) $company->portal_mode ?: '',
|
|
|
|
'portal_domain' => (string) $company->portal_domain ?: '',
|
2019-09-27 00:14:02 +02:00
|
|
|
'settings' => $company->settings ?: '',
|
2020-09-06 11:38:10 +02:00
|
|
|
'enabled_tax_rates' => (int) $company->enabled_tax_rates,
|
|
|
|
'enabled_modules' => (int) $company->enabled_modules,
|
|
|
|
'updated_at' => (int) $company->updated_at,
|
|
|
|
'archived_at' => (int) $company->deleted_at,
|
|
|
|
'created_at' =>(int) $company->created_at,
|
|
|
|
'slack_webhook_url' => (string) $company->slack_webhook_url,
|
|
|
|
'google_analytics_url' => (string) $company->google_analytics_key, //@deprecate
|
|
|
|
'google_analytics_key' => (string) $company->google_analytics_key,
|
2020-06-28 12:28:35 +02:00
|
|
|
'enabled_item_tax_rates' => (int) $company->enabled_item_tax_rates,
|
|
|
|
'client_can_register' => (bool) $company->client_can_register,
|
2020-07-06 23:58:26 +02:00
|
|
|
'is_large' => (bool) $company->is_large,
|
2020-07-29 11:25:59 +02:00
|
|
|
'enable_shop_api' => (bool) $company->enable_shop_api,
|
2019-03-27 05:50:13 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2020-08-06 05:04:09 +02:00
|
|
|
public function includeDocuments(Company $company)
|
|
|
|
{
|
|
|
|
$transformer = new DocumentTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($company->documents, $transformer, Document::class);
|
|
|
|
}
|
|
|
|
|
2019-06-24 02:13:53 +02:00
|
|
|
public function includeCompanyUser(Company $company)
|
|
|
|
{
|
|
|
|
$transformer = new CompanyUserTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeItem($company->company_users->where('user_id', auth()->user()->id)->first(), $transformer, CompanyUser::class);
|
|
|
|
}
|
2019-03-27 05:50:13 +01:00
|
|
|
|
2020-07-07 00:35:28 +02:00
|
|
|
public function includeTokens(Company $company)
|
|
|
|
{
|
|
|
|
$transformer = new CompanyTokenTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($company->tokens, $transformer, CompanyToken::class);
|
|
|
|
}
|
|
|
|
|
2020-07-13 04:54:56 +02:00
|
|
|
public function includeTokensHashed(Company $company)
|
|
|
|
{
|
|
|
|
$transformer = new CompanyTokenHashedTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($company->tokens, $transformer, CompanyToken::class);
|
|
|
|
}
|
|
|
|
|
2020-07-07 00:35:28 +02:00
|
|
|
public function includeWebhooks(Company $company)
|
|
|
|
{
|
|
|
|
$transformer = new WebhookTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($company->webhooks, $transformer, Webhook::class);
|
|
|
|
}
|
|
|
|
|
2019-11-27 10:47:59 +01:00
|
|
|
public function includeActivities(Company $company)
|
|
|
|
{
|
|
|
|
$transformer = new ActivityTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($company->activities, $transformer, Activity::class);
|
|
|
|
}
|
|
|
|
|
2019-03-28 03:36:36 +01:00
|
|
|
public function includeUsers(Company $company)
|
|
|
|
{
|
|
|
|
$transformer = new UserTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($company->users, $transformer, User::class);
|
|
|
|
}
|
|
|
|
|
2019-10-17 13:49:09 +02:00
|
|
|
public function includeCompanyGateways(Company $company)
|
|
|
|
{
|
|
|
|
$transformer = new CompanyGatewayTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($company->company_gateways, $transformer, CompanyGateway::class);
|
|
|
|
}
|
|
|
|
|
2019-03-28 03:36:36 +01:00
|
|
|
public function includeClients(Company $company)
|
|
|
|
{
|
|
|
|
$transformer = new ClientTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($company->clients, $transformer, Client::class);
|
|
|
|
}
|
|
|
|
|
2020-01-21 01:32:34 +01:00
|
|
|
public function includeProjects(Company $company)
|
|
|
|
{
|
|
|
|
$transformer = new ProjectTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($company->projects, $transformer, Project::class);
|
|
|
|
}
|
|
|
|
|
2020-01-21 10:13:16 +01:00
|
|
|
public function includeTasks(Company $company)
|
2020-01-21 01:32:34 +01:00
|
|
|
{
|
|
|
|
$transformer = new TaskTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($company->tasks, $transformer, Task::class);
|
|
|
|
}
|
|
|
|
|
2020-01-20 02:31:58 +01:00
|
|
|
public function includeExpenses(Company $company)
|
|
|
|
{
|
|
|
|
$transformer = new ExpenseTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($company->expenses, $transformer, Expense::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function includeVendors(Company $company)
|
|
|
|
{
|
|
|
|
$transformer = new VendorTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($company->vendors, $transformer, Vendor::class);
|
|
|
|
}
|
|
|
|
|
2019-09-22 12:41:43 +02:00
|
|
|
public function includeGroups(Company $company)
|
|
|
|
{
|
|
|
|
$transformer = new GroupSettingTransformer($this->serializer);
|
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
return $this->includeCollection($company->groups, $transformer, GroupSetting::class);
|
2019-09-22 12:41:43 +02:00
|
|
|
}
|
|
|
|
|
2019-03-28 03:36:36 +01:00
|
|
|
public function includeInvoices(Company $company)
|
|
|
|
{
|
|
|
|
$transformer = new InvoiceTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($company->invoices, $transformer, Invoice::class);
|
|
|
|
}
|
|
|
|
|
2019-12-26 23:49:47 +01:00
|
|
|
public function includeQuotes(Company $company)
|
|
|
|
{
|
|
|
|
$transformer = new QuoteTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($company->quotes, $transformer, Quote::class);
|
|
|
|
}
|
|
|
|
|
2020-05-14 11:08:49 +02:00
|
|
|
public function includeCredits(Company $company)
|
|
|
|
{
|
|
|
|
$transformer = new CreditTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($company->credits, $transformer, Credit::class);
|
|
|
|
}
|
|
|
|
|
2019-03-28 03:36:36 +01:00
|
|
|
public function includeAccount(Company $company)
|
|
|
|
{
|
|
|
|
$transformer = new AccountTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeItem($company->account, $transformer, Account::class);
|
|
|
|
}
|
2019-11-06 23:57:09 +01:00
|
|
|
|
|
|
|
public function includeTaxRates(Company $company)
|
|
|
|
{
|
|
|
|
$transformer = new TaxRateTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($company->tax_rates, $transformer, TaxRate::class);
|
|
|
|
}
|
2019-12-25 13:22:10 +01:00
|
|
|
|
|
|
|
public function includeProducts(Company $company)
|
|
|
|
{
|
|
|
|
$transformer = new ProductTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($company->products, $transformer, Product::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function includePayments(Company $company)
|
|
|
|
{
|
|
|
|
$transformer = new PaymentTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($company->payments, $transformer, Payment::class);
|
|
|
|
}
|
2020-02-15 10:06:30 +01:00
|
|
|
|
|
|
|
public function includeDesigns(Company $company)
|
|
|
|
{
|
|
|
|
$transformer = new DesignTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($company->designs()->get(), $transformer, Design::class);
|
|
|
|
}
|
2020-04-11 13:19:05 +02:00
|
|
|
|
|
|
|
public function includeLedger(Company $company)
|
|
|
|
{
|
|
|
|
$transformer = new CompanyLedgerTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($company->ledger, $transformer, CompanyLedger::class);
|
|
|
|
}
|
2020-05-23 05:33:44 +02:00
|
|
|
|
|
|
|
public function includePaymentTerms(Company $company)
|
|
|
|
{
|
|
|
|
$transformer = new PaymentTermTransformer($this->serializer);
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
return $this->includeCollection($company->payment_terms()->get(), $transformer, PaymentTerm::class);
|
2020-05-23 05:33:44 +02:00
|
|
|
}
|
2020-08-24 04:45:53 +02:00
|
|
|
|
|
|
|
public function includeSystemLogs(Company $company)
|
|
|
|
{
|
|
|
|
$transformer = new SystemLogTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($company->system_logs, $transformer, SystemLog::class);
|
|
|
|
}
|
2019-03-27 05:50:13 +01:00
|
|
|
}
|