add datatbles for invoices, add pdf icon, refactor icons components, add autocomplete on search, adapt searching to meilisearch
This commit is contained in:
@@ -18,7 +18,7 @@ class Articles
|
||||
|
||||
public static function autocomplete($str)
|
||||
{
|
||||
$data = Article::byAutocomplete($str)->orderBy('name')->limit(30)->pluck('name', 'id');
|
||||
$data = Article::byAutocomplete($str)->orderBy('name')->limit(20)->pluck('name', 'id');
|
||||
$export = [];
|
||||
foreach ($data as $key => $name) {
|
||||
$export[] = ['value' => $key, 'text' => $name];
|
||||
@@ -143,6 +143,7 @@ class Articles
|
||||
public static function getArticlesToSell($options)
|
||||
{
|
||||
$articles = self::getArticlesWithOffers($options);
|
||||
$searchOrder = array_flip($options['ids']->toArray() ?? []);
|
||||
foreach ($articles as $article) {
|
||||
$price_lists = $article->offers[0]->tariff->price_lists->toArray();
|
||||
if (! count($price_lists)) {
|
||||
@@ -150,6 +151,7 @@ class Articles
|
||||
}
|
||||
if (! is_array($data[$article->name] ?? false)) {
|
||||
$data[$article->name] = self::getDataForSale($article);
|
||||
$data[$article->name]['searchOrder'] = $searchOrder[$article->id];
|
||||
}
|
||||
$prices = $price_lists[0]['price_list_values'][0];
|
||||
$article_nature_name = strtolower($article->article_nature->name);
|
||||
@@ -248,20 +250,17 @@ class Articles
|
||||
|
||||
public static function getModelByOptions($options = false)
|
||||
{
|
||||
$category_id = $options['category_id'] ?? false;
|
||||
$search = $options['search'] ?? false;
|
||||
$tags = $options['tags'] ?? false;
|
||||
$article_nature_id = $options['article_nature_id'] ?? false;
|
||||
$article_nature_ids = $options['article_nature_ids'] ?? false;
|
||||
$product_type = $options['product_type'] ?? false;
|
||||
|
||||
$model = $options['homepage'] ?? false ? Article::homepage()->visible() : Article::visible();
|
||||
$model = $category_id ? $model->byCategoryParent($category_id) : $model;
|
||||
$model = $tags ? $model->byTags($tags) : $model;
|
||||
$model = $search ? $model->search($search) : $model;
|
||||
$model = $options['category_id'] ?? false ? $model->byCategoryParent($options['category_id']) : $model;
|
||||
$model = $options['tags'] ?? false ? $model->byTags($options['tags']) : $model;
|
||||
$model = $options['search'] ?? false ? $model->rawSearch($options['search']) : $model;
|
||||
$model = $options['ids'] ?? false ? $model->byIDs($options['ids']) : $model;
|
||||
$model = $article_nature_id ? $model->byArticleNature($article_nature_id) : $model;
|
||||
$model = $article_nature_ids ? $model->byArticleNatures($article_nature_ids) : $model;
|
||||
switch ($product_type) {
|
||||
switch ($options['product_type'] ?? false) {
|
||||
case 'botanic':
|
||||
$model = $model->botanic();
|
||||
break;
|
||||
@@ -324,11 +323,6 @@ class Articles
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getPricesByArticle($article)
|
||||
{
|
||||
return Prices::getByArticle($article->id);
|
||||
}
|
||||
|
||||
public static function storeFull($data)
|
||||
{
|
||||
$images = $data['images'] ?? false;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Datatables\Shop\CustomerInvoicesDataTable;
|
||||
use App\Datatables\Shop\CustomerOrdersDataTable;
|
||||
use App\Models\Shop\Customer;
|
||||
use App\Repositories\Core\File;
|
||||
@@ -54,13 +55,14 @@ class Customers
|
||||
|
||||
public static function editProfile($id = false)
|
||||
{
|
||||
$id = $id ? $id : self::getId();
|
||||
$datatableOrders = new CustomerOrdersDataTable();
|
||||
$datatableInvoices = new CustomerInvoicesDataTable();
|
||||
|
||||
return [
|
||||
'customer' => self::get($id, ['addresses', 'deliveries'])->toArray(),
|
||||
'deliveries' => Deliveries::getAllWithSaleChannel()->toArray(),
|
||||
'orders' => $datatableOrders->html(),
|
||||
'invoices' => $datatableInvoices->html(),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -29,39 +29,54 @@ class Invoices
|
||||
public static function init()
|
||||
{
|
||||
return [
|
||||
'statuses' => Invoices::statuses(),
|
||||
'statuses' => self::statuses(),
|
||||
'payment_types' => InvoicePayments::paymentTypes(),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getFull($id)
|
||||
public static function view($uuid)
|
||||
{
|
||||
return self::get($id, ['address', 'payments', 'order.customer', 'order.delivery_address', 'order.detail']);
|
||||
$data = self::getFullByUUID($uuid)->toArray();
|
||||
$data['payment_type'] = InvoicePayments::getPaymentType($data['payment_type']);
|
||||
$data['status'] = self::getStatus($data['status']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getByUUID($uuid)
|
||||
public static function getFullByUUID($id)
|
||||
{
|
||||
return Invoice::byUUID($uuid)->first();
|
||||
return self::getByUUID($id, self::full());
|
||||
}
|
||||
|
||||
public static function getFull($id)
|
||||
{
|
||||
return self::get($id, self::full());
|
||||
}
|
||||
|
||||
public static function full()
|
||||
{
|
||||
return [
|
||||
'address',
|
||||
'customer',
|
||||
'order.delivery_address',
|
||||
'order.detail',
|
||||
'order.sale_channel',
|
||||
'payments',
|
||||
];
|
||||
}
|
||||
|
||||
public static function saveInvoice($orderId, $data)
|
||||
{
|
||||
$data['order_id'] = $orderId;
|
||||
$data['date_invoice'] = date('Y-m-d');
|
||||
$data['date_due'] = Carbon::now()->addMonth()->format('Y-m-d');
|
||||
|
||||
return self::store($data);
|
||||
}
|
||||
|
||||
public static function countByMonth()
|
||||
{
|
||||
$start = Carbon::now()->beginOfMonth();
|
||||
|
||||
return Invoice::where('created_at', '>', $start);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
InvoiceStats::increase($data['total_taxed']);
|
||||
InvoiceStats::increase($data['total']);
|
||||
$data['uuid'] = Str::uuid()->toString();
|
||||
$data['ref'] = self::getNewRef();
|
||||
|
||||
@@ -71,7 +86,7 @@ class Invoices
|
||||
public static function delete($id)
|
||||
{
|
||||
$invoice = self::get($id);
|
||||
InvoiceStats::decrease($invoice->total_priced);
|
||||
InvoiceStats::decrease($invoice->total);
|
||||
|
||||
return Invoice::destroy($id);
|
||||
}
|
||||
|
||||
@@ -14,6 +14,15 @@ class Orders
|
||||
{
|
||||
use Basic, DateStats;
|
||||
|
||||
public static function view($uuid)
|
||||
{
|
||||
$data = self::getFullByUUID($uuid)->toArray();
|
||||
$data['payment_type'] = InvoicePayments::getPaymentType($data['payment_type']);
|
||||
$data['status'] = self::getStatus($data['status']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getLast($nb = 10)
|
||||
{
|
||||
return Order::with('customer')->orderBy('id', 'DESC')->take($nb)->get();
|
||||
@@ -40,24 +49,12 @@ class Orders
|
||||
|
||||
public static function getFullByUUID($uuid)
|
||||
{
|
||||
return self::getFull(self::getIdByUUID($uuid));
|
||||
return self::getByUUID($uuid, self::full());
|
||||
}
|
||||
|
||||
public static function getFull($id)
|
||||
{
|
||||
return Order::with(['customer', 'delivery', 'delivery_address', 'detail', 'invoice.address', 'sale_channel'])
|
||||
->byID($id)->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;
|
||||
return self::get($id, self::full());
|
||||
}
|
||||
|
||||
public static function saveOrder($data)
|
||||
@@ -160,6 +157,11 @@ class Orders
|
||||
return $lastRef ? $lastRef->ref + 1 : $ref + 1;
|
||||
}
|
||||
|
||||
public static function full()
|
||||
{
|
||||
return ['customer', 'delivery', 'delivery_address', 'detail', 'invoice.address', 'sale_channel'];
|
||||
}
|
||||
|
||||
public static function getModel()
|
||||
{
|
||||
return Order::query();
|
||||
|
||||
@@ -6,9 +6,11 @@ use App\Models\Shop\Article;
|
||||
|
||||
class Searches
|
||||
{
|
||||
public static function search($query)
|
||||
public static function search($options)
|
||||
{
|
||||
return Article::withAvailableOffers()->search($query)->get();
|
||||
return collect(Articles::getArticlesToSell([
|
||||
'ids' => Article::search($options['search_name'])->get()->pluck('id'),
|
||||
]))->sortBy('searchOrder')->toArray();
|
||||
}
|
||||
public static function getResults($options)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user