当前位置: 首页>>代码示例>>PHP>>正文


PHP Money::allocate方法代码示例

本文整理汇总了PHP中Money\Money::allocate方法的典型用法代码示例。如果您正苦于以下问题:PHP Money::allocate方法的具体用法?PHP Money::allocate怎么用?PHP Money::allocate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Money\Money的用法示例。


在下文中一共展示了Money::allocate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getPlan

 /**
  * @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'));
 }
开发者ID:cambridgeuniversity,项目名称:ice-paymentplan,代码行数:22,代码来源:PercentOnDateCalculator.php

示例2: testAllocationOrderIsImportant

 public function testAllocationOrderIsImportant()
 {
     $m = new Money(5, new Currency('EUR'));
     list($part1, $part2) = $m->allocate(array(3, 7));
     $this->assertEquals(new Money(2, new Currency('EUR')), $part1);
     $this->assertEquals(new Money(3, new Currency('EUR')), $part2);
     $m = new Money(5, new Currency('EUR'));
     list($part1, $part2) = $m->allocate(array(7, 3));
     $this->assertEquals(new Money(4, new Currency('EUR')), $part1);
     $this->assertEquals(new Money(1, new Currency('EUR')), $part2);
 }
开发者ID:hemeragestao,项目名称:money,代码行数:11,代码来源:MoneyTest.php

示例3: splitMoneyEvenly

 /**
  * @param Money $total
  * @param integer $numberOfParts
  * @return Money[]
  */
 private function splitMoneyEvenly(Money $total, $numberOfParts)
 {
     /*
      * Use money's allocate method to divide the amount by the divisor - this is better than just dividing manually
      * as the allocate algorithm ensures against the total changing due to rounding error.
      */
     if (1 === $numberOfParts) {
         return [$total];
     }
     if (!is_int($numberOfParts) || $numberOfParts <= 0) {
         throw new \RuntimeException("Invalid divisor");
     }
     //Use an array with $numberOfParts elements each with value 1/$numberOfParts as the input $ratios
     return $total->allocate(array_pad([], $numberOfParts, 1 / $numberOfParts));
 }
开发者ID:cambridgeuniversity,项目名称:ice-paymentplan,代码行数:20,代码来源:BursaryOffFinalPaymentModifier.php


注:本文中的Money\Money::allocate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。