function test() { global $apiContext; // IncludeConfig('paypal/bootstrap.php'); $payer = new Payer(); $payer->setPaymentMethod("paypal"); $item1 = new Item(); $item1->setName('Ground Coffee 40 oz')->setCurrency('USD')->setQuantity(1)->setPrice(7.5); $item2 = new Item(); $item2->setName('Granola bars')->setCurrency('USD')->setQuantity(5)->setPrice(2); $itemList = new ItemList(); $itemList->setItems(array($item1, $item2)); $details = new Details(); $details->setShipping(1.2)->setTax(1.3)->setSubtotal(17.5); $amount = new Amount(); $amount->setCurrency("USD")->setTotal(20)->setDetails($details); $transaction = new Transaction(); $transaction->setAmount($amount)->setItemList($itemList)->setDescription("Payment description")->setInvoiceNumber(uniqid()); $baseUrl = getBaseUrl(); $redirectUrls = new RedirectUrls(); $redirectUrls->setReturnUrl("{$baseUrl}/donate.php/execute_payment_test?success=true")->setCancelUrl("{$baseUrl}/donate.php/execute_payment_test?success=false"); $payment = new Payment(); $payment->setIntent("sale")->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction)); $request = clone $payment; try { $payment->create($apiContext); } catch (Exception $ex) { ResultPrinter::printError("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", null, $request, $ex); exit(1); } $approvalUrl = $payment->getApprovalLink(); ResultPrinter::printResult("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", "<a href='{$approvalUrl}' >{$approvalUrl}</a>", $request, $payment); return $payment; }
public function addAmount(Amount $amount) { if ($this->forceConversionTo) { $amount->convertTo($this->forceConversionTo); } $this->amounts[] = $amount; return $this; }
public function calc(User $user, Amount $amount) { $grade = $user->getGrade(); $sex = $user->getSex(); if ($grade === 'ゴールド') { return new Amount(floor($amount->getValue() * 0.9)); } if ($grade === 'シルバー') { return new Amount(floor($amount->getValue() * 0.95)); } if ($grade === '一般' && $sex === '女性') { return new Amount(floor($amount->getValue() * 0.95)); } return new Amount($amount->getValue()); }
/** * @covers FireflyIII\Http\Controllers\PreferencesController::index */ public function testIndex() { $user = FactoryMuffin::create('FireflyIII\\User'); $pref = FactoryMuffin::create('FireflyIII\\Models\\Preference'); $currency = FactoryMuffin::create('FireflyIII\\Models\\TransactionCurrency'); $this->be($user); // mock: $repository = $this->mock('FireflyIII\\Repositories\\Account\\AccountRepositoryInterface'); // fake! $repository->shouldReceive('getAccounts')->with(['Default account', 'Asset account'])->andReturn(new Collection()); Preferences::shouldReceive('get')->once()->withArgs(['viewRange', '1M'])->andReturn($pref); Preferences::shouldReceive('get')->once()->withArgs(['frontPageAccounts', []])->andReturn($pref); Preferences::shouldReceive('get')->once()->withArgs(['budgetMaximum', 1000])->andReturn($pref); Preferences::shouldReceive('get')->withArgs(['currencyPreference', 'EUR'])->andReturn($pref); Amount::shouldReceive('format')->andReturn('xx'); Amount::shouldReceive('getCurrencyCode')->andReturn('X'); Amount::shouldReceive('getCurrencySymbol')->andReturn('X'); Amount::shouldReceive('getAllCurrencies')->andReturn(new Collection()); Amount::shouldReceive('getDefaultCurrency')->andReturn($currency); $lastActivity = FactoryMuffin::create('FireflyIII\\Models\\Preference'); $lastActivity->data = microtime(); Preferences::shouldReceive('lastActivity')->andReturn($lastActivity); // language preference: $language = FactoryMuffin::create('FireflyIII\\Models\\Preference'); $language->data = 'en'; $language->save(); Preferences::shouldReceive('get')->withAnyArgs()->andReturn($language); $this->call('GET', '/preferences'); $this->assertResponseOk(); }
public function stage(GatewayType $adapter, $normalized, &$stagedData) { if (empty($normalized['amount']) || empty($normalized['currency_code']) || !is_numeric($normalized['amount'])) { //can't do anything with amounts at all. Just go home. unset($stagedData['amount']); return; } $amount = Amount::round($normalized['amount'], $normalized['currency_code']); $stagedData['amount'] = $amount * 100; }
public static function create(DB $db, Amount $denom, Purchase $p) { $prepared = $db->prepare(' INSERT INTO `bills` ( `entered_at`, `denomination`, `purchase_id` ) VALUES ( NOW(), :denomination, :purchase_id ) '); $result = $prepared->execute(array(':denomination' => $denom->get(), ':purchase_id' => $p->getId())); if ($result === false) { throw new Exception("Unable to log bill."); } return self::load($db, $db->lastInsertId()); }
public function unstage(GatewayType $adapter, $stagedData, &$unstagedData) { if (Amount::is_exponent3_currency($stagedData['currency_code'])) { $unstagedData['amount'] = $stagedData['amount'] / 1000; } elseif (Amount::is_fractional_currency($stagedData['currency_code'])) { $unstagedData['amount'] = $stagedData['amount'] / 100; } else { $unstagedData['amount'] = $stagedData['amount']; } }
function getSpendingMoney($accountId, $startDate) { global $badgerDb; $accountManager = new AccountManager($badgerDb); $account = $accountManager->getAccountById($accountId); $account->setType('finished'); $account->setOrder(array(array('key' => 'valutaDate', 'dir' => 'asc'))); $account->setFilter(array(array('key' => 'valutaDate', 'op' => 'ge', 'val' => $startDate), array('key' => 'periodical', 'op' => 'eq', 'val' => false), array('key' => 'exceptional', 'op' => 'eq', 'val' => false))); $sum = new Amount(); $realStartDate = false; while ($currentTransaction = $account->getNextFinishedTransaction()) { if (!$realStartDate) { $realStartDate = $currentTransaction->getValutaDate(); } $sum->add($currentTransaction->getAmount()); } $span = new Date_Span($realStartDate, new Date()); $count = $span->toDays(); if ($count > 0) { $sum->div($count); } return $sum; }
/** * @covers FireflyIII\Http\Controllers\NewUserController::index */ public function testIndex() { $user = FactoryMuffin::create('FireflyIII\\User'); $repository = $this->mock('FireflyIII\\Repositories\\Account\\AccountRepositoryInterface'); $this->be($user); // mock ALL THE THINGS! $repository->shouldReceive('countAccounts')->once()->andReturn(0); // language preference: $language = FactoryMuffin::create('FireflyIII\\Models\\Preference'); $language->data = 'en'; $language->save(); Preferences::shouldReceive('get')->withAnyArgs()->andReturn($language); $lastActivity = FactoryMuffin::create('FireflyIII\\Models\\Preference'); $lastActivity->data = microtime(); Preferences::shouldReceive('lastActivity')->andReturn($lastActivity); Amount::shouldReceive('getCurrencyCode')->andReturn('X'); Amount::shouldReceive('getCurrencySymbol')->andReturn('X'); $this->call('GET', '/new-user'); $this->assertResponseStatus(200); }
/** * Integration test to verify that the Amazon gateway converts Canadian * dollars before redirecting * * @dataProvider canadaLanguageProvider */ function testCanadianDollarConversion($language) { $init = $this->getDonorTestData('CA'); unset($init['order_id']); $init['payment_method'] = 'amazon'; $init['ffname'] = 'amazon'; $init['language'] = $language; $rates = CurrencyRates::getCurrencyRates(); $cadRate = $rates['CAD']; $expectedAmount = floor($init['amount'] / $cadRate); TestingAmazonAdapter::$fakeGlobals = array('FallbackCurrency' => 'USD', 'NotifyOnConvert' => true); $expectedNotification = wfMessage('donate_interface-fallback-currency-notice', 'USD')->inLanguage($language)->text(); $locale = $init['language'] . '_' . $init['country']; $expectedDisplayAmount = Amount::format($expectedAmount, 'USD', $locale); $that = $this; //needed for PHP pre-5.4 $convertTest = function ($amountString) use($expectedDisplayAmount, $that) { $that->assertEquals($expectedDisplayAmount, trim($amountString), 'Displaying wrong amount'); }; $assertNodes = array('selected-amount' => array('innerhtml' => $convertTest), 'mw-content-text' => array('innerhtmlmatches' => "/.*{$expectedNotification}.*/")); $this->verifyFormOutput('AmazonGateway', $init, $assertNodes, false); }
public function start(array $items, $settings = array(), $paymentMethod = 'paypal', $currency = 'USD') { ## unable to authenticate if (!$this->authenthication($settings['environment'])) { return false; } #set ApiContext $apiContext = PaypalContext::ApiContext($this->credentials, $this->sdkConfiguration); #set payment method $payer = PaymentMethod::ConfigPayment($paymentMethod); #set Items and Total to bill if (!($itemsList = Items::setItemsList($items, $currency))) { ## unable to load the items to sell. return false; } #set final amount. $amount = Amount::setAmount(Items::getTotal(), $currency); #set transaction. $transaction = Transaction::setTransaction($amount, $itemsList); #set redirections. $redirectUrls = Redirections::setURLs(); self::_createPaymentURL($payer, $redirectUrls, $transaction, $apiContext); }
public function home() { $catagory = Catagory::all(); $subcatagory = Subcatagory::all(); $product = Product::orderBy('created_at', 'desc')->paginate(9); // Check if any users have got any amount by their referals if (Auth::user()) { $amount = Amount::where("user_id", Auth::user()->id)->where('status', 0); if ($amount->count() > 0) { $amount->update(['status' => 1]); // Check the user's referal is an admin or not $my_referal = User::find(Auth::user()->referal_id); if (Auth::user()->referal_id != 0) { if ($my_referal->type == 'admin') { $distributed_amount = 600; } else { $distributed_amount = 300; } Amount::create(['user_id' => Auth::user()->referal_id, 'amount' => $distributed_amount]); } } } return View::make('Main.Home.Index', array('catagories' => $catagory, 'subcatagories' => $subcatagory, 'products' => $product)); }
/** * @dataProvider allocateProvider */ public function testAllocate(Amount $amount, $precision, array $ratios, array $result) { $this->assertEquals($result, $amount->allocate($ratios, $precision)); }
/** * @covers FireflyIII\Http\Controllers\PiggyBankController::show */ public function testShow() { $piggyBank = FactoryMuffin::create('FireflyIII\\Models\\PiggyBank'); $this->be($piggyBank->account->user); $piggyBanks = $this->mock('FireflyIII\\Repositories\\PiggyBank\\PiggyBankRepositoryInterface'); $piggyBanks->shouldReceive('getEvents')->andReturn(new Collection()); Amount::shouldReceive('format')->andReturn('something'); Amount::shouldReceive('getCurrencySymbol')->andReturn('something'); Amount::shouldReceive('getCurrencyCode')->andReturn('something'); $this->call('GET', '/piggy-banks/show/' . $piggyBank->id); $this->assertResponseOk(); }
/** * @covers FireflyIII\Http\Controllers\HomeController::index */ public function testIndex() { $user = FactoryMuffin::create('FireflyIII\\User'); $preference = FactoryMuffin::create('FireflyIII\\Models\\Preference'); $journal = FactoryMuffin::create('FireflyIII\\Models\\TransactionJournal'); $journals = new Collection([$journal]); $account = FactoryMuffin::create('FireflyIII\\Models\\Account'); $accounts = new Collection([$account]); $repository = $this->mock('FireflyIII\\Repositories\\Account\\AccountRepositoryInterface'); $this->be($user); // mock ALL THE THINGS! $repository->shouldReceive('countAccounts')->once()->andReturn(3); Preferences::shouldReceive('get')->once()->withArgs(['frontPageAccounts', []])->andReturn($preference); $repository->shouldReceive('getFrontpageAccounts')->once()->with($preference)->andReturn($accounts); $repository->shouldReceive('getSavingsAccounts')->once()->andReturn($accounts); $repository->shouldReceive('getPiggyBankAccounts')->once()->andReturn($accounts); $repository->shouldReceive('sumOfEverything')->once()->andReturn(1); $repository->shouldReceive('getFrontpageTransactions')->once()->andReturn($journals); // language preference: $language = FactoryMuffin::create('FireflyIII\\Models\\Preference'); $language->data = 'en'; $language->save(); Preferences::shouldReceive('get')->withAnyArgs()->andReturn($language); $lastActivity = FactoryMuffin::create('FireflyIII\\Models\\Preference'); $lastActivity->data = microtime(); Preferences::shouldReceive('lastActivity')->andReturn($lastActivity); Amount::shouldReceive('getCurrencyCode')->andReturn('EUR'); Amount::shouldReceive('getCurrencySymbol')->andReturn('X'); Amount::shouldReceive('format')->andReturn('xxx'); Amount::shouldReceive('formatJournal')->with($journal)->andReturn('xxx'); $this->call('GET', '/'); $this->assertResponseOk(); }
public function makePaymentUsingPayPal($total, $currency, $paymentDesc, $returnUrl, $cancelUrl) { $payer = new Payer(); $payer->setPaymentMethod("paypal"); // Specify the payment amount. $amount = new Amount(); $amount->setCurrency($currency); $amount->setTotal($total); // ###Transaction // A transaction defines the contract of a // payment - what is the payment for and who // is fulfilling it. Transaction is created with // a 'Payee' and 'Amount' types $transaction = new Transaction(); $transaction->setAmount($amount); $transaction->setDescription($paymentDesc); $redirectUrls = new RedirectUrls(); $redirectUrls->setReturnUrl($returnUrl); $redirectUrls->setCancelUrl($cancelUrl); $payment = new Payment(); $payment->setRedirectUrls($redirectUrls); $payment->setIntent("sale"); $payment->setPayer($payer); $payment->setTransactions(array($transaction)); $payment->create(getApiContext()); return $payment; }
/** * normalize helper function. * Takes all possible sources for the intended donation amount, and * normalizes them into the 'amount' field. */ protected function setNormalizedAmount() { if ($this->getVal('amount') === 'Other') { $this->setVal('amount', $this->getVal('amountGiven')); } $amountIsNotValidSomehow = !$this->isSomething('amount') || !is_numeric($this->getVal('amount')) || $this->getVal('amount') <= 0; if ($amountIsNotValidSomehow && ($this->isSomething('amountGiven') && is_numeric($this->getVal('amountGiven')))) { $this->setVal('amount', $this->getVal('amountGiven')); } else { if ($amountIsNotValidSomehow && ($this->isSomething('amountOther') && is_numeric($this->getVal('amountOther')))) { $this->setVal('amount', $this->getVal('amountOther')); } } if (!$this->isSomething('amount')) { $this->setVal('amount', '0.00'); } $this->expunge('amountGiven'); $this->expunge('amountOther'); if (!is_numeric($this->getVal('amount'))) { //fail validation later, log some things. $mess = 'Non-numeric Amount.'; $keys = array('amount', 'utm_source', 'utm_campaign', 'email', 'user_ip'); foreach ($keys as $key) { $mess .= ' ' . $key . '=' . $this->getVal($key); } $this->logger->debug($mess); $this->setVal('amount', 'invalid'); return; } $this->setVal('amount', Amount::round($this->getVal('amount'), $this->getVal('currency_code'))); }
function importMatching($importedTransaction, $accountId) { global $us; global $badgerDb; static $dateDelta = null; static $amountDelta = null; static $textSimilarity = null; static $categories = null; if (is_null($dateDelta)) { try { $dateDelta = $us->getProperty('matchingDateDelta'); } catch (BadgerException $ex) { $dateDelta = 5; } try { $amountDelta = $us->getProperty('matchingAmountDelta'); } catch (BadgerException $ex) { $amountDelta = 0.1; } try { $textSimilarity = $us->getProperty('matchingTextSimilarity'); } catch (BadgerException $ex) { $textSimilarity = 0.25; } $categoryManager = new CategoryManager($badgerDb); while ($currentCategory = $categoryManager->getNextCategory()) { $categories[$currentCategory->getId()] = preg_split('/[\\n]+/', $currentCategory->getKeywords(), -1, PREG_SPLIT_NO_EMPTY); } } if (!$importedTransaction['valutaDate']) { return $importedTransaction; } $minDate = new Date($importedTransaction['valutaDate']); $minDate->subtractSeconds($dateDelta * 24 * 60 * 60); $maxDate = new Date($importedTransaction['valutaDate']); $maxDate->addSeconds($dateDelta * 24 * 60 * 60); if (!$importedTransaction['amount']) { return $importedTransaction; } $minAmount = new Amount($importedTransaction['amount']); $minAmount->mul(1 - $amountDelta); $maxAmount = new Amount($importedTransaction['amount']); $maxAmount->mul(1 + $amountDelta); $accountManager = new AccountManager($badgerDb); $account = $accountManager->getAccountById($accountId); $account->setFilter(array(array('key' => 'valutaDate', 'op' => 'ge', 'val' => $minDate), array('key' => 'valutaDate', 'op' => 'le', 'val' => $maxDate), array('key' => 'amount', 'op' => 'ge', 'val' => $minAmount), array('key' => 'amount', 'op' => 'le', 'val' => $maxAmount))); $similarTransactions = array(); while ($currentTransaction = $account->getNextTransaction()) { $titleSimilarity = getSimilarity($importedTransaction['title'], $currentTransaction->getTitle(), $textSimilarity); $descriptionSimilarity = getSimilarity($importedTransaction['description'], $currentTransaction->getDescription(), $textSimilarity); $transactionPartnerSimilarity = getSimilarity($importedTransaction['transactionPartner'], $currentTransaction->getTransactionPartner(), $textSimilarity); $currDate = $currentTransaction->getValutaDate(); $impDate = $importedTransaction['valutaDate']; $dateSimilarity = 1 - abs(Date_Calc::dateDiff($currDate->getDay(), $currDate->getMonth(), $currDate->getYear(), $impDate->getDay(), $impDate->getMonth(), $impDate->getYear())) / $dateDelta; $cmpAmount = new Amount($currentTransaction->getAmount()); $impAmount = new Amount($importedTransaction['amount']); $cmpAmount->sub($impAmount); $cmpAmount->abs(); $impAmount->mul($amountDelta); $impAmount->abs(); $amountSimilarity = 1 - $cmpAmount->div($impAmount)->get(); $currentTextSimilarity = ($titleSimilarity + $descriptionSimilarity + $transactionPartnerSimilarity) / 3; // if ($currentTextSimilarity >= $textSimilarity) { $overallSimilarity = ($titleSimilarity + $descriptionSimilarity + $transactionPartnerSimilarity + $dateSimilarity + $amountSimilarity) / 5; //$similarTransactions["$overallSimilarity t:$titleSimilarity d:$descriptionSimilarity tp:$transactionPartnerSimilarity vd:$dateSimilarity a:$amountSimilarity"] = $currentTransaction; $similarTransactions[$overallSimilarity] = $currentTransaction; // } } krsort($similarTransactions); if (count($similarTransactions)) { $importedTransaction['similarTransactions'] = $similarTransactions; return $importedTransaction; } if ($importedTransaction['categoryId']) { return $importedTransaction; } $transactionStrings = array($importedTransaction['title'], $importedTransaction['description'], $importedTransaction['transactionPartner']); foreach ($transactionStrings as $currentTransactionString) { foreach ($categories as $currentCategoryId => $keywords) { foreach ($keywords as $keyword) { if (stripos($currentTransactionString, trim($keyword)) !== false) { $importedTransaction['categoryId'] = $currentCategoryId; break 3; } //if keyword found } //foreach keywords } //foreach categories } //foreach transactionStrings return $importedTransaction; }
/** * Compare to amount * * @param Amount $amount * @param int $precision Optional decimal precision used in calculation * @return int 0 if instance and $amount are equal, 1 if instance is larger, -1 otherwise. */ public function compareTo(Amount $amount, $precision = -1) { return bccomp($this->getAmount(), $amount->getAmount(), $precision >= 0 ? $precision : $this->getInternalPrecision()); }
public function addCurrencyAmount(Amount $amt) { $this->currencyAmount = $amt->add($this->currencyAmount); return $this; }
function showCategoryData() { global $badgerDb; global $logger; $logger->log('showCategoryData: REQUEST_URI: ' . $_SERVER['REQUEST_URI']); if (!isset($_GET['accounts']) || !isset($_GET['startDate']) || !isset($_GET['endDate']) || !isset($_GET['type']) || !isset($_GET['summarize'])) { throw new BadgerException('statistics', 'missingParameter'); } $accounts = explode(';', $_GET['accounts']); foreach ($accounts as $key => $val) { settype($accounts[$key], 'integer'); } $startDate = new Date($_GET['startDate']); $endDate = new Date($_GET['endDate']); $type = $_GET['type']; if ($type !== 'o') { $type = 'i'; } if ($_GET['summarize'] !== 't') { $summarize = false; } else { $summarize = true; } $categories = gatherCategories($accounts, $startDate, $endDate, $type, $summarize); $sum = new Amount(); foreach ($categories as $currentCategory) { $sum->add($currentCategory['amount']); } $chart = array(); //for documentation for the following code see: http://www.maani.us/charts/index.php?menu=Reference $chart['chart_type'] = '3d pie'; $chart['axis_category'] = array('skip' => 0, 'font' => "Arial", 'bold' => false, 'size' => 10, 'color' => "000000", 'alpha' => 100, 'orientation' => "horizontal"); $chart['chart_rect'] = array('x' => 150, 'y' => 50, 'width' => 500, 'height' => 250, 'positive_color' => "ffffff", 'negative_color' => "000000", 'positive_alpha' => 0, 'negative_alpha' => 0); $chart['chart_value'] = array('prefix' => "", 'suffix' => "", 'decimals' => 0, 'decimal_char' => ".", 'separator' => "", 'position' => "outside", 'hide_zero' => true, 'as_percentage' => false, 'font' => "Arial", 'bold' => false, 'size' => 10, 'color' => "000000", 'alpha' => 90); $chart['chart_transition'] = array('type' => "none", 'delay' => 1, 'duration' => 1, 'order' => "all"); $chart['legend_rect'] = array('x' => 700, 'y' => 400, 'width' => 0, 'height' => 0, 'margin' => 5, 'fill_color' => "FFFFFF", 'fill_alpha' => 100, 'line_color' => "000000", 'line_alpha' => 100, 'line_thickness' => 1); $chart['legend_label'] = array('layout' => "vertical", 'bullet' => "circle", 'font' => "Arial", 'bold' => false, 'size' => 11, 'color' => "000000", 'alpha' => 90); $chart['legend_transition'] = array('type' => "none", 'delay' => 1, 'duration' => 1); $chart['series_color'] = array('000070', 'FFFF99', '007000', 'FFCC99', '700070', 'CC99FF', '660000', '9999FF', '006666', 'CCFF99', 'A35200', 'FFCA7A'); $chart['chart_data'] = array(); $chart['chart_value_text'] = array(); $chart['chart_data'][0][0] = ''; $chart['chart_data'][1][0] = ''; $chart['chart_value_text'][0][0] = ''; $chart['chart_value_text'][1][0] = ''; foreach ($categories as $key => $val) { $chart['chart_data'][0][] = utf8_encode($val['title']); $chart['chart_value_text'][0][] = null; if ($type == 'i') { $chart['chart_data'][1][] = $val['amount']->get(); } else { $chart['chart_data'][1][] = $val['amount']->mul(-1)->get(); } $chart['chart_value_text'][1][] = utf8_encode($val['title'] . "\n" . $val['amount']->getFormatted() . "\n" . round($val['amount']->div($sum)->mul($type == 'i' ? 100 : -100)->get(), 2) . ' %'); } SendChartData($chart); }
/** * Returns all fields in an array. * * The result has the following form: * array ( * array ( * 'field name 0' => 'value of field 0', * 'field name 1' => 'value of field 1' * ) * ); * * The inner array is repeated for each row. * The fields need to be in the order returned by @link getFieldNames(). * * @return array A list of all fields. */ public function getAll() { global $badgerDb; $us = new UserSettings($badgerDb); $tpl = new TemplateEngine($us, BADGER_ROOT); $widgets = new WidgetEngine($tpl); $currentLanguage = $us->getProperty('badgerLanguage'); $result = array(); switch ($this->type) { case 'transaction': $this->fetchTransactions(); $sum = new Amount(); foreach ($this->finishedTransactions as $currentTransaction) { $sum->add($currentTransaction->getAmount()); $result[] = array('transactionId' => $currentTransaction->getId(), 'type' => $widgets->addImage($currentTransaction->getType() == 'FinishedTransaction' ? 'Account/finished_transaction.png' : 'Account/planned_transaction.png', 'title="' . getBadgerTranslation2('Account', $currentTransaction->getType()) . '"'), 'title' => $currentTransaction->getTitle(), 'description' => $currentTransaction->getDescription(), 'valutaDate' => ($tmp = $currentTransaction->getValutaDate()) ? $tmp->getFormatted() : '', 'amount' => $currentTransaction->getAmount()->getFormatted(), 'outsideCapital' => is_null($tmp = $currentTransaction->getOutsideCapital()) ? '' : $tmp, 'transactionPartner' => $currentTransaction->getTransactionPartner(), 'categoryId' => ($tmp = $currentTransaction->getCategory()) ? $tmp->getId() : '', 'categoryTitle' => ($tmp = $currentTransaction->getCategory()) ? $tmp->getTitle() : '', 'sum' => $sum->getFormatted()); } break; case 'finished': while ($this->fetchNextFinishedTransaction()) { } foreach ($this->finishedTransactions as $currentTransaction) { $result[] = array('finishedTransactionId' => $currentTransaction->getId(), 'title' => $currentTransaction->getTitle(), 'description' => $currentTransaction->getDescription(), 'valutaDate' => ($tmp = $currentTransaction->getValutaDate()) ? $tmp->getFormatted() : '', 'amount' => $currentTransaction->getAmount()->getFormatted(), 'outsideCapital' => is_null($tmp = $currentTransaction->getOutsideCapital()) ? '' : $tmp, 'transactionPartner' => $currentTransaction->getTransactionPartner(), 'categoryId' => ($tmp = $currentTransaction->getCategory()) ? $tmp->getId() : '', 'categoryTitle' => ($tmp = $currentTransaction->getCategory()) ? $tmp->getTitle() : '', 'exceptional' => is_null($tmp = $currentTransaction->getExceptional()) ? '' : $tmp, 'periodical' => is_null($tmp = $currentTransaction->getPeriodical()) ? '' : $tmp); } break; case 'planned': while ($this->fetchNextPlannedTransaction()) { } foreach ($this->plannedTransactions as $currentTransaction) { $result[] = array('plannedTransactionId' => 'p' . $currentTransaction->getId() . '_X', 'title' => $currentTransaction->getTitle(), 'description' => $currentTransaction->getDescription(), 'amount' => $currentTransaction->getAmount()->getFormatted(), 'outsideCapital' => is_null($tmp = $currentTransaction->getOutsideCapital()) ? '' : $tmp, 'transactionPartner' => $currentTransaction->getTransactionPartner(), 'beginDate' => $currentTransaction->getBeginDate()->getFormatted(), 'endDate' => ($tmp = $currentTransaction->getEndDate()) ? $tmp->getFormatted() : '', 'repeatUnit' => getBadgerTranslation2('Account', $currentTransaction->getRepeatUnit()), 'repeatFrequency' => $currentTransaction->getRepeatFrequency(), 'categoryId' => ($tmp = $currentTransaction->getCategory()) ? $tmp->getId() : '', 'categoryTitle' => ($tmp = $currentTransaction->getCategory()) ? $tmp->getTitle() : ''); } break; } return $result; }
} ?> </p> <h3>Delivery details</h3> <p> <?php echo $krustomer->DeliveryAddress->get_full_address(); ?> </p> <h3>Allergy details</h3> <p> <?php echo $krustomer->Allergies ? htmlspecialchars($krustomer->Allergies) : 'NA'; ?> </p> <h3>Transaction details</h3> <p> <?php //subscription $total = new Amount(); if ($sub) { $CostPerMeal = new Amount(($sub->WeeklyReg * COST_REGULAR_SERVING) + ($sub->WeeklyVeg * COST_VEGETARIAN_SERVING)); $subscription_subtotal = new Amount($sub->WeeklyMeals * $CostPerMeal->rounded); if ($krustomer->PromoCode) { $subscription_pretax = $krustomer->PromoCode->apply_discount($subscription_subtotal); } else { $subscription_pretax = new Amount($subscription_subtotal); } # Add delivery charge if necessary $zip = dbi()->q_1("SELECT * FROM ZipCode WHERE ZipCode = '{$krustomer->DeliveryAddress->Zip}'"); if (!empty($zip) && $zip->Delivery !== '0.00') { $deliveryFee = new Amount($zip->Delivery); } else {
public function recharge() { $v = Validator::make(Input::all(), ["code" => "required|size:22"], ["required" => "<span class='glyphicon glyphicon-exclamation-sign'></span> Please typr the code.", "size" => "<span class='glyphicon glyphicon-exclamation-sign'></span> Invalid code"]); if ($v->fails()) { return Redirect::back()->withErrors($v)->withInput(); } $find = Product::where("code", Input::get("code")); if ($find->count() > 0) { // Give the point associated with the code $point = $find->get()->first()->point; $p = new Point(); $p->user_id = Auth::user()->id; $p->point = $point; $p->product_id = $find->get()->first()->id; $p->save(); // Set user's designation $active_member = User::find(Auth::user()->id); $active_member->designation = "Active member"; $active_member->save(); // Remove the code from product. So that any user can't use the same code twice. $find->update(["code" => ""]); // If the user has 1000 points then add amount 500 $how_many_points = Point::where('user_id', Auth::user()->id)->sum('point'); if ($how_many_points >= 1000) { // Set the user's designation to Model member $model_member = User::find(Auth::user()->id); $model_member->designation = "Model member"; $model_member->save(); // Check the user's referal is an admin or not $my_referal = User::find(Auth::user()->referal_id); if ($my_referal->type == 'admin') { $distributed_amount = 600; } else { $distributed_amount = 300; } Amount::create(['user_id' => Auth::user()->id, 'amount' => 500, 'status' => 1]); Amount::create(['user_id' => Auth::user()->referal_id, 'amount' => $distributed_amount]); Point::where('user_id', Auth::user()->id)->delete(); } return Redirect::back()->with("event", "<p class='alert alert-success'><span class='glyphicon glyphicon-ok'></span> Congratulation! You got " . $point . " points.</p>"); } return Redirect::back()->with("event", "<p class='alert alert-danger'><span class='glyphicon glyphicon-exclamation-sign'></span> Invalid code.</p>"); }
public function testGCFormLoad() { $init = $this->getDonorTestData('US'); unset($init['order_id']); $init['payment_method'] = 'cc'; $init['payment_submethod'] = 'visa'; $init['ffname'] = 'cc-vmad'; $assertNodes = array('submethod-mc' => array('nodename' => 'input'), 'selected-amount' => array('nodename' => 'span', 'innerhtmlmatches' => '/^\\s*' . str_replace('$', '\\$', Amount::format(1.55, 'USD', $init['language'] . '_' . $init['country'])) . '\\s*$/'), 'state' => array('nodename' => 'select', 'selected' => 'CA')); $this->verifyFormOutput('GlobalCollectGateway', $init, $assertNodes, true); }
/** * Make sure Canadian CC form loads in English and French * @dataProvider canadaLanguageProvider */ public function testGlobalCollectFormLoad_CA($language) { $init = $this->getDonorTestData('CA'); unset($init['order_id']); $init['payment_method'] = 'cc'; $init['payment_submethod'] = 'visa'; $init['ffname'] = 'cc-vma'; $init['language'] = $language; $locale = $language . '_CA'; $assertNodes = array('selected-amount' => array('nodename' => 'span', 'innerhtmlmatches' => '/^\\s*' . str_replace('$', '\\$', Amount::format(1.55, 'CAD', $init['language'] . '_' . $init['country'])) . '\\s*$/'), 'fname' => array('nodename' => 'input', 'placeholder' => wfMessage('donate_interface-donor-fname')->inLanguage($language)->text()), 'lname' => array('nodename' => 'input', 'placeholder' => wfMessage('donate_interface-donor-lname')->inLanguage($language)->text()), 'informationsharing' => array('nodename' => 'p', 'innerhtml' => wfMessage('donate_interface-informationsharing', '.*')->inLanguage($language)->text()), 'state' => array('nodename' => 'select', 'selected' => 'SK'), 'zip' => array('nodename' => 'input', 'value' => $init['zip']), 'country' => array('nodename' => 'input', 'value' => 'CA')); $this->verifyFormOutput('GlobalCollectGateway', $init, $assertNodes, true); }
/** * @covers FireflyIII\Http\Controllers\ReportController::year */ public function testYear() { $user = FactoryMuffin::create('FireflyIII\\User'); $journal = FactoryMuffin::create('FireflyIII\\Models\\TransactionJournal'); $currency = FactoryMuffin::create('FireflyIII\\Models\\TransactionCurrency'); $account = FactoryMuffin::create('FireflyIII\\Models\\Account'); // make shared: AccountMeta::create(['account_id' => $account->id, 'name' => 'accountRole', 'data' => 'sharedAsset']); new Collection([$journal]); $this->be($user); $helper = $this->mock('FireflyIII\\Helpers\\Report\\ReportHelperInterface'); $helper->shouldReceive('getAccountReport')->once()->withAnyArgs()->andReturn([]); $helper->shouldReceive('getIncomeReport')->once()->withAnyArgs()->andReturn([]); $helper->shouldReceive('getExpenseReport')->once()->withAnyArgs()->andReturn([]); // mock stuff! Amount::shouldReceive('getDefaultCurrency')->andReturn($currency); Amount::shouldReceive('getAllCurrencies')->andReturn([$currency]); Amount::shouldReceive('getCurrencyCode')->andReturn('X'); Amount::shouldReceive('getCurrencySymbol')->andReturn('X'); Amount::shouldReceive('format')->andReturn('X'); $this->call('GET', '/reports/2015/shared'); $this->assertResponseOk(); }
protected function addCurrencyData(&$data) { $supportedCurrencies = $this->gateway->getCurrencies(); if (count($supportedCurrencies) === 1) { $data['show_currency_selector'] = false; // The select input will be hidden, but posting the form will use its only value // Display the same currency code $data['currency_code'] = $supportedCurrencies[0]; } else { $data['show_currency_selector'] = true; } foreach ($supportedCurrencies as $currency) { $data['currencies'][] = array('code' => $currency, 'selected' => $currency === $data['currency_code']); } $data['display_amount'] = Amount::format($data['amount'], $data['currency_code'], $data['language'] . '_' . $data['country']); }
public function testGetSubunitFormat() { $amount = new Amount(new Number(5.99), new Currency('EUR'), new SubunitFormat(SubunitFormat::NUMBERS)); $this->assertInstanceOf('Kwn\\NumberToWords\\Model\\SubunitFormat', $amount->getSubunitFormat()); }
public function modulusBy(Amount $b) { return new Amount(bcmod($this->get(), $b->get(), Amount::SCALE)); }