2017 © Pedro Peláez
 

kohana-module jam-monetary

A Jam Field to transparently use 'monetary' as a jam field, and have currency exchange arithmetic out of the box

image

openbuildings/jam-monetary

A Jam Field to transparently use 'monetary' as a jam field, and have currency exchange arithmetic out of the box

  • Friday, October 13, 2017
  • by hkdobrev
  • Repository
  • 11 Watchers
  • 1 Stars
  • 42,192 Installations
  • PHP
  • 4 Dependents
  • 3 Suggesters
  • 0 Forks
  • 1 Open issues
  • 27 Versions
  • 11 % Grown

The README.md

Jam Monetary

A Jam Field to transparently use "monetary" as a Jam field, and have currency exchange arithmetic out of the box, (*1)

Build Status Scrutinizer Quality Score Code Coverage Latest Stable Version, (*2)

Usage

In your model, define the field as usual:, (*3)

``` php class Model_Product extends Jam_Model {, (*4)

static public function initialize(Jam_Meta $meta)
{
    $meta
        ->fields(array(
            'id' => Jam::field('primary'),
            'name' => Jam::field('string'),
            'price' => Jam::field('price', array('default_currency' => 'GBP')),
            'discount_price' => Jam::field('price'),
        ));
}

}, (*5)


And to use it you can: ``` php $product = Jam::build('product', array('price' => 10)); echo $product->price->amount(); // will output 10.00 float echo $product->price->currency(); // will output GBP - the price currency echo $product->price; // will output '10.00' echo $product->price->as_string(); // will output '10.00' echo $product->price->as_string('USD'); // will output '10.00' echo $product->price->in('USD'); // will output 18.12 float echo $product->price->humanize(); // will output '£10.00' echo $product->price->humanize('USD'); // will output '$18.12' echo $product->price->as_html(); // will output '£10.00' echo $product->price->as_html('USD'); // will output '$18.12' echo $product->price->as_html('EUR'); // will output '€18.12' // Price arithmetic $product->price->add(10); // Add 2 prices together, doing the exchange conversion arithmetic on the fly $product->price->add(new Jam_Price(20, 'EUR')); // Adding more than one price $product->price->add(new Jam_Price(20, 'EUR'), new Jam_Price(10, 'GBP'), 12.32);

Methods

  • in($currency) : display the amount in the specified currency, put through number_format with 2 digits after the dot
  • as_string($currency = NULL) : return the number_format() on the price's amount, with 2 digits after the dot.
  • humanize($currency = NULL) : display the amount with showing the proper currency sign in the correct position
  • as_html($currency = NULL) : same as humanize(), but with HTML entities support
  • add(... prices) : add one or more price values to this price (you can add negative prices in order to substract)

Automatic currency and monetary values

If the model has a method currency(), then each time a price object is requested, the result of this method is used for the price currency. That will allow you storing the currency alongside the amount iteself in the model, (*6)

The same goes for a monetary() method - if its there in the model, then it'll be used for all the conversions., (*7)

Validators

There are 2 out of the box validator rules - one for currency and one for price., (*8)

The price rule is basically a numeric rule, which performes the checks on the price's amount., (*9)

The currency validator is a choice validator, with the currencies of the world preselected in the "in" variable., (*10)

``` php class Model_Product extends Jam_Model {, (*11)

static public function initialize(Jam_Meta $meta)
{
    $meta
        ->fields(array(
            'id' => Jam::field('primary'),
            'price' => Jam::field('price'),
            'currency' => Jam::field('string'),
        ))
        ->validator('price' => array('price' => array('greater_than' => 10)))
        ->validator('currency' => array('currency' => TRUE));
}

} ```, (*12)

License

Copyright (c) 2012-2013, OpenBuildings Ltd. Developed by Ivan Kerin as part of clippings.com, (*13)

Under BSD-3-Clause license, read LICENSE file., (*14)

The Versions

13/10 2017

dev-master

9999999-dev https://github.com/OpenBuildings/jam-monetary

A Jam Field to transparently use 'monetary' as a jam field, and have currency exchange arithmetic out of the box

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

money exchange kohana price monetary jam

13/10 2017

0.1.24

0.1.24.0 https://github.com/OpenBuildings/jam-monetary

A Jam Field to transparently use 'monetary' as a jam field, and have currency exchange arithmetic out of the box

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

money exchange kohana price monetary jam

13/10 2017

dev-fix-price-field-default-string-conversation

dev-fix-price-field-default-string-conversation https://github.com/OpenBuildings/jam-monetary

A Jam Field to transparently use 'monetary' as a jam field, and have currency exchange arithmetic out of the box

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

money exchange kohana price monetary jam

12/10 2017

0.1.23

0.1.23.0 https://github.com/OpenBuildings/jam-monetary

A Jam Field to transparently use 'monetary' as a jam field, and have currency exchange arithmetic out of the box

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

money exchange kohana price monetary jam

26/08 2017

0.1.22

0.1.22.0 https://github.com/OpenBuildings/jam-monetary

