Examples of BigMoney


Examples of org.joda.money.BigMoney

    // Configure the Supplier
    Role supplierRole = DatabaseLoader.buildSupplierRole();
    User steveUser = DatabaseLoader.buildSteveSupplier(supplierRole);

    BigMoney unitPrice = MoneyUtils.parse("GBP 1.23");

    // Configure some PricingRules
    PricingRule pricingRule = DatabaseLoader.buildPresetMarginPricingRule();

    BigMoney price = PriceBuilder
      .newInstance()
      .withSupplier(steveUser.getSupplier())
      .withPricingRule(pricingRule)
      .withStartingPrice(unitPrice)
      .build();

    assertEquals("GBP 1.476",price.toString());

  }
View Full Code Here

Examples of org.joda.money.BigMoney

    book1.setId(1L);
    Item book2 = DatabaseLoader.buildBookItemQuantumThief();
    book2.setId(2L);

    // TODO Pull this into DatabaseLoader
    BigMoney book1UnitPrice = MoneyUtils.parse("GBP 1.23");
    BigMoney book1UnitTax = MoneyUtils.parse("GBP 0.20");
    BigMoney book2UnitPrice = MoneyUtils.parse("GBP 2.46");
    BigMoney book2UnitTax = MoneyUtils.parse("GBP 0.40");

    PurchaseOrder stevePurchaseOrder1 = PurchaseOrderBuilder
      .newInstance()
      .withSupplier(steveUser.getSupplier())
      .withPurchaseOrderItem(book1, 1, book1UnitPrice, book1UnitTax)
      .withPurchaseOrderItem(book2, 2, book2UnitPrice, book2UnitTax)
      .build();
    stevePurchaseOrder1.setId(1L);
    steveUser.getSupplier().getPurchaseOrders().add(stevePurchaseOrder1);

    // Configure Sam Supplier
    User samUser = DatabaseLoader.buildSamSupplier(supplierRole);
    samUser.setId(1L);
    samUser.getSupplier().setId(1L);

    // Configure Sam's PurchaseOrder with Items
    Item book3 = DatabaseLoader.buildBookItemCompleteWorks();
    book3.setId(3L);
    Item book4 = DatabaseLoader.buildBookItemPlumbing();
    book4.setId(4L);

    // TODO Pull this into DatabaseLoader
    BigMoney book3UnitPrice = MoneyUtils.parse("GBP 1.23");
    BigMoney book3UnitTax = MoneyUtils.parse("GBP 0.20");
    BigMoney book4UnitPrice = MoneyUtils.parse("GBP 2.46");
    BigMoney book4UnitTax = MoneyUtils.parse("GBP 0.40");

    PurchaseOrder samPurchaseOrder1 = PurchaseOrderBuilder
      .newInstance()
      .withSupplier(samUser.getSupplier())
      .withPurchaseOrderItem(book3, 3, book3UnitPrice, book3UnitTax)
View Full Code Here

