2019-04-03 02:09:22 +02: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
|
|
|
|
*
|
2023-01-28 23:21:40 +01:00
|
|
|
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2019-05-11 05:32:07 +02:00
|
|
|
*/
|
2019-04-03 02:09:22 +02:00
|
|
|
|
|
|
|
namespace App\Transformers;
|
|
|
|
|
2019-04-03 03:17:21 +02:00
|
|
|
use App\Models\Company;
|
2020-06-22 23:56:32 +02:00
|
|
|
use App\Models\Document;
|
2019-04-03 02:09:22 +02:00
|
|
|
use App\Models\Product;
|
2019-04-03 03:17:21 +02:00
|
|
|
use App\Models\User;
|
2019-04-03 02:09:22 +02:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2020-10-28 11:10:49 +01:00
|
|
|
use League\Fractal\Resource\Collection;
|
2019-04-03 02:09:22 +02:00
|
|
|
|
|
|
|
class ProductTransformer extends EntityTransformer
|
|
|
|
{
|
|
|
|
use MakesHash;
|
2019-04-03 03:17:21 +02:00
|
|
|
|
2023-08-21 03:29:31 +02:00
|
|
|
protected array $defaultIncludes = [
|
2020-08-06 05:04:09 +02:00
|
|
|
'documents',
|
2019-04-03 03:17:21 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2023-08-21 03:29:31 +02:00
|
|
|
protected array $availableIncludes = [
|
2019-04-03 03:17:21 +02:00
|
|
|
'company',
|
2020-06-22 23:56:32 +02:00
|
|
|
'user',
|
2019-04-03 03:17:21 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Product $product
|
|
|
|
*
|
2023-07-26 04:59:36 +02:00
|
|
|
* @return \Illuminate\Support\Collection
|
2019-04-03 03:17:21 +02:00
|
|
|
*/
|
|
|
|
public function includeUser(Product $product)
|
|
|
|
{
|
|
|
|
$transformer = new UserTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeItem($product->user, $transformer, User::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Product $product
|
|
|
|
*
|
2023-07-26 04:59:36 +02:00
|
|
|
* @return \Illuminate\Support\Collection
|
2019-04-03 03:17:21 +02:00
|
|
|
*/
|
|
|
|
public function includeCompany(Product $product)
|
|
|
|
{
|
|
|
|
$transformer = new CompanyTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeItem($product->company, $transformer, Company::class);
|
|
|
|
}
|
|
|
|
|
2020-06-22 23:56:32 +02:00
|
|
|
public function includeDocuments(Product $product)
|
|
|
|
{
|
|
|
|
$transformer = new DocumentTransformer($this->serializer);
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-06-22 23:56:32 +02:00
|
|
|
return $this->includeCollection($product->documents, $transformer, Document::class);
|
|
|
|
}
|
|
|
|
|
2019-04-03 02:09:22 +02:00
|
|
|
public function transform(Product $product)
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'id' => $this->encodePrimaryKey($product->id),
|
2019-11-06 23:57:09 +01:00
|
|
|
'user_id' => $this->encodePrimaryKey($product->user_id),
|
|
|
|
'assigned_user_id' => $this->encodePrimaryKey($product->assigned_user_id),
|
2019-09-27 00:14:02 +02:00
|
|
|
'product_key' => $product->product_key ?: '',
|
|
|
|
'notes' => $product->notes ?: '',
|
2019-10-02 09:41:22 +02:00
|
|
|
'cost' => (float) $product->cost ?: 0,
|
|
|
|
'price' => (float) $product->price ?: 0,
|
2019-10-05 04:28:23 +02:00
|
|
|
'quantity' => (float) $product->quantity ?: 1.0,
|
2019-04-03 02:09:22 +02:00
|
|
|
'tax_name1' => $product->tax_name1 ?: '',
|
2019-10-02 09:41:22 +02:00
|
|
|
'tax_rate1' => (float) $product->tax_rate1 ?: 0,
|
2019-04-03 02:09:22 +02:00
|
|
|
'tax_name2' => $product->tax_name2 ?: '',
|
2019-10-02 09:41:22 +02:00
|
|
|
'tax_rate2' => (float) $product->tax_rate2 ?: 0,
|
2019-10-05 04:28:23 +02:00
|
|
|
'tax_name3' => $product->tax_name3 ?: '',
|
|
|
|
'tax_rate3' => (float) $product->tax_rate3 ?: 0,
|
2020-09-06 11:38:10 +02:00
|
|
|
'created_at' => (int) $product->created_at,
|
|
|
|
'updated_at' => (int) $product->updated_at,
|
|
|
|
'archived_at' => (int) $product->deleted_at,
|
2019-04-03 02:09:22 +02:00
|
|
|
'custom_value1' => $product->custom_value1 ?: '',
|
|
|
|
'custom_value2' => $product->custom_value2 ?: '',
|
2019-09-26 01:47:33 +02:00
|
|
|
'custom_value3' => $product->custom_value3 ?: '',
|
|
|
|
'custom_value4' => $product->custom_value4 ?: '',
|
2019-04-03 02:09:22 +02:00
|
|
|
'is_deleted' => (bool) $product->is_deleted,
|
2022-06-03 12:50:19 +02:00
|
|
|
'in_stock_quantity' => (int) $product->in_stock_quantity ?: 0,
|
|
|
|
'stock_notification' => (bool) $product->stock_notification,
|
2022-06-04 00:48:52 +02:00
|
|
|
'stock_notification_threshold' => (int) $product->stock_notification_threshold,
|
2023-02-07 12:47:43 +01:00
|
|
|
'max_quantity' => (int) $product->max_quantity,
|
|
|
|
'product_image' => (string) $product->product_image ?: '',
|
2023-04-19 07:21:50 +02:00
|
|
|
'tax_id' => (string) $product->tax_id ?: '1',
|
2019-04-03 02:09:22 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|