From 9f624b3c613fedb2ebc1d741dadf6494280c0324 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 10 Jul 2019 11:42:34 +1000 Subject: [PATCH] Mock Client InvoiceList --- .../Controllers/Contact/InvoiceController.php | 50 ++++++++++++++ .../{SetContactDb.php => ContactSetDb.php} | 2 +- app/Models/ClientContact.php | 4 +- .../ClientContactLoginTransformer.php | 51 ++++++++++++++ .../Contact/InvoiceTransformer.php | 69 +++++++++++++++++++ routes/contact.php | 1 + 6 files changed, 174 insertions(+), 3 deletions(-) create mode 100644 app/Http/Controllers/Contact/InvoiceController.php rename app/Http/Middleware/{SetContactDb.php => ContactSetDb.php} (98%) create mode 100644 app/Transformers/ClientContactLoginTransformer.php create mode 100644 app/Transformers/Contact/InvoiceTransformer.php diff --git a/app/Http/Controllers/Contact/InvoiceController.php b/app/Http/Controllers/Contact/InvoiceController.php new file mode 100644 index 000000000000..9139fe259bc1 --- /dev/null +++ b/app/Http/Controllers/Contact/InvoiceController.php @@ -0,0 +1,50 @@ +user()->client->id); + //$invoices = Invoice::filter($filters); + + return $this->listResponse($invoices); + + } +} \ No newline at end of file diff --git a/app/Http/Middleware/SetContactDb.php b/app/Http/Middleware/ContactSetDb.php similarity index 98% rename from app/Http/Middleware/SetContactDb.php rename to app/Http/Middleware/ContactSetDb.php index d95b47b7b51c..919df54712d1 100644 --- a/app/Http/Middleware/SetContactDb.php +++ b/app/Http/Middleware/ContactSetDb.php @@ -15,7 +15,7 @@ use App\Libraries\MultiDB; use App\Models\CompanyToken; use Closure; -class SetContactDb +class ContactSetDb { /** * Handle an incoming request. diff --git a/app/Models/ClientContact.php b/app/Models/ClientContact.php index e9613acd040f..45240c1e2b62 100644 --- a/app/Models/ClientContact.php +++ b/app/Models/ClientContact.php @@ -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() diff --git a/app/Transformers/ClientContactLoginTransformer.php b/app/Transformers/ClientContactLoginTransformer.php new file mode 100644 index 000000000000..f476f9ddffb4 --- /dev/null +++ b/app/Transformers/ClientContactLoginTransformer.php @@ -0,0 +1,51 @@ + $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 ?: '', + ]; + } +} diff --git a/app/Transformers/Contact/InvoiceTransformer.php b/app/Transformers/Contact/InvoiceTransformer.php new file mode 100644 index 000000000000..46231ca91d0b --- /dev/null +++ b/app/Transformers/Contact/InvoiceTransformer.php @@ -0,0 +1,69 @@ + $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 + ]; + } +} \ No newline at end of file diff --git a/routes/contact.php b/routes/contact.php index aba67e0cdc58..dd26a0442780 100644 --- a/routes/contact.php +++ b/routes/contact.php @@ -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 }); \ No newline at end of file