Fix on addresses

This commit is contained in:
ludo
2023-11-13 00:02:21 +01:00
parent 4ce3d528dd
commit 9f90f983ab
29 changed files with 660 additions and 447 deletions

View File

@@ -51,11 +51,11 @@ class CustomerOrdersDataTable extends DataTable
protected function getColumns()
{
return [
Column::make('status')->title('Statut'),
Column::make('ref')->title('Ref'),
Column::make('created_at')->title('Date'),
Column::make('ref')->title('Ref'),
Column::make('payment_type')->title('Règlement'),
Column::make('total_shipped')->title('Montant')->class('text-right'),
Column::make('status')->title('Statut'),
$this->makeColumnButtons(),
];
}

View File

@@ -47,19 +47,19 @@ class OrdersDataTable extends DataTable
public function getHtmlButtons()
{
return self::getButtonShow();
return '<button type="button" data-id="{{$uuid}}" class="btn btn-xs btn-secondary btn-show mr-2"><i class="fa fa-fw fa-eye"></i></button>';
}
protected function getColumns()
{
return [
Column::make('ref')->title('Ref'),
Column::make('status')->title('Statut'),
Column::make('created_at')->title('Date'),
Column::make('ref')->title('Ref'),
Column::make('customer.last_name')->title('Client'),
Column::make('delivery.name')->title('Point de distribution'),
Column::make('payment_type')->title('Règlement'),
Column::make('total_shipped')->title('Montant')->class('text-right'),
Column::make('status')->title('Statut'),
$this->makeColumnButtons(),
];
}

View File

@@ -16,7 +16,8 @@ class BasketController extends Controller
{
$offerId = $request->input('offer_id');
$quantity = $request->input('quantity') ?? 1;
$price = Offers::getPrice($offerId, $quantity)->price_taxed;
$offer = Offers::getPrice($offerId, $quantity);
$price = $offer ? $offer->price_taxed : 0;
return number_format($quantity * $price, 2);
}

View File

@@ -2,16 +2,19 @@
namespace App\Http\Controllers\Shop;
use App\Http\Controllers\Controller;
use App\Repositories\Shop\Customers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Repositories\Shop\Customers;
use Illuminate\Support\Facades\Auth;
class CustomerController extends Controller
{
public function profile($id = false)
{
return view('Shop.Customers.profile', Customers::editProfile($id));
$data = Customers::editProfile($id);
return view('Shop.Customers.profile', $data);
}
public function modalProfile($id = false)
@@ -23,15 +26,27 @@ class CustomerController extends Controller
public function edit()
{
return view('Shop.Customers.edit', [
'customer' => Customers::getArray(Auth::id(), 'addresses'),
]);
$id = Auth::id();
$data['customer'] = Customers::edit($id);
return view('Shop.Customers.edit', $data);
}
public function storeProfileAjax(Request $request)
{
$customer = Customers::store($request->all());
$data = $request->all();
$customer = Customers::store($data);
return response()->json(['error' => 0]);
}
public function store(Request $request)
{
$data = $request->all();
dump($data);
exit;
$customer = Customers::storeFull($data);
return response()->json(['error' => 0]);
}
}

View File

@@ -8,6 +8,7 @@ use App\Repositories\Core\User\ShopCart;
use App\Repositories\Shop\Baskets;
use App\Repositories\Shop\Customers;
use App\Repositories\Shop\Deliveries;
use App\Repositories\Shop\DeliveryTypes;
use App\Repositories\Shop\OrderMails;
use App\Repositories\Shop\Orders;
use App\Repositories\Shop\Paybox;
@@ -18,17 +19,19 @@ class OrderController extends Controller
{
public function index(OrdersDataTable $dataTable)
{
return $dataTable->render('Shop.Orders.partials.list', $data ?? []);
return $dataTable->render('Shop.Orders.partials.list');
}
public function view($uuid)
{
$data = Orders::getByUUID($uuid);
$data['order'] = Orders::view($uuid);
return view('Shop.Orders.view', $data);
}
public function pdf($uuid)
{
$data = Orders::getByUUID($uuid);
$data['order'] = Orders::getByUUID($uuid);
return view('Shop.Orders.pdf', $data);
}
@@ -43,6 +46,7 @@ class OrderController extends Controller
'basket' => ShopCart::getSummary(),
'deliveries' => Deliveries::getAllWithSaleChannel()->toArray(),
'sale_channel' => SaleChannels::getDefault()->toArray(),
'delivery_types' => DeliveryTypes::getAll(),
];
return view('Shop.Orders.order', $data);

View File

@@ -0,0 +1,23 @@
<?php
namespace App\Http\Requests\Admin\Shop;
use Illuminate\Foundation\Http\FormRequest;
class StoreArticlePost extends FormRequest
{
public function authorize()
{
return true;
}
public function rules()
{
return [
'ref' => 'required|unique:articles,ref,'.$this->ref,
'product_type' => 'required',
'product_id' => 'required',
'article_nature_id' => 'required',
];
}
}

