Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.31 KB | None | 0 0
  1. <?php
  2. namespace Libraries\Common;
  3. use Resources;
  4.  
  5. class Func {
  6.  
  7. public static function rupiah($price)
  8. {
  9. $price = number_format($price + 0, 0, '', '.');
  10. return $price;
  11. }
  12.  
  13. public static function rupiahd($rup)
  14. {
  15. $rup = number_format($rup + 0, 2, ',', '.');
  16. return $rup;
  17. }
  18.  
  19. public static function rupiaht($rup)
  20. {
  21. $rup = number_format($rup + 0, 1, ',', '.');
  22. return $rup;
  23. }
  24.  
  25. public static function rupiahb($rup)
  26. {
  27. if ($rup < 2000000000)
  28. {
  29. $rups = number_format($rup + 0, 0, '', '.');
  30. }
  31. else
  32. {
  33. $rups = substr($rup, 0, 1) . '.' . substr($rup, 1, 3) . '.' . substr($rup, 4, 3) . '.' . substr($rup, 7, 3);
  34. }
  35.  
  36. return $rups;
  37. }
  38.  
  39. public static function get_bulan($bulan)
  40. {
  41. switch ($bulan)
  42. {
  43. case '01': $nama_bulan = 'JAN'; break;
  44. case '02': $nama_bulan = 'FEB'; break;
  45. case '03': $nama_bulan = 'MAR'; break;
  46. case '04': $nama_bulan = 'APR'; break;
  47. case '05': $nama_bulan = 'MEI'; break;
  48. case '06': $nama_bulan = 'JUN'; break;
  49. case '07': $nama_bulan = 'JUL'; break;
  50. case '08': $nama_bulan = 'AGU'; break;
  51. case '09': $nama_bulan = 'SEP'; break;
  52. case '10': $nama_bulan = 'OKT'; break;
  53. case '11': $nama_bulan = 'NOV'; break;
  54. case '12': $nama_bulan = 'DES'; break;
  55. default : $nama_bulan = '-'; break;
  56. }
  57. return $nama_bulan;
  58. }
  59.  
  60. public static function get_bulan_lengkap($bulan)
  61. {
  62. switch ($bulan)
  63. {
  64. case '01': $nama_bulan = 'JANUARI'; break;
  65. case '02': $nama_bulan = 'FEBRUARI'; break;
  66. case '03': $nama_bulan = 'MARET'; break;
  67. case '04': $nama_bulan = 'APRIL'; break;
  68. case '05': $nama_bulan = 'MEI'; break;
  69. case '06': $nama_bulan = 'JUNI'; break;
  70. case '07': $nama_bulan = 'JULI'; break;
  71. case '08': $nama_bulan = 'AGUSTUS'; break;
  72. case '09': $nama_bulan = 'SEPTEMBER'; break;
  73. case '10': $nama_bulan = 'OKTOBER'; break;
  74. case '11': $nama_bulan = 'NOVEMBER'; break;
  75. case '12': $nama_bulan = 'DESEMBER'; break;
  76. default : $nama_bulan = '-'; break;
  77. }
  78. return $nama_bulan;
  79. }
  80.  
  81. public static function swref($admin, $norefs)
  82. {
  83. $noref = strlen($norefs) < 30 ? self::randomStrings(32) : $norefs;
  84.  
  85. if ($admin == 0) {
  86. $swref = '1BNS25'.substr($noref, 6, 26);
  87. } else {
  88. $swref = '0BNS25'.substr($noref, 6, 26);
  89. }
  90. return $swref;
  91. }
  92.  
  93. public static function randomStrings($length = 12)
  94. {
  95. $chars = 'ABCDEFGHIJKLMNPQRSTUVWXYZ123456789';
  96.  
  97. $str = '';
  98. for ($i = 0; $i < $length; $i++)
  99. {
  100. $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
  101. }
  102.  
  103. return $str;
  104. }
  105.  
  106. public static function randomNumber($length = 12)
  107. {
  108. $chars = '123456789';
  109.  
  110. $str = '';
  111. for ($i = 0; $i < $length; $i++) {
  112. $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
  113. }
  114. return $str;
  115. }
  116.  
  117. public static function spasi($jml, $char)
  118. {
  119. $result = '';
  120. $selisih = $jml - strlen($char);
  121.  
  122. if($selisih < 0)
  123. {
  124. $result = substr($char, 0, $jml);
  125. }
  126. else
  127. {
  128. $result = $char;
  129.  
  130. for($x=1;$x <= $selisih;$x++)
  131. {
  132. $result = $result.' ';
  133. }
  134. }
  135.  
  136. return $result;
  137. }
  138.  
  139. public static function spasiKanan($jml, $char)
  140. {
  141. $result = '';
  142. $spasi = '';
  143. $selisih = $jml - strlen($char);
  144.  
  145. if($selisih < 0)
  146. {
  147. $result = substr($char, 0, $jml);
  148. }
  149. else
  150. {
  151. $result = $char;
  152.  
  153. for($x=1;$x <= $selisih;$x++)
  154. {
  155. $spasi = $spasi.' ';
  156. }
  157.  
  158. $result = $spasi.$result;
  159. }
  160.  
  161. return $result;
  162. }
  163.  
  164. // FUNGSI TERBILANG KE RUPIAH => http://harviacode.com/2014/09/23/membuat-fungsi-terbilang-php/
  165. public static function kekata($x)
  166. {
  167. $x = abs($x);
  168. $angka = array("", "satu", "dua", "tiga", "empat", "lima",
  169. "enam", "tujuh", "delapan", "sembilan", "sepuluh", "sebelas");
  170. $temp = "";
  171. if ($x <12) {
  172. $temp = " ". $angka[$x];
  173. } else if ($x <20) {
  174. $temp = self::kekata($x - 10). " belas";
  175. } else if ($x <100) {
  176. $temp = self::kekata($x/10)." puluh". self::kekata($x % 10);
  177. } else if ($x <200) {
  178. $temp = " seratus" . self::kekata($x - 100);
  179. } else if ($x <1000) {
  180. $temp = self::kekata($x/100) . " ratus" . self::kekata($x % 100);
  181. } else if ($x <2000) {
  182. $temp = " seribu" . self::kekata($x - 1000);
  183. } else if ($x <1000000) {
  184. $temp = self::kekata($x/1000) . " ribu" . self::kekata($x % 1000);
  185. } else if ($x <1000000000) {
  186. $temp = self::kekata($x/1000000) . " juta" . self::kekata($x % 1000000);
  187. } else if ($x <1000000000000) {
  188. $temp = self::kekata($x/1000000000) . " milyar" . self::kekata(fmod($x,1000000000));
  189. } else if ($x <1000000000000000) {
  190. $temp = self::kekata($x/1000000000000) . " trilyun" . self::kekata(fmod($x,1000000000000));
  191. }
  192. return $temp;
  193. }
  194.  
  195.  
  196. public static function terbilang($x, $style=4)
  197. {
  198. if($x<0) {
  199. $hasil = "minus ". trim(self::kekata($x));
  200. } else {
  201. $hasil = trim(self::kekata($x));
  202. }
  203. switch ($style) {
  204. case 1:
  205. $hasil = strtoupper($hasil);
  206. break;
  207. case 2:
  208. $hasil = strtolower($hasil);
  209. break;
  210. case 3:
  211. $hasil = ucwords($hasil);
  212. break;
  213. default:
  214. $hasil = ucfirst($hasil);
  215. break;
  216. }
  217. return $hasil;
  218. }
  219. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement