Synchro back-office, fix on tariffs

This commit is contained in:
Ludovic CANDELLIER
2021-10-26 21:41:46 +02:00
parent c150be2c3e
commit 86f6ee9a13
45 changed files with 1095 additions and 406 deletions

View File

@@ -2,22 +2,68 @@
namespace App\Models\Core;
use Exception;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use App\Repositories\Core\DateTime;
use App\Traits\HasComments;
class Comment extends Model
{
protected $guarded = [];
use HasComments;
public function user()
protected $fillable = [
'comment',
'user_id',
'is_approved'
];
protected $casts = [
'is_approved' => 'boolean'
];
public function scopeApproved($query)
{
return $this->belongsTo(\App\Models\Core\Auth\User::class);
return $query->where('is_approved', true);
}
public function getUpdatedAtAttribute($value)
public function commentable()
{
return DateTime::DateToLocale($value);
}
}
return $this->morphTo();
}
public function commentator()
{
return $this->belongsTo($this->getAuthModelName(), 'user_id');
}
public function approve()
{
$this->update([
'is_approved' => true,
]);
return $this;
}
public function disapprove()
{
$this->update([
'is_approved' => false,
]);
return $this;
}
protected function getAuthModelName()
{
if (config('comments.user_model')) {
return config('comments.user_model');
}
if (!is_null(config('auth.providers.users.model'))) {
return config('auth.providers.users.model');
}
throw new Exception('Could not determine the commentator model name.');
}
}

View File

@@ -10,13 +10,14 @@ use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
use BeyondCode\Comments\Traits\HasComments;
use Rinvex\Categories\Traits\Categorizable;
use Rinvex\Tags\Traits\Taggable;
use Kirschbaum\PowerJoins\PowerJoins;
use Fico7489\Laravel\EloquentJoin\Traits\EloquentJoin;
use Wildside\Userstamps\Userstamps;
use App\Traits\HasComments;
class Article extends Model implements HasMedia
{
use Categorizable, EloquentJoin, HasComments, InteractsWithMedia, Powerjoins, Taggable, SoftDeletes, UserStamps;
@@ -44,6 +45,11 @@ class Article extends Model implements HasMedia
return $this->hasMany(InvoiceItem::class);
}
public function offers()
{
return $this->hasMany(Offer::class);
}
public function prices()
{
return $this->hasMany(Price::class);
@@ -66,6 +72,9 @@ class Article extends Model implements HasMedia
public function scopeByCategory($query, $category_id)
{
return $query->whereHas('categories', function ($query) use ($category_id) {
$query->where('id', $category_id);
});
}
public function scopeByArticleNature($query, $id)
@@ -83,6 +92,11 @@ class Article extends Model implements HasMedia
return $query->where($this->table . '.product_id', $model_id);
}
public function scopeWithOffers($query)
{
return $query->has('Offers');
}
public function registerMediaConversions(Media $media = null) : void
{
$this->addMediaConversion('thumb')->fit(Manipulations::FIT_CROP, 32, 32);

View File

@@ -35,4 +35,9 @@ class Category extends Model
return $this->belongsTo(app('rinvex.categories.category'),'category_id');
}
public function scopeByCategory($query, $category_id)
{
return $query->where('category_id', $category_id);
}
}

View File

@@ -4,7 +4,8 @@ namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
use BeyondCode\Comments\Traits\HasComments;
use App\Traits\HasComments;
class Offer extends Model
{
use HasComments;
@@ -17,6 +18,11 @@ class Offer extends Model
return $this->belongsTo(Article::class);
}
public function categories()
{
return $this->article->categories();
}
public function variation()
{
return $this->belongsTo(Variation::class);
@@ -26,4 +32,26 @@ class Offer extends Model
{
return $this->belongsTo(Tariff::class);
}
public function scopeByArticle($query, $id)
{
return $query->where('article_id', $id);
}
public function scopeByCategory($query, $category_id)
{
return $query->whereHas('article.categories', function ($query) use ($category_id) {
$query->where('category_id', $category_id);
});
}
public function scopeByStatus($query, $id)
{
return $query->where('status_id', $id);
}
public function scopeByVariation($query, $id)
{
return $query->where('variation_id', $id);
}
}

View File

@@ -4,9 +4,10 @@ namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
use BeyondCode\Comments\Traits\HasComments;
use Znck\Eloquent\Traits\BelongsToThrough;
use App\Traits\HasComments;
class PriceList extends Model
{
use BelongsToThrough, HasComments;

View File

@@ -5,9 +5,10 @@ namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
use Staudenmeir\EloquentHasManyDeep\HasRelationships;
use BeyondCode\Comments\Traits\HasComments;
use Kirschbaum\PowerJoins\PowerJoins;
use App\Traits\HasComments;
class Tariff extends Model
{
use HasComments, HasRelationships, PowerJoins;

View File

@@ -4,7 +4,7 @@ namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
use BeyondCode\Comments\Traits\HasComments;
use App\Traits\HasComments;
class Variation extends Model
{
use HasComments;