Dashboard sipadu mbip
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

StatisticController.php 8.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Api\BaseController;
  5. use Carbon\Carbon;
  6. use App\Model\Staff;
  7. use App\Model\StaffDetail;
  8. use App\Model\Module\Compound;
  9. use App\Model\Module\ConfidentialFile;
  10. use App\Model\Module\Department;
  11. use App\Model\Module\Faulty;
  12. class StatisticController extends BaseController
  13. {
  14. /**
  15. * Create compound report controller for kelantanpay.
  16. *
  17. * @return json
  18. */
  19. public function compoundBasedFaulty($start_date, $end_date){
  20. $temp = [];
  21. if($start_date == 'null'){
  22. $compound = Compound::with('Faulty')->distinct('seksyen_kesalahan')->groupBy('seksyen_kesalahan')->get();
  23. foreach ($compound as $key => $c) {
  24. $temp[] = $c->faulty;
  25. }
  26. }else {
  27. $dateS = Carbon::createFromFormat('Y-m-d', $start_date);
  28. $start = $dateS->copy()->startOfDay();
  29. if($end_date != 'null'){
  30. $dateE = Carbon::createFromFormat('Y-m-d', $end_date);
  31. $end = $dateE->copy()->endOfDay();
  32. }else{
  33. $end = $dateS->copy()->endOfDay();
  34. }
  35. $compound = Compound::with('Faulty')->distinct('seksyen_kesalahan')->whereBetween('created_at', array($start, $end))
  36. ->groupBy('seksyen_kesalahan')->get();
  37. foreach ($compound as $key => $c) {
  38. $temp[] = $c->faulty;
  39. }
  40. }
  41. return $temp;
  42. }
  43. private function kadarKompaunDiBayar($id,$start_date,$end_date){
  44. $total = 0;
  45. if($start_date == 'null'){
  46. $compound = Compound::where('seksyen_kesalahan', $id)->where('status','Berbayar')->get();
  47. foreach ($compound as $key => $c) {
  48. $total += $c->amount_payment;
  49. }
  50. }else{
  51. $dateS = Carbon::createFromFormat('Y-m-d', $start_date);
  52. $start = $dateS->copy()->startOfDay();
  53. if($end_date != 'null'){
  54. $dateE = Carbon::createFromFormat('Y-m-d', $end_date);
  55. $end = $dateE->copy()->endOfDay();
  56. }else{
  57. $end = $dateS->copy()->endOfDay();
  58. }
  59. $compound = Compound::with('Faulty')->where('seksyen_kesalahan', $id)->where('status','Berbayar')
  60. ->whereBetween('created_at', array($start, $end))->get();
  61. foreach ($compound as $key => $c) {
  62. $total += ($c->Faulty->amount - $c->amount_payment);
  63. }
  64. }
  65. return $total;
  66. }
  67. private function kadarKompaunKurang($id,$start_date,$end_date){
  68. $total = 0;
  69. if($start_date == 'null'){
  70. $compound = Compound::with('Faulty')->where('seksyen_kesalahan', $id)->where('status','Berbayar')->get();
  71. foreach ($compound as $key => $c) {
  72. $total += ($c->Faulty->amount - $c->amount_payment);
  73. }
  74. }else{
  75. $dateS = Carbon::createFromFormat('Y-m-d', $start_date);
  76. $start = $dateS->copy()->startOfDay();
  77. if($end_date != 'null'){
  78. $dateE = Carbon::createFromFormat('Y-m-d', $end_date);
  79. $end = $dateE->copy()->endOfDay();
  80. }else{
  81. $end = $dateS->copy()->endOfDay();
  82. }
  83. $compound = Compound::with('Faulty')->where('seksyen_kesalahan', $id)->where('status','Berbayar')
  84. ->whereBetween('created_at', array($start, $end))->get();
  85. foreach ($compound as $key => $c) {
  86. $total += ($c->Faulty->amount - $c->amount_payment);
  87. }
  88. }
  89. return $total;
  90. }
  91. public function reportCompoundList($start_date, $end_date)
  92. {
  93. $nested_data = array();
  94. $noFaulty = $this->compoundBasedFaulty($start_date, $end_date);
  95. if($start_date == 'null'){
  96. foreach ($noFaulty as $key => $f) {
  97. $jumlah_kompaun = 0; $jumlah_kadar_kompaun = 0;
  98. $jumlah_kompaun_dibayar = 0; $jumlah_kadar_kompaun_dibayar = 0;
  99. $jumlah_kompaun_belum_bayar = 0; $jumlah_tunggakkan = 0;
  100. $jumlah_kompaun_kurg = 0; $jumlah_kadar_kompaun_kurg = 0;
  101. $jumlah_kompaun = count(Compound::where('seksyen_kesalahan', $f->_id)->get());
  102. $jumlah_kadar_kompaun = floatval($f->amount) * $jumlah_kompaun;
  103. $jumlah_kompaun_dibayar = count(Compound::where('seksyen_kesalahan', $f->_id)->where('status','Berbayar')->get());
  104. $jumlah_kompaun_belum_bayar = count(Compound::where('seksyen_kesalahan', $f->_id)->where('status','Belum Bayar')->get());
  105. $jumlah_tunggakkan = ($jumlah_kompaun_belum_bayar - $jumlah_kompaun_dibayar) * floatval($f->amount);
  106. $jumlah_kompaun_kurg = count(Compound::where('seksyen_kesalahan', $f->_id)->where('jumlah_kemaskini_kompaun','!=','')->get());
  107. $jumlah_kadar_kompaun_dibayar = $this->kadarKompaunDiBayar($f->_id,$start_date,$end_date);
  108. $jumlah_kadar_kompaun_kurg = $this->kadarKompaunKurang($f->_id,$start_date,$end_date);
  109. array_push($nested_data, array(
  110. 'kesalahan' => $f->nama,
  111. 'jumlahK' => $jumlah_kompaun,
  112. 'amaunK' => $jumlah_kadar_kompaun,
  113. 'jumlahB' => $jumlah_kompaun_dibayar,
  114. 'amaunB' => $jumlah_kadar_kompaun_dibayar,
  115. 'belumB' => $jumlah_kompaun_belum_bayar,
  116. 'amaunT' => $jumlah_tunggakkan,
  117. 'kBatal' => '0',
  118. 'amaunBatal' => '0',
  119. 'kompaunKurang' => $jumlah_kompaun_kurg,
  120. 'amaunKurang' => $jumlah_kadar_kompaun_kurg,
  121. ));
  122. }
  123. }else{
  124. $dateS = Carbon::createFromFormat('Y-m-d', $start_date);
  125. $start = $dateS->copy()->startOfDay();
  126. if($end_date != 'null'){
  127. $dateE = Carbon::createFromFormat('Y-m-d', $end_date);
  128. $end = $dateE->copy()->endOfDay();
  129. }else{
  130. $end = $dateS->copy()->endOfDay();
  131. }
  132. foreach ($noFaulty as $key => $f) {
  133. $jumlah_kompaun = 0; $jumlah_kadar_kompaun = 0;
  134. $jumlah_kompaun_dibayar = 0; $jumlah_kadar_kompaun_dibayar = 0;
  135. $jumlah_kompaun_belum_bayar = 0; $jumlah_tunggakkan = 0;
  136. $jumlah_kompaun_kurg = 0; $jumlah_kadar_kompaun_kurg = 0;
  137. $jumlah_kompaun = count(Compound::where('seksyen_kesalahan', $f->_id)->whereBetween('created_at', array($start, $end))->get());
  138. $jumlah_kadar_kompaun = floatval($f->amount) * $jumlah_kompaun;
  139. $jumlah_kompaun_dibayar = count(Compound::where('seksyen_kesalahan', $f->_id)->where('status','Berbayar')->whereBetween('created_at', array($start, $end))->get());
  140. $jumlah_kompaun_belum_bayar = count(Compound::where('seksyen_kesalahan', $f->_id)->where('status','Belum Bayar')->whereBetween('created_at', array($start, $end))->get());
  141. $jumlah_tunggakkan = ($jumlah_kompaun_belum_bayar - $jumlah_kompaun_dibayar) * floatval($f->amount);
  142. $jumlah_kompaun_kurg = count(Compound::where('seksyen_kesalahan', $f->_id)->where('jumlah_kemaskini_kompaun','!=','')->whereBetween('created_at', array($start, $end))->get());
  143. $jumlah_kadar_kompaun_dibayar = $this->kadarKompaunDiBayar($f->_id,$start_date,$end_date);
  144. $jumlah_kadar_kompaun_kurg = $this->kadarKompaunKurang($f->_id,$start_date,$end_date);
  145. array_push($nested_data, array(
  146. 'kesalahan' => $f->nama,
  147. 'jumlahK' => $jumlah_kompaun,
  148. 'amaunK' => $jumlah_kadar_kompaun,
  149. 'jumlahB' => $jumlah_kompaun_dibayar,
  150. 'amaunB' => $jumlah_kadar_kompaun_dibayar,
  151. 'belumB' => $jumlah_kompaun_belum_bayar,
  152. 'amaunT' => $jumlah_tunggakkan,
  153. 'kBatal' => '0',
  154. 'amaunBatal' => '0',
  155. 'kompaunKurang' => $jumlah_kompaun_kurg,
  156. 'amaunKurang' => $jumlah_kadar_kompaun_kurg,
  157. ));
  158. }
  159. }
  160. return \DataTables::of($nested_data)->addIndexColumn()->make(true);
  161. }
  162. }