A Jam Field to transparently use 'monetary' as a jam field, and have currency exchange arithmetic out of the box

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

money exchange kohana price monetary jam

18/09 2016

0.1.21

0.1.21.0 https://github.com/OpenBuildings/jam-monetary

A Jam Field to transparently use 'monetary' as a jam field, and have currency exchange arithmetic out of the box

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

money exchange kohana price monetary jam

08/12 2015

0.1.20

0.1.20.0 https://github.com/OpenBuildings/jam-monetary

A Jam Field to transparently use 'monetary' as a jam field, and have currency exchange arithmetic out of the box

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

money exchange kohana price monetary jam

09/02 2015

0.1.19

0.1.19.0 https://github.com/OpenBuildings/jam-monetary

A Jam Field to transparently use 'monetary' as a jam field, and have currency exchange arithmetic out of the box

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

money exchange kohana price monetary jam

06/01 2014

0.1.18

0.1.18.0 https://github.com/OpenBuildings/jam-monetary

A Jam Field to transparently use 'monetary' as a jam field, and have currency exchange arithmetic out of the box

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

money exchange kohana price monetary jam

06/01 2014

0.1.17

0.1.17.0 https://github.com/OpenBuildings/jam-monetary

A Jam Field to transparently use 'monetary' as a jam field, and have currency exchange arithmetic out of the box

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

money exchange kohana price monetary jam

29/10 2013

0.1.16

0.1.16.0 https://github.com/OpenBuildings/jam-monetary

A Jam Field to transparently use 'monetary' as a jam field, and have currency exchange arithmetic out of the box

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

money exchange kohana price monetary jam

29/10 2013

0.1.15

0.1.15.0 https://github.com/OpenBuildings/jam-monetary

A Jam Field to transparently use 'monetary' as a jam field, and have currency exchange arithmetic out of the box

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

money exchange kohana price monetary jam

28/10 2013

0.1.14

0.1.14.0 https://github.com/OpenBuildings/jam-monetary

A Jam Field to transparently use 'monetary' as a jam field, and have currency exchange arithmetic out of the box

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

money exchange kohana price monetary jam

14/10 2013

0.1.13

0.1.13.0 https://github.com/OpenBuildings/jam-monetary

A Jam Field to transparently use 'monetary' as a jam field, and have currency exchange arithmetic out of the box

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

money exchange kohana price monetary jam

10/10 2013

0.1.12

0.1.12.0 https://github.com/OpenBuildings/jam-monetary

A Jam Field to transparently use 'monetary' as a jam field, and have currency exchange arithmetic out of the box

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

money exchange kohana price monetary jam

10/10 2013

0.1.11

0.1.11.0 https://github.com/OpenBuildings/jam-monetary

A Jam Field to transparently use 'monetary' as a jam field, and have currency exchange arithmetic out of the box

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

money exchange kohana price monetary jam

04/10 2013

0.1.10

0.1.10.0 https://github.com/OpenBuildings/jam-monetary

A Jam Field to transparently use 'monetary' as a jam field, and have currency exchange arithmetic out of the box

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

money exchange kohana price monetary jam

20/09 2013

0.1.9

0.1.9.0 https://github.com/OpenBuildings/jam-monetary

A Jam Field to transparently use 'monetary' as a jam field, and have currency exchange arithmetic out of the box

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

money exchange kohana price monetary jam

10/09 2013

0.1.8

0.1.8.0 https://github.com/OpenBuildings/jam-monetary

A Jam Field to transparently use 'monetary' as a jam field, and have currency exchange arithmetic out of the box

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

money exchange kohana price monetary jam

09/09 2013

0.1.7

0.1.7.0 https://github.com/OpenBuildings/jam-monetary

A Jam Field to transparently use 'monetary' as a jam field, and have currency exchange arithmetic out of the box

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

money exchange kohana price monetary jam

09/09 2013

0.1.6

0.1.6.0 https://github.com/OpenBuildings/jam-monetary

Closuretable behavior

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

money exchange kohana price monetary jam

07/09 2013

0.1.5

0.1.5.0 https://github.com/OpenBuildings/jam-monetary

Closuretable behavior

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

money exchange kohana price monetary jam

07/09 2013

0.1.4

0.1.4.0 https://github.com/OpenBuildings/jam-monetary

Closuretable behavior

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

money exchange kohana price monetary jam

07/09 2013

0.1.3

0.1.3.0 https://github.com/OpenBuildings/jam-monetary

Closuretable behavior

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

money exchange kohana price monetary jam

07/09 2013

0.1.2

0.1.2.0 https://github.com/OpenBuildings/jam-monetary

Closuretable behavior

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

money exchange kohana price monetary jam

05/09 2013

0.1.1

0.1.1.0 https://github.com/OpenBuildings/jam-monetary

Closuretable behavior

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

money exchange kohana price monetary jam

05/09 2013

0.1.0

0.1.0.0 https://github.com/OpenBuildings/jam-monetary

Closuretable behavior

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

money exchange kohana price monetary jam