123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace App\Services;
  3. class HelperService
  4. {
  5. public static function addPrevValue($array)
  6. {
  7. $i = [];
  8. for ($j = 0; $j <= count($array) - 1; $j++) {
  9. if ($j === 0) {
  10. array_push($i, $array[$j]);
  11. } else {
  12. array_push($i, $i[$j - 1] + $array[$j]);
  13. }
  14. }
  15. return $i;
  16. }
  17. public static function setRupiahFormat($num, $sign = false)
  18. {
  19. if ($sign) {
  20. if ($num < 0) {
  21. return '-Rp' . number_format(abs($num), 0, ',', '.');
  22. } else {
  23. return 'Rp' . number_format($num, 0, ',', '.');
  24. }
  25. } else {
  26. if ($num < 0) {
  27. return '-' . number_format(abs($num), 0, ',', '.');
  28. } else {
  29. return number_format($num, 0, ',', '.');
  30. }
  31. }
  32. }
  33. }