akaunting 3.0 (the last dance)
This commit is contained in:
32
app/Http/Resources/Common/Company.php
Normal file
32
app/Http/Resources/Common/Company.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Common;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class Company extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'email' => $this->email,
|
||||
'currency' => $this->currency,
|
||||
'domain' => $this->domain,
|
||||
'address' => $this->address,
|
||||
'logo' => $this->logo,
|
||||
'enabled' => $this->enabled,
|
||||
'created_from' => $this->created_from,
|
||||
'created_by' => $this->created_by,
|
||||
'created_at' => $this->created_at ? $this->created_at->toIso8601String() : '',
|
||||
'updated_at' => $this->updated_at ? $this->updated_at->toIso8601String() : '',
|
||||
];
|
||||
}
|
||||
}
|
37
app/Http/Resources/Common/Contact.php
Normal file
37
app/Http/Resources/Common/Contact.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Common;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class Contact extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'company_id' => $this->company_id,
|
||||
'user_id' => $this->user_id,
|
||||
'type' => $this->type,
|
||||
'name' => $this->name,
|
||||
'email' => $this->email,
|
||||
'tax_number' => $this->tax_number,
|
||||
'phone' => $this->phone,
|
||||
'address' => $this->address,
|
||||
'website' => $this->website,
|
||||
'currency_code' => $this->currency_code,
|
||||
'enabled' => $this->enabled,
|
||||
'reference' => $this->reference,
|
||||
'created_from' => $this->created_from,
|
||||
'created_by' => $this->created_by,
|
||||
'created_at' => $this->created_at ? $this->created_at->toIso8601String() : '',
|
||||
'updated_at' => $this->updated_at ? $this->updated_at->toIso8601String() : '',
|
||||
];
|
||||
}
|
||||
}
|
35
app/Http/Resources/Common/Dashboard.php
Normal file
35
app/Http/Resources/Common/Dashboard.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Common;
|
||||
|
||||
use App\Http\Resources\Common\Widget;
|
||||
use App\Utilities\Widgets;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class Dashboard extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
$widgets = $this->widgets->filter(function ($widget) {
|
||||
return Widgets::canShow($widget->class);
|
||||
});
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'company_id' => $this->company_id,
|
||||
'name' => $this->name,
|
||||
'enabled' => $this->enabled,
|
||||
'created_from' => $this->created_from,
|
||||
'created_by' => $this->created_by,
|
||||
'created_at' => $this->created_at ? $this->created_at->toIso8601String() : '',
|
||||
'updated_at' => $this->updated_at ? $this->updated_at->toIso8601String() : '',
|
||||
'widgets' => [static::$wrap => Widget::collection($widgets)],
|
||||
];
|
||||
}
|
||||
}
|
40
app/Http/Resources/Common/Item.php
Normal file
40
app/Http/Resources/Common/Item.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Common;
|
||||
|
||||
use App\Http\Resources\Common\ItemTax;
|
||||
use App\Http\Resources\Setting\Category;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class Item extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'company_id' => $this->company_id,
|
||||
'type' => $this->type,
|
||||
'name' => $this->name,
|
||||
'description' => $this->description,
|
||||
'sale_price' => $this->sale_price,
|
||||
'sale_price_formatted' => money($this->sale_price, setting('default.currency'), true)->format(),
|
||||
'purchase_price' => $this->purchase_price,
|
||||
'purchase_price_formatted' => money($this->purchase_price, setting('default.currency'), true)->format(),
|
||||
'category_id' => $this->category_id,
|
||||
'picture' => $this->picture,
|
||||
'enabled' => $this->enabled,
|
||||
'created_from' => $this->created_from,
|
||||
'created_by' => $this->created_by,
|
||||
'created_at' => $this->created_at ? $this->created_at->toIso8601String() : '',
|
||||
'updated_at' => $this->updated_at ? $this->updated_at->toIso8601String() : '',
|
||||
'taxes' => [static::$wrap => ItemTax::collection($this->taxes)],
|
||||
'category' => new Category($this->category),
|
||||
];
|
||||
}
|
||||
}
|
30
app/Http/Resources/Common/ItemTax.php
Normal file
30
app/Http/Resources/Common/ItemTax.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Common;
|
||||
|
||||
use App\Http\Resources\Setting\Tax;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class ItemTax extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'company_id' => $this->company_id,
|
||||
'item_id' => $this->item_id,
|
||||
'tax_id' => $this->tax_id,
|
||||
'created_from' => $this->created_from,
|
||||
'created_by' => $this->created_by,
|
||||
'created_at' => $this->created_at ? $this->created_at->toIso8601String() : '',
|
||||
'updated_at' => $this->updated_at ? $this->updated_at->toIso8601String() : '',
|
||||
'tax' => new Tax($this->tax),
|
||||
];
|
||||
}
|
||||
}
|
53
app/Http/Resources/Common/Report.php
Normal file
53
app/Http/Resources/Common/Report.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Common;
|
||||
|
||||
use App\Utilities\Reports as Utility;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class Report extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'company_id' => $this->company_id,
|
||||
'class' => $this->class,
|
||||
'name' => $this->name,
|
||||
'description' => $this->description,
|
||||
'settings' => $this->settings,
|
||||
'data' => $this->getReportData(),
|
||||
'created_from' => $this->created_from,
|
||||
'created_by' => $this->created_by,
|
||||
'created_at' => $this->created_at ? $this->created_at->toIso8601String() : '',
|
||||
'updated_at' => $this->updated_at ? $this->updated_at->toIso8601String() : '',
|
||||
];
|
||||
}
|
||||
|
||||
protected function getReportData()
|
||||
{
|
||||
if (! Utility::canShow($this->class)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$report = Utility::getClassInstance($this);
|
||||
|
||||
if (empty($report)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$unset_attributes = ['model', 'views', 'loaded', 'column_name_width', 'column_value_width'];
|
||||
|
||||
foreach ($unset_attributes as $attribute) {
|
||||
unset($report->$attribute);
|
||||
}
|
||||
|
||||
return $report;
|
||||
}
|
||||
}
|
32
app/Http/Resources/Common/Widget.php
Normal file
32
app/Http/Resources/Common/Widget.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Common;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class Widget extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'company_id' => $this->company_id,
|
||||
'dashboard_id' => $this->dashboard_id,
|
||||
'class' => $this->class,
|
||||
'name' => $this->name,
|
||||
'sort' => $this->sort,
|
||||
'settings' => $this->settings,
|
||||
'data' => show_widget($this),
|
||||
'created_from' => $this->created_from,
|
||||
'created_by' => $this->created_by,
|
||||
'created_at' => $this->created_at ? $this->created_at->toIso8601String() : '',
|
||||
'updated_at' => $this->updated_at ? $this->updated_at->toIso8601String() : '',
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user