{"id":21559642,"url":"https://github.com/skeeks-cms/cms-money","last_synced_at":"2026-05-22T05:13:04.195Z","repository":{"id":47898221,"uuid":"133651508","full_name":"skeeks-cms/cms-money","owner":"skeeks-cms","description":"Module for working with money and currency","archived":false,"fork":false,"pushed_at":"2023-06-05T11:25:08.000Z","size":59,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-18T06:53:04.592Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://cms.skeeks.com","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/skeeks-cms.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-05-16T10:48:04.000Z","updated_at":"2023-05-11T11:30:45.000Z","dependencies_parsed_at":"2024-11-24T09:08:17.989Z","dependency_job_id":"3af05619-49ff-49c9-a9dd-d0e7dee6e932","html_url":"https://github.com/skeeks-cms/cms-money","commit_stats":{"total_commits":49,"total_committers":1,"mean_commits":49.0,"dds":0.0,"last_synced_commit":"b5f6b4ade9681ad618d2b50eca3b72fdc2ec6e6b"},"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skeeks-cms%2Fcms-money","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skeeks-cms%2Fcms-money/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skeeks-cms%2Fcms-money/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skeeks-cms%2Fcms-money/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/skeeks-cms","download_url":"https://codeload.github.com/skeeks-cms/cms-money/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244155506,"owners_count":20407362,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-24T09:08:10.031Z","updated_at":"2026-05-22T05:12:59.172Z","avatar_url":"https://github.com/skeeks-cms.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Module for working with money and currency\n===================================\n\nInfo\n-------------------\n\nМодуль для работы с деньгами и валютой.\n\nОсновная работа была в том, чтобы появилась некоторая прозрачная работа с деньгами.\nТипичны пример, который мы прозрачно решаем в этой библиотеке.\n(10$ + 154руб + 12$) = рузальтат нужно показать в GBP, для de_DE локали\n\nExample:\n\n```\nuse \\skeeks\\cms\\money\\Money;\n\n$result  = new Money('0', \"RUB\");\n\n$money1  = new Money('10', \"USD\");\n$money2 = new Money('154', \"EUR\");\n$money3 = new Money('12', \"RUB\");\n\n$result-\u003eadd($money1)-\u003eadd($money2)-\u003eadd($money3);\n\n$result-\u003econvertToCurrency('GBP');\n\necho (string) $result; // \necho $result-\u003eformat();\n\n$formatter = new IntlFormatter('de_DE');\n\n```\n\n\nInstallation\n------------\n\nThe preferred way to install this extension is through [composer](http://getcomposer.org/download/).\n\nEither run\n\n```\nphp composer.phar require --prefer-dist skeeks/cms-money \"*\"\n```\n\nor add\n\n```\n\"skeeks/cms-money\": \"*\"\n```\n\nInstall migrations\n\n```\nphp yii migrate --migrationPath=vendor/skeeks/cms-money/migrations\n```\n\nConfiguration\n----------\n\n```php\n\n'components' =\u003e\n[\n 'money' =\u003e [\n     'class'         =\u003e 'skeeks\\cms\\money\\MoneyComponent',\n ],\n 'i18n' =\u003e [\n     'translations' =\u003e\n     [\n         'skeeks/money' =\u003e [\n             'class'             =\u003e 'yii\\i18n\\PhpMessageSource',\n             'basePath'          =\u003e '@skeeks/cms/money/messages',\n             'fileMap' =\u003e [\n                 'skeeks/money' =\u003e 'main.php',\n             ],\n         ]\n     ]\n ],\n ],\n 'modules' =\u003e\n [\n    'money' =\u003e [\n        'class'         =\u003e 'skeeks\\cms\\money\\Module',\n    ]\n ]\n\n```\n\n# Примеры и использование\n\n## Оригинальные примеры\n\n#### Creating a Money object and accessing its monetary value\n\n```php\nuse skeeks\\cms\\modules\\money\\Currency;\nuse skeeks\\cms\\modules\\money\\Money;\n\n// Create Money object that represents 1 EUR\n$m = new Money(100, new Currency('EUR'));\n\n// Access the Money object's monetary value\nprint $m-\u003egetAmount();\n```\n\nThe code above produces the output shown below:\n\n    100\n\n#### Creating a Money object from a string value\n\n```php\nuse skeeks\\cms\\modules\\money\\Currency;\nuse skeeks\\cms\\modules\\money\\Money;\n\n// Create Money object that represents 12.34 EUR\n$m = Money::fromString('12.34', new Currency('EUR'))\n\n// Access the Money object's monetary value\nprint $m-\u003egetAmount();\n```\n\nThe code above produces the output shown below:\n\n    1234\n#### Formatting a Money object using PHP's built-in NumberFormatter\n\n```php\nuse skeeks\\cms\\modules\\money\\Currency;\nuse skeeks\\cms\\modules\\money\\Money;\nuse skeeks\\cms\\modules\\money\\IntlFormatter;\n\n// Create Money object that represents 1 EUR\n$m = new Money(100, new Currency('EUR'));\n\n// Format a Money object using PHP's built-in NumberFormatter (German locale)\n$f = new IntlFormatter('de_DE');\n\nprint $f-\u003eformat($m);\n```\n\nThe code above produces the output shown below:\n\n    1,00 €\n\n#### Basic arithmetic using Money objects\n\n```php\nuse skeeks\\cms\\modules\\money\\Currency;\nuse skeeks\\cms\\modules\\money\\Money;\n\n// Create two Money objects that represent 1 EUR and 2 EUR, respectively\n$a = new Money(100, new Currency('EUR'));\n$b = new Money(200, new Currency('EUR'));\n\n// Negate a Money object\n$c = $a-\u003enegate();\nprint $c-\u003egetAmount();\n\n// Calculate the sum of two Money objects\n$c = $a-\u003eadd($b);\nprint $c-\u003egetAmount();\n\n// Calculate the difference of two Money objects\n$c = $b-\u003esubtract($a);\nprint $c-\u003egetAmount();\n\n// Multiply a Money object with a factor\n$c = $a-\u003emultiply(2);\nprint $c-\u003egetAmount();\n```\n\nThe code above produces the output shown below:\n\n    -100\n    300\n    100\n    200\n\n#### Comparing Money objects\n\n```php\nuse skeeks\\cms\\modules\\money\\Currency;\nuse skeeks\\cms\\modules\\money\\Money;\n\n// Create two Money objects that represent 1 EUR and 2 EUR, respectively\n$a = new Money(100, new Currency('EUR'));\n$b = new Money(200, new Currency('EUR'));\n\nvar_dump($a-\u003elessThan($b));\nvar_dump($a-\u003egreaterThan($b));\n\nvar_dump($b-\u003elessThan($a));\nvar_dump($b-\u003egreaterThan($a));\n\nvar_dump($a-\u003ecompareTo($b));\nvar_dump($a-\u003ecompareTo($a));\nvar_dump($b-\u003ecompareTo($a));\n```\n\nThe code above produces the output shown below:\n\n    bool(true)\n    bool(false)\n    bool(false)\n    bool(true)\n    int(-1)\n    int(0)\n    int(1)\n\nThe `compareTo()` method returns an integer less than, equal to, or greater than\nzero if the value of one `Money` object is considered to be respectively less\nthan, equal to, or greater than that of another `Money` object.\n\nYou can use the `compareTo()` method to sort an array of `Money` objects using\nPHP's built-in sorting functions:\n\n```php\nuse skeeks\\cms\\modules\\money\\Currency;\nuse skeeks\\cms\\modules\\money\\Money;\n\n$m = array(\n    new Money(300, new Currency('EUR')),\n    new Money(100, new Currency('EUR')),\n    new Money(200, new Currency('EUR'))\n);\n\nusort(\n    $m,\n    function ($a, $b) { return $a-\u003ecompareTo($b); }\n);\n\nforeach ($m as $_m) {\n    print $_m-\u003egetAmount() . \"\\n\";\n}\n```\n\nThe code above produces the output shown below:\n\n    100\n    200\n    300\n\n#### Allocate the monetary value represented by a Money object among N targets\n\n```php\nuse skeeks\\cms\\modules\\money\\Currency;\nuse skeeks\\cms\\modules\\money\\Money;\n\n// Create a Money object that represents 0,99 EUR\n$a = new Money(99, new Currency('EUR'));\n\nforeach ($a-\u003eallocateToTargets(10) as $t) {\n    print $t-\u003egetAmount() . \"\\n\";\n}\n```\n\nThe code above produces the output shown below:\n\n    10\n    10\n    10\n    10\n    10\n    10\n    10\n    10\n    10\n    9\n\n#### Allocate the monetary value represented by a Money object using a list of ratios\n\n```php\nuse skeeks\\cms\\modules\\money\\Currency;\nuse skeeks\\cms\\modules\\money\\Money;\n\n// Create a Money object that represents 0,05 EUR\n$a = new Money(5, new Currency('EUR'));\n\nforeach ($a-\u003eallocateByRatios(array(3, 7)) as $t) {\n    print $t-\u003egetAmount() . \"\\n\";\n}\n```\n\nThe code above produces the output shown below:\n\n    2\n    3\n\n#### Extract a percentage (and a subtotal) from the monetary value represented by a Money object\n\n```php\nuse skeeks\\cms\\modules\\money\\Currency;\nuse skeeks\\cms\\modules\\money\\Money;\n\n// Create a Money object that represents 100,00 EUR\n$original = new Money(10000, new Currency('EUR'));\n\n// Extract 21% (and the corresponding subtotal)\n$extract = $original-\u003eextractPercentage(21);\n\nprintf(\n    \"%d = %d + %d\\n\",\n    $original-\u003egetAmount(),\n    $extract['subtotal']-\u003egetAmount(),\n    $extract['percentage']-\u003egetAmount()\n);\n```\n\nThe code above produces the output shown below:\n\n    10000 = 8265 + 1735\n\nPlease note that this extracts the percentage out of a monetary value where the\npercentage is already included. If you want to get the percentage of the\nmonetary value you should use multiplication (`multiply(0.21)`, for instance,\nto calculate 21% of a monetary value represented by a Money object) instead.\n\n\n\n\nLinks\n-------\n* [Web site](https://cms.skeeks.com)\n* [Author](https://skeeks.com)\n* [ChangeLog](https://github.com/skeeks-cms/cms-money/blob/master/CHANGELOG.md)\n\n___\n\n\u003e [![skeeks!](https://skeeks.com/img/logo/logo-no-title-80px.png)](https://skeeks.com)  \n\u003ci\u003eSkeekS CMS (Yii2) — quickly, easily and effectively!\u003c/i\u003e  \n[skeeks.com](https://skeeks.com) | [cms.skeeks.com](https://cms.skeeks.com)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskeeks-cms%2Fcms-money","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fskeeks-cms%2Fcms-money","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskeeks-cms%2Fcms-money/lists"}