[WIP] Working on orders & invoices
This commit is contained in:
@@ -3,8 +3,11 @@
|
||||
namespace App\Datatables\Shop;
|
||||
|
||||
use Yajra\DataTables\Html\Column;
|
||||
|
||||
use App\Datatables\ParentDataTable as DataTable;
|
||||
use App\Models\Shop\Order;
|
||||
use App\Repositories\Shop\InvoicePayments;
|
||||
use App\Repositories\Shop\Orders;
|
||||
|
||||
class OrdersDataTable extends DataTable
|
||||
{
|
||||
@@ -12,13 +15,38 @@ class OrdersDataTable extends DataTable
|
||||
|
||||
public function query(Order $model)
|
||||
{
|
||||
$model = $model->with(['customer', 'delivery']);
|
||||
return $this->buildQuery($model);
|
||||
}
|
||||
|
||||
public function modifier($datatables)
|
||||
{
|
||||
$datatables
|
||||
->editColumn('status', function (Order $order) {
|
||||
return Orders::getStatus($order->status);
|
||||
})
|
||||
->editColumn('created_at', function (Order $order) {
|
||||
return $order->created_at->toDateTimeString();
|
||||
})
|
||||
->editColumn('customer.last_name', function (Order $order) {
|
||||
return $order->customer->last_name . ' ' . $order->customer->first_name;
|
||||
})
|
||||
->editColumn('payment_type', function (Order $order) {
|
||||
return InvoicePayments::getPaymentType($order->payment_type);
|
||||
})
|
||||
->rawColumns(['action']);
|
||||
return parent::modifier($datatables);
|
||||
}
|
||||
|
||||
protected function getColumns()
|
||||
{
|
||||
return [
|
||||
Column::make('name'),
|
||||
Column::make('status')->title('Statut'),
|
||||
Column::make('created_at')->title('Date'),
|
||||
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'),
|
||||
$this->makeColumnButtons(),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -34,11 +34,13 @@ class OrderController extends Controller
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$data['customer'] = Orders::get($id)->toArray();
|
||||
$data['order'] = Orders::get($id, ['customer', 'detail'])->toArray();
|
||||
dump($data['order']);
|
||||
exit;
|
||||
return view('Admin.Shop.Orders.edit', $data);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
public function delete($id)
|
||||
{
|
||||
return Orders::destroy($id);
|
||||
}
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\Shop;
|
||||
|
||||
use App\OrderPayment;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class OrderPaymentController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\OrderPayment $orderPayment
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(OrderPayment $orderPayment)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\OrderPayment $orderPayment
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(OrderPayment $orderPayment)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\OrderPayment $orderPayment
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, OrderPayment $orderPayment)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\OrderPayment $orderPayment
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(OrderPayment $orderPayment)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,11 @@
|
||||
namespace App\Http\Controllers\Shop;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Repositories\Core\User\ShopCart;
|
||||
use App\Repositories\Shop\Offers;
|
||||
use App\Repositories\Shop\Baskets;
|
||||
use App\Repositories\Shop\Orders;
|
||||
use App\Repositories\Users;
|
||||
|
||||
@@ -25,19 +26,19 @@ class BasketController extends Controller
|
||||
$offer_id = $request->input('offer_id');
|
||||
$quantity = $request->input('quantity') ?? 1;
|
||||
$update = $request->input('update') ?? false;
|
||||
return Offers::addBasket($offer_id, $quantity, $update);
|
||||
return Baskets::addBasket($offer_id, $quantity, $update);
|
||||
}
|
||||
|
||||
public function modalBasket($offer_id, $quantity)
|
||||
{
|
||||
$data['offer'] = Offers::getFull($offer_id)->toArray();
|
||||
$data['basket'] = Offers::addBasket($offer_id, $quantity);
|
||||
$data['basket'] = Baskets::addBasket($offer_id, $quantity);
|
||||
return view('Shop.Baskets.partials.modalBasket', $data);
|
||||
}
|
||||
|
||||
public function basket()
|
||||
{
|
||||
$data['basket'] = Offers::getBasket();
|
||||
$data['basket'] = Baskets::getBasket();
|
||||
return view('Shop.Baskets.basket', $data);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,28 +9,8 @@ use App\Repositories\Shop\Customers;
|
||||
|
||||
class CustomerController extends Controller
|
||||
{
|
||||
public function show($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function edit(C$id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function update(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function profile($id = false)
|
||||
{
|
||||
return view('Shop.Profile.profile');
|
||||
return view('Shop.Customers.profile');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,17 +9,20 @@ use App\Repositories\Core\User\ShopCart;
|
||||
use App\Repositories\Shop\Customers;
|
||||
use App\Repositories\Shop\Deliveries;
|
||||
use App\Repositories\Shop\Orders;
|
||||
use App\Repositories\Shop\Offers;
|
||||
use App\Repositories\Shop\Baskets;
|
||||
use App\Repositories\Shop\SaleChannels;
|
||||
|
||||
class OrderController extends Controller
|
||||
{
|
||||
public function order()
|
||||
{
|
||||
$data['customer'] = Customers::getWithAddresses()->toArray();
|
||||
$data['basket'] = ShopCart::getSummary();
|
||||
$data['deliveries'] = Deliveries::getAllWithSaleChannel()->toArray();
|
||||
$data['sale_channel'] = SaleChannels::getDefault()->toArray();
|
||||
$customer = Customers::getWithAddresses();
|
||||
$data = [
|
||||
'customer' => $customer ? $customer->toArray() : false,
|
||||
'basket' => ShopCart::getSummary(),
|
||||
'deliveries' => Deliveries::getAllWithSaleChannel()->toArray(),
|
||||
'sale_channel' => SaleChannels::getDefault()->toArray(),
|
||||
];
|
||||
return view('Shop.Orders.order', $data);
|
||||
}
|
||||
|
||||
@@ -27,18 +30,23 @@ class OrderController extends Controller
|
||||
{
|
||||
$data = $request->all();
|
||||
$data['customer_id'] = Customers::getId();
|
||||
$data['basket'] = ShopCart::getSummary();
|
||||
$data['basket'] = Baskets::getBasketSummary();
|
||||
dump($data);
|
||||
exit;
|
||||
$order = Orders::saveOrder($data);
|
||||
if ($order) {
|
||||
if (intval($data['payment']) === 1) {
|
||||
return redirect('Shop.Payments.online');
|
||||
if ($data['payment'] == '1') {
|
||||
return redirect()->route('Shop.Payments.online');
|
||||
} else {
|
||||
return redirect('Shop.Orders.confirmed');
|
||||
return redirect()->route('Shop.Orders.confirmed');
|
||||
}
|
||||
} else {
|
||||
return view('Shop.Orders.order');
|
||||
}
|
||||
}
|
||||
|
||||
public function confirmed()
|
||||
{
|
||||
return view('Shop.Orders.confirmed');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
class Invoice extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'shop_invoices';
|
||||
|
||||
public function InvoiceItems()
|
||||
{
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class InvoiceItem extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public function Product()
|
||||
{
|
||||
return $this->belongsTo(Product::class);
|
||||
}
|
||||
|
||||
public function Invoice()
|
||||
{
|
||||
return $this->belongsTo(Invoice::class);
|
||||
}
|
||||
}
|
||||
21
app/Models/Shop/InvoicePayment.php
Normal file
21
app/Models/Shop/InvoicePayment.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class InvoicePayment extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'shop_invoice_payments';
|
||||
|
||||
public function invoice()
|
||||
{
|
||||
return $this->belongsTo(Invoice::class);
|
||||
}
|
||||
|
||||
public function scopeByInvoice($query, $invoice_id)
|
||||
{
|
||||
return $query->where('invoice_id', $invoice_id);
|
||||
}
|
||||
}
|
||||
@@ -7,14 +7,55 @@ use Illuminate\Database\Eloquent\Model;
|
||||
class Order extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'shop_orders';
|
||||
|
||||
public function customer()
|
||||
{
|
||||
return $this->belongsTo(Customer::class);
|
||||
}
|
||||
|
||||
public function payments()
|
||||
public function address()
|
||||
{
|
||||
return $this->hasMany(OrderPayment::class);
|
||||
return $this->belongsTo(CustomerAddress::class, 'customer_address_id');
|
||||
}
|
||||
|
||||
public function delivery()
|
||||
{
|
||||
return $this->belongsTo(Delivery::class);
|
||||
}
|
||||
|
||||
public function detail()
|
||||
{
|
||||
return $this->hasMany(OrderDetail::class);
|
||||
}
|
||||
|
||||
public function invoice()
|
||||
{
|
||||
return $this->hasOne(Invoice::class);
|
||||
}
|
||||
|
||||
public function sale_channel()
|
||||
{
|
||||
return $this->belongsTo(SaleChannel::class);
|
||||
}
|
||||
|
||||
public function scopeByCustomer($query, $customer_id)
|
||||
{
|
||||
return $query->where('customer_id', $customer_id);
|
||||
}
|
||||
|
||||
public function scopeByDelivery($query, $delivery_id)
|
||||
{
|
||||
return $query->where('delivery_id', $delivery_id);
|
||||
}
|
||||
|
||||
public function scopeByStatus($query, $status)
|
||||
{
|
||||
return $query->where('status', $status);
|
||||
}
|
||||
|
||||
public function scopeByPaymentType($query, $payment_type)
|
||||
{
|
||||
return $query->where('payment_type', $payment_type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,25 @@ use Illuminate\Database\Eloquent\Model;
|
||||
class OrderDetail extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'shop_order_details';
|
||||
|
||||
public function order()
|
||||
{
|
||||
return $this->belongsTo(Order::class);
|
||||
}
|
||||
|
||||
public function offer()
|
||||
{
|
||||
return $this->belongsTo(Offer::class);
|
||||
}
|
||||
|
||||
public function scopeByOrder($query, $order_id)
|
||||
{
|
||||
return $query->where('order_id', $order_id);
|
||||
}
|
||||
|
||||
public function scopeByOffer($query, $offer_id)
|
||||
{
|
||||
return $query->where('offer_id', $offer_id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class OrderPayment extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public function order()
|
||||
{
|
||||
return $this->belongsTo(Order::class);
|
||||
}
|
||||
}
|
||||
100
app/Repositories/Shop/Baskets.php
Normal file
100
app/Repositories/Shop/Baskets.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Offer;
|
||||
use App\Repositories\Core\User\ShopCart;
|
||||
|
||||
class Baskets
|
||||
{
|
||||
public static function addBasket($offer_id, $quantity = 1, $update = false)
|
||||
{
|
||||
if (ShopCart::has($offer_id) && !$quantity) {
|
||||
$ret = ShopCart::remove($offer_id);
|
||||
}
|
||||
$data = $quantity ? self::getBasketData($offer_id, $quantity) : false;
|
||||
return $data ? ShopCart::add($data, $update) : false;
|
||||
}
|
||||
|
||||
public static function getBasketSummary()
|
||||
{
|
||||
$basket = ShopCart::getContent();
|
||||
$offers = Offer::with('variation')->whereIn('id', ShopCart::keys())->get();
|
||||
$total = 0;
|
||||
$total_taxed = 0;
|
||||
foreach ($basket as $item) {
|
||||
$offer = $offers->where('id', $item->id)->first();
|
||||
$detail[] = [
|
||||
'id' => (int) $item->id,
|
||||
'name' => $offer->article->name . ' (' . $offer->variation->name . ')',
|
||||
'quantity' => (int) $item->quantity,
|
||||
'price' => $item->price,
|
||||
'tax' => '',
|
||||
'price_taxed' => $item->price,
|
||||
'total' => self::getTotal($item->quantity, $item->price),
|
||||
'total_taxed' => self::getTotal($item->quantity, $item->price),
|
||||
];
|
||||
$total += self::getTotal($item->quantity, $item->price);
|
||||
$total_taxed += self::getTotal($item->quantity, $item->price);
|
||||
}
|
||||
$data = [
|
||||
'detail' => $detail,
|
||||
'total' => $total,
|
||||
'taxes' => $total_taxed - $total,
|
||||
'total_taxed' => $total_taxed,
|
||||
];
|
||||
return $data ?? false;
|
||||
}
|
||||
|
||||
public static function getTotal($quantity, $price)
|
||||
{
|
||||
return (int) $quantity * $price;
|
||||
}
|
||||
|
||||
public static function getBasket($sale_channel_id = false)
|
||||
{
|
||||
$sale_channel_id = $sale_channel_id ? $sale_channel_id : SaleChannels::getDefaultID();
|
||||
$basket = ShopCart::getContent();
|
||||
// dump($basket->toArray());
|
||||
$offers = Offer::with([
|
||||
'variation',
|
||||
'article.article_nature',
|
||||
'article.product.Specie',
|
||||
'article.image',
|
||||
'price_lists.price_list_values',
|
||||
])->withPriceListsBySaleChannel($sale_channel_id)
|
||||
->whereIn('id', ShopCart::keys())->get();
|
||||
foreach ($basket as $item) {
|
||||
$offer = $offers->where('id', $item->id)->first();
|
||||
$article_nature = strtolower($offer->article->article_nature->name);
|
||||
$data[$article_nature][] = [
|
||||
'id' => (int) $item->id,
|
||||
'name' => $item->name,
|
||||
'quantity' => (int) $item->quantity,
|
||||
'price' => $item->price,
|
||||
'variation' => $offer->variation->name,
|
||||
'image' => Articles::getPreviewSrc(Articles::getFullImageByArticle($offer->article)),
|
||||
'latin' => $offer->article->product->specie->latin ?? false,
|
||||
];
|
||||
}
|
||||
return $data ?? false;
|
||||
}
|
||||
|
||||
public static function getBasketData($id, $quantity = 1)
|
||||
{
|
||||
$offer = Offers::get($id, ['article', 'variation']);
|
||||
return [
|
||||
'id' => $id,
|
||||
'name' => self::getArticleName($offer),
|
||||
'price' => Offers::getPrice($id, $quantity)->price_taxed,
|
||||
'quantity' => $quantity,
|
||||
'attributes' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public static function getArticleName(&$offer)
|
||||
{
|
||||
return $offer->article->name;
|
||||
// return $offer->article->name . ' (' . $offer->variation->name . ')';
|
||||
}
|
||||
}
|
||||
12
app/Repositories/Shop/CustomerStats.php
Normal file
12
app/Repositories/Shop/CustomerStats.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use Spatie\Stats\BaseStats;
|
||||
|
||||
class CustomerStats extends BaseStats {}
|
||||
{
|
||||
public function getName() : string{
|
||||
return 'customers';
|
||||
}
|
||||
}
|
||||
54
app/Repositories/Shop/InvoicePayments.php
Normal file
54
app/Repositories/Shop/InvoicePayments.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use App\Models\Shop\InvoicePayment;
|
||||
|
||||
class InvoicePayments
|
||||
{
|
||||
|
||||
public static function get($id, $relations = false)
|
||||
{
|
||||
return $relations ? InvoicePayment::with($relations)->findOrFail($id) : InvoicePayment::findOrFail($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
return ($data['id'] ?? false) ? self::update($data) : self::create($data);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return InvoicePayment::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 InvoicePayment::destroy($id);
|
||||
}
|
||||
|
||||
public static function getPaymentType($id)
|
||||
{
|
||||
return self::PaymentTypes()[$id] ?? false;
|
||||
}
|
||||
|
||||
public static function PaymentTypes()
|
||||
{
|
||||
return [
|
||||
'',
|
||||
'CB',
|
||||
'CHEQUE',
|
||||
'VIREMENT',
|
||||
];
|
||||
}
|
||||
}
|
||||
12
app/Repositories/Shop/InvoiceStats.php
Normal file
12
app/Repositories/Shop/InvoiceStats.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use Spatie\Stats\BaseStats;
|
||||
|
||||
class InvoiceStats extends BaseStats {}
|
||||
{
|
||||
public function getName() : string{
|
||||
return 'invoices';
|
||||
}
|
||||
}
|
||||
@@ -2,50 +2,55 @@
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use App\Models\Shop\Invoice;
|
||||
|
||||
class Invoices
|
||||
{
|
||||
public static function getOptions()
|
||||
|
||||
public static function saveInvoice($order_id, $data)
|
||||
{
|
||||
return Invoice::orderBy('value', 'asc')->get()->pluck('value', 'id')->toArray();
|
||||
$data['order_id'] = $order_id;
|
||||
dump($data);
|
||||
exit;
|
||||
return self::store($data);
|
||||
}
|
||||
|
||||
public static function getOptionsByPackage($package_id)
|
||||
public static function get($id, $relations = false)
|
||||
{
|
||||
return Invoice::byPackage($package_id)->orderBy('value', 'asc')->get()->pluck('value', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Invoice::orderBy('value', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Invoice::find($id);
|
||||
return $relations ? Invoice::with($relations)->findOrFail($id) : Invoice::findOrFail($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;
|
||||
return ($data['id'] ?? false) ? self::update($data) : self::create($data);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
$data['uuid'] = Str::uuid()->toString();
|
||||
$data['ref'] = self::getNewRef();
|
||||
return Invoice::create($data);
|
||||
}
|
||||
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
return self::get($id)->update($data);
|
||||
$id = $id ? $id : $data['id'];
|
||||
$item = self::get($id);
|
||||
$item->update($data);
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
public static function delete($id)
|
||||
{
|
||||
return Invoice::destroy($id);
|
||||
}
|
||||
|
||||
public static function getNewRef()
|
||||
{
|
||||
$ref = date('ym') . '00000';
|
||||
$last_ref = Invoice::orderBy('ref', 'desc')->where('ref', '>', $ref)->first();
|
||||
return $last_ref ? $last_ref + 1 : $ref + 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,15 +7,6 @@ use App\Repositories\Core\User\ShopCart;
|
||||
|
||||
class Offers
|
||||
{
|
||||
public static function addBasket($offer_id, $quantity = 1, $update = false)
|
||||
{
|
||||
if (ShopCart::has($offer_id) && !$quantity) {
|
||||
$ret = ShopCart::remove($offer_id);
|
||||
}
|
||||
$data = $quantity ? Offers::getBasketData($offer_id, $quantity) : false;
|
||||
return $data ? ShopCart::add($data, $update) : false;
|
||||
}
|
||||
|
||||
public static function getFull($id, $sale_channel_id = false)
|
||||
{
|
||||
$sale_channel_id = $sale_channel_id ? $sale_channel_id : SaleChannels::getDefaultID();
|
||||
@@ -43,47 +34,6 @@ class Offers
|
||||
return $offer->price_lists->first()->price_list_values->first();
|
||||
}
|
||||
|
||||
public static function getBasket($sale_channel_id = false)
|
||||
{
|
||||
$sale_channel_id = $sale_channel_id ? $sale_channel_id : SaleChannels::getDefaultID();
|
||||
$basket = ShopCart::getContent();
|
||||
// dump($basket->toArray());
|
||||
$offers = Offer::with([
|
||||
'variation',
|
||||
'article.article_nature',
|
||||
'article.product.Specie',
|
||||
'article.image',
|
||||
'price_lists.price_list_values',
|
||||
])->withPriceListsBySaleChannel($sale_channel_id)
|
||||
->whereIn('id', ShopCart::keys())->get();
|
||||
foreach ($basket as $item) {
|
||||
$offer = $offers->where('id', $item->id)->first();
|
||||
$article_nature = strtolower($offer->article->article_nature->name);
|
||||
$data[$article_nature][] = [
|
||||
'id' => (int) $item->id,
|
||||
'name' => $item->name,
|
||||
'quantity' => (int) $item->quantity,
|
||||
'price' => $item->price,
|
||||
'variation' => $offer->variation->name,
|
||||
'image' => Articles::getPreviewSrc(Articles::getFullImageByArticle($offer->article)),
|
||||
'latin' => $offer->article->product->specie->latin ?? false,
|
||||
];
|
||||
}
|
||||
return $data ?? false;
|
||||
}
|
||||
|
||||
public static function getBasketData($id, $quantity = 1)
|
||||
{
|
||||
$offer = Offer::with(['article'])->findOrFail($id);
|
||||
return [
|
||||
'id' => $id,
|
||||
'name' => $offer->article->name,
|
||||
'price' => self::getPrice($id, $quantity)->price_taxed,
|
||||
'quantity' => $quantity,
|
||||
'attributes' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public static function getOffersByArticles($article_ids, $sale_channel_id = false)
|
||||
{
|
||||
return self::getOffersBySaleChannelRaw($sale_channel_id)->byArticles($article_ids)->get();
|
||||
@@ -155,16 +105,14 @@ class Offers
|
||||
return Offer::get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
public static function get($id, $relations = false)
|
||||
{
|
||||
return Offer::findOrFail($id);
|
||||
return $relations ? Offer::with($relations)->findOrFail($id) : Offer::findOrFail($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;
|
||||
return ($data['id'] ?? false) ? self::update($data) : self::create($data);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
|
||||
@@ -6,12 +6,15 @@ use App\Models\Shop\OrderDetail;
|
||||
|
||||
class OrderDetails
|
||||
{
|
||||
|
||||
public static function saveBasket($order_id, $data)
|
||||
{
|
||||
foreach ($data as $item) {
|
||||
$item['order_id'] = $order_id;
|
||||
$detail = self::store($item);
|
||||
$detail = self::store([
|
||||
'order_id' => $order_id,
|
||||
'offer_id' => $item['id'],
|
||||
'quantity' => $item['quantity'],
|
||||
'price_taxed' => $item['price'],
|
||||
]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,10 @@ class Orders
|
||||
{
|
||||
$basket = $data['basket'];
|
||||
unset($data['basket']);
|
||||
dump($data);
|
||||
exit;
|
||||
$order = self::store($data);
|
||||
$invoice = Invoices::saveInvoice($order->id, $data);
|
||||
return $order ? OrderDetails::saveBasket($order->id, $basket) : false;
|
||||
}
|
||||
|
||||
@@ -42,4 +45,18 @@ class Orders
|
||||
{
|
||||
return Order::destroy($id);
|
||||
}
|
||||
|
||||
public static function getStatus($id)
|
||||
{
|
||||
return self::statuses()[$id] ?? false;
|
||||
}
|
||||
|
||||
public static function statuses()
|
||||
{
|
||||
return [
|
||||
'En attente',
|
||||
'Expédié',
|
||||
'Livré',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ class CreateMediaTable extends Migration
|
||||
$table->json('custom_properties');
|
||||
$table->json('generated_conversions');
|
||||
$table->json('responsive_images');
|
||||
$table->unsignedInteger('order_column')->nullable();
|
||||
$table->unsignedInteger('order_column')->nullable()->index();
|
||||
|
||||
$table->nullableTimestamps();
|
||||
});
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
Schema::table('categories', function (Blueprint $table) {
|
||||
$table->tinyInteger('visible')->nullable()->after('id');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateMediaTable extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
Schema::create('media', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
|
||||
$table->morphs('model');
|
||||
$table->uuid('uuid')->nullable()->unique();
|
||||
$table->string('collection_name');
|
||||
$table->string('name');
|
||||
$table->string('file_name');
|
||||
$table->string('mime_type')->nullable();
|
||||
$table->string('disk');
|
||||
$table->string('conversions_disk')->nullable();
|
||||
$table->unsignedBigInteger('size');
|
||||
$table->json('manipulations');
|
||||
$table->json('custom_properties');
|
||||
$table->json('generated_conversions');
|
||||
$table->json('responsive_images');
|
||||
$table->unsignedInteger('order_column')->nullable()->index();
|
||||
|
||||
$table->nullableTimestamps();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,29 +1,51 @@
|
||||
@extends('layout.index', [
|
||||
'title' => 'Famille d\'articles',
|
||||
'subtitle' => 'Edition d\'une famille d\'article',
|
||||
'breadcrumb' => ['Articles']
|
||||
'title' => 'Commandes',
|
||||
'subtitle' => 'Edition d\'une commandes',
|
||||
'breadcrumb' => ['Commandes']
|
||||
])
|
||||
|
||||
@include('boilerplate::load.fileinput')
|
||||
|
||||
@section('content')
|
||||
|
||||
{{ Form::open(['route' => 'Admin.Shop.ArticleFamilies.update', 'id' => 'article-family-form', 'autocomplete' => 'off', 'files' => true]) }}
|
||||
{{ Form::open(['route' => 'Admin.Shop.Orders.update', 'id' => 'order-form', 'autocomplete' => 'off']) }}
|
||||
<input type="hidden" name="id" value="{{ $id }}">
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 mbl">
|
||||
<a href="{{ route("Admin.Shop.ArticleFamilies.index") }}" class="btn btn-default">
|
||||
{{ __('article_families.list.title') }}
|
||||
</a>
|
||||
|
||||
<span class="btn-group pull-right">
|
||||
@include('components.form.buttons.button-save')
|
||||
</span>
|
||||
<div class="col-12">
|
||||
{{ $order['last_name'] }} {{ $order['first_name'] }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<input type="hidden" name="id" value="{{ $id }}">
|
||||
@include('Admin.Shop.ArticleFamilies.form')
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
{{ $order['delivery']['name'] }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
{{ $order['address'] }}<br/>
|
||||
{{ $order['address2'] }}<br/>
|
||||
{{ $order['zipcode'] }} {{ $order['city'] }}<br/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<x-card title="Détail de a commande">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<table class="datatable">
|
||||
@foreach ($order['details'] as $detail)
|
||||
<tr>
|
||||
<td>{{ $detail['quantity'] }}</td>
|
||||
<td>{{ $detail['name'] }}</td>
|
||||
<td>{{ $detail['price'] }}</td>
|
||||
<td>{{ $detail['total'] }}</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</x-card>
|
||||
|
||||
</form>
|
||||
|
||||
@endsection
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
<form id="{{ $model }}-filters">
|
||||
<input type="hidden" name="tariff_id" value="{{ $tariff['id'] ?? false }}">
|
||||
</form>
|
||||
7
resources/views/Shop/Customers/profile.blade.php
Normal file
7
resources/views/Shop/Customers/profile.blade.php
Normal file
@@ -0,0 +1,7 @@
|
||||
@extends('Shop.layout.layout', [
|
||||
'title' => __('Profil'),
|
||||
])
|
||||
|
||||
@section('content')
|
||||
Profil
|
||||
@endsection
|
||||
11
resources/views/Shop/Orders/confirmed.blade.php
Normal file
11
resources/views/Shop/Orders/confirmed.blade.php
Normal file
@@ -0,0 +1,11 @@
|
||||
@extends('Shop.layout.layout', [
|
||||
'title' => __('Commande confirmée'),
|
||||
])
|
||||
|
||||
@section('content')
|
||||
<div class="row">
|
||||
<div class="col-8">
|
||||
Votre commande a été confirmée
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
@@ -1,26 +1,26 @@
|
||||
<div class="row">
|
||||
<div class="col-1">
|
||||
<x-form.radios.icheck name="payment" val="1" id="payment_card"/>
|
||||
<x-form.radios.icheck name="payment_type" val="1" id="payment_card"/>
|
||||
</div>
|
||||
<div class="col-11">
|
||||
<div class="col-11 pt-1">
|
||||
PAIEMENT PAR CARTE BANCAIRE
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-1">
|
||||
<x-form.radios.icheck name="payment" val="2" id="payment_check"/>
|
||||
<x-form.radios.icheck name="payment_type" val="2" id="payment_check"/>
|
||||
</div>
|
||||
<div class="col-11">
|
||||
<div class="col-11 pt-1">
|
||||
PAIEMENT PAR CHEQUE
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-1">
|
||||
<x-form.radios.icheck name="payment" val="3" id="payment_transfer"/>
|
||||
<x-form.radios.icheck name="payment_type" val="3" id="payment_transfer"/>
|
||||
</div>
|
||||
<div class="col-11">
|
||||
<div class="col-11 pt-1">
|
||||
PAIEMENT PAR VIREMENT BANCAIRE
|
||||
</div>
|
||||
</div>
|
||||
@@ -29,7 +29,7 @@
|
||||
<div class="col-1">
|
||||
<x-form.checkboxes.icheck name="agree" val="1" required=true/>
|
||||
</div>
|
||||
<div class="col-11">
|
||||
<div class="col-11 pt-1">
|
||||
J'ai lu les conditions générales de vente et j'y adhère sans réserve
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
<div class="row">
|
||||
<div class="col-4">
|
||||
Livraison
|
||||
</div>
|
||||
<div class="col-8">
|
||||
Mon nom
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
Route::middleware('auth')->prefix('Customers')->name('Customers.')->group(function () {
|
||||
Route::prefix('Customers')->name('Customers.')->group(function () {
|
||||
Route::get('show/{id}', 'CustomerController@show')->name('show');
|
||||
Route::get('profile/{id?}', 'CustomerController@profile')->name('profile');
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
Route::middleware('auth')->prefix('Invoices')->name('Invoices.')->group(function () {
|
||||
Route::get('show/{id}', 'InvoiceController@show')->name('show');
|
||||
Route::prefix('Invoices')->name('Invoices.')->group(function () {
|
||||
Route::get('show/{id}', 'InvoiceController@show')->name('show');
|
||||
});
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
Route::prefix('Orders')->name('Orders.')->group(function () {
|
||||
Route::get('order', 'OrderController@order')->name('order');
|
||||
Route::get('confirmed', 'OrderController@confirmed')->name('confirmed');
|
||||
Route::post('order', 'OrderController@store')->name('store');
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user