minor fixes

This commit is contained in:
ludo
2023-12-09 21:02:28 +01:00
parent b5da5fc881
commit 2a429e4163
49 changed files with 448 additions and 266 deletions

View File

@@ -13,10 +13,18 @@ class CustomersDataTable extends DataTable
public function query(Customer $model)
{
$model = $model->with('addresses');
$model = self::filterBySaleChannel($model);
return $this->buildQuery($model);
}
public static function filterBySaleChannel($model, $sale_channel_id = false)
{
$sale_channel_id = $sale_channel_id ? $sale_channel_id : self::isFilteredByField('sale_channel_id');
return $sale_channel_id ? $model->bySaleChannel($sale_channel_id) : $model;
}
protected function getColumns()
{
return [

View File

@@ -13,10 +13,18 @@ class DeliveriesDataTable extends DataTable
public function query(Delivery $model)
{
$model = $model->with('sale_channel');
$model = self::filterBySaleChannel($model);
return $this->buildQuery($model);
}
public static function filterBySaleChannel($model, $sale_channel_id = false)
{
$sale_channel_id = $sale_channel_id ? $sale_channel_id : self::isFilteredByField('sale_channel_id');
return $sale_channel_id ? $model->bySaleChannel($sale_channel_id) : $model;
}
public function modifier($datatables)
{
$datatables
@@ -26,7 +34,7 @@ class DeliveriesDataTable extends DataTable
'on' => __('active'),
'off' => __('inactive'),
'meta' => 'data-id='.$delivery->id,
'size' => 'sm',
'size' => 'xs',
]);
})
->editColumn('is_public', function (Delivery $delivery) {

View File

@@ -12,7 +12,7 @@ class SaleChannelsDataTable extends DataTable
public function query(SaleChannel $model)
{
$model = $model->withCount(['deliveries', 'tariffs']);
$model = $model->withCount(['customers', 'deliveries', 'tariffs']);
return $this->buildQuery($model);
}
@@ -22,6 +22,7 @@ class SaleChannelsDataTable extends DataTable
return [
Column::make('code')->title('Code abrégé')->width(100),
Column::make('name')->title('Nom'),
Column::make('customers_count')->title('#Clients')->searchable(false)->class('text-right'),
Column::make('deliveries_count')->title('#Distrib')->searchable(false)->class('text-right'),
Column::make('tariffs_count')->title('#Tarifs')->searchable(false)->class('text-right'),
$this->makeColumnButtons(),

View File

@@ -2,7 +2,7 @@
namespace App\Http\Controllers\Admin\Shop;
use App\Datatables\Shop\CustomerAddressesDataTable;
use App\Datatables\Admin\Shop\CustomerAddressesDataTable;
use App\Repositories\Shop\CustomerAddresses;
use Illuminate\Http\Request;

View File

@@ -5,21 +5,20 @@ namespace App\Http\Controllers\Admin\Shop;
use App\Datatables\Admin\Shop\CustomerAddressesDataTable;
use App\Datatables\Admin\Shop\CustomersDataTable;
use App\Repositories\Shop\Customers;
use App\Repositories\Shop\Deliveries;
use Illuminate\Http\Request;
class CustomerController extends Controller
{
public function index(CustomersDataTable $dataTable)
{
$data = [];
$data = Customers::init();
return $dataTable->render('Admin.Shop.Customers.list', $data);
}
public function create()
{
$data['deliveries'] = Deliveries::getOptions();
$data = Customers::init();
return view('Admin.Shop.Customers.create', $data);
}
@@ -40,8 +39,8 @@ class CustomerController extends Controller
public function edit($id)
{
$data = Customers::init();
$data['customer'] = Customers::edit($id);
$data['deliveries'] = Deliveries::getOptions();
$model = new CustomerAddressesDataTable();
$data['customer_addresses'] = $model->html();

View File

@@ -4,21 +4,20 @@ namespace App\Http\Controllers\Admin\Shop;
use App\Datatables\Admin\Shop\DeliveriesDataTable;
use App\Repositories\Shop\Deliveries;
use App\Repositories\Shop\SaleChannels;
use Illuminate\Http\Request;
class DeliveryController extends Controller
{
public function index(DeliveriesDataTable $dataTable)
{
return $dataTable->render('Admin.Shop.Deliveries.list');
$data = Deliveries::init();
return $dataTable->render('Admin.Shop.Deliveries.list', $data);
}
public function create()
{
$data = [
'sale_channels' => SaleChannels::getOptions(),
];
$data = Deliveries::init();
return view('Admin.Shop.Deliveries.create', $data);
}
@@ -41,10 +40,8 @@ class DeliveryController extends Controller
public function edit($id)
{
$data = [
'delivery' => Deliveries::get($id)->toArray(),
'sale_channels' => SaleChannels::getOptions(),
];
$data = Deliveries::init();
$data['delivery'] = Deliveries::getArray($id);
return view('Admin.Shop.Deliveries.edit', $data);
}

View File

@@ -2,8 +2,8 @@
namespace App\Http\Controllers\Admin\Shop;
use App\Datatables\Admin\Shop\InvoicesDataTable;
use App\Datatables\Admin\Shop\InvoicePaymentsDataTable;
use App\Datatables\Admin\Shop\InvoicesDataTable;
use App\Http\Controllers\Controller;
use App\Repositories\Shop\Invoices;
use Illuminate\Http\Request;

View File

@@ -18,7 +18,7 @@ class InvoicePaymentController extends Controller
{
$data = InvoicePayments::init();
return view('Admin.Shop.InvoicePayments.create' , $data);
return view('Admin.Shop.InvoicePayments.create', $data);
}
public function store(Request $request)

View File

@@ -5,9 +5,6 @@ namespace App\Http\Controllers\Admin\Shop;
use App\Datatables\Admin\Shop\PriceListsDataTable;
use App\Http\Controllers\Controller;
use App\Repositories\Shop\PriceLists;
use App\Repositories\Shop\SaleChannels;
use App\Repositories\Shop\Tariffs;
use App\Repositories\Shop\Taxes;
use Illuminate\Http\Request;
class PriceListController extends Controller

View File

@@ -4,7 +4,6 @@ namespace App\Http\Controllers\Admin\Shop;
use App\Datatables\Admin\Shop\ProducersDataTable;
use App\Repositories\Shop\Producers;
use App\Repositories\Shop\TagGroups;
use Illuminate\Http\Request;
class ProducerController extends Controller

View File

@@ -2,11 +2,8 @@
namespace App\Http\Controllers\Admin\Shop;
use App\Datatables\Admin\Shop\PriceListsDataTable;
use App\Datatables\Admin\Shop\TariffsDataTable;
use App\Repositories\Shop\SaleChannels;
use App\Repositories\Shop\Tariffs;
use App\Repositories\Shop\TariffUnities;
use Illuminate\Http\Request;
class TariffController extends Controller

View File

@@ -4,8 +4,6 @@ namespace App\Http\Controllers\Admin\Shop;
use App\Datatables\Admin\Shop\VariationsDataTable;
use App\Http\Requests\Admin\Shop\StoreVariationPost;
use App\Repositories\Shop\Packages;
use App\Repositories\Shop\Unities;
use App\Repositories\Shop\Variations;
use Illuminate\Http\Request;

View File

@@ -5,7 +5,6 @@ namespace App\Http\Controllers\Shop;
use App\Http\Controllers\Controller;
use App\Repositories\Core\User\ShopCart;
use App\Repositories\Shop\Baskets;
use App\Repositories\Shop\Customers;
use App\Repositories\Shop\Offers;
use App\Repositories\Shop\Orders;
use App\Repositories\Users;
@@ -66,7 +65,7 @@ class BasketController extends Controller
public function getBasketTotal($deliveryId = false, $deliveryTypeId = false)
{
$data['basket'] = Baskets::getBasketTotal($deliveryId, $deliveryTypeId);
return view('Shop.Baskets.partials.basketTotal', $data);
}

View File

@@ -3,11 +3,8 @@
namespace App\Http\Controllers\Shop;
use App\Http\Controllers\Controller;
use App\Repositories\Shop\ArticleNatures;
use App\Repositories\Shop\Articles;
use App\Repositories\Shop\Categories;
use App\Repositories\Shop\Shelves;
use App\Repositories\Shop\TagGroups;
use Illuminate\Http\Request;
class CategoryController extends Controller

View File

@@ -2,10 +2,9 @@
namespace App\Http\Controllers\Shop;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Repositories\Shop\Customers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class CustomerController extends Controller
@@ -46,7 +45,7 @@ class CustomerController extends Controller
dump($data);
exit;
$customer = Customers::storeFull($data);
return response()->json(['error' => 0]);
}
}

View File

@@ -25,7 +25,7 @@ class OrderController extends Controller
public function view($uuid)
{
$data['order'] = Orders::view($uuid);
return view('Shop.Orders.view', $data);
}
@@ -67,7 +67,7 @@ class OrderController extends Controller
if ($order) {
if ($data['payment_type'] == '1') {
return Paybox::makeAuthorizationRequest($data['basket']['total_shipped']);
// return redirect()->route('Shop.Payments.online');
// return redirect()->route('Shop.Payments.online');
} else {
return redirect()->route('Shop.Orders.confirmed');
}

View File

@@ -60,7 +60,7 @@ class ArticleNature extends Model implements HasMedia
return $query->whereIn($this->table.'.id', $ids);
}
public function registerMediaConversions(Media $media = null): void
public function registerMediaConversions(?Media $media = null): void
{
$this->addMediaConversion('thumb')->fit(Manipulations::FIT_MAX, 60, 32)->keepOriginalImageFormat()->nonQueued();
$this->addMediaConversion('normal')->fit(Manipulations::FIT_MAX, 360, 192)->keepOriginalImageFormat()->nonQueued();

View File

@@ -21,7 +21,6 @@ class Customer extends Authenticatable
protected $casts = ['email_verified_at' => 'datetime'];
public function delivery_addresses()
{
return $this->addresses()->byDelivery();
@@ -31,7 +30,6 @@ class Customer extends Authenticatable
{
return $this->addresses()->byInvoicing();
}
public function addresses()
{
@@ -43,11 +41,21 @@ class Customer extends Authenticatable
return $this->hasMany(CustomerDelivery::class);
}
public function customer_sale_channels()
{
return $this->hasMany(CustomerSaleChannel::class);
}
public function deliveries()
{
return $this->belongsToMany(Delivery::class, CustomerDelivery::class);
}
public function sale_channels()
{
return $this->belongsToMany(SaleChannel::class, CustomerSaleChannel::class)->wherePivotNull('deleted_at');
}
public function invoices()
{
return $this->hasMany(Invoice::class);
@@ -58,6 +66,13 @@ class Customer extends Authenticatable
return $this->hasMany(Order::class);
}
public function scopeBySaleChannel($query, $saleChannelId)
{
return $query->whereHas('sale_channels', function ($query) use ($saleChannelId) {
return $query->byId($saleChannelId);
});
}
public function sendEmailVerificationNotification()
{
if (config('boilerplate.auth.verify_email')) {

View File

@@ -20,13 +20,13 @@ class CustomerDelivery extends Model
return $this->belongsTo(Delivery::class);
}
public function scopeByCustomer($query, $customer_id)
public function scopeByCustomer($query, $customerId)
{
return $query->where($this->table.'.customer_id', $customer_id);
return $query->where($this->table.'.customer_id', $customerId);
}
public function scopeByDelivery($query, $customer_id)
public function scopeByDelivery($query, $deliveryId)
{
return $query->where($this->table.'.delivery_id', $customer_id);
return $query->where($this->table.'.delivery_id', $deliveryId);
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Wildside\Userstamps\Userstamps;
class CustomerSaleChannel extends Model
{
use SoftDeletes, Userstamps;
protected $guarded = ['id'];
protected $table = 'shop_customer_sale_channels';
public function customer()
{
return $this->belongsTo(Customer::class);
}
public function sale_channel()
{
return $this->belongsTo(SaleChannel::class);
}
public function scopeByCustomer($query, $customerId)
{
return $query->where($this->table.'.customer_id', $customerId);
}
public function scopeBySaleChannel($query, $saleChannelId)
{
return $query->where($this->table.'.sale_channel_id', $saleChannelId);
}
}

View File

@@ -67,6 +67,11 @@ class Delivery extends Model
return $query->where($this->table.'.at_house', 1);
}
public function scopeBySaleChannel($query)
{
return $query->where($this->table.'.sale_channel_id', 1);
}
public function scopeManaged($query)
{
return $query->byPublic(0);

View File

@@ -10,6 +10,16 @@ class SaleChannel extends Model
protected $table = 'shop_sale_channels';
public function customer_sale_channels()
{
return $this->hasMany(CustomerSaleChannel::class);
}
public function customers()
{
return $this->belongsToMany(Customer::class, CustomerSaleChannel::class)->wherePivotNull('deleted_at');
}
public function deliveries()
{
return $this->hasMany(Delivery::class);
@@ -29,4 +39,9 @@ class SaleChannel extends Model
{
return $query->where($this->table.'.code', $code);
}
public function scopeById($query, $id)
{
return $query->where($this->table.'.id', $id);
}
}

View File

@@ -29,7 +29,7 @@ class ArticleNatures
public static function getIdBySlug($slug)
{
$model = self::getBySlug($slug);
return $model ? $model->id : false;
}

View File

@@ -4,11 +4,11 @@ namespace App\Repositories\Shop;
use App\Models\Shop\Article;
use App\Models\Shop\Merchandise;
use App\Traits\Model\Basic;
use App\Repositories\Botanic\Species;
use App\Repositories\Botanic\Varieties;
use App\Repositories\Core\Comments;
use App\Repositories\Core\Tag;
use App\Traits\Model\Basic;
use App\Traits\Repository\Imageable;
use Illuminate\Support\Str;
@@ -245,7 +245,7 @@ class Articles
public static function getArticleNaturesOptionsWithOffers($options = false)
{
$ids = self::getArticleNaturesIdsWithOffers($options);
}
public static function getArticleNaturesWithOffers($options = false)
@@ -342,7 +342,7 @@ class Articles
switch ($product_type) {
case 'App\Models\Botanic\Variety':
$product = Varieties::get($product_id);
if (!$product) {
if (! $product) {
break;
}
$data[] = [
@@ -358,7 +358,7 @@ class Articles
break;
case 'App\Models\Botanic\Specie':
$product = Species::get($product_id);
if (!$product) {
if (! $product) {
break;
}
$data[] = [
@@ -369,7 +369,7 @@ class Articles
break;
case 'App\Models\Shop\Merchandise':
$product = Merchandises::get($product_id);
if (!$product) {
if (! $product) {
break;
}
$data[] = [

View File

@@ -19,7 +19,7 @@ class Baskets
public static function getBasketTotal($deliveryId = false, $deliveryTypeId = false)
{
$saleChannelId = Deliveries::getSaleChannelId($deliveryId);
return self::getBasketSummary($saleChannelId, $deliveryTypeId);
}
@@ -41,7 +41,7 @@ class Baskets
$totalWeight += $weight;
}
$shipping = DeliveryTypeCalculations::getPriceByDeliveryType($deliveryTypeId, $totalWeight);
$data = [
'detail' => $detail,
'total' => $total,
@@ -84,7 +84,7 @@ class Baskets
$weight = $offer->weight * $item->quantity;
$totalWeight += $weight;
}
return $totalWeight;
}

View File

@@ -0,0 +1,21 @@
<?php
namespace App\Repositories\Shop;
use App\Models\Shop\CustomerSaleChannel;
use App\Traits\Model\Basic;
class CustomerSaleChannels
{
use Basic;
public static function destroyByCustomerAndSaleChannel($customerId, $saleChannelId)
{
return CustomerSaleChannel::byCustomer($customerId)->bySaleChannel($saleChannelId)->delete();
}
public static function getModel()
{
return CustomerSaleChannel::query();
}
}

View File

@@ -14,6 +14,27 @@ class Customers
{
use Basic;
public static function init()
{
return [
'sale_channels' => SaleChannels::getOptions(),
];
}
public static function getSaleChannelIds($customerId = false)
{
$channels = self::getSaleChannels($customerId);
return $channels ? $channels->pluck('id')->toArray() : false;
}
public static function getSaleChannels($customerId = false)
{
$customer = $customerId ? self::get($customerId) : self::getAuth();
return $customer ? $customer->sale_channels : SaleChannels::getDefault();
}
public static function getSaleChannel()
{
return SaleChannels::getDefault();
@@ -60,7 +81,7 @@ class Customers
$filename = self::makeAvatarFilename($customer);
$name = $customer->first_name.' '.$customer->last_name;
$avatar = new Avatar();
return $avatar->create($name)
->setBackground('#F2B90F')
->setForeground('#335012')
@@ -129,22 +150,25 @@ class Customers
public static function edit($id)
{
$customer = self::get($id, ['delivery_addresses', 'invoice_addresses']);
$customer = self::get($id, ['delivery_addresses', 'invoice_addresses', 'sale_channels']);
$data = $customer->toArray();
$data['deliveries'] = $customer->deliveries->pluck('id')->toArray();
$data['sale_channels'] = $customer->sale_channels->pluck('id')->toArray();
return $data;
}
public static function storeFull($data)
{
$deliveries = $data['deliveries'];
$invoices = $data['invoices'];
unset($data['deliveries']);
unset($data['invoices']);
// $invoices = $data['invoices'];
$saleChannels = $data['sale_channels'];
// unset($data['invoices']);
unset($data['sale_channels']);
$customer = self::store($data);
self::storeAddresses($customer, $deliveries);
self::storeAddresses($customer, $invoices);
if ($customer) {
// self::storeAddresses($customer->id, $deliveries);
// self::storeAddresses($customer->id, $invoices);
self::storeSaleChannels($customer->id, $saleChannels);
}
return $customer->id;
}
@@ -163,31 +187,37 @@ class Customers
return $customer->deliveries()->sync($deliveries);
}
public static function storeAddresses($customer, $addresses)
public static function storeAddresses($customerId, $addresses)
{
foreach ($addresses as $address) {
$address['customer_id'] = $customer->id;
$address['customer_id'] = $customerId;
CustomerAddresses::store($address);
}
}
public static function storeSaleChannels($customerId, $saleChannels)
{
$oldSaleChannels = self::getSaleChannelIds($customerId);
$deleteSaleChannels = array_diff($oldSaleChannels, $saleChannels);
$newSaleChannels = array_diff($saleChannels, $oldSaleChannels);
$data = ['customer_id' => $customerId];
foreach ($newSaleChannels as $saleChannelId) {
$data['sale_channel_id'] = $saleChannelId;
CustomerSaleChannels::store($data);
}
foreach ($deleteSaleChannels as $saleChannelId) {
CustomerSaleChannels::destroyByCustomerAndSaleChannel($customerId, $saleChannelId);
}
}
public static function create($data)
{
return Customer::create([
'uuid' => Str::uuid(),
'active' => true,
'first_name' => $data['first_name'],
'last_name' => $data['last_name'],
'company' => $data['company'],
'tva' => $data['tva'],
'phone' => $data['phone'],
'address' => $data['address'],
'address2' => $data['address2'],
'zipcode' => $data['zipcode'],
'city' => $data['city'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
$data['uuid'] = Str::uuid();
$data['active'] = true;
$data['password'] = bcrypt($data['password']);
return Customer::create($data);
}
public static function getStorage($filename = false)

View File

@@ -9,6 +9,13 @@ class Deliveries
{
use Basic;
public static function init()
{
return [
'sale_channels' => SaleChannels::getOptions(),
];
}
public static function getSaleChannelId($deliveryId)
{
return $deliveryId ? Deliveries::getField($deliveryId, 'sale_channel_id') : SaleChannels::getDefaultID();

View File

@@ -12,7 +12,7 @@ class DeliveryTypeCalculations
public static function getPriceByDeliveryType($deliveryTypeId, $weight)
{
$price = DeliveryTypeCalculation::byDeliveryType($deliveryTypeId)->byWeight($weight)->first();
return $price ? $price->price : false;
}

View File

@@ -8,7 +8,7 @@ use App\Traits\Model\Basic;
class InvoicePayments
{
use Basic;
public static function init()
{
return [

View File

@@ -3,8 +3,8 @@
namespace App\Repositories\Shop;
use App\Models\Shop\Merchandise;
use App\Traits\Model\Basic;
use App\Repositories\Core\Tag;
use App\Traits\Model\Basic;
use App\Traits\Repository\Imageable;
class Merchandises
@@ -68,7 +68,6 @@ class Merchandises
return Tag::storeTags($merchandise, $tags);
}
public static function getModel()
{
return Merchandise::query();

View File

@@ -3,7 +3,6 @@
namespace App\Repositories\Shop;
use App\Models\Shop\Offer;
use App\Models\Shop\PriceList;
use App\Traits\Model\Basic;
class Offers
@@ -30,6 +29,7 @@ class Offers
{
return Offer::with('variation')->byIds($ids)->get();
}
public static function getWithPricesByIds($ids, $saleChannelId = false)
{
$saleChannelId = $saleChannelId ? $saleChannelId : SaleChannels::getDefaultID();
@@ -69,7 +69,7 @@ class Offers
$saleChannelId = $saleChannelId ? $saleChannelId : SaleChannels::getDefaultID();
$offer = Offer::withPriceBySaleChannelByQuantity($saleChannelId, $quantity)->find($id);
$priceList = $offer->price_lists->first();
return $priceList ? $priceList->price_list_values->first() : false;
}

View File

@@ -29,6 +29,7 @@ class Orders
$data = $order->toArray();
$data['payment_type'] = InvoicePayments::getPaymentType($order->payment_type);
$data['status'] = Orders::getStatus($order->status);
return $data;
}

View File

@@ -8,7 +8,7 @@ use App\Traits\Model\Basic;
class PriceLists
{
use Basic;
public static function init($tariffId = false)
{
return [
@@ -47,7 +47,6 @@ class PriceLists
return PriceList::byTariff($id)->get();
}
public static function edit($id)
{
$price_list = self::getFull($id)->toArray();

View File

@@ -2,10 +2,6 @@
namespace App\Repositories\Shop;
use App\Models\Shop\Category;
use App\Repositories\Core\Categories as CategoryTrees;
use App\Repositories\Core\Tag;
class Shelves
{
public static function getOffersByCategoryAndNature($categoryId, $articleNatureId = false, $tags = [], $articleNature = false, $displayByRows = false)
@@ -29,6 +25,7 @@ class Shelves
$productType = ArticleNatures::getProductTypeBySlug($articleNature);
$articleNatureId = ArticleNatures::getIdBySlug($articleNature);
}
return [
'category' => Categories::getFull($categoryId),
'breadcrumb' => Categories::getAncestorsByCategory($categoryId),

View File

@@ -23,6 +23,7 @@ class Tariffs
],
];
}
public static function autocomplete($str)
{
$data = Tariff::byAutocomplete($str)->orderBy('name')->limit(30)->get()->pluck('name', 'id');

View File

@@ -17,6 +17,7 @@ class Variations
'unities' => Unities::getOptions(),
];
}
public static function autocomplete($str)
{
$data = Variation::where('name', 'LIKE', "%${str}%")->orderBy('name')->limit(30)->get()->pluck('name', 'id');
@@ -57,7 +58,6 @@ class Variations
return Packages::getName($data['package_id']).' '.$data['quantity'].' '.Unities::getName($data['unity_id']);
}
public static function getFull($id)
{
return Variation::with(['package', 'unity'])->findOrFail($id);

View File

@@ -190,6 +190,7 @@ trait Basic
if ($stopStamping) {
$model->stopUserstamping();
}
return $model;
}
}

View File

@@ -20,7 +20,7 @@ trait Imageable
return $this->hasOne(Media::class, 'model_id')->where('model_type', get_class($this))->latest();
}
public function registerMediaConversions(Media $media = null): void
public function registerMediaConversions(?Media $media = null): void
{
$watermark = public_path('img/watermark.png');