作者:jordicasadeval
项目:MoneyFormatte
public function getAmountInBaseUnits(Money $money)
{
$iso = $this->iso4217->getByAlpha3($money->getCurrency()->getName());
$decimals = $iso['exp'];
$dividend = pow(10, $decimals);
return $money->getAmount() / $dividend;
}
作者:zoek
项目:php-testing-tool
/**
* Decrease this account current balance
*
* @param Money $amount
* @throws InsufficientFunds
* A member cannot withdraw more than it's account current balance
*/
public function withdraw(Money $amount)
{
if ($amount->greaterThan($this->balance)) {
throw new InsufficientFunds("Cannot withdraw {$amount->getAmount()}");
}
$this->balance = $this->balance->subtract($amount);
}
作者:srtfishe
项目:mone
/**
* @param \Money\Money $money
* @param $rounding_mode
* @return \Money\Money
* @expectedException InvalidArgumentException
*/
public function convert(Money $money, RoundingMode $rounding_mode = null)
{
if (!$money->getCurrency()->equals($this->baseCurrency)) {
throw new InvalidArgumentException("The Money has the wrong currency");
}
$rounding_mode = $rounding_mode ?: RoundingMode::halfUp();
return new Money((int) round($money->getAmount() * $this->ratio, 0, $rounding_mode->getRoundingMode()), $this->counterCurrency);
}
作者:umpirsk
项目:locurr
public function convert(Money $money, $target)
{
if (!$target instanceof MoneyCurrency) {
throw new InvalidArgumentException(sprintf('Second argument must be Currency, %s given.', gettype($target)));
}
$rate = $this->swap->quote(new CurrencyPair($money->getCurrency(), $target));
return new Money($money->multiply((double) $rate->getValue())->getAmount(), $target);
}
作者:csbil
项目:csbil
/**
* @param Quote|Invoice $object
* @param Money $total
*
* @return mixed
*/
private function setDiscount($object, Money $total)
{
if (null !== $object->getDiscount()) {
$discount = $total->multiply($object->getDiscount());
$total = $total->subtract($discount);
return $total;
}
return $total;
}
作者:zfbrasi
项目:doctrine-money-modul
public function testHydratorHydratesAsExpected()
{
$hydrator = new MoneyHydrator();
$data = ['amount' => 500, 'currency' => 'BRL'];
$money = new Money(500, new Currency('BRL'));
$object = $hydrator->hydrate($data, new \stdClass());
$this->assertEquals($money->getAmount(), $object->getAmount());
$this->assertEquals($money->getCurrency(), $object->getCurrency());
}
作者:squig
项目:mone
/**
* {@inheritdoc}
*/
public function format(Money $money)
{
$currencyCode = $money->getCurrency()->getCode();
if (isset($this->formatters[$currencyCode])) {
return $this->formatters[$currencyCode]->format($money);
}
if (isset($this->formatters['*'])) {
return $this->formatters['*']->format($money);
}
throw new FormatterException('No formatter found for currency ' . $currencyCode);
}
作者:umpirsk
项目:locurr
function it_converts_money_using_swap(SwapInterface $swap, Money $money, Money $converted, Currency $from, Currency $to)
{
$money->getAmount()->willReturn(100);
$money->getCurrency()->willReturn($from);
$money->multiply(120.3971)->willReturn($converted);
$converted->getAmount()->willReturn(12039);
$converted->getCurrency()->willReturn($to);
$from->__toString()->willReturn('EUR');
$to->__toString()->willReturn('RSD');
$rate = new Rate(120.3971);
$swap->quote('EUR/RSD')->shouldBeCalled()->willReturn($rate);
$this->convert($money, $to)->getAmount()->shouldBe(12039);
}
作者:zoek
项目:php-testing-tool
/**
* @param string $fromMemberId
* @param string $amount
* @param string $toMemberId
* @param string $occurredOn
*/
public function __construct($fromMemberId, $amount, $toMemberId, $occurredOn)
{
$this->occurredOn = DateTime::createFromFormat('Y-m-d H:i:s', $occurredOn);
$this->fromMemberId = Identifier::fromString($fromMemberId);
$this->amount = Money::MXN($amount);
$this->toMemberId = Identifier::fromString($toMemberId);
}
作者:zoek
项目:php-testing-tool
/** @test */
function it_should_serialize_a_domain_event_to_json()
{
$serializer = new JsonSerializer();
$anEvent = new InstantaneousEvent(Identifier::fromString('abc'), Money::MXN(10000), new DateTime('2015-10-24 12:39:51'));
$json = $serializer->serialize($anEvent);
$this->assertEquals('{"occurred_on":"2015-10-24 12:39:51","member_id":"abc","amount":10000}', $json, 'JSON format for serialized event is incorrect');
}
作者:BboyKee
项目:TbbcMoneyBundl
public function testOverrideCurrency()
{
\Locale::setDefault("fr_FR");
$form = $this->factory->create($this->simpleMoneyTypeClass, null, ["currency" => "USD"]);
$form->submit(array("tbbc_amount" => '1 252,5'));
$this->assertEquals(Money::USD(125250), $form->getData());
}
作者:zfbrasi
项目:doctrine-money-modul
/**
* @return MoneyFieldset
*/
public function __invoke()
{
$moneyFieldset = new MoneyFieldset();
$moneyFieldset->setHydrator(new MoneyHydrator());
$moneyFieldset->setObject(Money::BRL(0));
return $moneyFieldset;
}
作者:Grummf
项目:cam
/**
* @param SimpleXMLElement $statementXml
* @param Statement $statement
*/
private function addEntriesToStatement(SimpleXMLElement $statementXml, Statement $statement)
{
$index = 0;
$entriesXml = $statementXml->Ntry;
foreach ($entriesXml as $entryXml) {
$amount = Money::stringToUnits((string) $entryXml->Amt);
$currency = (string) $entryXml->Amt['Ccy'];
$bookingDate = (string) $entryXml->BookgDt->Dt;
$valueDate = (string) $entryXml->ValDt->Dt;
if ((string) $entryXml->CdtDbtInd === 'DBIT') {
$amount = $amount * -1;
}
$entry = new Entry($statement, $index, new Money($amount, new Currency($currency)), new DateTimeImmutable($bookingDate), new DateTimeImmutable($valueDate));
if (isset($entryXml->RvslInd) && (string) $entryXml->RvslInd === 'true') {
$entry->setReversalIndicator(true);
}
if (isset($entryXml->NtryRef) && (string) $entryXml->NtryRef) {
$entry->setReference((string) $entryXml->NtryRef);
}
if (isset($entryXml->NtryDtls->Btch->PmtInfId) && (string) $entryXml->NtryDtls->Btch->PmtInfId) {
$entry->setBatchPaymentId((string) $entryXml->NtryDtls->Btch->PmtInfId);
}
$this->addTransactionDetailsToEntry($entryXml, $entry);
$statement->addEntry($entry);
$index++;
}
}
作者:cambridgeuniversit
项目:ice-paymentpla
/**
* @param PlanDefinition $definition
* @param Money $amountToPay
* @param PlanParameters $parameters
* @return PaymentPlan
*/
public function getPlan(PlanDefinition $definition, Money $amountToPay, PlanParameters $parameters)
{
/** @var array $paymentProportions */
$paymentProportions = $definition->getAttribute('payments');
//The values of the payments array is a ratios array
/** @var Money[] $amounts */
$amounts = $amountToPay->allocate(array_values($paymentProportions));
$payments = array_map(function ($rawDate, $amount) {
//rawDate is either 'immediate' or a 'Y-m-d' string, or invalid.
if ($rawDate === 'immediate') {
return PlannedPayment::immediate($amount);
}
return PlannedPayment::withDueDate($amount, DueDate::fromString($rawDate));
}, array_keys($paymentProportions), $amounts);
return new PaymentPlan($payments, $definition->getAttribute('short_description'), $definition->getAttribute('long_description'));
}
作者:zoek
项目:php-testing-tool
/** @test */
function it_should_update_the_information_of_a_registered_member()
{
$member = $this->members->with(Identifier::fromString('wxyz'));
$member->transfer(Money::MXN(500), $this->existingMember);
$this->members->update($this->existingMember);
$this->assertBalanceAmounts(3500, $this->existingMember, "Current member balance should be 3500");
}
作者:zfbrasi
项目:doctrine-money-modul
/**
* {@inheritdoc}
*
* @throws InvalidArgumentException
*
* @return int|null
*/
public function filter($value)
{
if (null === $value || is_string($value) && strlen($value) === 0) {
return null;
}
return Money::stringToUnits($value);
}
作者:ming-ha
项目:XoopsCor
/**
* @covers Xoops\Core\Kernel\Dtype\DtypeMoney::getVar
* @covers Xoops\Core\Kernel\Dtype\DtypeMoney::cleanVar
*/
public function testGetVarCleanVar()
{
$testValue = new Money(10000, new Currency('USD'));
$key = 'money_test';
$this->xObject[$key] = $testValue;
$this->xObject[$key] = $this->object->cleanVar($this->xObject, $key);
$value = $this->xObject->getVar($key, Dtype::FORMAT_NONE);
$this->assertInstanceOf('\\Money\\Money', $value);
$this->assertEquals($testValue->getAmount(), $value->getAmount());
$this->assertEquals($testValue->getCurrency(), $value->getCurrency());
$this->assertNotSame($value, $testValue);
$value2 = $this->xObject->getVar($key, Dtype::FORMAT_SHOW);
$this->assertInstanceOf('\\Money\\Money', $value2);
$this->assertEquals($testValue->getAmount(), $value2->getAmount());
$this->assertEquals($testValue->getCurrency(), $value2->getCurrency());
$this->assertNotSame($value, $value2);
}
作者:BboyKee
项目:TbbcMoneyBundl
public function testSetData()
{
\Locale::setDefault("fr_FR");
$form = $this->factory->create($this->moneyTypeClass, null, array("currency_type" => $this->currencyTypeClass));
$form->setData(Money::EUR(120));
$formView = $form->createView();
$this->assertEquals("1,20", $formView->children["tbbc_amount"]->vars["value"]);
}
作者:ammonitenetwork
项目:f3-finance
public function widthdrawl($amount)
{
$originalfunds = Money::USD((int) $this->fundsavailable);
$addedFunds = Money::USD((int) $amount);
$fundsavailable = $originalfunds->subtract($addedFunds);
$this->fundsavailable = $fundsavailable->getAmount();
$this->save();
}
作者:lakhma
项目:TbbcMoneyBundl
public function testSetData()
{
\Locale::setDefault("fr_FR");
$moneyType = new SimpleMoneyType($this->pairManager, 2);
$form = $this->factory->create($moneyType, null, array());
$form->setData(Money::EUR(120));
$formView = $form->createView();
$this->assertEquals("1,20", $formView->children["tbbc_amount"]->vars["value"]);
}