fix editing orders
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Datatables\Shop;
|
||||
use Yajra\DataTables\Html\Column;
|
||||
use App\Datatables\ParentDataTable as DataTable;
|
||||
use App\Models\Shop\Invoice;
|
||||
use App\Repositories\Shop\Invoices;
|
||||
|
||||
class InvoicesDataTable extends DataTable
|
||||
{
|
||||
@@ -15,11 +16,29 @@ class InvoicesDataTable extends DataTable
|
||||
return $this->buildQuery($model);
|
||||
}
|
||||
|
||||
public function modifier($datatables)
|
||||
{
|
||||
$datatables
|
||||
->editColumn('status', function (Invoice $invoice) {
|
||||
return Invoices::getStatus($invoice->status);
|
||||
})
|
||||
->editColumn('created_at', function (Invoice $invoice) {
|
||||
return $invoice->created_at->toDateTimeString();
|
||||
})
|
||||
->editColumn('customer.last_name', function (Invoice $invoice) {
|
||||
return $invoice->customer->last_name . ' ' . $invoice->customer->first_name;
|
||||
})
|
||||
->rawColumns(['action']);
|
||||
return parent::modifier($datatables);
|
||||
}
|
||||
|
||||
protected function getColumns()
|
||||
{
|
||||
return [
|
||||
Column::make('status.name'),
|
||||
Column::make('customer.name'),
|
||||
|
||||
Column::make('status'),
|
||||
Column::make('created_at')->title('Date'),
|
||||
Column::make('customer.last_name'),
|
||||
Column::make('total'),
|
||||
$this->makeColumnButtons(),
|
||||
];
|
||||
|
||||
@@ -12,6 +12,9 @@ use App\Repositories\Shop\Orders;
|
||||
class OrdersDataTable extends DataTable
|
||||
{
|
||||
public $model_name = 'orders';
|
||||
public $sortedColumn = 1;
|
||||
public $sortedOrder = 'desc';
|
||||
public $stateSave = true;
|
||||
|
||||
public function query(Order $model)
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Repositories\Shop\Dashboards;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
@@ -14,6 +15,7 @@ class HomeController extends Controller
|
||||
|
||||
public function index()
|
||||
{
|
||||
return view('Admin.Shop.Dashboard.index');
|
||||
$data = Dashboards::getStats();
|
||||
return view('Admin.Shop.Dashboard.index', $data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,9 +28,7 @@ class OrderController extends Controller
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$data['order'] = Orders::edit($id)->toArray();
|
||||
// dump($data);
|
||||
// exit;
|
||||
$data = Orders::edit($id);
|
||||
return view('Admin.Shop.Orders.edit', $data);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,12 +3,19 @@
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
use Venturecraft\Revisionable\RevisionableTrait;
|
||||
|
||||
class Order extends Model
|
||||
{
|
||||
use RevisionableTrait, SoftDeletes;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'shop_orders';
|
||||
|
||||
protected $revisionCreationsEnabled = false;
|
||||
protected $keepRevisionOf = ['customer_address_id', 'delivery_id', 'payment_type', 'status'];
|
||||
|
||||
public function customer()
|
||||
{
|
||||
return $this->belongsTo(Customer::class);
|
||||
|
||||
@@ -458,17 +458,17 @@ class Articles
|
||||
$images = count($article->images) ? $article->images : collect([]);
|
||||
switch ($article->product_type) {
|
||||
case 'App\Models\Botanic\Variety':
|
||||
$variety = $article->product;
|
||||
$specie = $variety->specie;
|
||||
$variety = $article->product ?? false;
|
||||
$specie = $variety->specie ?? false;
|
||||
$images = $variety ? (count($variety->images) ? $images->merge($variety->images) : $images) : $images;
|
||||
$images = $specie ? (count($specie->images) ? $images->merge($specie->images) : $images) : $images;
|
||||
break;
|
||||
case 'App\Models\Botanic\Specie':
|
||||
$specie = $article->product;
|
||||
$images = count($specie->images) ? $specie->images : $images;
|
||||
$specie = $article->product ?? false;
|
||||
$images = count($specie->images ?? []) ? $specie->images : $images;
|
||||
break;
|
||||
case 'App\Models\Shop\Merchandise':
|
||||
$merchandise = $article->product;
|
||||
$merchandise = $article->product ?? false;
|
||||
$images = count($merchandise->images) ? $merchandise->images : $images;
|
||||
break;
|
||||
}
|
||||
@@ -488,20 +488,13 @@ class Articles
|
||||
}
|
||||
switch ($article->product_type) {
|
||||
case 'App\Models\Botanic\Variety':
|
||||
$variety = $article->product;
|
||||
$image = $variety->image ?? false;
|
||||
if (!$image) {
|
||||
$specie = $variety->specie;
|
||||
$image = $specie->image ?? false;
|
||||
}
|
||||
$image = $article->product->image ?? ($article->product->specie->image ?? false);
|
||||
break;
|
||||
case 'App\Models\Botanic\Specie':
|
||||
$specie = $article->product;
|
||||
$image = $specie->image ?? false;
|
||||
$image = $article->product->image ?? false;
|
||||
break;
|
||||
case 'App\Models\Shop\Merchandise':
|
||||
$merchandise = $article->product;
|
||||
$image = $merchandise->image ?? false;
|
||||
$image = $article->product->image ?? false;
|
||||
break;
|
||||
}
|
||||
return $image;
|
||||
@@ -509,16 +502,16 @@ class Articles
|
||||
|
||||
public static function storeFull($data)
|
||||
{
|
||||
$images = isset($data['images']) ? $data['images'] : false;
|
||||
$images = $data['images'] ?? false;
|
||||
unset($data['images']);
|
||||
|
||||
$categories = isset($data['categories']) ? $data['categories'] : false;
|
||||
$categories = $data['categories'] ?? false;
|
||||
unset($data['categories']);
|
||||
|
||||
$tags = isset($data['tags']) ? $data['tags'] : false;
|
||||
$tags = $data['tags'] ?? false;
|
||||
unset($data['tags']);
|
||||
|
||||
$prices = isset($data['prices']) ? $data['prices'] : false;
|
||||
$prices = $data['prices'] ?? false;
|
||||
unset($data['prices']);
|
||||
|
||||
$article = self::store($data);
|
||||
|
||||
@@ -15,14 +15,11 @@ class Customers
|
||||
public static function editProfile($id = false)
|
||||
{
|
||||
$id = $id ? $id : self::getId();
|
||||
dump($id);
|
||||
exit;
|
||||
$data = [
|
||||
'customer' => self::get($id, ['addresses', 'deliveries', 'orders']),
|
||||
'customer' => self::get($id, ['addresses', 'deliveries', 'orders'])->toArray(),
|
||||
'deliveries' => Deliveries::getAll('sale_channel')->toArray(),
|
||||
];
|
||||
dump($data);
|
||||
exit;
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
18
app/Repositories/Shop/Dashboards.php
Normal file
18
app/Repositories/Shop/Dashboards.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Homepage;
|
||||
|
||||
class Dashboards
|
||||
{
|
||||
|
||||
public static function getStats()
|
||||
{
|
||||
return [
|
||||
'orders_count' => Orders::countByMonth(),
|
||||
'orders_sum' => Orders::sumByMonth(),
|
||||
'orders_avg' => Orders::avgByMonth(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\Models\Shop\Invoice;
|
||||
|
||||
class Invoices
|
||||
@@ -19,6 +19,17 @@ class Invoices
|
||||
return $relations ? Invoice::with($relations)->findOrFail($id) : Invoice::findOrFail($id);
|
||||
}
|
||||
|
||||
public static function count()
|
||||
{
|
||||
return Invoice::count();
|
||||
}
|
||||
|
||||
public static function countByMonth()
|
||||
{
|
||||
$start = Carbon::now()->beginOfMonth();
|
||||
return Invoice::where('created_at', '>', $start);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
return ($data['id'] ?? false) ? self::update($data) : self::create($data);
|
||||
@@ -53,4 +64,9 @@ class Invoices
|
||||
$last_ref = Invoice::orderBy('ref', 'desc')->where('ref', '>', $ref)->first();
|
||||
return $last_ref ? $last_ref->ref + 1 : $ref + 1;
|
||||
}
|
||||
|
||||
public static function statuses()
|
||||
{
|
||||
return ['En attente', 'Non soldée', 'Soldée'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\Models\Shop\Order;
|
||||
|
||||
class Orders
|
||||
@@ -24,9 +25,36 @@ class Orders
|
||||
return ($order && $detail) ? Invoices::saveInvoice($order->id, $data) : false;
|
||||
}
|
||||
|
||||
public static function count()
|
||||
{
|
||||
return Order::count();
|
||||
}
|
||||
|
||||
public static function countByMonth()
|
||||
{
|
||||
$start = Carbon::now()->startOfMonth();
|
||||
return Order::where('created_at', '>', $start)->count();
|
||||
}
|
||||
|
||||
public static function sumByMonth()
|
||||
{
|
||||
$start = Carbon::now()->startOfMonth();
|
||||
return Order::where('created_at', '>', $start)->sum('total_shipped');
|
||||
}
|
||||
|
||||
public static function avgByMonth()
|
||||
{
|
||||
return self::countByMonth() ? round(self::sumByMonth() / self::countByMonth(), 2) : 0;
|
||||
}
|
||||
|
||||
public static function edit($id)
|
||||
{
|
||||
return Orders::get($id, ['customer', 'address', 'delivery', 'detail']);
|
||||
return [
|
||||
'order' => self::get($id, ['customer', 'address', 'detail']),
|
||||
'statuses' => self::statuses(),
|
||||
'payment_types' => self::payment_types(),
|
||||
'sale_channels' => SaleChannels::getOptions(),
|
||||
];
|
||||
}
|
||||
|
||||
public static function get($id, $relations = false)
|
||||
@@ -65,10 +93,16 @@ class Orders
|
||||
|
||||
public static function statuses()
|
||||
{
|
||||
return [
|
||||
'En attente',
|
||||
'Expédié',
|
||||
'Livré',
|
||||
];
|
||||
return ['En attente', 'Expédié', 'Livré'];
|
||||
}
|
||||
|
||||
public static function getPaymentType($id)
|
||||
{
|
||||
return self::payment_types()[$id] ?? false;
|
||||
}
|
||||
|
||||
public static function payment_types()
|
||||
{
|
||||
return ['', 'CARTE BANCAIRE', 'CHEQUE', 'VIREMENT BANCAIRE'];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user