Advertisement
Guest User

Untitled

a guest
Sep 21st, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.73 KB | None | 0 0
  1. <?php
  2. function selisihWaktu($FromDate, $ToDate) {
  3. $multiply = 1;
  4. if(strtotime($FromDate) > strtotime($ToDate))
  5. {
  6. $multiply = -1;
  7. }
  8. $FromDate = new DateTime($FromDate);
  9. $ToDate = new DateTime($ToDate);
  10. $Interval = $FromDate->diff($ToDate);
  11.  
  12. if($Interval->h != 0)
  13. {
  14. $Difference["jam"] = $Interval->h * $multiply;
  15. }
  16. else
  17. {
  18. $Difference["jam"] = $Interval->h;
  19. }
  20.  
  21.  
  22. if(floor($Interval->d/7) != 0)
  23. {
  24. $Difference["minggu"] = floor($Interval->d/7) * $multiply;
  25. }
  26. else
  27. {
  28. $Difference["minggu"] = floor($Interval->d/7);
  29. }
  30.  
  31.  
  32. if($Interval->d != 0)
  33. {
  34. $Difference["hari"] = $Interval->d * $multiply;
  35. }
  36. else
  37. {
  38. $Difference["hari"] = $Interval->d;
  39. }
  40.  
  41. if($Interval->m != 0)
  42. {
  43. $Difference["bulan"] = $Interval->m * $multiply;
  44. }
  45. else
  46. {
  47. $Difference["bulan"] = $Interval->m;
  48. }
  49. if($Interval->y != 0)
  50. {
  51. $Difference["tahun"] = $Interval->y * $multiply;
  52. }
  53. else
  54. {
  55. $Difference["tahun"] = $Interval->y;
  56. }
  57. return $Difference;
  58. }
  59.  
  60. function notifikasiBayar($tanggal_kasus, $tanggal_sekarang)
  61. {
  62. $hasil = ["",""];
  63. //~ $tanggal_kasus = '2019-04-09'; // TANGGAL KASUS DARI DATABASE
  64. $batas = date('Y-m-d', strtotime("+12 months", strtotime($tanggal_kasus)));
  65. //~ $tanggal_sekarang = '2019-05-10'; // TANGGAL SEKARANG, BISA PAKAI date('Y-m-d')
  66.  
  67. $daftar_tanggal = [];
  68. $tanggal_kasus_tmp = $tanggal_kasus;
  69. for($x = 1; $x <= 12; $x++)
  70. {
  71. $tanggal_kasus_tmp = date('Y-m-d', strtotime("+1 months", strtotime($tanggal_kasus_tmp)));
  72. $daftar_tanggal[] = $tanggal_kasus_tmp;
  73. }
  74.  
  75. if(strtotime($tanggal_sekarang) <= strtotime($batas))
  76. {
  77. $selisih_waktu = selisihWaktu($tanggal_sekarang, $batas);
  78. $sisa_bulan = $selisih_waktu['bulan'];
  79.  
  80. // Logika bulan terakhir
  81. if($sisa_bulan == 0)
  82. {
  83. if($selisih_waktu['hari'] > 15)
  84. {
  85. $hasil[1] = "Expired in 1 month";
  86. }
  87. elseif($selisih_waktu['hari'] > 7 && $selisih_waktu['hari'] <= 15)
  88. {
  89. $hasil[1] = "Expired in 15 days";
  90. }
  91. elseif($selisih_waktu['hari'] == 7)
  92. {
  93. $hasil[1] = "Expired in a week";
  94. }
  95. elseif($selisih_waktu['hari'] < 7 && $selisih_waktu['hari'] >= 0)
  96. {
  97. $hasil[1] = "Expired soon";
  98. }
  99. }
  100.  
  101.  
  102. $selisih_waktu = selisihWaktu($tanggal_kasus, $tanggal_sekarang);
  103. if($selisih_waktu['hari'] <= 10 && $selisih_waktu['hari'] > 0)
  104. {
  105. $hasil[0] = "Frozen";
  106. }
  107. elseif($selisih_waktu['hari'] >= 24 || $selisih_waktu['hari'] == 0)
  108. {
  109. $selisih_hari = 0;
  110. while(true)
  111. {
  112. $selisih_waktu = selisihWaktu($tanggal_kasus, $tanggal_sekarang);
  113. if($selisih_waktu['hari'] != 0)
  114. {
  115. $selisih_hari++;
  116. $tanggal_sekarang = date('Y-m-d', strtotime("+1 days", strtotime($tanggal_sekarang)));
  117. }
  118. else
  119. {
  120. break;
  121. }
  122. }
  123. if($selisih_hari <= 3)
  124. {
  125. $hasil[0] = "Billing Period";
  126. }
  127. }
  128. }
  129. else
  130. {
  131. $hasil[0] = "Expired";
  132. $hasil[1] = "Expired";
  133. }
  134. return $hasil;
  135. }
  136.  
  137. // CARA PAKAI
  138. /*
  139. *
  140. * $notifikasi = notifikasiBayar($tgl_kasus, date('Y-m-d'));
  141. *
  142. * echo $notifikasi[0]; -> Menampilkan notifikasi perbulan alias frozen dan billing period
  143. * echo $notifikasi[1]; -> Menampilkan notifikasi akhir bulan alias expired in 1 month, in 15 days, in a week, serta expired soon
  144. *
  145. * Jika kasusnya sudah lewat dari 1 tahun, maka hasil echo $notifikasi[0] dan $notifikasi[1] sama yaitu EXPIRED
  146. *
  147. */
  148.  
  149. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement