001/*
002 * Copyright (C) 2014 konik.io
003 *
004 * This file is part of Konik library.
005 *
006 * Konik library is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU Affero General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * Konik library is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU Affero General Public License for more details.
015 *
016 * You should have received a copy of the GNU Affero General Public License
017 * along with Konik library.  If not, see <http://www.gnu.org/licenses/>.
018 */
019package io.konik.zugferd.unqualified;
020
021import java.math.BigDecimal;
022
023import javax.xml.bind.annotation.XmlAccessType;
024import javax.xml.bind.annotation.XmlAccessorType;
025import javax.xml.bind.annotation.XmlAttribute;
026import javax.xml.bind.annotation.XmlType;
027import javax.xml.bind.annotation.XmlValue;
028
029import com.neovisionaries.i18n.CurrencyCode;
030
031/**
032 * = The Monetary Amount.
033 * 
034 * A number of monetary units specified in a currency where the unit of the currency is explicit or implied.
035 */
036@XmlAccessorType(XmlAccessType.FIELD)
037@XmlType(name = "AmountType", propOrder = { "value" })
038public class Amount {
039
040   @XmlValue
041   private BigDecimal value;
042
043   @XmlAttribute(name = "currencyID")
044//   @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
045   private CurrencyCode currency;
046
047   /** Instantiates a new amount. */
048   public Amount() {
049   }
050
051   /**
052    * Instantiates a new amount.
053    *
054    * @param value the value
055    * @param currency the currency code
056    */
057   public Amount(long value, CurrencyCode currency) {
058      super();
059      this.value = BigDecimal.valueOf(value);
060      this.currency = currency;
061   }
062
063   /**
064    * Instantiates a new amount.
065    *
066    * @param value the value
067    * @param currency the currency code
068    */
069   public Amount(String value, CurrencyCode currency) {
070      super();
071      this.value = new BigDecimal(value);
072      this.currency = currency;
073   }
074
075   /**
076    * Instantiates a new amount.
077    *
078    * @param value the value
079    * @param currency the currency code
080    */
081   public Amount(BigDecimal value, CurrencyCode currency) {
082      super();
083      this.value = value;
084      this.currency = currency;
085   }
086
087   /**
088    * Gets the amount value.
089    * 
090    * @return the value
091    */
092   public BigDecimal getValue() {
093      return value;
094   }
095
096   /**
097    * Sets the amount value.
098    *
099    * @param value the new value
100    * @return the amount
101    */
102   public Amount setValue(BigDecimal value) {
103      this.value = value;
104      return this;
105   }
106
107   /**
108    * Gets the currency code.
109    *
110    * @return the +ISO 4217 3A+ currency code
111    */
112   public CurrencyCode getCurrency() {
113      return currency;
114   }
115   
116   /**
117    * Sets the currency code.
118    *
119    * @param currency the new +ISO 4217 3A+ currency code
120    * @return the amount
121    */
122   public Amount setCurrency(CurrencyCode currency) {
123      this.currency = currency;
124      return this;
125   }
126
127}