Merge Invoice and Bill into Document
This commit is contained in:
@@ -12,7 +12,7 @@ class Item extends TransformerAbstract
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $defaultIncludes = ['tax', 'category'];
|
||||
protected $defaultIncludes = ['taxes', 'category'];
|
||||
|
||||
/**
|
||||
* @param Model $model
|
||||
@@ -28,7 +28,7 @@ class Item extends TransformerAbstract
|
||||
'sale_price' => $model->sale_price,
|
||||
'purchase_price' => $model->purchase_price,
|
||||
'category_id' => $model->category_id,
|
||||
'tax_id' => $model->tax_id,
|
||||
'tax_ids' => $model->tax_ids,
|
||||
'picture' => $model->picture,
|
||||
'enabled' => $model->enabled,
|
||||
'created_at' => $model->created_at ? $model->created_at->toIso8601String() : '',
|
||||
@@ -40,13 +40,13 @@ class Item extends TransformerAbstract
|
||||
* @param Model $model
|
||||
* @return mixed
|
||||
*/
|
||||
public function includeTax(Model $model)
|
||||
public function includeTaxes(Model $model)
|
||||
{
|
||||
if (!$model->tax) {
|
||||
if (!$model->taxes) {
|
||||
return $this->null();
|
||||
}
|
||||
|
||||
return $this->item($model->tax, new Tax());
|
||||
return $this->item($model->taxes, new Tax());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Transformers\Purchase;
|
||||
namespace App\Transformers\Document;
|
||||
|
||||
use App\Transformers\Banking\Transaction;
|
||||
use App\Transformers\Common\Contact;
|
||||
use App\Transformers\Setting\Currency;
|
||||
use App\Models\Purchase\Bill as Model;
|
||||
use App\Models\Document\Document as Model;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
|
||||
class Bill extends TransformerAbstract
|
||||
class Document extends TransformerAbstract
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
@@ -24,10 +24,11 @@ class Bill extends TransformerAbstract
|
||||
return [
|
||||
'id' => $model->id,
|
||||
'company_id' => $model->company_id,
|
||||
'bill_number' => $model->bill_number,
|
||||
'type' => $model->type,
|
||||
'document_number' => $model->document_number,
|
||||
'order_number' => $model->order_number,
|
||||
'status' => $model->status,
|
||||
'billed_at' => $model->billed_at ? $model->billed_at->toIso8601String() : '',
|
||||
'issued_at' => $model->issued_at ? $model->issued_at->toIso8601String() : '',
|
||||
'due_at' => $model->due_at ? $model->due_at->toIso8601String() : '',
|
||||
'amount' => $model->amount,
|
||||
'currency_code' => $model->currency_code,
|
||||
@@ -69,7 +70,7 @@ class Bill extends TransformerAbstract
|
||||
*/
|
||||
public function includeHistories(Model $model)
|
||||
{
|
||||
return $this->collection($model->histories, new BillHistories());
|
||||
return $this->collection($model->histories, new DocumentHistories());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,7 +79,7 @@ class Bill extends TransformerAbstract
|
||||
*/
|
||||
public function includeItems(Model $model)
|
||||
{
|
||||
return $this->collection($model->items, new BillItems());
|
||||
return $this->collection($model->items, new DocumentItems());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1,11 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Transformers\Sale;
|
||||
namespace App\Transformers\Document;
|
||||
|
||||
use App\Models\Sale\InvoiceHistory as Model;
|
||||
use App\Models\Document\DocumentHistory as Model;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
|
||||
class InvoiceHistories extends TransformerAbstract
|
||||
class DocumentHistories extends TransformerAbstract
|
||||
{
|
||||
/**
|
||||
* @param Model $model
|
||||
@@ -16,7 +16,8 @@ class InvoiceHistories extends TransformerAbstract
|
||||
return [
|
||||
'id' => $model->id,
|
||||
'company_id' => $model->company_id,
|
||||
'invoice_id' => $model->invoice_id,
|
||||
'type' => $model->type,
|
||||
'document_id' => $model->document_id,
|
||||
'status' => $model->status,
|
||||
'notify' => $model->notify,
|
||||
'description' => $model->description,
|
||||
@@ -1,11 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Transformers\Sale;
|
||||
namespace App\Transformers\Document;
|
||||
|
||||
use App\Models\Sale\InvoiceItem as Model;
|
||||
use App\Models\Document\DocumentItem as Model;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
|
||||
class InvoiceItems extends TransformerAbstract
|
||||
class DocumentItems extends TransformerAbstract
|
||||
{
|
||||
/**
|
||||
* @param Model $model
|
||||
@@ -16,7 +16,8 @@ class InvoiceItems extends TransformerAbstract
|
||||
return [
|
||||
'id' => $model->id,
|
||||
'company_id' => $model->company_id,
|
||||
'invoice_id' => $model->invoice_id,
|
||||
'type' => $model->type,
|
||||
'document_id' => $model->document_id,
|
||||
'item_id' => $model->item_id,
|
||||
'name' => $model->name,
|
||||
'price' => $model->price,
|
||||
@@ -1,11 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Transformers\Sale;
|
||||
namespace App\Transformers\Document;
|
||||
|
||||
use App\Models\Sale\InvoiceTotal as Model;
|
||||
use App\Models\Document\DocumentTotal as Model;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
|
||||
class InvoiceTotals extends TransformerAbstract
|
||||
class DocumentTotals extends TransformerAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -17,7 +17,8 @@ class InvoiceTotals extends TransformerAbstract
|
||||
return [
|
||||
'id' => $model->id,
|
||||
'company_id' => $model->company_id,
|
||||
'invoice_id' => $model->invoice_id,
|
||||
'type' => $model->type,
|
||||
'document_id' => $model->document_id,
|
||||
'code' => $model->code,
|
||||
'name' => $model->name,
|
||||
'amount' => $model->amount,
|
||||
@@ -1,27 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Transformers\Purchase;
|
||||
|
||||
use App\Models\Purchase\BillHistory as Model;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
|
||||
class BillHistories extends TransformerAbstract
|
||||
{
|
||||
/**
|
||||
* @param Model $model
|
||||
* @return array
|
||||
*/
|
||||
public function transform(Model $model)
|
||||
{
|
||||
return [
|
||||
'id' => $model->id,
|
||||
'company_id' => $model->company_id,
|
||||
'bill_id' => $model->bill_id,
|
||||
'status' => $model->status,
|
||||
'notify' => $model->notify,
|
||||
'description' => $model->description,
|
||||
'created_at' => $model->created_at ? $model->created_at->toIso8601String() : '',
|
||||
'updated_at' => $model->updated_at ? $model->updated_at->toIso8601String() : '',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Transformers\Purchase;
|
||||
|
||||
use App\Models\Purchase\BillItem as Model;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
|
||||
class BillItems extends TransformerAbstract
|
||||
{
|
||||
/**
|
||||
* @param Model $model
|
||||
* @return array
|
||||
*/
|
||||
public function transform(Model $model)
|
||||
{
|
||||
return [
|
||||
'id' => $model->id,
|
||||
'company_id' => $model->company_id,
|
||||
'bill_id' => $model->bill_id,
|
||||
'item_id' => $model->item_id,
|
||||
'name' => $model->name,
|
||||
'price' => $model->price,
|
||||
'total' => $model->total,
|
||||
'tax' => $model->tax,
|
||||
'tax_id' => $model->tax_id,
|
||||
'created_at' => $model->created_at ? $model->created_at->toIso8601String() : '',
|
||||
'updated_at' => $model->updated_at ? $model->updated_at->toIso8601String() : '',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Transformers\Purchase;
|
||||
|
||||
use App\Models\Purchase\BillTotal as Model;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
|
||||
class BillTotals extends TransformerAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Model $model
|
||||
* @return array
|
||||
*/
|
||||
public function transform(Model $model)
|
||||
{
|
||||
return [
|
||||
'id' => $model->id,
|
||||
'company_id' => $model->company_id,
|
||||
'bill_id' => $model->bill_id,
|
||||
'code' => $model->code,
|
||||
'name' => $model->name,
|
||||
'amount' => $model->amount,
|
||||
'sort_order' => $model->sort_order,
|
||||
'created_at' => $model->created_at ? $model->created_at->toIso8601String() : '',
|
||||
'updated_at' => $model->updated_at ? $model->updated_at->toIso8601String() : '',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Transformers\Sale;
|
||||
|
||||
use App\Transformers\Banking\Transaction;
|
||||
use App\Transformers\Common\Contact;
|
||||
use App\Transformers\Setting\Currency;
|
||||
use App\Models\Sale\Invoice as Model;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
|
||||
class Invoice extends TransformerAbstract
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $defaultIncludes = ['contact', 'currency', 'histories', 'items', 'transactions'];
|
||||
|
||||
/**
|
||||
* @param Model $model
|
||||
* @return array
|
||||
*/
|
||||
public function transform(Model $model)
|
||||
{
|
||||
return [
|
||||
'id' => $model->id,
|
||||
'company_id' => $model->company_id,
|
||||
'invoice_number' => $model->invoice_number,
|
||||
'order_number' => $model->order_number,
|
||||
'status' => $model->status,
|
||||
'invoiced_at' => $model->invoiced_at ? $model->invoiced_at->toIso8601String() : '',
|
||||
'due_at' => $model->due_at ? $model->due_at->toIso8601String() : '',
|
||||
'amount' => $model->amount,
|
||||
'currency_code' => $model->currency_code,
|
||||
'currency_rate' => $model->currency_rate,
|
||||
'contact_id' => $model->contact_id,
|
||||
'contact_name' => $model->contact_name,
|
||||
'contact_email' => $model->contact_email,
|
||||
'contact_tax_number' => $model->contact_tax_number,
|
||||
'contact_phone' => $model->contact_phone,
|
||||
'contact_address' => $model->contact_address,
|
||||
'notes' => $model->notes,
|
||||
'attachment' => $model->attachment,
|
||||
'created_at' => $model->created_at ? $model->created_at->toIso8601String() : '',
|
||||
'updated_at' => $model->updated_at ? $model->updated_at->toIso8601String() : '',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model $model
|
||||
* @return \League\Fractal\Resource\Item
|
||||
*/
|
||||
public function includeContact(Model $model)
|
||||
{
|
||||
return $this->item($model->contact, new Contact());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model $model
|
||||
* @return \League\Fractal\Resource\Item
|
||||
*/
|
||||
public function includeCurrency(Model $model)
|
||||
{
|
||||
return $this->item($model->currency, new Currency());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model $model
|
||||
* @return \League\Fractal\Resource\Collection
|
||||
*/
|
||||
public function includeHistories(Model $model)
|
||||
{
|
||||
return $this->collection($model->histories, new InvoiceHistories());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model $model
|
||||
* @return \League\Fractal\Resource\Collection
|
||||
*/
|
||||
public function includeItems(Model $model)
|
||||
{
|
||||
return $this->collection($model->items, new InvoiceItems());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model $model
|
||||
* @return \League\Fractal\Resource\Collection
|
||||
*/
|
||||
public function includeTransactions(Model $model)
|
||||
{
|
||||
return $this->collection($model->transactions, new Transaction());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user