mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
Mock Client InvoiceList
This commit is contained in:
parent
45d00be174
commit
9f624b3c61
50
app/Http/Controllers/Contact/InvoiceController.php
Normal file
50
app/Http/Controllers/Contact/InvoiceController.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com)
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Contact;
|
||||
|
||||
use App\Http\Controllers\BaseController;
|
||||
use App\Models\Invoice;
|
||||
use App\Transformers\Contact\InvoiceTransformer;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class InvoiceController extends BaseController
|
||||
{
|
||||
use MakesHash;
|
||||
|
||||
protected $entity_type = Invoice::class;
|
||||
|
||||
protected $entity_transformer = InvoiceTransformer::class;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
parent::__construct();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the list of Invoices
|
||||
*
|
||||
* @param \App\Filters\ContactInvoiceFilters $filters The filters
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$invoices = Invoice::whereClientId(auth('contact')->user()->client->id);
|
||||
//$invoices = Invoice::filter($filters);
|
||||
|
||||
return $this->listResponse($invoices);
|
||||
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@ use App\Libraries\MultiDB;
|
||||
use App\Models\CompanyToken;
|
||||
use Closure;
|
||||
|
||||
class SetContactDb
|
||||
class ContactSetDb
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
@ -71,12 +71,12 @@ class ClientContact extends Authenticatable
|
||||
|
||||
public function client()
|
||||
{
|
||||
$this->hasOne(Client::class);
|
||||
return $this->belongsTo(Client::class);
|
||||
}
|
||||
|
||||
public function primary_contact()
|
||||
{
|
||||
$this->where('is_primary', true);
|
||||
return $this->where('is_primary', true);
|
||||
}
|
||||
|
||||
public function company()
|
||||
|
51
app/Transformers/ClientContactLoginTransformer.php
Normal file
51
app/Transformers/ClientContactLoginTransformer.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com)
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Transformers;
|
||||
|
||||
use App\Models\ClientContact;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
|
||||
/**
|
||||
* Class ContactTransformer.
|
||||
*
|
||||
* @SWG\Definition(definition="ClientContact", @SWG\Xml(name="ClientContact"))
|
||||
*/
|
||||
class ClientContactLoginTransformer extends EntityTransformer
|
||||
{
|
||||
use MakesHash;
|
||||
/**
|
||||
* @param ClientContact $contact
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
*/
|
||||
public function transform(ClientContact $contact)
|
||||
{
|
||||
|
||||
return [
|
||||
'id' => $this->encodePrimaryKey($contact->id),
|
||||
'first_name' => $contact->first_name ?: '',
|
||||
'last_name' => $contact->last_name ?: '',
|
||||
'email' => $contact->email ?: '',
|
||||
'updated_at' => $contact->updated_at,
|
||||
'archived_at' => $contact->deleted_at,
|
||||
'is_primary' => (bool) $contact->is_primary,
|
||||
'is_locked' => (bool) $contact->is_locked,
|
||||
'phone' => $contact->phone ?: '',
|
||||
'custom_value1' => $contact->custom_value1 ?: '',
|
||||
'custom_value2' => $contact->custom_value2 ?: '',
|
||||
'custom_value3' => $contact->custom_value3 ?: '',
|
||||
'custom_value4' => $contact->custom_value4 ?: '',
|
||||
'token'=> $contact->token ?: '',
|
||||
];
|
||||
}
|
||||
}
|
69
app/Transformers/Contact/InvoiceTransformer.php
Normal file
69
app/Transformers/Contact/InvoiceTransformer.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com)
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Transformers\Contact;
|
||||
|
||||
use App\Models\Invoice;
|
||||
use App\Transformers\EntityTransformer;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
|
||||
/**
|
||||
* @SWG\Definition(definition="Invoice", required={"invoice_number"}, @SWG\Xml(name="Invoice"))
|
||||
*/
|
||||
class InvoiceTransformer extends EntityTransformer
|
||||
{
|
||||
use MakesHash;
|
||||
|
||||
protected $defaultIncludes = [
|
||||
// 'invoice_items',
|
||||
];
|
||||
|
||||
protected $availableIncludes = [
|
||||
];
|
||||
|
||||
public function transform(Invoice $invoice)
|
||||
{
|
||||
return [
|
||||
'id' => $this->encodePrimaryKey($invoice->id),
|
||||
'amount' => (float) $invoice->amount,
|
||||
'balance' => (float) $invoice->balance,
|
||||
'status_id' => (int) ($invoice->status_id ?: 1),
|
||||
'updated_at' => $invoice->updated_at,
|
||||
'archived_at' => $invoice->deleted_at,
|
||||
'invoice_number' => $invoice->invoice_number,
|
||||
'discount' => (float) $invoice->discount,
|
||||
'po_number' => $invoice->po_number,
|
||||
'invoice_date' => $invoice->invoice_date ?: '',
|
||||
'due_date' => $invoice->due_date ?: '',
|
||||
'terms' => $invoice->terms ?: '',
|
||||
'public_notes' => $invoice->public_notes ?: '',
|
||||
'is_deleted' => (bool) $invoice->is_deleted,
|
||||
'invoice_type_id' => (int) $invoice->invoice_type_id,
|
||||
'tax_name1' => $invoice->tax_name1 ? $invoice->tax_name1 : '',
|
||||
'tax_rate1' => (float) $invoice->tax_rate1,
|
||||
'tax_name2' => $invoice->tax_name2 ? $invoice->tax_name2 : '',
|
||||
'tax_rate2' => (float) $invoice->tax_rate2,
|
||||
'is_amount_discount' => (bool) ($invoice->is_amount_discount ?: false),
|
||||
'invoice_footer' => $invoice->invoice_footer ?: '',
|
||||
'partial' => (float) ($invoice->partial ?: 0.0),
|
||||
'partial_due_date' => $invoice->partial_due_date ?: '',
|
||||
'custom_value1' => (float) $invoice->custom_value1,
|
||||
'custom_value2' => (float) $invoice->custom_value2,
|
||||
'custom_value3' => (bool) $invoice->custom_value3,
|
||||
'custom_value4' => (bool) $invoice->custom_value4,
|
||||
'has_tasks' => (bool) $invoice->has_tasks,
|
||||
'has_expenses' => (bool) $invoice->has_expenses,
|
||||
'custom_text_value1' => $invoice->custom_text_value1 ?: '',
|
||||
'custom_text_value2' => $invoice->custom_text_value2 ?: '',
|
||||
'line_items' => $invoice->line_items
|
||||
];
|
||||
}
|
||||
}
|
@ -23,5 +23,6 @@ Route::group(['middleware' => ['api_secret_check']], function () {
|
||||
|
||||
Route::group(['middleware' => ['contact_db','api_secret_check','contact_token_auth'], 'prefix' =>'api/v1/contact', 'as' => 'api.contact.'], function () {
|
||||
|
||||
Route::get('invoices', 'Contact\InvoiceController@index'); // name = (clients. index / create / show / update / destroy / edit
|
||||
|
||||
});
|
Loading…
Reference in New Issue
Block a user