From 8d9b0c7027839d80c4c370c3df8ec9203e7a6b06 Mon Sep 17 00:00:00 2001 From: Deon George Date: Mon, 20 Aug 2018 22:15:28 +1000 Subject: [PATCH] Improvements to ordering --- app/Http/Controllers/OrderController.php | 65 +++++-- app/Models/Account.php | 5 + app/Models/Service.php | 2 +- app/User.php | 3 +- .../backend/adminlte/r/accounts.blade.php | 2 +- .../theme/backend/adminlte/r/agents.blade.php | 2 +- .../backend/adminlte/r/clients.blade.php | 2 +- .../theme/backend/adminlte/r/home.blade.php | 74 ++++---- .../adminlte/r/service_movements.blade.php | 2 +- .../widgets/account_summary.blade.php | 3 + .../adminlte/widgets/invoices_due.blade.php | 2 +- .../widgets/payment_history.blade.php | 2 +- .../widgets/services_active.blade.php | 2 +- .../theme/frontend/metronic/order.blade.php | 175 +++++++++++------- 14 files changed, 217 insertions(+), 124 deletions(-) diff --git a/app/Http/Controllers/OrderController.php b/app/Http/Controllers/OrderController.php index 09e899b..57bc1fc 100644 --- a/app/Http/Controllers/OrderController.php +++ b/app/Http/Controllers/OrderController.php @@ -8,7 +8,7 @@ use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Validator; use Illuminate\Database\Eloquent\Model; -use App\Models\{Product,Service}; +use App\Models\{Account,Product,Service}; use App\User; class OrderController extends Controller @@ -37,33 +37,70 @@ class OrderController extends Controller Validator::make($request->all(),[ 'product_id'=>'required|exists:ab_product,id', ]) - ->sometimes('order_email','required|email',function($input) use ($request) { - return ($input->order_email AND ! $input->order_email_manual) OR (! $input->order_email_manual); + // Reseller + ->sometimes('account_id','required|email',function($input) use ($request) { + return is_null($input->account_id) AND is_null($input->order_email_manual); }) - ->sometimes('order_email_manual','required|email',function($input) use ($request) { - return $input->order_email_manual AND ! $input->order_email; - })->validate(); + // Un-Authed User + ->sometimes('order_email_manual','required|email|unique:users,email,NULL,id',function($input) use ($request) { + return (is_null($input->order_email_manual) AND ! isset($input->account_id)) OR $input->order_email_manual; + }) + // Authed User + ->sometimes('account_id','required|email',function($input) use ($request) { + return is_null($input->account_id) AND ! isset($input->order_email_manual); + }) + ->validate(); + // Check the plugin details. - $po = Product::findOrFail($request->post('product_id')); + $po = Product::findOrFail($request->input('product_id')); // Check we have the custom attributes for the product $options = $po->orderValidation($request); - $uo = User::where('email','=',$request->post('order_email') ?: $request->post('order_email_manual'))->firstOrFail(); + $uo = User::firstOrNew(['email'=>$request->input('order_email') ?: $request->input('order_email_manual')]); - $ao = $request->input('account_id') - ? $uo->accounts->where('account_id',$request->input('account_id')) - : $uo->accounts->first(); + // If this is a new client + if (! $uo->exists) + { + // @todo Make this automatic + $uo->site_id = config('SITE_SETUP')->id; + $uo->active = FALSE; + $uo->firstname = ''; + $uo->lastname = ''; + $uo->country_id = config('SITE_SETUP')->country_id; // @todo This might be wrong + $uo->parent_id = Auth::id() ?: 1; // @todo This should be configured to a default user + $uo->active = 1; + $uo->save(); + } + + // If we have a new account. + if (is_null($request->input('account_id'))) + { + $ao = new Account; + //$ao->id = Account::NextId(); + // @todo Make this automatic + $ao->site_id = config('SITE_SETUP')->id; + $ao->country_id = config('SITE_SETUP')->country_id; // @todo This might be wrong + $ao->language_id = config('SITE_SETUP')->language_id; // @todo This might be wrong + $ao->currency_id = config('SITE_SETUP')->currency_id; // @todo This might be wrong + $ao->active = 1; + $uo->accounts()->save($ao); + + } else { + // @todo This logic may be wrong, if account_id is not set, it'll pick the first account, which may be wrong. + $ao = $request->input('account_id') + ? $uo->accounts->where('account_id',$request->input('account_id')) + : $uo->accounts->first(); + } $so = new Service; - $so->id = Service::NextId(); // @todo Make this automatic $so->site_id = config('SITE_SETUP')->id; - $so->product_id = $request->post('product_id'); + $so->product_id = $request->input('product_id'); $so->order_status = 'ORDER-SUBMIT'; - $so->orderby_id = Auth::user()->id; + $so->orderby_id = Auth::id(); if ($options->order_info) { diff --git a/app/Models/Account.php b/app/Models/Account.php index 7a6c7ea..da559a7 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -4,8 +4,13 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; +use App\Traits\NextKey; + class Account extends Model { + use NextKey; + public $incrementing = FALSE; + protected $table = 'ab_account'; public $timestamps = FALSE; diff --git a/app/Models/Service.php b/app/Models/Service.php index 60622e4..3154c1f 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -8,6 +8,7 @@ use App\Traits\NextKey; class Service extends Model { use NextKey; + public $incrementing = FALSE; protected $table = 'ab_service'; protected $with = ['product.descriptions','account.language','service_adsl','service_domain.tld','service_ssl','service_voip']; @@ -15,7 +16,6 @@ class Service extends Model protected $casts = [ 'order_info'=>'array', ]; - public $incrementing = FALSE; const CREATED_AT = 'date_orig'; const UPDATED_AT = 'date_last'; diff --git a/app/User.php b/app/User.php index 37ce9e2..d82e3fa 100644 --- a/app/User.php +++ b/app/User.php @@ -237,12 +237,11 @@ class User extends Authenticatable $o->level = $level; - $result->push($o); - // Include clients of agents $result->push($o->all_clients($level+1)); } + $result->push($this); return $result->flatten(); } diff --git a/resources/theme/backend/adminlte/r/accounts.blade.php b/resources/theme/backend/adminlte/r/accounts.blade.php index a436e79..f683dec 100644 --- a/resources/theme/backend/adminlte/r/accounts.blade.php +++ b/resources/theme/backend/adminlte/r/accounts.blade.php @@ -1,4 +1,4 @@ -
+

Accounts

diff --git a/resources/theme/backend/adminlte/r/agents.blade.php b/resources/theme/backend/adminlte/r/agents.blade.php index 1026ad5..9afde44 100644 --- a/resources/theme/backend/adminlte/r/agents.blade.php +++ b/resources/theme/backend/adminlte/r/agents.blade.php @@ -1,4 +1,4 @@ -
+

Agents

diff --git a/resources/theme/backend/adminlte/r/clients.blade.php b/resources/theme/backend/adminlte/r/clients.blade.php index 93267f8..e4cbb26 100644 --- a/resources/theme/backend/adminlte/r/clients.blade.php +++ b/resources/theme/backend/adminlte/r/clients.blade.php @@ -1,4 +1,4 @@ -
+

Clients

diff --git a/resources/theme/backend/adminlte/r/home.blade.php b/resources/theme/backend/adminlte/r/home.blade.php index 45493d3..2f4db2e 100644 --- a/resources/theme/backend/adminlte/r/home.blade.php +++ b/resources/theme/backend/adminlte/r/home.blade.php @@ -12,45 +12,51 @@ @endsection @section('main-content') -
+
@include('widgets.account_summary')
- -
-
-
-
- @include('widgets.services_active') -
-
- @include('widgets.invoices_due') -
-
- @include('widgets.payment_history') + +
+ + +
+
+
+
+ @include('widgets.services_active') +
+
+ @include('widgets.invoices_due') +
+
+ @include('widgets.payment_history') +
-
-
-
-
- @include('r.accounts') -
-
- @include('r.service_movements') -
-
- @include('r.agents') -
-
- @include('r.clients') +
+
+
+ @include('r.accounts') +
+
+ @include('r.service_movements') +
+
+ @include('r.agents') +
+ {{-- +
+ @include('r.clients') +
+ --}}
diff --git a/resources/theme/backend/adminlte/r/service_movements.blade.php b/resources/theme/backend/adminlte/r/service_movements.blade.php index 1f91af5..8e0604a 100644 --- a/resources/theme/backend/adminlte/r/service_movements.blade.php +++ b/resources/theme/backend/adminlte/r/service_movements.blade.php @@ -1,4 +1,4 @@ -
+

Service Movements

diff --git a/resources/theme/backend/adminlte/widgets/account_summary.blade.php b/resources/theme/backend/adminlte/widgets/account_summary.blade.php index d61daab..cab08e1 100644 --- a/resources/theme/backend/adminlte/widgets/account_summary.blade.php +++ b/resources/theme/backend/adminlte/widgets/account_summary.blade.php @@ -9,6 +9,7 @@
@endif +
@@ -18,6 +19,7 @@
+
@@ -27,6 +29,7 @@
+
diff --git a/resources/theme/backend/adminlte/widgets/invoices_due.blade.php b/resources/theme/backend/adminlte/widgets/invoices_due.blade.php index 54d4327..148c6d3 100644 --- a/resources/theme/backend/adminlte/widgets/invoices_due.blade.php +++ b/resources/theme/backend/adminlte/widgets/invoices_due.blade.php @@ -1,4 +1,4 @@ -
+

Invoices Due

diff --git a/resources/theme/backend/adminlte/widgets/payment_history.blade.php b/resources/theme/backend/adminlte/widgets/payment_history.blade.php index e08022f..8c1eeaf 100644 --- a/resources/theme/backend/adminlte/widgets/payment_history.blade.php +++ b/resources/theme/backend/adminlte/widgets/payment_history.blade.php @@ -1,4 +1,4 @@ -
+

Payment History

diff --git a/resources/theme/backend/adminlte/widgets/services_active.blade.php b/resources/theme/backend/adminlte/widgets/services_active.blade.php index 5661d6d..f4c6242 100644 --- a/resources/theme/backend/adminlte/widgets/services_active.blade.php +++ b/resources/theme/backend/adminlte/widgets/services_active.blade.php @@ -1,4 +1,4 @@ -
+

Services

diff --git a/resources/theme/frontend/metronic/order.blade.php b/resources/theme/frontend/metronic/order.blade.php index 69bec0a..f6d68f2 100644 --- a/resources/theme/frontend/metronic/order.blade.php +++ b/resources/theme/frontend/metronic/order.blade.php @@ -26,93 +26,50 @@ {{ csrf_field() }}
- -
-
-

Register or Sign In

-
- -
-
-
- @if (Auth::user()) - {{ Auth::user()->name }} - @else - Login - @endif -
- -
-
-
-
- -
-
- - @if ($user->isReseller()) + @if (Auth::user() AND Auth::user()->isReseller())

- Client + Account

-
-
+
+
-
+
+
+ + + {{ $errors->first('account_id') }} +
+
+ +
{{ $errors->first('order_email_manual') }}
- -
-
- - - {{ $errors->first('order_email') }} -
- - - @if (FALSE AND Auth::user()->isBusiness()) -
- - -
-
-
-
-
- @endif -
-
@@ -124,8 +81,94 @@
+ + + @elseif (Auth::user()) +
+
+

+ Account +

+
+ +
+
+
+ +
+ + +
+
+
+ + + {{ $errors->first('account_id') }} +
+
+ +
+
+ + + {{ $errors->first('account_name') }} +
+
+
+
+
+ +
+
+
+
+
+
+
+ + @else - + @php + //dd($errors); + @endphp +
+
+

+ Account +

+
+ +
+
+
+
+
+ + + {{ $errors->first('order_email_manual') }} +
+
+
+ +
+
+
+
+
+
+
@endif