diff --git a/app/Http/Controllers/OrderController.php b/app/Http/Controllers/OrderController.php
new file mode 100644
index 0000000..7ff8946
--- /dev/null
+++ b/app/Http/Controllers/OrderController.php
@@ -0,0 +1,34 @@
+$o]);
+ }
+
+ public function product_info(Product $o)
+ {
+ Theme::set('metronic-fe');
+
+ return view('widgets.product_description',['o'=>$o]);
+ }
+
+ public function submit(Request $request)
+ {
+ }
+}
\ No newline at end of file
diff --git a/app/Models/Product.php b/app/Models/Product.php
index 595a809..7fa68fc 100644
--- a/app/Models/Product.php
+++ b/app/Models/Product.php
@@ -3,6 +3,7 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
+use Illuminate\Support\Facades\Auth;
class Product extends Model
{
@@ -19,19 +20,56 @@ class Product extends Model
return $this->hasMany(Service::class);
}
+ public function getCategoryAttribute()
+ {
+ return $this->prod_plugin_file;
+ }
+
+ public function getDescriptionAttribute()
+ {
+ // @todo If the user has selected a specific language.
+ return $this->description($this->getDefaultLanguage());
+ }
+
+ public function getNameAttribute()
+ {
+ return $this->name(Auth::user()->language);
+ }
+
public function getProductIdAttribute()
{
return sprintf('#%04s',$this->id);
}
+ public function scopeActive()
+ {
+ return $this->where('active',TRUE);
+ }
+
+ public function description(Language $lo=NULL)
+ {
+ if (is_null($lo))
+ $lo = $this->getDefaultLanguage();
+
+ return $this->descriptions->where('language_id',$lo->id)->first()->description_short;
+ }
+
+ private function getDefaultLanguage()
+ {
+ return config('SITE_SETUP')->language;
+ }
+
/**
- * Get the language name
+ * Get the product name
*
* @param Language $lo
* @return string Product Name
*/
- public function name(Language $lo)
+ public function name(Language $lo=NULL)
{
+ if (is_null($lo))
+ $lo = $this->getDefaultLanguage();
+
return $this->descriptions->where('language_id',$lo->id)->first()->name;
}
}
\ No newline at end of file
diff --git a/app/Models/Service.php b/app/Models/Service.php
index 080dd09..aa32ce3 100644
--- a/app/Models/Service.php
+++ b/app/Models/Service.php
@@ -77,7 +77,7 @@ class Service extends Model
public function getCategoryAttribute()
{
- return $this->product->prod_plugin_file;
+ return $this->product->category;
}
public function getNameAttribute()
diff --git a/app/User.php b/app/User.php
index 44397df..3fe88b4 100644
--- a/app/User.php
+++ b/app/User.php
@@ -95,6 +95,8 @@ class User extends Authenticatable
return $this->hasMany(static::class,'parent_id','id');
}
+ /** Attributes **/
+
public function getActiveDisplayAttribute($value)
{
return sprintf('%s',$this->active ? 'primary' : 'danger',$this->active ? 'Active' : 'Inactive');
@@ -110,24 +112,6 @@ class User extends Authenticatable
return sprintf('%s %s',$this->firstname,$this->lastname);
}
- public function getSurFirstNameAttribute()
- {
- return sprintf('%s, %s',$this->lastname,$this->firstname);
- }
-
- /**
- * Return a Carbon Date if it has a value.
- *
- * @param $value
- * @return \Leenooks\Carbon
- * @todo This attribute is not in the schema
- */
- public function getLastAccessAttribute($value)
- {
- if (! is_null($value))
- return new Carbon($value);
- }
-
public function getInvoicesDueAttribute()
{
return $this->invoices
@@ -144,6 +128,28 @@ class User extends Authenticatable
return config('SITE_SETUP')->language;
}
+ /**
+ * Return a Carbon Date if it has a value.
+ *
+ * @param $value
+ * @return \Leenooks\Carbon
+ * @todo This attribute is not in the schema
+ */
+ public function getLastAccessAttribute($value)
+ {
+ if (! is_null($value))
+ return new Carbon($value);
+ }
+
+ /**
+ * @deprecated Use static::getFullNameAttribute()
+ * @return mixed
+ */
+ public function getNameAttribute()
+ {
+ return $this->full_name;
+ }
+
public function getPaymentHistoryAttribute()
{
return $this->payments
@@ -157,20 +163,16 @@ class User extends Authenticatable
->where('active',TRUE);
}
- /**
- * @deprecated Use static::getFullNameAttribute()
- * @return mixed
- */
- public function getNameAttribute()
- {
- return $this->full_name;
- }
-
public function getServicesCountHtmlAttribute()
{
return sprintf('%s /%s',$this->services->where('active',TRUE)->count(),$this->services->count());
}
+ public function getSurFirstNameAttribute()
+ {
+ return sprintf('%s, %s',$this->lastname,$this->firstname);
+ }
+
public function getSwitchUrlAttribute()
{
return sprintf('',$this->id);
@@ -186,41 +188,14 @@ class User extends Authenticatable
return sprintf('%s',$this->id,$this->user_id);
}
+ /** Scopes **/
+
public function scopeActive()
{
return $this->where('active',TRUE);
}
- public function isAdmin($id)
- {
- return $id AND in_array($this->role(),['wholesaler','reseller']) AND in_array($id,$this->all_accounts()->pluck('id')->toArray());
- }
-
- public function sendPasswordResetNotification($token)
- {
- $this->notify(new ResetPasswordNotification($token));
- }
-
- // List all the agents, including agents of agents
- public function all_agents($level=0)
- {
- $result = collect();
-
- foreach ($this->agents as $o)
- {
- if (! $o->active OR ! $o->agents->count())
- continue;
-
- $o->level = $level;
-
- $result->push($o);
-
- // Include agents of agents
- $result->push($o->all_agents($level+1));
- }
-
- return $result->flatten();
- }
+ /** Functions */
public function all_accounts()
{
@@ -253,6 +228,49 @@ class User extends Authenticatable
return $result->flatten();
}
+
+ // List all the agents, including agents of agents
+ public function all_agents($level=0)
+ {
+ $result = collect();
+
+ foreach ($this->agents as $o)
+ {
+ if (! $o->active OR ! $o->agents->count())
+ continue;
+
+ $o->level = $level;
+
+ $result->push($o);
+
+ // Include agents of agents
+ $result->push($o->all_agents($level+1));
+ }
+
+ return $result->flatten();
+ }
+
+ /**
+ * Determine if the user is an admin of the account with $id
+ *
+ * @param $id
+ * @return bool
+ */
+ public function isAdmin($id)
+ {
+ return $id AND $this->isReseller() AND in_array($id,$this->all_accounts()->pluck('id')->toArray());
+ }
+
+ /**
+ * Determine if the logged in user is a reseller or wholesaler
+ *
+ * @return bool
+ */
+ public function isReseller()
+ {
+ return in_array($this->role(),['wholesaler','reseller']);
+ }
+
public function role()
{
// If I have agents and no parent, I am the wholesaler
@@ -267,4 +285,8 @@ class User extends Authenticatable
elseif (! $this->all_agents()->count() AND ! $this->all_clients()->count())
return 'customer';
}
+ public function sendPasswordResetNotification($token)
+ {
+ $this->notify(new ResetPasswordNotification($token));
+ }
}
\ No newline at end of file
diff --git a/resources/theme/frontend/metronic/layouts/app.blade.php b/resources/theme/frontend/metronic/layouts/app.blade.php
index 16d80f0..f45418b 100644
--- a/resources/theme/frontend/metronic/layouts/app.blade.php
+++ b/resources/theme/frontend/metronic/layouts/app.blade.php
@@ -23,7 +23,15 @@
- @yield('main-content')
+