diff --git a/app/Http/Controllers/Admin/Shop/PriceListController.php b/app/Http/Controllers/Admin/Shop/PriceListController.php index 21ad147c..94560702 100644 --- a/app/Http/Controllers/Admin/Shop/PriceListController.php +++ b/app/Http/Controllers/Admin/Shop/PriceListController.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers\Admin\Shop; -use App\Datatables\Shop\PriceListsDataTable; +use App\Datatables\Admin\Shop\PriceListsDataTable; use App\Http\Controllers\Controller; use App\Repositories\Shop\PriceLists; use App\Repositories\Shop\SaleChannels; @@ -14,45 +14,20 @@ class PriceListController extends Controller { public function index(PriceListsDataTable $dataTable) { - $data = []; - - return $dataTable->render('Admin.Shop.PriceLists.list', $data); + return $dataTable->render('Admin.Shop.PriceLists.list'); } - public function create() + public function modalCreate($tariffId) { - $data = []; - $data['sale_channels'] = SaleChannels::getOptions(); - - return view('Admin.Shop.PriceLists.create', $data); - } - - public function edit($id) - { - $data['price_list'] = PriceLists::get($id); - $data['sale_channels'] = SaleChannels::getOptions(); - - return view('Admin.Shop.PriceLists.edit', $data); - } - - public function modalCreate($tariff_id) - { - $data = []; - $data['price_list']['tariff_id'] = $tariff_id; - $data['price_list']['price_list_values'] = array_fill(0, 3, ''); - $data['sale_channels'] = SaleChannels::getOptions(); - $data['statuses'] = Tariffs::getStatuses(); - $data['taxes'] = Taxes::getOptions(); + $data = PriceLists::init($tariffId); return view('Admin.Shop.PriceLists.modal', $data); } public function modalEdit($id) { + $data = PriceLists::init(); $data['price_list'] = PriceLists::edit($id); - $data['sale_channels'] = SaleChannels::getOptions(); - $data['statuses'] = Tariffs::getStatuses(); - $data['taxes'] = Taxes::getOptions(); return view('Admin.Shop.PriceLists.modal', $data); } diff --git a/app/Http/Controllers/Admin/Shop/TariffController.php b/app/Http/Controllers/Admin/Shop/TariffController.php index fb855d85..2fcf89d3 100644 --- a/app/Http/Controllers/Admin/Shop/TariffController.php +++ b/app/Http/Controllers/Admin/Shop/TariffController.php @@ -25,32 +25,22 @@ class TariffController extends Controller public function create() { - $data['sale_channels'] = SaleChannels::getOptions(); - $data['statuses'] = Tariffs::getStatuses(); - $data['tariff_unities'] = TariffUnities::getOptions(); - - $model = new PriceListsDataTable(); - $data['datatables']['price_lists'] = $model->html(); + $data = Tariffs::init(); return view('Admin.Shop.Tariffs.create', $data); } public function show($id) { - $data['tariff'] = Tariffs::getFull($id); + $data['tariff'] = Tariffs::getArray($id); return view('Admin.Shop.Tariffs.view', $data); } public function edit($id) { + $data = Tariffs::init(); $data['tariff'] = Tariffs::get($id); - $data['sale_channels'] = SaleChannels::getOptions(); - $data['statuses'] = Tariffs::getStatuses(); - $data['tariff_unities'] = TariffUnities::getOptions(); - - $model = new PriceListsDataTable(); - $data['datatables']['price_lists'] = $model->html(); return view('Admin.Shop.Tariffs.edit', $data); } diff --git a/app/Http/Controllers/Shop/BasketController.php b/app/Http/Controllers/Shop/BasketController.php index b92ac1c1..292cb7ea 100644 --- a/app/Http/Controllers/Shop/BasketController.php +++ b/app/Http/Controllers/Shop/BasketController.php @@ -5,8 +5,7 @@ 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\Deliveries; -use App\Repositories\Shop\DeliveryTypes; +use App\Repositories\Shop\Customers; use App\Repositories\Shop\Offers; use App\Repositories\Shop\Orders; use App\Repositories\Users; @@ -67,7 +66,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); } diff --git a/app/Models/Shop/Customer.php b/app/Models/Shop/Customer.php index aebb8fa9..38f06221 100644 --- a/app/Models/Shop/Customer.php +++ b/app/Models/Shop/Customer.php @@ -69,4 +69,9 @@ class Customer extends Authenticatable { $this->notify(new ResetPassword($token)); } + + public function getNameAttribute() + { + return $this->getAttribute('first_name').' '.$this->getAttribute('last_name'); + } } diff --git a/app/Repositories/Shop/Baskets.php b/app/Repositories/Shop/Baskets.php index c9c2f8fe..9a7928c8 100644 --- a/app/Repositories/Shop/Baskets.php +++ b/app/Repositories/Shop/Baskets.php @@ -6,19 +6,19 @@ use App\Repositories\Core\User\ShopCart; class Baskets { - public static function addBasket($offer_id, $quantity = 1, $update = false) + public static function addBasket($offerId, $quantity = 1, $update = false) { - if (ShopCart::has($offer_id) && ! $quantity) { - $ret = ShopCart::remove($offer_id); + if (ShopCart::has($offerId) && ! $quantity) { + $ret = ShopCart::remove($offerId); } - $data = $quantity ? self::getBasketData($offer_id, $quantity) : false; + $data = $quantity ? self::getBasketData($offerId, $quantity) : false; return $data ? ShopCart::add($data, $update) : false; } public static function getBasketTotal($deliveryId = false, $deliveryTypeId = false) { - $saleChannelId = $deliveryId ? Deliveries::getField($deliveryId, 'sale_channel_id') : SaleChannels::getDefaultID(); + $saleChannelId = Deliveries::getSaleChannelId($deliveryId); return self::getBasketSummary($saleChannelId, $deliveryTypeId); } @@ -36,8 +36,8 @@ class Baskets $prices = Offers::getPrice($item->id, $item->quantity, $saleChannelId); $weight = $offer->weight * $item->quantity; $detail[] = self::getRowDetail($item, $offer, $prices, $weight); - $total += self::getTotal($item->quantity, $prices->price); - $totalTaxed += self::getTotal($item->quantity, $prices->price_taxed); + $total += $prices ? self::getTotal($item->quantity, $prices->price) : false; + $totalTaxed += $prices ? self::getTotal($item->quantity, $prices->price_taxed) : false; $totalWeight += $weight; } $shipping = DeliveryTypeCalculations::getPriceByDeliveryType($deliveryTypeId, $totalWeight); @@ -52,6 +52,7 @@ class Baskets 'count' => ShopCart::count(), 'quantity' => ShopCart::getTotalQuantity(), 'weight' => $totalWeight, + 'sale_channel' => SaleChannels::getArray($saleChannelId), ]; return $data ?? false; @@ -63,12 +64,12 @@ class Baskets 'offer_id' => (int) $item->id, 'name' => $offer->article->name.' ('.$offer->variation->name.')', 'quantity' => (int) $item->quantity, - 'price' => (float) $prices->price, - 'tax' => $prices->price_taxed - $prices->price, - 'price_taxed' => (float) $prices->price_taxed, - 'total' => self::getTotal($item->quantity, $prices->price), - 'total_tax' => self::getTotal($item->quantity, $prices->price_taxed - $prices->price), - 'total_taxed' => self::getTotal($item->quantity, $prices->price_taxed), + 'price' => $prices ? (float) $prices->price : false, + 'tax' => $prices ? $prices->price_taxed - $prices->price : false, + 'price_taxed' => $prices ? (float) $prices->price_taxed : false, + 'total' => $prices ? self::getTotal($item->quantity, $prices->price) : false, + 'total_tax' => $prices ? self::getTotal($item->quantity, $prices->price_taxed - $prices->price) : false, + 'total_taxed' => $prices ? self::getTotal($item->quantity, $prices->price_taxed) : false, 'weight' => $weight, ]; } @@ -110,6 +111,7 @@ class Baskets 'latin' => $offer->article->product->specie->latin ?? false, ]; } + $data['sale_channel'] = Customers::getSaleChannel(); return $data ?? false; } diff --git a/app/Repositories/Shop/Customers.php b/app/Repositories/Shop/Customers.php index 4c89988d..78017600 100644 --- a/app/Repositories/Shop/Customers.php +++ b/app/Repositories/Shop/Customers.php @@ -14,6 +14,18 @@ class Customers { use Basic; + public static function getSaleChannel() + { + return SaleChannels::getDefault(); + } + + public static function getDeliveries() + { + $customer = self::getAuth(); + + return $customer ? $customer->deliveries : Deliveries::getDefault(); + } + public static function getOptions() { return Customer::pluck('last_name', 'id'); @@ -23,13 +35,13 @@ class Customers { $id = $id ? $id : self::getId(); $datatableOrders = new CustomerOrdersDataTable(); - $data = [ + + return [ 'customer' => self::get($id, ['addresses', 'deliveries'])->toArray(), 'deliveries' => Deliveries::getAllWithSaleChannel()->toArray(), 'orders' => $datatableOrders->html(), ]; - return $data; } public static function getAvatar($id = false) @@ -48,7 +60,8 @@ class Customers $filename = self::makeAvatarFilename($customer); $name = $customer->first_name.' '.$customer->last_name; $avatar = new Avatar(); - $ret = $avatar->create($name) + + return $avatar->create($name) ->setBackground('#F2B90F') ->setForeground('#335012') ->setBorder(1, '#28a745') @@ -56,8 +69,6 @@ class Customers ->setDimension(36) ->setFontSize(16) ->save($filename); - - return $ret; } public static function makeAvatarFilename($customer) @@ -93,7 +104,7 @@ class Customers { $user = $id ? self::get($id) : self::getAuth(); - return $user ? $user->first_name.' '.$user->last_name : ''; + return $user ? $user->name : ''; } public static function getAuth() @@ -162,7 +173,7 @@ class Customers public static function create($data) { - $user = Customer::create([ + return Customer::create([ 'uuid' => Str::uuid(), 'active' => true, 'first_name' => $data['first_name'], @@ -177,8 +188,6 @@ class Customers 'email' => $data['email'], 'password' => bcrypt($data['password']), ]); - - return $user; } public static function getStorage($filename = false) diff --git a/app/Repositories/Shop/Deliveries.php b/app/Repositories/Shop/Deliveries.php index 5187edb1..77e1ff9c 100644 --- a/app/Repositories/Shop/Deliveries.php +++ b/app/Repositories/Shop/Deliveries.php @@ -9,6 +9,16 @@ class Deliveries { use Basic; + public static function getSaleChannelId($deliveryId) + { + return $deliveryId ? Deliveries::getField($deliveryId, 'sale_channel_id') : SaleChannels::getDefaultID(); + } + + public static function getDefault() + { + return Delivery::active()->atHouse()->first(); + } + public static function getOptions() { return Delivery::orderBy('name', 'asc')->pluck('name', 'id')->toArray(); diff --git a/app/Repositories/Shop/Homepages.php b/app/Repositories/Shop/Homepages.php index ef6c0861..768dd11e 100644 --- a/app/Repositories/Shop/Homepages.php +++ b/app/Repositories/Shop/Homepages.php @@ -3,9 +3,12 @@ namespace App\Repositories\Shop; use App\Models\Shop\Homepage; +use App\Traits\Model\Basic; class Homepages { + use Basic; + public static function getLast() { $model = Homepage::latest('id')->first(); @@ -28,34 +31,8 @@ class Homepages return self::get(3)->text ?? ''; } - public static function get($id) + public static function getModel() { - return Homepage::find($id); - } - - public static function store($data) - { - $item = ($data['id'] ?? false) ? self::update($data) : self::create($data); - - return $item->id; - } - - public static function create($data) - { - return Homepage::create($data); - } - - public static function update($data, $id = false) - { - $id = $id ? $id : $data['id']; - $item = self::get($id); - $item->update($data); - - return $item; - } - - public static function destroy($id) - { - return Homepage::destroy($id); + return Homepage::query(); } } diff --git a/app/Repositories/Shop/InvoicePayments.php b/app/Repositories/Shop/InvoicePayments.php index b9e7c703..9d1d9e61 100644 --- a/app/Repositories/Shop/InvoicePayments.php +++ b/app/Repositories/Shop/InvoicePayments.php @@ -28,6 +28,7 @@ class InvoicePayments 'CB', 'CHEQUE', 'VIREMENT', + 'PRELEVEMENT', ]; } diff --git a/app/Repositories/Shop/Offers.php b/app/Repositories/Shop/Offers.php index 12aa4f44..2cf7eb87 100644 --- a/app/Repositories/Shop/Offers.php +++ b/app/Repositories/Shop/Offers.php @@ -3,6 +3,7 @@ namespace App\Repositories\Shop; use App\Models\Shop\Offer; +use App\Models\Shop\PriceList; use App\Traits\Model\Basic; class Offers @@ -36,7 +37,7 @@ class Offers return Offer::with([ 'variation', 'article.article_nature', - 'article.product.Specie', + 'article.product', 'article.image', 'price_lists.price_list_values', ])->withPriceListsBySaleChannel($saleChannelId)->byIds($ids)->get(); @@ -67,8 +68,9 @@ class Offers { $saleChannelId = $saleChannelId ? $saleChannelId : SaleChannels::getDefaultID(); $offer = Offer::withPriceBySaleChannelByQuantity($saleChannelId, $quantity)->find($id); - - return $offer->price_lists->first()->price_list_values->first(); + $priceList = $offer->price_lists->first(); + + return $priceList ? $priceList->price_list_values->first() : false; } public static function getOffersByArticles($article_ids, $saleChannelId = false) diff --git a/app/Repositories/Shop/OrderDetails.php b/app/Repositories/Shop/OrderDetails.php index c1a3dd5c..ef4edc8d 100644 --- a/app/Repositories/Shop/OrderDetails.php +++ b/app/Repositories/Shop/OrderDetails.php @@ -3,9 +3,12 @@ namespace App\Repositories\Shop; use App\Models\Shop\OrderDetail; +use App\Traits\Model\Basic; class OrderDetails { + use Basic; + public static function saveBasket($order_id, $data) { foreach ($data as $item) { @@ -16,32 +19,8 @@ class OrderDetails return true; } - public static function get($id, $relations = false) + public static function getModel() { - return $relations ? OrderDetail::with($relations)->findOrFail($id) : OrderDetail::findOrFail($id); - } - - public static function store($data) - { - return ($data['id'] ?? false) ? self::update($data) : self::create($data); - } - - public static function create($data) - { - return OrderDetail::create($data); - } - - public static function update($data, $id = false) - { - $id = $id ? $id : $data['id']; - $item = self::get($id); - $item->update($data); - - return $item; - } - - public static function delete($id) - { - return OrderDetail::destroy($id); + return OrderDetail::query(); } } diff --git a/app/Repositories/Shop/Packages.php b/app/Repositories/Shop/Packages.php index 2a8932bf..2c493090 100644 --- a/app/Repositories/Shop/Packages.php +++ b/app/Repositories/Shop/Packages.php @@ -3,9 +3,12 @@ namespace App\Repositories\Shop; use App\Models\Shop\Package; +use App\Traits\Model\Basic; class Packages { + use Basic; + public static function getOptions() { return Package::orderBy('value', 'asc')->pluck('value', 'id')->toArray(); @@ -21,35 +24,8 @@ class Packages return self::get($id)->value; } - public static function get($id) + public static function getModel() { - return Package::find($id); - } - - public static function store($data) - { - $id = isset($data['id']) ? $data['id'] : false; - $item = $id ? self::update($data) : self::create($data); - - return $item->id; - } - - public static function create($data) - { - return Package::create($data); - } - - public static function update($data, $id = false) - { - $id = $id ? $id : $data['id']; - $item = self::get($id); - $item->update($data); - - return $item; - } - - public static function destroy($id) - { - return Package::destroy($id); + return Package::query(); } } diff --git a/app/Repositories/Shop/PriceListValues.php b/app/Repositories/Shop/PriceListValues.php index ce1bb056..67c16eda 100644 --- a/app/Repositories/Shop/PriceListValues.php +++ b/app/Repositories/Shop/PriceListValues.php @@ -4,9 +4,12 @@ namespace App\Repositories\Shop; use App\Models\Shop\Offer; use App\Models\Shop\PriceListValue; +use App\Traits\Model\Basic; class PriceListValues { + use Basic; + public static function getPriceByOffer($offer_id, $quantity = 1, $sale_channel_id = false) { $prices = self::getPricesByOffer($offer_id, $sale_channel_id); @@ -31,16 +34,6 @@ class PriceListValues return PriceListValue::byPriceList($id)->get(); } - public static function getAll() - { - return PriceListValue::orderBy('name', 'asc')->get(); - } - - public static function get($id) - { - return PriceListValue::find($id); - } - public static function storePrices($price_list_id, $values) { foreach ($values as $value) { @@ -51,30 +44,8 @@ class PriceListValues } } - public static function store($data) + public static function getModel() { - $id = isset($data['id']) ? $data['id'] : false; - $price = $id ? self::update($data) : self::create($data); - - return $price; - } - - public static function create($data) - { - return PriceListValue::create($data); - } - - public static function update($data, $id = false) - { - $id = $id ? $id : $data['id']; - $item = self::get($id); - $item->update($data); - - return $item; - } - - public static function destroy($id) - { - return PriceListValue::destroy($id); + return PriceListValue::query(); } } diff --git a/app/Repositories/Shop/PriceLists.php b/app/Repositories/Shop/PriceLists.php index e0aa0738..b67336b2 100644 --- a/app/Repositories/Shop/PriceLists.php +++ b/app/Repositories/Shop/PriceLists.php @@ -3,9 +3,25 @@ namespace App\Repositories\Shop; use App\Models\Shop\PriceList; +use App\Traits\Model\Basic; class PriceLists { + use Basic; + + public static function init($tariffId = false) + { + return [ + 'sale_channels' => SaleChannels::getOptions(), + 'statuses' => Tariffs::getStatuses(), + 'taxes' => Taxes::getOptions(), + 'price_list' => [ + 'tariff_id' => $tariffId, + 'price_list_values' => array_fill(0, 3, ''), + ], + ]; + } + public static function getByOfferAndSaleChannel($offer_id, $sale_channel_id) { return PriceList::bySaleChannel($sale_channel_id)->byOffer($offer_id)->get(); @@ -31,15 +47,6 @@ class PriceLists return PriceList::byTariff($id)->get(); } - public static function getOptions() - { - return PriceList::pluck('name', 'id')->toArray(); - } - - public static function getAll() - { - return PriceList::orderBy('name', 'asc')->get(); - } public static function edit($id) { @@ -52,11 +59,6 @@ class PriceLists return $price_list; } - public static function get($id) - { - return PriceList::find($id); - } - public static function getPrices($id) { return PriceList::with('price_list_values')->find($id); @@ -78,22 +80,8 @@ class PriceLists return $price_list; } - public static function create($data) + public static function getModel() { - return PriceList::create($data); - } - - public static function update($data, $id = false) - { - $id = $id ? $id : $data['id']; - $item = self::get($id); - $item->update($data); - - return $item; - } - - public static function destroy($id) - { - return PriceList::destroy($id); + return PriceList::query(); } } diff --git a/app/Repositories/Shop/SaleChannels.php b/app/Repositories/Shop/SaleChannels.php index 9ccb8fe7..1cd1aca8 100644 --- a/app/Repositories/Shop/SaleChannels.php +++ b/app/Repositories/Shop/SaleChannels.php @@ -3,9 +3,12 @@ namespace App\Repositories\Shop; use App\Models\Shop\SaleChannel; +use App\Traits\Model\Basic; class SaleChannels { + use Basic; + public static function getDefaultID() { $default = self::getDefault(); @@ -23,45 +26,8 @@ class SaleChannels return SaleChannel::byCode($code)->first(); } - public static function getOptions() + public static function getModel() { - return SaleChannel::orderBy('name', 'asc')->pluck('name', 'id')->toArray(); - } - - public static function getAll() - { - return SaleChannel::orderBy('name', 'asc')->get(); - } - - public static function get($id) - { - return SaleChannel::findOrFail($id); - } - - public static function store($data) - { - $id = isset($data['id']) ? $data['id'] : false; - $item = $id ? self::update($data) : self::create($data); - - return $item->id; - } - - public static function create($data) - { - return SaleChannel::create($data); - } - - public static function update($data, $id = false) - { - $id = $id ? $id : $data['id']; - $item = self::get($id); - $item->update($data); - - return $item; - } - - public static function destroy($id) - { - return SaleChannel::destroy($id); + return SaleChannel::query(); } } diff --git a/app/Repositories/Shop/Tariffs.php b/app/Repositories/Shop/Tariffs.php index f5a33e59..499f072c 100644 --- a/app/Repositories/Shop/Tariffs.php +++ b/app/Repositories/Shop/Tariffs.php @@ -2,10 +2,27 @@ namespace App\Repositories\Shop; +use App\Datatables\Admin\Shop\PriceListsDataTable; use App\Models\Shop\Tariff; +use App\Traits\Model\Basic; class Tariffs { + use Basic; + + public static function init() + { + $model = new PriceListsDataTable(); + + return [ + 'sale_channels' => SaleChannels::getOptions(), + 'statuses' => Tariffs::getStatuses(), + 'tariff_unities' => TariffUnities::getOptions(), + 'datatables' => [ + 'price_lists' => $model->html(), + ], + ]; + } public static function autocomplete($str) { $data = Tariff::byAutocomplete($str)->orderBy('name')->limit(30)->get()->pluck('name', 'id'); @@ -27,11 +44,6 @@ class Tariffs return Tariff::with(['price_lists.price_list_values', 'price_lists.sale_channel'])->find($id); } - public static function getOptions() - { - return Tariff::orderBy('name', 'asc')->get()->pluck('name', 'id')->toArray(); - } - public static function getStatus($status_id) { return self::getStatuses()[$status_id]; @@ -42,40 +54,8 @@ class Tariffs return ['Actif', 'Suspendu', 'Invisible', 'Obsolete']; } - public static function getAll() + public static function getModel() { - return Tariff::orderBy('name', 'asc')->get(); - } - - public static function get($id) - { - return Tariff::find($id); - } - - public static function store($data) - { - $id = isset($data['id']) ? $data['id'] : false; - $item = $id ? self::update($data, $id) : self::create($data); - - return $item->id; - } - - public static function create($data) - { - return Tariff::create($data); - } - - public static function update($data, $id = false) - { - $id = $id ? $id : $data['id']; - $item = self::get($id); - $item->update($data); - - return $item; - } - - public static function destroy($id) - { - return Tariff::destroy($id); + return Tariff::query(); } } diff --git a/resources/views/Admin/Shop/InvoicePayments/form.blade.php b/resources/views/Admin/Shop/InvoicePayments/form.blade.php index 2eb09e66..66034806 100644 --- a/resources/views/Admin/Shop/InvoicePayments/form.blade.php +++ b/resources/views/Admin/Shop/InvoicePayments/form.blade.php @@ -1,6 +1,6 @@