@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Track total funding amount on Fund initiatives

Summary: Ref T5835. Show total funding amount and payable merchant on initiatives.

Test Plan: {F214936}

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T5835

Differential Revision: https://secure.phabricator.com/D10657

+78 -19
+4
resources/sql/autopatches/20141007.fundtotal.sql
··· 1 + ALTER TABLE {$NAMESPACE}_fund.fund_initiative 2 + ADD totalAsCurrency VARCHAR(64) NOT NULL COLLATE utf8_bin; 3 + 4 + UPDATE {$NAMESPACE}_fund.fund_initiative SET totalAsCurrency = '0.00 USD';
+14 -1
src/applications/fund/controller/FundInitiativeViewController.php
··· 84 84 ->setObject($initiative); 85 85 86 86 $owner_phid = $initiative->getOwnerPHID(); 87 - $this->loadHandles(array($owner_phid)); 87 + $merchant_phid = $initiative->getMerchantPHID(); 88 + $this->loadHandles( 89 + array( 90 + $owner_phid, 91 + $merchant_phid, 92 + )); 88 93 89 94 $view->addProperty( 90 95 pht('Owner'), 91 96 $this->getHandle($owner_phid)->renderLink()); 97 + 98 + $view->addProperty( 99 + pht('Payable To Merchant'), 100 + $this->getHandle($merchant_phid)->renderLink()); 101 + 102 + $view->addProperty( 103 + pht('Total Funding'), 104 + $initiative->getTotalAsCurrency()->formatForDisplay()); 92 105 93 106 $view->invokeWillRenderEvent(); 94 107
+12 -1
src/applications/fund/editor/FundInitiativeEditor.php
··· 78 78 $object->setStatus($xaction->getNewValue()); 79 79 return; 80 80 case FundInitiativeTransaction::TYPE_BACKER: 81 - // TODO: Calculate total funding / backers / etc. 81 + $backer = id(new FundBackerQuery()) 82 + ->setViewer($this->requireActor()) 83 + ->withPHIDs(array($xaction->getNewValue())) 84 + ->executeOne(); 85 + if (!$backer) { 86 + throw new Exception(pht('No such backer!')); 87 + } 88 + 89 + $backer_amount = $backer->getAmountAsCurrency(); 90 + $total = $object->getTotalAsCurrency()->add($backer_amount); 91 + $object->setTotalAsCurrency($total); 92 + 82 93 return; 83 94 case PhabricatorTransactions::TYPE_SUBSCRIBERS: 84 95 case PhabricatorTransactions::TYPE_EDGE:
+7 -1
src/applications/fund/storage/FundInitiative.php
··· 18 18 protected $viewPolicy; 19 19 protected $editPolicy; 20 20 protected $status; 21 + protected $totalAsCurrency; 21 22 22 23 private $projectPHIDs = self::ATTACHABLE; 23 24 ··· 43 44 ->setOwnerPHID($actor->getPHID()) 44 45 ->setViewPolicy($view_policy) 45 46 ->setEditPolicy($actor->getPHID()) 46 - ->setStatus(self::STATUS_OPEN); 47 + ->setStatus(self::STATUS_OPEN) 48 + ->setTotalAsCurrency(PhortuneCurrency::newEmptyCurrency()); 47 49 } 48 50 49 51 public function getConfiguration() { ··· 54 56 'description' => 'text', 55 57 'status' => 'text32', 56 58 'merchantPHID' => 'phid?', 59 + 'totalAsCurrency' => 'text64', 60 + ), 61 + self::CONFIG_APPLICATION_SERIALIZERS => array( 62 + 'totalAsCurrency' => new PhortuneCurrencySerializer(), 57 63 ), 58 64 self::CONFIG_KEY_SCHEMA => array( 59 65 'key_status' => array(
+23 -15
src/applications/phortune/currency/PhortuneCurrency.php
··· 72 72 public static function newFromList(array $list) { 73 73 assert_instances_of($list, 'PhortuneCurrency'); 74 74 75 - $total = 0; 76 - $currency = null; 75 + if (!$list) { 76 + return PhortuneCurrency::newEmptyCurrency(); 77 + } 78 + 79 + $total = null; 77 80 foreach ($list as $item) { 78 - if ($currency === null) { 79 - $currency = $item->getCurrency(); 80 - } else if ($currency === $item->getCurrency()) { 81 - // Adding a value denominated in the same currency, which is 82 - // fine. 81 + if ($total === null) { 82 + $total = $item; 83 83 } else { 84 - throw new Exception( 85 - pht('Trying to sum a list of unlike currencies.')); 84 + $total = $total->add($item); 86 85 } 87 - 88 - // TODO: This should check for integer overflows, etc. 89 - $total += $item->getValue(); 90 86 } 91 87 92 - return PhortuneCurrency::newFromValueAndCurrency( 93 - $total, 94 - self::getDefaultCurrency()); 88 + return $total; 95 89 } 96 90 97 91 public function formatForDisplay() { ··· 130 124 131 125 private static function throwFormatException($string) { 132 126 throw new Exception("Invalid currency format ('{$string}')."); 127 + } 128 + 129 + public function add(PhortuneCurrency $other) { 130 + if ($this->currency !== $other->currency) { 131 + throw new Exception(pht('Trying to add unlike currencies!')); 132 + } 133 + 134 + $currency = new PhortuneCurrency(); 135 + 136 + // TODO: This should check for integer overflows, etc. 137 + $currency->value = $this->value + $other->value; 138 + $currency->currency = $this->currency; 139 + 140 + return $currency; 133 141 } 134 142 135 143 /**
+18 -1
src/applications/phortune/currency/__tests__/PhortuneCurrencyTestCase.php
··· 19 19 } 20 20 } 21 21 22 - 23 22 public function testCurrencyFormatBareValue() { 24 23 25 24 // NOTE: The PayPal API depends on the behavior of the bare value format! ··· 140 139 $caught = $ex; 141 140 } 142 141 $this->assertTrue($caught instanceof Exception); 142 + } 143 + 144 + public function testAddCurrency() { 145 + $cases = array( 146 + array('0.00 USD', '0.00 USD', '$0.00 USD'), 147 + array('1.00 USD', '1.00 USD', '$2.00 USD'), 148 + array('1.23 USD', '9.77 USD', '$11.00 USD'), 149 + ); 150 + 151 + foreach ($cases as $case) { 152 + list($l, $r, $expect) = $case; 153 + 154 + $l = PhortuneCurrency::newFromString($l); 155 + $r = PhortuneCurrency::newFromString($r); 156 + $sum = $l->add($r); 157 + 158 + $this->assertEqual($expect, $sum->formatForDisplay()); 159 + } 143 160 } 144 161 145 162 }