public static function fromJson($json) { $r = new Price(); $r->setGross($json->gross); $r->setCurrency($json->currency); return $r; }
public function testPricesWithNoTax() { $price = new Price(100, Price::NETTO, -1); $this->assertEquals(100, $price->convertTo(Price::NETTO)); $this->assertEquals(100, $price->convertTo(Price::BRUTTO)); $this->assertEquals(0, $price->convertTo(Price::TAX)); }
protected function import_csv() { set_time_limit(0); $file_name = dirname(APPLICATION_PATH) . '/files/price.csv'; if (file_exists($file_name)) { $Price = new Price(); $f = fopen($file_name, 'r'); echo getdate() . "<BR>"; while (!feof($f)) { $s = fgets($f); $s = trim($s); if ($s != '') { $ar = split(';', $s); if ($ar[1] == '2') { $data = array('id_product' => $ar[0], 'exists_type' => $ar[1], 'price' => $ar[2]); if (!($er = $Price->add($data))) { print_r($data); print_r('error=' . $er); exit; } } } } echo getdate(); fclose($f); } else { echo 'file not found'; } }
public function Amount($order) { $shopConfig = ShopConfig::current_shop_config(); $amount = new Price(); $amount->setAmount($order->SubTotal()->getAmount() * ($this->Rate / 100)); $amount->setCurrency($shopConfig->BaseCurrency); $amount->setSymbol($shopConfig->BaseCurrencySymbol); return $amount; }
/** * Choose Discounted price depending on current member's StreakDiscountType. * * @param Price $amount */ public function updateAmount($amount) { // only if we are on a front-end page if (Controller::curr() instanceof Page_Controller) { if ($discountedPrice = $this->discountedPrice()) { $amount->setAmount($discountedPrice); } } }
public function testPayload() { $p = new Price(); foreach ($this->payload as $testCase) { echo "Testing case: " . json_encode($testCase) . "\n"; $p->setPricePerMinute($testCase["ppm"]); $this->assertEquals($p->calculateCallCost($testCase["duration"]), $testCase["result"]); } }
public function getPriceForDays($days) { $price = Price::fromString('0', $this->price->getCurrency()); while ($days > 0) { $days -= $this->unitInDays; $price = $price->add($this->price); } return $price; }
public function testCurrencyPairsConversions() { $price = new Price(array('EUR' => 5, 'USD' => 10, 'GBP' => 15), array('USD/CHF 1.500')); $conversions = $price->getConversions(); $this->assertCount(1, $conversions); $this->assertInstanceOf('Money\\CurrencyPair', $conversions[0]); $this->assertEquals('USD', $conversions[0]->getBaseCurrency()); $this->assertEquals('CHF', $conversions[0]->getCounterCurrency()); $this->assertEquals(1.5, $conversions[0]->getRatio()); }
public function Amount() { // TODO: Multi currency $shopConfig = ShopConfig::current_shop_config(); $amount = new Price(); $amount->setAmount($this->Price); $amount->setCurrency($shopConfig->BaseCurrency); $amount->setSymbol($shopConfig->BaseCurrencySymbol); $this->extend('updateAmount', $amount); return $amount; }
public function testShouldBeImmutable() { $p1ArrayMoney = ['EUR' => 100, 'GBP' => 101]; $p2ArrayMoney = ['EUR' => 100]; $p2ArrayCurrency = ['EUR/GBP 1.100']; $price1 = new Price($p1ArrayMoney); $price2 = new Price($p2ArrayMoney, $p2ArrayCurrency); $priceAdd = $price1->add($price2); $priceMul = $price1->multiply(2); $this->assertEquals(new Price($p1ArrayMoney), $price1); $this->assertEquals(new Price($p2ArrayMoney, $p2ArrayCurrency), $price2); }
public function testPayload() { $price = new Price(); $plan = new Plan(); foreach ($this->payload as $testCase) { echo "Testing case: " . json_encode($testCase) . "\n"; $price->setPricePerMinute($testCase["price"]["ppm"]); $plan->setMinutes($testCase["plan"]["min"]); $plan->setFareAdditionalMin($testCase["plan"]["fare"]); $this->assertEquals($plan->calculateCallCost($price, $testCase["duration"]), $testCase["result"]); } }
private function toObject($row) { $obj = new Price(); if (isset($row["from_ddd"])) { $obj->setFromDDD($row["from_ddd"]); } if (isset($row["to_ddd"])) { $obj->setToDDD($row["to_ddd"]); } if (isset($row["price_per_minute"])) { $obj->setPricePerMinute($row["price_per_minute"]); } return $obj; }
public function __construct($controller, $name, $quantity = null, $redirectURL = null) { parent::__construct($controller, $name, FieldList::create(), FieldList::create(), null); Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js'); Requirements::javascript(THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js'); Requirements::javascript('swipestripe/javascript/ProductForm.js'); $this->product = $controller->data(); $this->quantity = $quantity; $this->redirectURL = $redirectURL; $this->fields = $this->createFields(); $this->actions = $this->createActions(); $this->validator = $this->createValidator(); $this->setupFormErrors(); $this->addExtraClass('product-form'); //Add a map of all variations and prices to the page for updating the price $map = array(); $variations = $this->product->Variations(); $productPrice = $this->product->Price(); if ($variations && $variations->exists()) { foreach ($variations as $variation) { if ($variation->isEnabled()) { $variationPrice = $variation->Price(); $amount = Price::create(); $amount->setAmount($productPrice->getAmount() + $variationPrice->getAmount()); $amount->setCurrency($productPrice->getCurrency()); $amount->setSymbol($productPrice->getSymbol()); $map[] = array('price' => $amount->Nice(), 'options' => $variation->Options()->column('ID'), 'free' => _t('Product.FREE', 'Free')); } } } $this->setAttribute('data-map', json_encode($map)); }
public static function setList($list) { $sql = 'UPDATE {{catalog}} SET available=0'; DB::exec($sql); foreach ($list as $partname => $items) { $sql = 'SELECT tree FROM {{catalog}} WHERE partname="' . $partname . '"'; $parent = DB::getOne($sql); if ($parent) { $available = 0; foreach ($items as $size => $item) { $sql = 'SELECT id FROM {{tree}} WHERE parent=' . $parent . ' AND name="' . $size . '"'; $tree = DB::getOne($sql); if (!$tree) { $sql = 'SELECT id FROM {{tree}} WHERE parent=' . $parent . ' AND path="' . $size . '"'; $tree = DB::getOne($sql); } foreach ($item as $k => $f) { $sql = 'SELECT type FROM {{fields}} WHERE module=6 AND path="' . $k . '"'; $r = DB::getOne($sql); $row = array('field' => Fields::$types[$r]['type'], 'path' => $k, 'value' => $f); Price::updateField($tree, $row); if ($k == 'numberRetailSales' && $f > 0) { $available = 1; } } } $sql = 'UPDATE {{catalog}} SET available=' . $available . ' WHERE tree=' . $parent; DB::exec($sql); } } }
/** * Get the form fields for the OrderForm. * * @return FieldList List of fields */ public function getFormFields() { $fields = new FieldList(); $field = new XeroTaxModifierField($this, _t('Xero.TAX', 'Tax')); $shopConfig = ShopConfig::current_shop_config(); $amount = new Price(); $amount->setAmount($this->Price); $amount->setCurrency($shopConfig->BaseCurrency); $amount->setSymbol($shopConfig->BaseCurrencySymbol); $field->setAmount($amount); $fields->push($field); if (!$fields->exists()) { Requirements::javascript('swipestripe-flatfeetax/javascript/FlatFeeTaxModifierField.js'); } return $fields; }
public function run() { Price::create(['min' => '0', 'max' => '1000000']); Price::create(['min' => '1000000', 'max' => '10000000']); Price::create(['min' => '10000000', 'max' => '100000000']); Price::create(['min' => '100000000']); }
/** * * @param Price $price * @return int id of the Price inserted in base. False if it didn't work. */ public static function flush($price) { $priceId = $price->getId(); $pricevar = $price->getPrice(); if ($priceId > 0) { $sql = 'UPDATE price p SET ' . 'p.price = ?, ' . 'WHERE p.id_price = ?'; $params = array('di', &$pricevar, $priceId); } else { $sql = 'INSERT INTO price ' . '(price) ' . 'VALUES(?) '; $params = array('d', &$pricevar); } $idInsert = BaseSingleton::insertOrEdit($sql, $params); if ($idInsert !== false && $priceId > 0) { $idInsert = $priceId; } return $idInsert; }
/** * Add the [recras-arrangement] shortcode * * @param array $attributes * * @return string */ public static function addArrangementShortcode($attributes) { if (!isset($attributes['id'])) { return __('Error: no ID set', Plugin::TEXT_DOMAIN); } if (!ctype_digit($attributes['id'])) { return __('Error: ID is not a number', Plugin::TEXT_DOMAIN); } if (!isset($attributes['show'])) { return __('Error: "show" option not set', Plugin::TEXT_DOMAIN); } if (!in_array($attributes['show'], self::getValidOptions())) { return __('Error: invalid "show" option', Plugin::TEXT_DOMAIN); } $subdomain = Settings::getSubdomain($attributes); if (!$subdomain) { return Plugin::getNoSubdomainError(); } $json = get_transient('recras_' . $subdomain . '_arrangement_' . $attributes['id']); if ($json === false) { try { $json = Http::get($subdomain, 'arrangementen/' . $attributes['id']); } catch (\Exception $e) { return $e->getMessage(); } set_transient('recras_' . $subdomain . '_arrangement_' . $attributes['id'], $json, 86400); } switch ($attributes['show']) { case 'description': return $json->uitgebreide_beschrijving; case 'duration': return self::getDuration($json); case 'image_url': return $json->image_filename; case 'location': return self::getLocation($json); case 'persons': return '<span class="recras-persons">' . $json->aantal_personen . '</span>'; case 'price_pp_excl_vat': return Price::format($json->prijs_pp_exc); case 'price_pp_incl_vat': return Price::format($json->prijs_pp_inc); case 'price_total_excl_vat': return Price::format($json->prijs_totaal_exc); case 'price_total_incl_vat': return Price::format($json->prijs_totaal_inc); case 'program': case 'programme': $startTime = isset($attributes['starttime']) ? $attributes['starttime'] : '00:00'; $showHeader = !isset($attributes['showheader']) || Settings::parseBoolean($attributes['showheader']); return self::generateProgramme($json->programma, $startTime, $showHeader); case 'title': return '<span class="recras-title">' . $json->arrangement . '</span>'; default: return __('Error: unknown option', Plugin::TEXT_DOMAIN); } }
public function label() { $charactor = Charactor::all(); $scene = Scene::all(); $object = Object::all(); // dd('man'); $price = Price::all(); return View::make('pc.search')->with(array('errCode' => 0, 'message' => '返回标签', '_char' => $charactor, 'scene' => $scene, 'object' => $object, 'price' => $price)); }
public function label() { $charactor = Charactor::all(); $scene = Scene::all(); $object = Object::all(); // dd('man'); $price = Price::all(); return Response::json(array('errCode' => 0, 'message' => '返回标签', '_char' => $charactor, 'scene' => $scene, 'object' => $object, 'price' => $price)); }
public static function fromJson($json) { $r = new Checkout(); $r->setItems(array_map(function ($json) { return CheckoutItem::fromJson($json); }, $json->items)); $r->setTotal(Price::fromJson($json->total)); return $r; }
public function getSubTotal() { $subtotal = Price::fromString('0', Currency::fromString('EUR')); /** @var RateQuoteLineItem $lineItem */ foreach ($this->lineItems as $lineItem) { $subtotal = $subtotal->add($lineItem->getLineTotal()); } return $subtotal; }
public function __construct($attributes) { parent::__construct($attributes); if (!isset($this->attributes['base_price_field']) || !$this->attributes['base_price_field'] instanceof Field) { throw new Exception("Base price source field (attribute: base_price_field) not set for field '{$this->attributes['name']}'."); } $this->attributes['base_price_field_name'] = $this->attributes['base_price_field']->getName(); $this->attributes['suffixes'] = App::getModel('suffix/suffix')->getSuffixTypesForSelect(); }
public function Amount() { $amount = Price::create(); $amount->setCurrency($this->Currency); $amount->setAmount($this->Price); $amount->setSymbol(ShopConfig::current_shop_config()->BaseCurrencySymbol); //Transform amount for applying discounts etc. $this->extend('updateAmount', $amount); return $amount; }
public function Amount() { // TODO: Multi currency $order = $this->Order(); $amount = Price::create(); $amount->setAmount($this->Price); $amount->setCurrency($order->BaseCurrency); $amount->setSymbol($order->BaseCurrencySymbol); return $amount; }
public function estimatePrice($opts = array()) { extract($opts); $info = $this->info(); if (!isset($material)) { $material = reset(json_decode($info['material'])); } $price = $info['weight'] * (1 + Setting::get('wear_tear')) * Price::current($material) * ($material === 'PT950' ? Setting::get('weight_ratio') : 1) + Setting::get('labor_expense') + $info['small_stone'] * (Setting::get('st_expense') + Setting::get('st_price')); return round($price, 2); }
public static function usdeurgbp($totalprice) { $usd = 17; $eur = 13; $gbp = 10; $plex = Price::getItemPrice('29668', date('Ymd')); $usdval = $plex / $usd; $eurval = $plex / $eur; $gbpval = $plex / $gbp; return array('usd' => $totalprice / $usdval, 'eur' => $totalprice / $eurval, 'gbp' => $totalprice / $gbpval); }
public static function fromJson($json) { $r = new CheckoutItem(); $r->setCount($json->count); $r->setName(isset($json->name) ? $json->name : null); $r->setSku($json->sku); $r->setExternalId(isset($json->external_id) ? $json->external_id : null); $r->setPrice(Price::fromJson($json->price)); $r->setTotal(Price::fromJson($json->total)); return $r; }
/** * Add shipping region code dropdown to form. * @return FieldList */ public function getFormFields() { $fields = new FieldList(); $field = new StreakGST_ModifierField($this, self::description()); /** @var Price $price */ $price = Price::create(); $price->setAmount($this->GST); $field->setAmount($price); $fields->push($field); return $fields; }
/** * This is the constructor of the price with quantity object. * * @api * @author David Pauli <*****@*****.**> * @since 0.1.0 * @since 0.1.1 No locale parameter is needed * @param mixed[] $priceParameter The price parameter. * @param mixed[] $quantityParameter The quantity parameter. */ public function __construct($priceParameter, $quantityParameter) { parent::__construct($priceParameter); if (InputValidator::isArray($quantityParameter)) { if (!InputValidator::isEmptyArrayKey($quantityParameter, "amount")) { $this->quantityAmount = $quantityParameter['amount']; } if (!InputValidator::isEmptyArrayKey($quantityParameter, "unit")) { $this->quantityUnit = $quantityParameter['unit']; } } }