Refactoring, change menu, add many features
This commit is contained in:
@@ -30,7 +30,7 @@ class ArticlesDataTable extends DataTable
|
||||
{
|
||||
$datatables
|
||||
->editColumn('thumb', function (Article $article) {
|
||||
return Articles::getThumbSrc($article->image);
|
||||
return '<img src="' . Articles::getThumbSrc($article->image) . '">';
|
||||
})
|
||||
->rawColumns(['thumb','action']);
|
||||
return parent::modifier($datatables);
|
||||
@@ -41,7 +41,7 @@ class ArticlesDataTable extends DataTable
|
||||
{
|
||||
return [
|
||||
Column::make('article_nature.name')->title('Nature'),
|
||||
Column::make('thumb')->searchable(false),
|
||||
Column::make('thumb')->searchable(false)->width(40)->class('text-center'),
|
||||
Column::make('name')->title('Nom'),
|
||||
Column::make('tags_count')->title('Tags')->class('text-right')->searchable(false),
|
||||
Column::make('categories_count')->title('Rayons')->class('text-right')->searchable(false),
|
||||
|
||||
41
app/Datatables/Shop/DeliveriesDataTable.php
Normal file
41
app/Datatables/Shop/DeliveriesDataTable.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Datatables\Shop;
|
||||
|
||||
use Yajra\DataTables\Html\Column;
|
||||
use App\Datatables\ParentDataTable as DataTable;
|
||||
use App\Models\Shop\Delivery;
|
||||
|
||||
class DeliveriesDataTable extends DataTable
|
||||
{
|
||||
public $model_name = 'deliveries';
|
||||
|
||||
public function query(Delivery $model)
|
||||
{
|
||||
$model = $model->with('SaleChannel');
|
||||
return self::buildQuery($model);
|
||||
}
|
||||
|
||||
public function modifier($datatables)
|
||||
{
|
||||
$datatables
|
||||
->editColumn('active', function (Delivery $delivery) {
|
||||
return view("components.form.toggle", ['value' => $delivery->active, 'on' => __('active'), 'off' => __('inactive'), 'meta' => 'data-id='.$delivery->id, 'size' => 'sm']);
|
||||
})
|
||||
->rawColumns(['active', 'action']);
|
||||
return parent::modifier($datatables);
|
||||
}
|
||||
|
||||
protected function getColumns()
|
||||
{
|
||||
return [
|
||||
Column::make('active')->title(__('active'))->width(60)->class('text-center'),
|
||||
Column::make('name')->title('Nom'),
|
||||
Column::make('sale_channel.name')->title(__('shop.sale_channels.name')),
|
||||
Column::make('address')->title('Adresse'),
|
||||
Column::make('zipcode')->title('Code postal'),
|
||||
Column::make('city')->title('Ville'),
|
||||
self::makeColumnButtons(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ class PackagesDataTable extends DataTable
|
||||
|
||||
public function query(Package $model)
|
||||
{
|
||||
$model = $model->withCount(['variations','offers']);
|
||||
return self::buildQuery($model);
|
||||
}
|
||||
|
||||
@@ -19,6 +20,8 @@ class PackagesDataTable extends DataTable
|
||||
{
|
||||
return [
|
||||
Column::make('value')->title('Valeur'),
|
||||
Column::make('variations_count')->title('nb variations')->searchable(false)->class('text-right'),
|
||||
Column::make('offers_count')->title('nb offres')->searchable(false)->class('text-right'),
|
||||
self::makeColumnButtons(),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -12,13 +12,16 @@ class SaleChannelsDataTable extends DataTable
|
||||
|
||||
public function query(SaleChannel $model)
|
||||
{
|
||||
$model = $model->withCount('deliveries');
|
||||
return self::buildQuery($model);
|
||||
}
|
||||
|
||||
protected function getColumns()
|
||||
{
|
||||
return [
|
||||
Column::make('code')->title('Code abrégé')->width(100),
|
||||
Column::make('name')->title('Nom'),
|
||||
Column::make('deliveries_count')->title(__('shop.deliveries.list'))->searchable(false),
|
||||
self::makeColumnButtons(),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Admin\Shop;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use App\Repositories\Shop\Customers;
|
||||
use App\Repositories\Shop\SaleChannels;
|
||||
use App\Datatables\Shop\CustomersDataTable;
|
||||
|
||||
class CustomerController extends Controller
|
||||
@@ -17,7 +18,8 @@ class CustomerController extends Controller
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('Admin.Shop.Customers.create');
|
||||
$data['sale_channels'] = SaleChannels::getOptions();
|
||||
return view('Admin.Shop.Customers.create', $data);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
@@ -35,6 +37,7 @@ class CustomerController extends Controller
|
||||
public function edit($id)
|
||||
{
|
||||
$data['customer'] = Customers::get($id)->toArray();
|
||||
$data['sale_channels'] = SaleChannels::getOptions();
|
||||
return view('Admin.Shop.Customers.edit', $data);
|
||||
}
|
||||
|
||||
|
||||
55
app/Http/Controllers/Admin/Shop/DeliveryController.php
Normal file
55
app/Http/Controllers/Admin/Shop/DeliveryController.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\Shop;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use App\Repositories\Shop\Deliveries;
|
||||
use App\Repositories\Shop\SaleChannels;
|
||||
use App\Datatables\Shop\DeliveriesDataTable;
|
||||
|
||||
class DeliveryController extends Controller
|
||||
{
|
||||
public function index(DeliveriesDataTable $dataTable)
|
||||
{
|
||||
$data = [];
|
||||
return $dataTable->render('Admin.Shop.Deliveries.list', $data);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$data['sale_channels'] = SaleChannels::getOptions();
|
||||
return view('Admin.Shop.Deliveries.create', $data);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$ret = Deliveries::store($request->all());
|
||||
return redirect()->route('Admin.Shop.Deliveries.index');
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$data['delivery'] = Deliveries::get($id);
|
||||
return view('Admin.Shop.Deliveries.view', $data);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$data['delivery'] = Deliveries::get($id)->toArray();
|
||||
$data['sale_channels'] = SaleChannels::getOptions();
|
||||
return view('Admin.Shop.Deliveries.edit', $data);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
return Deliveries::destroy($id);
|
||||
}
|
||||
|
||||
public function toggleActive(Request $request)
|
||||
{
|
||||
$data = Deliveries::toggle_active($request->input('id'), ($request->input('active') == 'true') ? 1 : 0);
|
||||
return response()->json(['error' => 0]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Shop\Admin;
|
||||
namespace App\Http\Controllers\Admin\Shop;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
@@ -12,7 +12,7 @@ class Botanic
|
||||
$menu->add('Botanique', [ 'permission' => 'backend_access', 'icon' => 'leaf' ])
|
||||
->id('botanic')
|
||||
->activeIfRoute('botanic')
|
||||
->order(4);
|
||||
->order(5);
|
||||
|
||||
$menu->addTo('botanic', 'Familles', [ 'route' => 'Admin.Botanic.Families.index', 'permission' => 'backend_access' ])
|
||||
->activeIfRoute(['Admin.Botanic.Families.*'])->order(1);
|
||||
|
||||
@@ -8,15 +8,13 @@ class Customers
|
||||
{
|
||||
public function make(Builder $menu)
|
||||
{
|
||||
$menu->add('Clients', [ 'permission' => 'backend_access', 'icon' => 'address-card' ])
|
||||
$menu->add('Clients finaux', [ 'permission' => 'backend_access', 'icon' => 'address-card' ])
|
||||
->id('customers')
|
||||
->activeIfRoute('customers')
|
||||
->order(3);
|
||||
->order(4);
|
||||
|
||||
$menu->addTo('customers', __('customer.customers.name'), [ 'route' => 'Admin.Shop.Customers.index', 'permission' => 'backend_access' ])
|
||||
->activeIfRoute(['Admin.Shop.Customers.*'])->order(1);
|
||||
|
||||
$menu->addTo('customers', __('customer.sale_channels.name'), [ 'route' => 'Admin.Shop.SaleChannels.index', 'permission' => 'backend_access' ])
|
||||
->activeIfRoute(['Admin.Shop.SaleChannels.*'])->order(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
22
app/Menu/Deliveries.php
Normal file
22
app/Menu/Deliveries.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Menu;
|
||||
|
||||
use Sebastienheyd\Boilerplate\Menu\Builder;
|
||||
|
||||
class Deliveries
|
||||
{
|
||||
public function make(Builder $menu)
|
||||
{
|
||||
$menu->add('Modes de vente', [ 'permission' => 'backend_access', 'icon' => 'address-card' ])
|
||||
->id('sales_mode')
|
||||
->activeIfRoute('sales_mode')
|
||||
->order(3);
|
||||
|
||||
$menu->addTo('sales_mode', __('shop.sale_channels.name'), [ 'route' => 'Admin.Shop.SaleChannels.index', 'permission' => 'backend_access' ])
|
||||
->activeIfRoute(['Admin.Shop.SaleChannels.*'])->order(1);
|
||||
|
||||
$menu->addTo('sales_mode', __('shop.deliveries.title'), [ 'route' => 'Admin.Shop.Deliveries.index', 'permission' => 'backend_access' ])
|
||||
->activeIfRoute(['Admin.Shop.Deliveries.*'])->order(1);
|
||||
}
|
||||
}
|
||||
@@ -3,22 +3,15 @@
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Spatie\MediaLibrary\HasMedia\HasMedia;
|
||||
use Spatie\MediaLibrary\HasMedia\HasMediaTrait;
|
||||
// use Rinvex\Categories\Traits\Categorizable;
|
||||
use Rinvex\Tags\Traits\Taggable;
|
||||
// use Conner\Tagging\Taggable;
|
||||
use Fico7489\Laravel\EloquentJoin\Traits\EloquentJoin;
|
||||
|
||||
class Category extends Model
|
||||
class Basket extends Model
|
||||
{
|
||||
use Taggable, HasMediaTrait;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'shop_categories';
|
||||
protected $table = 'shop_baskets';
|
||||
|
||||
public function Articles()
|
||||
public function Offer()
|
||||
{
|
||||
return $this->morphedByMany('App\Models\Shop\Article', 'categorizable');
|
||||
return $this->belongsTo('App\Models\Shop\Offer');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,11 @@ class Customer extends Model
|
||||
return $this->hasMany(Invoice::class);
|
||||
}
|
||||
|
||||
public function Deliveries()
|
||||
{
|
||||
return $this->hasMany(Delivery::class);
|
||||
}
|
||||
|
||||
public function Orders()
|
||||
{
|
||||
return $this->hasMany(Order::class);
|
||||
|
||||
57
app/Models/Shop/Delivery.php
Normal file
57
app/Models/Shop/Delivery.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Delivery extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'shop_deliveries';
|
||||
|
||||
public function Customers()
|
||||
{
|
||||
return $this->hasMany(Customer::class);
|
||||
}
|
||||
|
||||
public function SaleChannel()
|
||||
{
|
||||
return $this->belongsTo(SaleChannel::class);
|
||||
}
|
||||
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $this->byActive(1);
|
||||
}
|
||||
|
||||
public function scopeByActive($query, $active)
|
||||
{
|
||||
return $query->where($this->table . '.active', $active);
|
||||
}
|
||||
|
||||
public function scopeByPublic($query, $is_public)
|
||||
{
|
||||
return $query->where($this->table . '.is_public', $is_public);
|
||||
}
|
||||
|
||||
public function scopeAtHouse($query)
|
||||
{
|
||||
return $query->where($this->table . '.at_house', 1);
|
||||
}
|
||||
|
||||
public function scopeInactive($query)
|
||||
{
|
||||
return $this->byActive(0);
|
||||
}
|
||||
|
||||
public function scopeManaged($query)
|
||||
{
|
||||
return $this->byPublic(0);
|
||||
}
|
||||
|
||||
public function scopePublic($query)
|
||||
{
|
||||
return $this->byPublic(1);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,17 +8,11 @@ class Invoice extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function InvoiceItems()
|
||||
{
|
||||
return $this->hasMany(InvoiceItem::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function Customer()
|
||||
{
|
||||
return $this->belongsTo(Customer::class);
|
||||
|
||||
@@ -19,6 +19,16 @@ class Package extends Model
|
||||
return $this->hasMany(Unity::class);
|
||||
}
|
||||
|
||||
public function variations()
|
||||
{
|
||||
return $this->hasMany(Variation::class);
|
||||
}
|
||||
|
||||
public function offers()
|
||||
{
|
||||
return $this->hasManyThrough(Offer::class, Variation::class);
|
||||
}
|
||||
|
||||
public function scopeByArticleNature($query, $id)
|
||||
{
|
||||
return $query->where($this->table . '.article_family_id', $id);
|
||||
|
||||
@@ -8,4 +8,10 @@ class SaleChannel extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'shop_sale_channels';
|
||||
|
||||
public function deliveries()
|
||||
{
|
||||
return $this->hasMany(Delivery::class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,4 +21,9 @@ class Variation extends Model
|
||||
{
|
||||
return $this->belongsTo(Unity::class);
|
||||
}
|
||||
|
||||
public function offers()
|
||||
{
|
||||
return $this->hasMany(Offer::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,28 +5,28 @@ namespace App\Repositories;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Ville;
|
||||
use App\Models\City;
|
||||
|
||||
class Villes
|
||||
class Cities
|
||||
{
|
||||
public static function getVillesByName($query)
|
||||
public static function getCitiesByName($query)
|
||||
{
|
||||
return Ville::select('id', DB::raw("concat(nom,' (',code_postal,')') as text"))->where('nom', 'LIKE', "$query%")->orderBy('nom', 'ASC')->take(30)->get();
|
||||
return City::select('id', DB::raw("concat(nom,' (',code_postal,')') as text"))->where('nom', 'LIKE', "$query%")->orderBy('nom', 'ASC')->take(30)->get();
|
||||
}
|
||||
|
||||
public static function getVillesByCP($query)
|
||||
public static function getCitiesByCP($query)
|
||||
{
|
||||
return Ville::select('id', DB::raw("concat(nom,' (',code_postal,')') as text"))->where('code_postal', 'LIKE', "%q$guery%")->orderBy('nom', 'ASC')->take(30)->get();
|
||||
return City::select('id', DB::raw("concat(nom,' (',code_postal,')') as text"))->where('code_postal', 'LIKE', "%q$guery%")->orderBy('nom', 'ASC')->take(30)->get();
|
||||
}
|
||||
|
||||
public static function getCPByVille($id)
|
||||
public static function getCPByCity($id)
|
||||
{
|
||||
$ville = self::get($id);
|
||||
$codes = explode("-", $ville->code_postal);
|
||||
return $codes;
|
||||
}
|
||||
|
||||
public static function getNomByVille($id)
|
||||
public static function getNomByCity($id)
|
||||
{
|
||||
$ville = self::get($id);
|
||||
return $ville->nom;
|
||||
@@ -34,7 +34,7 @@ class Villes
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Ville::find($id);
|
||||
return City::find($id);
|
||||
}
|
||||
|
||||
public static function getCoords($adresse)
|
||||
@@ -58,9 +58,9 @@ class Villes
|
||||
}
|
||||
}
|
||||
|
||||
public static function getCoordsByVille($id)
|
||||
public static function getCoordsByCity($id)
|
||||
{
|
||||
$ville = Ville::find($id);
|
||||
$ville = City::find($id);
|
||||
return ['latitude' => $ville->latitude, 'longitude' => $ville->longitude];
|
||||
}
|
||||
}
|
||||
|
||||
54
app/Repositories/Shop/Deliveries.php
Normal file
54
app/Repositories/Shop/Deliveries.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Delivery;
|
||||
|
||||
class Deliveries
|
||||
{
|
||||
public static function getOptions()
|
||||
{
|
||||
return Delivery::orderBy('name', 'asc')->get()->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Delivery::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Delivery::find($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = $data['id'] ?? false;
|
||||
$item = $id ? self::update($data, $id) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return Delivery::create($data);
|
||||
}
|
||||
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = $id ? $id : $data['id'];
|
||||
$delivery = self::get($id);
|
||||
$delivery->update($data);
|
||||
return $delivery;
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Delivery::destroy($id);
|
||||
}
|
||||
|
||||
public static function toggle_active($id, $active)
|
||||
{
|
||||
return self::update(['active' => $active], $id);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user