Aucune description
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

DashboardUtil.php 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace App\Utils;
  3. use DB;
  4. use Illuminate\Support\Carbon;
  5. use App\Model\Master\ItemKantongs;
  6. use Auth;
  7. class DashboardUtil
  8. {
  9. public function getDataLast30Days($param, $petugas_udd_id, $date_at)
  10. {
  11. $query = ItemKantongs::where('status_id', $param)
  12. ->where('unit_donor_darah_id', $petugas_udd_id)
  13. ->whereBetween(DB::raw('date(kantong_items.'.$date_at.')'), [\Carbon::now()->subDays(30), \Carbon::now()])
  14. ->orderBy($date_at, 'ASC');
  15. $query->select(
  16. DB::raw("DATE_FORMAT(kantong_items.".$date_at.", '%Y-%m-%d') as date, count(*) as total"),
  17. )
  18. ->groupBy(DB::raw('Date(kantong_items.'.$date_at.')'));
  19. $data = $query->get();
  20. $arr= [];
  21. for ($i = 29; $i >= 0; $i--) {
  22. $date = \Carbon::now()->subDays($i)->format('Y-m-d');
  23. $arr[$date] = 0;
  24. }
  25. for ($i = 29; $i >= 0; $i--) {
  26. $date = \Carbon::now()->subDays($i)->format('Y-m-d');
  27. if(!empty($data[$i])){ //cek data histori pendonor
  28. $tanggal = $data[$i]->date;
  29. $arr[$tanggal] = $data[$i]->total;
  30. }
  31. }
  32. ksort($arr);
  33. return $arr;
  34. }
  35. public function getDataLast1Years($param, $petugas_udd_id)
  36. {
  37. $now = Carbon::now();
  38. $year = $now->year;
  39. $query = DB::select("SELECT COUNT(*) as jumlah, MONTH(updated_at) as bulan FROM kantong_items WHERE YEAR(updated_at) = $year and status_id = $param and unit_donor_darah_id = $petugas_udd_id GROUP BY MONTH(updated_at)");
  40. $data = array();
  41. for($i=0; $i<=12; $i++)
  42. {
  43. if(!empty($query[$i])){
  44. if($query[$i]->bulan != $i+1){
  45. $data[$i] = 0;
  46. }
  47. $bulan = $query[$i]->bulan;
  48. $data[$bulan] = $query[$i]->jumlah;
  49. }else{
  50. if(empty($data[$i])){
  51. $data[$i] = 0;
  52. }
  53. }
  54. }
  55. ksort($data);
  56. return $data;
  57. }
  58. }