diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index 5889c64..eba2293 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -5,7 +5,7 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Arr; -use App\Models\{Service,SiteDetails}; +use App\Models\{Service,SiteDetail}; class AdminController extends Controller { @@ -39,9 +39,10 @@ class AdminController extends Controller 'social' => 'nullable|array', 'top_menu' => 'nullable|array', 'site_logo' => 'nullable|image', + 'email_logo' => 'nullable|image', ]); - $so = config('SITE_SETUP'); + $site = config('SITE'); // @todo - not currently rendered in the home page $validated['social'] = []; @@ -50,9 +51,9 @@ class AdminController extends Controller // Handle the images foreach(['site_logo','email_logo'] as $key) if (array_key_exists($key,$validated)) - $validated[$key] = ($x=$validated[$key])->storeAs('site/'.config('SITE_SETUP')->site_id,$x->getClientOriginalName(),'public'); + $validated[$key] = ($x=$validated[$key])->storeAs('site/'.$site->site_id,$x->getClientOriginalName(),'public'); - foreach ($so->details as $oo) + foreach ($site->details as $oo) if (array_key_exists($oo->key,$validated)) { $oo->value = Arr::get($validated,$oo->key); $oo->save(); @@ -62,11 +63,11 @@ class AdminController extends Controller // Left over values to be created. foreach ($validated as $k=>$v) { - $oo = new SiteDetails; + $oo = new SiteDetail; $oo->key = $k; $oo->value = $v ?: ''; - $so->details()->save($oo); + $site->details()->save($oo); } return redirect()->back() diff --git a/app/Http/Controllers/MediaController.php b/app/Http/Controllers/MediaController.php index 6ce3810..86227af 100644 --- a/app/Http/Controllers/MediaController.php +++ b/app/Http/Controllers/MediaController.php @@ -2,7 +2,6 @@ namespace App\Http\Controllers; -use App\Http\Requests; use Image; class MediaController extends Controller @@ -10,8 +9,9 @@ class MediaController extends Controller /** * Create a generic image * - * @param $width - * @param $height + * @param $width + * @param $height + * @param string $color * @return mixed */ public function image($width,$height,$color='#ccc') { diff --git a/app/Http/Controllers/OrderController.php b/app/Http/Controllers/OrderController.php index 411a957..eb1503f 100644 --- a/app/Http/Controllers/OrderController.php +++ b/app/Http/Controllers/OrderController.php @@ -71,11 +71,11 @@ class OrderController extends Controller if (! $uo->exists) { // @todo Make this automatic - $uo->site_id = config('SITE_SETUP')->id; + $uo->site_id = config('SITE')->id; $uo->active = FALSE; $uo->firstname = ''; $uo->lastname = ''; - $uo->country_id = config('SITE_SETUP')->country_id; // @todo This might be wrong + $uo->country_id = config('SITE')->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(); @@ -88,10 +88,10 @@ class OrderController extends Controller $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->site_id = config('SITE')->id; + $ao->country_id = config('SITE')->country_id; // @todo This might be wrong + $ao->language_id = config('SITE')->language_id; // @todo This might be wrong + $ao->currency_id = config('SITE')->currency_id; // @todo This might be wrong $ao->active = 1; $uo->accounts()->save($ao); @@ -102,7 +102,7 @@ class OrderController extends Controller $so = new Service; // @todo Make this automatic - $so->site_id = config('SITE_SETUP')->id; + $so->site_id = config('SITE')->id; $so->product_id = $request->input('product_id'); $so->order_status = 'ORDER-SUBMIT'; $so->orderby_id = Auth::id(); diff --git a/app/Http/Middleware/SetSite.php b/app/Http/Middleware/SetSite.php index a041138..24cbbdd 100644 --- a/app/Http/Middleware/SetSite.php +++ b/app/Http/Middleware/SetSite.php @@ -43,9 +43,9 @@ class SetSite } // Set who we are in SETUP. - Config::set('SITE_SETUP',$so); + Config::set('SITE',$so); if (! $request->ajax()) - View::share('so',$so); + View::share('site',$so); return $next($request); } diff --git a/app/Models/Account.php b/app/Models/Account.php index 5c15a4a..2b14c8e 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -149,6 +149,20 @@ class Account extends Model implements IDs return $this->getUrlAdminAttribute(); } + /** + * Get the address for the account + * + * @return array + */ + public function getAddressAttribute(): array + { + return [ + $this->address1, + $this->address2, + sprintf('%s %s %s',$this->city.(($this->state OR $this->zip) ? ',' : ''),$this->state,$this->zip) + ]; + } + /** * Return the Account Unique Identifier * @return string @@ -219,36 +233,7 @@ class Account extends Model implements IDs return sprintf('%s',$this->id,$this->account_id); } - /** FUNCTIONS **/ - - private function _address() - { - $return = []; - - if ($this->address1) - array_push($return,$this->address1); - if ($this->address2) - array_push($return,$this->address2); - if ($this->city) - array_push($return,sprintf('%s %s %s',$this->city.(($this->state OR $this->zip) ? ',' : ''),$this->state,$this->zip)); - - if (! $return) - $return = ['No Address']; - - return $return; - } - - public function address($type='plain') - { - switch ($type) - { - case 'html' : return join('
',$this->_address()); - case 'newline': return join("\m",$this->_address()); - - default: - return join("\n",$this->_address()); - } - } + /* GENERAL METHODS */ /** * Get the due invoices on an account diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index be69de2..89811ae 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -139,7 +139,7 @@ class Invoice extends Model implements IDs // @todo Move this to a site configuration public function getInvoiceTextAttribute() { - return sprintf('Thank you for using %s for your Internet Services.',config('SITE_SETUP')->site_name); + return sprintf('Thank you for using %s for your Internet Services.',config('SITE')->site_name); } /** diff --git a/app/Models/Product.php b/app/Models/Product.php index 7f49900..c98e326 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -100,7 +100,7 @@ class Product extends Model implements IDs private function getDefaultLanguage() { - return config('SITE_SETUP')->language; + return config('SITE')->language; } public function getDescriptionAttribute() diff --git a/app/Models/Site.php b/app/Models/Site.php index 0b586d2..fc75766 100644 --- a/app/Models/Site.php +++ b/app/Models/Site.php @@ -31,7 +31,7 @@ class Site extends Model public function details() { - return $this->hasMany(SiteDetails::class,NULL,'site_id'); + return $this->hasMany(SiteDetail::class,NULL,'site_id'); } public function language() @@ -60,7 +60,7 @@ class Site extends Model return $x; if (is_null($details)) - $details = new SiteDetails; + $details = new SiteDetail; // Get a default value for this key $value = $details->sample($key); @@ -88,6 +88,15 @@ class Site extends Model return NULL; } + public function getAddressAttribute(): array + { + return [ + $this->site_address1, + $this->site_address2, + sprintf('%s %s %s',$this->site_city.(($this->site_state OR $this->site_postcode) ? ',' : ''),$this->site_state,$this->site_postcode) + ]; + } + /** * Add the path to the mail logo, so it can be displayed. * @@ -108,35 +117,4 @@ class Site extends Model { return (($x=$this->detail_item('site_logo')) !== NULL) ? '/storage/'.$x : '/image/generic/150/20/fff'; } - - // @todo - To optimize - private function _address() - { - $return = []; - - if ($this->site_address1) - array_push($return,$this->site_address1); - if ($this->site_address2) - array_push($return,$this->site_address2); - if ($this->site_city) - array_push($return,sprintf('%s %s %s',$this->site_city.(($this->site_state OR $this->site_postcode) ? ',' : ''),$this->site_state,$this->site_postcode)); - - if (! $return) - $return = ['No Address']; - - return $return; - } - - // @todo - To optimize - public function address($type='plain') - { - switch ($type) - { - case 'html' : return join('
',$this->_address()); - case 'newline': return join("\m",$this->_address()); - - default: - return join("\n",$this->_address()); - } - } } \ No newline at end of file diff --git a/app/Models/SiteDetails.php b/app/Models/SiteDetail.php similarity index 98% rename from app/Models/SiteDetails.php rename to app/Models/SiteDetail.php index a553979..2582882 100644 --- a/app/Models/SiteDetails.php +++ b/app/Models/SiteDetail.php @@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Collection; use Leenooks\Traits\CompositeKeys; -class SiteDetails extends Model +class SiteDetail extends Model { use CompositeKeys; @@ -189,6 +189,7 @@ class SiteDetails extends Model ['title'=>'Title 3','text'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.','icon'=>'fa fa-check red','image'=>'/image/generic/200/100/999'], ], */ + 'email_logo'=>route('image',['width'=>150,'height'=>20,'color'=>'eee']), 'site_address1' => 'Address line 1', 'site_address2' => 'Address line 2', 'site_description'=>'Example Site', diff --git a/app/Traits/NextKey.php b/app/Traits/NextKey.php index 2f149d2..ea4a385 100644 --- a/app/Traits/NextKey.php +++ b/app/Traits/NextKey.php @@ -23,7 +23,7 @@ trait NextKey $model->id = self::NextId(); if (! $model->site_id) - $model->site_id = config('SITE_SETUP')->id; + $model->site_id = config('SITE')->id; }); static::saved(function($model) @@ -40,14 +40,14 @@ trait NextKey $mo = new Module; $mo->name = $model::RECORD_ID; - $mo->site_id = $model->site_id ?: config('SITE_SETUP')->id; + $mo->site_id = $model->site_id ?: config('SITE')->id; $mo->save(); } if (! $mo->record) { $mo->record = new Record; $mo->record->module_id = $mo->id; - $mo->record->site_id = $model->site_id ?: config('SITE_SETUP')->id; + $mo->record->site_id = $model->site_id ?: config('SITE')->id; } $mo->record->id = $model->id; diff --git a/app/Traits/OrderServiceOptions.php b/app/Traits/OrderServiceOptions.php index 08c08a3..e7b4148 100644 --- a/app/Traits/OrderServiceOptions.php +++ b/app/Traits/OrderServiceOptions.php @@ -43,7 +43,7 @@ trait OrderServiceOptions $o->forceFill(array_undot($x)); // @todo Make this automatic - $o->site_id = config('SITE_SETUP')->id; + $o->site_id = config('SITE')->id; return $o; } diff --git a/composer.lock b/composer.lock index b6b34b3..5f2a983 100644 --- a/composer.lock +++ b/composer.lock @@ -2884,11 +2884,11 @@ }, { "name": "leenooks/laravel", - "version": "9.0.5", + "version": "9.0.7", "source": { "type": "git", "url": "https://dev.leenooks.net/leenooks/laravel", - "reference": "45be8553a29f1887273b10a56982f55134bfd9e0" + "reference": "1f114667aad9c023716516e19a292fbc0748f9a8" }, "require": { "creativeorange/gravatar": "^1.0", @@ -2925,7 +2925,7 @@ "laravel", "leenooks" ], - "time": "2021-07-01T01:58:50+00:00" + "time": "2021-07-01T23:09:31+00:00" }, { "name": "monolog/monolog", diff --git a/resources/views/theme/backend/adminlte/a/setup.blade.php b/resources/views/theme/backend/adminlte/a/setup.blade.php index 1bbbd6c..27f170a 100644 --- a/resources/views/theme/backend/adminlte/a/setup.blade.php +++ b/resources/views/theme/backend/adminlte/a/setup.blade.php @@ -8,7 +8,7 @@ @endsection @section('contentheader_title') - {{ $so->site_name }} + {{ $site->site_name }} @endsection @section('contentheader_description') Setup @@ -36,7 +36,7 @@
- + @error('site_name') {{ $message }} @@ -53,7 +53,7 @@
- + @error('site_logo') {{ $message }} @@ -62,6 +62,20 @@
+ +
+
+
+ + + + @error('email_logo') + {{ $message }} + @enderror + +
+
+
@@ -69,8 +83,8 @@
- - + + @error('site_address1') {{ $message }} @@ -86,7 +100,7 @@
- + @error('site_city') {{ $message }} @@ -102,7 +116,7 @@
- + @error('site_state') {{ $message }} @@ -114,7 +128,7 @@
- + @error('site_postcode') {{ $message }} @@ -130,7 +144,7 @@
- + @error('site_phone') {{ $message }} @@ -140,7 +154,7 @@
- + @error('site_fax') {{ $message }} @@ -150,7 +164,7 @@
- + @error('site_email') {{ $message }} @@ -163,7 +177,7 @@
ABN - + @error('site_tax') {{ $message }} @@ -177,7 +191,7 @@
- + Brief description of site. @error('site_description') @@ -192,7 +206,7 @@
Cancel @can('wholesaler') - + @endcan
diff --git a/resources/views/theme/backend/adminlte/u/invoice/home.blade.php b/resources/views/theme/backend/adminlte/u/invoice/home.blade.php index 7d42f54..5f4d7c8 100644 --- a/resources/views/theme/backend/adminlte/u/invoice/home.blade.php +++ b/resources/views/theme/backend/adminlte/u/invoice/home.blade.php @@ -20,7 +20,7 @@

- +

@@ -35,11 +35,11 @@
FROM:
- {{ $so->site_name }}
- {!! $so->address('html') !!}
+ {{ $site->site_name }}
+ {!! join('
',$site->address) !!}
- Email: {{ $so->site_email }}
- Phone: {{ $so->site_phone }} + Email: {{ $site->site_email }}
+ Phone: {{ $site->site_phone }}
@@ -47,7 +47,7 @@ TO:
{{ $o->account->company }}
- {!! $o->account->address('html') !!}
+ {!! join('
',$o->account->address) !!}
Email: {{ $o->account->email }}
@if ($o->account->phone) diff --git a/resources/views/theme/frontend/metronic/welcome/widgets/clients.blade.php b/resources/views/theme/frontend/metronic/welcome/widgets/clients.blade.php index c6cb63b..93d658b 100644 --- a/resources/views/theme/frontend/metronic/welcome/widgets/clients.blade.php +++ b/resources/views/theme/frontend/metronic/welcome/widgets/clients.blade.php @@ -4,14 +4,14 @@

Our Clients

-

{{ $so->clients_intro }}

+

{{ $site->clients_intro }}

{{-- @todo make sure this scrolls --}}