fix shipping
This commit is contained in:
@@ -7,13 +7,11 @@ use App\Models\Botanic\Variety;
|
||||
use App\Models\Shop\Article;
|
||||
use App\Models\Shop\ArticleNature;
|
||||
use App\Models\Shop\Merchandise;
|
||||
use App\Traits\Model\Basic;
|
||||
|
||||
class ArticleNatures
|
||||
{
|
||||
public static function getOptions()
|
||||
{
|
||||
return ArticleNature::get()->pluck('name', 'id')->toArray();
|
||||
}
|
||||
use Basic;
|
||||
|
||||
public static function getProductType($id)
|
||||
{
|
||||
@@ -37,12 +35,16 @@ class ArticleNatures
|
||||
switch ($model) {
|
||||
case Specie::class:
|
||||
case Variety::class:
|
||||
return 1;
|
||||
$type = 1;
|
||||
break;
|
||||
case Merchandise::class:
|
||||
return 2;
|
||||
$type = 2;
|
||||
break;
|
||||
default:
|
||||
$type = false;
|
||||
}
|
||||
|
||||
return false;
|
||||
return $type;
|
||||
}
|
||||
|
||||
public static function getProductTypes()
|
||||
@@ -77,14 +79,9 @@ class ArticleNatures
|
||||
return ArticleNature::byProductType($type)->get();
|
||||
}
|
||||
|
||||
public static function getByCategory($category_id)
|
||||
public static function getByCategory($categoryId)
|
||||
{
|
||||
return Article::byCategory($category_id)->select('article_nature_id')->distinct()->get();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return ArticleNature::orderBy('name', 'asc')->get();
|
||||
return Article::byCategory($categoryId)->select('article_nature_id')->distinct()->get();
|
||||
}
|
||||
|
||||
public static function getNamesByIds($ids)
|
||||
@@ -94,34 +91,8 @@ class ArticleNatures
|
||||
return array_map('strtolower', $names);
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
public static function getModel()
|
||||
{
|
||||
return ArticleNature::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 ArticleNature::create($data);
|
||||
}
|
||||
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = $id ? $id : $data['id'];
|
||||
$item = self::get($id);
|
||||
$ret = $item->update($data);
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return ArticleNature::destroy($id);
|
||||
return ArticleNature::query();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,30 +3,18 @@
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\CustomerAddress;
|
||||
use App\Traits\Model\Basic;
|
||||
|
||||
class CustomerAddresses
|
||||
{
|
||||
public static function getOptions()
|
||||
{
|
||||
return CustomerAddress::orderBy('name', 'asc')->get()->pluck('name', 'id')->toArray();
|
||||
}
|
||||
use Basic;
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return CustomerAddress::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return CustomerAddress::find($id);
|
||||
}
|
||||
|
||||
public static function add($user_id, $data)
|
||||
public static function add($userId, $data)
|
||||
{
|
||||
$name = $data['company'] ? $data['company'] : $data['first_name'].' '.$data['last_name'];
|
||||
if ($data['use_for_delivery'] ?? false) {
|
||||
return self::store([
|
||||
'customer_id' => $user_id,
|
||||
'customer_id' => $userId,
|
||||
'name' => $name,
|
||||
'address' => $data['delivery_address'],
|
||||
'address2' => $data['delivery_address2'],
|
||||
@@ -35,7 +23,7 @@ class CustomerAddresses
|
||||
]);
|
||||
} else {
|
||||
return self::store([
|
||||
'customer_id' => $user_id,
|
||||
'customer_id' => $userId,
|
||||
'name' => $name,
|
||||
'address' => $data['address'],
|
||||
'address2' => $data['address2'],
|
||||
@@ -45,35 +33,13 @@ class CustomerAddresses
|
||||
}
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = $data['id'] ?? false;
|
||||
$item = $id ? self::update($data, $id) : self::create($data);
|
||||
|
||||
return $item->id;
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return CustomerAddress::create($data);
|
||||
}
|
||||
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = $id ? $id : $data['id'];
|
||||
$delivery = self::get($id);
|
||||
$delivery->update($data);
|
||||
|
||||
return $delivery;
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return CustomerAddress::destroy($id);
|
||||
}
|
||||
|
||||
public static function toggle_active($id, $active)
|
||||
public static function toggleActive($id, $active)
|
||||
{
|
||||
return self::update(['active' => $active], $id);
|
||||
}
|
||||
|
||||
public static function getModel()
|
||||
{
|
||||
return CustomerAddress::query();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,14 +7,14 @@ class Dashboards
|
||||
public static function getStats($start, $end)
|
||||
{
|
||||
return [
|
||||
'orders_count' => Orders::countByPeriod($start, $end),
|
||||
'orders_sum' => Orders::sumByPeriod($start, $end, 'total_shipped'),
|
||||
'orders_avg' => Orders::avgByPeriod($start, $end, 'total_shipped'),
|
||||
'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(),
|
||||
'preparationLess24H' => Orders::countInPreparationLess24H(),
|
||||
'preparationLess48H' => Orders::countInPreparationLess48H(),
|
||||
'preparationMore48H' => Orders::countInPreparationMore48H(),
|
||||
'preparationLess24H' => OrderMetrics::countInPreparationLess24H(),
|
||||
'preparationLess48H' => OrderMetrics::countInPreparationLess48H(),
|
||||
'preparationMore48H' => OrderMetrics::countInPreparationMore48H(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,42 +3,14 @@
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\DeliveryPackage;
|
||||
use App\Traits\Model\Basic;
|
||||
|
||||
class DeliveryPackages
|
||||
{
|
||||
public static function getOptions()
|
||||
use Basic;
|
||||
|
||||
public static function getModel()
|
||||
{
|
||||
return DeliveryPackage::pluck('name', 'id');
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return DeliveryPackage::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 DeliveryPackage::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 DeliveryPackage::destroy($id);
|
||||
return DeliveryPackage::query();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,52 +3,14 @@
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\DeliveryTypeCalculation;
|
||||
use App\Traits\Model\Basic;
|
||||
|
||||
class DeliveryTypeCalculations
|
||||
{
|
||||
public static function getByDeliveryType($typeId)
|
||||
use Basic;
|
||||
|
||||
public static function getModel()
|
||||
{
|
||||
return DeliveryTypeCalculation::byDeliveryTpe($typeId)->get();
|
||||
}
|
||||
|
||||
public static function getPrice($typeId, $weight)
|
||||
{
|
||||
return DeliveryTypeCalculation::byDeliveryType($typeId)->byWeight($weight)->get();
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return DeliveryTypeCalculation::pluck('name', 'id');
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return DeliveryTypeCalculation::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 DeliveryTypeCalculation::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 DeliveryTypeCalculation::destroy($id);
|
||||
return DeliveryTypeCalculation::query();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,42 +3,14 @@
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\DeliveryType;
|
||||
use App\Traits\Model\Basic;
|
||||
|
||||
class DeliveryTypes
|
||||
{
|
||||
public static function getOptions()
|
||||
use Basic;
|
||||
|
||||
public static function getModel()
|
||||
{
|
||||
return DeliveryType::pluck('name', 'id');
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return DeliveryType::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 DeliveryType::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 DeliveryType::destroy($id);
|
||||
return DeliveryType::query();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,9 +28,9 @@ class Invoices
|
||||
return Invoice::byUUID($uuid)->first();
|
||||
}
|
||||
|
||||
public static function saveInvoice($order_id, $data)
|
||||
public static function saveInvoice($orderId, $data)
|
||||
{
|
||||
$data['order_id'] = $order_id;
|
||||
$data['order_id'] = $orderId;
|
||||
|
||||
return self::store($data);
|
||||
}
|
||||
@@ -86,9 +86,9 @@ class Invoices
|
||||
public static function getNewRef()
|
||||
{
|
||||
$ref = date('ym').'00000';
|
||||
$last_ref = Invoice::orderBy('id', 'desc')->first();
|
||||
$lastRef = Invoice::orderBy('id', 'desc')->first();
|
||||
|
||||
return $last_ref ? $last_ref->ref + 1 : $ref + 1;
|
||||
return $lastRef ? $lastRef->ref + 1 : $ref + 1;
|
||||
}
|
||||
|
||||
public static function getStatus($id)
|
||||
|
||||
44
app/Repositories/Shop/OrderMails.php
Normal file
44
app/Repositories/Shop/OrderMails.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Mail\Acheminement;
|
||||
use App\Mail\ConfirmationCommande;
|
||||
use App\Mail\Preparation;
|
||||
use App\Models\Shop\Order;
|
||||
use App\Repositories\Core\DateStats;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class OrderMails
|
||||
{
|
||||
public static function testSend($id)
|
||||
{
|
||||
self::sendPreparation($id);
|
||||
}
|
||||
|
||||
public static function sendOrderConfirmed($orderId)
|
||||
{
|
||||
$order = Orders::get($orderId, ['customer', 'address']);
|
||||
$mail = new ConfirmationCommande($order);
|
||||
|
||||
return Mail::to($order->customer->email)->send($mail);
|
||||
}
|
||||
|
||||
public static function sendPreparation($orderId)
|
||||
{
|
||||
$order = Orders::get($orderId, ['customer', 'address']);
|
||||
$mail = new Preparation($order);
|
||||
|
||||
return Mail::to($order->customer->email)->send($mail);
|
||||
}
|
||||
|
||||
public static function sendShipping($orderId)
|
||||
{
|
||||
$order = Orders::get($orderId, ['customer', 'address']);
|
||||
$mail = new Acheminement($order);
|
||||
|
||||
return Mail::to($order->customer->email)->send($mail);
|
||||
}
|
||||
}
|
||||
45
app/Repositories/Shop/OrderMetrics.php
Normal file
45
app/Repositories/Shop/OrderMetrics.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Order;
|
||||
use App\Repositories\Core\DateStats;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class OrderMetrics
|
||||
{
|
||||
use DateStats;
|
||||
|
||||
public static function countInPreparationLess24H()
|
||||
{
|
||||
$start = Carbon::now()->subHours(24);
|
||||
$end = Carbon::now();
|
||||
|
||||
return Order::preparation()->byPeriod($start, $end, 'updated_at')->count();
|
||||
}
|
||||
|
||||
public static function countInPreparationLess48H()
|
||||
{
|
||||
$start = Carbon::now()->subHours(48);
|
||||
$end = Carbon::now();
|
||||
|
||||
return Order::preparation()->byPeriod($start, $end, 'updated_at')->count();
|
||||
}
|
||||
|
||||
public static function countInPreparationMore48H()
|
||||
{
|
||||
$start = Carbon::now()->subHours(48);
|
||||
|
||||
return Order::preparation()->where('updated_at', '>', $start)->count();
|
||||
}
|
||||
|
||||
public static function getTotalByPeriod($start, $end)
|
||||
{
|
||||
return self::sumByPeriod($start, $end, 'total_shipped');
|
||||
}
|
||||
|
||||
public static function getModel()
|
||||
{
|
||||
return Order::query();
|
||||
}
|
||||
}
|
||||
@@ -2,18 +2,14 @@
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Mail\Acheminement;
|
||||
use App\Mail\ConfirmationCommande;
|
||||
use App\Mail\Preparation;
|
||||
use App\Models\Shop\Order;
|
||||
use App\Repositories\Core\DateStats;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use App\Traits\Model\Basic;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Orders
|
||||
{
|
||||
use DateStats;
|
||||
use Basic, DateStats;
|
||||
|
||||
public static function getByUUID($uuid)
|
||||
{
|
||||
@@ -38,68 +34,6 @@ class Orders
|
||||
return ($order && $detail) ? Invoices::saveInvoice($order->id, $data) : false;
|
||||
}
|
||||
|
||||
public static function testSend($id)
|
||||
{
|
||||
self::sendPreparation($id);
|
||||
}
|
||||
|
||||
public static function sendOrderConfirmed($order_id)
|
||||
{
|
||||
$order = self::get($order_id, ['customer', 'address']);
|
||||
$mail = new ConfirmationCommande($order);
|
||||
|
||||
return Mail::to($order->customer->email)->send($mail);
|
||||
}
|
||||
|
||||
public static function sendPreparation($order_id)
|
||||
{
|
||||
$order = self::get($order_id, ['customer', 'address']);
|
||||
$mail = new Preparation($order);
|
||||
|
||||
return Mail::to($order->customer->email)->send($mail);
|
||||
}
|
||||
|
||||
public static function sendShipping($order_id)
|
||||
{
|
||||
$order = self::get($order_id, ['customer', 'address']);
|
||||
$mail = new Acheminement($order);
|
||||
|
||||
return Mail::to($order->customer->email)->send($mail);
|
||||
}
|
||||
|
||||
public static function count()
|
||||
{
|
||||
return Order::count();
|
||||
}
|
||||
|
||||
public static function countInPreparationLess24H()
|
||||
{
|
||||
$start = Carbon::now()->subHours(24);
|
||||
$end = Carbon::now();
|
||||
|
||||
return Order::preparation()->byPeriod($start, $end, 'updated_at')->count();
|
||||
}
|
||||
|
||||
public static function countInPreparationLess48H()
|
||||
{
|
||||
$start = Carbon::now()->subHours(48);
|
||||
$end = Carbon::now();
|
||||
|
||||
return Order::preparation()->byPeriod($start, $end, 'updated_at')->count();
|
||||
}
|
||||
|
||||
public static function countInPreparationMore48H()
|
||||
{
|
||||
$start = Carbon::now()->subHours(48);
|
||||
|
||||
return Order::preparation()->where('updated_at', '>', $start)->count();
|
||||
}
|
||||
|
||||
public static function getTotalByPeriod($start, $end)
|
||||
{
|
||||
return self::sumByPeriod($start, $end, 'total_shipped');
|
||||
}
|
||||
|
||||
public static function edit($id)
|
||||
{
|
||||
return [
|
||||
@@ -111,16 +45,6 @@ class Orders
|
||||
];
|
||||
}
|
||||
|
||||
public static function get($id, $relations = false)
|
||||
{
|
||||
return $relations ? Order::with($relations)->findOrFail($id) : Order::findOrFail($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
return ($data['id'] ?? false) ? self::update($data) : self::create($data);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
OrderStats::increase();
|
||||
@@ -130,20 +54,6 @@ class Orders
|
||||
return Order::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 Order::destroy($id);
|
||||
}
|
||||
|
||||
public static function download($id)
|
||||
{
|
||||
dump($id);
|
||||
@@ -180,9 +90,9 @@ class Orders
|
||||
public static function getNewRef()
|
||||
{
|
||||
$ref = date('ym').'00000';
|
||||
$last_ref = Order::orderBy('id', 'desc')->first();
|
||||
$lastRef = Order::orderBy('id', 'desc')->first();
|
||||
|
||||
return $last_ref ? $last_ref->ref + 1 : $ref + 1;
|
||||
return $lastRef ? $lastRef->ref + 1 : $ref + 1;
|
||||
}
|
||||
|
||||
public static function getModel()
|
||||
|
||||
Reference in New Issue
Block a user