add metrics

This commit is contained in:
ludo
2024-01-30 23:24:00 +01:00
parent 1bc9bf9fe9
commit 8eb3104b2a
12 changed files with 226 additions and 70 deletions

View File

@@ -0,0 +1,75 @@
<?php
namespace App\Http\Controllers\Admin\Shop;
use App\Datatables\Shop\PriceListValuesDataTable;
use App\Http\Controllers\Controller;
use App\Repositories\Shop\Packages;
use App\Repositories\Shop\PriceListValueCategories;
use App\Repositories\Shop\PriceListValues;
use App\Repositories\Shop\Taxes;
use App\Repositories\Shop\Unities;
use Illuminate\Http\Request;
class PriceListValueController extends Controller
{
public function index(PriceListValuesDataTable $dataTable)
{
$data['categories'] = PriceListValueCategories::getOptions();
return $dataTable->render('Admin.Shop.PriceListValues.list', $data);
}
public function create()
{
$data['unities'] = Unities::getOptions();
$data['taxes_options'] = Taxes::getOptions();
$data['categories'] = PriceListValueCategories::getOptions();
return view('Admin.Shop.PriceListValues.create', $data);
}
public function edit($id)
{
$data['generic'] = PriceListValues::getFull($id)->toArray();
$data['packages'] = Packages::getSelectByFamily($data['generic']['category']['article_family_id']);
$data['unities'] = ($data['packages']['id'] ?? false) ? Unities::getSelectByPackage($data['packages']['id']) : [];
$data['taxes_options'] = Taxes::getOptions();
$data['categories'] = PriceListValueCategories::getOptions();
return view('Admin.Shop.PriceListValues.edit', $data);
}
public function store(Request $request)
{
$ret = PriceListValues::store($request->all());
return redirect()->route('Admin.Shop.PriceListValues.index');
}
public function show($id)
{
$data = PriceListValues::get($id);
return view('Admin.Shop.PriceListValues.view', $data);
}
public function destroy($id)
{
return PriceListValues::destroy($id);
}
public function getPrice($id)
{
$data['generic'] = PriceListValues::getFull($id);
return view('Admin.Shop.PriceListValues.partials.table-prices', $data);
}
public function addPrice($index)
{
$data['index'] = $index;
return view('Admin.Shop.PriceListValues.partials.row_price', $data);
}
}

View File

@@ -69,6 +69,11 @@ class Order extends Model
return $query->where('delivery_id', $deliveryId);
}
public function scopeWaiting($query)
{
return $query->byStatus(0);
}
public function scopePreparation($query)
{
return $query->byStatus(1);

View File

@@ -3,10 +3,13 @@
namespace App\Repositories\Shop;
use App\Models\Shop\Basket;
use App\Traits\Model\Basic;
use Darryldecode\Cart\CartCollection;
class BasketStores
{
use Basic;
public function has($key)
{
return Basket::find($key);
@@ -14,30 +17,29 @@ class BasketStores
public function get($key)
{
if($this->has($key))
{
if($this->has($key)) {
return new CartCollection(Basket::find($key)->cart_data);
}
else
{
} else {
return [];
}
}
public function put($key, $value)
{
if($row = Basket::find($key))
{
if($row = Basket::find($key)) {
// update
$row->cart_data = $value;
$row->save();
}
else
{
} else {
Basket::create([
'id' => $key,
'cart_data' => $value
]);
}
}
public static function getModel()
{
return Basket::query();
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace App\Repositories\Shop;
use App\Models\Shop\Customer;
use App\Repositories\Core\DateStats;
use App\Traits\Model\Basic;
class CustomerMetrics
{
use Basic, DateStats;
public static function countOfToday()
{
return Customer::ofToday()->count();
}
public static function countOfLastWeek()
{
return Customer::ofLastWeek()->count();
}
public static function countOfLastMonth()
{
return Customer::ofLastMonth()->count();
}
public static function getModel()
{
return Customer::query();
}
}

View File

@@ -10,12 +10,15 @@ class Dashboards
'orders_count' => OrderMetrics::countByPeriod($start, $end),
'orders_sum' => OrderMetrics::sumByPeriod($start, $end, 'total_shipped'),
'orders_avg' => OrderMetrics::avgByPeriod($start, $end, 'total_shipped'),
'offers_count' => Offers::count(),
'clients_count' => Customers::count(),
'countClients' => CustomerMetrics::countByPeriod($start, $end),
'waitingOrders' => OrderMetrics::countWaiting(),
'preparationLess24H' => OrderMetrics::countPreparationLess24h(),
'preparationLess48H' => OrderMetrics::countPreparationLess48h(),
'preparationMore48H' => OrderMetrics::countPreparationMore48h(),
'offers_count' => Offers::count(),
'stocksWarning' => OfferStocks::countAlerts(),
'countCustomers' => Customers::count(),
'lastOrders' => Orders::getLast(),
];
}
}

View File

@@ -20,6 +20,11 @@ class OrderMetrics
return self::sumMonthly('total_taxed');
}
public static function countWaiting()
{
return Order::waiting()->count();
}
public static function countPreparationLess24h()
{
$date = now()->subHours(24);

View File

@@ -14,6 +14,11 @@ class Orders
{
use Basic, DateStats;
public static function getLast($nb = 10)
{
return Order::with('customer')->orderBy('id', 'DESC')->take($nb)->get();
}
public static function getPdfByUUID($uuid)
{
return self::getPdf(self::getIdByUUID($uuid), 'commande-' . $uuid . '.pdf');