Improvements to ordering

This commit is contained in:
Deon George 2018-08-20 22:15:28 +10:00
parent e9b5f9ac0c
commit 8d9b0c7027
No known key found for this signature in database
GPG Key ID: 7670E8DC27415254
14 changed files with 217 additions and 124 deletions

View File

@ -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)
{

View File

@ -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;

View File

@ -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';

View File

@ -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();
}

View File

@ -1,4 +1,4 @@
<div class="box box-success small">
<div class="box box-success">
<div class="box-header">
<h3 class="box-title">Accounts</h3>
<div class="box-tools pull-right">

View File

@ -1,4 +1,4 @@
<div class="box box-warning small">
<div class="box box-warning">
<div class="box-header">
<h3 class="box-title">Agents</h3>
<div class="box-tools pull-right">

View File

@ -1,4 +1,4 @@
<div class="box box-warning small">
<div class="box box-warning">
<div class="box-header">
<h3 class="box-title">Clients</h3>
<div class="box-tools pull-right">

View File

@ -12,45 +12,51 @@
@endsection
@section('main-content')
<div class="row">
<div class="row col-md-12">
@include('widgets.account_summary')
</div>
<ul class="nav nav-tabs">
<li class="active">
<a href="#personal-tab" data-toggle="tab">Personal</a>
</li>
<li>
<a href="#clients-tab" data-toggle="tab">Clients</a>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="personal-tab">
<div class="row">
<div class="col-xs-7">
@include('widgets.services_active')
</div>
<div class="col-xs-5">
@include('widgets.invoices_due')
</div>
<div class="col-xs-5">
@include('widgets.payment_history')
<div class="col-md-12">
<ul class="nav nav-tabs">
<li class="active">
<a href="#services-tab" data-toggle="tab">Services</a>
</li>
<li>
<a href="#clients-tab" data-toggle="tab">Clients</a>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="services-tab">
<div class="row">
<div class="col-xs-7">
@include('widgets.services_active')
</div>
<div class="col-xs-5">
@include('widgets.invoices_due')
</div>
<div class="col-xs-5">
@include('widgets.payment_history')
</div>
</div>
</div>
</div>
<div class="tab-pane" id="clients-tab">
<div class="row">
<div class="col-xs-6">
@include('r.accounts')
</div>
<div class="col-xs-6">
@include('r.service_movements')
</div>
<div class="col-xs-6">
@include('r.agents')
</div>
<div class="col-xs-6">
@include('r.clients')
<div class="tab-pane" id="clients-tab">
<div class="row">
<div class="col-xs-6">
@include('r.accounts')
</div>
<div class="col-xs-6">
@include('r.service_movements')
</div>
<div class="col-xs-6">
@include('r.agents')
</div>
{{--
<div class="col-xs-6">
@include('r.clients')
</div>
--}}
</div>
</div>
</div>

View File

@ -1,4 +1,4 @@
<div class="box box-warning small">
<div class="box box-warning">
<div class="box-header">
<h3 class="box-title">Service Movements</h3>
<div class="box-tools pull-right">

View File

@ -9,6 +9,7 @@
</div>
</div>
@endif
<div class="col-sm-3">
<div class="info-box">
<span class="info-box-icon bg-red"><i class="fa fa-dollar"></i></span>
@ -18,6 +19,7 @@
</div>
</div>
</div>
<div class="col-sm-3">
<div class="info-box">
<span class="info-box-icon bg-green"><i class="fa fa-clone"></i></span>
@ -27,6 +29,7 @@
</div>
</div>
</div>
<div class="col-sm-3">
<div class="info-box">
<span class="info-box-icon bg-blue"><i class="fa fa-hashtag"></i></span>

View File

@ -1,4 +1,4 @@
<div class="box box-info small">
<div class="box box-info">
<div class="box-header">
<h3 class="box-title">Invoices Due</h3>
<div class="box-tools pull-right">

View File

@ -1,4 +1,4 @@
<div class="box box-notice small">
<div class="box box-notice">
<div class="box-header">
<h3 class="box-title">Payment History</h3>
<div class="box-tools pull-right">

View File

@ -1,4 +1,4 @@
<div class="box box-success small">
<div class="box box-success">
<div class="box-header">
<h3 class="box-title">Services</h3>
<div class="box-tools pull-right">

View File

