本文整理汇总了PHP中Money类的典型用法代码示例。如果您正苦于以下问题:PHP Money类的具体用法?PHP Money怎么用?PHP Money使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Money类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: addMoney
public function addMoney(Money $m)
{
if ($this->currency() == $m->currency()) {
return new Money($this->amount() + $m->amount(), $this->currency());
}
return MoneyBag::create($this, $m);
}
开发者ID:dalinhuang,项目名称:shopexts,代码行数:7,代码来源:Money.php
示例2: convert
/**
* Converts Money from base to counter currency.
*
* @param Money $money
* @param int $roundingMode
*
* @return Money
*
* @throws \InvalidArgumentException If $money's currency is not equal to base currency
*/
public function convert(Money $money, $roundingMode = Money::ROUND_HALF_UP)
{
if (!$money->getCurrency()->equals($this->baseCurrency)) {
throw new \InvalidArgumentException('The Money has the wrong currency');
}
return $money->convert($this->counterCurrency, $this->conversionRatio, $roundingMode);
}
开发者ID:barryvdh,项目名称:money,代码行数:17,代码来源:CurrencyPair.php
示例3: add
/**
* @param money $amount
* @return money
*/
public function add(Money $amount)
{
if (!$this->currency->equals($amount->getCurrency())) {
throw new \InvalidArgumentException('Currency mismatch');
}
return new Money($this->currency, $this->amount + $amount->getValue());
}
开发者ID:rocketpastsix,项目名称:OOPExample,代码行数:11,代码来源:money.php
示例4: testShouldFail
public function testShouldFail()
{
$a = new Money(9);
//$b = $a->negate();
//$this->assertEquals(-9, $b->getAmount());
$this->assertEquals(-8, $a->getAmount());
}
开发者ID:redace85,项目名称:phpunit-playground,代码行数:7,代码来源:MoneyTest.php
示例5: price_for_display
public static function price_for_display($price)
{
$currency = ShopConfig::get_site_currency();
$field = new Money("Price");
$field->setAmount($price);
$field->setCurrency($currency);
return $field;
}
开发者ID:helpfulrobot,项目名称:silvershop-core,代码行数:8,代码来源:ShopTools.php
示例6: convert
/** @return Money */
public function convert(Money $money)
{
if (!$money->getCurrency()->equals($this->counterCurrency)) {
throw new InvalidArgumentException("The Money has the wrong currency");
}
// @todo add rounding mode?
return new Money((int) round($money->getAmount() * $this->ratio), $this->baseCurrency);
}
开发者ID:SerdarSanri,项目名称:laravel-money,代码行数:9,代码来源:CurrencyPair.php
示例7: testCanBeNegated
public function testCanBeNegated()
{
// Arrange
$a = new Money(1);
// Act
$b = $a->negate();
// Assert
$this->assertEquals(-1, $b->getAmount());
}
开发者ID:bntptr,项目名称:training,代码行数:9,代码来源:MoneyTest.php
示例8: testSubstractionResult
public function testSubstractionResult()
{
// Arrange
$a = new Money();
// Act
$b = $a->substraction(2, 1);
// Assert
$this->assertEquals(1, $b);
}
开发者ID:ds0201,项目名称:devci,代码行数:9,代码来源:MoneyTest.php
示例9: testAdd
public function testAdd()
{
// Arrange
$a = new Money(600);
// Act
$a->add(66);
// Assert
$this->assertEquals(666, $a->getAmount());
}
开发者ID:edele,项目名称:travis-tryout,代码行数:9,代码来源:MoneyTest.php
示例10: testStringAmount
/**
* @covers ::evaluate
*/
public function testStringAmount()
{
$money = new Money();
$money->setValue(['amount' => '50', 'currency' => 'XTS']);
$this->assertTrue($money->isValid());
$obj = $money->evaluate();
$this->assertInstanceOf('SebastianBergmann\\Money\\Money', $obj);
$this->assertSame(50, $obj->getAmount());
$this->assertEquals(new \SebastianBergmann\Money\Currency('XTS'), $obj->getCurrency());
}
开发者ID:firehed,项目名称:inputobjects,代码行数:13,代码来源:MoneyTest.php
示例11: credit
public function credit($methodId, $typeId, $marketId, $presenterId, $userId, Money $cost, $entryUser, $referenceId)
{
$result = $this->saveCreate(array("ProductCredit" => array("market_id" => $marketId, "user_id" => $userId, "presenter_id" => $presenterId, "product_credit_type_id" => $typeId, "product_credit_entry_type_id" => $methodId, "product_credit_status_type_id" => self::STATUS_SETTLED, "entry_user" => $entryUser, "amount" => (string) $cost->makePositive(), "reference_id" => $referenceId)));
if ($result) {
syslog(LOG_DEBUG, "Credit\tLedger {$this->id}\t{$marketId} {$presenterId}\t{$userId}\t{$cost}");
} else {
syslog(LOG_DEBUG, "CreditERROR\tLedger\t{$marketId} {$presenterId}\t{$userId}\t{$cost}");
}
return $result;
}
开发者ID:kameshwariv,项目名称:testexample,代码行数:10,代码来源:ProductCredit.php
示例12: convert
/**
* @param Money $money
* @param Currency $counterCurrency
* @param int $roundingMode
*
* @return Money
*/
public function convert(Money $money, Currency $counterCurrency, $roundingMode = Money::ROUND_HALF_UP)
{
$baseCurrency = $money->getCurrency();
$ratio = $this->exchange->quote($baseCurrency, $counterCurrency)->getConversionRatio();
$baseCurrencySubunit = $this->currencies->subunitFor($baseCurrency);
$counterCurrencySubunit = $this->currencies->subunitFor($counterCurrency);
$subunitDifference = $baseCurrencySubunit - $counterCurrencySubunit;
$ratio = $ratio / pow(10, $subunitDifference);
$counterValue = $money->multiply($ratio, $roundingMode);
return new Money($counterValue->getAmount(), $counterCurrency);
}
开发者ID:squigg,项目名称:money,代码行数:18,代码来源:Converter.php
示例13: testSetValueAsMoney
public function testSetValueAsMoney()
{
$o = new MoneyFieldTest_Object();
$f = new MoneyField('MyMoney', 'MyMoney');
$m = new Money();
$m->setAmount(123456.78);
$m->setCurrency('EUR');
$f->setValue($m);
$f->saveInto($o);
$this->assertEquals(123456.78, $o->MyMoney->getAmount());
$this->assertEquals('EUR', $o->MyMoney->getCurrency());
}
开发者ID:ivoba,项目名称:silverstripe-framework,代码行数:12,代码来源:MoneyFieldTest.php
示例14: testAddCompositedExtraFields
public function testAddCompositedExtraFields()
{
$obj = new ManyManyListTest_ExtraFields();
$obj->write();
$money = new Money();
$money->setAmount(100);
$money->setCurrency('USD');
// the actual test is that this does not generate an error in the sql.
$obj->Clients()->add($obj, array('Worth' => $money, 'Reference' => 'Foo'));
$check = $obj->Clients()->First();
$this->assertEquals('Foo', $check->Reference, 'Basic scalar fields should exist');
$this->assertInstanceOf('Money', $check->Worth, 'Composite fields should exist on the record');
$this->assertEquals(100, $check->Worth->getAmount());
}
开发者ID:aaronleslie,项目名称:aaronunix,代码行数:14,代码来源:ManyManyListTest.php
示例15: display
/**
* @param Money|string|int|float $amount
* @param int $precision
* @return string
*/
public function display($amount, $precision = 2)
{
$amount = Utils::toStringAmount($amount);
$money = new Money($amount);
if ($this->isLeftSign) {
if ($money->isLessThan('0')) {
return '-' . $this->sign . $money->abs()->format($precision);
} else {
return $this->sign . $money->format($precision);
}
} else {
return $money->format($precision) . $this->sign;
}
}
开发者ID:superbalist,项目名称:php-money,代码行数:19,代码来源:Currency.php
示例16: Amount
/**
* Get Amount for this modifier so that it can be saved into an {@link Order} {@link Modification}.
* Get the FlatFeeTaxRate and multiply the rate by the Order subtotal.
*
* @see Modification
* @param Order $order
* @param Int $value ID for a {@link FlatFeeShippingRate}
* @return Money
*/
public function Amount($order, $value)
{
$currency = Modification::currency();
$amount = new Money();
$amount->setCurrency($currency);
$taxRate = DataObject::get_by_id('FlatFeeTaxRate', $value);
if ($taxRate && $taxRate->exists()) {
$amount->setAmount($order->SubTotal->getAmount() * ($taxRate->Rate / 100));
} else {
user_error("Cannot find flat tax rate for that ID.", E_USER_WARNING);
//TODO return meaningful error to browser in case error not shown
return;
}
return $amount;
}
开发者ID:helpfulrobot,项目名称:swipestripe-swipestripe,代码行数:24,代码来源:FlatFeeTax.php
示例17: testProductCreditSubtractions
public function testProductCreditSubtractions()
{
$presenterId = 1;
$userId = 1;
$this->assertEqual($this->ProductCredit->balance($presenterId, $userId), Money::fromFloat(70));
$transactionId = $this->ProductCredit->authorize(ProductCredit::METHOD_MANUAL, ProductCredit::TYPE_PURCHASE, $presenterId, $userId, Money::fromFloat(20), "Steve", "Manual Subtraction");
$this->assertEqual($transactionId !== false, true);
$productCredit = $this->ProductCredit->findById($transactionId);
unset($productCredit['ProductCredit']['id']);
unset($productCredit['ProductCredit']['modified']);
unset($productCredit['ProductCredit']['created']);
$this->assertArraysEqual($productCredit, array('ProductCredit' => array('user_id' => '1', 'presenter_id' => '1', 'product_credit_type_id' => '4', 'product_credit_entry_type_id' => '2', 'product_credit_status_type_id' => '1', 'entry_user' => 'Steve', 'reference_id' => 'Manual Subtraction', 'amount' => '-20.00')));
//Doesn't have enough money
$this->assertEqual($this->ProductCredit->balance($presenterId, $userId), Money::fromFloat(50));
$result = $this->ProductCredit->authorize(ProductCredit::METHOD_MANUAL, ProductCredit::TYPE_PURCHASE, $presenterId, $userId, Money::fromFloat(90), "Steve", "Manual Subtraction");
$this->assertEqual($result, false);
$this->assertEqual($this->ProductCredit->balance($presenterId, $userId), Money::fromFloat(50));
//Doesn't have enough money, but somehow hacked around it
// now you can set your expectations here
$this->ProductCreditBadBalance->expects($this->at(0))->method('balance')->will($this->returnValue(Money::fromFloat(30000)));
$this->ProductCreditBadBalance->expects($this->at(1))->method('balance')->will($this->returnValue(Money::fromFloat(-200)));
$result = $this->ProductCreditBadBalance->authorize(ProductCredit::METHOD_MANUAL, ProductCredit::TYPE_PURCHASE, $presenterId, $userId, Money::fromFloat(90), "Steve", "Manual Subtraction");
$this->assertEqual($result, false);
$this->assertEqual($this->ProductCredit->balance($presenterId, $userId), Money::fromFloat(50));
$productCredit = $this->ProductCredit->find("first", array("order" => "id desc"));
unset($productCredit['ProductCredit']['id']);
unset($productCredit['ProductCredit']['modified']);
unset($productCredit['ProductCredit']['created']);
$this->assertArraysEqual($productCredit, array('ProductCredit' => array('user_id' => '1', 'presenter_id' => '1', 'product_credit_type_id' => '4', 'product_credit_entry_type_id' => '2', 'product_credit_status_type_id' => '3', 'entry_user' => 'Steve', 'reference_id' => 'Manual Subtraction', 'amount' => '-90.00')));
}
开发者ID:kameshwariv,项目名称:testexample,代码行数:30,代码来源:ProductCreditTest.php
示例18: __construct
public function __construct($data = [], $connection = null)
{
$this->connection = $connection;
foreach (['id', 'order_reference', 'shop_system', 'customer_number', 'service_point_reference', 'weight_in_g'] as $prop) {
if (isset($data[$prop])) {
$this->{$prop} = $data[$prop];
}
}
foreach (['recipient', 'billing_contact'] as $prop) {
$this->{$prop} = isset($data[$prop]) ? new Address($data[$prop]) : null;
}
foreach (['subtotal', 'shipping_cost', 'tax_value'] as $prop) {
$this->{$prop} = isset($data[$prop]) ? Money::import($data[$prop]) : null;
}
$this->product = isset($data['product']) ? new Product($data['product'], $this->connection) : null;
if (isset($data['items'])) {
$this->items = [];
foreach ($data['items'] as $item_data) {
$this->items[] = new Item($item_data);
}
}
if (isset($data['shipments'])) {
$this->shipments = [];
foreach ($data['shipments'] as $url) {
$this->shipments[] = Shipment::import($url, $this->connection);
}
}
}
开发者ID:sendworks,项目名称:sendworks-php,代码行数:28,代码来源:Order.php
示例19: partyOrderTotals
/**
* Get Totals for order with previous/current month totals
* @param $Model
* @return array
*/
public function partyOrderTotals($Model)
{
/**
* Fields
*/
if ($Model->hostess_market_id == Market::MARKET_UNITED_KINGDOM) {
$fields = array('sum(Order.market_commissionable) as total, sum(Order.point_total) as points');
} else {
$fields = array('sum(Order.presenter_commissionable) as total, sum(Order.point_total) as points');
}
/**
* Order status conditions
*/
$status = array(Order::STATUS_ENTERED, Order::STATUS_PRINTED, Order::STATUS_SHIPPED, Order::STATUS_PROCESSING);
/**
* Order Total points
*/
$total = $Model->Order->find('first', array('fields' => $fields, 'conditions' => array('Order.party_id' => $Model->id, "Order.order_status_id" => $status)));
/**
* Order Double points
*/
$prev_total = $Model->Order->find('first', array('fields' => $fields, 'conditions' => array('Order.party_id' => $Model->id, 'MONTH(Order.date_completed)' => 2, "Order.order_status_id" => $status)));
$points = (int) $total['0']['points'];
$double_points = (int) $prev_total['0']['points'];
/**
* Returns array with previous month and current month points
*/
return array("total" => Money::fromString($total['0']['total']), "points" => $points, "double_points" => $double_points, "regular_points" => $points - $double_points);
}
开发者ID:kameshwariv,项目名称:testexample,代码行数:34,代码来源:PreviousPointsBehavior.php
示例20: testAddNoUser
public function testAddNoUser()
{
$this->assertEqual($this->ShoppingCart->addItem("US-1001-00", array("qty" => 1)), array("success" => true, "count" => 1));
$this->assertEqual($this->ShoppingCart->addItem("US-1012-00", array("qty" => 5, "US-1011-00" => array("skus" => array("US-1011-03" => 1, "US-1011-04" => 1, "US-1011-05" => 1, "US-1011-06" => 1)))), array("success" => true, "count" => 2));
$this->assertEqual($this->ShoppingCart->getCart(), array("total" => array("subtotal" => Money::fromFloat(274), "taxes" => Money::fromFloat(0), "shipping" => Money::fromFloat(0), "total" => Money::fromFloat(274), "commissionable_total" => Money::fromFloat(274), 'productcredits' => Money::fromFloat(0), 'charge' => Money::fromFloat(274), 'usedCoupons' => array(), 'totalItemCount' => 6, 'toFreeShipping' => Money::fromFloat(-174)), "0" => array("item_id" => '1', 'sku' => 'US-1001-00', "name" => "Presenter Starter Kit", "quantity" => 1, "price" => Money::fromFloat(99.0), "subtotal" => Money::fromFloat(99.0), "taxes" => Money::fromFloat(0), "originalsubtotal" => Money::fromFloat(99.0), "discount" => Money::fromFloat(0), "discounts" => array(), "shipping" => Money::fromFloat(10), "total" => Money::fromFloat(99.0), 'image' => array('name' => 'Main', 'thumb_path' => '/img/product_images/fake_thumb.jpg', 'file_path' => '/img/product_images/fake_main.jpg'), "included" => array(), 'options' => array()), "1" => array("item_id" => '3', 'sku' => 'US-1012-00', "name" => "Minerals Pigment Set", "quantity" => 5, "price" => Money::fromFloat(35.0), "subtotal" => Money::fromFloat(175), "taxes" => Money::fromFloat(0), "shipping" => Money::fromFloat(5.0), "total" => Money::fromFloat(175), "originalsubtotal" => Money::fromFloat(175), "discount" => Money::fromFloat(0), "discounts" => array(), 'image' => array('name' => 'Main', 'thumb_path' => '/img/product_images/US-1011-00-thumb.png', 'file_path' => '/img/product_images/US-1011-00.jpg'), 'included' => array(array('name' => 'Sassy', 'shortname' => 'Sassy', 'id' => '7', 'item_type_id' => '1', 'children_qty_required' => null, 'qty_required' => null, 'qty_purchased' => (int) 1, 'sku' => 'US-1011-03', 'image' => array('name' => 'main', 'thumb_path' => '/img/product_images/US-1011-03-thumb.jpg', 'file_path' => '/img/product_images/US-1011-03.jpg')), array('name' => 'Regal', 'shortname' => 'Regal', 'id' => '8', 'item_type_id' => '1', 'children_qty_required' => null, 'qty_required' => null, 'qty_purchased' => (int) 1, 'sku' => 'US-1011-04', 'image' => array('name' => 'main', 'thumb_path' => '/img/product_images/US-1011-04-thumb.jpg', 'file_path' => '/img/product_images/US-1011-04.jpg')), array('name' => 'Flirty', 'shortname' => 'Flirty', 'id' => '9', 'item_type_id' => '1', 'children_qty_required' => null, 'qty_required' => null, 'qty_purchased' => (int) 1, 'sku' => 'US-1011-05', 'image' => array('name' => 'main', 'thumb_path' => '/img/product_images/US-1011-05-thumb.jpg', 'file_path' => '/img/product_images/US-1011-05.jpg')), array('name' => 'Playful', 'shortname' => 'Playful', 'id' => '10', 'item_type_id' => '1', 'children_qty_required' => null, 'qty_required' => null, 'qty_purchased' => (int) 1, 'sku' => 'US-1011-06', 'image' => array('name' => 'main', 'thumb_path' => '/img/product_images/US-1011-06-thumb.jpg', 'file_path' => '/img/product_images/US-1011-06.jpg'))), 'options' => array('US-1011-00' => array('skus' => array('US-1011-03' => 1, 'US-1011-04' => 1, 'US-1011-05' => 1, 'US-1011-06' => 1))))));
$this->assertEqual($this->ShoppingCart->getCart("84003"), array("total" => array("subtotal" => Money::fromFloat(274), "taxes" => Money::fromFloat(18.5), "shipping" => Money::fromFloat(0), "total" => Money::fromFloat(292.5), "commissionable_total" => Money::fromFloat(274), 'productcredits' => Money::fromFloat(0), 'charge' => Money::fromFloat(292.5), 'usedCoupons' => array(), 'totalItemCount' => 6, 'toFreeShipping' => Money::fromFloat(-174)), "0" => array("item_id" => 1, 'sku' => 'US-1001-00', "name" => "Presenter Starter Kit", "quantity" => 1, "price" => Money::fromFloat(99.0), "subtotal" => Money::fromFloat(99.0), "taxes" => Money::fromFloat(6.68), "shipping" => Money::fromFloat(10), "originalsubtotal" => Money::fromFloat(99.0), "discount" => Money::fromFloat(0), "discounts" => array(), "total" => Money::fromFloat(105.68), 'image' => array('name' => 'Main', 'thumb_path' => '/img/product_images/fake_thumb.jpg', 'file_path' => '/img/product_images/fake_main.jpg'), "included" => array(), 'options' => array()), "1" => array("item_id" => 3, 'sku' => 'US-1012-00', "name" => "Minerals Pigment Set", "quantity" => 5, "price" => Money::fromFloat(35.0), "subtotal" => Money::fromFloat(175), "taxes" => Money::fromFloat(11.81), "shipping" => Money::fromFloat(5.0), "total" => Money::fromFloat(186.81), "originalsubtotal" => Money::fromFloat(175), "discount" => Money::fromFloat(0), "discounts" => array(), 'image' => array('name' => 'Main', 'thumb_path' => '/img/product_images/US-1011-00-thumb.png', 'file_path' => '/img/product_images/US-1011-00.jpg'), "included" => array(array('name' => 'Sassy', 'shortname' => 'Sassy', 'id' => '7', 'item_type_id' => '1', 'children_qty_required' => null, 'qty_required' => null, 'qty_purchased' => (int) 1, 'sku' => 'US-1011-03', 'image' => array('name' => 'main', 'thumb_path' => '/img/product_images/US-1011-03-thumb.jpg', 'file_path' => '/img/product_images/US-1011-03.jpg')), array('name' => 'Regal', 'shortname' => 'Regal', 'id' => '8', 'item_type_id' => '1', 'children_qty_required' => null, 'qty_required' => null, 'qty_purchased' => (int) 1, 'sku' => 'US-1011-04', 'image' => array('name' => 'main', 'thumb_path' => '/img/product_images/US-1011-04-thumb.jpg', 'file_path' => '/img/product_images/US-1011-04.jpg')), array('name' => 'Flirty', 'shortname' => 'Flirty', 'id' => '9', 'item_type_id' => '1', 'children_qty_required' => null, 'qty_required' => null, 'qty_purchased' => (int) 1, 'sku' => 'US-1011-05', 'image' => array('name' => 'main', 'thumb_path' => '/img/product_images/US-1011-05-thumb.jpg', 'file_path' => '/img/product_images/US-1011-05.jpg')), array('name' => 'Playful', 'shortname' => 'Playful', 'id' => '10', 'item_type_id' => '1', 'children_qty_required' => null, 'qty_required' => null, 'qty_purchased' => (int) 1, 'sku' => 'US-1011-06', 'image' => array('name' => 'main', 'thumb_path' => '/img/product_images/US-1011-06-thumb.jpg', 'file_path' => '/img/product_images/US-1011-06.jpg'))), 'options' => array('US-1011-00' => array('skus' => array('US-1011-03' => 1, 'US-1011-04' => 1, 'US-1011-05' => 1, 'US-1011-06' => 1))))));
}
开发者ID:kameshwariv,项目名称:testexample,代码行数:7,代码来源:ShoppingCartTest.php
注:本文中的Money类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论