DashboardService.php 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace App\Services;
  3. use Illuminate\Support\Facades\DB;
  4. class DashboardService
  5. {
  6. public static function productFavorites()
  7. {
  8. return DB::table("sale_details")
  9. ->selectRaw(
  10. "sale_details.product_number,
  11. products.name AS title,
  12. SUM(sale_details.qty) AS qty,
  13. products.profit"
  14. )
  15. ->join(
  16. "products",
  17. "products.number",
  18. "=",
  19. "sale_details.product_number"
  20. )
  21. ->groupByRaw("product_number")
  22. ->orderByRaw("qty DESC")
  23. ->limit(5)
  24. ->get();
  25. }
  26. public static function productAmount()
  27. {
  28. return [
  29. QueryService::amount("sales", __("words.sale")),
  30. QueryService::amount("purchases", __("words.purchase")),
  31. QueryService::amount("products", __("words.product")),
  32. QueryService::amount("stock_products", __("words.stock_product")),
  33. ];
  34. }
  35. public static function salePurchaseStatistic()
  36. {
  37. return [
  38. __("words.sale") => QueryService::statistic("sales"),
  39. __("words.purchase") => QueryService::statistic("purchases"),
  40. ];
  41. }
  42. }