@ -26,93 +26,50 @@
{{ csrf_field() }}
<div id="accordion">
<!-- User -->
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">Register or Sign In</h4>
</div>
<div class="panel-collapse">
<div class="panel-body">
<div class="col-md-12">
@if (Auth::user())
{{ Auth::user()->name }}
@else
<a href="{{ url('login') }}">Login</a>
@endif
</div>
<div class="row">
<div class="col-sm-2"><button class="btn btn-block btn-primary next">Next</button></div>
</div>
</div>
</div>
</div>
<!-- Reseller Choose Client -->
@if ($user->isReseller())
@if (Auth::user() AND Auth::user()->isReseller())
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
Client
Account
</h4>
</div>
<div class="panel-collapse">
<div class="panel-body">
<div class="col-md-12">
<div class="col-md-6">
<div class="col-md-12 margin-bottom-20">
<div class="col-md-6">
<ul class="nav nav-tabs">
<li>
<a href="#tab_1" data-toggle="tab">New Client</a>
</li>
<li class="active">
<a href="#tab_2" data-toggle="tab">Existing Client</a>
<a href="#account_exist" data-toggle="tab">Existing Account</a>
</li>
<li>
<a href="#client_new" data-toggle="tab">New Client</a>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane row fade" id="tab_1">
<div class="tab-pane row fade in active" id="account_exist">
<div class="control-group form-group col-sm-12 {{ $errors->has('account_id') ? 'has-error' : '' }}">
<label for="order_email">Client Account</label>
<select class="form-control" id="account_id" name="account_id">
<option value="">&nbsp;</option>
@foreach ($user->all_accounts()->sortBy('company') as $o)
<option value="{{ $o->id }}" @if($o->id == old('account_id')) selected @endif>{{ $o->company }}</option>
@endforeach
</select>
<span class="help-block">{{ $errors->first('account_id') }}</span>
</div>
</div>
<div class="tab-pane row fade" id="client_new">
<div class="control-group form-group col-sm-12 {{ $errors->has('order_email_manual') ? 'has-error' : '' }}">
<label for="order_email_manual">New Client Email</label>
<input type="email" class="form-control" id="order_email_manual" name="order_email_manual" placeholder="New Client Email" value="{{ old('order_email_manual') }}">
<span class="help-block">{{ $errors->first('order_email_manual') }}</span>
</div>
</div>
<div class="tab-pane row fade in active" id="tab_2">
<div class="control-group form-group col-sm-12 {{ $errors->has('order_email') ? 'has-error' : '' }}">
<label for="order_email">Client Account</label>
<select class="form-control" id="order_email" name="order_email">
<option value="">&nbsp;</option>
@foreach ($user->all_accounts()->sortBy('company') as $o)
<option value="{{ $o->user->email }}" @if($o->user->email == old('order_email')) selected @endif>{{ $o->company }}</option>
@endforeach
</select>
<span class="help-block">{{ $errors->first('order_email') }}</span>
</div>
<!-- Account -->
@if (FALSE AND Auth::user()->isBusiness())
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a href="#accordion1_2" data-parent="#accordion1" class="accordion-toggle">
Account
</a>
</h4>
</div>
<div class="panel-collapse collapse" id="accordion1_2">
<div class="panel-body">
</div>
</div>
</div>
@endif
</div>
</div>
</div>
</div>
@ -124,8 +81,94 @@
</div>
</div>
</div>
<!-- Non-Authed User -->
@elseif (Auth::user())
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
Account
</h4>
</div>
<div class="panel-collapse">
<div class="panel-body">
<div class="col-md-12 margin-bottom-20">
<div class="col-md-6">
<ul class="nav nav-tabs">
<li class="active">
<a href="#account_exist" data-toggle="tab">Existing Account</a>
</li>
<li>
<a href="#account_new" data-toggle="tab">New Account</a>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane row fade in active" id="account_exist">
<div class="control-group form-group col-sm-12 {{ $errors->has('account_id') ? 'has-error' : '' }}">
<label for="order_email">Existing Account</label>
<select class="form-control" id="account_id" name="account_id">
<option value="">&nbsp;</option>
@foreach ($user->accounts->sortBy('company') as $o)
<option value="{{ $o->id }}" @if($o->id == old('account_id')) selected @endif>{{ $o->company }}</option>
@endforeach
</select>
<span class="help-block">{{ $errors->first('account_id') }}</span>
</div>
</div>
<div class="tab-pane row fade" id="account_new">
<div class="control-group form-group col-sm-12 {{ $errors->has('account_name') ? 'has-error' : '' }}">
<label for="account_name">Account Name</label>
<input type="text" class="form-control" id="account_name" name="account_name" placeholder="New Account Name" value="{{ old('order_email_manual') }}" disabled>
<span class="help-block">{{ $errors->first('account_name') }}</span>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-2"><button class="btn btn-block btn-primary">Previous</button></div>
<div class="col-sm-2"><button class="btn btn-block btn-primary next">Next</button></div>
</div>
</div>
</div>
</div>
<!-- Non-Authed User -->
@else
<input type="hidden" name="order_email" value="{{ $user->email }}">
@php
//dd($errors);
@endphp
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
Account
</h4>
</div>
<div class="panel-collapse">
<div class="panel-body">
<div class="col-md-12">
<div class="row col-md-6">
<div class="control-group form-group col-sm-12 {{ $errors->has('order_email_manual') ? 'has-error' : '' }}">
<label for="order_email_manual">Email Address</label>
<input type="email" class="form-control" id="order_email_manual" name="order_email_manual" placeholder="Email Address" value="{{ old('order_email_manual') }}">
<span class="help-block">{{ $errors->first('order_email_manual') }}</span>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-2"><button class="btn btn-block btn-primary">Previous</button></div>
<div class="col-sm-2"><button class="btn btn-block btn-primary next">Next</button></div>
</div>
</div>
</div>
</div>
@endif
<!-- Product -->