View File

@@ -4,8 +4,6 @@ namespace App\Models\Shop;
use App\Notifications\ResetPassword;
use App\Notifications\VerifyEmail;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
@@ -23,37 +21,39 @@ class Customer extends Authenticatable
protected $casts = ['email_verified_at' => 'datetime'];
public function addresses(): HasMany
public function delivery_addresses()
{
return $this->addresses()->byDelivery();
}
public function invoice_addresses()
{
return $this->addresses()->byInvoicing();
}
public function addresses()
{
return $this->hasMany(CustomerAddress::class);
}
public function invoicing_addresses(): HasMany
{
return $this->addresses()->where('type', 2);
}
public function delivery_addresses(): HasMany
{
return $this->addresses()->where('type', 1);
}
public function customer_deliveries(): HasMany
public function customer_deliveries()
{
return $this->hasMany(CustomerDelivery::class);
}
public function deliveries(): BelongsToMany
public function deliveries()
{
return $this->belongsToMany(Delivery::class, CustomerDelivery::class);
}
public function invoices(): HasMany
public function invoices()
{
return $this->hasMany(Invoice::class);
}
public function orders(): HasMany
public function orders()
{
return $this->hasMany(Order::class);
}

View File

@@ -17,16 +17,17 @@ class Baskets
return $data ? ShopCart::add($data, $update) : false;
}
public static function getBasketSummary($sale_channel_id = false)
public static function getBasketSummary($saleChannelId = false)
{
$basket = ShopCart::getContent();
$offers = Offer::with('variation')->whereIn('id', ShopCart::keys())->get();
$total = 0;
$total_taxed = 0;
$totalTaxed = 0;
$shipping = 5;
foreach ($basket as $item) {
$offer = $offers->where('id', $item->id)->first();
$prices = Offers::getPrice($item->id, $item->quantity, $sale_channel_id);
$prices = Offers::getPrice($item->id, $item->quantity, $saleChannelId);
$weight = $offer->weight * $item->quantity;
$detail[] = [
'offer_id' => (int) $item->id,
'name' => $offer->article->name.' ('.$offer->variation->name.')',
@@ -37,17 +38,18 @@ class Baskets
'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),
'weight' => $weight,
];
$total += self::getTotal($item->quantity, $prices->price);
$total_taxed += self::getTotal($item->quantity, $prices->price_taxed);
$totalTaxed += self::getTotal($item->quantity, $prices->price_taxed);
}
$data = [
'detail' => $detail,
'total' => $total,
'taxes' => $total_taxed - $total,
'total_taxed' => $total_taxed,
'taxes' => $totalTaxed - $total,
'total_taxed' => $totalTaxed,
'shipping' => $shipping,
'total_shipped' => $total_taxed + $shipping,
'total_shipped' => $totalTaxed + $shipping,
];
return $data ?? false;
@@ -58,9 +60,9 @@ class Baskets
return $quantity * $price;
}
public static function getBasket($sale_channel_id = false)
public static function getBasket($saleChannelId = false)
{
$sale_channel_id = $sale_channel_id ? $sale_channel_id : SaleChannels::getDefaultID();
$saleChannelId = $saleChannelId ? $saleChannelId : SaleChannels::getDefaultID();
$basket = ShopCart::getContent();
// dump($basket->toArray());
$offers = Offer::with([
@@ -69,7 +71,7 @@ class Baskets
'article.product.Specie',
'article.image',
'price_lists.price_list_values',
])->withPriceListsBySaleChannel($sale_channel_id)
])->withPriceListsBySaleChannel($saleChannelId)
->whereIn('id', ShopCart::keys())->get();
foreach ($basket as $item) {
$offer = $offers->where('id', $item->id)->first();

View File

@@ -84,7 +84,9 @@ class Customers
public static function getWithAddresses($id = false)
{
return self::get($id, ['invoicing_addresses', 'delivery_addresses']);
$id = $id ? $id : self::getId();
return self::get($id, ['invoice_addresses', 'delivery_addresses']);
}
public static function getName($id = false)
@@ -99,18 +101,16 @@ class Customers
return self::guard()->user();
}
public static function get($id, $relations = false, $relationsCount = false)
{
$id = $id ? $id : self::getId();
return self::getModelRelations($relations, $relationsCount)->find($id);
}
public static function getId()
{
return self::guard()->id();
}
public static function isNotConnected()
{
return ! self::isConnected();
}
public static function isConnected()
{
return self::guard()->check();
@@ -118,7 +118,7 @@ class Customers
public static function edit($id)
{
$customer = self::get($id, 'addresses');
$customer = self::get($id, ['delivery_addresses', 'invoice_addresses']);
$data = $customer->toArray();
$data['deliveries'] = $customer->deliveries->pluck('id')->toArray();
@@ -128,12 +128,12 @@ class Customers
public static function storeFull($data)
{
$deliveries = $data['deliveries'];
$addresses = $data['addresses'];
$invoices = $data['invoices'];
unset($data['deliveries']);
unset($data['addresses']);
unset($data['invoices']);
$customer = self::store($data);
self::storeDeliveries($customer, $deliveries);
self::storeAddresses($customer, $addresses);
self::storeAddresses($customer, $deliveries);
self::storeAddresses($customer, $invoices);
return $customer->id;
}

View File

@@ -11,17 +11,24 @@ class Offers
return Offer::count();
}
public static function getFull($id, $sale_channel_id = false)
public static function getWeight($id, $quantity = 1)
{
$sale_channel_id = $sale_channel_id ? $sale_channel_id : SaleChannels::getDefaultID();
$offer = self::get($id);
return $offer ? $offer->weight * $quantity : 0;
}
public static function getFull($id, $saleChannelId = false)
{
$saleChannelId = $saleChannelId ? $saleChannelId : SaleChannels::getDefaultID();
$offer = Offer::with([
'article.article_nature',
'article.product',
'tariff' => function ($query) use ($sale_channel_id) {
$query->bySaleChannel($sale_channel_id);
'tariff' => function ($query) use ($saleChannelId) {
$query->bySaleChannel($saleChannelId);
},
'tariff.price_lists' => function ($query) use ($sale_channel_id) {
$query->BySaleChannel($sale_channel_id);
'tariff.price_lists' => function ($query) use ($saleChannelId) {
$query->BySaleChannel($saleChannelId);
},
'tariff.price_lists.price_list_values',
'variation',
@@ -32,43 +39,43 @@ class Offers
return $offer;
}
public static function getPrice($id, $quantity = 1, $sale_channel_id = false)
public static function getPrice($id, $quantity = 1, $saleChannelId = false)
{
$sale_channel_id = $sale_channel_id ? $sale_channel_id : SaleChannels::getDefaultID();
$offer = Offer::withPriceBySaleChannelByQuantity($sale_channel_id, $quantity)->find($id);
$saleChannelId = $saleChannelId ? $saleChannelId : SaleChannels::getDefaultID();
$offer = Offer::withPriceBySaleChannelByQuantity($saleChannelId, $quantity)->find($id);
return $offer->price_lists->first()->price_list_values->first();
}
public static function getOffersByArticles($article_ids, $sale_channel_id = false)
public static function getOffersByArticles($article_ids, $saleChannelId = false)
{
return self::getOffersBySaleChannelRaw($sale_channel_id)->byArticles($article_ids)->get();
return self::getOffersBySaleChannelRaw($saleChannelId)->byArticles($article_ids)->get();
}
public static function getOffersByArticle($article_id, $sale_channel_id = false)
public static function getOffersByArticle($article_id, $saleChannelId = false)
{
return self::getOffersBySaleChannelRaw($sale_channel_id)->byArticle($article_id)->get();
return self::getOffersBySaleChannelRaw($saleChannelId)->byArticle($article_id)->get();
}
public static function getOffersBySaleChannel($sale_channel_id = false)
public static function getOffersBySaleChannel($saleChannelId = false)
{
return self::getOffersBySaleChannelRaw($sale_channel_id)->get();
return self::getOffersBySaleChannelRaw($saleChannelId)->get();
}
public static function getOffersBySaleChannelRaw($sale_channel_id = false)
public static function getOffersBySaleChannelRaw($saleChannelId = false)
{
$sale_channel_id = $sale_channel_id ? $sale_channel_id : SaleChannels::getDefaultID();
$saleChannelId = $saleChannelId ? $saleChannelId : SaleChannels::getDefaultID();
return Offer::active()->byStockAvailable()
->with([
'article_nature',
'variation',
'tariff.price_lists' => function ($query) use ($sale_channel_id) {
$query->bySaleChannel($sale_channel_id);
'tariff.price_lists' => function ($query) use ($saleChannelId) {
$query->bySaleChannel($saleChannelId);
},
'tariff.price_lists.price_list_values',
])
->bySaleChannel($sale_channel_id);
->bySaleChannel($saleChannelId);
}
public static function getThumbSrcById($id)

View File

@@ -16,6 +16,22 @@ class Orders
return Order::byUUID($uuid)->first();
}
public static function getFullByUUID($uuid)
{
return Order::with(['customer', 'delivery', 'delivery_address', 'detail', 'invoice.address', 'sale_channel'])
->byUUID($uuid)->first();
}
public static function view($uuid)
{
$data = [];
$order = self::getFullByUUID($uuid);
$data = $order->toArray();
$data['payment_type'] = InvoicePayments::getPaymentType($order->payment_type);
$data['status'] = Orders::getStatus($order->status);
return $data;
}
public static function saveOrder($data)
{
$data += $data['basket'];