paymenr order

This commit is contained in:
2024-11-03 21:30:28 +05:00
parent 1c650710b1
commit 62ea6af082
27 changed files with 27049 additions and 3 deletions

View File

@@ -0,0 +1,110 @@
<?php
namespace App\Modules\TurkmenNumberFormatter\Repositories;
class TurkmenNumberFormatter
{
// Define number mappings
private static $units = ['', 'bir', 'iki', 'üç', 'dört', 'bäş', 'alty', 'ýedi', 'sekiz', 'dokuz'];
private static $tens = ['', 'on', 'ýigrimi', 'otuz', 'kyrk', 'elli', 'altmyş', 'ýetmiş', 'segsen', 'togsan'];
private static $hundreds = ['', 'ýüz', 'iki ýüz', 'üç ýüz', 'dört ýüz', 'bäş ýüz', 'alty ýüz', 'ýedi ýüz', 'sekiz ýüz', 'dokuz ýüz'];
private static $largeNumbers = ['', 'müň', 'million', 'milliard', 'trillion'];
/**
* Main method to format a given amount in Turkmen.
*
* @param float $amount The amount to format.
* @return string The amount in written Turkmen format.
*/
public static function format($amount)
{
// Split the amount into whole and fractional parts
[$whole, $fraction] = explode('.', number_format($amount, 2, '.', ''));
// Convert the whole part
$wholeWords = self::convertWholePart($whole);
// Convert the fractional part
$fractionWords = self::convertFractionalPart($fraction);
return trim($wholeWords.' '.$fractionWords);
}
/**
* Convert the whole part of the number.
*
* @param int $whole The whole part of the number.
* @return string The converted whole part in Turkmen.
*/
private static function convertWholePart($whole)
{
$words = '';
$level = 0;
while ($whole > 0) {
$part = $whole % 1000;
$whole = (int) ($whole / 1000);
if ($part > 0) {
$words = self::convertToWords($part).' '.self::$largeNumbers[$level].' '.$words;
}
$level++;
}
return trim($words).' manat';
}
/**
* Convert the fractional part of the number.
*
* @param int $fraction The fractional part of the number.
* @return string The converted fractional part in Turkmen.
*/
private static function convertFractionalPart($fraction)
{
if ($fraction <= 0) {
return '';
}
$fractionTens = (int) ($fraction / 10);
$fractionUnits = $fraction % 10;
$words = '';
$words .= ($fractionTens > 0 ? self::$tens[$fractionTens].' ' : '');
$words .= ($fractionUnits > 0 ? self::$units[$fractionUnits].' ' : '');
return trim($words).' teňňe';
}
/**
* Convert a number up to 999 to Turkmen words.
*
* @param int $num The number to convert.
* @return string The converted number in Turkmen.
*/
private static function convertToWords($num)
{
$words = '';
if ($num >= 100) {
$hundredsPart = (int) ($num / 100);
$num %= 100;
$words .= self::$hundreds[$hundredsPart].' ';
}
if ($num >= 10) {
$tensPart = (int) ($num / 10);
$num %= 10;
$words .= self::$tens[$tensPart].' ';
}
if ($num > 0) {
$words .= self::$units[$num].' ';
}
return trim($words);
}
}