Examples of org.joda.money.BigMoney

   */
  public BigMoney build() {
    validateState();

    // Price is not a DTO
    BigMoney price = startingPrice;

    for (PricingRule pricingRule : pricingRules) {
      pricingRule.setCustomer(customer);
      pricingRule.setSupplier(supplier);
      pricingRule.setQuantity(quantity);
View Full Code Here

Examples of org.joda.money.BigMoney

    String currencySymbol = "Ƀ"; // or £ or €
    String currencyCode = "BTC";

    // Calculate the value of the delivery items
    // TODO Allow for currency conversion
    BigMoney deliveryTotal = MoneyUtils.parseBitcoin("BTC 0.0000");
    BigMoney taxTotal = MoneyUtils.parseBitcoin("BTC 0.0000");
    for (DeliveryItem deliveryItem: delivery.getDeliveryItems()) {
      deliveryTotal = deliveryTotal.plus(deliveryItem.getPriceSubtotal());
      taxTotal = taxTotal.plus(deliveryItem.getTaxSubtotal());
    }

    // Create top-level resource
    Representation deliveryRepresentation = new DefaultRepresentationFactory()
      .newRepresentation(basePath)
      // Do not reveal the supplier to non-admins
      .withLink("supplier","/supplier")
      .withProperty("currency_symbol", currencySymbol)
      .withProperty("currency_code", currencyCode)
      .withProperty("price_total", deliveryTotal.getAmount().toPlainString())
      .withProperty("tax_total", taxTotal.getAmount().toPlainString())
      .withProperty("item_total", delivery.getItemTotal())
      .withProperty("quantity_total", delivery.getQuantityTotal())
      // End of build
      ;
View Full Code Here

Examples of org.joda.money.BigMoney

    String currencySymbol = "Ƀ"; // or £ or €
    String currencyCode = "BTC";

    // Calculate the value of the purchaseOrder items
    // TODO Allow for currency conversion
    BigMoney purchaseOrderTotal = MoneyUtils.parseBitcoin("BTC 0.0000");
    BigMoney taxTotal = MoneyUtils.parseBitcoin("BTC 0.0000");
    for (PurchaseOrderItem purchaseOrderItem: purchaseOrder.getPurchaseOrderItems()) {
      purchaseOrderTotal = purchaseOrderTotal.plus(purchaseOrderItem.getPriceSubtotal());
      taxTotal = taxTotal.plus(purchaseOrderItem.getTaxSubtotal());
    }

    // Create top-level resource
    Representation purchaseOrderRepresentation = new DefaultRepresentationFactory()
      .newRepresentation(basePath)
      // Do not reveal the supplier to non-admins
      .withLink("supplier","/supplier")
      .withProperty("currency_symbol", currencySymbol)
      .withProperty("currency_code", currencyCode)
      .withProperty("price_total", purchaseOrderTotal.getAmount().toPlainString())
      .withProperty("tax_total", taxTotal.getAmount().toPlainString())
      .withProperty("item_total", purchaseOrder.getItemTotal())
      .withProperty("quantity_total", purchaseOrder.getQuantityTotal())
      // End of build
      ;
View Full Code Here

Examples of org.joda.money.BigMoney

    String currencySymbol = "Ƀ"; // or £ or €
    String currencyCode = "BTC";

    // Calculate the value of the cart items
    // TODO Allow for currency conversion
    BigMoney cartTotal = MoneyUtils.parseBitcoin("BTC 0.0000");
    BigMoney taxTotal = MoneyUtils.parseBitcoin("BTC 0.0000");
    for (CartItem cartItem : cart.getCartItems()) {
      cartTotal = cartTotal.plus(cartItem.getPriceSubtotal());
      taxTotal = taxTotal.plus(cartItem.getTaxSubtotal());
    }

    // Create top-level resource
    Representation cartRepresentation= new DefaultRepresentationFactory()
      .newRepresentation(basePath)
        // Do not reveal the customer to non-admins
      .withLink("customer", "/customer")
      .withProperty("currency_symbol", currencySymbol)
      .withProperty("currency_code", currencyCode)
      .withProperty("price_total", cartTotal.getAmount().toPlainString())
      .withProperty("tax_total", taxTotal.getAmount().toPlainString())
      .withProperty("item_total", cart.getItemTotal())
      .withProperty("quantity_total", cart.getQuantityTotal())
      // End of build
      ;
View Full Code Here

Examples of org.joda.money.BigMoney

  @Override
  public Object getPropertyValue(Object component, int propertyIndex) throws HibernateException {
    if (component == null) {
      return null;
    }
    final BigMoney money = (BigMoney) component;
    switch (propertyIndex) {
      case 0: {
        return money.getAmount();
      }
      case 1: {
        return money.getCurrencyUnit().getCurrencyCode();
      }
      default: {
        throw new HibernateException("Invalid property index [" + propertyIndex + "]");
      }
    }
View Full Code Here

Examples of org.joda.money.BigMoney

  public void setPropertyValue(Object component, int propertyIndex, Object value) throws HibernateException {
    if (component == null) {
      return;
    }

    final BigMoney money = (BigMoney) component;
    switch (propertyIndex) {
      case 0: {
        money.withAmount((BigDecimal) value);
        break;
      }
      case 1: {
        money.withCurrencyUnit(CurrencyUnit.getInstance((String) value));
        break;
      }
      default: {
        throw new HibernateException("Invalid property index [" + propertyIndex + "]");
      }
View Full Code Here

Examples of org.joda.money.BigMoney

      return false;
    }
    if (x.getClass() != y.getClass()) {
      return false;
    }
    final BigMoney xMoney = (BigMoney) x;
    final BigMoney yMoney = (BigMoney) y;

    return ObjectUtils.isEqual(
      xMoney.getCurrencyUnit(), yMoney.getCurrencyUnit(),
      xMoney.getAmount(), yMoney.getAmount()
    );
  }
View Full Code Here

Examples of org.joda.money.BigMoney

  public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException {
    if (value == null) {
      BigDecimalType.INSTANCE.set(st, null, index, session);
      StringType.INSTANCE.set(st, null, index + 1, session);
    } else {
      final BigMoney money = (BigMoney) value;
      BigDecimalType.INSTANCE.set(st, money.getAmount(), index, session);
      StringType.INSTANCE.set(st, money.getCurrencyUnit().getCurrencyCode(), index + 1, session);
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.