add datatbles for invoices, add pdf icon, refactor icons components, add autocomplete on search, adapt searching to meilisearch

This commit is contained in:
ludo
2024-02-04 02:51:38 +01:00
parent 067532b6fc
commit 4c6f9b3b61
39 changed files with 503 additions and 211 deletions

View File

@@ -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);
}