change construction of articles/offers
This commit is contained in:
@@ -42,8 +42,8 @@ class TariffsDataTable extends DataTable
|
|||||||
Column::make('sale_channels2')->title('Canaux de vente')->searchable(false)->orderable(false),
|
Column::make('sale_channels2')->title('Canaux de vente')->searchable(false)->orderable(false),
|
||||||
Column::make('code')->title('Code'),
|
Column::make('code')->title('Code'),
|
||||||
Column::make('ref')->title('Référence'),
|
Column::make('ref')->title('Référence'),
|
||||||
Column::make('price_lists_count')->title('#Lst prix')->searchable(false)->orderable(false),
|
Column::make('price_lists_count')->title('#Lst prix')->searchable(false)->orderable(false)->class('text-right'),
|
||||||
Column::make('offers_count')->title('#Offres')->searchable(false)->orderable(false),
|
Column::make('offers_count')->title('#Offres')->searchable(false)->orderable(false)->class('text-right'),
|
||||||
$this->makeColumnButtons(),
|
$this->makeColumnButtons(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,12 +38,15 @@ class Article extends Model implements HasMedia
|
|||||||
return $this->hasMany(Offer::class);
|
return $this->hasMany(Offer::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
public function prices()
|
public function prices()
|
||||||
{
|
{
|
||||||
return $this->hasManyDeep(PriceListValue::class, [Offer::class, Tariff::class, PriceList::class]);
|
return $this->hasManyDeep(
|
||||||
|
PriceListValue::class,
|
||||||
|
[Offer::class, Tariff::class, PriceList::class],
|
||||||
|
['article_id', 'id', 'tariff_id'],
|
||||||
|
['id', 'tariff_id', 'id'],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
public function product()
|
public function product()
|
||||||
{
|
{
|
||||||
@@ -120,7 +123,7 @@ class Article extends Model implements HasMedia
|
|||||||
public function scopeWithAvailableOffers($query)
|
public function scopeWithAvailableOffers($query)
|
||||||
{
|
{
|
||||||
return $query->whereHas('offers', function ($query) {
|
return $query->whereHas('offers', function ($query) {
|
||||||
$query->byStatus(1);
|
$query->active();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ class Offer extends Model
|
|||||||
|
|
||||||
public function scopeActive($query)
|
public function scopeActive($query)
|
||||||
{
|
{
|
||||||
return $query->where($this->table . '.status_id', 1);
|
return $query->byStatus(1)->byTariffActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function scopeByArticle($query, $id)
|
public function scopeByArticle($query, $id)
|
||||||
@@ -77,6 +77,11 @@ class Offer extends Model
|
|||||||
return $query->whereIn($this->table . '.article_id', $ids);
|
return $query->whereIn($this->table . '.article_id', $ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function scopeByID($query, $id)
|
||||||
|
{
|
||||||
|
return $query->where($this->table . '.id', $id);
|
||||||
|
}
|
||||||
|
|
||||||
public function scopeByOffer($query, $id)
|
public function scopeByOffer($query, $id)
|
||||||
{
|
{
|
||||||
return $query->where($this->table . '.id', $id);
|
return $query->where($this->table . '.id', $id);
|
||||||
@@ -126,4 +131,11 @@ class Offer extends Model
|
|||||||
$query->whereIn('tag_id', $tags);
|
$query->whereIn('tag_id', $tags);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function scopeByTariffActive($query)
|
||||||
|
{
|
||||||
|
return $query->whereHas('tariff', function ($query) {
|
||||||
|
$query->active();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,10 +50,15 @@ class PriceList extends Model
|
|||||||
return $query->where($this->table . '.status_id', $id);
|
return $query->where($this->table . '.status_id', $id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function scopeActive($query)
|
||||||
|
{
|
||||||
|
return $query->byStatus(0)->has('price_list_values');
|
||||||
|
}
|
||||||
|
|
||||||
public function scopeByOffer($query, $id)
|
public function scopeByOffer($query, $id)
|
||||||
{
|
{
|
||||||
return $query->whereHas('offers', function ($query) use ($id) {
|
return $query->whereHas('offers', function ($query) use ($id) {
|
||||||
$query->byOffer($id);
|
$query->byID($id);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,19 @@ class Tariff extends Model
|
|||||||
public function scopeByOffer($query, $id)
|
public function scopeByOffer($query, $id)
|
||||||
{
|
{
|
||||||
return $query->whereHas('offers', function ($query) use ($id) {
|
return $query->whereHas('offers', function ($query) use ($id) {
|
||||||
$query->where('id', $id);
|
$query->byID($id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function scopeActive($query)
|
||||||
|
{
|
||||||
|
return $query->byStatus(0)->byPriceListsActive();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function scopeByPriceListsActive($query)
|
||||||
|
{
|
||||||
|
return $query->whereHas('price_lists', function ($query) {
|
||||||
|
$query->active();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,6 +111,7 @@ class Articles
|
|||||||
$price_lists = $article->offers[0]->tariff->price_lists->toArray();
|
$price_lists = $article->offers[0]->tariff->price_lists->toArray();
|
||||||
// dump($price_lists);
|
// dump($price_lists);
|
||||||
if (count($price_lists)) {
|
if (count($price_lists)) {
|
||||||
|
if (!is_array($data[$article->name] ?? false)) {
|
||||||
$data[$article->name] = [
|
$data[$article->name] = [
|
||||||
'description' => (!empty($article->description)) ? $article->description : $article->product->description,
|
'description' => (!empty($article->description)) ? $article->description : $article->product->description,
|
||||||
'image' => $article->image,
|
'image' => $article->image,
|
||||||
@@ -119,6 +120,7 @@ class Articles
|
|||||||
'product_name' => $article->product->name,
|
'product_name' => $article->product->name,
|
||||||
'parent_name' => trim(str_replace($article->product->name, '', $article->name)),
|
'parent_name' => trim(str_replace($article->product->name, '', $article->name)),
|
||||||
];
|
];
|
||||||
|
}
|
||||||
$prices = $price_lists[0]['price_list_values'][0];
|
$prices = $price_lists[0]['price_list_values'][0];
|
||||||
$article_nature_name = strtolower($article->article_nature->name);
|
$article_nature_name = strtolower($article->article_nature->name);
|
||||||
// dump($prices);
|
// dump($prices);
|
||||||
@@ -131,8 +133,6 @@ class Articles
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// dump($data);
|
|
||||||
// exit;
|
|
||||||
return $data ?? false;
|
return $data ?? false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -129,14 +129,11 @@ class Categories
|
|||||||
$id = $id ? (int) $id : $data['id'];
|
$id = $id ? (int) $id : $data['id'];
|
||||||
$category = self::get($id);
|
$category = self::get($id);
|
||||||
$ret = $category->update($data);
|
$ret = $category->update($data);
|
||||||
// CategoryTrees::update($data, $category->category_id);
|
|
||||||
return $category;
|
return $category;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function destroy($id)
|
public static function destroy($id)
|
||||||
{
|
{
|
||||||
// $category = self::get($id);
|
|
||||||
// CategoryTrees::destroy($category->category_id);
|
|
||||||
return Category::destroy($id);
|
return Category::destroy($id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user