<?php
namespace App\Utils\DigitsToLetters; class SA extends GeneralAbstract { public function getText() { $val = ""; $andStr = ""; $pointStr = ""; $endStr = ""; list($wholeNo, $points) = explode(".", $this->value); $wholeNoText = trim($this->translateWholeNumber($wholeNo)); if ($wholeNoText) { $wholeNoText .= $this->separator.$this->currencyName; } if ($points) { if ($wholeNo) { $andStr = "و".$this->separator; } $pointStr = trim($this->translateWholeNumber($points)); if ($pointStr) { $pointStr .= $this->separator.$this->currencySubdivision; } } $val = sprintf("%s{$this->separator}%s%s{$this->separator}%s", $wholeNoText, $andStr, $pointStr, $endStr); return trim($val, $this->separator); } private function translateWholeNumber($number) { $word = ""; $signStr = ($number<0) ? "-":""; $numberAbs = abs($number); $beginsZero = false; $isDone = false; $dblAmt = sprintf("%.2f", $numberAbs); if ($dblAmt != 0) { if (strpos($numberAbs, "0") === 0) { $beginsZero = true; } $numDigits = strlen($numberAbs); $pos = 0; $place = ""; switch ($numDigits) { case 1: $word = $this->ones($numberAbs); $isDone = true; break; case 2: $word = $this->tens($numberAbs); $isDone = true; break; case 3: $pos = ($numDigits % 3) + 1; $place = " مائة "; break; case 4: case 5: case 6: $pos = ($numDigits % 4) + 1; $place = " ألف "; break; case 7: case 8: case 9: $pos = ($numDigits % 7) + 1; $place = " مليون "; break; case 10: $pos = ($numDigits % 10) + 1; $place = " مليار "; break; default: $isDone = true; break; } if (!$isDone) { $word = $this->translateWholeNumber(substr($numberAbs, 0, $pos)) . $place . $this->translateWholeNumber(substr($numberAbs, $pos)); if ($beginsZero) { $word = $this->separator . "و" . $this->separator . trim($word, $this->separator); } } if (trim($word)==trim($place)) { $word = ""; } if ($word) { $word = $signStr.$word; } } return trim($word); } private function tens($digit) { $digt = (int)$digit; $name = null; switch ($digt) { case 10: $name = "عشرة"; break; case 11: $name = "أحد عشر"; break; case 12: $name = "اثني عشر"; break; case 13: $name = "ثلاثة عشر"; break; case 14: $name = "أربعة عشرة"; break; case 15: $name = "خمسة عشر"; break; case 16: $name = "السادس عشر"; break; case 17: $name = "سبعة عشر"; break; case 18: $name = "الثامنة عشر"; break; case 19: $name = "تسعة عشر"; break; case 20: $name = "عشرين"; break; case 30: $name = "ثلاثون"; break; case 40: $name = "أربعون"; break; case 50: $name = "خمسون"; break; case 60: $name = "ستون"; break; case 70: $name = "سبعون"; break; case 80: $name = "ثمانون"; break; case 90: $name = "تسعين"; break; default: if ($digt > 0) { $name = ($this->tens(substr($digit, 0, 1) . "0") . $this->separator) . $this->ones(substr($digit, 1)); } break; } return $name; } private function ones($digit) { $digt = (int)$digit; $name = ""; switch ($digt) { case 1: $name = "واحد"; break; case 2: $name = "اثنين"; break; case 3: $name = "ثلاثة"; break; case 4: $name = "أربعة"; break; case 5: $name = "خمسة"; break; case 6: $name = "ستة"; break; case 7: $name = "سبعة"; break; case 8: $name = "ثمانية"; break; case 9: $name = "تسع"; break; } return $name; } } 